Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

Embedded hardware and software

Practical notes on how embedded hardware and software interact: definitions, performance formulas (bus bandwidth, DMA, interrupts, Amdahl), worked numerical examples and exam focus.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Embedded hardware and software are designed together so a device meets cost, power and timing constraints. Engineers use these concepts when choosing an MCU/SoC, deciding what to implement in hardware vs firmware, sizing buses and memories, and writing drivers/ISRs so the system meets real-time requirements.

Key ideas

Start from first principles and simple definitions.

  • Embedded system: a computing system that is part of a larger system, dedicated to specific control or monitoring tasks. (Contrast with a general-purpose computer.)
  • Firmware: software that is closely tied to hardware, stored in non-volatile memory, providing low-level control (startup, device drivers). It runs on the MCU/CPU.
  • MCU (microcontroller) and SoC (system on chip): an MCU is a chip containing CPU core(s), memory and peripherals; an SoC may integrate more complex IP blocks (GPU, accelerators).
  • Peripheral: a hardware device (UART, SPI, ADC) connected to the CPU for I/O.
  • Bus: a set of signal lines for data, address and control used to connect CPU, memory and peripherals. Distinguish shared bus and point-to-point interconnects (AMBA is a family of bus protocols — see the AMBA bus topic).
  • Memory-mapped I/O: peripheral registers appear at memory addresses; CPU reads/writes them like memory. An alternative is port-mapped I/O.
  • Register: a small fast storage element inside CPU or peripheral used for configuration and status.
  • Interrupt: an asynchronous hardware signal that stops normal program flow and runs an ISR (interrupt service routine).
  • DMA (direct memory access): hardware that transfers data between memory and peripheral without continuous CPU involvement; acts as a bus master.
  • Hardware–software co-design: the process of partitioning functionality between hardware blocks and software routines to meet constraints (power, cost, latency). Use Amdahl's law to estimate gains from accelerating part of the code.
  • Device driver: software component that controls a peripheral, hides hardware details from higher-level code. A HAL (hardware abstraction layer) provides an API isolating hardware differences.

Exact statement (Amdahl's law) and assumptions used in partition decisions:

  • Amdahl's law: if fraction f of the execution time of a task can be accelerated by factor S (S > 1), then overall speedup is Speedup = 1 / ((1 - f) + f / S). Assumptions: execution time is additive; speedup affects only fraction f; other overheads (communication, setup) are ignored unless included in f.

Interrupt timing and CPU load assumptions:

  • Interrupt latency: time from the peripheral asserting the interrupt to the first instruction of the ISR executing. Components: detect + route delay (hardware), context save time, pipeline refill (for pipelined CPUs) and any interrupt nesting overhead.
  • Interrupt service time: ISR execution time including prologue/epilogue and device handling. Interrupt response time = interrupt latency + interrupt service time until the ISR completes.
  • CPU load from periodic tasks and ISRs: for a set of periodic tasks or interrupt-driven jobs, CPU utilization U = sum (C_i / T_i) where C_i is execution time and T_i is period/average interarrival. For schedulability, U must be less than 1 (or the scheduler bound for certain algorithms). For EDF scheduling, a necessary and sufficient condition is U ≤ 1; for RM with n tasks, a sufficient bound is U ≤ n(2^(1/n) − 1).

Bus performance and bandwidth:

  • Bandwidth (raw) of a parallel synchronous bus = (data_width_in_bytes) × (clock_frequency). If the bus transfers multiple data beats per clock (e.g., DDR), multiply by transfers_per_clock. Effective bandwidth is raw × efficiency (accounting for wait states, arbitration, protocol overhead).
  • Transfer time = data_size / effective_bandwidth. Be careful to use same units (bytes and seconds).

Cache/memory effective access time (EAT):

  • EAT = hit_time + (1 − hit_rate) × miss_penalty. Define hit_time (time to read when data is in cache) and miss_penalty as the additional time beyond hit_time to fetch from lower memory. Assumes independent accesses.

Diagrams to draw in exams (describe exactly what to draw):

  • Draw a block diagram labelled: CPU core (label registers, ALU), instruction memory (flash/ROM), data memory (RAM), system bus (address, data, control lines), DMA controller as bus master, peripherals (UART, SPI, ADC) connected to bus, interrupt lines from peripherals to CPU interrupt controller. Show memory-mapped addresses for a peripheral register and annotate "MMIO region".

Formulas

Bandwidth_raw = data_width_bytes × f_clock — data_width_bytes in bytes, f_clock in Hz, result in bytes/s; applies to synchronous parallel bus. Bandwidth_effective = Bandwidth_raw × efficiency — efficiency (0..1) accounts for protocol overhead and wait states. Transfer_time = data_size_bytes / Bandwidth_effective — data_size_bytes in bytes, Bandwidth_effective in bytes/s, result in s. Amdahl_speedup = 1 / ((1 - f) + f / S) — f is fraction (0..1) of execution time accelerated, S is speedup factor of that fraction, unitless. CPU_utilization = Σ (C_i / T_i) — C_i is execution time (s) of job i, T_i is period or average interarrival (s); unitless fraction of CPU capacity. EAT = hit_time + (1 - hit_rate) × miss_penalty — miss_penalty is the additional time beyond hit_time; times in seconds, hit_rate [0..1], result in seconds. Interrupt_load = Σ (ISR_exec_time_j / avg_interarrival_j) — ISR_exec_time_j in s, avg_interarrival_j in s, unitless.

Worked examples

Example 1 — Bus bandwidth and transfer time Problem: A 32-bit parallel bus runs at 50 MHz. Protocol overhead reduces effective cycles to 80% of raw. How long to transfer 1 MiB (1 MiB = 1,048,576 bytes)? Steps:

  1. Data width = 32 bits = 4 bytes.
  2. Raw bandwidth = 4 bytes × 50×10^6 Hz = 200×10^6 bytes/s = 200 MB/s.
  3. Effective bandwidth = 200×10^6 × 0.8 = 160×10^6 bytes/s = 160 MB/s.
  4. Transfer_time = 1,048,576 bytes / 160×10^6 bytes/s = 0.0065536 s = 6.5536 ms. Answer: 6.5536 ms.

Example 2 — DMA vs CPU copy (compare time and CPU cycles used) Problem: Copy 10 MB of data from peripheral to RAM.

  • CPU can copy 1 byte in 4 cycles (load, store, addressing and loop overhead) and runs at 200 MHz.
  • A DMA controller provides 150 MB/s effective transfer with small CPU setup overhead of 2000 cycles. Compute time and CPU cycles used for both methods. Steps CPU copy:
  1. Time per byte = 4 cycles / 200×10^6 s = 20×10^−9 s = 20 ns/byte.
  2. Throughput_CPU = 1 / (20 ns) = 50×10^6 bytes/s = 50 MB/s.
  3. Time_CPU = 10×2^20 bytes / (50×10^6 bytes/s) = 10,485,760 / 50,000,000 = 0.2097152 s = 209.7152 ms.
  4. CPU cycles used = time × clock = 0.2097152 s × 200×10^6 Hz = 41,943,040 cycles. Steps DMA copy:
  5. DMA time = 10,485,760 bytes / 150×10^6 bytes/s = 0.06990507 s = 69.9051 ms.
  6. CPU cycles for setup = 2000 cycles (given) = 2000 / 200×10^6 s = 10×10^−6 s = 10 µs negligible compared to transfer.
  7. CPU cycles used ≈ 2000 cycles. Answers: CPU copy time = 209.7152 ms, CPU cycles = 41,943,040 cycles. DMA time = 69.9051 ms, CPU cycles ≈ 2,000 cycles. Note: the assumption of 4 cycles/byte and DMA setup cycles must be checked for a real system (verify list below).

Example 3 — Amdahl for hardware acceleration Problem: 30% of execution time can be moved to a hardware accelerator giving a 10× speedup for that part. What is overall speedup? Steps:

  1. f = 0.30, S = 10.
  2. Speedup = 1 / ((1 - 0.30) + 0.30 / 10) = 1 / (0.70 + 0.03) = 1 / 0.73 = 1.369863. Answer: 1.3699× overall speedup.

Common mistakes

  • Ignoring bus/protocol overhead and assuming 100% efficiency.
  • Forgetting interrupt prologue/epilogue and nesting when estimating ISR time and CPU load.
  • Using average times where worst-case is required for real-time guarantees (schedulability needs worst-case execution times for hard real-time).
  • Applying Amdahl's law without including communication/setup costs (f must include those costs if they are significant).
  • Failing to declare memory-mapped I/O registers as volatile in C, causing the compiler to optimize away required reads/writes.

For your exam

Types of questions you will see: definitions, short notes, block-diagram sketches, derivations (Amdahl, bandwidth), numericals (bandwidth, transfer times, CPU utilization), and small code/driver design outlines (ISR pseudo-code, DMA setup sequence). What full-marks answers include:

  • Clear definitions of terms used (e.g., interrupt, DMA, memory-mapped I/O) before employing them.
  • For derivations: state assumptions, show algebraic steps, simplify and comment on limits (e.g., what happens when f → 1 in Amdahl).
  • For numericals: show unit conversions, write formula then substitute numbers with units, carry units through to final answer and box the final numeric value with correct units.
  • For diagrams: label every block and signal line, indicate address/data/control lines, mark which components are bus masters, and annotate memory-mapped address ranges.
  • For design/algorithm questions: show sequence steps (e.g., steps to initialize DMA: set source/destination/length, start transfer, wait or use interrupt), mention error handling and relevant registers.

Quick check

  1. What is memory-mapped I/O?
  2. State Amdahl's law formula and explain what f and S mean.
  3. How to compute effective transfer time if raw bandwidth is B_raw and efficiency is η for transferring N bytes? Answers: Memory-mapped I/O = peripheral registers mapped to memory address space so CPU reads/writes like memory; Amdahl: Speedup = 1/((1−f)+f/S) where f is fraction accelerated and S is speedup of that part; Transfer_time = N / (B_raw × η).

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?