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 typedef void (*Hal_Handler)(uint8_t id);
32 * --------- Hal_buttonEnable ---------
34 * Enable the button interrupt and connect it to the user's buttonHandler
36 * When the button is pressed, it will cause an interrupt that will cause BUTTON event
37 * to be entered into the event list. Once dispatched by the idle loop, the user's
38 * buttonHandler will be called.
41 * buttonHandler - pointer to the user's handler to be called after interrupt
47 * BUTTON interrupt enabled
50 extern void Hal_buttonEnable(void (*handler)(void));
52 * --------- Hal_connected ---------
54 * Called whenever the MCM peripheral connects to a central.
56 * Could do other things associated with connection to the central.
65 extern void Hal_connected(void);
67 * --------- Hal_debugOff ---------
69 * Turns the selected DEBUG line off.
71 * The two DEBUG lines are output GPIOs that are available to the user for
75 * line - the index value of the debug line to turn off
84 extern void Hal_debugOff(uint8_t line);
86 * --------- Hal_debugOn ---------
88 * Turns the selected DEBUG line on.
90 * The two DEBUG lines are output GPIOs that are available to the user for
94 * line - the index value of the debug line to turn on
103 extern void Hal_debugOn(uint8_t line);
105 * --------- Hal_debugPulse ---------
107 * Emits a pulse on the selected DEBUG line.
109 * The two DEBUG lines are output GPIOs that are available to the user for
113 * line - the index value of the debug line to emit a pulse
119 * DEBUG line turns on then off.
122 extern void Hal_debugPulse(uint8_t line);
124 * --------- Hal_delay ---------
126 * Delays for the specified number of milliseconds.
128 * In this example, delay is done with CPU spinning for simplicity's sake.
129 * This could easily use a timer interrupt for more power savings.
132 * msecs - the number of milliseconds to delay
141 extern void Hal_delay(uint16_t msecs);
143 * --------- Hal_disconnected ---------
145 * Called whenever the MCM peripheral disconnects from a central.
147 * Could do other things associated with connection to the central.
156 extern void Hal_disconnected(void);
158 * --------- Hal_idleLoop ---------
160 * The idle loop that controls EAP operations.
162 * The hal implements an event driven "idle loop" scheduler.
163 * When there are no events pending, the idle loop sleeps.
164 * When an event happens, the idle loop wakes up, and dispatches
165 * to the appropriate event handler.
167 * The dispatching is done through a handlerTab that has one entry for each type of event.
168 * Each handlerTab entry should be a handler of type hal_handler *.
169 * There are currently three types of events, i.e. entries in the handlerTab:
170 * BUTTON_HANDLER_ID: handler to call upon a button press
171 * TICK_HANDLER_ID: handler to call upon a timer interrupt
172 * DISPATCH_HANDLER_ID: handler to call upon a received message from the MCM
181 * dispatches events as they come in
184 extern void Hal_idleLoop(void);
186 * --------- Hal_init ---------
188 * Initialize the hardware
190 * Initializes the EAP and MCM into their reset state. Should be called first.
191 * Sets up the clock, ports, watchdog timer, etc.
201 * EAP and MCM in their initial state.
204 extern void Hal_init(void);
206 * --------- Hal_ledOff ---------
208 * Turns the user LED off.
220 extern void Hal_greenLedOff(void);
221 extern void Hal_redLedOff(void);
223 * --------- Hal_ledOn ---------
225 * Turns the user LED on.
237 extern void Hal_greenLedOn(void);
238 extern void Hal_redLedOn(void);
240 * --------- Hal_ledRead ---------
242 * Returns the user LED state.
248 * Bool - (true = user LED is on, false = user LED is off)
254 extern bool Hal_greenLedRead(void);
255 extern bool Hal_redLedRead(void);
257 * --------- Hal_ledToggle ---------
259 * Toggles the user LED.
268 * User LED toggles state.
271 extern void Hal_greenLedToggle(void);
272 extern void Hal_redLedToggle(void);
274 * --------- Hal_tickStart ---------
276 * Sets up the timer to interrupt every msecs milliseconds and the user's tickHandler
277 * that will be called upon interrupt.
279 * Enable a timer interrupt every msecs ms. The interrupt will cause a TICK event
280 * to be entered into the event list. Once dispatched by the idle loop, the user's
281 * tickHandler will be called.
284 * msecs - the number of milliseconds between tick interrupts
285 * tickHandler - the address of the user's tick handler that will be called
291 * tickhandler called by the idle loop
294 extern void Hal_tickStart(uint16_t msecs, Hal_Handler Handler);
295 extern void Hal_tickStop(void);