MEC302

MEC302 期末复习资料

0. 期末复习范围总览

Revision 课件明确说:Lectures 1–11 all relevant。也就是说,前面所有课件都可能考。
但从 L12 给的 sample questions 来看,重点大概集中在这些类型:

Lecture 主题 常见考法
L1 Embedded Systems / CPS 定义、结构、例子
L2 Continuous Dynamics 建模、微分方程、线性化、系统性质
L3 Discrete Dynamics FSM、Mealy/Moore machine、状态图
L4 Sensors & Actuators 选传感器、ADC/DAC、sensor metrics
L5 Embedded Processors CPU、memory、bus、address calculation
L6 Memory Architecture volatile/non-volatile、memory hierarchy
L7 Multitasking & Scheduling threads/processes、scheduler、preemptive/non-preemptive
L8 LTL / Model Checking temporal operators、formal specification
L9 Interfacing power、clock、reset、boot、interrupt/polling
L10 Serial Communication serial/parallel、bit/baud、simplex/duplex、differential link
L11 Evaluation evaluation/validation、multi-objective optimization、WCET、dependability

1. L1 Embedded Systems / Cyber-Physical Systems

1.1 Embedded System 是什么?

Embedded system 是嵌入到更大产品或系统中的计算机系统,通常用于完成某个特定功能,而不是像 PC 一样作为通用计算机使用。

可以这样写:

An embedded system is a computer system integrated into a larger device or product to perform dedicated functions. It usually consists of hardware, software, sensors, actuators, memory, and communication interfaces.

关键词:

  • dedicated function

  • integrated into larger system

  • hardware + software

  • real-time / resource-constrained

  • interacts with physical environment

例子:

  • washing machine controller

  • car engine control unit

  • drone flight controller

  • smart watch

  • robot controller

  • medical device


1.2 Cyber-Physical System, CPS

CPS 是计算和物理过程紧密结合的系统。

可以这样写:

A cyber-physical system integrates computation, communication, and physical processes. Sensors measure the physical world, the embedded computer processes the data, and actuators affect the physical system.

典型结构:

1
2
3
4
5
Physical world
↓ sensors
Embedded computer / controller
↓ actuators
Physical world changes

例子:

  • self-driving car

  • quadrotor drone

  • robot arm

  • smart grid

  • industrial automation system


1.3 Embedded System 的核心组成

一般包括:

1
2
3
4
5
6
7
8
9
CPU / processor
Memory
I/O interface
Sensors
Actuators
Power source
Clock
Communication interface
Software / firmware

考试如果问 “structure of embedded computer system”,可以画:

1
2
3
4
5
6
7
8
9
        Sensors

Input interface / ADC

CPU / Microcontroller ↔ Memory

Output interface / DAC / PWM

Actuators

2. L2 Continuous Dynamics

Revision 课件特别强调:

Many embedded systems are also dynamic physical systems.

也就是说,机器人、无人机、车辆、机械系统不只是计算机系统,还是有物理动态行为的系统。


2.1 Continuous Dynamics 是什么?

Continuous dynamics 用微分方程描述系统随时间连续变化的行为。

核心公式:

$\dot{x}(t)=f(x(t),u,t)$
其中:

  • (x(t)):state,系统状态

  • (\dot{x}(t)):state derivative,状态变化率

  • (u):input/control input

  • (t):time

可以这样写:

Continuous dynamics describes the evolution of a physical system over continuous time using differential or integral equations. It is suitable for mechanical systems, electrical circuits, chemical processes, biological systems, etc.


2.2 Dynamic Model 的常见来源

主要是物理定律,例如:

  • Newton’s second law:

$F = ma = m\ddot{x}$

  • rotational dynamics:

$\tau = I\alpha$

  • electrical circuits:

$V = IR$

如果题目让你 derive dynamics,一般步骤是:

  1. Draw free-body diagram.

  2. Define coordinates and positive directions.

  3. List all forces/torques.

  4. Apply Newton’s law.

  5. Rearrange into differential equations.

  6. Define state variables if needed.


2.3 系统性质:Model Properties

Revision 课件说,为了设计有效控制,系统最好满足:

Causal, Not Memoryless, Linear, Time Invariant and Stable

这几个必须会解释。

1. Causality

Causal system:输出只依赖当前和过去输入,不依赖未来输入。

可以写:

A system is causal if its output at the current time depends only on current and past inputs, not future inputs.

例如真实物理系统一般都是 causal,因为未来还没发生。


2. Memory / Memoryless

Memoryless system:输出只依赖当前输入。

例如:

$y(t)=2x(t)$

是 memoryless。

Not memoryless system:输出依赖过去状态或过去输入。

例如:

$\dot{x}(t)=f(x(t),u(t))$

这类动态系统通常不是 memoryless,因为当前状态包含过去信息。

可以写:

A dynamic physical system is usually not memoryless because its current output depends on the current state, and the state is a summary of past behavior.


3. Linearity

线性系统满足 superposition:

$f(ax_1+bx_2)=af(x_1)+bf(x_2)$

简单写法:

A system is linear if the output is proportional to the input and the superposition principle holds.

非线性例子:

$y=x^2$

$\sin\theta$


4. Time Invariance

如果系统行为不随时间改变,则是 time-invariant。

可以写:

A system is time-invariant if its behavior does not explicitly depend on time. The same input applied later produces the same output shifted in time.

如果方程中显式出现 (t),例如:

$\dot{x}=tx+u$

则通常是 time-varying。


5. Stability

课件提到 BIBO stability:

Bounded input leads to bounded output.

即:

如果输入有限,输出也有限,那么系统稳定。

可以写:

A system is stable if bounded input signals always lead to bounded output signals.


2.4 Linearization 线性化

Revision 课件特别强调:

  • Jacobian linearization

  • small angle linearization

  • assignment 1 里的 cart-pole / drone / robot locomotion 都和这个思想有关

1. 为什么要线性化?

真实物理系统通常是 nonlinear 的,例如:

$\sin\theta,\quad \cos\theta,\quad x^2,\quad \dot{x}^2$

但很多控制方法,例如 LQR、linear controller,需要线性模型。

所以在某个 operating point 附近,把 nonlinear system 近似成 linear system。


2. Small angle approximation

当 (\theta) 很小时:

$\sin\theta \approx \theta$

$\cos\theta \approx 1$

$\tan\theta \approx \theta$

这个在 assignment 1 cart-pole 里面很重要。


3. Jacobian linearization

非线性系统:

$\dot{x}=f(x,u)$

在 equilibrium point ((x_0,u_0)) 附近线性化:

$\delta \dot{x}=A\delta x+B\delta u$

其中:

$A=\frac{\partial f}{\partial x}\bigg|_{x_0,u_0}$

$B=\frac{\partial f}{\partial u}\bigg|_{x_0,u_0}$

可以这样解释:

Jacobian linearization approximates a nonlinear system by its first-order Taylor expansion around an operating point.


2.5 典型题:Draw FBD and derive dynamics

答题框架:

1
2
3
4
5
1. Define coordinates.
2. Draw all forces.
3. Apply Newton’s second law.
4. Write equations of motion.
5. Rearrange into state-space form if required.

如果是质量-弹簧-阻尼系统:

1
2
3
4
forces:
spring force = -kx
damping force = -cẋ
external force = u

动力学:

$m\ddot{x}=u-c\dot{x}-kx$

整理:

$m\ddot{x}+c\dot{x}+kx=u$

state 选:

$x_1=x,\quad x_2=\dot{x}$

则:

$\dot{x}_1=x_2$
$\dot{x}_2=\frac{1}{m}(u-cx_2-kx_1)$

3. L3 Discrete Dynamics

3.1 Discrete Dynamics 是什么?

Discrete dynamics 不是连续时间变化,而是状态按离散 step 或 event 改变。

可以写:

Discrete dynamics describes systems whose states evolve through discrete transitions rather than continuously in time. Such systems are commonly modeled by finite-state machines.

例子:

  • vending machine

  • traffic light

  • elevator

  • digital lock

  • parking lot counter


3.2 State 的定义

课件里强调:

State is a summary of the past.

可以写:

The state of a system represents its condition at a certain moment. It determines how the system reacts to future inputs and summarizes the relevant past history.

例如 parking lot counter 的 state 可以是当前车位数量:

$states={0,1,2,\dots,M}$

3.3 FSM 五元组

FSM 通常可以写成:

$FSM=(S,I,O,\delta,\lambda)$
其中:

  • (S):states

  • (I):inputs

  • (O):outputs

  • ($\delta$):transition function

  • ($\lambda$):output function

更完整可以加 initial state:

$FSM=(S,I,O,\delta,\lambda,s_0)$

3.4 FSM 图中常见元素

元素 含义
state 系统当前状态
transition 状态转移
guard 判断转移是否发生的条件
action 转移时产生的输出或执行动作
initial state 初始状态
default transition 没有其他 transition enabled 时发生

3.5 Mealy Machine vs Moore Machine

Revision 课件 sample question 明确说可能让你设计 Mealy machine。

Mealy Machine

Mealy machine 的输出在 transition 上产生。

特点:

Output depends on current state and input.

可以写:

$output = \lambda(state,input)$
图上一般写:

1
input / output

例如:

1
press / light_on

Moore Machine

Moore machine 的输出由 state 决定。

特点:

Output depends only on the current state.

可以写:

$output = \lambda(state)$
图上通常在 state 里面写 output。


对比表

项目 Mealy Moore
输出取决于 state + input state only
输出位置 transition 上 state 内
响应速度 通常更快 通常慢一个状态
状态数 可能更少 可能更多
是否 strict causal 不一定 通常 strict causal

考试如果让画 Mealy machine,要记得把 output 写在 arrow 上,不要只写在 state 里。


3.6 Hybrid System

Hybrid system 同时有:

  • continuous dynamics

  • discrete dynamics

例如:

  • thermostat:温度连续变化,但 heater on/off 是离散状态

  • bouncing ball:位置连续变化,碰撞是离散事件

  • robot:机械运动连续,任务阶段离散

可以写:

A hybrid system combines continuous dynamics with discrete state transitions. It is useful for modeling cyber-physical systems.


4. L8 Linear Temporal Logic and Model Checking

Revision 里把 L8 放在 L3 后面,因为它和 FSM、formal specification 关系很强。


4.1 LTL 是什么?

LTL = Linear Temporal Logic。

它不仅能表达普通逻辑,还能表达时间顺序上的性质。

可以写:

Linear Temporal Logic is a formal language used to specify temporal properties of system behavior over traces. It extends propositional logic with temporal operators such as always, eventually, next, and until.


4.2 普通逻辑连接词

符号 含义
(\neg p) not p
(p \land q) p and q
(p \lor q) p or q
(p \Rightarrow q) if p then q

4.3 Temporal Operators

常见 LTL temporal operators:

符号 名称 含义
(X p) next 下一步 p 成立
(F p) eventually / finally 未来某时刻 p 成立
(G p) globally / always 从现在起 p 一直成立
(p U q) until p 一直成立直到 q 成立

4.4 常见英文转 LTL

1. Always p

“p is always true”

$G p$

2. Eventually p

“p will eventually happen”

$F p$

3. Whenever p happens, q eventually happens

“每当 p 发生,之后 q 最终会发生”

$G(p \Rightarrow Fq)$
这是非常常考的模式。

4. p never happens

“p 永远不会发生”

$G(\neg p)$

5. p must hold until q happens

“p 一直成立直到 q 发生”

$p U q$

6. If p, then q in next step

$G(p \Rightarrow Xq)$

4.5 课件里的例子

例 1

Whenever the door is locked, it will not open until someone unlocks it.

定义:

  • (p):door is locked

  • (q):door is open

  • (r):someone unlocks it

可以写成:

$G(p \Rightarrow (\neg q \ U \ r))$
意思是:只要门锁着,在解锁之前门不能开。

例 2

Whenever you press ctrl-C, you will get a command line prompt.

定义:

  • (p):press ctrl-C

  • (q):command line prompt appears

公式:

$G(p \Rightarrow Fq)$

4.6 Safety vs Liveness

很重要。

Safety property

意思是:“bad thing never happens”。

例如:

$G(\neg collision)$
$G(\neg(error))$
可以写:

A safety property states that something bad should never happen.


Liveness property

意思是:“good thing eventually happens”。

例如:

$G(request \Rightarrow F response)$
可以写:

A liveness property states that something good will eventually happen.


4.7 Model Checking

Model checking 是用数学严谨方式验证系统模型是否满足 specification。

可以写:

Model checking is a formal verification technique that checks whether a system model satisfies a given temporal logic property.

基本流程:

1
2
3
4
5
System model S
+ Environment model E
= Closed model M

Check whether M satisfies property φ

符号:

$M \models \varphi$
表示 model (M) satisfies property (\varphi)。


5. L4 Sensors and Actuators

5.1 Sensor 和 Actuator

Sensor

A sensor is a device that measures a physical quantity and converts it into a signal.

例子:

  • temperature sensor

  • gyroscope

  • accelerometer

  • camera

  • LIDAR

  • microphone

  • pressure sensor

Actuator

An actuator is a device that changes or controls a physical quantity in the environment.

例子:

  • motor

  • servo

  • LED

  • speaker

  • heater

  • valve


5.2 Signal Chain

典型 sensor chain:

1
2
3
4
5
Physical quantity
→ Sensor
→ Signal conditioning
→ ADC
→ Digital processor

典型 actuator chain:

1
2
3
4
5
Digital processor
→ DAC / PWM
→ Driver
→ Actuator
→ Physical action

5.3 ADC 和 DAC

ADC

Analog-to-Digital Converter。

ADC converts a continuous analog signal into a digital binary representation.

用于 sensor input。


DAC

Digital-to-Analog Converter。

DAC converts digital values into analog signals.

用于 actuator output。


5.4 Active vs Passive Sensors

Active sensor

主动产生信号。

例子:

  • thermocouple

  • piezoelectric sensor

可以写:

Active sensors generate an electrical signal in response to the measured physical quantity.


Passive sensor

自身不产生信号,而是改变电阻、电容、电感等 passive quantity。

例子:

  • capacitive sensor

  • resistive sensor

可以写:

Passive sensors produce changes in passive electrical quantities and usually require an external excitation source.


5.5 Sensor Figures of Merit

这一部分很容易考定义。

指标 含义
Sensitivity 输出对输入变化的斜率
Range 可测量的最大最小范围
Precision 重复测量的一致性
Accuracy 测量值接近真实值的程度
Resolution 能检测的最小输入变化
Offset 输入为 0 时的非零输出
Linearity 输入输出关系接近直线的程度
Hysteresis 输入增加和减少时输出路径不同
Response time 输出响应输入变化所需时间

5.6 Accuracy vs Precision

这个很容易混。

Accuracy

接近真实值。

Precision

重复测量是否集中。

可以这样写:

Accuracy describes closeness to the true value, while precision describes repeatability of measurements.

例子:

  • 高 accuracy 高 precision:测量值都接近真实值且集中

  • 低 accuracy 高 precision:测量值很集中,但整体偏离真实值

  • 高 accuracy 低 precision:平均值接近真实值,但数据分散

  • 低 accuracy 低 precision:又偏又散


5.7 Sensor Model

线性 sensor:

$f(x(t))=ax(t)$
仿射 sensor:

$f(x(t))=ax(t)+b$
其中:

  • (a):sensitivity / gain

  • (b):offset

现实中 sensor 可能会:

  • saturate

  • have noise

  • have hysteresis

  • have nonlinear distortion


5.8 Sampling and Nyquist Rate

Uniform sampling:固定时间间隔采样。

如果信号最高频率是 (f_{max}),采样频率至少需要:

$f_s > 2f_{max}$
或者理论上:

$f_s \ge 2f_{max}$
这个叫 Nyquist rate。

可以写:

To avoid aliasing, the sampling frequency must be at least twice the maximum frequency component of the signal.

Aliasing:

Aliasing occurs when a signal is sampled too slowly, causing high-frequency components to appear as lower-frequency components.


5.9 SNR

Signal-to-noise ratio:

$SNR=\frac{signal\ power}{noise\ power}$
dB 形式:

$SNR_{dB}=10\log_{10}\frac{P_s}{P_n}$
如果是 amplitude ratio:

$SNR_{dB}=20\log_{10}\frac{A_s}{A_n}$

5.10 传感器选择题答题框架

如果题目问:

Select appropriate sensors for a dynamical system.

可以按这个框架答:

1
2
3
4
5
1. Identify what physical quantities need to be measured.
2. Choose sensors that can measure these quantities.
3. Consider range, accuracy, precision, resolution, response time, and noise.
4. Consider environmental conditions.
5. Consider cost, size, power consumption, and interface compatibility.

例子:无人机

需求 传感器
姿态角速度 gyroscope
加速度 accelerometer
航向 magnetometer
高度 barometer / lidar
位置 GPS / camera / optical flow
障碍物 ultrasonic / lidar / camera

6. L5 Embedded Processors

6.1 Microcontroller 基本组成

课件说 minimal set of components:

1
2
3
CPU
System memory
I/O interface

再加 system buses:

1
2
3
Address bus
Data bus
Control bus

6.2 CPU

CPU 的作用:

The CPU retrieves instructions from program memory, decodes them, and executes them.

也就是:

1
fetch → decode → execute

CPU 内部常见部件:

  • ALU

  • registers

  • control unit

  • program counter

  • instruction decoder


6.3 System Memory

两类:

Program memory

存程序指令。

Data memory

存运行时数据。

可以写:

Program memory stores executable instructions, while data memory stores variables and intermediate data used by the CPU.


6.4 I/O Interface

I/O interface 允许 CPU 和外部设备通信,例如:

  • sensors

  • actuators

  • communication modules

  • timers

  • ADC/DAC

  • GPIO

也叫 peripheral subsystem。


6.5 System Bus

Address Bus

用于选择 memory location 或 peripheral register。

如果 address bus 有 (m) bits,则最多可访问:

$2^m$
个 memory locations。

地址范围:

$0x000…0 \quad \text{to} \quad 2^m-1$
例子:

如果 address bus 是 12 bits:

$2^{12}=4096$
地址范围:

$0x000 \text{ to } 0xFFF$
如果 address bus 是 22 bits:

$2^{22}=4194304$
因为 22 bits = 5.5 hex digits,所以通常写成 6 位 hex:

$0x000000 \text{ to } 0x3FFFFF$

Data Bus

data bus 传输数据和指令。

如果 data bus 是 8-bit,一次最多传 1 byte。

如果要传 16-bit 数据,需要两次 8-bit transfer。

可以写:

The width of the data bus determines the maximum amount of data transferred in one bus transaction.


Control Bus

control bus 传控制信号,例如:

  • read/write

  • clock

  • interrupt

  • reset

  • enable


6.6 MPU vs MCU

MPU, Microprocessor Unit

只有 CPU 核心,其他 memory、I/O 通常外接。

常见于 PC 或复杂计算系统。

MCU, Microcontroller Unit

CPU、memory、I/O 集成在一个芯片中。

可以写:

A microcontroller integrates CPU, memory, and I/O peripherals on a single chip, while a microprocessor usually requires external memory and peripherals.


6.7 RISC vs CISC

RISC

Reduced Instruction Set Computing。

特点:

  • 指令简单

  • 指令数量少

  • 通常 fixed length

  • 适合 pipeline

  • load/store architecture

例子:

  • ARM

  • RISC-V

CISC

Complex Instruction Set Computing。

特点:

  • 指令复杂

  • 指令数量多

  • 一条指令可能完成复杂操作

  • 硬件译码复杂

例子:

  • x86

6.8 Parallelism vs Concurrency

Revision 课件专门提示:

Parallelism (L5) vs concurrency (L7)

Parallelism

真的同时执行。

需要多个 core 或多个 processing units。

可以写:

Parallelism means multiple tasks are executed at the same time, usually on multiple processors or cores.


Concurrency

多个任务逻辑上同时进行,但不一定真的同时执行。

单核 CPU 也可以通过 scheduling 实现 concurrency。

可以写:

Concurrency means multiple tasks make progress over overlapping time periods, but they may be interleaved on a single processor.


7. L6 Memory Architecture

7.1 Volatile vs Non-volatile Memory

Revision sample question 明确提到:

Explain the difference between volatile and non-volatile memory.

Volatile memory

断电后数据丢失。

例子:

  • RAM

  • SRAM

  • DRAM

  • cache

可以写:

Volatile memory loses its stored data when power is removed.


Non-volatile memory

断电后数据仍保留。

例子:

  • ROM

  • Flash

  • EEPROM

  • SSD

可以写:

Non-volatile memory retains stored data even when power is removed.


7.2 RAM vs ROM

类型 用途
RAM 存运行时变量、stack、heap
ROM / Flash 存程序代码、firmware、constant data

7.3 SRAM vs DRAM

项目 SRAM DRAM
存储方式 flip-flop capacitor
是否需要 refresh 不需要 需要
速度 较慢
成本
密度
用途 cache main memory

7.4 Memory Hierarchy

一般从快到慢:

1
2
3
4
5
6
Registers
Cache
SRAM
DRAM
Flash / ROM
External storage

越靠近 CPU:

  • faster

  • smaller

  • more expensive per bit

越远离 CPU:

  • slower

  • larger

  • cheaper per bit


7.5 Cache

Cache 是 CPU 和 main memory 之间的高速小容量存储器。

作用:

Cache stores recently or frequently used data to reduce average memory access time.

核心思想:

  • temporal locality:最近访问过的数据可能很快再次访问

  • spatial locality:访问某地址后,附近地址也可能被访问


7.6 Memory-mapped I/O

在 embedded system 中,peripheral register 可以映射到 memory address。

CPU 通过读写特定地址来控制外设。

可以写:

In memory-mapped I/O, peripheral registers are assigned addresses in the same address space as memory, so the CPU can access peripherals using normal load/store instructions.


8. L7 Multitasking and Scheduling

Revision 课件强调:

How to schedule concurrent systems on a single core?


8.1 Task / Thread / Process

Task

一个需要执行的工作单元。

例如:

  • read sensor

  • update controller

  • send communication packet

  • log data


Thread

同一 process 内的轻量执行流,共享 memory。

优点:

  • communication easy

  • lower overhead

缺点:

  • shared memory causes race condition

  • synchronization needed


Process

独立地址空间的执行实体。

优点:

  • isolation

  • safer

缺点:

  • communication more expensive

  • context switch overhead larger


8.2 Threads 的挑战

线程共享 memory,所以可能出现:

  • race condition

  • deadlock

  • priority inversion

  • inconsistent data

  • synchronization overhead

Race condition

多个线程同时访问共享数据,结果取决于执行顺序。

解决:

  • mutex

  • semaphore

  • lock

  • critical section


8.3 Message Passing

进程之间可以通过 message passing 通信。

优点:

  • no shared memory race condition

  • modular

  • safer

缺点:

  • overhead higher

  • message delay

  • communication design more complex


8.4 Scheduler

scheduler 决定哪个 task 在什么时候运行。

常见目标:

  • meet deadlines

  • minimize response time

  • maximize CPU utilization

  • ensure fairness

  • avoid starvation


8.5 Static vs Dynamic Scheduling

Fully-static scheduler

所有任务执行顺序在设计时确定。

优点:

  • predictable

  • simple

  • suitable for periodic tasks

缺点:

  • inflexible

  • difficult to handle unexpected events


Dynamic scheduler

运行时根据优先级、deadline 等决定任务顺序。

优点:

  • flexible

  • can respond to events

缺点:

  • runtime overhead

  • harder to verify


8.6 Preemptive vs Non-preemptive

Non-preemptive

一个 task 一旦开始执行,就运行到完成或主动让出 CPU。

优点:

  • simple

  • lower context-switch overhead

  • no mid-task interruption

缺点:

  • high-priority task 可能需要等待

  • response time 可能较长


Preemptive

高优先级 task 到来时,可以打断低优先级 task。

优点:

  • better response for urgent tasks

  • suitable for real-time systems

缺点:

  • context switch overhead

  • synchronization more difficult

  • possible race condition


8.7 Priority-based Scheduling

每个 task 有 priority。

scheduler 选择最高优先级 ready task 执行。

如果是 non-preemptive priority scheduler:

  • 当前 task 不会被打断

  • 当前 task 完成后,选择 ready queue 里 priority 最高的 task

如果是 preemptive priority scheduler:

  • 高优先级 task 一 ready,就可以打断低优先级 task

8.8 画 Scheduling 图的方法

如果题目给几个 task:

Task Arrival time Execution time Priority
T1 0 3 2
T2 1 2 1
T3 2 1 3

假设 priority 数字越小优先级越高。

Non-preemptive

1
2
3
4
5
6
t=0: T1 arrives, run T1
t=1: T2 arrives, but T1 continues
t=2: T3 arrives, but T1 continues
t=3: T1 finishes, choose highest priority ready task T2
t=5: T2 finishes, run T3
t=6: finish

Gantt chart:

1
2
0     3     5   6
| T1 | T2 |T3 |

Preemptive

1
2
3
4
5
t=0: T1 runs
t=1: T2 arrives, higher priority, preempts T1
t=3: T2 finishes, T1 resumes
t=5: T1 finishes
t=5: T3 runs

Gantt chart:

1
2
0  1     3     5   6
|T1| T2 | T1 |T3 |

9. L9 Interfacing

Revision 课件明确说 MCU basic interface 有四个 fundamental elements:

  1. Power source

  2. Clock generator

  3. Power-on reset circuit

  4. Booting function


9.1 Basic MCU Interface

可以写:

A microcontroller requires a basic interface to become usable, including a power source, a clock generator, a reset circuit, and a booting function.


9.2 Power Source

常见 power source:

  • battery

  • wall-connected AC power

  • capacitor

  • energy harvesting

Energy harvesting 例子:

  • photovoltaic

  • piezoelectric

  • thermoelectric generator

  • kinetic energy

  • electromagnetic radiation


9.3 Voltage and Power

课件提到:

$P \sim V^2$
即 digital circuit 的 power consumption 和 supply voltage 平方相关。

所以降低 voltage 可以降低功耗,但也会降低最高工作频率。

可以写:

Lower supply voltage reduces power consumption, but it also reduces the maximum operating frequency of the circuit.


9.4 Battery Model

Revision sample question 提到:

Draw the water bucket model for rechargeable batteries.

核心概念:

  • available charge:可以立即使用的电荷

  • bound charge:暂时不容易直接使用的电荷

  • internal resistance:内部电阻导致损耗

  • leakage/self-discharge:电池慢慢损失电量

可以把电池想成两个水桶:

1
2
3
Bound charge bucket  → slowly transfers → Available charge bucket

load consumes

解释:

The available-charge well represents charge that can be immediately extracted by the load. The bound-charge well represents charge that is stored chemically but not immediately available. Charge can flow from bound to available over time, and losses occur due to internal resistance and irreversible reactions.


9.5 Peukert’s Law

课件提到 lead-acid battery lifetime:

$t=\frac{C}{I^\alpha}$
其中:

  • (t):discharge time

  • (C):capacity

  • (I):discharge current

  • ($\alpha$):Peukert coefficient

意义:

Higher discharge current reduces effective battery capacity and shortens battery lifetime.


9.6 Clock

Clock 用于同步系统操作。

Clock requirements:

  • fixed amplitude swing

$V_{SW}=V_{OH}-V_{OL}$

  • fixed frequency

$f_{clk}=\frac{1}{T_{clk}}$

  • constant duty cycle

$DC=\frac{T_{high}}{T_{clk}}$

  • small rising/falling time

$t_r,\ t_f$

9.7 Clock Jitter and Drift

Jitter

Clock jitter is uncertainty in the periodicity of a clock signal.

也就是每个周期不完全一致。

Drift

Frequency drift is a systematic change in clock frequency over time.

原因可能包括:

  • thermal noise

  • power supply variation

  • loading condition

  • temperature change


9.8 Internal vs External Clock

Internal clock

  • RC oscillator / ring oscillator

  • cheaper

  • simpler

  • less stable

  • limited frequency choices

External clock

  • quartz crystal / ceramic resonator

  • more stable

  • more accurate

  • extra components needed


9.9 Reset and POR

RESET signal 的作用:

RESET takes the system to its initial state.

RESET 可能导致:

  • load PC with first boot instruction address

  • clear status register

  • initialize peripherals

  • reset FSM state

Power-on reset circuit, POR:

A POR circuit generates a reset signal when power is first applied, ensuring that the MCU starts from a known initial state.


9.10 Booting

Booting 是 CPU reset 后执行的一系列初始化指令。

包括:

  1. identifying and initializing peripherals

  2. setting up the stack

  3. initializing global variables

  4. performing diagnostics

  5. loading OS or main program

可以写:

Booting is the sequence of instructions executed after reset to initialize the system and start software execution.


9.11 Polling vs Interrupts

Polling

CPU 不断检查外设状态。

优点:

  • simple

  • predictable

  • easy to implement

缺点:

  • wastes CPU cycles

  • poor response if polling interval too long

  • higher energy consumption


Interrupt

外设需要服务时发送 IRQ。

CPU 暂停当前任务,执行 ISR。

优点:

  • faster response

  • lower CPU waste

  • lower energy consumption

  • better for asynchronous events

缺点:

  • more complex

  • ISR must be short

  • possible priority issues

  • concurrency problems


10. L10 Serial Communication

10.1 Serial vs Parallel Communication

Serial communication

一条信号链路逐 bit 传输。

Serial communication transmits an n-bit character over one signal link sequentially.

优点:

  • fewer wires

  • lower cost

  • better for long distance

  • less crosstalk

  • suitable for high-speed communication


Parallel communication

n 条线同时传 n bits。

Parallel communication transmits multiple bits simultaneously using multiple signal links.

理论上快,但高速或长距离时会有:

  • skew

  • crosstalk

  • transmission line effects

  • synchronization difficulty

所以现代高速通信很多使用 serial link。


10.2 Bit Rate vs Baud Rate

Bit rate

每秒传输 bit 数:

$bit\ rate=\frac{1}{t_{bit}}$
单位:bps。

Baud rate

每秒传输 symbol 数。

关系:

$bit\ rate = baud\ rate \times bits\ per\ symbol$
例子:

BPSK

一个 symbol 表示 1 bit:

$bit\ rate=baud\ rate$

QPSK

一个 symbol 表示 2 bits:

$bit\ rate=2 \times baud\ rate$
所以:

$baud\ rate=0.5 \times bit\ rate$

Single-ended

信号相对于 ground reference 测量。

例子:

  • RS-232

缺点:

  • 容易受 ground noise 影响

  • noise immunity 较差


Differential

用两条线的电压差表示信号:

$V_{diff}=V_+ - V_-$
如果两条线同时受到相同 noise (V_n):

$V_{diff}=(V_+ + V_n)-(V_- + V_n)=V_+-V_-$
noise 被抵消。

可以写:

Differential links reject common-mode noise because the receiver measures the voltage difference between two lines, and noise common to both lines is cancelled.


10.4 Simplex / Half-duplex / Full-duplex

Simplex

单方向通信。

例子:

  • TV broadcast

  • radio broadcast

1
A → B

Half-duplex

双向通信,但同一时间只能一个方向。

例子:

  • walkie-talkie
1
2
A ⇄ B
but not simultaneously

Full-duplex

两个方向可以同时通信。

例子:

  • phone call
1
2
A ↔ B
simultaneously

10.5 Synchronous vs Asynchronous Serial Communication

Synchronous

发送端和接收端共享 clock,或者 clock embedded in signal。

优点:

  • high speed

  • no start/stop bit overhead

缺点:

  • clock synchronization needed

  • more complex

例子:

  • SPI

  • I2C


Asynchronous

没有共享 clock,通过 start bit / stop bit 同步每个 frame。

优点:

  • simple

  • fewer clock wires

缺点:

  • overhead higher

  • clock mismatch can accumulate

例子:

  • UART

10.6 Packet / Datagram

Message 可以分成 packet。

每个 packet 包括:

1
Header + Body + Footer
  • start of packet

  • address

  • type

  • length

Body

实际数据。

  • end of packet

  • error checking

  • checksum / CRC


11. L11 Evaluation and Validation

11.1 Evaluation vs Validation

Evaluation

Evaluation is the process of computing quantitative information about key system characteristics.

也就是测量性能指标,例如:

  • execution time

  • energy consumption

  • memory usage

  • temperature

  • quality of result


Validation

Validation checks whether the design satisfies requirements and design objectives.

也就是判断系统是否达到需求。


Formal Verification

Formal verification validates a system with mathematical rigor.

例如 model checking。


11.2 Multi-objective Optimization

Revision sample question:

Formulate a multi-objective optimization.

embedded system 设计中,目标通常冲突。

Product criteria (f(x)):

  • cost

  • execution time

  • energy consumption

  • durability

  • reliability

  • memory usage

  • accuracy

Product characteristics (x):

  • number of processors

  • size of memory

  • bus type

  • clock frequency

  • battery capacity

  • sensor type

  • algorithm parameters

可以写成:

$
\min_x f(x)=
\begin{bmatrix}
cost(x) \
execution\ time(x) \
energy(x)
\end{bmatrix}
$subject to:$
memory(x)\le M_{max}
$

$accuracy(x)\ge A_{min}$
$power(x)\le P_{max}$

11.3 Pareto Optimality

如果一个 design 在某个目标上更好,但不会让其他目标变差,则它 dominates 另一个 design。

Pareto optimal point:

A design is Pareto optimal if no other design can improve one objective without worsening at least one other objective.

考试可以写:

In multi-objective optimization, there may not be a single best solution. Instead, designers select from Pareto-optimal solutions according to design priorities.


11.4 WCET and BCET

WCET

Worst-case execution time。

WCET is the largest execution time of a program for any feasible input and initial state.

估计值:

$WCET_{EST}\ge WCET$
并且要 tight:

$WCET_{EST}-WCET \ll WCET$
意思是:估计值要安全,但不能过于保守。


BCET

Best-case execution time。

BCET is the smallest execution time of a program for feasible inputs and initial states.

估计值:

$BCET_{EST}\le BCET$
并且要 tight:

$BCET-BCET_{EST} \ll BCET$

11.5 Approximate Computing

课件定义:

Approximate computing allows tolerated deviation from the best possible output in exchange for reduced resource consumption.

例子:

  • mp3

  • jpeg

  • mp4

  • approximate image processing

  • approximate machine learning inference

权衡:

1
2
3
4
less accuracy
→ lower execution time
→ lower energy
→ lower memory

11.6 Error Metrics

MSE

$MSE=\frac{1}{N}\sum_{i=1}^{N}(x_i-y_i)^2$
特点:

  • penalizes large errors more

  • unit is squared


RMSE

$RMSE=\sqrt{MSE}$
特点:

  • same unit as original data

  • easier to interpret than MSE

  • still penalizes large error


MAE

$MAE=\frac{1}{N}\sum_{i=1}^{N}|x_i-y_i|$
特点:

  • average absolute distance

  • same unit as original data

  • less sensitive to outliers than MSE

注意:PPT 里可能写了 “emphasizes large deviations/outliers”,但从数学上看,MSE 比 MAE 更强调大误差。考试如果按课件写,保守写法是:

MAE measures the average absolute deviation in the same unit as the data, while MSE/RMSE penalize larger errors more strongly due to squaring.


PSNR

Peak signal-to-noise ratio 常用于图像质量。

通常:

$PSNR=10\log_{10}\frac{MAX_I^2}{MSE}$
MSE 越小,PSNR 越大,图像质量越好。


11.7 Dependability

Dependability 包括:

  • reliability

  • safety

  • security

  • availability

  • maintainability

Reliability

系统在一定时间内正确工作的能力。

Safety

系统不会造成危险或伤害。

Security

系统抵抗攻击和未授权访问的能力。

Availability

系统在需要时可用。


12. 高频题型模板

12.1 Address Bus 计算题

题目:

Determine how many memory locations can be accessed and the address range in hex notation with an address bus of 12 bits.

答:

$2^{12}=4096$
所以可以访问 4096 个 memory locations。

12 bits = 3 hex digits。

地址范围:

$0x000 \text{ to } 0xFFF$
模板:

1
2
3
An m-bit address bus can address 2^m different memory locations.
The address range is from 0 to 2^m - 1.
Then convert both limits to hexadecimal.

12.2 Volatile vs Non-volatile Memory

可直接背:

Volatile memory loses its stored data when power is removed, such as RAM, SRAM, DRAM, and cache. Non-volatile memory retains data without power, such as ROM, Flash, and EEPROM. In embedded systems, volatile memory is usually used for runtime data, while non-volatile memory is used to store firmware and permanent data.


12.3 Sensor Selection

可直接背:

To select sensors for a dynamical system, we first identify the physical quantities that need to be measured, such as position, velocity, acceleration, temperature, or pressure. Then suitable sensors are chosen according to range, sensitivity, accuracy, precision, resolution, response time, noise level, power consumption, cost, size, and interface compatibility. For example, a mobile robot may use encoders for wheel position, IMU for acceleration and angular velocity, LIDAR or camera for obstacle detection, and GPS for outdoor localization.


12.4 Non-preemptive Priority Scheduler

答题步骤:

1
2
3
4
5
1. Sort tasks by arrival time.
2. At each decision point, list ready tasks.
3. Select the ready task with highest priority.
4. Since it is non-preemptive, once a task starts, it runs until completion.
5. Draw Gantt chart.

关键句:

In a non-preemptive priority scheduler, a running task cannot be interrupted. The scheduler only chooses the highest-priority ready task when the CPU becomes free.


可直接背:

In a differential link, the receiver measures the voltage difference between two signal wires. If the same noise is added to both wires, it is common-mode noise. Since the receiver subtracts the two voltages, the common noise is cancelled.

公式:

$V_{diff}=(V_+ + V_n)-(V_- + V_n)=V_+-V_-$

12.6 LTL Factory Inspection Task

题目可能是:

Formally specify a factory inspection task by a robot as an LTL formula.

可以自己定义 propositions:

  • (p):robot receives inspection request

  • (q):robot reaches inspection station

  • (r):robot completes inspection

  • (s):unsafe area is entered

  • (c):collision occurs

可以写:

  1. 收到任务后最终到达检查点:

$G(p \Rightarrow Fq)$
2. 到达检查点后最终完成检查:

$G(q \Rightarrow Fr)$
3. 永远不能碰撞:

$G(\neg c)$
4. 不能进入危险区域:

$G(\neg s)$
综合:

$G(p \Rightarrow Fq)\land G(q \Rightarrow Fr)\land G(\neg c)\land G(\neg s)$
文字解释:

This formula specifies that whenever an inspection request is issued, the robot must eventually reach the inspection station and complete the inspection, while always avoiding collision and unsafe areas.


12.7 Multi-objective Optimization

题目:

Formulate a multi-objective optimization.

可以写:

Let (x) represent design choices, such as CPU frequency, memory size, battery capacity, and sensor type.

Objectives:

$
\min_x
\begin{bmatrix}
cost(x)\
energy(x)\
execution\ time(x)
\end{bmatrix}
$Constraints:$
accuracy(x)\ge A_{min}
$

$memory(x)\le M_{max}$
$response\ time(x)\le T_{max}$
解释:

The objectives conflict with each other. For example, increasing CPU frequency may reduce execution time but increase energy consumption. Therefore, the designer should consider Pareto-optimal solutions.


13. 最后冲刺背诵版

必背定义

Embedded System

A dedicated computer system integrated into a larger device to perform specific functions.

CPS

A system integrating computation, communication, and physical processes.

Continuous Dynamics

Describes time-continuous system behavior using differential equations.

Discrete Dynamics

Describes systems whose states change through discrete transitions.

FSM

A mathematical model consisting of states, inputs, outputs, transitions, and output functions.

Sensor

A device that measures a physical quantity and converts it into a signal.

Actuator

A device that changes or controls a physical quantity in the environment.

MCU

A computer-on-a-chip integrating CPU, memory, and I/O peripherals.

Volatile Memory

Memory that loses data when power is removed.

Non-volatile Memory

Memory that retains data without power.

Interrupt

A signal from a peripheral that causes the CPU to suspend its current task and execute an ISR.

Bit Rate

Number of bits transmitted per second.

Baud Rate

Number of symbols transmitted per second.

Evaluation

Computing quantitative information about system characteristics.

Validation

Checking whether a design satisfies requirements.


14. 考试答题建议

  1. 看到 “draw” 就一定画图
    例如 FSM、scheduler、FBD、battery bucket model、differential link。

  2. 看到 “explain difference” 就写对比表
    例如 volatile vs non-volatile,Mealy vs Moore,polling vs interrupt,serial vs parallel。

  3. 看到公式题,先写 general rule
    例如 address bus:
    $2^m$
    然后再代入。

  4. LTL 题先定义 proposition
    不要直接写公式。先写:

    1
    2
    3
    p: request
    q: inspection completed
    c: collision

    然后再写:

$G(p\Rightarrow Fq)\land G(\neg c)$
5. scheduler 题一定说明 preemptive / non-preemptive
很多人错在没有说明任务能不能被打断。

  1. 传感器选择题不要只写 sensor 名字
    还要写为什么:

    1
    selected because it measures acceleration, has fast response, and is suitable for robot motion estimation
  2. Evaluation 题要体现 trade-off
    embedded system 设计几乎都是 trade-off:

    1
    2
    3
    4
    speed vs energy
    cost vs performance
    accuracy vs resource consumption
    memory vs capability

这份资料里最值得优先背的是:

1
2
3
4
5
6
7
8
9
10
L2 系统性质 + 线性化
L3 FSM / Mealy / Moore
L4 sensor metrics
L5 address bus 计算
L6 volatile vs non-volatile
L7 scheduling
L8 LTL 公式模板
L9 power / clock / reset / boot / interrupt
L10 bit rate / baud rate / differential link
L11 evaluation / validation / multi-objective optimization