Embedded Systems October 2000 Vol13_11

Issue link:

Contents of this Issue


Page 129 of 181

i I o· = section where code may need LO be written if th e I/O functio ns can't be called directly by the RTOS o r to encapsulate in an ISR Classify I/ O types In this step, each type of 1/ 0 tllat is used by tile organizatio n is defined and tile parameters are classifi ed. For LISTING /************************************* * Define structure to hoLd anaLog inputs *************************************/ struct anaLoginputstruct { U8 constant; BOOLEAN vaLidvaLue; U8 channeL; U8 defauLtvaLue; U8 fiL teredvaLue; } Ana LogInput; 1************************************* * SampLe AnaLog Input ports sampLe and fiLter a Li st of anaLog inputs. * Routine is passed a nuLL terminated List of anaLog inputs. *************************************/ void SampLeAnaLogInputs(AnaLogInput **List) { ConvertAL LAnaLogsO; whiLe(*List != NULL) { *List->fiLteredvaLue = fiLter(rawanaLog[*List->channeLJ,*List->fiLteredvaLue, *List->constant); L ist++; } } example, disc re te inputs may be defin ed as being from either a digital or an analog port, will be debounced, and have a default value upon power- up. Othe r types of I/O may include d iscrete outpu ts, ana log inputs/ outputs, PWM inputs/ o utputs, fre- que ncy in p uts/ o utputs, multi-sta te inputs/ outputs, and so on. Define type defInitions Fo r each type above, defin e a variable (RAM) and a constant (ROM) SU"UC- ture that will be used by each instance of tllat type of input. Fo r the previous example of discrete inputs from a d ig- ital po rt, the structures shown in Listing 8 would be defin ed. The defin ition IOHANDLE will be used for the API fun ction call s. Tn the RAM 'u"ucture, rawva Lue is tile last sampled value of th e input; LISTING 7 Output driver for frequency outputs /************************************ * Define an interrupt service routine for an output and a routine for * frequency outputs in generaL ************************************/ interrupt void EPAO_ISR(void) { UpdateFrequencyOutput(&FreqOutput); } void UpdateFrequencyOutput(FreqOutputStruct *output) { *output->time_register += output->period; } debouncedva Lue is the debounced state of the input; and time is the time that each rawva Lue has been constant in order to debounce. Each RAM SU"UC- ture can hold eight d igital inputs. The ROM structure includes *digitaLpor t , a po inter LO the d igital port; mask, the mask of tile bi tin the port corre- sponding LO the input; debouncetime, the time to debounce the input in samples; ramLocati on, the offset into tile array of Di gi ta LInputRam variables that holds the particulal- input; ram- mask, the mask of the RAM location LO extract the digital in put; and defauL t - s t at e, tile default state of tile input. Simi larl y, defin itio ns of each of tile input and output types defin ed previ- ously would be created. DefIne macros Defin e macros tha t create the in stances of each in put or output. These macros encapsulate the defin i- tio n of the structure, thereby allowing the structure to be mod ified to adapt LO changes in the API. Examples of macros for our d igital input example are in Listing 9. These macros will all appear in the configuration fi le. T he first macro reserves RAM memo ry for the packed digital inpu ts 128 OCTOBER 2000 Embedded Systems Programming

Articles in this issue

Archives of this issue

view archives of EETimes - Embedded Systems October 2000 Vol13_11