6. Embedded System Software Design, Testing, and Debugging

Section I

Quality Attributes

  1. Operational Quality Attributes

  2. Non-Operational Quality Attributes

Embedded Firmware

The control algorithm (Program instructions) and or the configuration settings that an embedded system developer dumps into the code (Program) memory of the embedded system.

Components for Embedded Programs

State Machine

Circular Buffers

Queue

Models of Program

Data Flow Graph (Basic Block)

  • 没有条件/循环语句的一个代码块

Control / Data Flow Graph

  • Basic Block作为基本元素

Compilation Techniques

Frame

  1. 定义
  • 当一个函数被调用时,一个新的frame会被创建并压入堆栈中,在函数执行结束后,这个frame会从堆栈中弹出并销毁。这个过程也被称为“函数调用栈”或“运行时堆栈”。
  1. 原理
  • Stack Pointer 指向当前帧的结尾

  • Frame Pointer 指向上一个帧的结尾

Compilation of an Arithmetic Expression & Register Allocation Optimisation

  1. Example

  1. Optimization
  • 变量数超过寄存器数时,需要重复利用某些寄存器以优化代码

  • 在此例中,最多只要3个寄存器

  • 伪代码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
Load r1, a
Load r2, b
ADD r1, r1, r2
; now r2 is free
Load r2, c
Load r3, d
ADD r2,r2,r3
SUB r1,r1,r2
; now r2 and r3 are free
Load r2, e
ADD r1, r1, r2

Testing Techniques

黑盒测试分类

Function Testing 测试功能可不可用
Non-functional Testing 测试怎么实现功能
Regression Testing 测试更新后的软件性能是否下降了

白盒/黑盒比较

比较项目 White-Box Testing Black-Box Testing(functional testing)
测试前的数据 测试前对硬件和软件都了如指掌 测试前只知道输入输出
(时间和经济)成本
复杂度
对测试者的知识储备要求
效果 相对较差

Debugging

Debug & Test

  1. Debug: Given a symptom of software failure, locate and correct the defect.

  2. Test: Executing a program to see if it performs as expected.

选择Debug工具

  • ESC (Easy Use, Special Capability, Cost)

Debug 工具

  1. Burn and Learn
stateDiagram 写(修改)代码 --> 编译 编译 --> 测试 测试 --> 写(修改)代码
  1. Software Simulation
  • I/O: Waveforms, Register Log, Digital Signal, Manual Input
  1. Oscilloscope

  2. Logic Analyzer

Pros Cons
高效 external memory bus
只能监测I/O,而不是内存活动
  1. Hardware Emulation
In-Circuit Emulation (ICE) More Powerful, more expensive
In-Circuit Debug (ICD)

Section II

Embedded Firmware – Design and Development

Super Loop

  1. 定义
  • 经典循环, 时序进行

  • 任务简单对时间没有要求

  1. 例子

  1. 优缺点
Pros Cons
简单 错一点就会死机
没OS 非实时
省内存
  1. 改进
  • 加个中断,从而可以执行实时任务

Embedded OS based Approach

  1. RTOS (Real-Time OS)

  1. GPOS (Customized General-Purpose OS)

  2. 比较

Scheduling

基本概念

  1. TAT (Turn Around Time)
  • 进入序列(开始排队)到运行结束
  1. Waiting Time

Non-preemptive

FIFO/FCFS(First-Come-First-Served))

LIFO/LCFS

SJF(Shortest Job First)

Priority-Based Scheduling

优缺点综述

SJF + PBS
会出现Starvation

Preemptive

Preemptive SJF Scheduling / Shortest Time(SRT)

  • 每当有新的任务进入队列,系统会重新计算SRT,并重新调整当前执行任务

Round Robin (RR)

  • Ready Queue

  • Ready Queue中的程序都执行*Pre-defined Time**

Preemptive Priority-Based Scheduling

Rate Monotonic (RM) Scheduling Algorithm

  • 根据时间给任务安排优先级

  • 但是任务时间很难预测的

附录

Firmware

  • 装载ROM上的软件, 提供最底层的操作
Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy