CA and OS
On this page
Computer Architecture
Computer Parts
Part of Computer | Description |
---|---|
Central Processing Unit (CPU) | Executing instructions and performing arithmetic operations on Instructions Set Architecture (ISA) like ARM (Mobile), x86 (Traditional Desktop), RISC (Open Source). Each ISA has its own assembly language. |
Random Access Memory (RAM) | Main memory for storing data and instructions. Quick but volatile. |
Read Only Memory (ROM) | Read-only memory for storing instructions. Slow but non-volatile. Mask ROM can’t be overwritten while flash ROM can. |
Hard Drive (SSD, HDD) | Store data |
Graphics Processing Unit (GPU) | Processing repeated tasks in parallel efficiently |
Types of Chips
Type | Description | Example |
---|---|---|
Microprocessor | CPU on chip. Does not include memory, storage, IO | Desktop CPU |
Microcontroller | Single-chip computer that integrates a CPU, memory and peripherals | Arduino |
SoC (System on a Chip) | Integrates one or more CPU, RAM, microcontrollers into one system | Smartphone, tablet, laptop |
Tips
Rasberry PI contains SoC
Connectivity
Bus | Type | Use Case | Key Traits |
---|---|---|---|
SPI (Serial Peripheral Interface) | Synchronous serial | Fast comms to flash, sensors | Full duplex, needs CS, MOSI, MISO, SCLK |
I2C (Inter-Integrated Circuit) | Synchronous serial | Low-speed sensors, EEPROM | Only 2 wires (SDA + SCL), addressable slaves |
UART (Universal Async Receiver Transmitter) | Asynchronous serial | Serial consoles, Bluetooth modules | Simple 2-wire (TX/RX), no clock line |
CAN (Controller Area Network) | Message-based | Automotive, industrial | Robust, supports priorities and multi-master |
- Memory-Mapped I/O memory address that is mapped with a peripheral to communicate.
- Debouncing remove noise from signal (hardware and software method available)
Firmware
Firmware is the system lifecycle software program that runs on the chip. It consist of two part, bootloader and firmware. Bootloader is a small program that loads the firmware into the chip when booted.
The firmware is coded in C/C++ or assembly language and compiled into a binary machine code through compiler like gcc. The compiler will need to know the chip specification (ISA, cores, memory) to compile the binary code correctly. The machine code then is stored in ROM.
Take a bluetooth module as example. It consists CPU, RAM and ROM with firmware stored. When it is booted, the bootloader will call the CPU to load the firmware from ROM into RAM and execute the firmware line by line.
For Arduino, the C/C++ code we burn into SD card is the firmware. The bootloader in Arduino loads the firmware in SD card. It doesn’t have OS.
Embedded System
Embedded system is a system that integrates hardware and software to perform a specific task. Take rasberry pi as an example. The linux OS and bootloader is running on the SoC. It is a embedded system.
When rasberry pi is booted, the bootloader load bootcode.bin
from ROM or EEPROM to initialze RAM. Then the bootcode will call start.elf
in SD card to call firmware on GPU. It reads config.txt
, kernel.img
and .dtb
on SD card.
The configuration config.txt
determime which kernel image to use, which device tree .dtb
to use, and the memory allocation, etc. Device tree tells the kernel about the hardware configuration like architecture, GPIO address, etc. for kernel initialization.
The kernel image must be compatible with SoC family like x32 or x64, arm or x86. The kernel image is coded in c and compiled by compiler like gcc.
A same CPU/SoC can be integrated to different type of board. The need of device tree to tell a GPIO driver in kernel where is the address of GPIO (General-Purpose Input/Output) signal pin. A driver is a piece of software in kernel that provides API for OS and controls the hardware.
PC Boot
The steps of booting a PC:
- Power on → CPU runs BIOS (Basic Input/Output System) / UEFI firmware. This was preinstalled on the motherboard.
- BIOS initialize memory and hardware.
- BIOS loads bootloader like GRUB into memory.
- Bootloader choose OS kernel.
- kernel loads and initialize root filesystem.
- kernel scans devices using ACPI (Advanced Configuration and Power Interface) and loads drivers. ACPI is like device tree.
- Login to user space.
Low-Level Development
Tool | Use |
---|---|
Compiler: gcc, clang | Convert .c /.cpp to .o |
Assembler | Convert .asm to .o |
Linker | Link .o files into final binary using linker script |
Debugger: gdb | GNU Debugger for C/C++ |
OpenOCD | Open On-Chip Debugger |
Flasher | Write binary into the chip |
Build System: make, cmake, npm | Automate above steps |
QEMU | Emulator |
JLink Debugger | A very eficient piece of hardware, connects to your PC and the chip for debugging |
Low-Level Analyzing
Tool | Use |
---|---|
Oscilloscope | View voltage and current to check a GPIO pin |
Logic Analyzer | View digital signal over time — usually across multiple lines. Great for reverse engineering, debudding SPI, I2C, … |
Some CPU have a tract unit that records every instruction executed. Debugger use symbol + memory maps to remember the address of a memory location. CPU execution is abstract using symbol tables and IDE/GDB integration.
Real Time Operating System (RTOS)
An OS kernel designed for embedded systems that need predictable timing and task scheduling.
| RTOS kernel | Who Made It | Notes | | FreeRTOS | Amazon | Most popular RTOS ever. Open-source, tiny (<10KB), easy to port. | | Zephyr | Linux Foundation | Modular, modern, built for IoT. More complex, includes full drivers, POSIX-ish API. | | CMSIS-RTOS RTX | Arm | Integrated in ARM ecosystem. | | TI-RTOS | Texas Instruments | TI-specific, optimized for their chips. Not as portable. |
Operating System
The manager of computer resources and processes.
A program is a set of instructions like an application. A process is a running instance of a program like multile instances of a browser, it has it’s own memory. A thread is a lightweight unit of execution within a process, they share the memory of a process and allows cncurrency. A task is a more general term that can refer to either a process or a thread, represent a unit of work.
Task/Threads Scheduler
Decide which runs next based on round-robin, priority, etc. Interrupts to switch tasks (context switch).
Mutexes/Semaphores
Mutex is a lock so only one thread can own it. Used to protect shared resources. A thread spinlock to acquire lock repeateadly. Semaphore is a counter that allow N threads to pass or wait.
IPC (Inter-Process Communication)
Using message queues, shared memory, socket, signal, semaphore, event flags.
Memory Management
Keep track of who owns what memory. A paging/virtual memory maps shorter virtual memory to physical memory.
ISR(Interrupt Service Routine)
Signal kernel to run an interrupt. Interrupt vector table maps an interrupt trigger to a handler function which tells what to do.
POSIX(Portable Operating System Interface)
A standard API for UNIX-like OS. It’s a contract between C and OS kernel.
Cache
Cache Type | Role |
---|---|
CPU cache (L1/L2/L3) | Stores recently used memory |
Disk cache | Stores recently accessed disk blocks |
Filesystem cache | Buffers file reads/writes |
Web/app cache | High-level user-space caching |
- L1: Closest to core, fastest, smallest (~32KB)
- L2: Shared per core or pair (~256KB-1MB)
- L3: Shared across all cores (~2MB-64MB)
File System
FS | Notes |
---|---|
ext4 | Default in Linux, simple, reliable and efficient |
FAT32/exFAT | Ubiquitous, low-overhead, compatiblity, used for flash drives and SD cards |
NTFS | Windows default, complex and advanced |
APFS/HFS+ | Apple systems |
LittleFS / SPIFFS | For embedded systems (flash memory!) |