Sie sind auf Seite 1von 18

Embedded Systems

Unit V RTOS & Case Studies

Prepared by Prof. N.Shanmugasundaram, Head, ECE Department Vidyaa Vikas College of Engg & Technology

Need for Tested RTOS

While designing a complex embedded systems, we need a tested bug free codes for the following.
Multiple task functions in C or C++. Real time clock based software timers (RTCSWT). Software for Co-operative scheduler. Software for a Pre-emptive scheduler. Device drivers and Device managers. Functions for Inter Process Communications. Network functions Error handling functions and exception handling functions. Testing and System debugging software.

A readily available RTOS package provides the above functions and a lot of time is saved for coding the same.

Options in RTOS

Options for RTOS


Linux Based RTOS


PSoS VxWorks Nucleus Win CE Palm OS

Use of RTOS - C/OS-II

The C/OS-II is a freeware RTOS, available for Non-commercial use. C/OS-II codes are in C and few CPU specific modules are written in assembly. It supports many CPU that are used in embedded systems. MUCOS is a scalable OS. It employs Pre-emptive scheduler for multitasking. MUCOS has system level functions. MUCOS has task service functions and task delay functions. MUCOS has IPC functions and Memory related functions. MUCOS has Mailbox, Queue, Semaphore related functions.

RTOS System level functions

The System level functions are

void OSInit (void) void OSStart (void) void OSTickInit (void) void OSIntEnter (void) Void OSIntExit (void) OS_ENTER_CRITICAL At the beginning prior to OSStart() After OSInit() and task creating functions To initialize System timer ticks Just after the start of ISR codes before return form the ISR codes Macro to disable all interrupts


Macro to enable all interrupts

Task Service functions

These functions are used to create task, suspend and resume, and time setting and retrieving functions.

unsigned byte OSTaskCreate () unsigned byte OSTaskSuspend (..) unsigned byte OSTaskResume (..) void OSTimeset (..) Unsigned int OSTimeGet (void)

Must call before running a task Called for blocking a task Called for resuming a blocked task When system time is to be set Find present count when time is read

Time Delay functions

MUCOS Time delay functions for the tasks are

void OSTimeDly () unsigned byte OSTimeDlyResume () void OSTimeDlyHMSM () To delay a task by count-1 value To resume a task after a preset delay Time delay to block a task

Memory related functions

MUCOS memory related functions for the tasks are

OSMem *OSMemCreate () void *OSMemGet (..) unsigned byte OSMemQuery (..) unsigned byte OSMemPut () To create and initialize memory partition To find the pointer of memory control block To find pointers of memory blocks and data structures To return a pointer of memory block

Semaphore related functions

When a semaphore created by OS and used a resource acquiring key, it must be initialized with 1 to indicate the resource is available. MUCOS Semaphore related functions for the tasks are

OS_Event OSSemCreate () void OSSemPend (..) unsigned short OSSemAccept (..) unsigned byte OSSemPost () unsigned byte OSSemQuery ()

To create and initialize a semaphore To check whether a semaphore is pending To check whether SemVal > 0 If SemVal = 0 or more, increments, and makes a semaphore again not pending. To get semaphore information

Other functions

Apart from the previous said functions, MUCOS has functions related to

Mailbox Queue

Case Study:

Automatic Chocolate Vending Machine (ACVM)

Automatic Chocolate Vending Machine (ACVM)

System Requirement: ACVM has a slot for inserting coins and chocolate is delivered if correct change is deposited (eg. Say Rs.8/-). When coins are inserted, a mechanical system directs the coins to appropriate port ie., port_1, port_2 & port_5. LCD display acts as User interface. (port_display) Buyer collects the chocolate at bowl from chocolate channel through a port (port_deliver). port_refund return the coins if inserted in shortage. port_excessrefund returns the excess coins.

Automatic Chocolate Vending Machine (ACVM)

System Requirement (contd..): RTOS has to schedule the process from start to finish. It should also be possible to re-program the codes, whenever the following happens: - the price of chocolate increases. - the message lines need to be changed - the machine feature change

Automatic Chocolate Vending Machine (ACVM)

Automatic Chocolate Vending Machine (ACVM)

Tasks Involved:
Waits for Coins & Action as per coins collected Collect coins >= cost, wait till timeout Deliver the chocolate Refund coins, if coins are inserted in shortage Refund coins, if coins are inserted in excess Display the present operation & status Updates the display of Time & date in 3rd line of the LCD display

1 2 3 4 5 6 7

Task_ReadPorts Task_Collect Task_Deliver Task_Refund Task_ExcessRefund Task_Display Task_TimeDateDisplay

Automatic Chocolate Vending Machine (ACVM)

Automatic Chocolate Vending Machine (ACVM)

Task_ReadPorts start action only when semaphore SemFinish is reset / posted by Task_Deliver, Task_Refund or Task_ExcessRefund. Tasks wait for events from port_1, port_2 & port_5. Task then counts SemAmtCount. the amount by posting to semaphore

It posts an event flag SemFlag1 to Task_Collect for collecting the amount greater or equal to the chocolate cost. This in turn, posts SemFlag2 to Task_Refund or SemFlag3 to Task_ExcessRefund, if the coins are insufficient or excess. SemFlag4 is posted to Task_Display for displaying coins status. Task_Collect releases SemDeliver to Task_Deliver to deliver the chocolate and the SemFlag3 for refunding the excess coins inserted. Task_Deliver releases SemFinish on finishing the delivery.

Automatic Chocolate Vending Machine (ACVM)

Task_Refund waits for taking SemFlag2 and releases SemFinish after delivering the coins inserted in shortage. Task_ExcessRefund waits for taking SemFlag3 and SemFinish after delivering the excess coins inserted. releases

Task_Display waits for taking SemFlag4 and takes SemMKey2 before posting the messages to display through Port_Display and releases it after displaying.