导图社区 Embedded System嵌入式系统
嵌入式系统课程涵盖了从ARM处理器架构、指令集和总线结构到嵌入式开发周期和数据传输与通信的各个方面,内容全面实用。通过本课程的学习,你将掌握嵌入式系统开发的核心技能,包括系统设计、固件开发和任务调度,适用于各种嵌入式应用的开发,是提升工程技术能力的绝佳机会。
编辑于2024-06-04 15:38:47Embedded System
EP_1
Refresh
Computer architecture
types
Harvard
Von-Neumann
components
Microprocessors (MPU) vs. Microcontroller (MCU)
Bus structure
System bus
Address bus
Control bus
Data bus
Communications
Parallel
Serial
syncrhonous
asynchronous
Bitwise operations
& AND
| OR
^ XOR
~ NOT
ARM Processors & interfacing
Concept
ISA ( Instruction Set Architecture)
ARM (Advanced RISC Machine)
RISC - Reduced Instruction Set Computer/Computing
CISC - Complex Instruction Set Computer/Computing
L432KC
Memory mapping
GPIOs
PWM (Pulse Width Modulation)
Period
Duty cycle
Resolution
Assemble & Machine Language
Elements
Mnemonic Operation Codes
move (MOV)
Arithmetic operation
add (ADD)
add with carry flag (ADC)
substract (SUB)
substact with carry flag (SBC)
Multiply (MUL)
Logical operation
AND
ORR
XOR (EOR)
Bit Clear (BIC R6, R1, R2)
R2=0, R1不变, R2=1, R1取0
MVN
Shift
Left (LSL)
Right (LSR)
memory
get address (ADR): ADR R4,a
load (LDR R1, [R4] / LDR R1, [R4, #4]
store (STR)
Compare
CMP R5, R6
perform R5-R6 &set flag
=0: Z=1
negative: N=1
cause carry: C=1
cause signed overflow: V=1
Condition
Condition Flags
N: Negative
Z: Zero
C: Carry
V: Overflow
Branching
B: to another instruction
BL:
C code: if/else
根据C code,写assembly
if 和 flag有关
if/else 和 branching
根据assembly,用某些助记符改写assembly
Data transfer instruction
X = ( A+B ) - C
get address: ADR
get value: LDR
各种运算
get address ADR
store STR
Operands
Registers
constant / immediates
Data declarations
Byte Arrangement
Endian
The ARM Register File
EP_2
EP Development Circle Tagged
Project Development Cycle
Requirement Analysis and Specification
System Design
Prototyping
Testing and Verification
Deployment and Maintenance
Feedback and Iteration
Embedded Firmware
2 approaches for the design and implementation firmware
Super loop
Embedded OS
Task Scheduling
Considered Factors
CPU Utilisation
CPU利用率 = (工作时间/总时间) × 100% = xxx%
high
Throughput ( 吞吐量)
吞吐量 = 完成任务数量 / 总时间 = xxx任务/时间单位
maximum
Turnaround Time (TAT, 周转时间)
Turnaround Time = Completion Time - Arrival Time
minimum
Waiting Time
Waiting time = Turnaround time - Burst time
分段时,和response time 不一样
Response Time
Response time = Starting time - Arrival time
least
Type
Preemptive
更高级任务可先执行
Nonpreemptive
所有任务运行至完成
Real Time Management
Hard
任务严格在ddl前完成,否则fail
Soft
大多数情况需要ddl前完成,偶尔可超时
Firm
在大多数情况下可以容忍一些延迟,但在关键时刻必须严格遵守ddl
Testing & Debugging
Test
Type
Unit testing
测试单独的软件单元(函数、模块)以验证其正确性和功能
Integration testing
测试不同软件模块或组件之间的交互和集成
System testing
测试完整的嵌入式系统
Acceptance testing
确保系统满足用户需求和期望
Regresssion testing
重复以前的测试以确保修改未引入新问题
Techniques
White Box
关注软件的内部结构和代码实现
Black Box
不关注内部代码,仅关注输入和输出
Grey Box
既关注外部行为,又涉及部分内部实现,但都不完全
Static
分析不执行
有限
Dynamic
执行
成本高
Task Scheduling
Non-preemptive
FCFS ( First Come First Service )
LCFS / LIFO ( Last In First Out )
SJF ( Shortest Job First )
Priority based Scheduling
Gantt Chart
Preemptive
SJF ( Shortest Job First )
RR ( Round Robin Scheduling )
每个任务被分配一个固定的时间片,在该时间片内任务可以运行。如果任务在时间片结束前未完成,则被暂停,等待下一个轮回
Priority based Scheduling
Polling
轮询是一种协议( protocol ),它向CPU指示某个设备需要其注意。这是一个连续的过程,用于检查设备是否正常工作
Interrupt
过程
Test interrupts occur (more than one interrupts)
Current instruction is stopped
Protect the status of current instruction
eight registers are pushed on the stack,
LR (链接寄存器) is set to 0xFFFFFFF9
IPSR (中断服务程序号) is set to the interrupt number,
PC is loaded with the interrupt vector
EP_4
DAC
Equation
Function
AnalogOut
write
output XX.X%
write_u16
output 0xFF%
=
DAC-based waveform generation
Modular Programming
target
readable, structured, documented
fully and extensively tested
reuse existing code
multiple engineers working on a single project
future upgrades
Key Terminologies
Modules
Interfaces
Abstraction
Encapsulation
Dependencies
优缺点
Benefit
代码可复用
易管理
易读
Drawback
执行时间开销
嵌套函数使程序复杂
只能返回一个值
variable type
local variable 局部变量
函数内部
formal parameter 形式参数
函数的输入
global variable 全局变量
Structure
Declaration / Prototype
提供函数名、返回类型和参数信息 声明在“.h”文件中
Definition
包含函数的实际实现 定义在“.cpp”文件中
Process
pre-process
处理 '#' 的指令
#include
.h文件插入进去
宏 #define
compile
编译源文件.c/.cpp->目标文件.o/.obj
link
链接所有.o文件->二进制文件.bin
防止被多重声明
#ifndef #define ...... #endif
if not defined
Energy-Efficient EP
Hardware
MCU
peripherals/component
type
quantity
System powering
Software
run time
Algorithms
data structure
delays, variables, iterations
Factors
Appllication
Process technology
Voltage and Frequency
Power Consumption 计算
Static (leakage): 待机状态, 设备没有进行任何任务时
Dynamic: 设备在运作状态下
单位: mWh等
3 power modes of Mbed OS
Active
MCU和所有时钟都在运行
Sleep
core system clock被禁用,
消除 processor/memory systems/buses 的 dynamic power
Deep sleep
core system clock / high-frequency clocks 被禁用
SysTick(系统计时器)也被禁用
API
void sleep_manager_sleep_auto (void)
void sleep_manager_lock_deep_sleep_internal (void)
void sleep_manager_unlock_deep_sleep_internal (void)
static void sleep (void)
测量mbed 的功率
自带的
用安培表
JP1 (IDD)
CPU统计睡眠的时间
API
us_timestamp_t mbed_time_sleep (void)
自启动以来睡眠模式下的时间。
us_timestamp_t mbed_time_deepsleep (void)
自启动以来深度睡眠模式下的时间
us_timestamp_t mbed_time_idle (void)
自启动以来在空闲模式下的时间
us_timestamp_t mbed_uptime (void)
自系统启动以来的时间
EP_3
Lec7
ADC
function
PWM
function
Interrupt
external interrupt
InterruptIn
InterruptIn button(BUTTON1);
ISR
void button_isr() { // 中断服务程序 printf("Button pressed!\n"); }
主程序
int main() { button.rise(&button_isr); // 在上升沿触发中断 while (true) {} }
timeout interrupt
Timeout
Timeout timeout;
ISR
void timeout_isr() { // 超时服务程序 printf("Timeout occurred!\n"); }
主程序
int main() { timeout.attach(&timeout_isr, 5.0); // 5秒后触发中断 while (true) {} }
Timeout+debouncing
Timeout+InterruptIn
Timeout debounce_timeout; InterruptIn button(BUTTON1);
ISR
void debounce_isr() { // 去抖动服务程序 printf("Button debounced!\n"); }
void button_isr() { debounce_timeout.attach(&debounce_isr, 0.05); // 50毫秒去抖动 }
主程序
int main() { button.rise(&button_isr); // 在上升沿触发中断 while (true) {} }
Ticker
Ticker
Ticker ticker;
ISR
void ticker_isr() { // 定时服务程序 printf("Ticker interrupt!\n"); }
主程序
int main() { ticker.attach(&ticker_isr, 2.0); // 每2秒触发一次中断 while (true) {} }
Polling
I2C Inter-integrated-circuit
简介
Synchronous
master-slave hierarchy
usually 1 master - multiple slaves
predefined address for slaves
限制个数
Only master can initiate data transmission
Structure
Serial Data Line (SDA)
Bi-directional (one direction at a time – half duplex)
data, address, and control
Serial Clock Line (SCL)
synchronisation
Transmission
Start & Stop
Start: High to Low
Stop: Low to High
Clock & Data
One clock pulse per data bit
Data changes when SCL is LOW
The first byte : 7 bit address + R/W bit
Each byte + 1bit Ack (Acknowlege)
拉低: 确认
未拉低: 错误
receiver 发送 Ack, master 失去SDA的控制
Function
I2C
I2CSlave (slave)
read
write
frequency
start (master)
stop
receive (slave)
check if addressed
address (slave)
SPI Serial Pheripheral Interface
简介
Synchronous
master slave hierarchy
onyl master initiate data transmission
Structure
Serial Data In (SDI)
Serial Data Out (SDO)
full duplex
Serial Clock (SCK)
Slave Select (SS) Chip Select (CS)
=0: 开始通信
Functions
master
SPI
format
frequency
write
set_default_write_value
slave
SPISlave
format
frequency
receive
read
reply
SPI vs I2C
SPI - Advantages
Full-duplex communication
Speed – I2C: 5 Mbps / SPI: >=10 Mbps
Not limited to 8-bit words
Lower power requirements
I2C - Advantages
Simple – Implements a 2-wire interface unlike SPI
Multiple slave devices without using extra pins
Flexibility - Supports multiple Masters