[More examples are referenced from the main RTOS task notifications page] This example demonstrates how to use xTaskNotifyFromISR() with the eSetBits action. See the xTaskNotify() API documentation page for examples showing how to use the eNoAction, eSetValueWithOverwrite and eSetValueWithoutOverwrite actions. /* The interrupt handler does not perform any processing itself. Instead it it unblocks a high priority task in which the events that generated the interrupt are processed. If the priority of the task is high enough then the interrupt will return directly to the task (so it will interrupt one task but return to a different task), so the processing will occur contiguously in time - just as if all the processing had been done in the interrupt handler itself. The status of the interrupting peripheral is sent to the task using an RTOS task notification. */ void vANInterruptHandler( void ) { BaseType_t xHigherPriorityTaskWoken; uint32_t ulStatusRegister; /* Read the interrupt status register which has a bit for each interrupt source (for example, maybe an Rx bit, a Tx bit, a buffer overrun bit, etc. */ ulStatusRegister = ulReadPeripheralInterruptStatus(); /* Clear the interrupts. */ vClearPeripheralInterruptStatus( ulStatusRegister ); /* xHigherPriorityTaskWoken must be initialised to pdFALSE. If calling xTaskNotifyFromISR() unblocks the handling task, and the priority of the handling task is higher than the priority of the currently running task, then xHigherPriorityTaskWoken will automatically get set to pdTRUE. */ xHigherPriorityTaskWoken = pdFALSE; /* Unblock the handling task so the task can perform any processing necessitated by the interrupt. xHandlingTask is the task's handle, which was obtained when the task was created. The handling task's notification value is bitwise ORed with the interrupt status - ensuring bits that are already set are not overwritten. */ xTaskNotifyFromISR( xHandlingTask, ulStatusRegister, eSetBits, &xHigherPriorityTaskWoken ); /* Force a context switch if xHigherPriorityTaskWoken is now set to pdTRUE. The macro used to do this is dependent on the port and may be called portEND_SWITCHING_ISR. */ portYIELD_FROM_ISR( xHigherPriorityTaskWoken ); } /* ----------------------------------------------------------- */ /* A task that blocks waiting to be notified that the peripheral needs servicing, processing all the events pending in the peripheral each time it is notified to do so. */ void vHandlingTask( void *pvParameters ) { uint32_t ulInterruptStatus; for( ;; ) { /* Block indefinitely (without a timeout, so no need to check the function's return value) to wait for a notification. NOTE! Real applications should not block indefinitely, but instead time out occasionally in order to handle error conditions that may prevent the interrupt from sending any more notifications. */ xTaskNotifyWait( 0x00, /* Don't clear any bits on entry. */ ULONG_MAX, /* Clear all bits on exit. */ &ulInterruptStatus, /* Receives the notification value. */ portMAX_DELAY ); /* Block indefinitely. */ /* Process any bits set in the received notification value. This assumes the peripheral sets bit 1 for an Rx interrupt, bit 2 for a Tx interrupt, and bit 3 for a buffer overrun interrupt. */ if( ( ulInterruptStatus & 0x01 ) != 0x00 ) { prvProcessRxInterrupt(); } if( ( ulInterruptStatus & 0x02 ) != 0x00 ) { prvProcessTxInterrupt(); } if( ( ulInterruptStatus & 0x04 ) != 0x00 ) { prvClearBufferOverrun(); } } }
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
|