Embedded Systems 简明教程
Embedded Systems - Terms
Program Counter
程序计数器是一个 16 位或 32 位寄存器,其中包含要执行的下一条指令的地址。每次获取指令时,PC 会自动递增到下一个顺序内存位置。分支、跳转和中断操作会使用其他于下一个顺序位置的地址加载程序计数器。
The Program Counter is a 16- or 32-bit register which contains the address of the next instruction to be executed. The PC automatically increments to the next sequential memory location every time an instruction is fetched. Branch, jump, and interrupt operations load the Program Counter with an address other than the next sequential location.
激活上电复位将导致寄存器中的所有值丢失。这意味着上电复位后 PC(程序计数器)的值为 0,迫使 CPU 从 ROM 存储器位置 0000 获取第一个操作码。这意味着我们必须将第一个字节的上行码放在 ROM 位置 0000,因为这是 CPU 希望找到第一条指令的位置
Activating a power-on reset will cause all values in the register to be lost. It means the value of the PC (program counter) is 0 upon reset, forcing the CPU to fetch the first opcode from the ROM memory location 0000. It means we must place the first byte of upcode in ROM location 0000 because that is where the CPU expects to find the first instruction
Reset Vector
复位向量的意义在于它指向处理器包含固件的第一条指令的内存地址。没有复位向量,处理器将不知道从何处开始执行。上电复位后,处理器使用预定义的内存位置中的复位向量值为程序计数器 (PC) 加载。在 CPU08 架构中,它位于位置 $FFFE:$FFFF。
The significance of the reset vector is that it points the processor to the memory address which contains the firmware’s first instruction. Without the Reset Vector, the processor would not know where to begin execution. Upon reset, the processor loads the Program Counter (PC) with the reset vector value from a predefined memory location. On CPU08 architecture, this is at location $FFFE:$FFFF.
当复位向量不必要时,开发人员通常会认为理所当然,并且不会对其编程以生成最终映像。结果,处理器不会在最终产品上启动。这是在调试阶段发生的常见错误。
When the reset vector is not necessary, developers normally take it for granted and don’t program into the final image. As a result, the processor doesn’t start up on the final product. It is a common mistake that takes place during the debug phase.
Stack Pointer
栈在RAM中实现,一个CPU寄存器用于访问它,称为SP(堆栈指针)寄存器。SP寄存器是8位寄存器,可以寻址范围为00h到FFh的存储器地址。最初,SP寄存器包含值07,指向位置08,作为8051为堆栈使用的第一个位置。
Stack is implemented in RAM and a CPU register is used to access it called SP (Stack Pointer) register. SP register is an 8-bit register and can address memory addresses of range 00h to FFh. Initially, the SP register contains value 07 to point to location 08 as the first location being used for the stack by the 8051.
当CPU寄存器的内容存储在堆栈中时,称为PUSH操作。当堆栈的内容存储在CPU寄存器中时,称为POP操作。换句话说,将寄存器推送到堆栈中以保存它,并将其弹出堆栈以检索它。
When the content of a CPU register is stored in a stack, it is called a PUSH operation. When the content of a stack is stored in a CPU register, it is called a POP operation. In other words, a register is pushed onto the stack to save it and popped off the stack to retrieve it.
Infinite Loop
无限循环或无穷循环可以标识为计算机程序中的一系列指令,由于以下原因,它们在循环中无限地执行−
An infinite loop or an endless loop can be identified as a sequence of instructions in a computer program that executes endlessly in a loop, because of the following reasons −
-
loop with no terminating condition.
-
loop with a terminating condition that can never be met.
-
loop with a terminating condition that causes the loop to start over.
此类无限循环通常会导致较旧的操作系统无响应,因为无限循环会消耗所有可用的处理器时间。等待用户输入的I/O操作也称为“无限循环”。计算机“冻结”的一个可能是无限循环;其他原因包括 deadlock 和 access violations 。
Such infinite loops normally caused older operating systems to become unresponsive, as an infinite loop consumes all the available processor time. I/O operations waiting for user inputs are also called "infinite loops". One possible cause of a computer "freezing" is an infinite loop; other causes include deadlock and access violations.
与PC不同,嵌入式系统从不“退出”应用程序。它们通过无限循环空闲,等待事件以中断的形式发生,或 pre-scheduled task 。为了节省电能,一些处理器进入特殊的 sleep 或 wait modes ,而不是通过无限循环空闲,但它们将在计时器或外部中断时退出此模式。
Embedded systems, unlike a PC, never "exit" an application. They idle through an Infinite Loop waiting for an event to take place in the form of an interrupt, or a pre-scheduled task. In order to save power, some processors enter special sleep or wait modes instead of idling through an Infinite Loop, but they will come out of this mode upon either a timer or an External Interrupt.
Interrupts
中断主要是硬件机制,用于指示程序事件已发生。它们可能随时发生,因此与程序流异步。它们需要处理器进行特殊处理,最终由相应的Interrupt Service Routine(ISR)处理。中断需要迅速处理。如果您花太多时间来处理中断,那么您可能会错过另一个中断。
Interrupts are mostly hardware mechanisms that instruct the program that an event has occurred. They may occur at any time, and are therefore asynchronous to the program flow. They require special handling by the processor, and are ultimately handled by a corresponding Interrupt Service Routine (ISR). Interrupts need to be handled quickly. If you take too much time servicing an interrupt, then you may miss another interrupt.
Little Endian Vs Big Endian
尽管数字总是以相同的方式显示,但它们在存储器中不是以相同的方式存储的。大端序机器将数据最重要的字节存储在最低的存储器地址中。大端序机器将0x12345678存储为−
Although numbers are always displayed in the same way, they are not stored in the same way in memory. Big-Endian machines store the most significant byte of data in the lowest memory address. A Big-Endian machine stores 0x12345678 as −
ADD+0: 0x12
ADD+1: 0x34
ADD+2: 0x56
ADD+3: 0x78
另一方面,小端序机器将数据的最小有效字节存储在最低存储器地址中。小端序机器将0x12345678存储为−
Little-Endian machines, on the other hand, store the least significant byte of data in the lowest memory address. A Little-Endian machine stores 0x12345678 as −
ADD+0: 0x78
ADD+1: 0x56
ADD+2: 0x34
ADD+3: 0x12