[More examples are referenced from the main RTOS task notifications page] /* This is an example of a transmit function in a generic peripheral driver. An RTOS task calls the transmit function, then waits in the Blocked state (so not using an CPU time) until it is notified that the transmission is complete. The transmission is performed by a DMA, and the DMA end interrupt is used to notify the task. */ static TaskHandle_t xTaskToNotify = NULL; /* The peripheral driver's transmit function. */ void StartTransmission( uint8_t *pcData, size_t xDataLength ) { /* At this point xTaskToNotify should be NULL as no transmission is in progress. A mutex can be used to guard access to the peripheral if necessary. */ configASSERT( xTaskToNotify == NULL ); /* Store the handle of the calling task. */ xTaskToNotify = xTaskGetCurrentTaskHandle(); /* Start the transmission - an interrupt is generated when the transmission is complete. */ vStartTransmit( pcData, xDatalength ); } /*-----------------------------------------------------------*/ /* The transmit end interrupt. */ void vTransmitEndISR( void ) { BaseType_t xHigherPriorityTaskWoken = pdFALSE; /* At this point xTaskToNotify should not be NULL as a transmission was in progress. */ configASSERT( xTaskToNotify != NULL ); /* Notify the task that the transmission is complete. */ vTaskNotifyGiveFromISR( xTaskToNotify, &xHigherPriorityTaskWoken ); /* There are no transmissions in progress, so no tasks to notify. */ xTaskToNotify = NULL; /* If xHigherPriorityTaskWoken is now set to pdTRUE then a context switch should be performed to ensure the interrupt returns directly to the highest priority task. The macro used for this purpose is dependent on the port in use and may be called portEND_SWITCHING_ISR(). */ portYIELD_FROM_ISR( xHigherPriorityTaskWoken ); } /*-----------------------------------------------------------*/ /* The task that initiates the transmission, then enters the Blocked state (so not consuming any CPU time) to wait for it to complete. */ void vAFunctionCalledFromATask( uint8_t ucDataToTransmit, size_t xDataLength ) { uint32_t ulNotificationValue; const TickType_t xMaxBlockTime = pdMS_TO_TICKS( 200 ); /* Start the transmission by calling the function shown above. */ StartTransmission( ucDataToTransmit, xDataLength ); /* Wait for the transmission to complete. */ ulNotificationValue = ulTaskNotifyTake( pdFALSE, xMaxBlockTime ); if( ulNotificationValue == 1 ) { /* The transmission ended as expected. */ } else { /* The call to ulTaskNotifyTake() timed out. */ } }
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
|