Professional Documents
Culture Documents
- By Vamshi Krishna D
Contents
• What is RTOS
• Scheduling Methods
• Designs of RTOS -Event Driven & Time sharing
• Task & Its states.
• READY LIST
• Inter task communication and sharing
• RTXC Overview
• RTXC Features
• Rules of RTXC
• RTXC Tasks
• Semaphores
• Queues
• Resources
• Timers
• Interrupt service Routine
• Introduction to RTXCGen
• Introduction to RTXCBug
• Glossary of Terms
What is RTOS
• A real-time operating system (RTOS) is a multitasking
operating system intended for real-time applications.
Such applications include embedded systems and scientific
research equipment .
• An RTOS provides facilities which, if used properly, guarantee
1) Running state :The task is in execution ,the task has control of all
highest priority task to run does not require iterating through the
entire list.
Inserting a task then requires walking the ready list until reaching
either the end of the list, or a task of lower priority than that of the
task being inserted.
Inter task communication and
sharing
Intertask communication and resource sharing:Multitasking
systems must manage sharing data and hardware resources among
multiple tasks. It is usually "unsafe" for two tasks to access the same
specific data or hardware resource simultaneously.
There are three common approaches to resolve this problem:
2)Binary semaphores
3)Message passing
Inter task communication and
•
sharing
1)Masking Interrupts:On single-processor systems, if the
application runs in kernel mode and can mask interrupts, then the
current task has exclusive use of the CPU and thus can prevent
simultaneous access to a shared resource.No other task or interrupt
can take control, so the critical section is effectively protected.
When the task exits its critical section, it must unmask interrupts;
pending interrupts, if any, will then execute.
• disadvantages:interrupts if masked for long periods increases the
semaphores and then wait forever (no timeout) for other binary
semaphores, creating a cyclic dependency graph
Inter task communication and
sharing
• Message passing: The other approach to resource sharing is for
tasks to send messages. In this paradigm, the resource is managed
directly by only one task; when another task wants to interrogate
or manipulate the resource, it sends a message to the managing
task.
• Can be done by FIFO QUEUES , MESSAGES(MailBox)
•
MEMORY ALLOCATIONS
• MEMORY ALLOCATION: Memory allocation is even more critical in
an RTOS than in other operating systems.Firstly, speed of
allocation is important. Next there should be minimum
Fragmentation as the RTOS is designed to work for years without
reboot .
• Different techniques are followed such as Memory Partitioning ,
having a Memory Management Unit etc to avoid memory
fragmentation.
RTXC Overview
• RTXC is a Real-Time Operating System (RTOS).RTXC is designed
to support real-time, multitasking systems.
•
1)Employs a multitasking design in order to achieve
maximum CPU efficiency .
•
2) time-sharing scheduling with priority driven pre-emptive
scheduling
• 3)RTXC multitasking is driven in response to system events,
whether of internal or external origin.
• 4)support an application design composed of a set of separate
but interrelated tasks each having a priority indicative of its
relative scheduling importance.
• 5)Small ram requirement: RTXC requires small RAM
requirement for kernel operations.
•
•
RTXC Features
• These features include:
• Multitasking with pre-emptive task scheduling
• Round Robin and Time-Sliced scheduling within same priority level
• Support for static and dynamically created tasks
• Fixed or dynamically changeable task priorities
• Intertask communication and synchronization via semaphores, messages,
and queues
• Efficient timer management
•
RTXC features
• Timeouts on many services
• Management of memory
• Resource management
• Fast context switch
• Small RAM and ROM requirements
• Standard programmer interface on all processors
• Highly flexible configuration to permit custom fit to the application
Rules of RTXC
• The Current Task (i.e., the task which is currently in control of the
CPU) is the highest priority task in the system which is not
otherwise blocked (yields, becomes blocked by unavailability of a
needed resource, or is preempted.).
• If a task of higher priority than the Current Task becomes
Ready, it preempts the lower priority task and becomes
the Current Task.
• The Null Task is always the lowest priority task and whose priority
must never be changed. It must always be Ready and MUST NEVER
be blocked.The Null Task must terminate the READY List.
• Any event used for task synchronization must be associated with
a semaphore.
• A semaphore can be associated with only one event at a time.
•
Rules of RTXC
• A set of tasks using a Round Robin scheduling protocol and
Time-Sliced scheduling must have the same priority.
• A queue has a capacity (Depth) of a predefined number of
entries .Within a given queue, an entry has a predefined size
(Width).
• Any task can send mail to any mailbox.A task may own none, one,
• READY LIST: In RTXC,The READY List is actually a doubly linked list containing
those tasks which are runnable (Ready) in descending order of priority. Thus,
the Current Task is always the first task in the thread.
• This list is constantly being changed by various Kernel Services which insert
runnable tasks or remove those which are blocked and temporarily not able to
run.
READY LIST
TCB parameters
TCB 1)Function
current entry point
READY task 2)stack base
LIST 3)stack size
4)priority
TCB
priority
of
order
Decreasing
TCB
point function)
• - KS_execute() to launch the task.
• KS_execute(taskname);
RTXC semaphores
• RTXC semaphores are the primary mechanism of synchronizing a task with an
event.The basic use of semaphores is that of a "handshake" in which one task
waits for a signal and another provides the signal
• Each semaphore contains information about
the state of the associated event
the task trying to synchronize with the event.
• The system designer defines all semaphores via RTXCgen during the system
generation process.
• Semaphores are assigned names which equate to numbers.The semaphore
name or number is its identifier
• An RTXC semaphore contains a value representing one of the three possible
states
A PENDING state indicates that the event associated with the semaphore
has not yet occurred and is therefore pending.
The WAITING state shows that not only has the event not yet occurred,
but a task is waiting for it to happen.
The DONE state tells that the event has occurred.
• RTXC startup code initializes all semaphores to the PENDING state.
Synchronization with semaphores
• semaphores are always associated with an event.
• For a task to synchronize with an event it must first wait for the event
to occur.
• To do this, the task waits on an RTXC semaphore using one of three Kernel
Services, KS_wait(), KS_waitm(), or KS_waitt().
• If a task attempts to wait on a semaphore in the PENDING state, the state of
the semaphore is changed to WAITING.
• The Current Task will be blocked with SEMAPHORE_WAIT and removed from
the READY List. Additionally, the task's execution is suspended until the event
occurs.
• If the Current Task attempts to wait on a semaphore which is in
the DONE state, the wait does not occur (since the desired event has
already happened), and the task is immediately resumed. RTXC automatically
changes the semaphore state back to PENDING.)
• An attempt to wait on a semaphore which is already in the
WAITING state can cause unpredictable results and should not be
attempted.
Synchronization with semaphores
• EVENT SIGNALING :signaling a semaphore constitutes the second
action in the handshake. The occurrence of a specific event can
be indicated by signaling the semaphore associated with that
event.
• a signal may originate in either a task or in an interrupt service
routine.
• For tasks performing a signal, RTXC provides the Kernel
• #ifdef RESOURCE_WAITERS
• TCB *waiters; ----------- priority list of waiters, 0=no waiters
• TCB *dummy; ------------- reserved - must follow *waiters
• #ifdef PRIORITY_INVERSION
• PRIORITY priority; ----------- original owner's priority iff inversion
• RESATTR resattr; ----------- priority inversion option switch
• #endif
• #endif
• #ifdef CBUG -----------RTXCbug use
• unsigned int count; ------------- statistics - no. of locks performed
• unsigned int conflict; --------- statistics - no. resource conflicts
• #endif
• } RHEADER;
MEMORY PARTITIONS
• RTXC supports a RAM memory management concept which features the use of
defined memory partitions to prevent fragmentation
• Memory partitions may be statically or dynamically defined according to the
needs of the application.
• Each memory partition, also called a Map, contains one or more blocks all of
which are the same size.
• Tasks allocate blocks of memory from various Maps as needed to perform their
assigned jobs.
• The attributes include:
· Memory Partition Identifier
· Block Size
Number of Blocks
· RAM Area Address
• When finished with a memory block, they release it by freeing it to the Map
from which it was allocated.
•
•
MEMORY PARTITIONS
• Static Memory partitions:The system designer defines all static Memory
Partitions during system generation using RTXCgen .
• with RTXCgen, the user specifies the various attributes of each static Map
including its name, the number of blocks it is to contain, and its block size.
RTXCgen computes how much memory to allocate and produces the C
structures and memory arrays to accommodate the specification.
• RTXC does permit attribute redefinition for a static Memory Partition
through the use of the Kernel Service KS_defpart().
• Dynamic Memory partition:The number of dynamic Memory Partitions is
specified via RTXCgen,but the attributes and size are defined at run time.
• The task issues a KS_alloc_part() Kernel Service to allocate an unused
Map control block from the pool of free Map control blocks.
• The task defines the Map's attributes through the KS_defpart() Kernel
Service.
• Allocation of the dynamic Map control block and attribute definition can be
done by single Kernel Service request, KS_create_part().
• If a dynamic Memory Partition no longer has utility to the application, it
may be released by KS_free_part() Kernel Service
TIMER
• Timer TICKS: The basic time unit used internally by RTXC is a TICK. A TICK
defines the amount of time between interrupts generated by the system clock
• RTXC uses two types of timers--General Timers and Timeout Timers.
• General Timers time system events such as the periodicity of a task's
cyclic operation or the operation of some mechanical device in the
physical process.
• eg: allocating a cyclic timer for processing HTTP connections
• A General timer has to be allocated and started by
• GTimer =KS_alloc_timer()
• KS_start_timer(GTimer, TICKS ,TICKS period, SEMA )
• Timeout Timers are a special type of timer used in limiting the duration
of certain Kernel Services in blocking the requesting task.
•
• General Timers are suitable for general purpose timing, including such uses as
timing events and establishing periodic task activation.
•
TIMER
•
particular device.
• After storing the context, the ISR prologue transfers control to the main function of
the ISR to service the interrupting device. This is usually a C function which performs
some device specific operation in order to clear the source of the interrupt request.
•
•
Interrupt Service Routine
• RTXC provides two special services to deal with commonly encountered
requirements of interrupt processing. The function KS_ISRsignal() should be
called to signal a semaphore from the ISR while KS_ISRtick() provides RTXC
required processing for a clock tick.
• When its device specific operations are complete, the device servicing
function indicates that fact by calling the fourth special interrupt service
function, KS_ISRexit().
• Epilogue:The epilogue is the end action performed to finish interrupt
processing and continue with the application.
• It sole function is to restore the context of the highest priority Ready task and
grant it control of the CPU.
•
Introduction to RTXCgen
• used for the generation of RTXC OS related tasks, and other various data
structures.
• Sysgen Utility:
• This utility is present under the multivoip->src->rtxcnet->bin directory and is
named as sysgen.exe. The sysgen utility requires a project file which will
define the tasks and the other datastructure. This project file is named as
'digivoip.rtx'.
•
Operations on Task with RTXCgen
• There are multiple operations that can be done on the task. The task details
can be invoked by selecting View->tasks
•
●