// A co-routine that blocks on a queue waiting for characters to be received. static void vReceivingCoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex ) { char cRxedChar; BaseType_t xResult; // All co-routines must start with a call to crSTART(). crSTART( xHandle ); for( ;; ) { // Wait for data to become available on the queue. This assumes the // queue xCommsRxQueue has already been created! crQUEUE_RECEIVE( xHandle, xCommsRxQueue, &uxLEDToFlash, portMAX_DELAY, &xResult ); // Was a character received? if( xResult == pdPASS ) { // Process the character here. } } // All co-routines must end with a call to crEND(). crEND(); } // An ISR that uses a queue to send characters received on a serial port to // a co-routine. void vUART_ISR( void ) { char cRxedChar; BaseType_t xCRWokenByPost = pdFALSE; // We loop around reading characters until there are none left in the UART. while( UART_RX_REG_NOT_EMPTY() ) { // Obtain the character from the UART. cRxedChar = UART_RX_REG; // Post the character onto a queue. xCRWokenByPost will be pdFALSE // the first time around the loop. If the post causes a co-routine // to be woken (unblocked) then xCRWokenByPost will be set to pdTRUE. // In this manner we can ensure that if more than one co-routine is // blocked on the queue only one is woken by this ISR no matter how // many characters are posted to the queue. xCRWokenByPost = crQUEUE_SEND_FROM_ISR( xCommsRxQueue, &cRxedChar, xCRWokenByPost ); } }
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|
Latest News
NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS. Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019 Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed. View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS. Careers
FreeRTOS and other embedded software careers at AWS. FreeRTOS Partners
|