2 * Hal.h -- HAL Interface Definitions
4 * This example HAL is intentionally simple. The implementation is limited to:
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
14 * For information on Hal implementations for specific target hardware platforms,
15 * visit the http://wiki.em-hub.com/display/ED.
29 extern int32_t buttonCnt;
31 typedef void (*Hal_Handler)(void);
34 * --------- Hal_buttonEnable ---------
36 * Enable the button interrupt and connect it to the user's buttonHandler
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.
43 * buttonHandler - pointer to the user's handler to be called after interrupt
49 * BUTTON interrupt enabled
52 extern void Hal_buttonEnable(Hal_Handler handler);
54 * --------- Hal_connected ---------
56 * Called whenever the MCM peripheral connects to a central.
58 * Could do other things associated with connection to the central.
67 extern void Hal_connected(void);
69 * --------- Hal_debugOff ---------
71 * Turns the selected DEBUG line off.
73 * The two DEBUG lines are output GPIOs that are available to the user for
77 * line - the index value of the debug line to turn off
86 extern void Hal_debugOff(uint8_t line);
88 * --------- Hal_debugOn ---------
90 * Turns the selected DEBUG line on.
92 * The two DEBUG lines are output GPIOs that are available to the user for
96 * line - the index value of the debug line to turn on
105 extern void Hal_debugOn(uint8_t line);
107 * --------- Hal_debugPulse ---------
109 * Emits a pulse on the selected DEBUG line.
111 * The two DEBUG lines are output GPIOs that are available to the user for
115 * line - the index value of the debug line to emit a pulse
121 * DEBUG line turns on then off.
124 extern void Hal_debugPulse(uint8_t line);
126 * --------- Hal_delay ---------
128 * Delays for the specified number of milliseconds.
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.
134 * msecs - the number of milliseconds to delay
143 extern void Hal_delay(uint16_t msecs);
145 * --------- Hal_disconnected ---------
147 * Called whenever the MCM peripheral disconnects from a central.
149 * Could do other things associated with connection to the central.
158 extern void Hal_disconnected(void);
160 * --------- Hal_idleLoop ---------
162 * The idle loop that controls EAP operations.
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.
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
183 * dispatches events as they come in
186 extern void Hal_idleLoop(void);
188 * --------- Hal_init ---------
190 * Initialize the hardware
192 * Initializes the EAP and MCM into their reset state. Should be called first.
193 * Sets up the clock, ports, watchdog timer, etc.
203 * EAP and MCM in their initial state.
206 extern void Hal_init(void);
208 * --------- Hal_ledOff ---------
210 * Turns the user LED off.
222 extern void Hal_greenLedOff(void);
223 extern void Hal_redLedOff(void);
225 * --------- Hal_ledOn ---------
227 * Turns the user LED on.
239 extern void Hal_greenLedOn(void);
240 extern void Hal_redLedOn(void);
242 * --------- Hal_ledRead ---------
244 * Returns the user LED state.
250 * Bool - (true = user LED is on, false = user LED is off)
256 extern bool Hal_greenLedRead(void);
257 extern bool Hal_redLedRead(void);
259 * --------- Hal_ledToggle ---------
261 * Toggles the user LED.
270 * User LED toggles state.
273 extern void Hal_greenLedToggle(void);
274 extern void Hal_redLedToggle(void);
276 * --------- Hal_tickStart ---------
278 * Sets up the timer to interrupt every msecs milliseconds and the user's tickHandler
279 * that will be called upon interrupt.
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.
286 * msecs - the number of milliseconds between tick interrupts
287 * tickHandler - the address of the user's tick handler that will be called
293 * tickhandler called by the idle loop
296 extern void Hal_tickStart(uint16_t msecs, Hal_Handler Handler);