task.h
BaseType_t xTaskNotifyFromISR( TaskHandle_t xTaskToNotify,
uint32_t ulValue,
eNotifyAction eAction,
BaseType_t *pxHigherPriorityTaskWoken );
[If you are using RTOS task notifications to implement binary or counting
semaphore type behaviour then use the simpler
vTaskNotifyGiveFromISR() API
function instead of xTaskNotifyFromISR()]
A version of xTaskNotify() that can be called
from an ISR.
Each RTOS task has a 32-bit notification value which is initialised to
zero when the RTOS task is created. xTaskNotifyFromISR() is used to send an event
directly to and potentially unblock an RTOS task, and optionally update the
receiving task's notification value in one of the following ways:
-
Write a 32-bit number to the notification value
-
Add one (increment) the notification value
-
Set one or more bits in the notification value
-
Leave the notification value unchanged
-
Parameters:
-
xTaskToNotify
|
The handle of the RTOS task being notified. This is the subject task.
To obtain a task's handle create the task using
xTaskCreate() and make use of the
pxCreatedTask parameter, or create the task using
xTaskCreateStatic()
and store the returned value, or use the task's name in a
call to xTaskGetHandle().
The handle of the currently executing RTOS task is returned by
the xTaskGetCurrentTaskHandle()
API function.
|
ulValue
|
Used to update the notification value of the subject task.
See the description of the eAction parameter below.
|
eAction
|
An enumerated type that can take one of the values documented
in the table below in order to perform the associated action.
|
pxHigherPriorityTaskWoken
|
*pxHigherPriorityTaskWoken must be initialised to 0.
xTaskNotifyFromISR() will set *pxHigherPriorityTaskWoken to
pdTRUE if sending the notification caused a task to unblock,
and the unblocked task has a priority higher than the
currently running task.
If xTaskNotifyFromISR() sets this value to pdTRUE then a
context switch should be requested before the interrupt is
exited. See the example below.
pxHigherPriorityTaskWoken is an optional parameter and can
be set to NULL.
|
eAction Setting
|
Action Performed
|
eNoAction
|
The subject task receives the event, but its
notification value is not updated.
In this case ulValue is not used.
|
eSetBits
|
The notification value of the subject task will
be bitwise ORed with ulValue. For example, if
ulValue is set to 0x01, then bit 0 will get set
within the subject task's notification value.
Likewise if ulValue is 0x04 then bit 2 will get
set in the subject task's notification value.
In this way the RTOS task notification mechanism can be used
as a light weight alternative to an
event group.
|
eIncrement
|
The notification value of the subject task will
be incremented by one, making the call to xTaskNotifyFromISR()
equivalent to a call to vTaskNotifyGiveFromISR().
In this case ulValue is not used.
|
eSetValueWithOverwrite
|
The notification value of the subject task is
unconditionally set to ulValue. In this way the
RTOS task notification mechanism is being used as a light
weight alternative to xQueueOverwrite().
|
eSetValueWithoutOverwrite
|
If the subject task does not already have a
notification pending then its notification value
will be set to ulValue.
If the subject task already has a notification
pending then its notification value is not
updated as to do so would overwrite the previous
value before it was used. In this case the call
to xTaskNotify() fails.
In this way the RTOS task notification mechanism
is being used as a light weight alternative to
xQueueSend() on a
queue of length 1.
|
-
Returns:
-
pdPASS is returned in all cases other than when eAction is set to
eSetValueWithoutOverwrite and the subject task's notification value
cannot be updated because the subject task already had a notification
pending.
Example usage:
[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.
|