1 /** @file gio.c
2 * @brief GIO Driver Implementation File
3 * @date 29.May.2013
4 * @version 03.05.02
5 *
6 */
7
8 /* (c) Texas Instruments 2009-2013, All rights reserved. */
9
10 /* USER CODE BEGIN (0) */
11 /* USER CODE END */
12
13 #include "gio.h"
14
15 /* USER CODE BEGIN (1) */
16 /* USER CODE END */
17
18 /** @fn void gioInit(void)
19 * @brief Initializes the GIO Driver
20 *
21 * This function initializes the GIO module and set the GIO ports
22 * to the initial values.
23 */
24 /* SourceId : GIO_SourceId_001 */
25 /* Requirements : HL_SR115, HL_SR116, HL_SR117, HL_SR118, HL_SR119, HL_SR120, HL_SR121, HL_SR122 */
gioInit(void)26 void gioInit(void)
27 {
28 /* USER CODE BEGIN (2) */
29 /* USER CODE END */
30
31 /** bring GIO module out of reset */
32 gioREG->GCR0 = 1U;
33 gioREG->INTENACLR = 0xFFU;
34 gioREG->LVLCLR = 0xFFU;
35
36 /** @b initialize @b Port @b A */
37
38 /** - Port A output values */
39 gioPORTA->DOUT = 0U /* Bit 0 */
40 | (0U << 1U) /* Bit 1 */
41 | (0U << 2U) /* Bit 2 */
42 | (0U << 3U) /* Bit 3 */
43 | (0U << 4U) /* Bit 4 */
44 | (0U << 5U) /* Bit 5 */
45 | (0U << 6U) /* Bit 6 */
46 | (0U << 7U); /* Bit 7 */
47
48 /** - Port A direction */
49 gioPORTA->DIR = 0U /* Bit 0 */
50 | (0U << 1U) /* Bit 1 */
51 | (0U << 2U) /* Bit 2 */
52 | (0U << 3U) /* Bit 3 */
53 | (0U << 4U) /* Bit 4 */
54 | (0U << 5U) /* Bit 5 */
55 | (0U << 6U) /* Bit 6 */
56 | (0U << 7U); /* Bit 7 */
57
58 /** - Port A open drain enable */
59 gioPORTA->PDR = 0U /* Bit 0 */
60 | (0U << 1U) /* Bit 1 */
61 | (0U << 2U) /* Bit 2 */
62 | (0U << 3U) /* Bit 3 */
63 | (0U << 4U) /* Bit 4 */
64 | (0U << 5U) /* Bit 5 */
65 | (0U << 6U) /* Bit 6 */
66 | (0U << 7U); /* Bit 7 */
67
68 /** - Port A pullup / pulldown selection */
69 gioPORTA->PSL = 0U /* Bit 0 */
70 | (0U << 1U) /* Bit 1 */
71 | (0U << 2U) /* Bit 2 */
72 | (0U << 3U) /* Bit 3 */
73 | (0U << 4U) /* Bit 4 */
74 | (0U << 5U) /* Bit 5 */
75 | (0U << 6U) /* Bit 6 */
76 | (0U << 7U); /* Bit 7 */
77
78 /** - Port A pullup / pulldown enable*/
79 gioPORTA->PULDIS = 0U /* Bit 0 */
80 | (0U << 1U) /* Bit 1 */
81 | (0U << 2U) /* Bit 2 */
82 | (0U << 3U) /* Bit 3 */
83 | (0U << 4U) /* Bit 4 */
84 | (0U << 5U) /* Bit 5 */
85 | (0U << 6U) /* Bit 6 */
86 | (0U << 7U); /* Bit 7 */
87
88 /** @b initialize @b Port @b B */
89
90 /** - Port B output values */
91 gioPORTB->DOUT = 0U /* Bit 0 */
92 | (0U << 1U) /* Bit 1 */
93 | (0U << 2U) /* Bit 2 */
94 | (0U << 3U) /* Bit 3 */
95 | (0U << 4U) /* Bit 4 */
96 | (0U << 5U) /* Bit 5 */
97 | (0U << 6U) /* Bit 6 */
98 | (0U << 7U); /* Bit 7 */
99
100 /** - Port B direction */
101 gioPORTB->DIR = 0U /* Bit 0 */
102 | (0U << 1U) /* Bit 1 */
103 | (0U << 2U) /* Bit 2 */
104 | (0U << 3U) /* Bit 3 */
105 | (0U << 4U) /* Bit 4 */
106 | (0U << 5U) /* Bit 5 */
107 | (0U << 6U) /* Bit 6 */
108 | (0U << 7U); /* Bit 7 */
109
110 /** - Port B open drain enable */
111 gioPORTB->PDR = 0U /* Bit 0 */
112 | (0U << 1U) /* Bit 1 */
113 | (0U << 2U) /* Bit 2 */
114 | (0U << 3U) /* Bit 3 */
115 | (0U << 4U) /* Bit 4 */
116 | (0U << 5U) /* Bit 5 */
117 | (0U << 6U) /* Bit 6 */
118 | (0U << 7U); /* Bit 7 */
119
120 /** - Port B pullup / pulldown selection */
121 gioPORTB->PSL = 0U /* Bit 0 */
122 | (0U << 1U) /* Bit 1 */
123 | (0U << 2U) /* Bit 2 */
124 | (0U << 3U) /* Bit 3 */
125 | (0U << 4U) /* Bit 4 */
126 | (0U << 5U) /* Bit 5 */
127 | (0U << 6U) /* Bit 6 */
128 | (0U << 7U); /* Bit 7 */
129
130 /** - Port B pullup / pulldown enable*/
131 gioPORTB->PULDIS = 0U /* Bit 0 */
132 | (0U << 1U) /* Bit 1 */
133 | (0U << 2U) /* Bit 2 */
134 | (0U << 3U) /* Bit 3 */
135 | (0U << 4U) /* Bit 4 */
136 | (0U << 5U) /* Bit 5 */
137 | (0U << 6U) /* Bit 6 */
138 | (0U << 7U); /* Bit 7 */
139
140 /* USER CODE BEGIN (3) */
141 /* USER CODE END */
142
143 /** @b initialize @b interrupts */
144
145 /** - interrupt polarity */
146 gioREG->POL = 0U /* Bit 0 */
147 | (0U << 1U) /* Bit 1 */
148 | (0U << 2U) /* Bit 2 */
149 | (0U << 3U) /* Bit 3 */
150 | (0U << 4U) /* Bit 4 */
151 | (0U << 5U) /* Bit 5 */
152 | (0U << 6U) /* Bit 6 */
153 | (0U << 7U) /* Bit 7 */
154
155 | (0U << 8U) /* Bit 8 */
156 | (0U << 9U) /* Bit 9 */
157 | (0U << 10U) /* Bit 10 */
158 | (0U << 11U) /* Bit 11 */
159 | (0U << 12U) /* Bit 12 */
160 | (0U << 13U) /* Bit 13 */
161 | (0U << 14U) /* Bit 14 */
162 | (0U << 15U);/* Bit 15 */
163
164
165 /** - interrupt level */
166 gioREG->LVLSET = 0U /* Bit 0 */
167 | (0U << 1U) /* Bit 1 */
168 | (0U << 2U) /* Bit 2 */
169 | (0U << 3U) /* Bit 3 */
170 | (0U << 4U) /* Bit 4 */
171 | (0U << 5U) /* Bit 5 */
172 | (0U << 6U) /* Bit 6 */
173 | (0U << 7U) /* Bit 7 */
174
175 | (0U << 8U) /* Bit 8 */
176 | (0U << 9U) /* Bit 9 */
177 | (0U << 10U) /* Bit 10 */
178 | (0U << 11U) /* Bit 11 */
179 | (0U << 12U) /* Bit 12 */
180 | (0U << 13U) /* Bit 13 */
181 | (0U << 14U) /* Bit 14 */
182 | (0U << 15U);/* Bit 15 */
183
184
185
186
187 /** - clear all pending interrupts */
188 gioREG->FLG = 0xFFU;
189
190 /** - enable interrupts */
191 gioREG->INTENASET = 0U /* Bit 0 */
192 | (0U << 1U) /* Bit 1 */
193 | (0U << 2U) /* Bit 2 */
194 | (0U << 3U) /* Bit 3 */
195 | (0U << 4U) /* Bit 4 */
196 | (0U << 5U) /* Bit 5 */
197 | (0U << 6U) /* Bit 6 */
198 | (0U << 7U) /* Bit 7 */
199
200 | (0U << 8U) /* Bit 8 */
201 | (0U << 9U) /* Bit 9 */
202 | (0U << 10U) /* Bit 10 */
203 | (0U << 11U) /* Bit 11 */
204 | (0U << 12U) /* Bit 12 */
205 | (0U << 13U) /* Bit 13 */
206 | (0U << 14U) /* Bit 14 */
207 | (0U << 15U);/* Bit 15 */
208
209 /* USER CODE BEGIN (4) */
210 /* USER CODE END */
211 }
212
213
214 /** @fn void gioSetDirection(gioPORT_t *port, uint32 dir)
215 * @brief Set Port Direction
216 * @param[in] port pointer to GIO port:
217 * - gioPORTA: PortA pointer
218 * - gioPORTB: PortB pointer
219 * @param[in] dir value to write to DIR register
220 *
221 * Set the direction of GIO pins at runtime.
222 */
223 /* SourceId : GIO_SourceId_002 */
224 /* Requirements : HL_SR123 */
gioSetDirection(gioPORT_t * port,uint32 dir)225 void gioSetDirection(gioPORT_t *port, uint32 dir)
226 {
227 port->DIR = dir;
228 }
229
230
231 /** @fn void gioSetBit(gioPORT_t *port, uint32 bit, uint32 value)
232 * @brief Write Bit
233 * @param[in] port pointer to GIO port:
234 * - gioPORTA: PortA pointer
235 * - gioPORTB: PortB pointer
236 * @param[in] bit number 0-7 that specifies the bit to be written to.
237 * - 0: LSB
238 * - 7: MSB
239 * @param[in] value binary value to write to bit
240 *
241 * Writes a value to the specified pin of the given GIO port
242 */
243 /* SourceId : GIO_SourceId_003 */
244 /* Requirements : HL_SR126 */
gioSetBit(gioPORT_t * port,uint32 bit,uint32 value)245 void gioSetBit(gioPORT_t *port, uint32 bit, uint32 value)
246 {
247 /* USER CODE BEGIN (5) */
248 /* USER CODE END */
249
250 if (value != 0U)
251 {
252 port->DSET = 1U << bit;
253 }
254 else
255 {
256 port->DCLR = 1U << bit;
257 }
258 }
259
260
261 /** @fn void gioSetPort(gioPORT_t *port, uint32 value)
262 * @brief Write Port Value
263 * @param[in] port pointer to GIO port:
264 * - gioPORTA: PortA pointer
265 * - gioPORTB: PortB pointer
266 * @param[in] value value to write to port
267 *
268 * Writes a value to all pin of a given GIO port
269 */
270 /* SourceId : GIO_SourceId_004 */
271 /* Requirements : HL_SR127 */
gioSetPort(gioPORT_t * port,uint32 value)272 void gioSetPort(gioPORT_t *port, uint32 value)
273 {
274 /* USER CODE BEGIN (6) */
275 /* USER CODE END */
276
277 port->DOUT = value;
278
279 /* USER CODE BEGIN (7) */
280 /* USER CODE END */
281
282 }
283
284
285 /** @fn uint32 gioGetBit(gioPORT_t *port, uint32 bit)
286 * @brief Read Bit
287 * @param[in] port pointer to GIO port:
288 * - gioPORTA: PortA pointer
289 * - gioPORTB: PortB pointer
290 * @param[in] bit number 0-7 that specifies the bit to be written to.
291 * - 0: LSB
292 * - 7: MSB
293 *
294 * Reads a the current value from the specified pin of the given GIO port
295 */
296 /* SourceId : GIO_SourceId_005 */
297 /* Requirements : HL_SR124 */
gioGetBit(gioPORT_t * port,uint32 bit)298 uint32 gioGetBit(gioPORT_t *port, uint32 bit)
299 {
300 /* USER CODE BEGIN (8) */
301 /* USER CODE END */
302
303 return (port->DIN >> bit) & 1U;
304 }
305
306
307 /** @fn uint32 gioGetPort(gioPORT_t *port)
308 * @brief Read Port Value
309 * @param[in] port pointer to GIO port:
310 * - gioPORTA: PortA pointer
311 * - gioPORTB: PortB pointer
312 *
313 * Reads a the current value of a given GIO port
314 */
315 /* SourceId : GIO_SourceId_006 */
316 /* Requirements : HL_SR125 */
gioGetPort(gioPORT_t * port)317 uint32 gioGetPort(gioPORT_t *port)
318 {
319 /* USER CODE BEGIN (9) */
320 /* USER CODE END */
321
322 return port->DIN;
323 }
324
325 /** @fn void gioToggleBit(gioPORT_t *port, uint32 bit)
326 * @brief Write Bit
327 * @param[in] port pointer to GIO port:
328 * - gioPORTA: PortA pointer
329 * - gioPORTB: PortB pointer
330 * @param[in] bit number 0-7 that specifies the bit to be written to.
331 * - 0: LSB
332 * - 7: MSB
333 *
334 * Toggle a value to the specified pin of the given GIO port
335 */
336 /* SourceId : GIO_SourceId_007 */
337 /* Requirements : */
gioToggleBit(gioPORT_t * port,uint32 bit)338 void gioToggleBit(gioPORT_t *port, uint32 bit)
339 {
340 /* USER CODE BEGIN (10) */
341 /* USER CODE END */
342
343 if ((port->DIN & (1U << bit)) != 0U)
344 {
345 port->DCLR = 1U << bit;
346 }
347 else
348 {
349 port->DSET = 1U << bit;
350 }
351 }
352
353 /** @fn void gioEnableNotification(uint32 bit)
354 * @brief Enable Interrupt
355 * @param[in] port pointer to GIO port:
356 * - gioPORTA: PortA pointer
357 * - gioPORTB: PortB pointer
358 * @param[in] bit interrupt pin to enable
359 * - 0: LSB
360 * - 7: MSB
361 *
362 * Enables an interrupt pin of selected port
363 */
364 /* SourceId : GIO_SourceId_008 */
365 /* Requirements : HL_SR128 */
gioEnableNotification(gioPORT_t * port,uint32 bit)366 void gioEnableNotification(gioPORT_t *port, uint32 bit)
367 {
368 /* USER CODE BEGIN (11) */
369 /* USER CODE END */
370
371 if (port == gioPORTA)
372 {
373 gioREG->INTENASET = 1U << bit;
374 }
375 else if (port == gioPORTB)
376 {
377 gioREG->INTENASET = 1U << (bit + 8);
378 }
379 else
380 {
381 /* Empty */
382 }
383 }
384
385
386 /** @fn void gioDisableNotification(uint32 bit)
387 * @brief Disable Interrupt
388 * @param[in] port pointer to GIO port:
389 * - gioPORTA: PortA pointer
390 * - gioPORTB: PortB pointer
391 * @param[in] bit interrupt pin to enable
392 * - 0: LSB
393 * - 7: MSB
394 *
395 * Disables an interrupt pin of selected port
396 */
397 /* SourceId : GIO_SourceId_009 */
398 /* Requirements : HL_SR129 */
gioDisableNotification(gioPORT_t * port,uint32 bit)399 void gioDisableNotification(gioPORT_t *port, uint32 bit)
400 {
401 /* USER CODE BEGIN (12) */
402 /* USER CODE END */
403
404 if (port == gioPORTA)
405 {
406 gioREG->INTENACLR = 1U << bit;
407 }
408 else if (port == gioPORTB)
409 {
410 gioREG->INTENACLR = 1U << (bit + 8);
411 }
412 else
413 {
414 /* Empty */
415 }
416 }
417
418
419
420 /* USER CODE BEGIN (19) */
421 /* USER CODE END */
422