]> www.average.org Git - pulsecounter.git/blob - Hal/Hal.h
add some timer
[pulsecounter.git] / Hal / Hal.h
1 /**
2  * Hal.h -- HAL Interface Definitions
3  *
4  * This example HAL is intentionally simple.  The implementation is limited to:
5  *
6  * BUTTON -- a single button that when pressed will cause an interrupt.
7  * DEBUG -- two debug GPIOs that are available as outputs from the EAP and under user control.
8  * DELAY -- a delay routine that can delay by n milliseconds.
9  * INIT -- set the hardware up to its initial state
10  * LED -- a user LED that is available for application control.
11  * TICK -- a timer that can be set to interrupt every n milliseconds
12  * IDLE LOOP -- an event driven idle loop for controlling the EAP
13  *
14  * For information on Hal implementations for specific target hardware platforms,
15  * visit the http://wiki.em-hub.com/display/ED.
16  *
17  **/
18
19 #ifndef Hal__H
20 #define Hal__H
21
22 #include <stdint.h>
23 #include <stdbool.h>
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 extern int32_t buttonCnt;
30
31 typedef void (*Hal_Handler)(void);
32
33 /**
34  * --------- Hal_buttonEnable ---------
35  *
36  * Enable the button interrupt and connect it to the user's buttonHandler
37  *
38  * When the button is pressed, it will cause an interrupt that will cause BUTTON event
39  * to be entered into the event list.  Once dispatched by the idle loop, the user's
40  * buttonHandler will be called.
41  *
42  * Inputs:
43  *   buttonHandler - pointer to the user's handler to be called after interrupt
44  *
45  * Returns:
46  *   None
47  *
48  * Side effects:
49  *   BUTTON interrupt enabled
50  *
51  **/
52 extern void Hal_buttonEnable(Hal_Handler handler);
53 /**
54  * --------- Hal_connected ---------
55  *
56  * Called whenever the MCM peripheral connects to a central.
57  *
58  * Could do other things associated with connection to the central.
59  *
60  * Inputs:
61  *   None
62  *
63  * Returns:
64  *   None
65  *
66  **/
67 extern void Hal_connected(void);
68 /**
69  * --------- Hal_debugOff ---------
70  *
71  * Turns the selected DEBUG line off.
72  *
73  * The two DEBUG lines are output GPIOs that are available to the user for
74  * debug purposes.
75  *
76  * Inputs:
77  *   line - the index value of the debug line to turn off
78  *
79  * Returns:
80  *   None
81  *
82  * Side Effects:
83  *   DEBUG line off.
84  *
85  **/
86 extern void Hal_debugOff(uint8_t line);
87 /**
88  * --------- Hal_debugOn ---------
89  *
90  * Turns the selected DEBUG line on.
91  *
92  * The two DEBUG lines are output GPIOs that are available to the user for
93  * debug purposes.
94  *
95  * Inputs:
96  *   line - the index value of the debug line to turn on
97  *
98  * Returns:
99  *   None
100  *
101  * Side Effects:
102  *   DEBUG line on.
103  *
104  **/
105 extern void Hal_debugOn(uint8_t line);
106 /**
107  * --------- Hal_debugPulse ---------
108  *
109  * Emits a pulse on the selected DEBUG line.
110  *
111  * The two DEBUG lines are output GPIOs that are available to the user for
112  * debug purposes.
113  *
114  * Inputs:
115  *   line - the index value of the debug line to emit a pulse
116  *
117  * Returns:
118  *   None
119  *
120  * Side Effects:
121  *   DEBUG line turns on then off.
122  *
123  **/
124 extern void Hal_debugPulse(uint8_t line);
125 /**
126  * --------- Hal_delay ---------
127  *
128  * Delays for the specified number of milliseconds.
129  *
130  * In this example, delay is done with CPU spinning for simplicity's sake.
131  * This could easily use a timer interrupt for more power savings.
132  *
133  * Inputs:
134  *   msecs - the number of milliseconds to delay
135  *
136  * Returns:
137  *   None
138  *
139  * Side Effects:
140  *   None
141  *
142  **/
143 extern void Hal_delay(uint16_t msecs);
144 /**
145  * --------- Hal_disconnected ---------
146  *
147  * Called whenever the MCM peripheral disconnects from a central.
148  *
149  * Could do other things associated with connection to the central.
150  *
151  * Inputs:
152  *   None
153  *
154  * Returns:
155  *   None
156  *
157  **/
158 extern void Hal_disconnected(void);
159 /**
160  * --------- Hal_idleLoop ---------
161  *
162  * The idle loop that controls EAP operations.
163  *
164  * The hal implements an event driven "idle loop" scheduler.
165  * When there are no events pending, the idle loop sleeps.
166  * When an event happens, the idle loop wakes up, and dispatches
167  * to the appropriate event handler.
168  *
169  * The dispatching is done through a handlerTab that has one entry for each type of event.
170  * Each handlerTab entry should be a handler of type hal_handler *.
171  * There are currently three types of events, i.e. entries in the handlerTab:
172  *   BUTTON_HANDLER_ID:    handler to call upon a button press
173  *   TICK_HANDLER_ID:      handler to call upon a timer interrupt
174  *   DISPATCH_HANDLER_ID:  handler to call upon a received message from the MCM
175  *
176  * Inputs:
177  *   None
178  *
179  * Returns:
180  *   None
181  *
182  * Side Effects:
183  *   dispatches events as they come in
184  *
185  **/
186 extern void Hal_idleLoop(void);
187 /**
188  * --------- Hal_init ---------
189  *
190  * Initialize the hardware
191  *
192  * Initializes the EAP and MCM into their reset state.  Should be called first.
193  * Sets up the clock, ports, watchdog timer, etc.
194  *
195  *
196  * Inputs:
197  *   None
198  *
199  * Returns:
200  *   None
201  *
202  * Side Effects:
203  *   EAP and MCM in their initial state.
204  *
205  **/
206 extern void Hal_init(void);
207 /**
208  * --------- Hal_ledOff ---------
209  *
210  * Turns the user LED off.
211  *
212  * Inputs:
213  *   None
214  *
215  * Returns:
216  *   None
217  *
218  * Side Effects:
219  *   User LED off.
220  *
221  **/
222 extern void Hal_greenLedOff(void);
223 extern void Hal_redLedOff(void);
224 /**
225  * --------- Hal_ledOn ---------
226  *
227  * Turns the user LED on.
228  *
229  * Inputs:
230  *   None
231  *
232  * Returns:
233  *   None
234  *
235  * Side Effects:
236  *   User LED on.
237  *
238  **/
239 extern void Hal_greenLedOn(void);
240 extern void Hal_redLedOn(void);
241 /**
242  * --------- Hal_ledRead ---------
243  *
244  * Returns the user LED state.
245  *
246  * Inputs:
247  *   None
248  *
249  * Returns:
250  *   Bool -  (true = user LED is on, false = user LED is off)
251  *
252  * Side Effects:
253  *   None
254  *
255  **/
256 extern bool Hal_greenLedRead(void);
257 extern bool Hal_redLedRead(void);
258 /**
259  * --------- Hal_ledToggle ---------
260  *
261  * Toggles the user LED.
262  *
263  * Inputs:
264  *   None
265  *
266  * Returns:
267  *   None
268  *
269  * Side Effects:
270  *   User LED toggles state.
271  *
272  **/
273 extern void Hal_greenLedToggle(void);
274 extern void Hal_redLedToggle(void);
275 /**
276  * --------- Hal_tickStart ---------
277  *
278  * Sets up the timer to interrupt every msecs milliseconds and the user's tickHandler
279  * that will be called upon interrupt.
280  *
281  * Enable a timer interrupt every msecs ms.  The interrupt will cause a TICK event
282  * to be entered into the event list.  Once dispatched by the idle loop, the user's
283  * tickHandler will be called.
284  *
285  * Inputs:
286  *   msecs - the number of milliseconds between tick interrupts
287  *   tickHandler - the address of the user's tick handler that will be called
288  *
289  * Returns:
290  *   None
291  *
292  * Side Effects:
293  *   tickhandler called by the idle loop
294  *
295  **/
296 extern void Hal_tickStart(uint16_t msecs, Hal_Handler Handler);
297 extern void Hal_tickStop(void);
298
299 #ifdef __cplusplus
300 }
301 #endif
302
303 #endif /* Hal__H */