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 extern int32_t buttonCnt;
32 typedef void (*Hal_Handler)(void);
35 * --------- Hal_buttonEnable ---------
37 * Enable the button interrupt and connect it to the user's buttonHandler
39 * When the button is pressed, it will cause an interrupt that will cause BUTTON event
40 * to be entered into the event list. Once dispatched by the idle loop, the user's
41 * buttonHandler will be called.
44 * buttonHandler - pointer to the user's handler to be called after interrupt
50 * BUTTON interrupt enabled
53 extern void Hal_buttonEnable(Hal_Handler handler);
55 * --------- Hal_connected ---------
57 * Called whenever the MCM peripheral connects to a central.
59 * Turns on the CONNECTED_LED to show connectivity to the central
60 * Could do other things associated with connection to the central.
72 extern void Hal_connected(void);
74 * --------- Hal_debugOff ---------
76 * Turns the selected DEBUG line off.
78 * The two DEBUG lines are output GPIOs that are available to the user for
82 * line - the index value of the debug line to turn off
91 extern void Hal_debugOff(uint8_t line);
93 * --------- Hal_debugOn ---------
95 * Turns the selected DEBUG line on.
97 * The two DEBUG lines are output GPIOs that are available to the user for
101 * line - the index value of the debug line to turn on
110 extern void Hal_debugOn(uint8_t line);
112 * --------- Hal_debugPulse ---------
114 * Emits a pulse on the selected DEBUG line.
116 * The two DEBUG lines are output GPIOs that are available to the user for
120 * line - the index value of the debug line to emit a pulse
126 * DEBUG line turns on then off.
129 extern void Hal_debugPulse(uint8_t line);
131 * --------- Hal_delay ---------
133 * Delays for the specified number of milliseconds.
135 * In this example, delay is done with CPU spinning for simplicity's sake.
136 * This could easily use a timer interrupt for more power savings.
139 * msecs - the number of milliseconds to delay
148 extern void Hal_delay(uint16_t msecs);
150 * --------- Hal_disconnected ---------
152 * Called whenever the MCM peripheral disconnects from a central.
154 * Turns off the CONNECTED_LED to show lack of connectivity to the central
155 * Could do other things associated with connection to the central.
167 extern void Hal_disconnected(void);
169 * --------- Hal_idleLoop ---------
171 * The idle loop that controls EAP operations.
173 * The hal implements an event driven "idle loop" scheduler.
174 * When there are no events pending, the idle loop sleeps.
175 * When an event happens, the idle loop wakes up, and dispatches
176 * to the appropriate event handler.
178 * The dispatching is done through a handlerTab that has one entry for each type of event.
179 * Each handlerTab entry should be a handler of type hal_handler *.
180 * There are currently three types of events, i.e. entries in the handlerTab:
181 * BUTTON_HANDLER_ID: handler to call upon a button press
182 * TICK_HANDLER_ID: handler to call upon a timer interrupt
183 * DISPATCH_HANDLER_ID: handler to call upon a received message from the MCM
192 * dispatches events as they come in
195 extern void Hal_idleLoop(void);
197 * --------- Hal_init ---------
199 * Initialize the hardware
201 * Initializes the EAP and MCM into their reset state. Should be called first.
202 * Sets up the clock, ports, watchdog timer, etc.
212 * EAP and MCM in their initial state.
215 extern void Hal_init(void);
217 * --------- Hal_ledOff ---------
219 * Turns the user LED off.
231 extern void Hal_ledOff(void);
233 * --------- Hal_ledOn ---------
235 * Turns the user LED on.
247 extern void Hal_ledOn(void);
249 * --------- Hal_ledRead ---------
251 * Returns the user LED state.
257 * Bool - (true = user LED is on, false = user LED is off)
263 extern bool Hal_ledRead(void);
265 * --------- Hal_ledToggle ---------
267 * Toggles the user LED.
276 * User LED toggles state.
279 extern void Hal_ledToggle(void);
281 * --------- Hal_tickStart ---------
283 * Sets up the timer to interrupt every msecs milliseconds and the user's tickHandler
284 * that will be called upon interrupt.
286 * Enable a timer interrupt every msecs ms. The interrupt will cause a TICK event
287 * to be entered into the event list. Once dispatched by the idle loop, the user's
288 * tickHandler will be called.
291 * msecs - the number of milliseconds between tick interrupts
292 * tickHandler - the address of the user's tick handler that will be called
298 * tickhandler called by the idle loop
301 extern void Hal_tickStart(uint16_t msecs, Hal_Handler Handler);