Embedded Systems - VTU 6th Sem - Chapter 3: RTOS and IDE for Embedded System Design
Q1. Explain monolithic and micro kernels with suitable example for each.
Monolithic Kernel:
• All OS services run in the same memory space (kernel space).
• Tight integration allows fast service interaction.
• Any error in one module can crash the entire system.
• Examples: Linux, MS-DOS, Solaris.
Features:
• High performance due to minimal context switching.
• Difficult to maintain and debug.
Microkernel:
• Only essential services (memory management, scheduling, etc.) run in kernel space.
• Other services (I/O, file system) run as user-space processes (servers).
• Examples: QNX, Minix, L4.
Features:
• Highly modular and secure.
• Easier debugging and maintenance.
• Slight performance overhead due to message passing.
Diagram:
Monolithic Kernel Microkernel
------------------ ------------------
| FS | MM | IPC | | Kernel Core |
| | | | |---------------|
|----------------| | Servers (FS, |
| Kernel Space | | I/O, etc) |
Q2. Discuss the terms tasks, process and threads.
Task:
• A task is a program in execution, also called a job.
• Managed by the OS using a Task Control Block (TCB).
1
Process:
• An executing instance of a program.
• Has its own memory space: code, data, stack.
• State transitions: Ready, Running, Blocked, Completed.
Thread:
• Lightweight process inside a process.
• Shares code, data, heap with other threads in the same process.
• Has its own program counter, stack, and registers.
POSIX Thread Example (C):
#include <pthread.h>
void* myFunction(void* arg) {
printf("Hello from thread!\n");
return NULL;
}
int main() {
pthread_t tid;
pthread_create(&tid, NULL, myFunction, NULL);
pthread_join(tid, NULL);
return 0;
}
Comparison Table:
Concept Memory Independence Example
Task Varies OS managed RTOS
Process Isolated Fully Linux
Thread Shared Partial POSIX
Q3. Calculate waiting time and turnaround time for P1(10ms), P2(5ms), P3(7ms).
Assume no I/O.
Given:
• P1 = 10ms, P2 = 5ms, P3 = 7ms
• Order: P1, P2, P3
• Scheduling: FCFS (First Come First Serve)
Gantt Chart:
2
| P1 | P2 | P3 |
0 10 15 22
Waiting Time:
• P1: 0ms
• P2: 10ms
• P3: 15ms
• Avg WT = (0+10+15)/3 = 25/3 = 8.33ms
Turnaround Time (TAT):
• P1: 10ms
• P2: 15ms
• P3: 22ms
• Avg TAT = (10+15+22)/3 = 47/3 = 15.67ms
Q4. Write a note on IAP and ISP.
In-System Programming (ISP):
• Programming done using UART/SPI while chip is soldered to board.
• Requires bootloader.
• Used during development or post-deployment updates.
In-Application Programming (IAP):
• Self-programming method during application execution.
• No external tools needed.
• Used for field firmware upgrades.
Comparison:
Feature ISP IAP
Tool needed Yes No
Bootloader Required Optional
Example Use Factory flashing OTA firmware update
Q5. Demonstrate a block schematic of IDE environment for embedded system design
and explain their functions in brief.
Block Diagram:
3
[Source Code] --> [Compiler] --> [Assembler] --> [Linker] --> [Executable File]
| |
|------> [Debugger] <-----[Emulator/Simulator]
Explanation of Components:
• Compiler: Converts C/C++ code to assembly.
• Assembler: Converts assembly to machine code.
• Linker: Combines object files into final executable.
• Debugger: Tests and verifies code.
• Simulator/Emulator: Simulates hardware behavior.
• IDE (e.g., Eclipse, IAR): Provides GUI, integrates tools.
Q6. Illustrate the concept of ‘deadlock’ with a neat diagram. Mention the different
conditions which favor a deadlock situation.
Deadlock Definition:
• A situation where two or more processes are waiting for each other’s resources, and none can
proceed.
Deadlock Conditions (Coffman’s Conditions):
1. Mutual Exclusion – One resource at a time.
2. Hold and Wait – Process holds one resource, waits for another.
3. No Preemption – Resources can’t be forcefully taken.
4. Circular Wait – Circular chain of processes each waiting for the next.
Diagram:
Process A --> Resource Y --> Process B --> Resource X --> Process A
Prevention Techniques:
• Avoid Circular Wait (resource hierarchy)
• Resource preemption
• Request all resources upfront
Q7. Explain preemptive task scheduling techniques.
Types of Preemptive Scheduling:
1. Shortest Remaining Time (SRT):
4
2. Picks task with shortest remaining execution time.
3. Suitable for predictable environments.
4. Round Robin (RR):
5. Each task gets a fixed time slice.
6. Fair but not optimal for high-priority tasks.
7. Priority-Based:
8. Executes highest-priority task first.
9. Lower-priority tasks may starve.
Gantt Chart Example (RR, time slice = 2ms):
P1(6), P2(4), P3(2)
|P1|P2|P3|P1|P2|P1|
Used in:
• Real-time OS for time sharing
• Ensures fairness and responsiveness
Q8. Describe various inter-process communication (IPC) methods used in RTOS.
IPC Mechanisms:
1. Shared Memory:
2. Common memory region for data exchange.
3. Fast but needs synchronization (mutex/semaphore).
4. Pipes:
5. Unidirectional/bidirectional communication.
6. Suitable for client-server models.
7. Message Queues:
5
8. FIFO queues for structured message passing.
9. Avoids data overwrites.
10. Mailbox:
11. One-message buffer, simpler than queues.
12. Signals:
13. Asynchronous notifications without data.
14. RPC (Remote Procedure Call):
15. Invokes a function on a remote process or machine.
Diagram (Message Queue):
Process A --> [Message Queue] --> Process B
Q9. Discuss task synchronization issues in RTOS.
Issues:
1. Racing:
2. Two tasks update the same variable simultaneously.
3. Can lead to inconsistent state.
4. Use semaphores/mutex to avoid.
5. Deadlock:
6. Two tasks wait for resources held by each other.
7. See Q6.
8. Starvation:
9. Low-priority task never gets CPU.
10. Prevent using aging techniques.
6
11. Livelock:
12. Tasks change state but can’t complete execution.
Solution:
• Proper use of synchronization primitives: mutex, semaphore, conditional variables.
• Careful task prioritization and scheduling.
Q10. How do you choose an RTOS for a project?
Factors for Choosing an RTOS:
1. Real-time Capability:
2. Deterministic behavior, fast context switch
3. Task Management:
4. Preemptive scheduling, priority support
5. Memory Footprint:
6. Low for embedded constraints
7. Inter-task Communication:
8. IPC mechanisms like queues, semaphores
9. Portability and Scalability:
10. Easily ported to different hardware
11. Development Tools:
12. Debugger, profiler, IDE support
13. Licensing & Cost:
14. Free (e.g., FreeRTOS) or commercial (e.g., VxWorks)
Examples:
• FreeRTOS – Open-source, widely used
7
• µC/OS-II – Certified for safety-critical apps
• QNX – High reliability, automotive/industrial use