EETimes

Embedded Systems October 2000 Vol13_11

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

Contents of this Issue

Navigation

Page 121 of 181

FIGURE 1 System model read the curre nt o utput value . Following are examples of access func- tio n names, with NAME replaced by a unique name for each input o r output: Operating System Utilities BOOLEAN CheckNAMEState(void}; void SetNAMEState(BOOLEAN}; U8 GetNAMEVaLue(void}; void SetNAMEVaLue(U16}; After the function is defined , it 1/0 Layer Physical Layer needs to be created. In the case of a macro, the definition and creation are simultaneous. The listings presented here provide examples of ro utines for each of the previous examples. The macros are included. However, only one or the other will actually exist in the final product. In Listing 1, the input is a d iscrete LISTING 1 Obtaining a descrete input state 1************************************ * Define an access of a discrete input that is packed in a byte with 7 other * di screte inputs. The macro or routine returns 0 if the input is inactive or * 1 if the input is active. ************************************/ #define CheckNAMEState() \ « NAMEvariabLe & NAMEMASK = 0) \ ?INACTIVE:ACTIVE) BOOLEAN CheckNAMEState(void) { if(NAMEvariabLe & NAMEMASK = 0) return INACTIVE; eLse return ACTIVE; } such as voltages and currents, time- based inputs and outputs such as fre- quencies and PWM signals, and so on. These sho uld be listed in a table along with any requ irements such as range, granularity, debouncing, fi ltering, default values, and so on. Define an access fWIction for each input and output This function or macro will always take o n the function prololype of: type i nputfuncti on( voi d); or voi d output- function(type};, where type is the lype that contains the complete range and granularity of the input. For digi- tal inputs, this is usually BOOLEAN, which most applications equate to an unsigned character. It may be any type of integer or fl oat available in C, and may also be a structure. The re turn value is always the value of the input or output. Outputs may have lWO fl.lIl c- tions if other application tasks need to 120 OCTOBER 2000 Embedded Systems Programming input that can have the value either ACTIVE or INACTIVE. Each input is packed into a byte that contains eight discrete inpu ts. The function must unpack the bit and return the proper value. Using a macro, the variable and mask must be defin ed globally so all routines can access them. The fun c- tion provides some level of e ncapsula- tion of the variable. For a discrete output, Listing 2 pre- sents an example where the output port is written directly. Again with til is macro, the port must be defined globally. For analog inputs, Listing 3 describes the access function . In tllis case, a structure is defin ed for each analog input as fo llows: typedef struct AnaLoglnputTypetag{ U16 rawvaLue; U16 fiLteredvaLue; U16 defauLtvaLue; BOOLEAN vaLidvaLue; } AnaLoglnputType; If an error occurs, the default is used; otherwise the filtered value is used. It is up to the sampling routine to set the va L i dva Lue status. Finally, for a timer-based output (PWM or variable freq uency), Listing 4 shows how the value is buffered for

Articles in this issue

Archives of this issue

view archives of EETimes - Embedded Systems October 2000 Vol13_11