Professional Documents
Culture Documents
blocks,
tasks,
which execute in parallel and independent of each other
• Having fully independent tasks is rarely possible practice.
• In many cases, tasks need to be activated on a particular event
• e.g., from an interrupt service routine or from another task requesting a
service.
• In such cases, tasks often need to receive related input, i.e., parameters.
• Tasks often need to share hardware resources such as communication
interfaces which can only be used by one task at a time, i.e. mutual exclusion,
a type of synchronization.
• It semaphores can cause various bugs.
• At least some of those bugs stem from undisciplined use:
• allowing code in many different modules to use the same semaphore and hoping that
they all use it correctly.
• These bugs can be compressed before they get crawling simply by hiding the
semaphore and the data that it protects inside of a module, thereby
encapsulating both.
• Similarly encapsulating queues that tasks use to receive messages from other
tasks
To handle a shared flash memory:
• That code deals correctly with synchronizing the requests for reading from
and writing to the flash memory, which was the point.
• However, it is not recommended to use that code in a real system.
Encapsulating Semaphores
• The act of putting Give and Get semaphore routines throughout the
code causes an increased probability of mistakes being made.
• Encapsulate Semaphore routines so that tasks that want to execute
some behavior involving the semaphore make a call to a single routine
• The Get and Give calls are inside this encapsulated routine.
Encapsulating Queues
Mistakes dealing with queues can be reduced by encapsulation.
• Queues typically have a protocol or format associated with.
• Multiple message passing calls increase the probability of a communication
mistake.
• Encapsulating such calls into functions that take specific arguments reduces
these errors.
Encapsulating Consideration
• When encapsulating semaphores or queues:
• Routines are shared by many tasks
• Care must be taken to avoid shared data problems
• Routines must be reentrant.
HARD REAL-TIME SCHEDULING
•Theory Exists For Guaranteeing Absolute Deadlines
•Consider a set of n periodic tasks, each with a period Ti and a worst-case execution time C
•(C1 /T1)+(C2 /T2) +…+(Cn/Tn)≤ bound
•Based On N Tasks, Worst Case Task Times Cn, And Tn Units Of Time.
•To More Complex Analysis Depending On Jitter And Deadlines
•It is important to write routines that always execute in the same amount of time or have clear worst case
times.
• Hard real Time Systems - Systems were time constraints are absolutely
critical
• Soft real Time Systems - Systems with time constraints where minor errors
are tolerated
• The obvious issue that arises in hard real-time systems is that it must
somehow guarantee that the system will meet the hard deadlines.
• The ability to meet hard deadlines comes from writing fast code
• To write some frequently called subroutine in assembly language.
• If tasks can be characterized, then analysis can be done to know whether
deadlines can be met or not
• A hard RT RTOS is one, which has predictable performance with no deadline miss, even in case of
sporadic tasks (sudden bursts of occurrence of events requiring attention).
• Automobile engine control system and anti lock brake are the examples of hard real time systems
• Disabling of all other interrupts of lower priority when running the hard real time tasks
• Preemption of higher priority task by lower priority tasks Some critical code in assembly to
meet the real time constraint (deadline) fast
• Task running in kernel space, [This saves the time required to first check whether access is
outside the memory space allocated to the kernel functions.]
• EX: Application having hard real-time tasks is an anti-missile system.
• An anti-missile system must first detect all incoming missiles, properly position the anti-missile gun, and then fire to
destroy the incoming missile before the incoming missile can do any damage.
• All these tasks are hard real-time in nature and the anti-missile system would be considered to have failed, if any of its
tasks fails to complete before the corresponding deadlines.
• For hard real-time tasks in practical systems, the time bounds usually range from several micro
seconds to a few milli seconds.
• It may be noted that a hard real-time task does not need to be completed within the shortest
time possible, but it is merely required that the task must complete within the specified time
bound.
Saving memory:
Embedded systems often have limited memory
RTOS: each task needs memory space for its stack.
Two methods for determining space requirements:
The first method for determining how much stack space a task needs is to
examine your code. Trace the deepest functional calls possible.
Add all the local variables, parameters and interrupt routine needs.
Accurate but very difficult to carry out.
The second method is experimental. Fill each stack with some
recognizable data pattern at startup, run the system for a period of time
Easy but not so accurate. Might have missed the worst case.
Saving Memory Space
Program Memory:
Limit the number of functions used
Check the automatic inclusions by your linker: may consider writing own functions
Include only needed functions in RTOS
Consider using assembly language for large routines
Make sure that you are not using two functions to do the same thing.
Check that your development tools are not sabotaging you.
Configure your RTOS to contain only those functions that you need.
Look at the assembly language listings created by your cross-compiler to see if certain of your C
statements translate into huge numbers of instructions.
Data Memory:
Consider using more static variables instead of stack variables
On 8-bit processors, use char instead of int when possible
•ROM (code) and RAM(data) are separate.
• Packing data tightly and neatly usually consumes more code space.
•It is often necessary to save space to get everything to fit .
Saving power:
The primary method for preserving battery power is to turn off parts or all of the system
whenever possible.
Most embedded-system microprocessors have at least one power-saving mode; many have
several.
The modes have names such as sleep mode, low-power mode, idle mode, standby mode, and so
on.
A very common power-saving mode is one in which the microprocessor stops executing
instructions, stops any built-in peripherals, and stops its clock circuit.
This saves a lot of power, but the drawback typically is that the only way to start the
microprocessor up again is to reset it.
Static RAM uses very little power when the microprocessor isn't executing instructions
Another typical power-saving mode is one in which the microprocessor stops executing instructions
but the on-board peripherals continue to operate.
Another common method for saving power is to turn off the entire system and have the user turn it
back on when it is needed.
• To some extent, the ability to meet hard deadlines comes from writing fast
code.
• Writing fast code for real-time systems is not very different from writing fast
code for applications,
• however. Faced, for example, with writing a system of either kind that
searches fix data items frequently but adds and deletes them rarely,
Host and Target machines
• Host: –
A computer system on which all the
programming tools run – Where the
embedded software is developed,
compiled, tested, debugged, optimized,
and prior to its translation into target
device.
• Target: –
After writing the program, compiled,
assembled and linked, it is moved to
target – After development, the code is
cross-compiled, translated – cross-
assembled, linked into target
processor instruction set and located
into the target.
Linkers and Locators
The process of converting the source code representation of embedded
software into an executable binary image involves three distinct steps:
• Tasks of Linker
• Searches the program to find library routines used by program, e.g.
printf(),sqrt(),strcat() and various other.
• Determines the memory locations that code from each module will occupy
and relocates its instructions by adjusting absolute references.
–Jumps to a startup routine that copies the program’s arguments from the stack to registers
and calls the program’s main routine.
Types of Loaders
Compile/Assemble and Go loader
Absolute Loader
Relocating Loader
Direct Linking loader
Assemble-and-go Loader
• Compilation, assembly, and link steps are not separated from program
execution all in single pass.
• The intermediate forms of the program are generally kept in RAM, and not
saved to the file system.
• Disadvantage:
• Difficult to use subroutine libraries.
• The need of programmer to state the actual address.
Algorithm for Absolute Loader
1. begin
2. read Header record
3. verify program name and length
4. read first Text record
5. while record type <> ’E’ do
6. begin
7. {if object code is in character form, convert into
8. internal representation}
9. move object code to specified location in memory
10. read next object program record
11. end
12. jump to address specified in End record
13. end
Bootstrap Loader
• Special Type of Absolute Loader.