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 * CONNECTED_LED -- an LED that is controlled inside the HAL to indicate connection to a central.
8 * DEBUG -- two debug GPIOs that are available as outputs from the EAP and under user control.
9 * DELAY -- a delay routine that can delay by n milliseconds.
10 * INIT -- set the hardware up to its initial state
11 * LED -- a user LED that is available for application control.
12 * TICK -- a timer that can be set to interrupt every n milliseconds
13 * IDLE LOOP -- an event driven idle loop for controlling the EAP
15 * For information on Hal implementations for specific target hardware platforms,
16 * visit the http://wiki.em-hub.com/display/ED.
30 typedef void (*Hal_Handler)(void);
33 * --------- Hal_buttonEnable ---------
35 * Enable the button interrupt and connect it to the user's buttonHandler
37 * When the button is pressed, it will cause an interrupt that will cause BUTTON event
38 * to be entered into the event list. Once dispatched by the idle loop, the user's
39 * buttonHandler will be called.
42 * buttonHandler - pointer to the user's handler to be called after interrupt
48 * BUTTON interrupt enabled
51 extern void Hal_buttonEnable(Hal_Handler handler);
53 * --------- Hal_connected ---------
55 * Called whenever the MCM peripheral connects to a central.
57 * Turns on the CONNECTED_LED to show connectivity to the central
58 * Could do other things associated with connection to the central.
70 extern void Hal_connected(void);
72 * --------- Hal_debugOff ---------
74 * Turns the selected DEBUG line off.
76 * The two DEBUG lines are output GPIOs that are available to the user for
80 * line - the index value of the debug line to turn off
89 extern void Hal_debugOff(uint8_t line);
91 * --------- Hal_debugOn ---------
93 * Turns the selected DEBUG line on.
95 * The two DEBUG lines are output GPIOs that are available to the user for
99 * line - the index value of the debug line to turn on
108 extern void Hal_debugOn(uint8_t line);
110 * --------- Hal_debugPulse ---------
112 * Emits a pulse on the selected DEBUG line.
114 * The two DEBUG lines are output GPIOs that are available to the user for
118 * line - the index value of the debug line to emit a pulse
124 * DEBUG line turns on then off.
127 extern void Hal_debugPulse(uint8_t line);
129 * --------- Hal_delay ---------
131 * Delays for the specified number of milliseconds.
133 * In this example, delay is done with CPU spinning for simplicity's sake.
134 * This could easily use a timer interrupt for more power savings.
137 * msecs - the number of milliseconds to delay
146 extern void Hal_delay(uint16_t msecs);
148 * --------- Hal_disconnected ---------
150 * Called whenever the MCM peripheral disconnects from a central.
152 * Turns off the CONNECTED_LED to show lack of connectivity to the central
153 * Could do other things associated with connection to the central.
165 extern void Hal_disconnected(void);
167 * --------- Hal_idleLoop ---------
169 * The idle loop that controls EAP operations.
171 * The hal implements an event driven "idle loop" scheduler.
172 * When there are no events pending, the idle loop sleeps.
173 * When an event happens, the idle loop wakes up, and dispatches
174 * to the appropriate event handler.
176 * The dispatching is done through a handlerTab that has one entry for each type of event.
177 * Each handlerTab entry should be a handler of type hal_handler *.
178 * There are currently three types of events, i.e. entries in the handlerTab:
179 * BUTTON_HANDLER_ID: handler to call upon a button press
180 * TICK_HANDLER_ID: handler to call upon a timer interrupt
181 * DISPATCH_HANDLER_ID: handler to call upon a received message from the MCM
190 * dispatches events as they come in
193 extern void Hal_idleLoop(void);
195 * --------- Hal_init ---------
197 * Initialize the hardware
199 * Initializes the EAP and MCM into their reset state. Should be called first.
200 * Sets up the clock, ports, watchdog timer, etc.
210 * EAP and MCM in their initial state.
213 extern void Hal_init(void);
215 * --------- Hal_ledOff ---------
217 * Turns the user LED off.
229 extern void Hal_ledOff(void);
231 * --------- Hal_ledOn ---------
233 * Turns the user LED on.
245 extern void Hal_ledOn(void);
247 * --------- Hal_ledRead ---------
249 * Returns the user LED state.
255 * Bool - (true = user LED is on, false = user LED is off)
261 extern bool Hal_ledRead(void);
263 * --------- Hal_ledToggle ---------
265 * Toggles the user LED.
274 * User LED toggles state.
277 extern void Hal_ledToggle(void);
279 * --------- Hal_tickStart ---------
281 * Sets up the timer to interrupt every msecs milliseconds and the user's tickHandler
282 * that will be called upon interrupt.
284 * Enable a timer interrupt every msecs ms. The interrupt will cause a TICK event
285 * to be entered into the event list. Once dispatched by the idle loop, the user's
286 * tickHandler will be called.
289 * msecs - the number of milliseconds between tick interrupts
290 * tickHandler - the address of the user's tick handler that will be called
296 * tickhandler called by the idle loop
299 extern void Hal_tickStart(uint16_t msecs, Hal_Handler Handler);