static void prvHookCoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex ) { static UBaseType_t uxReceivedValue[ hookNUM_HOOK_CO_ROUTINES ]; BaseType_t xResult; /* Each co-routine MUST start with a call to crSTART(); */ crSTART( xHandle ); for( ;; ) { /* Wait to receive a value from the tick hook. */ xResult = pdFAIL; crQUEUE_RECEIVE( xHandle, xHookTxQueues[ uxIndex ], &( uxReceivedValue[ uxIndex ] ), portMAX_DELAY, &xResult ); /* There is no reason why we should not have received something on the queue. */ if( xResult != pdPASS ) { xCoRoutineErrorDetected = pdTRUE; } /* Send the same number back to the idle hook so it can verify it. */ xResult = pdFAIL; crQUEUE_SEND( xHandle, xHookRxQueues[ uxIndex ], &( uxReceivedValue[ uxIndex ] ), hookNO_BLOCK_TIME, &xResult ); if( xResult != pdPASS ) { /* There is no reason why we should not have been able to post to the queue. */ xCoRoutineErrorDetected = pdTRUE; } } /* Each co-routine MUST end with a call to crEND(). */ crEND(); }
static void vI2CCoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex ) { portTickType xADCResult; static portBASE_TYPE xResult = 0, xMilliSecs, xLED; crSTART( xHandle ); for( ;; ) { /* Start the I2C off to read the ADC. */ uxState = mainI2C_READ_1; I2CMasterSlaveAddrSet( I2C_MASTER_BASE, mainI2CAddress, pdTRUE ); I2CMasterControl( I2C_MASTER_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START ); /* Wait to receive the conversion result. */ crQUEUE_RECEIVE( xHandle, xADCQueue, &xADCResult, portMAX_DELAY, &xResult ); /* Scale the result to give a useful range of values for a visual demo. */ xADCResult >>= 2; xMilliSecs = xADCResult / portTICK_RATE_MS; /* The delay is split between the four co-routines so they remain in synch. */ uxDelay = xMilliSecs / ( mainNUM_LEDs + 1 ); /* Trigger each of the flash co-routines. */ for( xLED = 0; xLED < mainNUM_LEDs; xLED++ ) { crQUEUE_SEND( xHandle, xDelayQueue, &xLED, 0, &xResult ); } /* Wait for the full delay time then start again. This delay is long enough to ensure the flash co-routines have done their thing and gone back to sleep. */ crDELAY( xHandle, xMilliSecs ); } crEND(); }
static void prvFixedDelayCoRoutine( xCoRoutineHandle 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 portTickType xFlashRates[ crfMAX_FLASH_TASKS ] = { 150 / portTICK_RATE_MS, 200 / portTICK_RATE_MS, 250 / portTICK_RATE_MS, 300 / portTICK_RATE_MS, 350 / portTICK_RATE_MS, 400 / portTICK_RATE_MS, 450 / portTICK_RATE_MS, 500 / portTICK_RATE_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. */ xCoRoutineFlashStatus = pdFAIL; } crDELAY( xHandle, xFlashRates[ uxIndex ] ); } /* Co-routines MUST end with a call to crEND. */ crEND(); }