Microprocessor System Design

Introduction

What is an Embedded System?

Application-specific computer system

Built into a larger system

Why use an Embedded System?

Better performance

More functions and features

Lower cost

More dependability

Core Components

6个核心components

image-20230306084312325

Benefits of Embedded Computer Systems

  • Greater performance and efficiency

• Software makes it possible to provide sophisticated control

  • Lower costs

• Less expensive components can be used

e.g. standard LCD display that works with standard MCUs(单片机)

• Manufacturing costs reduced – mass production

• Maintenance costs reduced – fewer components

  • Better dependability

• Adaptive system which can compensate for failures

image-20230306193325496

e.g. when the motor is overheated, slow it down

• Better diagnostics (e.g. logging) to improve repair time

Embedded System: Functions

Closed-loop control system

• Monitor a process, adjust an output to maintain desired set point (temperature, speed, direction, etc.)

系统的输入影响输出同时又受输出的直接或间接影响的系统

Sequencing

根据环境和系统的不同,逐步经历不同的阶段

Signal processing

Remove noise, select desired signal features

Communications and networking

Exchange information reliably and quickly

Embedded Systems: Attributes

Interfacing with larger system and environment

  • Analog signals for reading sensors

    Typically use a voltage to represent a physical value

  • Power electronics for driving motors

  • Digital interfaces for communicating with other digital devices

Concurrent(并发性), reactive behaviours

嵌入式系统可以同时管理多个活动,有精确的时间控制能力

Typically perform multiple separate activities concurrently

CPU从一个或多个执行线程执行指令

image-20230306200451045

Fault handling & Diagnostics(诊断)

image-20230306202557690

Many systems must operate independently for long periods of time, requiring system to handle likely faults without crashing.

Often fault-handling code is larger and more complex than the normal-case code

存储在内存/磁盘上的日志/记录有助于服务人员快速判断问题

Embedded Design: Constraints(限制)

image-20230306202810841

Cost

竞争市场会惩罚那些性价比不高的产品

Size and weight limits

移动(航空、汽车)和便携式(例如手持)系统

Power and energy limits

Battery capacity

Environment

Temperatures may range from -40°C to 125°C, or even more

Impact of Constraints 限制

  • Microcontrollers (rather than microprocessors)

外设包括接口与其他设备,有效响应

片上RAM、ROM降低了电路板的复杂性和成本

  • Programming language

Programmed in C rather than Java (smaller and faster code, so less expensive MCU)

Some performance-critical code may be in assembly language

  • Operating system (OS)

Typically no OS, but instead simple scheduler (or even just interrupts + main code (foreground/background system)

If OS is used, likely to be a Real-Time OS(实时操作系统) with a small code size

Computer Design and Organisation

What is a Computer?

A computer is a machine that can perform simple calculations

• performs a sequence of calculations;

• makes decisions based on the results of calculations; and

• repeats the sequence if wanted.

image-20230308082331322

Von Neumann Architecture

image-20230308082431522

  • Central Processing Unit (CPU):controls the system and performs calculations

从内存中取指令、翻译指令、分析指令,然后根据指令的内存向有关部件发送控制命令,控制相关部件执行指令所包含的操作

  • Main Memory: stores both programs and data将程序编码为数据,然后与数据一同存放在存储器中,这样计算机就可以调用存储器中的程序来处理数据了。(存储程序原理)

哈佛模型中:数据与与program分别存储

Peripheral(外部的) Input/Output (I/O):allows data to be input to system

allows results to be output from system

Microprocessor vs Microcontroller

image-20230308083550942

  • MCP: A microprocessor mainly refers to the CPU with some memories.

    必须包含ROM、RAM、总线接口及这种外设器件,如ARM

  • MCU: A microcontroller unit is a microprocessor integrated with both memory and I/O. 微控制器是将整个计算机系统集成到一片芯片中,它是一种通用设备,用于获取数据,执行有限的计算和控制环境。image-20230308102503288

Stored Program Concept

The CPU executes instructions stored in memory.

• So called the “stored program” concept

  • two kinds of memory

• RAM – Random Access Memory: Can be used for both programs & data

• ROM - Read-Only Memory :Can be used for fixed programs & constant data

Fetch-Decode-Execute Cycle

The CPU is a finite state machine (FSM) which runs the programs stored in the memory by the user.

repeatedly performs three operations:

• Fetch – retrieve an instruction from memory 将一条指令从主存中取到指令寄存器的过程

• Decode – interpret the instruction 令译码器按照预定的指令格式,对取回的指令进行拆分和解释,识别区分出不同的指令类别以及各种获取操作数的方法。

• Execute – control appropriate hardware to carry out the instruction 完成指令所规定的各种操作,具体实现指令的功能

image-20230308084103273

Assembly(汇编) programming is considered the closest and the lowest level of programming to the HW.

Instructions

计算机语言中的单词叫做指令,它的词汇叫做指令集

The functionalities of a computer are specified by its instruction set.

  • Why is an instruction usually simp

    Simplicity favours regularity.

  • Why is the number of registers small and limited?

    Smaller is faster. A very large number of registers may increase the clock cycle time.

ADD r3, r1, r2对应C表述是r3 = r1 + r2( r1, r2 and r3 are registers)

MOV r2, r1 ;r2 = r1

image-20230308085645601

Translate the follow in style statement into instructions:w = x – (y + z);

image-20230308085723458 C-

Assembly Language

assembly language (ADD, MOV, etc.)

汇编程序将把我们的符号转换成机器代码

image-20230308085848304

汇编语言要求程序员为机器执行的每条指令写一行,这迫使程序员像机器一样思考

写c语言时:

image-20230308090007381