# Sending to a message buffer AND notifying a task

**URL:** <https://forums.freertos.org/t/sending-to-a-message-buffer-and-notifying-a-task/7352>\
**Category:** Kernel\
**Created:** [August 2, 2018, 2:12pm UTC](https://forums.freertos.org/t/sending-to-a-message-buffer-and-notifying-a-task/7352 "2018-08-02T14:12:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [August 2, 2018, 2:12pm UTC](https://forums.freertos.org/t/sending-to-a-message-buffer-and-notifying-a-task/7352/1 "2018-08-02T14:12:42Z")

</div>

**[nathanolacti](https://sourceforge.net/u/nathanolacti/)** wrote on [Thursday, August 02, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/315443f9/#2641):

Hi,

I am developing a software on a Cortex-M0.  
Each task of the system usualy wait on their notification value.  
When a hardware interrupt occures, I send a message to a message buffer through xMessageBufferSendFromISR and then wake the task using xTaskNotifyFromISR.  
As I am calling two FromISR functions I am not really sure how to handle their pxHigherPriorityTaskWoken parameters.

Should I initialize it to pdFALSE, call xMessageBufferSendFromISR, portYIELD and then initialize it again, call xTaskNotifyFromISR and portYIELD ? or just initialize it once and call portYIELD each time ? or event call portYIELD only at the end ?

Regards,  
Nathan O.

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [August 2, 2018, 3:19pm UTC](https://forums.freertos.org/t/sending-to-a-message-buffer-and-notifying-a-task/7352/2 "2018-08-02T15:19:38Z")

</div>

**[heinbali01](https://sourceforge.net/u/heinbali01/)** wrote on [Thursday, August 02, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/315443f9/#cdd0):

> As I am calling two FromISR functions I am not really sure how to handle their  
> pxHigherPriorityTaskWoken parameters.

As simple as this:

```auto
    void myISR()
    {
    BaseType_t xHigherPriorityTaskWoken = pdFALSE;
    
        xMessageBufferSendFromISR( xMessageBuffer, pvTxData, xDataLengthBytes, &xHigherPriorityTaskWoken );
        xTaskNotifyFromISR( xTask, ulValue, eSetBits, &xHigherPriorityTaskWoken );
        portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
    }

```

The two fromISR functions **may** set the variable `xHigherPriorityTaskWoken`. Once set, it won’t be cleared by a next function.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [August 10, 2018, 7:30am UTC](https://forums.freertos.org/t/sending-to-a-message-buffer-and-notifying-a-task/7352/3 "2018-08-10T07:30:48Z")

</div>

**[nathanolacti](https://sourceforge.net/u/nathanolacti/)** wrote on [Friday, August 10, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/315443f9/#dcb8):

Thank you very much for your answer. I will update my code accordingly.
