]> www.average.org Git - pulsecounter.git/blob - msp430/Hal/Hal.h
1ceecb55f63c98aff226bfc1f0ee5813076a489a
[pulsecounter.git] / msp430 / Hal / Hal.h
1 /**
2  * Hal.h -- HAL Interface Definitions
3  *
4  * This example HAL is intentionally simple.  The implementation is limited to:
5  *
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
12  *
13  * For information on Hal implementations for specific target hardware platforms,
14  * visit the http://wiki.em-hub.com/display/ED.
15  *
16  **/
17
18 #ifndef Hal__H
19 #define Hal__H
20
21 #include <stdint.h>
22 #include <stdbool.h>
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 typedef void (*Hal_Handler)(uint8_t id);
29
30 /**
31  * --------- Hal_buttonEnable ---------
32  *
33  * Enable the button interrupt and connect it to the user's buttonHandler
34  *
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.
38  *
39  * Inputs:
40  *   buttonHandler - pointer to the user's handler to be called after interrupt
41  *
42  * Returns:
43  *   None
44  *
45  * Side effects:
46  *   BUTTON interrupt enabled
47  *
48  **/
49 extern void Hal_gpioEnable(Hal_Handler handler);
50 /**
51  * --------- Hal_connected ---------
52  *
53  * Called whenever the MCM peripheral connects to a central.
54  *
55  * Could do other things associated with connection to the central.
56  *
57  * Inputs:
58  *   None
59  *
60  * Returns:
61  *   None
62  *
63  **/
64 extern void Hal_connected(void);
65 /**
66  * --------- Hal_delay ---------
67  *
68  * Delays for the specified number of milliseconds.
69  *
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.
72  *
73  * Inputs:
74  *   msecs - the number of milliseconds to delay
75  *
76  * Returns:
77  *   None
78  *
79  * Side Effects:
80  *   None
81  *
82  **/
83 extern void Hal_delay(uint16_t msecs);
84 /**
85  * --------- Hal_disconnected ---------
86  *
87  * Called whenever the MCM peripheral disconnects from a central.
88  *
89  * Could do other things associated with connection to the central.
90  *
91  * Inputs:
92  *   None
93  *
94  * Returns:
95  *   None
96  *
97  **/
98 extern void Hal_disconnected(void);
99 /**
100  * --------- Hal_idleLoop ---------
101  *
102  * The idle loop that controls EAP operations.
103  *
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.
108  *
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
115  *
116  * Inputs:
117  *   None
118  *
119  * Returns:
120  *   None
121  *
122  * Side Effects:
123  *   dispatches events as they come in
124  *
125  **/
126 extern void Hal_idleLoop(void);
127 /**
128  * --------- Hal_init ---------
129  *
130  * Initialize the hardware
131  *
132  * Initializes the EAP and MCM into their reset state.  Should be called first.
133  * Sets up the clock, ports, watchdog timer, etc.
134  *
135  *
136  * Inputs:
137  *   None
138  *
139  * Returns:
140  *   None
141  *
142  * Side Effects:
143  *   EAP and MCM in their initial state.
144  *
145  **/
146 extern void Hal_init(void);
147 /**
148  * --------- Hal_ledOff ---------
149  *
150  * Turns the user LED off.
151  *
152  * Inputs:
153  *   None
154  *
155  * Returns:
156  *   None
157  *
158  * Side Effects:
159  *   User LED off.
160  *
161  **/
162 extern void Hal_greenLedOff(void);
163 extern void Hal_redLedOff(void);
164 /**
165  * --------- Hal_ledOn ---------
166  *
167  * Turns the user LED on.
168  *
169  * Inputs:
170  *   None
171  *
172  * Returns:
173  *   None
174  *
175  * Side Effects:
176  *   User LED on.
177  *
178  **/
179 extern void Hal_greenLedOn(void);
180 extern void Hal_redLedOn(void);
181 /**
182  * --------- Hal_ledRead ---------
183  *
184  * Returns the user LED state.
185  *
186  * Inputs:
187  *   None
188  *
189  * Returns:
190  *   Bool -  (true = user LED is on, false = user LED is off)
191  *
192  * Side Effects:
193  *   None
194  *
195  **/
196 extern bool Hal_greenLedRead(void);
197 extern bool Hal_redLedRead(void);
198 /**
199  * --------- Hal_ledToggle ---------
200  *
201  * Toggles the user LED.
202  *
203  * Inputs:
204  *   None
205  *
206  * Returns:
207  *   None
208  *
209  * Side Effects:
210  *   User LED toggles state.
211  *
212  **/
213 extern void Hal_greenLedToggle(void);
214 extern void Hal_redLedToggle(void);
215 /**
216  * --------- Hal_tickStart ---------
217  *
218  * Sets up the timer to interrupt every msecs milliseconds and the user's tickHandler
219  * that will be called upon interrupt.
220  *
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.
224  *
225  * Inputs:
226  *   msecs - the number of milliseconds between tick interrupts
227  *   tickHandler - the address of the user's tick handler that will be called
228  *
229  * Returns:
230  *   None
231  *
232  * Side Effects:
233  *   tickhandler called by the idle loop
234  *
235  **/
236 extern void Hal_tickStart(uint16_t msecs, Hal_Handler Handler);
237 extern void Hal_tickStop(void);
238
239 #ifdef __cplusplus
240 }
241 #endif
242
243 #endif /* Hal__H */