Bailey O.H.Embedded systems.Desktop integration.2005
.pdf
50 |
Chapter 2 / Embedded System Design |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Function |
Category |
|
|
|
|
|
|
|
|
Manage remote message output |
SYSTEM |
|
|
|
|
|
|
|
|
Edit remote display messages |
SYSTEM |
|
|
|
|
|
|
We have now completed the function and category tables for both the embedded system and desktop systems. Using the categories we have just created we will build our message tables. Since we have accounted for both the embedded system and host system functions, we can now consolidate the rest of the protocol definitions into a single table. In Table 2-4 we have taken each function in the previous two tables and assigned each to a message type. Once our categories and message types are defined, we can determine the parameters that will be associated with each function. Here I have assigned a message type and parameter type to the function categories.
Table 2-4: Message definitions
Category |
Type |
Message Definition |
Parameters |
|
|
|
|
CLIMATE |
MONITOR |
Request temperature |
Sensor ID |
|
|
|
|
CLIMATE |
CONTROL |
Set temperature alarm level |
Sensor ID, Hi/Lo Level |
|
|
|
Alarms |
|
|
|
|
CLIMATE |
MONITOR |
Check temperature alarm |
Sensor ID |
|
|
|
|
CLIMATE |
MONITOR |
Check all temperature |
None |
|
|
alarms |
|
|
|
|
|
CLIMATE |
MONITOR |
Get fan status |
Sensor ID |
|
|
|
|
CLIMATE |
CONTROL |
Set fan status |
Sensor ID |
|
|
|
|
SYSTEM |
MONITOR |
Check keyboard |
None |
|
|
|
|
SYSTEM |
MONITOR |
Get current display message |
None |
|
|
|
|
SYSTEM |
CONTROL |
Display user message |
Message ID |
|
|
|
|
SYSTEM |
CONTROL |
Change display message text |
Message ID |
|
|
|
|
SYSTEM |
MONITOR |
Request status |
Status ID |
|
|
|
|
SYSTEM |
CONTROL |
Set status |
Status ID, Message |
|
|
|
Length |
|
|
|
|
Chapter 2 / Embedded System Design |
51 |
|
|
Protocol Message and Variable Size
Considerations
We are now ready to assign a variable size to each message. We are doing this so we can make certain we always use a variable of the same size for each system that uses the protocol. Using the data from the above tables, the variable definitions are as follows:
Table 2-5: Message variable size
Variable Name |
Size |
|
|
Sensor ID |
1 byte |
|
|
Alarm Type |
1 byte (0 = Low, 1 = High) |
|
|
Alarm Temperature Setting |
2 bytes |
|
|
Message ID |
1 byte |
|
|
Message Size |
2 bytes |
|
|
We have now completed the protocol definition from the host (or desktop) query side. We have two message categories: climate and system. We also have two message types: monitor and control. In our final step we allocate a size to each variable we have defined. In Table 2-6 I have completed the definition structure.
Table 2-6: Completed message definition structure
Name |
Variable Size |
Accepted Values |
|
|
|
Message Category |
1 byte |
0-255 |
|
|
|
Message Type |
1 byte |
0-255 |
|
|
|
Sensor ID |
1 byte |
0-255 |
|
|
|
Alarm Type |
1 byte |
0 = Low, 1 = High |
|
|
|
Temperature |
2 bytes |
0-65535 |
|
|
|
Message ID |
1 byte |
0-255 |
|
|
|
Message Size |
2 bytes |
0-65535 |
|
|
|
Chapter 2
52 |
Chapter 2 / Embedded System Design |
|
|
To provide the flexibility of being able to add new messages without modifying the hardware I have added a variable called Message ID. Each message type will have an associated ID. Since a single byte can hold a value of 0 to 255, we have plenty of room for additional messages without changing the protocol. This means we can design several generations of this product or use this same protocol for several product lines without making further changes to the embedded or host system software. We’ve also declared a Message Size variable that holds the complete message length. This allows us to have messages of varying length (such as display text messages) and also allows us to change the size of existing messages without any changes needed to the protocol itself.
Embedded System Protocol Responses
Message categories, types, variables, and sizes have all been defined. During the implementation phase we will build a device response for each query from the host. Since our protocol is now completed, adding the responses during implementation will simply give us a list of possible responses. In order to visualize our protocol, following is a query and response table.
In Figures 2-13 and 2-14 the Control column is the host system making the control request. The Status column is the embedded system’s response. The Message Type column is the message class as viewed from the host side. Figure 2-13 shows the monitor class messages while Figure 2-14 shows the control class messages.
Chapter 2 / Embedded System Design |
53 |
|
|
Control |
|
Status |
|
|
|
Request |
|
Send |
Temperature |
|
Temperature |
|
|
|
|
|
|
Set |
|
Set |
|
Temperature |
|
Temperature |
|
|
|
& |
|
Alarm |
|
|
|
Acknowledge |
|
|
|
|
|
|
|
text
Get Temperature
Alarms
Get Fan
Status
Set Fan
Status
Send Pending
Alarms
Send
Fan
Status
Set Status
&
Acknowledge
Message
Type
Monitor
Control
Monitor
Monitor
Control
Figure 2-13
Chapter 2
54 |
Chapter 2 / Embedded System Design |
|
|
Control |
|
Status |
Message |
|
Type |
||
|
|
|
|
|
|
|
|
Get |
|
Send |
Monitor |
Key |
|
Key or NoKey |
|
|
|
||
|
|
|
|
Get
Send
LCD Msg
Message Monitor or NoMsg
Set
Set Message
LCD Msg
& Control
Acknowledge
text
Change |
Store Message |
|
Stored LCD |
& |
Control |
Message |
Acknowledge |
|
Get |
Send |
Device Status |
Monitor |
Status |
Set |
Set Status |
|
|
& |
Control |
||
Device Status |
|||
Acknowledge |
|
||
|
|
Figure 2-14
Chapter 2 / Embedded System Design |
55 |
|
|
Embedded System Summary
By defining each duty the embedded system is responsible for we have created a functional description for all device inputs and outputs. Using I/O definitions allowed us to define a protocol that a host computer can use to communicate with the device. Defining this information allows us to develop a complete protocol that can be used by the device and other systems to communicate.
Protocol Summary
We have now thoroughly defined a communications protocol by which our embedded system, Windows, and UNIX systems can all communicate. Message categories, types, variable names, and sizes have all been defined. We have made our protocol expandable by having room for new message types and varying message sizes.
When the need arises for a communications protocol to be developed there are always many details to consider. Walking through the protocol development process one step at a time assures that all the little details have been thought of and dealt with properly. Using this technique you are assured of building a solid protocol that will meet current and future needs without constant changes.
Chapter 2
56 |
Chapter 2 / Embedded System Design |
|
|
Chapter Summary
The embedded system now has a formal language that allows it to talk to the world. While this is a simple example, it covers handling device input, device output, display output, user input, and the remote monitoring and control of the environment. In the process of establishing a protocol we have narrowed the differences between desktop systems and the embedded system to the interface or device driver layer on the host systems. Our device input and output seamlessly interface to a protocol that the device driver layer uses to send and receive messages to a remote system. On the host side this protocol interfaces to the device driver, which will in turn interface to the desktop application layer. In the next chapter we will design the device interface layer to handle the differences in the hardware layer and the differences between UNIX and Windows. This approach will lead us to design a user application that will interface to the device driver layer the same way across platforms.
Chapter 3
Designing Portable Device Interfaces for Windows and UNIX
Overview
This is by far the most difficult chapter of this book and the largest chapter so far. If you have never written a device driver I recommend reading this chapter twice — the first time to learn the architecture and the second time to understand the design.
While there are many similarities between the current Intel-based UNIX and Windows 32-bit architectures, there are just as many differences. There are many factors that contribute to how portable a device driver can and will be. Some of these factors are:
Language portability — C, C++, etc.
Existing OS support — Whether some level of driver support is already present
Legacy driver support — Whether a similar device driver has already been developed in prior OS versions
57
58Chapter 3 / Designing Portable Device Interfaces for Windows and UNIX
Device type — Whether past versions of the OS supported this device type
Driver structure — Whether a complete driver needs to be written or a mini-driver or “wrapper layer” will suffice
Designing a portable device driver isn’t a decision that will be made at a given point in the development cycle. It is a decision that will be made from the project start and will influence decisions throughout the development cycle. This single decision can have the largest impact on the overall cost of a project. In an ideal world the implementation phase of this project would be the easiest since it would merely be implementing the work already defined. But as we all know, this is not an ideal world. Technology industries are constantly forging ahead with new ideas, products, and enhancements to existing products. It is not uncommon for one or more operating system updates to be released between the design of a product and its implementation. For that reason, any experienced software architect knows a certain amount of flexibility needs to be incorporated into the design. If this isn’t done, you can expect what I call the infinite design cycle implementation. Each time the implementation team gets the design, some changes need to be made to support the latest OS changes, so the design is sent back. Well, guess what happens by the time the design changes are made, reviewed, approved, and sent back. You guessed it — the whole cycle starts again.
Let’s examine each of the above considerations and the effect they have on the portability of the device layer. Unlike the hardware implementation, this side of the development is dependent on many outside forces. OS vendors and third-party suppliers to those vendors have a major influence, as do security updates due to virus threats and other market conditions. So how does one design a device driver under these conditions? Following a few simple rules not only allows your design to be current, but also develops the highest quality driver with the longest life cycle.
Chapter 3 / Designing Portable Device Interfaces for Windows and UNIX |
59 |
|
|
The Basic Driver Design
There is a world of difference between designing hardware and designing software. I’ve been involved with hardware and mechanical design for almost 25 years, and it is nothing like software design. Here’s why: Software is only one dimension, so when it works you cannot visibly see how the pieces fit together. That is one reason people tend to think software works by magic. There are no naming conventions defined in software, so learning a new operating system or user interface can take months or even years depending on how complex it is and the number of functions that exist. Can you imagine not having nut and bolt thread standards? You could spend weeks trying to find a nut or bolt exactly like the old one. Fortunately we were smart enough to realize that having standard thread dimensions was not only in the best interest of the consumer but the manufacturer as well. This approach has never been taken in software because everyone has a better idea than the next guy (or so they believe).
As a hardware and software designer you cannot control what others do or don’t do, so to design device drivers that can be implemented and maintained without a lot of ongoing design changes, try the following:
Keep your design document to the important points without defining implementation. This means making sure the developers know what is up to their discretion in implementation and what rules must be adhered to strictly. While a protocol must be coded as defined, the details of how the vendor and product ID are implemented can be left to the developers.
Point out items that will impact system performance by documenting these issues, but again leave implementation details to the developers. This will assure they account for these considerations while having the flexibility of developing to their breadth of knowledge.
Chapter 3
