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
*----------------------------------------------------------*/
@ -54,6 +54,11 @@
#define configIDLE_SHOULD_YIELD 1
#define configUSE_MUTEXES 1
/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 1
#define configMAX_CO_ROUTINE_PRIORITIES ( 4 )
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
@ -70,7 +75,7 @@ to exclude the API function. */
/* This demo makes use of one or more example stats formatting functions. These
format the raw data provided by the uxTaskGetSystemState() function in to human
readable ASCII form. See the notes in the implementation of vTaskList() within
readable ASCII form. See the notes in the implementation of vTaskList() within
FreeRTOS/Source/tasks.c for limitations. */
#define configUSE_STATS_FORMATTING_FUNCTIONS 1

View file

@ -0,0 +1,214 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/*
* This demo application file demonstrates the use of queues to pass data
* between co-routines.
*
* N represents the number of 'fixed delay' co-routines that are created and
* is set during initialisation.
*
* N 'fixed delay' co-routines are created that just block for a fixed
* period then post the number of an LED onto a queue. Each such co-routine
* uses a different block period. A single 'flash' co-routine is also created
* that blocks on the same queue, waiting for the number of the next LED it
* should flash. Upon receiving a number it simply toggle the instructed LED
* then blocks on the queue once more. In this manner each LED from LED 0 to
* LED N-1 is caused to flash at a different rate.
*
* The 'fixed delay' co-routines are created with co-routine priority 0. The
* flash co-routine is created with co-routine priority 1. This means that
* the queue should never contain more than a single item. This is because
* posting to the queue will unblock the 'flash' co-routine, and as this has
* a priority greater than the tasks posting to the queue it is guaranteed to
* have emptied the queue and blocked once again before the queue can contain
* any more date. An error is indicated if an attempt to post data to the
* queue fails - indicating that the queue is already full.
*
*/
/* Scheduler includes. */
#include "FreeRTOS.h"
#include "croutine.h"
#include "queue.h"
/* Demo application includes. */
#include "partest.h"
#include "crflash.h"
/* The queue should only need to be of length 1. See the description at the
top of the file. */
#define crfQUEUE_LENGTH 1
#define crfFIXED_DELAY_PRIORITY 0
#define crfFLASH_PRIORITY 1
/* Only one flash co-routine is created so the index is not significant. */
#define crfFLASH_INDEX 0
/* Don't allow more than crfMAX_FLASH_TASKS 'fixed delay' co-routines to be
created. */
#define crfMAX_FLASH_TASKS 8
/* We don't want to block when posting to the queue. */
#define crfPOSTING_BLOCK_TIME 0
/* Added by MPi, this define is added in order to make the vParTestToggleLED()
work. This basically differentiates the PDR09 from PDR00. 7-seg display LEDs connected
to PDR09 (SEG1) are used by the prvFlashCoRoutine() and PDR00 (SEG2) are used by tasks. */
#define PDR00_Offset 8
/*
* The 'fixed delay' co-routine as described at the top of the file.
*/
static void prvFixedDelayCoRoutine( CoRoutineHandle_t xHandle, unsigned portBASE_TYPE uxIndex );
/*
* The 'flash' co-routine as described at the top of the file.
*/
static void prvFlashCoRoutine( CoRoutineHandle_t xHandle, unsigned portBASE_TYPE uxIndex );
/* The queue used to pass data between the 'fixed delay' co-routines and the
'flash' co-routine. */
static QueueHandle_t xFlashQueue;
/* This will be set to pdFALSE if we detect an error. */
static unsigned portBASE_TYPE uxCoRoutineFlashStatus = pdPASS;
/*-----------------------------------------------------------*/
/*
* See the header file for details.
*/
void vStartFlashCoRoutines( unsigned portBASE_TYPE uxNumberToCreate )
{
unsigned portBASE_TYPE uxIndex;
if( uxNumberToCreate > crfMAX_FLASH_TASKS )
{
uxNumberToCreate = crfMAX_FLASH_TASKS;
}
/* Create the queue used to pass data between the co-routines. */
xFlashQueue = xQueueCreate( crfQUEUE_LENGTH, sizeof( unsigned portBASE_TYPE ) );
if( xFlashQueue )
{
/* Create uxNumberToCreate 'fixed delay' co-routines. */
for( uxIndex = 0; uxIndex < uxNumberToCreate; uxIndex++ )
{
xCoRoutineCreate( prvFixedDelayCoRoutine, crfFIXED_DELAY_PRIORITY, uxIndex );
}
/* Create the 'flash' co-routine. */
xCoRoutineCreate( prvFlashCoRoutine, crfFLASH_PRIORITY, crfFLASH_INDEX );
}
}
/*-----------------------------------------------------------*/
static void prvFixedDelayCoRoutine( CoRoutineHandle_t xHandle, unsigned portBASE_TYPE uxIndex )
{
/* Even though this is a co-routine the xResult variable does not need to be
static as we do not need it to maintain its state between blocks. */
signed portBASE_TYPE xResult;
/* The uxIndex parameter of the co-routine function is used as an index into
the xFlashRates array to obtain the delay period to use. */
static const TickType_t xFlashRates[ crfMAX_FLASH_TASKS ] = { 150 / portTICK_PERIOD_MS,
200 / portTICK_PERIOD_MS,
250 / portTICK_PERIOD_MS,
300 / portTICK_PERIOD_MS,
350 / portTICK_PERIOD_MS,
400 / portTICK_PERIOD_MS,
450 / portTICK_PERIOD_MS,
500 / portTICK_PERIOD_MS };
/* Co-routines MUST start with a call to crSTART. */
crSTART( xHandle );
for( ;; )
{
/* Post our uxIndex value onto the queue. This is used as the LED to
flash. */
crQUEUE_SEND( xHandle, xFlashQueue, ( void * ) &uxIndex, crfPOSTING_BLOCK_TIME, &xResult );
if( xResult != pdPASS )
{
/* For the reasons stated at the top of the file we should always
find that we can post to the queue. If we could not then an error
has occurred. */
uxCoRoutineFlashStatus = pdFAIL;
}
crDELAY( xHandle, xFlashRates[ uxIndex ] );
}
/* Co-routines MUST end with a call to crEND. */
crEND();
}
/*-----------------------------------------------------------*/
static void prvFlashCoRoutine( CoRoutineHandle_t xHandle, unsigned portBASE_TYPE uxIndex )
{
/* Even though this is a co-routine the variable do not need to be
static as we do not need it to maintain their state between blocks. */
signed portBASE_TYPE xResult;
unsigned portBASE_TYPE uxLEDToFlash;
/* Co-routines MUST start with a call to crSTART. */
crSTART( xHandle );
( void ) uxIndex;
for( ;; )
{
/* Block to wait for the number of the LED to flash. */
crQUEUE_RECEIVE( xHandle, xFlashQueue, &uxLEDToFlash, portMAX_DELAY, &xResult );
if( xResult != pdPASS )
{
/* We would not expect to wake unless we received something. */
uxCoRoutineFlashStatus = pdFAIL;
}
else
{
/* We received the number of an LED to flash - flash it! */
/* Added by MPi, PDR00_Offset is added in order to make the
vParTestToggleLED() work. */
vParTestToggleLED( uxLEDToFlash + PDR00_Offset );
}
}
/* Co-routines MUST end with a call to crEND. */
crEND();
}
/*-----------------------------------------------------------*/
portBASE_TYPE xAreFlashCoRoutinesStillRunning( void )
{
/* Return pdPASS or pdFAIL depending on whether an error has been detected
or not. */
return uxCoRoutineFlashStatus;
}

View file

@ -77,6 +77,7 @@
#include "death.h"
#include "taskutility.h"
#include "partest.h"
#include "crflash.h"
/* Demo task priorities. */
#define mainWATCHDOG_TASK_PRIORITY ( tskIDLE_PRIORITY + 5 )
@ -100,6 +101,9 @@ LCD represent LEDs]*/
#define mainNO_ERROR_CHECK_DELAY ( ( TickType_t ) 3000 / portTICK_PERIOD_MS )
#define mainERROR_CHECK_DELAY ( ( TickType_t ) 500 / portTICK_PERIOD_MS )
/* The total number of LEDs available. */
#define mainNO_CO_ROUTINE_LEDs ( 8 )
/* The first LED used by the comtest tasks. */
#define mainCOM_TEST_LED ( 0x05 )
@ -109,6 +113,9 @@ LCD represent LEDs]*/
/* The number of interrupt levels to use. */
#define mainINTERRUPT_LEVELS ( 31 )
/* The number of 'flash' co-routines to create - each toggles a different LED. */
#define mainNUM_FLASH_CO_ROUTINES ( 8 )
/*---------------------------------------------------------------------------*/
/*
@ -162,6 +169,7 @@ void main(void)
vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );
vStartQueuePeekTasks();
vCreateBlockTimeTasks();
vStartFlashCoRoutines( mainNUM_FLASH_CO_ROUTINES );
/* Start the 'Check' task which is defined in this file. */
xTaskCreate( prvErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
@ -326,6 +334,8 @@ static void prvSetupHardware( void )
#if WATCHDOG == WTC_IN_IDLE
Kick_Watchdog();
#endif
vCoRoutineSchedule();
}
#else
#if WATCHDOG == WTC_IN_IDLE

View file

@ -53,7 +53,7 @@ void vParTestToggleLED( unsigned portBASE_TYPE uxLED )
if( uxLED < partstNUM_LEDs )
{
taskENTER_CRITICAL();
{
{
/* Toggle the state of the single genuine on board LED. */
if( sState[ uxLED ] )
{
@ -63,9 +63,9 @@ void vParTestToggleLED( unsigned portBASE_TYPE uxLED )
{
PDR25 &= ~( 1 << uxLED );
}
sState[uxLED] = !( sState[ uxLED ] );
}
}
taskEXIT_CRITICAL();
}
else
@ -73,11 +73,11 @@ void vParTestToggleLED( unsigned portBASE_TYPE uxLED )
uxLED -= partstNUM_LEDs;
if( uxLED < partstNUM_LEDs )
{
{
taskENTER_CRITICAL();
{
{
/* Toggle the state of the single genuine on board LED. */
if( sState1[uxLED])
if( sState1[uxLED])
{
PDR16 |= ( 1 << uxLED );
}
@ -85,7 +85,7 @@ void vParTestToggleLED( unsigned portBASE_TYPE uxLED )
{
PDR16 &= ~( 1 << uxLED );
}
sState1[ uxLED ] = !( sState1[ uxLED ] );
}
taskEXIT_CRITICAL();
@ -114,7 +114,7 @@ void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )
}
taskEXIT_CRITICAL();
}
else
else
{
uxLED -= partstNUM_LEDs;

View file

@ -25,9 +25,9 @@
*/
/*
* BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER.
*
/*
* BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER.
*
* This file only supports UART 2
*/
@ -43,10 +43,10 @@
#include "serial.h"
/* The queue used to hold received characters. */
static QueueHandle_t xRxedChars;
static QueueHandle_t xRxedChars;
/* The queue used to hold characters waiting transmission. */
static QueueHandle_t xCharsForTx;
static QueueHandle_t xCharsForTx;
static volatile short sTHREEmpty;
@ -62,7 +62,7 @@ xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned port
/* Initialize UART asynchronous mode */
BGR02 = configPER_CLOCK_HZ / ulWantedBaud;
SCR02 = 0x17; /* 8N1 */
SMR02 = 0x0d; /* enable SOT3, Reset, normal mode */
SSR02 = 0x02; /* LSB first, enable receive interrupts */
@ -73,7 +73,7 @@ xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned port
EPFR20_D1 = 0; /* enable UART */
}
portEXIT_CRITICAL();
/* Unlike other ports, this serial code does not allow for more than one
com port. We therefore don't return a pointer to a port structure and can
instead just return NULL. */
@ -105,7 +105,7 @@ signed portBASE_TYPE xReturn;
{
if( sTHREEmpty == pdTRUE )
{
/* If sTHREEmpty is true then the UART Tx ISR has indicated that
/* If sTHREEmpty is true then the UART Tx ISR has indicated that
there are no characters queued to be transmitted - so we can
write the character directly to the shift Tx register. */
sTHREEmpty = pdFALSE;
@ -115,10 +115,10 @@ signed portBASE_TYPE xReturn;
else
{
/* sTHREEmpty is false, so there are still characters waiting to be
transmitted. We have to queue this character so it gets
transmitted. We have to queue this character so it gets
transmitted in turn. */
/* Return false if after the block time there is no room on the Tx
/* Return false if after the block time there is no room on the Tx
queue. It is ok to block inside a critical section as each task
maintains it's own critical section status. */
if (xQueueSend( xCharsForTx, &cOutChar, xBlockTime ) == pdTRUE)
@ -130,7 +130,7 @@ signed portBASE_TYPE xReturn;
xReturn = pdFAIL;
}
}
if (pdPASS == xReturn)
{
/* Turn on the Tx interrupt so the ISR will remove the character from the
@ -139,7 +139,7 @@ signed portBASE_TYPE xReturn;
will simply turn off the Tx interrupt again. */
SSR02_TIE = 1;
}
}
portEXIT_CRITICAL();
@ -155,7 +155,7 @@ signed portBASE_TYPE xReturn;
signed char cChar;
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
/* Get the character from the UART and post it on the queue of Rxed
/* Get the character from the UART and post it on the queue of Rxed
characters. */
cChar = RDR02;
@ -163,8 +163,8 @@ signed portBASE_TYPE xReturn;
if( xHigherPriorityTaskWoken )
{
/*If the post causes a task to wake force a context switch
as the woken task may have a higher priority than the task we have
/*If the post causes a task to wake force a context switch
as the woken task may have a higher priority than the task we have
interrupted. */
portYIELD_FROM_ISR();
}
@ -191,7 +191,7 @@ __interrupt void UART2_TxISR (void)
{
/* There were no other characters to transmit. */
sTHREEmpty = pdTRUE;
/* Disable transmit interrupts */
SSR02_TIE = 0;
}