基于单片机的遥控小车系统外文翻译资料

 2022-09-22 10:09

Chapter 5. Getting to Know the Hardware

hardware n. The part of a computer system that can be kicked.

As an embedded software engineer, youll have the opportunity to work with many different pieces of hardware in your career. In this chapter, I will teach you a simple procedure that I use to familiarize myself with any new board. In the process, Ill guide you through the creation of a header file that describes the boards most important features and a piece of software that initializes the hardware to a known state.

5.1 Understand the Big Picture

Before writing software for an embedded system, you must first be familiar with the hardware on which it will run. At first, you just need to understand the general operation of the system. You do not need to understand every little detail of the hardware; that kind of knowledge will not be needed right away and will come with time.

Whenever you receive a new board, you should take some time to read whatever documents have been provided with it. If the board is an off-the-shelf product, it might arrive with a 'Users Guide' or 'Programmers Manual' that has been written with the software developer in mind. However, if the board was custom designed for your project, the documentation might be more cryptic or written mainly for the reference of the hardware designers. Either way, this is the single best place for you to start.

While you are reading the documentation, set the board itself aside. This will help you to focus on the big picture. There will be plenty of time to examine the actual board more closely when you have finished reading. Before picking up the board, you should be able to answer two basic questions about it:

  • What is the overall purpose of the board?
  • How does data flow through it?

For example, imagine that you are a member of a modem design team. You are a software developer who has just received an early prototype board from the hardware designers. Because you are already familiar with modems, the overall purpose of the board and the data-flow through it should be fairly obvious to you. The purpose of the board is to send and receive digital data over an analog telephone line. The hardware reads digital data from one set of electrical connections and writes an analog version of the data to an attached telephone line. Data also flows in the opposite direction, when analog data is read from the telephone line jack and output digitally.

Though the purpose of most systems is fairly obvious, the flow of the data might not be. I often find that a data-flow diagram is helpful in achieving rapid comprehension. If you are lucky, the documentation provided with your hardware will contain a superset of the block diagram you need. However, you might still find it useful to create your own data-flow diagram. That way, you can leave out those hardware components that are unrelated to the basic flow of data through the system.

In the case of the Arcom board, the hardware was not designed with a particular application in mind. So for the remainder of this chapter, well have to imagine that it does have a purpose. We shall assume the board was designed for use as a printer-sharing device. A printer-sharing device allows two computers to share a single printer. The user of the device connects one computer to each serial port and a printer to the parallel port. Both computers can then send documents to the printer, though only one of them can do so at a given time.

In order to illustrate the flow of data through the printer-sharing device, Ive drawn the diagram in Figure 5-1. (Only those hardware devices that are involved in this application of the Arcom board are shown.) By looking at the block diagram, you should be able to quickly visualize the flow of the data through the system. Data to be printed is accepted from either serial port, held in RAM until the printer is ready for more data, and delivered to the printer via the parallel port. The software that makes all of this happen is stored in ROM.

Figure 5-1. Data-flow diagram for the printer-sharing device

Once youve created a block diagram, dont just crumple it up and throw it away. You should instead put it where you can refer to it throughout the project. I recommend creating a project notebook or binder, with this data-flow diagram on the first page. As you continue working with this piece of hardware, write down everything you learn about it in your notebook. You might also want to keep notes about the software design and implementation. A project notebook is valuable not only while you are developing the software, but also once the project is complete. You will appreciate the extra effort you put into keeping a notebook when you need to make changes to your software, or work with similar hardware, months or years later.

If you still have any big-picture questions after reading the hardware documents, ask a hardware engineer for some help. If you dont already know the hardwares designer, take a few minutes to introduce yourself. If you have some time, take him out to lunch or buy him a beer after work. (You dont even have to talk about the project the whole time!) I have found that many software engineers have difficulty communicating with hardware engineers, and vice versa. In embedded systems development, it is especially important that the hardware and software teams be able to communicate with one another.

5.2 Examine the Landscape

It is often useful to put yourself in the processors shoes for a while. After all, the processor is only going to do what you ultimately instruct it to do with your software. Imagine what it is like to be the

剩余内容已隐藏,支付完成后下载完整资料


第五章,认识硬件

硬件,即电脑系统中能被踢到的部分。

作为嵌入式软件工程师,在你的职业生涯里你将有机会与许多不同的硬件一起工作。在本章中,我会用任何新的电路板来教你一个我自己熟悉的简单的流程。在这个过程中,我会通过创建一个描述主板最重要特点的头文件和一张初始化硬件到已知状态的软件来引导你。

了解大局

为嵌入式系统编写软件之前,必须先熟悉上它所运行于其上的硬件。首先,你只需要了解系统的一般操作。你不需要了解硬件的每一个细节;那种知识不会马上需要,并会随着时间的推移而逐渐获得。

每当你收到一个新的板子,你应该花一些时间来阅读任何它已经提供的文件。如果电路板是一个现成的产品,它可能是以一种已经充分考虑了软件开发人员想法的“用户手册”或“程序员手册”的形式到达。但是,如果板子是为您的项目定制的,该文档可能会更隐蔽或主要给硬件设计人员提供参考。无论哪种方式,这是你开始的最好地方。

当你正在阅读文档的时候,把板子本身放在一边,这将帮助你专注于大局。在你读完文档后将有充足的时间来更仔细地检查实际的板子。在拿起板子之前,你应该能够回答有关它的两个基本问题:

什么是板子的总体目的?

数据如何流过它?

例如,假设你是调制解调器设计团队中的一员。你是一个刚刚从硬件设计师那里收到了早期原型板的软件开发人员。因为你已经熟悉了调制解调器,那么板子的大致目的和流过它的数据对你来说应该是相当明显了。板的目的是通过模拟电话线发送和接收数字数据。硬件从一组电气连接中读取数字数据和写入模拟数据到一个附加的电话线路。当模拟数据从电话线插口读取和输出数字数据时,数据还会流往相反的方向。

虽然大多数系统的目的是相当明显的,但数据的流向可能不是。我经常发现一个数据流程图对快速理解很有帮助。如果你很幸运,那和硬件一起提供的文档将包含你所需要的框图的一个超集。然而,你可能仍然发现创建自己的数据流程图很有用。这样的话,你可以通过流经系统的数据流来跳过那些不相关的硬件组件。

对Arcom板而言,硬件没有设计特定的用途。因此,对于本章的剩余部分,我们将不得不想象它确实有一个目的。我们可以假设电路板设计为打印机共享设备。打印机共享设备允许两台电脑共享一台打印机。该装置的用户连接一个计算机到每个串行端口伊及连接打印机到并行端口。那么这两个计算机可以将文件发送到打印机,但只有一个可以在给定的时间这样做。

为了说明通过打印机共享设备的数据流动,我画了图5-1的示图。 (仅示出了Arcom板里所涉及的那些硬件装置。)通过查看框图,你应该能够直观了解通过该系统的数据流动。要打印的数据从任一串行端口接受,在RAM中保存直到打印机准备好接收更多的数据,并通过并行端口传送到打印机。使得这一切发生的软件存储在ROM中。

图5-1 打印机共享设备的数据流程图

一旦你创建了一个框图,不要只是揉碎它,并把它扔掉。而应该把它放在你可以全程参考它的地方。我建议在第一页上创建一个项目的数据流图笔记或便利贴。随着您继续使用这块硬件,写下你了解的一切。您可能还希望记下有关软件设计和实现票据的笔记。工程的笔记不仅在你正在开发软件的时候是有价值的,项目完成后亦是如此。在几个月或几年后,当你需要更改你的软件或类似硬件的时候,你将感激你记笔记的额外努力。

如果你在阅读的硬件文件后仍有大局的问题,那么向硬件工程师寻求帮助吧。如果你还不认识硬件的设计师,花几分钟时间来介绍自己。如果你有时间,带他出去吃午饭或下班后请他喝啤酒。(你甚至不必一直都谈项目!)我发现,许多软件工程师同硬件工程师交流时有困难,反之亦然。在嵌入式系统的开发中,硬件和软件团队能够彼此交流是特别重要的。

5.2检查蓝图

把自己放在处理器的位置一段时间往往是有益的。毕竟,处理器只做你最终用你的软件来指示它做的事。想象一下做处理器是怎样的,处理器的世界会是什么样子?如果从这个角度去想,你很快会意识到的一件事是,处理器有很多同胞。这些都是电路板上处理器可以直接通信的其他部分。在本节中,你将学会识别他们的姓名和地址。

首先要注意的事情是有两种基本类型:存储器和外设。显然,存储器是用于数据及代码存储和检索的。但是,你可能想知道的外设是什么。这些要么是与外界坐标(I / O)相互作用的专门硬件设备,要么是执行特定功能的硬件。例如,在嵌入式系统中最常见的两个外设是串行端口和定时器。前者是一个I / O设备,而后者基本上是一个计数器。

英特尔80x86和其他一些家族处理器的成员有两个不同的地址空间,通过这些存储器和外设它们可以进行通信。第一地址空间被称为存储器空间,主要用于存储器装置;第二个是专门预留给外设的,被称为I / O空间。然而,外围设备也可以位于存储器空间内,这由硬件设计者决定。当这种情况发生时,我们说这些外设是内存映射。

但从处理器的角度来看,内存映射外设的外观和行为非常像存储设备。然而,外围设备的功能很明显跟一个存储器的完全不同。外围可能被解释为命令或数据以某种方式被处理,而不是简单地存储提供给它的数据。如果外设位于存储空间内,我们说系统有内存映射I / O。

嵌入式硬件的设计人员往往喜欢只使用内存映射I / O,因为它对硬件和软件开发商都有优势。这对硬件开发者有吸引力,因为他也许能消除I / O空间,以及一些与其相关的电线。这可能不能显著降低电路板的生产成本,但它可能会降低硬件设计的复杂性。内存映射的外设也更有利于程序员,使他们能够更有效且更容易地使用指针,数据结构以及与外围设备进行交互联合。[1]

5.2.1记忆地图

所有的处理器都把程序和数据存储在内存中。在某些情况下,这种存储器驻留在和处理器相同的芯片上,但是它更常见地位于外部存储器芯片上。这些芯片位于处理器的存储器空间,并且所述处理器通过两组称为地址总线和数据总线的电导线与他们进行通信。要读取或写入内存中的特定位置时,处理器首先写入所需的地址到地址总线上。然后数据通过数据总线传输。

当你正在阅读一个新的板子时,创建一个表,其中显示位于内存空间的每个存储设备和外设的名称和地址范围。组织这个表格,以便最低的地址是在底部且最高得地址是在顶部。每次你添加设备到存储映射时,请将其放在内存合适的位置中,并用十六进制贴上起始和结束的地址标签。在你插入所有的设备到存储器映射后,一定要标注任何未使用的存储区域。

如果你回头看看图5-1 Arcom板的框图,你会看到有三种设备附加到地址和数据总线上。这些器件分别是RAM、ROM以及一个标有“Zilog85230串行控制器”的神秘装置。由Arcom提供的文档说RAM位于存储器的底部,向上延伸到第一个128 KB的内存空间。该ROM位于内存的顶部向下延伸256 KB。但是,这种存储区实际上包含两个ROM中,一个EPROM和一个闪存器件,每个大小为128 KB。第三个装置中,Zilog85230串行通信控制器,是一个寄存器地址为70000h和72000h之间的存储器映射外设。

在图5-2的存储器框图上显示出这些设备对处理器来说是什么样的。在某种意义上,这是处理器的“地址簿”。正如你在你的个人生活里保持姓名和地址的列表,你必须为处理器保有类似的列表。存储器映射包含每个从处理器的存储器空间访问存储器和外设的一个条目。此图可以说是关于信息系统中最重要的部分,应该及时更新并且做为与项目有关的永久性记录的一部分。

图5-2 Arcom板的存储器映射图

对于每一个新板子,你应创建一个描述其最重要特点的头文件。此文件为硬件提供一个抽象接口。实际上,它允许你通过名字来引用在电路板上的各种设备,而不是地址。这对于使你的应用软件更便携很有好处。如果存储器映射发生了改变,例如,如果RAM的128 KB发生移动,你只需要更改受影响的特定板子的头文件然后重新编译你的应用程序。

正如本章的进程,我将向你展示如何为Arcom板创建头文件。该文件的第一部分如下。下面的头文件的某部分描述了存储器映射。在头文件存储器映射以及在图5-2之间的最显着的区别是地址的格式。指针和地址解释了原因。

/**********************************************************************

*

* Memory Map

*

* Base Address Size Description

* -------------- ----- -----------------------------------

* 0000:0000h 128K SRAM

* 2000:0000h Unused

* 7000:0000h Zilog SCC Registers

* 7000:1000h Zilog SCC Interrupt Acknowledge

* 7000:2000h Unused

* C000:0000h 128K Flash

* E000:0000h 128K EPROM

*

**********************************************************************/

#define SRAM_BASE (void *) 0x00000000

#define SCC_BASE (void *) 0x70000000

#define SCC_INTACK (void *) 0x70001000

#define FLASH_BASE (void *) 0xC0000000

#define EPROM_BASE (void *) 0xE0000000

指针和地址

在C和C 中,指针的值是一个地址。所以,当我们说我们有一个数据指针式,我们实际意味着我们有该数据的存储地址。但是程序员通常不直接设置或检查这些地址。例外的是那些需要在他们的代码中明确设置一个指针值的操作系统、设备驱动程序和嵌入式软件的开发人员。

不幸的是,地址的确切表示可以从处理器到处理器改变或甚至可以是依赖于编译器。这意味着像12345h的物理地址可能不被存储在固定的形式,甚至有可能由不同的编译器不同地进行存储。[2]然后出现的问题是一个程序员如何设置一个指针的明确值,以便它指向存储器映射中的所需位置。

大多数80times;86处理器的C/ C 编译器使用32位指针。然而,较旧的处理器没有简单的线性32位地址空间。例如,Intel的80188EB处理器仅具有20位的地址空间。并且,除此之外,它的内部寄存器不能容纳超过16位字节。所以在这个处理器上,2个16位寄存器,段寄存器和一个偏移寄存器被组合起来以创建一个20位的物理地址。 (物理地址计算涉及左移四位段寄存器的内容,并加上所述偏移寄存器的内容到结果。在任何溢出道21位的地址会被忽略。)

声明并初始化一个指向物理地址为12345h的寄存器,我们这样写:

int * pRegister = (int *) 0x10002345;

其中,最左边的16位包含段值,最右边的16位包含偏移值。

为方便起见,80x86的程序员有时编写地址作为段:偏移对。使用此表示法,物理地址为12345h的将写作为0x1000:2345。这恰恰是价值的SAN(冒号)我们用来初始化上面的指针的。然而,每个可能的物理地址有4096个不同段:指向一个给定的物理地址。例如,成对的0x1200:0345和0times;1234:0005(和4093等)也指物理地址12345h。

5.2.2 I / O地图

如果一个单独的I / O空间存在,重复存储器映射锻炼以创建板上的I / O映射将是必要的。过程是完全相同的。简单地创建外围的名称和地址范围的表格,以这样的方式则最低地址在底部。典型的是,I / O空间的很大比例将是未使用的,因为大多数位于外设上的空间将只有屈指可数的寄存器。

Arcom板的I / O映射如图5-3所示。它包括三个器件:外围控制块(PCB),并行端口,和调试端口。该PCB是一组位于80188EB内用于控制片上外设寄存器的。控制并行端口和调试端口的芯片驻留在处理器的外部。这些端口用于与打印机和基于主机的调试器分别进行通信。

图5-3 Arcom板的I / O图

创建您的主板头文件时,I / O映射也很有用。每一个I / O空间中的区域直接映射到一个常数,称为基址。上面的I / O映射为一组常量的转换可以在下面的清单中找到:

/**********************************************************************

*

* I/O Maplt;

剩余内容已隐藏,支付完成后下载完整资料


资料编号:[148245],资料为PDF文档或Word文档,PDF文档可免费转换为Word

原文和译文剩余内容已隐藏,您需要先支付 30元 才能查看原文和译文全部内容!立即支付

以上是毕业论文外文翻译,课题毕业论文、任务书、文献综述、开题报告、程序设计、图纸设计等资料可联系客服协助查找。