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
剩余内容已隐藏,支付完成后下载完整资料
了解硬件
硬件 n.计算机系统中可拆分的部分。
作为一个嵌入式软件工程师,你将有机会在你的职业生涯中接触许多不同的硬件。在本章中,我将教你一个简单的过程,我用来熟悉任何新的主板。在这个过程中,我将指导你创建一个头文件,描述了主板的最重要的功能和一块软件,初始化硬件到已知状态。
5.1了解概况
在为嵌入式系统编写软件之前,首先必须熟悉它将运行的硬件。首先,你只需要了解系统的一般操作。你不需要了解硬件的每一个小细节,这种知识不会马上需要并且是与时俱进的。
每当你收到一个新的主板,你应该花一些时间阅读无论它提供了什么文件。如果主板是一个现成的产品,可能会出现与软件开发人员一起撰写的“用户指南”或“程序员手册”。但是,如果该板是为您的项目定制设计的,文档可能更神秘或主要用于硬件设计者的参考。无论哪种方式,这是最适合你开始的地方。
当你在阅读文档时,把板放在一边。这将有助于你关注大局。当你完成阅读的时候,会有大量的时间来仔细检查实际的板子。在拿起板子之前,你应该能够回答两个基本问题:
1.板子的总体目标是什么?
2.如何通过数据流量呢?
例如,假设您是调制解调器设计团队的成员。你是一个刚刚从硬件设计师那里收到早期原型板的软件开发人员。因为你已经熟悉调制解调器了,板子的总体目的和通过它的数据流应该是相当明显的。板子的目的是通过模拟电话线发送和接收数字数据。硬件从一组电气连接读取数字数据,并将数据的模拟版本写入附加的电话线。数据也流向相反的方向,当模拟数据从电话线插座和输出以数字形式被读出。
虽然大多数系统的目的是相当明显的,数据流可能不是。我经常发现数据流图有助于实现快速理解。如果你是幸运的,你的硬件所提供的文件将包含你需要的一个超集框图。但是,您可能仍然觉得创建自己的数据流图很有用。这样,就可以省去那些与系统基本数据无关的硬件组件。
在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和一个神秘的装置“Zilog 85230串行控制器。”Arcom提供的文件说,RAM位于内存的底部且向上延伸的前128 KB的内存空间。ROM位于内存的顶部,向下延伸为256 KB。但这方面的内存实际上包含两个ROM—一个EPROM和一个闪存设备,每个大小128 KB。第三设备,Zilog 85230串行通信控制器,是一个内存映射外设,其寄存器访问的地址70000h和72000h之间。
图5-2中的内存映射显示了这些设备对处理器的作用。从某种意义上说,这是处理器的“地址簿”,就像你在个人生活中保留一个名字和地址的列表一样,你必须为处理器保存一个类似的列表。内存映射包含从处理器的存储空间访问的每个存储器和外围设备的一个条目。这个图表可以说是系统中最重要的信息,应该保持最新的信息,并作为与项目相关的永久记录的一部分。
图5-2 对于ARCOM板内存映射
对于每一个新的板子,你应该创建一个来描述它最重要的特性的头文件。此文件提供硬件的抽象接口。实际上,它允许您通过名称而不是地址来引用板上的各种设备。这具有使应用软件更便于携带的附加益处。如果内存映射发生变化,例如,如果移动了128 KB的RAM,则只需更改特定于板的头文件的受影响的行并重新编译应用程序。
本章将介绍如何为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 ] 然后出现的问题是程序员如何能够明确地设置一个指针,以便它指向存储器映射中的所需位置。
大多数用于80x86处理器的C / C 编译器使用32位指针。然而,旧的处理器没有简单的线性的32位地址空间。例如,英特尔的80188eb处理器有20位地址空间。此外,它的内部寄存器不能容纳超过16位。所以在这个处理器,两个16位寄存器(一个段寄存器和一个偏移寄存器)组合起来创建20位的物理地址。 (物理地址计算涉及将段寄存器的内容左移四位,并将偏移寄存器的内容添加到结果中,任何溢出到第21位都将被忽略)
为了声明和初始化一个位于物理地址12345h的寄存器的指针,我们写:
int * pregister =(int *)0x10002345;
在最左边的16位包含的段值和最右边的16位包含的偏移值。
为方便起见,80X86程序员有时会将地址写成段:offset对。用这个符号,物理地址12345h会写成 0x1000:2345。这正是我们用来初始化上面指针的无效的冒号。然而,对于每个可能的物理地址有4096个不同的段:指向给定物理地址的偏移对。例如,对 0x1200:0345 和 0x1234:0005 (4093人)也指的是物理地址12345h。
如果存在单独的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 Map
*
* Base Address Description
* --------------- ----------------------------------------
* 0000h Unused
* FC00h SourceVIEW Debugger Port (SVIEW)
* FD00h Parallel I/O Port (PIO)
* FE00h Unused
* FF00h Peripheral Contro
剩余内容已隐藏,支付完成后下载完整资料
资料编号:[139751],资料为PDF文档或Word文档,PDF文档可免费转换为Word
您可能感兴趣的文章
- 饮用水微生物群:一个全面的时空研究,以监测巴黎供水系统的水质外文翻译资料
- 步进电机控制和摩擦模型对复杂机械系统精确定位的影响外文翻译资料
- 具有温湿度控制的开式阴极PEM燃料电池性能的提升外文翻译资料
- 警报定时系统对驾驶员行为的影响:调查驾驶员信任的差异以及根据警报定时对警报的响应外文翻译资料
- 门禁系统的零知识认证解决方案外文翻译资料
- 车辆废气及室外环境中悬浮微粒中有机磷的含量—-个案研究外文翻译资料
- ZigBee协议对城市风力涡轮机的无线监控: 支持应用软件和传感器模块外文翻译资料
- ZigBee系统在医疗保健中提供位置信息和传感器数据传输的方案外文翻译资料
- 基于PLC的模糊控制器在污水处理系统中的应用外文翻译资料
- 光伏并联最大功率点跟踪系统独立应用程序外文翻译资料
