Revert "Remove coroutines (#874)" (#1019)

* Revert "Remove coroutines (#874)"

This reverts commit 569c78fd8c.

* Update freertos Kernel submodule to latest head

* Remove temporary files

* Fix MingW demos and spell check

* Fix manifest version; fix headers

* Add ignore files and paths to core-checker.py

* Fix copyright in remaining files

* Fix PR check build failure

1. Remove defining `inline` in Makefile. This was causing build
   warnings.
2. Ensure that the linker removed unused functions from various
   compilation units.
3. Update the linker script so that all the functions are correctly
   placed in FLASH section.

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>

---------

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
Co-authored-by: Gaurav Aggarwal <aggarg@amazon.com>
This commit is contained in:
Aniruddha Kanhere 2023-06-09 15:25:48 -07:00 committed by GitHub
parent 9ccae851e7
commit 1277ba1661
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
605 changed files with 11240 additions and 3628 deletions

View file

@ -34,7 +34,7 @@
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
*
* See http://www.freertos.org/a00110.html
*----------------------------------------------------------*/
@ -50,8 +50,10 @@
#define configUSE_TRACE_FACILITY 0
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 0
#define configUSE_CO_ROUTINES 1
#define configMAX_PRIORITIES ( 2 )
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
@ -69,4 +71,6 @@ to exclude the API function. */
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
#define configMAX_SYSCALL_INTERRUPT_PRIORITY 191 /* equivalent to 0xa0, or priority 5. */
#endif /* FREERTOS_CONFIG_H */

View file

@ -73,7 +73,7 @@ unsigned char ucBit = ( unsigned char ) 1;
}
PDCWrite( PDC_LED, ucOutputValue );
}
}
}
xTaskResumeAll();
}

View file

@ -907,6 +907,9 @@
<file>
<name>$PROJ_DIR$\commstest.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\Common\Minimal\crflash.c</name>
</file>
<file>
<name>$PROJ_DIR$\main.c</name>
</file>
@ -919,6 +922,9 @@
</group>
<group>
<name>FreeRTOS Source</name>
<file>
<name>$PROJ_DIR$\..\..\Source\croutine.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\Source\portable\MemMang\heap_1.c</name>
</file>
@ -951,3 +957,5 @@
</file>
</group>
</project>

View file

@ -25,7 +25,7 @@
*/
/*
* The comms test Rx and Tx task. See the comments at the top
* The comms test Rx and Tx task and co-routine. See the comments at the top
* of main.c for full information.
*/
@ -34,6 +34,7 @@
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "croutine.h"
/* Demo application include files. */
#include "partest.h"
@ -42,7 +43,7 @@
#include "DriverLib.h"
/* The LED's toggled by the various tasks. */
#define commsFAIL_LED ( 7 )
#define commsFAIL_LED ( 7 )
#define commsRX_LED ( 6 )
#define commsTX_LED ( 5 )
@ -50,7 +51,7 @@
task. */
#define commsRX_QUEUE_LEN ( 5 )
/* The baud rate used by the UART comms tasks. */
/* The baud rate used by the UART comms tasks/co-routine. */
#define commsBAUD_RATE ( 57600 )
/* FIFO setting for the UART. The FIFO is not used to create a better test. */
@ -116,6 +117,71 @@ void vSerialInit( void )
}
/*-----------------------------------------------------------*/
void vSerialTxCoRoutine( CoRoutineHandle_t xHandle, unsigned portBASE_TYPE uxIndex )
{
TickType_t xDelayPeriod;
static unsigned long *pulRandomBytes = commsFIRST_PROGRAM_BYTES;
/* Co-routine MUST start with a call to crSTART. */
crSTART( xHandle );
for(;;)
{
/* Was the previously transmitted string received correctly? */
if( uxCommsErrorStatus != pdPASS )
{
/* An error was encountered so set the error LED. */
vParTestSetLED( commsFAIL_LED, pdTRUE );
}
/* The next character to Tx is the first in the string. */
cNextChar = commsFIRST_TX_CHAR;
UARTIntDisable( UART0_BASE, UART_INT_TX );
{
/* Send the first character. */
if( !( HWREG( UART0_BASE + UART_O_FR ) & UART_FR_TXFF ) )
{
HWREG( UART0_BASE + UART_O_DR ) = cNextChar;
}
/* Move the variable to the char to Tx on so the ISR transmits
the next character in the string once this one has completed. */
cNextChar++;
}
UARTIntEnable(UART0_BASE, UART_INT_TX);
/* Toggle the LED to show a new string is being transmitted. */
vParTestToggleLED( commsTX_LED );
/* Delay before we start the string off again. A pseudo-random delay
is used as this will provide a better test. */
xDelayPeriod = xTaskGetTickCount() + ( *pulRandomBytes );
pulRandomBytes++;
if( pulRandomBytes > commsTOTAL_PROGRAM_MEMORY )
{
pulRandomBytes = commsFIRST_PROGRAM_BYTES;
}
/* Make sure we don't wait too long... */
xDelayPeriod &= commsMAX_TX_DELAY;
/* ...but we do want to wait. */
if( xDelayPeriod < commsMIN_TX_DELAY )
{
xDelayPeriod = commsMIN_TX_DELAY;
}
/* Block for the random(ish) time. */
crDELAY( xHandle, xDelayPeriod );
}
/* Co-routine MUST end with a call to crEND. */
crEND();
}
/*-----------------------------------------------------------*/
void vUART_ISR( void )
{
unsigned long ulStatus;
@ -138,7 +204,7 @@ portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
blocked on the queue waiting for characters. */
cRxedChar = ( char ) HWREG( UART0_BASE + UART_O_DR );
xQueueSendFromISR( xCommsQueue, &cRxedChar, &xHigherPriorityTaskWoken );
}
}
}
/* Was a Tx interrupt pending? */
@ -154,7 +220,7 @@ portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
cNextChar++;
}
}
/* If a task was woken by the character being received then we force
a context switch to occur in case the task is of higher priority than
the currently executing task (i.e. the task that this interrupt

View file

@ -37,6 +37,12 @@ void vSerialInit( void );
*/
void vCommsRxTask( void * pvParameters );
/*
* The co-routine that periodically initiates the transmission of the string on
* the UART.
*/
void vSerialTxCoRoutine( CoRoutineHandle_t xHandle, unsigned portBASE_TYPE uxIndex );
unsigned portBASE_TYPE uxGetCommsStatus( void );
#endif

View file

@ -24,11 +24,16 @@
*
*/
/*
* This demo application creates four tasks (five including the idle task).
* The application is limited in size to allow its compilation using
/*
* This demo application creates eight co-routines and four tasks (five
* including the idle task). The co-routines execute as part of the idle task
* hook. The application is limited in size to allow its compilation using
* the KickStart version of the IAR compiler.
*
* Six of the created co-routines are the standard 'co-routine flash'
* co-routines contained within the Demo/Common/Minimal/crflash.c file and
* documented on the FreeRTOS.org WEB site.
*
* The 'LCD Task' waits on a message queue for messages informing it what and
* where to display text. This is the only task that accesses the LCD
* so mutual exclusion is guaranteed.
@ -37,19 +42,37 @@
* the message queue. The strings are rotated to form a short message and
* are written to the top row of the LCD.
*
* A loopback connector is required to ensure that each character transmitted
* The 'ADC Co-routine' periodically reads the ADC input that is connected to
* the light sensor, forms a short message from the value, and then sends this
* message to the LCD Task using the same message queue. The ADC readings are
* displayed on the bottom row of the LCD.
*
* The eighth co-routine and final task control the transmission and reception
* of a string to UART 0. The co-routine periodically sends the first
* character of the string to the UART, with the UART's TxEnd interrupt being
* used to transmit the remaining characters. The UART's RxEnd interrupt
* receives the characters and places them on a queue to be processed by the
* 'COMs Rx' task. An error is latched should an unexpected character be
* received, or any character be received out of sequence.
*
* A loopback connector is required to ensure that each character transmitted
* on the UART is also received on the same UART. For test purposes the UART
* FIFO's are not utalised in order to maximise the interrupt overhead. Also
* a pseudo random interval is used between the start of each transmission in
* order that the resultant interrupts are more randomly distributed and
* a pseudo random interval is used between the start of each transmission in
* order that the resultant interrupts are more randomly distributed and
* therefore more likely to highlight any problems.
*
* In addition the idle task makes repetitive calls to
* vSetAndCheckRegisters(). This simply loads the general purpose registers
* with a known value, then checks each register to ensure the held value is
* still correct. As a low priority task this checking routine is likely to
* get repeatedly swapped in and out. A register being found to contain an
* incorrect value is therefore indicative of an error in the task switching
* The flash co-routines control LED's zero to four. LED five is toggled each
* time the string is transmitted on the UART. LED six is toggled each time
* the string is CORRECTLY received on the UART. LED seven is latched on
* should an error be detected in any task or co-routine.
*
* In addition the idle task makes repetitive calls to
* vSetAndCheckRegisters(). This simply loads the general purpose registers
* with a known value, then checks each register to ensure the held value is
* still correct. As a low priority task this checking routine is likely to
* get repeatedly swapped in and out. A register being found to contain an
* incorrect value is therefore indicative of an error in the task switching
* mechanism.
*
*/
@ -61,9 +84,11 @@
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "croutine.h"
/* Demo application include files. */
#include "partest.h"
#include "crflash.h"
#include "commstest.h"
/* Library include files. */
@ -77,9 +102,21 @@
#define mainADC_DELAY ( 200 / portTICK_PERIOD_MS )
/* The number of flash co-routines to create. */
#define mainNUM_FLASH_CO_ROUTINES ( 5 )
/* The length of the queue used to send messages to the LCD task. */
#define mainLCD_QUEUE_LEN ( 3 )
/* The priority of the co-routine used to initiate the transmission of the
string on UART 0. */
#define mainTX_CO_ROUTINE_PRIORITY ( 1 )
#define mainADC_CO_ROUTINE_PRIORITY ( 2 )
/* Only one of each co-routine is created so its index is not important. */
#define mainTX_CO_ROUTINE_INDEX ( 0 )
#define mainADC_CO_ROUTINE_INDEX ( 0 )
/* The task priorities. */
#define mainLCD_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
#define mainMSG_TASK_PRIORITY ( mainLCD_TASK_PRIORITY - 1 )
@ -92,7 +129,8 @@
/* Dimension for the buffer into which the ADC value string is written. */
#define mainMAX_ADC_STRING_LEN 20
/* The LED that is lit should an error be detected in any of the tasks */
/* The LED that is lit should an error be detected in any of the tasks or
co-routines. */
#define mainFAIL_LED ( 7 )
/*-----------------------------------------------------------*/
@ -107,6 +145,12 @@ static void prvLCDTask( void * pvParameters );
*/
static void prvLCDMessageTask( void * pvParameters );
/*
* The co-routine that reads the ADC and sends messages for display on the
* bottom row of the LCD.
*/
static void prvADCCoRoutine( CoRoutineHandle_t xHandle, unsigned portBASE_TYPE uxIndex );
/*
* Function to simply set a known value into the general purpose registers
* then read them back to ensure they remain set correctly. An incorrect value
@ -115,7 +159,7 @@ static void prvLCDMessageTask( void * pvParameters );
extern void vSetAndCheckRegisters( void );
/*
* Latch the LED that indicates that an error has occurred.
* Latch the LED that indicates that an error has occurred.
*/
void vSetErrorLED( void );
@ -139,7 +183,7 @@ typedef struct
portBASE_TYPE xRow; /*<< The row on which the message should be displayed. */
} xLCDMessage;
/* Error flag set to pdFAIL if an error is encountered in the tasks
/* Error flag set to pdFAIL if an error is encountered in the tasks/co-routines
defined within this file. */
unsigned portBASE_TYPE uxErrorStatus = pdPASS;
@ -149,7 +193,7 @@ static QueueHandle_t xLCDQueue;
/*-----------------------------------------------------------*/
/*
* Setup the hardware, create the tasks, then start the scheduler.
* Setup the hardware, create the tasks/co-routines, then start the scheduler.
*/
void main( void )
{
@ -159,15 +203,23 @@ void main( void )
/* Setup the ports used by the demo and the clock. */
prvSetupHardware();
/* Create the co-routines that flash the LED's. */
vStartFlashCoRoutines( mainNUM_FLASH_CO_ROUTINES );
/* Create the co-routine that initiates the transmission of characters
on the UART and the task that receives them, as described at the top of
this file. */
xCoRoutineCreate( vSerialTxCoRoutine, mainTX_CO_ROUTINE_PRIORITY, mainTX_CO_ROUTINE_INDEX );
xTaskCreate( vCommsRxTask, "CMS", configMINIMAL_STACK_SIZE, NULL, mainCOMMS_RX_TASK_PRIORITY, NULL );
/* Create the task that waits for messages to display on the LCD, plus the
task that sends messages for display (as described at the top
task and co-routine that send messages for display (as described at the top
of this file. */
xTaskCreate( prvLCDTask, "LCD", configMINIMAL_STACK_SIZE, ( void * ) &xLCDQueue, mainLCD_TASK_PRIORITY, NULL );
xTaskCreate( prvLCDMessageTask, "MSG", configMINIMAL_STACK_SIZE, ( void * ) &xLCDQueue, mainMSG_TASK_PRIORITY, NULL );
xCoRoutineCreate( prvADCCoRoutine, mainADC_CO_ROUTINE_PRIORITY, mainADC_CO_ROUTINE_INDEX );
/* Start the scheduler running the tasks just created. */
/* Start the scheduler running the tasks and co-routines just created. */
vTaskStartScheduler();
/* Should not get here unless we did not have enough memory to start the
@ -179,7 +231,7 @@ void main( void )
static void prvLCDMessageTask( void * pvParameters )
{
/* The strings that are written to the LCD. */
char *pcStringsToDisplay[] = {
char *pcStringsToDisplay[] = {
"IAR ",
"Stellaris ",
"Demo ",
@ -187,7 +239,7 @@ char *pcStringsToDisplay[] = {
""
};
QueueHandle_t *pxLCDQueue;
QueueHandle_t *pxLCDQueue;
xLCDMessage xMessageToSend;
portBASE_TYPE xIndex = 0;
@ -199,20 +251,20 @@ portBASE_TYPE xIndex = 0;
for( ;; )
{
/* Wait until it is time to move onto the next string. */
vTaskDelay( mainSTRING_WRITE_DELAY );
vTaskDelay( mainSTRING_WRITE_DELAY );
/* Create the message object to send to the LCD task. */
xMessageToSend.ppcMessageToDisplay = &pcStringsToDisplay[ xIndex ];
xMessageToSend.xRow = mainTOP_ROW;
/* Post the message to be displayed. */
if( !xQueueSend( *pxLCDQueue, ( void * ) &xMessageToSend, 0 ) )
{
uxErrorStatus = pdFAIL;
}
/* Move onto the next message, wrapping when necessary. */
xIndex++;
xIndex++;
if( *( pcStringsToDisplay[ xIndex ] ) == 0x00 )
{
xIndex = 0;
@ -230,7 +282,7 @@ unsigned portBASE_TYPE uxIndex;
QueueHandle_t *pxLCDQueue;
xLCDMessage xReceivedMessage;
char *pcString;
const unsigned char ucCFGData[] = {
const unsigned char ucCFGData[] = {
0x30, /* Set data bus to 8-bits. */
0x30,
0x30,
@ -239,7 +291,7 @@ const unsigned char ucCFGData[] = {
0x01, /* Display clear. */
0x06, /* Entry mode [cursor dir][shift]. */
0x0C /* Display on [display on][curson on][blinking on]. */
};
};
/* To test the parameter passing mechanism, the queue on which messages are
received is passed in as a parameter even though it is available as a file
@ -260,10 +312,10 @@ const unsigned char ucCFGData[] = {
/* Clear display. */
vTaskDelay( mainCHAR_WRITE_DELAY );
prvPDCWrite( PDC_LCD_CSR, LCD_CLEAR );
prvPDCWrite( PDC_LCD_CSR, LCD_CLEAR );
uxIndex = 0;
for( ;; )
for( ;; )
{
/* Wait for a message to arrive. */
if( xQueueReceive( *pxLCDQueue, &xReceivedMessage, portMAX_DELAY ) )
@ -273,26 +325,67 @@ const unsigned char ucCFGData[] = {
/* Where is the string we are going to display? */
pcString = *xReceivedMessage.ppcMessageToDisplay;
while( *pcString )
{
/* Don't write out the string too quickly as LCD's are usually
/* Don't write out the string too quickly as LCD's are usually
pretty slow devices. */
vTaskDelay( mainCHAR_WRITE_DELAY );
prvPDCWrite( PDC_LCD_RAM, *pcString );
pcString++;
}
}
}
}
}
/*-----------------------------------------------------------*/
static void prvADCCoRoutine( CoRoutineHandle_t xHandle, unsigned portBASE_TYPE uxIndex )
{
static unsigned long ulADCValue;
static char cMessageBuffer[ mainMAX_ADC_STRING_LEN ];
static char *pcMessage;
static xLCDMessage xMessageToSend;
/* Co-routines MUST start with a call to crSTART(). */
crSTART( xHandle );
for( ;; )
{
/* Start an ADC conversion. */
ADCProcessorTrigger( ADC_BASE, 0 );
/* Simply delay - when we unblock the result should be available */
crDELAY( xHandle, mainADC_DELAY );
/* Get the ADC result. */
ADCSequenceDataGet( ADC_BASE, 0, &ulADCValue );
/* Create a string with the result. */
sprintf( cMessageBuffer, "ADC = %d ", ulADCValue );
pcMessage = cMessageBuffer;
/* Configure the message we are going to send for display. */
xMessageToSend.ppcMessageToDisplay = ( char** ) &pcMessage;
xMessageToSend.xRow = mainBOTTOM_ROW;
/* Send the string to the LCD task for display. We are sending
on a task queue so do not have the option to block. */
if( !xQueueSend( xLCDQueue, ( void * ) &xMessageToSend, 0 ) )
{
uxErrorStatus = pdFAIL;
}
}
/* Co-routines MUST end with a call to crEND(). */
crEND();
}
/*-----------------------------------------------------------*/
static void prvSetupHardware( void )
{
/* Setup the PLL. */
SysCtlClockSet( SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_6MHZ );
/* Initialise the hardware used to talk to the LCD, LED's and UART. */
PDCInit();
vParTestInitialise();
@ -325,11 +418,17 @@ void vSetErrorLED( void )
void vApplicationIdleHook( void )
{
/* The co-routines are executed in the idle task using the idle task
hook. */
for( ;; )
{
vSetAndCheckRegisters();
/* Schedule the co-routines. */
vCoRoutineSchedule();
/* See if the comms task has found any errors. */
/* Run the register check function between each co-routine. */
vSetAndCheckRegisters();
/* See if the comms task and co-routine has found any errors. */
if( uxGetCommsStatus() != pdPASS )
{
vParTestSetLED( mainFAIL_LED, pdTRUE );