EETimes

Embedded Systems October 2000 Vol13_11

Issue link: http://dc.ee.ubm-us.com/i/71842

Contents of this Issue

Navigation

Page 137 of 181

LISTING 14 #ifdef CREATE~EMORY #define CreateOigitaLInRAM(number) OigitaLInputRam digitaLin[number/8 + 1J; #define\ CreateOigitaLIn(name,port,mask,debouncetime,position,rammask,message,defauLt)\ OigitaLInputRom const name = {\ &port,mask,debouncetime,position,rammask,message,defauLt}; #eLse #define CreateOigitaLInRAM(number) \ extern OigitaLInputRam digitaLin[number/8 + 1J;\ #define\ CreateOigitaLIn(name,port,mask,debouncetime,position,rammask,message,defauLt)\ extern OigitaLInputRom const name;\ #endif ated to An additional routine must be cre- enable ou tput. Sin ce SendMessage only ente rs the informa- tion in to th e message RAM, a d.-iver routine must be created to actually output the data to a port. This can be seen in Listing 16. With OSEK/ VDX, this routine can be called whe never an o utput changes. This routine navi- gates a null terminated list of outputs that are passed in names. It receives the cur rent message and sets the o ut- put at the port based on the state after inverting the message value fo r active low outputs. L1mNG 15 void SampLeOiscreteInput(IOHANOLE name) { BOOLEAN resuLt; U8 RawOigitaL = *«(OigitaLInputRom *)name)->port & « (Oigi taLInputRom *)name)->mask; resuLt = OebounceOiscrete(RawOigitaL, name); SendMessage«(OigitaLInputRom *)name)->message,&resuLt; } Message advantages and disadvantages The message method clearly abstracts the source of the data, whether it is a true hardware input or output, or data received over a network. Complex messages such as structures or strings can be received easil y, whereas the API calls work best if all data is of a simple type (that is, US, U16, float, and so on). The disadvan tage with this method is that more RAM, ROM, and through- put is uti lized by adding another level of abstraction: the message. L1mNG 16 Discrete output driver routine void WriteOiscreteOutput(IOHANOLE* names) { BOOLEAN resuLt; whiLe(*names != NULL) { ReceiveMessage«(OigitaLOutputRom *)*names)->message,&resuLt) ResuLt A= «(OigitaLOutputRom *)*names->activeLow); If(resuLt == INACTIVE) «OigitaLOutputRom *)*names)->port &= -« OigitaLOutputRom *)*names)->mask; eLse «OigitaLOutputRom *)*names)->port 1= «OigitaLOutputRom *)*names)->mask; names++; } } Software reuse is a noble goal that has been chased by many firms for years. In reali ty, attaining a large level of true reuse is usually di ffic ul t and sel- dom achieved. Maj or im pediments to reuse include differe nt microcon- trollers, multiple microcontrolle rs on a single proj ect, hardware chc ll1ges, and networks. Changing the source of data usually fo rces extensive changes in code. Following the tips just o ut- lined will help increase your reuse opportunities. esp Joe Lernieux is a senior applied specialist with EDS Ernbedded Solutions in Troy, MI. He holds an MSJ<."E f rorn the University of Michigan and has been writing software f or ernbedded systerns in the autornotive industry for over 17 years. He can be reached by e-rnail at joe.lernieux@eds. corn. 136 OCTOBER 2000 Embedded Systems Programming

Articles in this issue

Archives of this issue

view archives of EETimes - Embedded Systems October 2000 Vol13_11