Embedded Systems October 2000 Vol13_11

Issue link:

Contents of this Issue


Page 133 of 181

LlmNG8 Discrete input structure typedef void * IOHANDLE; typedef struet DigitaLInputRamtag { U8 rawva Lue; U8 debouneedvaLue; U8 timeC8J; } DigitaLInputRam; typedef struet DigitaLInputROOltag { U8 *digitaLport; U8 mask; U8 debouneetime; U8 ramLoeation; U8 ranmask; BOOLEAN defauLtstate; } DigitaLInputROOl; LlmNG9 Macros for creating discrete inputs #ifdef CREATE_MEMORY #define CreateDigitaLInRAM(number) \ DigitaLInputRam digitaLinCnumber/8 + 1J; #define\ CreateDigitaLIn(name,port,mask,debouneetime,position,rammask,defauLt)\ DigitaLInputROOl eonst name = {\ &port,mask,debouneetime,position,ranmask,defauLt}; #eLse #define CreateDigitaLInRAM(number) \ extern DigitaLInputRam digitaLinCnumber/8 + 1J; #define\ CreateDigitaLIn(name,port,mask,debouneetime,position,ranmask,defauLt)\ extern DigitaLInputROOl eonst name;\ #endif LlmNG 10 Obtaining a discrete input state BOOLEAN GetDisereteState(IOHANDLE name) { if(digitaLinC«OigitaLInputROOl *)name)->ramLoeationJ.debouneedvaLue & «OigtiaLInputROOl *)name)->ranmask == 0) { return INACTIVE; } eLse { return ACTIVE; } } API calls: advantages and disadvan- tages The advantage of this method is that little or no code is written when I/O is added , deleted , or modified. Only constants using the macros in the con- fi guration file need to be changed. This method has high reusabili ty and high portabili ty since each function receives a void pointer, and changes in the structure to which the poin ter is referenced do not affect the applica- tion code generated. The disadvantages of this method are slight increases in ROM and CPU usage. However, since Ule dilIerence has not been benchmarked, ulere may 132 oaOBER 2000 Embedded Systems Programming io.h file used by al l application mod- ules. However, the macro CREATE_ MEMORY must only be defined in io.c, or an error will occur during link. The configuration file will contain all of the macros to define all of the inpu ts and outputs used in the application. Use the names from the configuration me in the application module In each application, use the names created in the iocfg.h file to access the inputs and outputs. An example of a task in an application is shown in Listing 12. This task is part of a round robin scheduler that checks state and drives an output. Integrate into RTOS The final step is to in tegrate ule sample and dliver routines into the RTOS. Each sample routine Ulat periodically samples inputs needs to be scheduled. The advantage of u1ese routines is that indi- vidual inputs can be sampled at different frequencies. The example in the TI.II1C- tion name method requires all inputs on a port to be sampled at the same fre- quency. This may require the writing of a shell routine Ulat calls the function mul- tiple times, once for each inpuL This could be made more efficient by using a null terminated list of inputs to be sam- pled and a small whi LeO loop. ISRs that are specific to Ule application and call API routines must also be develol~ed.

Articles in this issue

Archives of this issue

view archives of EETimes - Embedded Systems October 2000 Vol13_11