Home | | Embedded Systems | Real Time Operating System Programming

Chapter: Embedded Systems

Real Time Operating System Programming

Study of Micro C/OS-II or Vx Works or Any other popular RTOS – RTOS System Level Functions – Task Service Functions – Time Delay Functions – Memory Allocation Related

Real Time Operating System Programming

 

 mC/OS-II andVxWorks

 

Kernel of an RTOS

Used for real-time programming features to meet hard and soft real time constraints,

 

  Provides for preemption points atkernel, user controlled dynamic priority changes, fixed memory blocks, asynchronous IOs, user processes inkernel space and other functions for asystem.

 

Common options available for selecting an RTOS

 


Complex multitasking embedded system design requirements

 

·        Integrated Development Environment,

·        Multiple task functions in Embedded C or Embedded C++,

·        Real time clock─ hardware and software timers,

·        Scheduler,

 

·        Device drivers and device manager,

 

·        Functions for inter inter-process communications using the signals, event flag group, semaphore- handling functions, functions for the queues, mailboxes, pipe, and sockets,

 

·          Additional functions for example, TCP/IPor USB port, other networking functions,

·          Error handling functions and Exception handling functions, and

 

·        Testing and system debugging software for testing RTOS as well as developed embedded application

 

Basic functions expected from kernel of an RTOS

 


RTOS features in general

 

·        Basic kernel functions and scheduling: Preemptive or Preemptive plus time slicing

·        Support to Limited Number of tasks and threads

·        Task priorities and Inter Service Threads priorities definitions

·        Priority Inheritance feature or option of priority ceiling feature

 

·        Task synchronization and IPC functions

·        Support to task and threads running in kernel space

 

·        IDE consisting of editor, platform builder, GUI and graphics software, compiler, debugging and host target support tools

 

·        Device Imaging tool and device drivers

·        Clock, time and timer functions,

·        Support to POSIX,

 

·        Asynchronous IOs,

·        Fixed memory blocks allocation and deal location system,

·        Support to different file systems and flash memory systems

·        TCP/IP protocols, network and buses protocols,

·        Development environment with Java

 

·        Componentization (reusable modules for different functions), which leads to small footprint (small of size of RTOS codes placed in ROM image)

 

·        Support to number of processor architectures, such as INTEL, ARM, Philips, …

 

Development Approaches

 

Host and Target Based Development Approach:

 

·        A host machine (Computer) for example, a PCuses a general purpose OS, for example, Windowsor Unix for system development. The target connects by a network protocol for example TCP/IP during the development phase. The developed codes and the target RTOS functions first connect a target. The target with downloaded codes finally disconnects and contains a small size footprint of RTOS. For example, the target does not download host machine resident compiler, cross compiler, editor for programs, simulation and debugging programs, and MMU support.

 

Self-host Based Development Approach:

 

·        Same system with full RTOS is used for development on which the application will be running. This also does not require cross compilation. When application codes are ready, the required RTOS functions codes and application codes are downloaded into the ROM of the target board

 

Types of RTOSes

 

1.     In-House Developed RTOSes

2.     Broad based Commercial RTOSes

 

3.     General Purposes OSes with RTOS

4.     Special Focus RTOSes

μC/OS-II System level and task Functions

 

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

·        void OSStart (void)After OSInit ( ) and task-creating function(s)

 

·        void OSTickInit (void)In first task function that executes once.Initializes the system timer ticks (RTCinterrupts)

 

Interrupt Service Task (ISR) Start andEnd

 

·        OSIntEnter ( ) and OSIntExit ( )

 

·        Function void OSIntEnter (void)─ used at the start of ISRFor sending a message to RTOS kernel fortaking control─ compulsory to let OS kernel control the nesting of the ISRs in case of occurrences of multiple interrupts of varying priorities.

 

·        Function void OSIntExit (void)─ used just before the return from the runningISR─ For sending a message to RTOS kernel forquitting control of presently running ISR

 

Critical Section Start and End

 

·        OS_ENTER_CRITICAL

§    Macro to disable interrupts before acritical section

 

§    Used at the start of a ISR or task - for sending a message to RTOS kernel and disabling the interrupts

 

§    Use compulsory when the OS kernel is to take note of and disable the interrupts of the system

 

·        OS_EXIT_CRITICAL─ Macro to enable interrupts. [ENTER and EXIT functions form a pair in the critical section]

§    used at the end of critical section

 

§    for sending a message to RTOS kernel and enabling the interrupts

 

§    Use is compulsory to OS kernel for taking note of and enables the disabled interrupts.

 

Function void OSTickInit (void)

 

─ is used to initiate the system clockticks and interrupts at regular intervals asper OS_TICKS_PER_SEC predefined when defining configuration of MUCOS

 

Task Service Functions

 

·        Service functions mean the functions of multitasking service (task create, suspend or resume), time setting andtime retrieving (getting) functions.

 

OSTaskCreate

 

§    unsigned byte OSTaskCreate (void(*task) (void *taskPointer), void*pmdata, OS_STK*taskStackPointer, unsigned bytetaskPriority)Called for creating a task.

Macro OS_TASK_CREATE_EN

§    Must be preprocessor directive to enableinclusion of task management functionsby

 

MUCOS

 

OSTaskSuspend and OSTaskResume

·        unsigned byte OSTaskSuspend(unsigned byte taskPriority)

§    Called for blocking a task

 

·        unsigned byte OSTaskResume(unsigned byte taskPriority)

Called for resuming a blocked task

 

System Time and Time DelayFunctions

 

• void OSTimeSet (unsigned intcounts) Used when system time is to be set bycounts

 

OSTimeGet( ) and OS TimeDly(delay Count)

• unsigned int OSTimeGet (void)

 

to find present counts when system time is read.

• void OSTimeDly (unsigned short delay Count)

To delay a task by period of count-input sequal to delay Count -1

 

OSTimeDlyHMSM

 

void OSTimeDlyHMSM (unsigned bytehr, unsigned byte mn, unsigned byte sec, unsigned short ms)

 

OSTimeDlyResume

• unsigned byte OSTimeDly Resume(unsigned byte task Priority)

 

When a task of priority = task Priority is to resume before the preset delay, which was bya value defined either by delay Count or (hr,mn and ms) and which is in blocked state now.

 

Macros to find status after execution of OS Time Delay Functions

OS_NO_ERR, when our arguments are valid and resumption after delay succeeds.

OS_TIME_INVALID_HOURS,

OS_TIME_INVALID_MINUTES,

OS_TIME_INVALID_SECONDS and

OS_TIME_INVALID_MILLI, returns true

OS_TIME_ZERO_DLY, returns true ifall the arguments passed are 0.

OS_NO_ERR returns true if all the arguments passed or when resumption after delay succeeds.

OS_TASK_NOT_EXIST returns true ,if task was not created earlier.

OS_TIME_NOT_DLY returns true,  if the task was not delayed.

 

  (vi) OS_PRIO_INVALID returns true, when task Priority parameter that was passed is more than the OS_PRIO_LOWEST (23)when maximum number of user tasks = 8

 

 

 

 

Memory Allocation RelatedFunctions

OSMemCreate

 

OSMemPut (*memCBPointer, *memErr)

OSMemGet (*memCBPointer, *memErr)

OSMemQuery (* memCBPointer, *memData)

 

Semaphore Functions

 

Provides for using same semaphorefunctions as an event signaling flagor mutex or counting semaphore.

 

OSSemCreate (semVal)

 

OSSemPend (*eventPointer, timeOut,*SemErrPointer) OSSemAccept (*eventPointer)

OSSemPost (*eventPointer)

 

OSSem   (*eventPointer)

 

Mailbox Functions

 

 

·        Used to communicate a pointer for information.

·        μC/OS-II permits one message-pointerper mailbox.

·        At the pointer, there can be a string or data structure of no size limit.

·        Assume an event pointer to the mailbox = *mboxMsg,

 

·        Pointer to the message, *MsgPointer(for retrieving the message itself).

 

 

OSMboxCreate(*mboxMsg)

To create a mailbox message pointer ECBof a mailbox message.

 

OSMboxPend(*mboxMsg, timeout,*MboxErr)

 

To check if mailbox message not pending(available) then read *mboxMsg is and empty mailbox [* mboxMsg = NULL again]. If message is not available [*mboxMsg points to NULL],then wait, suspend the task (block further running) till *mboxMsg not Null or timeout.

 

OSMboxAccept (*mboxMsg)

To check if mailbox message at the*MsgPointer, is available at *mboxMsg.

 

Unlike OSMboxPend function, it does notblock (suspend) the task if message is not available. If available, it returns the pointer.

 

OSMboxPost (*mboxMsg, *MsgPointer)

Sends a message of task at address MsgPointerby posting the address pointer to the mboxMsg.

If box is already full (*mboxMsg not Null),then the message is not placed and error status sent.

 

OSMboxQuery (*mboxMsg, *mboxData)

To get mailbox error information

Pointer Null or Not Null,

 

Queue Functions

 

  The message pointers post into a queue by the tasks either at the back as in a queue or at the front as in a stack.

 

  A task can thus insert a given message for deleting either in the first in firstout (FIFO) mode or in priority mode for priority message.

 

Assume pointer, **Qtop, to a queue of pointers for the messages and

 

  Assume two pointers, *QfrontPointerand *QbackPointer to insert (post) and delete (retrieve), respectively, thepointer of the message.

 

Functions

OSQCreate (**QTop, qSize)

OSQPost (*QMsgPointer, *QMsg)

OSQPostFront (*QMsgPointer, *QMsg)

 

OSQPend (*QMsgPointer, timeOut, *Qerr)

OSQFlush(*QMsgPointer)

OSQQuery (*QMsgPointer, *QData)

 

IPC Objects

·          For which there is waiting process or thread

 

·        A process (thread or scheduler, task orISR) generates some information by or value and sends event or semaphore or message into queue or a single IPC or multiple objects as output so that it letsanother process waiting for that object in order to take note or use the object.

 

·        A process waits for an IPC or object (s)in order to take note or use the object(s)

 

IPC Object Functions

Wait For Sing leObject

 

Wait For Multiple Objects


Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
Embedded Systems : Real Time Operating System Programming |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2024 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.