Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 7. More Operating System Services

Similar presentations


Presentation on theme: "Chapter 7. More Operating System Services"— Presentation transcript:

1 Chapter 7. More Operating System Services
The other features offered by commercial RTOSs.

2 Contents Message Queues, Mailboxes and Pipes Timer Functions Events
Memory Management Interrupt Routines in an RTOS Environment

3 Message Queues, Mailboxes and Pipes
Task must be able to communicate with one another to coordinate their activities or to share data. queues, mailboxes, and pipes

4 Message Queues, Mailboxes and Pipes
void Task1(void) { if (!!problem arises) vLogError(ERROR_TYPE_X); !! Other things that need to be done soon. } void Task2(void) vLogError(ERROR_TYPE_Y); void vLogError(int iErrorType) { AddToQueue(iErrorType); } static int cErrors; void ErrorTask(void) int iErrorType; while(FOREVER) ReadFromQueue(&iErrorType); ++cErrors; !! Send cErrors and iErrorType out on network task1 과 task2가 각각 실행 , 로그에러를 만나면 vLogError에 에러처리를 부탁하고 각자 자신의 task를 수행 각자가 에러를 받아서 처리하고 다시 돌아와 실행하는 것 줄임 vLogError , errortype 받아서 큐에 넣음 ErrorTask 계속 루프돌면서 큐로부터 ErrorType을 인자로 에러형태 찾음

5 Details with Message Queues
Initialize your queues before using queue. Have as many queues as you want the identity of the queue When queue is full, the RTOS must return an error block 주체는 RTOS임 m q 사용 전에 initialize가 필요 원하는 만큼 q를 사용가능 구별하기 위해 identity ---

6 Details with Message Queues
A function that will read from a queue if there is any data and will return error code and block if not. Write onto a queue the number of bytes taken up by a void pointer void 포인터를 써서 수 바이트를 q에 쓸 수 있는데 다음에 알아봄

7 Pointer and Queues Casting the data as a void pointer
One task can pass data to one other task Put the data into buffer And write a pointer to the buffer onto queue data를 void 포인터로 캐스트해서 수바이트를 큐에 더할 수 있음 한 task가 다른 task에 데이터를 전달하는 방법에 ---

8 Pointer and Queues Fig. 7.2 More Realistic Use of a Queue
void *apvQueue[SIZEOF_QUEUE]; void main(void) { pOseQueue = OSQCreate(apvQueue, SIZEOF_QUEUE); !!Start Task1 !!Start Task2 } void Task1(void) { void Task2(void) { void vLogError(int iErrorType) { byReturn = OSQPost(pOseQueue, (void*)iErorType); } void ErrorTask(void) { while(FOREVER) iErrorType = (int) OSQPend(pOseQueue, WAIT_FOREVER, &byErr); OSQCreate()는 큐를 생성 post는 큐에 에러를 추가함 pend는 큐에서 에러타입을 인자로 에러값을 얻음 ErrorType은 int형임 OSQCreate() apvQueue 큐를 배열로 선언, SIZEO_QUEUE는 25 OSQPost(), *OSQCreate()가 포인터 함수이고 함수의 포인터가 pOseQueue iErrorType을 void *형으로 cast해서 전달. OSQPend(). pOseQueue : identify of queue , byErr는 일단 ignore Fig. 7.2 More Realistic Use of a Queue

9 Pointer and Queues Fig. 7.3 Passing Pointer on Queues
void vMainTask(void) { int *pTemperatures; BYTE byErr; while(TRUE) pTemperatures = (int*)OSQPend(pOseQueueTemp, WAIT_FOREVER, &byErr); if (pTemperatures[0] != pTemperatures[1]) !! Set Off howling alarm; } static OS_EVENT *pOseQueueTemp; void vReadTemperaturesTask(void) { int *pTemperatures; While(TRUE) { pTemperatures = (int*)malloc(2*sizeof*pTemperatures); pTemperatures[0] = pTemperatures[1] = OSQPost(pOseQueueTemp, (void*)pTemperatures); } 앞의 예제는 메시지 큐를 에러를 저장해서 처리하는 것, 이 예제는 vReadTemperatureTask에서 pTemperatures[] 값을 하드웨어에서 읽어옴 큐에 저장 vMainTask()에서 큐로부터 temp값을 읽어와서 비교함 각 sub가 task1, 2등에 의해 실행될 수 있음 Fig Passing Pointer on Queues

10 Mailboxes Much like queues. RTOS can
Create, write ,check and read from mail boxes. The number of messages in a mailbox is limited. User can prioritize mailbox messages. MultiTask! sndmsg, rcvmsg, chkmsg

11 Pipes Much like queues. RTOS can Byte-oriented. Use fread(), fwrite()
Create, write ,check and read from pipes. Byte-oriented. Use fread(), fwrite() 데이터 처리 단위가 바이트임 몇 RTOS는 Pipe를 읽고 쓰는데 fread(), fwrite() 제공하기도 함

12 Which should I use? Trade-offs among
Flexibility, speed, memory space, disabled interrupt time length Refer to documents

13 Pitfalls Passing Pointers through a queue may create shared data bugs
void vReadTemperaturesTask(void) { int *pTemperatures; While(TRUE) { pTemperatures = (int*)malloc(2*sizeof*pTemperatures); pTemperatures[0] = pTemperatures[1] = OSQPost(pOseQueueTemp, (void*)pTemperatures); } void vReadTemperaturesTask(void) { int iTemperatures[2]; While(TRUE) { iTemperatures[0] = iTemperatures[1] = OSQPost(pOseQueueTemp, (void*)iTemperatures); } 각 switchin이 화살표에 일어났을때 앞의 것은 매번 pTemperature포인터를 지정받아서 사용함 뒤의 것은 메모리상의 iTemperatures의 위치가 같음 뒤에 값비교시에 뒤의 것은 같은 buffer위치를 가리켜서 shared data bugs가능성이 있음

14 Timer Functions Must Keep track of the passage of time
Offer taskDelay() functions. void vMakePhoneCallTask(void) { taskDelay(100); vDialingToneOn(*p_chPhoneNumber –’0’); vDialingToneOff(); } 짐작 *p_chPhoneNumber –’0’는 숫자의 거리를 인자로 다른 주파수의 소릴 냄 taskDelay()를 볼 수 있고 100은 system ticks를 말함

15 Events Procedure More than task can block waiting The events occurs The RTOS will unblock all of tasks Form group of events and any subset of events within the group Need to reset events automatically or manually events의 과정 group구성가능하고 그룹 안의 복수 개 event를 처리가능 예:task가 group안의 복수 개 event를 기다림 reset

16 Comparison for Intertask Comm.
Semaphore : the fastest and simplest not much information Events : more complicated than semapohre can wait several events at the same time take more CPU time Queues : much information CPU-intensive, bugs-opportunity.

17 Memory Management Avoid malloc and free function
Slow and unpredictable Use the functions that allocate and free fixed-size buffers. Predictable At MultiTask! system void *getbuf(PoolID, timeout); void *reqbuf(PoolID); void reluf(PoolID, *p_vBuffer); task block의 가능성 Pool은 buffer들의 집합이고 여러 개의 Pool을 정의가능 memory buffer full 일 때 getbuf는 buffer가 빌때까지 block함 reqbuf는 null pointer return relbuf는 p_vBuffer가 가리키는 해당 pool를 free함

18 Interrupt Routines in an RTOS Environment
Interrupt Routines must not call any RTOS functions that- Might block the caller. Might cause the RTOS to switching tasks without fair warning 큰 원리 : interrupt routine은 항상 수행이 완료되어서 next int.를 기다릴 수 있어야 함 task int rot RTOS func. block int rot. block task. block – high prioirity task 라도 task가 int rot수행중인 것을 모르고 int rout에서 다른 task로 control 를 옮기면 int rout가 완료되지 않게 되고 low prioriy int 혹 전채 int가 block되는것.

19 Interrupt Routines in an RTOS Environment
정상적인 int rout과정이고 ISR : int service rout. task low에서 int가 걸림 int가 send msg to mailbox의 func호출 또다른 함수 호출 isr이 완료하면 RTOS가 우선순위 높은 task혹은 낮은 task로 돌아가게 함 Fig How Interrupt Routines Should Work

20 Interrupt Routines in an RTOS Environment
문제가 있는 int rout과정 이전에 mailbox에 higher-prioirty task가 block되어 있다고 가정 tasklow 에서 int rout가 걸리고 RTOS function이 실행뒤에 higher priority task이 unblock되어서 실행 int rout가 완료되지 못함 전체 block Fig What Would Really Happen

21 Interrupt Routines in an RTOS Environment
The RTOS intercepts all the interrupts and then call your interrupt routine. RTOS가 all int rout를 가로막은뒤에 int rout를 수행 call return구간에는 int 구간임을 앎 도중에 hightask로 빠지지 않음 Fig How Interrupt Routines Do Work

22 Interrupt Routines in an RTOS Environment
Disabling the scheduler for the duration of the interrupt routine. ISR이 int rout가 시작된 것을 RTOS에게 알려주는 function을 실행 func , RTOS가 제공 뒤에 scheduler로 jump or call하는 함수 호출 Fig How Interrupt Routines Do Work:Plan B

23 Interrupt Routines in an RTOS Environment
A separate set of functions for interrupt routines specially OSSemPost OSISRSemPost for interrupt routines int rout도중에 other task로 switch되지 않고 항상 isr로 돌아오는 함수사용

24 Nested Interrupts The RTOS must know
when the lower-priority interrupt routine. low priority int rout도중에 high int rout가 걸리면 역시 RTOS가 low int rout수행중인 것을 알고 다시 low int rout로 돌아와야 함 그렇지 않으면 high int끝내고 taskhigh로 switch가능성 Fig Nested Interrupts and the RTOS


Download ppt "Chapter 7. More Operating System Services"

Similar presentations


Ads by Google