Module 5B
Module 5B
1. Co-operating Processes
2. Competing Processes
o Do not share data but compete for system resources (e.g., files, display devices, CPU
time).
IPC is the mechanism that allows processes to communicate and coordinate. Some common IPC
mechanisms include:
• Remote Procedure Calls (RPC) (used for communication between processes on different
machines)
Shared memory is one of the fastest IPC mechanisms, where multiple processes access a common
memory area to exchange data.
How Shared Memory Works
2. Other processes read the data from the same memory region.
Real-World Analogy
• A Notice Board:
o Unlike the real-world case, shared memory can support both read and write
operations.
Pipes
A pipe is a shared memory section used for communication between processes. It follows a
client-server architecture, where:
Pipes act as a conduit for information flow and have two ends:
Types of Pipes
1. Anonymous Pipes
• Unidirectional communication.
• Example:
2. Named Pipes
• Unlike anonymous pipes, named pipes have a name and can be accessed by multiple
processes.
• Any process can act as both client and server, allowing point-to-point communication.
Memory-mapped objects are a shared memory technique used by certain Real-Time Operating
Systems (RTOS) to allocate a shared block of memory accessible by multiple processes
simultaneously. Synchronization techniques are required to prevent inconsistent results
3. A process maps the entire memory block or a portion of it into its virtual address space.
4. Any read/write operations performed on this virtual address are directed to the underlying
physical memory area.
5. Another process that wants to share data maps the same memory area to its own virtual
memory space.
Windows API Calls for Memory-Mapped Objects
• CreateFileMapping():
o Parameters:
o If an object with the same name exists, it returns the handle of the existing object.
• MapViewOfFile():
o Maps a view of the memory-mapped object into the calling process’s address space.
o Parameters:
• UnmapViewOfFile():
• OpenFileMapping():
o Parameters:
The following sample code illustrates the creation and accessing of memory mapped objects across
multiple processes. The fi rst piece of code illustrates the creation of a memory mapped object with
name “memorymappedobject” and prints the address of the memory location where the memory is
mapped within the virtual address space of Process 1
The piece of code given below corresponds to Process 2. It illustrates the accessing of an existing
memory mapped object (memory mapped object with name “memorymappedobject” created by
Process 1) and prints the address of the memory location where the memory is mapped within the
virtual address space of Process 2. To demonstrate the application, the program corresponding to
Process 1 should be executed fi rst and the program corresponding to Process 2 should be executed
following Process 1
Process 1 is executed fi rst and Process 2 is executed while Process 1 waits for the user input from
the keyboard, is given in Fig. 10.19
10.7.2 Message Passing
Definition:
• Shared Memory allows large data exchange but has synchronization overhead.
• Message Passing is limited in data exchange but faster and free from synchronization issues.
10.7.2.1Message Queue:
•
Windows XP OS Implementation:
• Maintains one system message queue and one message queue per process/thread.
• A thread posts a message to the system queue, which the kernel processes and forwards to
the destination thread.
• The MSG structure contains the recipient thread handle, message parameters, timestamp,
etc.
• Asynchronous Messaging:
o The sending thread does not wait for a response. It continues execution after
posting the message.
• Synchronous Messaging:
o The sending thread waits (blocks) until the recipient thread processes the message
and responds.
10.7.2.2 Mailbox:
• Definition:
• How It Works:
o Mailboxes are useful for communication between an ISR (Interrupt Service Routine)
and a task.
• Implementation:
10.7.2.3. Signaling
• Definition:
• How It Works:
o VxWorks RTOS
▪
Remote Procedure Call (RPC)
• Definition:
o The processes can be on the same CPU or different CPUs connected over a network.
▪ The client waits (blocks) until it receives a response from the server.
▪ The client continues execution while the remote procedure runs in parallel.
• Security in RPC:
o Authentication methods include IDs, public key cryptography (DES, 3DES, etc.).
• Definition:
• Types of Sockets:
o Server Side: Listens on a specific port number and processes incoming requests.
o If both client and server run on the same CPU, they can use the same host name and
port number.
• Each process operates within its own boundary and communicates using IPC mechanisms
like shared memory and variables.
• Issues arise when multiple processes attempt to access the same resource simultaneously,
leading to unexpected results.
• Synchronization ensures that processes are aware of shared resource access, preventing
conflicts.
• Task synchronization is essential to maintain data integrity and avoid race conditions.
• Without proper synchronization, issues like data inconsistency, deadlocks, and resource
conflicts can occur.
10.8.1.1 Racing
#include “stdafx.h”
#include <windows.h>
• A race condition occurs when multiple processes access and modify shared data
concurrently, leading to unpredictable outcomes.
• In the given example, Process A and Process B both increment a shared variable (counter++),
but due to context switching, one increment is lost.
• The counter++ operation is broken into multiple low-level instructions (mov, add, mov),
making it non-atomic.
• Context switching between these instructions allows another process to modify the shared
variable before the first process completes its operation.
• As a result, Process A increments counter using an outdated value, leading to incorrect
results.
• The solution is to implement mutual exclusion—ensuring that only one process accesses the
shared variable at a time using synchronization mechanisms like locks, semaphores, or
atomic operations.
10.8.1.2 Deadlock
• Deadlock occurs when two or more processes are waiting for each other to release
resources, causing a standstill where none can proceed.
• It is similar to a traffic jam where vehicles block each other at an intersection.
Example:
•
Cause: Mutual exclusion (resources are locked by the process using them).
Solution:
2. Hold and Wait – A process holding a resource waits for additional resources held by other
processes.
3. No Resource Preemption – Resources cannot be forcibly taken from a process; they must be
released voluntarily.
4. Circular Wait – A circular chain of processes exists, where each process is waiting for a
resource held by the next.
• Prevention – Modify system conditions to avoid deadlocks (e.g., remove circular wait).
• Detection & Recovery – Identify deadlocks and recover (e.g., terminate a process).
•
Deadlock Avoidance
Deadlock Prevention
• Livelock is a condition where processes continuously change their state in response to each
other but fail to make any real progress.
• Unlike deadlock, where processes remain stuck in a waiting state forever, livelock processes
are actively executing but still unable to complete their tasks.
• Example: Two people trying to pass each other in a narrow corridor, repeatedly moving in
the same direction to give way but still blocking each other.
Starvation
• Starvation occurs when a process is unable to gain access to required resources for an
extended period due to unfair scheduling policies.
• This often happens in systems that prioritize high-priority tasks, causing lower-priority tasks
to be continuously postponed.
• Example: In a CPU scheduling system, if high-priority tasks keep arriving, a low-priority task
may never get CPU time.
• Solution: Use aging techniques, where a process’s priority gradually increases over time,
ensuring it eventually gets the required resources.
• Traditional busy waiting for mutual exclusion wastes CPU time and increases power
consumption.
• Not suitable for battery-powered embedded systems due to high energy usage.
• Alternative: Sleep & Wakeup mechanism, where processes go into a blocked state when
they can't access the critical section.
• The process that owns the critical section sends a wakeup signal once it releases the
resource.
• A process acquires a semaphore before using a resource and releases it after use.
Types of Semaphores
2. Counting Semaphore
o Maintains a count from zero to a maximum value, controlling the number of active
users.
o Example: Hard disk access, where different sectors can be used concurrently.
o If full, they wait for a slot and are notified when space is available.
1. Counting Semaphores
• Example: Shared hardware like a printer, where only a limited number of users can access it
simultaneously.
• State of a mutex:
• Hotel rooms are shared resources, accessible only to one user at a time.
• When a user vacates, the key is returned, and the room is made available for the next user.
3.
The selection of a Real-Time Operating System (RTOS) for an embedded system is a crucial
decision that depends on functional and non-functional requirements. Below are the key
factors to consider:
1. Functional Requirements
Processor Support
• Not all RTOSs support every processor architecture.
• Ensure compatibility with the target processor.
Memory Requirements
• RTOS requires ROM (for OS files, usually stored in FLASH) and RAM (for OS services).
• Since embedded systems are memory-constrained, choose an OS with minimal ROM/RAM
requirements.
Real-Time Capabilities
• Not all embedded OSs are real-time.
• Evaluate task scheduling policies and real-time standards compliance of the OS.
Kernel and Interrupt Latency
• RTOS kernels may disable interrupts while executing services, causing latency.
• For high-response embedded systems, latency should be minimal.
Inter-Process Communication & Task Synchronization
• Different OS kernels offer various communication and synchronization mechanisms.
• Some provide solutions for priority inversion during resource sharing.
Modularization Support
• Some RTOSs allow selecting only necessary modules, reducing footprint.
• Example: Windows CE is highly modular.
Networking & Communication Support
• Ensure the OS provides built-in network stacks and driver support for required interfaces.
Development Language Support
• Some RTOSs include Java Virtual Machine (JVM) or .NET Compact Framework (NETCF) for
Java/.NET applications.
• If not included, check third-party availability.
2. Non-Functional Requirements
Custom vs. Off-the-Shelf OS
• Choose between:
1. Custom-built OS (tailored but costly & time-consuming).
2. Off-the-shelf OS (Commercial or Open Source).
• Consider development cost, licensing fees, and time-to-market.
Cost
• Evaluate the total cost, including development, licensing, and maintenance.
Development & Debugging Tools
• Some RTOSs offer limited development/debugging tools, impacting ease of use.
• Ensure adequate tool support for the OS.
Ease of Use
• Some RTOSs have steeper learning curves.
• Consider how easy it is to develop, deploy, and manage applications.
After-Sales Support
• For commercial RTOS, check for:
o Bug fixes & security patches.
o Technical support (email, phone, etc.).
o Production issue resolution.
Chapter 12:
Integration Testing of Embedded Hardware and
Firmware
1. Integration Testing Step
o "Integration testing of the embedded hardware and firmware is the immediate step
following the embedded hardware and firmware development."
2. Embedded Hardware
o "The final embedded hardware constitutes a PCB with all necessary components
affixed to it as per the original schematic diagram."
3. Embedded Firmware
o "The target embedded hardware without embedding the firmware is a dumb device
and cannot function properly."
o "If you power up the hardware without embedding the firmware, the device may
behave in an unpredicted manner."
5. Unit Testing
o "As described in the earlier chapters, both embedded hardware and firmware should
be independently tested (Unit Tested) to ensure their proper functioning."
o "As far as the embedded firmware is concerned, its targeted functionalities can
easily be checked by the simulator environment provided by the embedded
firmware development tool’s IDE."
o "By simulating the firmware, the memory contents, register details, status of various
flags and registers can easily be monitored and it gives an approximate picture of
'What happens inside the processor/controller and what are the states of various
peripherals' when the firmware is running on the target hardware."
o "The IDE gives necessary support for simulating the various inputs required from the
external world, like inputting data on ports, generating an interrupt condition, etc."
o "This really helps in debugging the functioning of the firmware without dumping the
firmware in a real target board."
Integration of hardware and firmware involves embedding firmware into the target hardware board.
The commands to control the programmer are sent from the utility program to the programmer
through the interface (Fig. 12.2).
The sequence of operations for embedding the fi rmware with a programmer is listed below.
1. Connect the programming device to the specifi ed port of PC (USB/COM port/parallel port)
2. Power up the device (Most of the programmers incorporate LED to indicate Device power up.
Ensure that the power indication LED is ON)
3. Execute the programming utility on the PC and ensure proper connectivity is established
between PC and programmer. In case of error, turn off device power and try connecting it again
4. Unlock the ZIF socket by turning the lock pin
5. Insert the device to be programmed into the open socket as per the insert diagram shown on
the programmer
10. Wait till the completion of programming operation (Till busy LED of programmer is off)
11. Ensure that programming is successful by checking the status LED on the programmer
(Usually ‘Green’ for success and ‘Red’ for error condition) or by noticing the feedback from the
utility program
12. Unlock the ZIF socket and take the device out of programmer
Now the fi rmware is successfully embedded into the device. Insert the device into the board,
power up the board and test it for the required functionalities.
• In-System Programming (ISP) allows firmware to be embedded without removing the chip
from the board.
• It is a flexible and easy method but requires ISP-supported target devices.
• No extra hardware is needed apart from the PC, ISP cable, and ISP utility.
• The target board connects to a PC via Serial Port, Parallel Port, or USB using serial
communication protocols like JTAG or SPI.
• The device must enter ISP mode to receive commands, erase, and reprogram memory
before resuming normal operation.
Devices with SPI ISP support have a built-in SPI interface, and the on-chip EEPROM or FLASH memory
is programmed through this interface.
➢ The PC acts as the master, and the target device acts as the slave in ISP. The MOSI pin
receives program data, while the MISO pin sends acknowledgments.
➢ The SCK pin provides the clock signal for data transfer, and a utility program on the PC
generates these signals.
➢ If the target device operates under 5V logic, it can be directly connected to the parallel port
of the PC, without additional hardware for signal conversion.
➢ Standard SPI-ISP utilities are available online, so no custom programming is needed—just
connect the pins as required.
➢ The target device must be powered up in a predefined sequence to enable ISP mode.
The power up sequence for In System Programming for Atmel’s AT89S series microcontroller family is
listed below.
• Apply supply voltage between VCC and GND pins of target chip.
• Set RST pin to “HIGH” state.
• If a crystal is not connected across pins XTAL1 and XTAL2, apply a 3 MHz to 24 MHz clock to
XTAL1 pin and wait for at least 10 milliseconds
• Enable Serial Programming: Send the Programming Enable serial instruction to MOSI/P1.5.
• Clock Frequency Requirement: The shift clock at SCK/P1.7 must be less than CPU clock at
XTAL1 divided by 40.
• Programming Process:
➢ The write cycle is self-timed and takes less than 2.5 ms at 5V.
• Verification: Any memory location can be verified using the Read instruction, which returns
the stored data at MISO/P1.6.
• Final Step: After programming, set RST pin low or turn off and on the chip power supply to
start normal operation.
12.1.3 In Application Programming ( IAP)
Purpose: IAP allows firmware running on the target device to modify a selected portion of
the code memory, but it is not used for initial firmware embedding.
Use Cases: It is commonly used for updating calibration data, look-up tables, and other
stored information in code memory.
Boot ROM API:
• The Boot ROM resident API provides functions for programming, erasing, and reading Flash
memory during ISP mode.
• These API instructions can also be used by end-user firmware for IAP operations.
Execution Mechanism:
• Specific registers must be set as required for an operation.
• A call is made to a common entry point to execute the operation.
• After execution, control returns to the user’s firmware, like a subroutine call.
Memory Shadowing:
• The Boot ROM is shadowed with user code memory within its address range.
• A status bit controls whether accesses go to Boot ROM or user code memory.
• Before calling the IAP function, the user must set the status bit to ensure correct memory
access.
12.2 BOARD BRING UP
• Now the firmware is embedded into the target board using one of the programming
techniques described above.
• The first verification is to make sure that the processor is fetching the code and the firmware
execution is happening in the expected manner.
• When the hardware PCB is assembled, most designers, in their eagerness to get the project
rolling, will try to power it on immediately.
• The first check is to look over the board and check for any missing parts, loose or partly
soldered components, or shorts in the path.
• Make sure that various power lines in the board (2.2V, 3.3V, 5.0V etc.) are up, within the spec
limits, and clean.
• Certain controllers/processors with multiple power inputs will have power sequencing
requirements.
• Clocks play a critical role in the boot-up of the system, and all clocks must be up and running
within spec values.
• Monitor the different interconnect buses (like I2C) to ensure they meet electrical
specifications and protocol requirements.
• Bring-up of prototype/evaluation/production versions is one of the most important steps in
embedded product design.
• The bring-up process involves performing a series of validations in a controlled environment
to verify hardware and firmware functionality.