18
Embedded Systems Unit V – RTOS & Case Studies Prepared by Prof. N.Shanmugasundaram, Head, ECE Department Vidyaa Vikas College of Engg & Technology raja_ns@rediffmail.com

Embedded System Unit V (Prepared by N.Shanmugasundaram)

Embed Size (px)

DESCRIPTION

Embedded System - Unit V (BE-ECE, VII Semester, Anna University of Technology, Coimbatore, R2007)

Citation preview

Page 1: Embedded System Unit V (Prepared by N.Shanmugasundaram)

Embedded SystemsUnit V – RTOS & Case Studies

Prepared by

Prof. N.Shanmugasundaram,Head, ECE Department

Vidyaa Vikas College of Engg & Technology

[email protected]

Page 2: Embedded System Unit V (Prepared by N.Shanmugasundaram)

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.

Page 3: Embedded System Unit V (Prepared by N.Shanmugasundaram)

Options in RTOS

Options for

RTOS

Own RTOSLinux BasedRTOS

µC/ OS-II(Freeware)

PSoSVxWorksNucleusWin CE

Palm OS

Page 4: Embedded System Unit V (Prepared by N.Shanmugasundaram)

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.

Page 5: Embedded System Unit V (Prepared by N.Shanmugasundaram)

RTOS System level functions

The System level functions are

void OSInit (void) At the beginning prior to OSStart()

void OSStart (void) After OSInit() and task creating functions

void OSTickInit (void) To initialize System timer ticks

void OSIntEnter (void) Just after the start of ISR codes

Void OSIntExit (void) before return form the ISR codes

OS_ENTER_CRITICAL Macro to disable all interrupts

OS_EXIT_CRITICAL Macro to enable all interrupts

Page 6: Embedded System Unit V (Prepared by N.Shanmugasundaram)

Task Service functions

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

unsigned byte OSTaskCreate (…) Must call before running a task

unsigned byte OSTaskSuspend (..) Called for blocking a task

unsigned byte OSTaskResume (..) Called for resuming a blocked task

void OSTimeset (..) When system time is to be set

Unsigned int OSTimeGet (void) Find present count when time is read

Page 7: Embedded System Unit V (Prepared by N.Shanmugasundaram)

Time Delay functions

MUCOS Time delay functions for the tasks are

void OSTimeDly (…) To delay a task by count-1 value

unsigned byte OSTimeDlyResume (…) To resume a task after a preset delay

void OSTimeDlyHMSM (…) Time delay to block a task

Page 8: Embedded System Unit V (Prepared by N.Shanmugasundaram)

Memory related functions

MUCOS memory related functions for the tasks are

OSMem *OSMemCreate (…) To create and initialize memory partition

void *OSMemGet (..) To find the pointer of memory control block

unsigned byte OSMemQuery (..)To find pointers of memory blocks and data structures

unsigned byte OSMemPut (…) To return a pointer of memory block

Page 9: Embedded System Unit V (Prepared by N.Shanmugasundaram)

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 (…) To create and initialize a semaphore

void OSSemPend (..) To check whether a semaphore is pending

unsigned short OSSemAccept (..) To check whether SemVal > 0

unsigned byte OSSemPost (…)If SemVal = 0 or more, increments, and makes a semaphore again not pending.

unsigned byte OSSemQuery (…) To get semaphore information

Page 10: Embedded System Unit V (Prepared by N.Shanmugasundaram)

Other functions

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

• Mailbox

• Queue

Page 11: Embedded System Unit V (Prepared by N.Shanmugasundaram)

Case Study:

Automatic Chocolate Vending Machine (ACVM)

Page 12: Embedded System Unit V (Prepared by N.Shanmugasundaram)

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.

Page 13: Embedded System Unit V (Prepared by N.Shanmugasundaram)

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

Page 14: Embedded System Unit V (Prepared by N.Shanmugasundaram)

Automatic Chocolate Vending Machine (ACVM)

Page 15: Embedded System Unit V (Prepared by N.Shanmugasundaram)

Automatic Chocolate Vending Machine (ACVM)

Tasks Involved:

1 Task_ReadPorts Waits for Coins & Action as per coins collected

2 Task_Collect Collect coins >= cost, wait till timeout

3 Task_Deliver Deliver the chocolate

4 Task_Refund Refund coins, if coins are inserted in shortage

5 Task_ExcessRefund Refund coins, if coins are inserted in excess

6 Task_Display Display the present operation & status

7 Task_TimeDateDisplay Updates the display of Time & date in 3rd line of the LCD display

Page 16: Embedded System Unit V (Prepared by N.Shanmugasundaram)

Automatic Chocolate Vending Machine (ACVM)

Page 17: Embedded System Unit V (Prepared by N.Shanmugasundaram)

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 the amount by posting to semaphore SemAmtCount.

• 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.

Page 18: Embedded System Unit V (Prepared by N.Shanmugasundaram)

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 releases SemFinish after delivering the excess coins inserted.

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