Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Bailey O.H.Embedded systems.Desktop integration.2005

.pdf
Скачиваний:
73
Добавлен:
23.08.2013
Размер:
9.53 Mб
Скачать

40

Chapter 2 / Embedded System Design

 

 

Clock & Data Arrive on Different Lines at the Same Time

Source

Device

Figure 2-7

 

 

 

 

 

 

Address

 

0

 

Line 0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Address

 

1

 

Line 1

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Address

 

1

 

Line 2

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Address

 

0

 

Line 3

 

 

 

 

 

 

 

 

 

Destination

 

 

 

 

 

Address

 

1

 

Line 4

 

 

 

 

Device

 

 

 

 

 

 

 

 

 

 

 

Address

 

0

 

Line 5

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Address

 

1

 

Line 6

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Address

 

1

 

Line 7

 

 

 

 

 

 

 

 

 

 

 

Clock Line

 

 

 

 

 

 

 

 

Chapter 2 / Embedded System Design

41

 

 

The Communications World of

Windows and UNIX

Because embedded processors are used in out-of-the-way places and because they usually manage some type of mechanical or electrical control or appliance, the developer must be familiar with the actual hardware. Windows and UNIX systems were designed to be used by humans. Because of this there are many more layers of software between the hardware layer and the user. Device interfaces are handled at a much lower level, keeping human interaction minimal when using the system to address external devices. To make a system intuitive and easy for a person to use, much effort must go into the design and implementation under the hood. Unlike the embedded system where a single layer acts as the handler of all data, I/O, and user interaction, Windows and UNIX have a presentation layer that communicates with the user, a file handler that reads and writes file I/O, and a device layer that moves data between devices, files, and user interfaces. Rather than looking at the actual electrical signals in a device, the device is opened and the driver acts as the interpreter between the actual hardware and desktop application. This means the programmer doesn’t have to be an electronics engineer to address the hardware. In fact most applications programmers have little or no knowledge of the hardware. They simply open, read, write, and close files or device names.

Chapter 2

42

Chapter 2 / Embedded System Design

 

 

The Protocol, a Bridge between Different Worlds

The protocol is the software that bridges the embedded system and Windows, UNIX, and potentially any other system. Once the embedded hardware is defined, the protocol message categories are defined. Defining the message types and data definitions allows us to build a software bridge.

On the embedded system the protocol is implemented in software but becomes functional in hardware once the code is burned into the processor. On Windows and UNIX the protocol is developed as a shared library, or DLL. This allows the protocol to be seen by the application as a black box and prevents tampering with the protocol, thus keeping its integrity intact. The application programmer will open this black box by name or as a file and through a series of defined record or structure layouts will simply send these records off and await a response. Figure 2-8 graphically illustrates the differences between the embedded system and the Windows and UNIX hosts. The first block shows the embedded device model. There is no device driver layer because the embedded system deals with events and device interfaces directly. The second block is the physical interface layer. This would be the RS-232, USB, or Ethernet cable that connects the physical interface to the device. The third block contains two sections. The first is the device interface and protocol layer. This is functionally the same as the embedded system, interfacing directly to electrical signals. The second portion of this is the application layer. The application layer formats the messages and sends them through a device driver layer and eventually to the embedded system.

Chapter 2 / Embedded System Design

43

 

 

Outputs

 

Inputs

 

 

 

Embedded Device Application

 

Data Protocol Layer

 

Hardware

2

Physical Interface (RS-232, USB, Ethernet)

Chapter

 

 

Hardware

 

Device Driver Layer

 

Software Protocol Layer

 

UserI/O

 

Application Layer

Keyboard

Display

Figure 2-8

 

Embedded System Protocol Functions

In specifying a protocol we must define a formal set of rules that allow the embedded system designer and application software engineers to communicate. We then eliminate the possibility of miscommunications between these devices by specifying a procedure that allows all the devices to communicate only when it is their turn. Using this strategy we can convert data so it is always properly interpreted by the host and embedded system. This formal type of communication is called a protocol. As the embedded

44

Chapter 2 / Embedded System Design

 

 

system design process evolves it is broken down into a logical flow of data as shown in the following diagram.

 

 

 

 

INPUTS

 

 

 

StatusData

Sensor1

Sensor2

Sensor3

CharInput

Connection

To Host

 

 

 

 

 

 

Temperature Inputs

 

User Inputs

Host/LAN

 

CommandData

1Fan

Embedded Device

From Host

2Fan

3Fan

DataChar

 

 

 

 

 

 

 

 

 

 

Fan Control Outputs

 

LCD Display Output

 

 

 

 

OUTPUTS

 

Figure 2-9

In Figure 2-9 you can see the embedded system does little more than read inputs from temperature sensors, adjust outputs to control fans and other environmental equipment, process host commands for logging and control messages for climate overrides, and provide data to the host and end user for monitor and display purposes. As our design progresses the arrows will eventually turn into processor pins on the embedded system that monitor or control environmental functions. The data flow arrows identify a serial, USB, or Ethernet connection to the host. Since we now have a defined flow of data and control within the embedded system, we will establish the foundation for a communications protocol between the embedded system and the desktop

Chapter 2 / Embedded System Design

45

 

 

computers. A message sent that doesn’t conform to protocol definitions will be ignored. Expanding the system in the future simply requires additional message types, categories, and message fields. To maintain backward compatibility the protocol will contain a protocol version. Adding new message types in the future will increment the version number. This assures a path to expansion while being able to process legacy messages without modifying the hardware in the field.

Communications Protocol History

Protocols have existed in the communications industry for many years. Datapoint developed the ARCNET protocol as the first broadband network protocol many years ago. ARCNET was the basis of what eventually became the Ethernet protocol. Today, Ethernet is the most widely used network protocol for LANs and WANs. Ward Christenson developed the X-Modem protocol in Chicago over 20 years ago as a way to transmit files from one computer to another and assure no data was lost or garbled in the process. These are two excellent examples of why protocols are developed and the functions they serve.

For our purpose a simple protocol will suffice as a simple means of establishing communications between the desktop computers and the embedded systems. We are simply establishing a format by which the two systems can talk and a priority handshake by which each party can take their turn speaking to prevent data collisions. Protocols are implemented every day for many different types of communications. In their simplest form they establish a set of commands or words each party or computer understands. In their most complex form they introduce error checking to make sure every word is spelled properly and used in proper context. Every protocol is different and is based on a specific need or requirement.

Building a good protocol is done in small steps. By illustrating each step we go from concept to working model by checking our query and response tables against our real-world requirements. It is very easy to write down the requirements and

Chapter 2

46

Chapter 2 / Embedded System Design

 

 

develop a working protocol; this is done all the time. There are several reasons why I am taking smaller steps. They are:

Proper data size definitions need to be established across all platforms

Thorough query definitions

Thorough response definitions

Functional completeness

Protocol Definition Considerations

By breaking down the requirements from Chapter 1 into smaller pieces we can determine how large a data message will be and how many commands our protocol will require. The following diagram shows detailed information on the data flow of the embedded system.

 

 

Temperature Sensor

 

SetAlarm

Temp

Check Alarm

Temp Alarm

Read Temp

 

 

Embedded Processor

 

Temp Alarm Data

 

 

 

 

Zone Temp Data

 

 

 

 

Set Zone Temp Alarm

 

Figure 2-10

From Figure 2-10 it is clear the data flow for the temperature sensors, temperature alarms, and zone temperature information is sent to the host but only if the host is connected and requests the information. The host can send zone alarm limits back to the

Chapter 2 / Embedded System Design

47

 

 

embedded processor. This allows the host to monitor temperature and temperature alarms and set the temperature alarm triggers, which in this case is setting a high and low temperature for each sensor to act upon. If the temperature range is between the high and low settings, no action is taken. If the range goes above or below those range settings, an alarm condition will cause the embedded system to start the heating or air conditioning and the associated fans for air movement. Addressing each sensor through its unique ID sets temperature ranges. The temperature can be read or a query can be generated to see if an alarm condition exists.

For the purpose of this book we will be controlling a small fan that turns on or off depending on temperature and/or alarm conditions as shown in Figure 2-11. The fans are managed completely by the embedded system through the use of an electronic switch. Since we are working on a small scale, a single byte is output to the switch to turn the fan on or off. Each bit that is turned on will turn a fan motor on. Each bit that is turned off will turn the fan motor off. The single byte used to manage the switch is stored in non-volatile memory, which allows the status

Connection

Control

Embedded

 

 

 

 

 

 

 

 

 

Host/LAN

Status

Processor

 

 

 

SetFan Status

ReadFan

Status

 

 

Fan Outputs

 

 

 

Fan1

Fan2

 

Fan3

Chapter 2

Figure 2-11

48

Chapter 2 / Embedded System Design

 

 

to be retained even if power is lost. Upon request the host can have the embedded processor retrieve the data and send it to the host for display, logging, or control purposes. The host can also tell the device to change the fan status by simply sending a new message to replace the old one. So, in addition to our temperature data, we can add a simple fan monitor and control message.

After temperature measurement, user input and display messages need to be included in the protocol. A single byte gives the ability to read eight switches. While there are currently two buttons, using a byte gives us expansion capability. In Figure 2-12 we see how user interface information flows.

Host / LAN Connection

Keyboard

Control Embedded

Status Processor

LCD

Display

Figure 2-12

This completes the data flow picture for each function the embedded system performs. Our protocol will handle keyboard and LCD messages in addition to controlling and monitoring the system in general. The keyboard is a read-only device. While an LCD is typically an output-only device, some LCDs have the ability to store special character sets and read them back. LCDs may

Chapter 2 / Embedded System Design

49

 

 

also allow their display contents to read by location, line, or all character positions at once. Since LCD designs are constantly changing, our protocol will be flexible enough to handle varying device types without making code changes. We have now mapped all the functions of the embedded system. Next we will take this information and implement the protocol.

Designing the Device Protocol

We start by listing the functions of the embedded system and placing those functions in categories. The following table illustrates the functions of the embedded system and the categories we have assigned them.

Table 2-2: Embedded system functions

Function

Category

 

 

Collect and monitor temperature changes

CLIMATE

 

 

Respond to temperature changes and alarms

CLIMATE

 

 

Monitor, control, and override fan controls

CLIMATE

 

 

Monitor remote user input

SYSTEM

 

 

Output remote display data

SYSTEM

 

 

Change remote message text

SYSTEM

 

 

Next we list the functions monitored by the host systems and assign each to a category. Table 2-3 illustrates these functions and categories.

Table 2-3: Desktop system functions

Function

Category

 

 

Collect temperature data

CLIMATE

 

 

Set temperature alarm

CLIMATE

 

 

Temperature alarm response

CLIMATE

 

 

Manual climate override

SYSTEM

 

 

Monitor remote user inputs

SYSTEM

 

 

Chapter 2

Соседние файлы в предмете Электротехника