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 * DELAY -- a delay routine that can delay by n milliseconds.
8 * INIT -- set the hardware up to its initial state
9 * LED -- a user LED that is available for application control.
10 * TICK -- a timer that can be set to interrupt every n milliseconds
11 * IDLE LOOP -- an event driven idle loop for controlling the EAP
13 * For information on Hal implementations for specific target hardware platforms,
14 * visit the http://wiki.em-hub.com/display/ED.
28 typedef void (*Hal_Handler)(uint8_t id);
31 * --------- Hal_buttonEnable ---------
33 * Enable the button interrupt and connect it to the user's buttonHandler
35 * When the button is pressed, it will cause an interrupt that will cause BUTTON event
36 * to be entered into the event list. Once dispatched by the idle loop, the user's
37 * buttonHandler will be called.
40 * buttonHandler - pointer to the user's handler to be called after interrupt
46 * BUTTON interrupt enabled
49 extern void Hal_gpioEnable(Hal_Handler handler);
51 * --------- Hal_connected ---------
53 * Called whenever the MCM peripheral connects to a central.
55 * Could do other things associated with connection to the central.
64 extern void Hal_connected(void);
66 * --------- Hal_delay ---------
68 * Delays for the specified number of milliseconds.
70 * In this example, delay is done with CPU spinning for simplicity's sake.
71 * This could easily use a timer interrupt for more power savings.
74 * msecs - the number of milliseconds to delay
83 extern void Hal_delay(uint16_t msecs);
85 * --------- Hal_disconnected ---------
87 * Called whenever the MCM peripheral disconnects from a central.
89 * Could do other things associated with connection to the central.
98 extern void Hal_disconnected(void);
100 * --------- Hal_idleLoop ---------
102 * The idle loop that controls EAP operations.
104 * The hal implements an event driven "idle loop" scheduler.
105 * When there are no events pending, the idle loop sleeps.
106 * When an event happens, the idle loop wakes up, and dispatches
107 * to the appropriate event handler.
109 * The dispatching is done through a handlerTab that has one entry for each type of event.
110 * Each handlerTab entry should be a handler of type hal_handler *.
111 * There are currently three types of events, i.e. entries in the handlerTab:
112 * BUTTON_HANDLER_ID: handler to call upon a button press
113 * TICK_HANDLER_ID: handler to call upon a timer interrupt
114 * DISPATCH_HANDLER_ID: handler to call upon a received message from the MCM
123 * dispatches events as they come in
126 extern void Hal_idleLoop(void);
128 * --------- Hal_init ---------
130 * Initialize the hardware
132 * Initializes the EAP and MCM into their reset state. Should be called first.
133 * Sets up the clock, ports, watchdog timer, etc.
143 * EAP and MCM in their initial state.
146 extern void Hal_init(void);
148 * --------- Hal_ledOff ---------
150 * Turns the user LED off.
162 extern void Hal_greenLedOff(void);
163 extern void Hal_redLedOff(void);
165 * --------- Hal_ledOn ---------
167 * Turns the user LED on.
179 extern void Hal_greenLedOn(void);
180 extern void Hal_redLedOn(void);
182 * --------- Hal_ledRead ---------
184 * Returns the user LED state.
190 * Bool - (true = user LED is on, false = user LED is off)
196 extern bool Hal_greenLedRead(void);
197 extern bool Hal_redLedRead(void);
199 * --------- Hal_ledToggle ---------
201 * Toggles the user LED.
210 * User LED toggles state.
213 extern void Hal_greenLedToggle(void);
214 extern void Hal_redLedToggle(void);
216 * --------- Hal_tickStart ---------
218 * Sets up the timer to interrupt every msecs milliseconds and the user's tickHandler
219 * that will be called upon interrupt.
221 * Enable a timer interrupt every msecs ms. The interrupt will cause a TICK event
222 * to be entered into the event list. Once dispatched by the idle loop, the user's
223 * tickHandler will be called.
226 * msecs - the number of milliseconds between tick interrupts
227 * tickHandler - the address of the user's tick handler that will be called
230 * Future clock when handler will be called
233 * tickhandler called by the idle loop
236 extern uint16_t Hal_tickStart(uint16_t msecs, void (*handler)(uint16_t clock));
237 extern void Hal_tickStop(void);
240 * --------- Hal_gpioCount ---------
242 * Returns the number of interrups encounted on gpio `id`
245 * id if the gpio (0-2 for gpio 3-5)
251 * Resets the accumulator (counting restarts from zero).
254 extern uint32_t Hal_gpioCount(uint8_t id);