A rudimentary software architecture:Project header

Project header
Context

● You are developing an embedded application using one or more members of the 8051 family of microcontrollers.

● You are designing an appropriate software foundation for your application.

Problem

How do you group together all the information relating to the hardware platform used in your project?

Background

Solution

As we saw in Chapter 3, the 8051 family shares a common set of core facilities. However, it is a family – rather than a group of clones – and the different family members have different features and facilities. For example, some devices require 12 oscillator cycles per instruction, while others perform the same instruction in 6, 4 or even 1 oscillator cycle (see Chapters 3 and 4).

If you create an application using a particular 8051 device operating at a particular oscillator frequency, this information will be required when compiling many of the different source files in your project. This information will also be required by anyone who wishes to use your code.

The ‘Project Header’ is simply a header file, included in all projects, that groups all of this information in one place. As such, it is a practical implementation of a stan- dard software design guideline: ‘Do not duplicate information in numerous files; place the common information in a single file, and refer to it where necessary.’

In the case of the great majority of the examples in this book, we use a Project Header file. This is always called Main.H. An example of a typical project header file is included in Listing 9.7. Please note that this is a real example and not all of the features of this file have yet been considered in this book.

A rudimentary software  architecture-0167A rudimentary software  architecture-0168A rudimentary software  architecture-0169

Hardware resource implications

There are no hardware resource implications.

Reliability and safety implications

Use of P ROJECT H EADER can help to improve reliability, not least because it helps to make your code more readable, because anyone using your projects knows where to find key information, such as the model of microcontroller and the oscillator frequency.

Use of P ROJECT H EADER can help to improve the reliability of applications which are subsequently ported to a different microcontroller, as discussed in the remainder of this chapter.

Portability

The use of a project header can help to make your code more easily portable, by plac- ing some of the key rnicrocontroller-dependent data in one place.

In addition, the typedef statements in the file create three key user-defined types which are used in all of the projects in this book:

typedef unsigned char tByte; typedef unsigned int tWord; typedef unsigned long tLong;

Thus, in the projects you will see code like this:

tWord Temperature;

Rather than:

unsigned int Temperature;

If the code is ported into – say – a 16-bit environment, changes to only three typedef statements are required in order to adapt the variable sizes to a new com- piler. Without the use of these user-defined types, porting the code becomes more complicated and error prone.

Overall strengths and weaknesses

clip_image003PROJECT HEADER can help to make your code more readable, not least because anyone using your projects knows where to find key information, such as the model of microcontroller and the oscillator frequency.

PROJECT HEADER can help to make your code more easily portable.

Related patterns and alternative solutions

See PORT HEADER [page 184].

Examples

Almost every example project on the CD includes a project header file. Search for the file Main.H.

Further reading

Leave a comment

Your email address will not be published. Required fields are marked *