11.07.2015 Views

IAR PowerPac RTOS User Guide

IAR PowerPac RTOS User Guide

IAR PowerPac RTOS User Guide

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

ExampleThe task that handles the serial input and the keyboard waits for a character to be received either via the keyboard(EVENT_KEYPRESSED) or serial interface (EVENT_SERIN):/** Just a small demo for events*/#define EVENT_KEYPRESSED (1)#define EVENT_SERIN (2)OS_STACKPTR int Stack0[96], Stack1[64]; /* Task stacks */OS_TASK TCB0, TCB1; /* Data area for tasks (task control blocks) */void Task0(void) {OS_U8 MyEvent;while(1)MyEvent = OS_WaitEvent(EVENT_KEYPRESSED | EVENT_SERIN)if (MyEvent & EVENT_KEYPRESSED) {/* handle key press */}if (MyEvent & EVENT_SERIN) {/* Handle serial reception */}}}void TimerKey(void) {/* More code to find out if key has been pressed */OS_SignalEvent(EVENT_SERIN, &TCB0); /* Notify Task that key was pressed */}void InitTask(void) {OS_CREATETASK(&TCB0, 0, Task0, 100, Stack0); /* Create Task0 */}If the task was only waiting for a key to be pressed, OS_GetMail() could simply be called. The task would then bedeactivated until a key is pressed. If the task has to handle multiple mailboxes, as in this case, events are a good option.OS_GetEventsOccurred()DescriptionReturns a list of events that have occurred for a specified task.Prototypechar OS_GetEventsOccurred (OS_TASK* pTask);ParameterDescriptionpTaskTable 87: OS_getEventsOccured() parameter listReturn valueThe event mask of the events that have actually occurred.Additional InformationBy calling this function, the actual events remain signaled. The event memory is not cleared. This is one way for a taskto find out which events have been signaled. The task is not suspended if no events are available.OS_ClearEvents()DescriptionThe task who's event mask is to be returned,NULL means current task.Returns the actual state of events and then clears the events of a specified task.80<strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong>for ARM CoresPP<strong>RTOS</strong>-2

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!