Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Include Page
css.Message Passing.css
css.Message Passing.css
Include Page
css.webworks.css
css.webworks.css

Anchor
1048410
1048410
Message Passing

Anchor
1059871
1059871
It is sometimes necessary for a task or an ISR to communicate information to another task. This information transfer is called inter-task communication. Information can be communicated between tasks in two ways: through global data, or by sending messages.

Anchor
1059873
1059873
As seen in Chapter 13, “Resource Management” on page 211, when using global variables, each task or ISR must ensure that it has exclusive access to variables. If an ISR is involved, the only way to ensure exclusive access to common variables is to disable interrupts. If two tasks share data, each can gain exclusive access to variables either by disabling interrupts, locking the scheduler, using a semaphore, or preferably, using a mutual-exclusion semaphore. Note that a task can only communicate information to an ISR by using global variables. A task is not aware when a global variable is changed by an ISR, unless the ISR signals the task, or the task polls the contents of a variable periodically.

Anchor
1059874
1059874
Messages can either be sent to an intermediate object called a message queue, or directly to a task since in µC/OS-III, each task has its own built-in message queue. You can use an external message queue if multiple tasks are to wait for messages. You would send a message directly to a task if only one task will process the data received.

Anchor
1059875
1059875
When a task waits for a message to arrive, it does not consume CPU time.