Pitfalls For Real Time Software Developer - 2
Pitfalls For Real Time Software Developer - 2
B.
<BACK
STEWART
f e a t u r e
NOVEMBER 1999
Most software systems are designed such that the entire system is
defined by a single diagram (or, even worse, none!).
NOVEMBER 1999
75
BEN FISHMAN
top 15 pitfalls
FIGURE 1 Many software developers will define data structures, as shown in (a). The design of the software and
interrelationship of the data structures is not obvious unless the code is accompanied by a data structure diagram, as
shown in (b).
(a)
(b)
def_t
next
prev
name
char name[8];
loval
short loval;
hival
short hival;
} def_t;
abc_t
*def
long i;
*xyz
float f;
nxyz
head
short s[2];
unsigned char b[8];
} xyz_t;
name1
namendef
xyz[0]
xyz[1]
xyz[2]
s[0]
s[1]
xyz_t *xyz;
abc_t
short ndef;
= structure abc_t
} abc_t;
= pointer
NOVEMBER 1999
xyz[nxyz1]
def_t *def;
= field
within a
structure
= zoomed-in view
of a structure
Data structure diagrams and class hierarchies. Data structure diagrams and
top 15 pitfalls
NOVEMBER 1999
top 15 pitfalls
On the other hand, if this information is stored in a configuration variable (possibly stored in nonvolatile
memory), then changing the value in
just one place is simple. The code does
not have to be recompiledat worst,
resetting or rebooting the system is
necessary. The need for recompilation
NOVEMBER 1999
79
top 15 pitfalls
M
xyzInit(xyzbase);
etc.
Adding a second device at address
0x7E0 is as easy as adding another variable. For example:
xyzReg_t *xyzbase2 =
(xyzReg_t *) 0x7E0;
M
xyzInit(xyzbase2);
NOVEMBER 1999
top 15 pitfalls
NOVEMBER 1999
81
top 15 pitfalls
NOVEMBER 1999
top 15 pitfalls
and not
84
NOVEMBER 1999
Description
File that contains code for module xyz
File that contains header info for module xyz. Anything
defined in this file MUST have an xyz or XYZ prefix, and must
be something that is exported by the module.
Primary data type for module xyz. Defined in xyz.h
Secondary type Abcde for module xyz. Defined in xyz.h.
Function Abcde that applies to items of type xyz_t.
Constant for module XYZ. Must be defined in xyz.h.
#defined macro for module XYZ. Must be defined in xyz.h.
Exported global variable defined in module xyz. Must be
defined in xyz.c, and declared as extern in xyz.h. Global
variables should be avoided!
Local constant internal to module. Must be defined at top of
xyz.c. The third version allows the use of multiple words. For
example, _ABCDE_FGH. If just ABCDE_FGH, is used, it
implies module abcde
Local variable. Must be defined inside a function.Fields within
a structure are also defined using this convention.
Internal global variable. Must be defined as static at top of
xyz.c.
Internal function. Must be defined as static. Prototype at top
of xyz.c. Function declared at bottom of xyz.c, after all the
exported functions have been declared.
Internally-defined type. Must be defined at top of xyz.c.
An exported enumerated type for module abc. Each entry of
the enumerated type should defined using the same
conventions as a constant.
xyzCreateFile
xyzDestroyFile
xyzReadFile
xyzWriteFile
top 15 pitfalls
xyzDestroy
xyzTerm
xyzFinish
xyzOff
xyzFree
xyzRcv
xyzWrite
xyzClose
xyzControl
xyzPrev
xyzDown
xyzGo
NOVEMBER 1999
85
top 15 pitfalls
Some programmers who do measure execution time wait until everything is implemented. In such cases,
there are usually so many timing problems in the system that no single set of
timing measurements will provide
enough clues as to the problems in the
system. The operative word in real-time
system is time.
86
NOVEMBER 1999