Hal.h
6.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
/**
* Hal.h -- HAL Interface Definitions
*
* This example HAL is intentionally simple. The implementation is limited to:
*
* BUTTON -- a single button that when pressed will cause an interrupt.
* CONNECTED_LED -- an LED that is controlled inside the HAL to indicate connection to a central.
* DEBUG -- two debug GPIOs that are available as outputs from the EAP and under user control.
* DELAY -- a delay routine that can delay by n milliseconds.
* INIT -- set the hardware up to its initial state
* LED -- a user LED that is available for application control.
* TICK -- a timer that can be set to interrupt every n milliseconds
* IDLE LOOP -- an event driven idle loop for controlling the EAP
*
* For information on Hal implementations for specific target hardware platforms,
* visit the http://wiki.em-hub.com/display/ED.
*
**/
#ifndef Hal__H
#define Hal__H
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef void (*Hal_Handler)(void);
/**
* --------- Hal_buttonEnable ---------
*
* Enable the button interrupt and connect it to the user's buttonHandler
*
* When the button is pressed, it will cause an interrupt that will cause BUTTON event
* to be entered into the event list. Once dispatched by the idle loop, the user's
* buttonHandler will be called.
*
* Inputs:
* buttonHandler - pointer to the user's handler to be called after interrupt
*
* Returns:
* None
*
* Side effects:
* BUTTON interrupt enabled
*
**/
extern void Hal_buttonEnable(Hal_Handler handler);
/**
* --------- Hal_connected ---------
*
* Called whenever the MCM peripheral connects to a central.
*
* Turns on the CONNECTED_LED to show connectivity to the central
* Could do other things associated with connection to the central.
*
* Inputs:
* None
*
* Returns:
* None
*
* Side Effects:
* CONNECTED_LED on.
*
**/
extern void Hal_connected(void);
/**
* --------- Hal_debugOff ---------
*
* Turns the selected DEBUG line off.
*
* The two DEBUG lines are output GPIOs that are available to the user for
* debug purposes.
*
* Inputs:
* line - the index value of the debug line to turn off
*
* Returns:
* None
*
* Side Effects:
* DEBUG line off.
*
**/
extern void Hal_debugOff(uint8_t line);
/**
* --------- Hal_debugOn ---------
*
* Turns the selected DEBUG line on.
*
* The two DEBUG lines are output GPIOs that are available to the user for
* debug purposes.
*
* Inputs:
* line - the index value of the debug line to turn on
*
* Returns:
* None
*
* Side Effects:
* DEBUG line on.
*
**/
extern void Hal_debugOn(uint8_t line);
/**
* --------- Hal_debugPulse ---------
*
* Emits a pulse on the selected DEBUG line.
*
* The two DEBUG lines are output GPIOs that are available to the user for
* debug purposes.
*
* Inputs:
* line - the index value of the debug line to emit a pulse
*
* Returns:
* None
*
* Side Effects:
* DEBUG line turns on then off.
*
**/
extern void Hal_debugPulse(uint8_t line);
/**
* --------- Hal_delay ---------
*
* Delays for the specified number of milliseconds.
*
* In this example, delay is done with CPU spinning for simplicity's sake.
* This could easily use a timer interrupt for more power savings.
*
* Inputs:
* msecs - the number of milliseconds to delay
*
* Returns:
* None
*
* Side Effects:
* None
*
**/
extern void Hal_delay(uint16_t msecs);
/**
* --------- Hal_disconnected ---------
*
* Called whenever the MCM peripheral disconnects from a central.
*
* Turns off the CONNECTED_LED to show lack of connectivity to the central
* Could do other things associated with connection to the central.
*
* Inputs:
* None
*
* Returns:
* None
*
* Side Effects:
* CONNECTED_LED off.
*
**/
extern void Hal_disconnected(void);
/**
* --------- Hal_idleLoop ---------
*
* The idle loop that controls EAP operations.
*
* The hal implements an event driven "idle loop" scheduler.
* When there are no events pending, the idle loop sleeps.
* When an event happens, the idle loop wakes up, and dispatches
* to the appropriate event handler.
*
* The dispatching is done through a handlerTab that has one entry for each type of event.
* Each handlerTab entry should be a handler of type hal_handler *.
* There are currently three types of events, i.e. entries in the handlerTab:
* BUTTON_HANDLER_ID: handler to call upon a button press
* TICK_HANDLER_ID: handler to call upon a timer interrupt
* DISPATCH_HANDLER_ID: handler to call upon a received message from the MCM
*
* Inputs:
* None
*
* Returns:
* None
*
* Side Effects:
* dispatches events as they come in
*
**/
extern void Hal_idleLoop(void);
/**
* --------- Hal_init ---------
*
* Initialize the hardware
*
* Initializes the EAP and MCM into their reset state. Should be called first.
* Sets up the clock, ports, watchdog timer, etc.
*
*
* Inputs:
* None
*
* Returns:
* None
*
* Side Effects:
* EAP and MCM in their initial state.
*
**/
extern void Hal_init(void);
/**
* --------- Hal_ledOff ---------
*
* Turns the user LED off.
*
* Inputs:
* None
*
* Returns:
* None
*
* Side Effects:
* User LED off.
*
**/
extern void Hal_ledOff(void);
/**
* --------- Hal_ledOn ---------
*
* Turns the user LED on.
*
* Inputs:
* None
*
* Returns:
* None
*
* Side Effects:
* User LED on.
*
**/
extern void Hal_ledOn(void);
/**
* --------- Hal_ledRead ---------
*
* Returns the user LED state.
*
* Inputs:
* None
*
* Returns:
* Bool - (true = user LED is on, false = user LED is off)
*
* Side Effects:
* None
*
**/
extern bool Hal_ledRead(void);
/**
* --------- Hal_ledToggle ---------
*
* Toggles the user LED.
*
* Inputs:
* None
*
* Returns:
* None
*
* Side Effects:
* User LED toggles state.
*
**/
extern void Hal_ledToggle(void);
/**
* --------- Hal_tickStart ---------
*
* Sets up the timer to interrupt every msecs milliseconds and the user's tickHandler
* that will be called upon interrupt.
*
* Enable a timer interrupt every msecs ms. The interrupt will cause a TICK event
* to be entered into the event list. Once dispatched by the idle loop, the user's
* tickHandler will be called.
*
* Inputs:
* msecs - the number of milliseconds between tick interrupts
* tickHandler - the address of the user's tick handler that will be called
*
* Returns:
* None
*
* Side Effects:
* tickhandler called by the idle loop
*
**/
extern void Hal_tickStart(uint16_t msecs, Hal_Handler Handler);
#ifdef __cplusplus
}
#endif
#endif /* Hal__H */