RTOS
Uses
1. Task management
Activation and termination of tasks
Management of task switching and task states
2. Synchronization
Resource management
Event control /management
3. Interrupt management
Services for Interrupt processing
4. Alarms
Relative and absolute alarms
5. Error treatment
Mechanisms supporting the user in case of various errors
Task management
Task concept
A task provides the framework for the execution of functions.
1. Basic Tasks
Does not support events
States: Ready, Running, Suspended
2. Extended Tasks
Can pause the execution until an event occurs
States: Ready, Running, Suspended, Waiting
Suspended > Ready > Running > Suspended
Termination of a task is only possible if the task terminates itself ("self-
termination").
There is no provision for a direct transition from the suspended state into the
waiting state
Task priority
The scheduler decides based on the task priority (precedence) which is the next
of the ready tasks to be transferred into the running state.
Value 0 is defined as the lowest priority of a task.
Tasks on the same priority level started depending on their order of
activation.
Extended tasks in the waiting state do not block the start of subsequent
tasks.
A preempted task is the first (oldest) task in the ready list of its current
priority.
A task released from waiting state is the last (newest) task in the ready queue
of its priority.
Scheduling policy
Full preemptive scheduling
Preemptive scheduling means the running task may be rescheduled by higher
priority tasks.
It put the running task into the ready state, as soon as a higher priority task
has got ready.
The task context is saved so that the preempted task can be continued later.
Non preemptive scheduling
Non preemptive scheduling means the running task can’t be preempted by
other tasks.
It imposes non preemptive to achieve timing requirements of the tasks.
Mixed preemptive scheduling
Both preemptive and non-preemptive tasks can be mixed in the system, and
scheduling is decided based on the running task.
Preemptive is allowed for Preemptive task and vice versa.
Extended tasks and short execution tasks can be non preemptive nature.
Interrupt processing
Two ISR categories provided by RTOS for accessing OS services from an ISR.
ISR1: Does not use RTOS services. execution starts from interrupted task at the
end of the ISR.
ISR2: Can use RTOS services. rescheduling takes place at the end of the ISR.
APIs are provided to disable/enable all interrupts to protect short critical
sections of ISR.
Event mechanism
Events are objects managed by operating system.
Each extended task has a definite no of events, it is called the owner of these
events.
When activating an extended task these events are cleared by RTOS.
Any task or ISR2 can set an event, and extended tasks may only clear the
events they own
E.g. of events: expiration of a timer, availability of a resource, reception of a
message etc.
RTOS provides services for setting, clearing, and waiting for the events to
occur.
Resource management
Protocols
I2C
Two wires synchronous communication with multi master support.
SDA (Data line) SCL (Clock line).
In idle, both SDA & SCL lines are high.
Start condition: SDA high to low when SCL high.
Data changes in falling edge (SCL low), and data is sampled in leading edge
(SCL high).
Stop condition: SDA low to high when SCL high
Arbitration:
Clock Stretching: allows a slave device to pull the SCL line until it is ready for
transmission.