2 * @brief GIO Driver Implementation File
\r
8 /* (c) Texas Instruments 2009-2012, All rights reserved. */
\r
10 /* USER CODE BEGIN (0) */
\r
15 /* USER CODE BEGIN (1) */
\r
18 /** @fn void gioInit(void)
\r
19 * @brief Initializes the GIO Driver
\r
21 * This function initializes the GIO module and set the GIO ports
\r
22 * to the inital values.
\r
26 /* USER CODE BEGIN (2) */
\r
29 /** bring GIO module out of reset */
\r
31 gioREG->INTENACLR = 0xFF;
\r
32 gioREG->LVLCLR = 0xFF;
\r
34 /** @b initalise @b Port @b A */
\r
36 /** - Port A output values */
\r
37 gioPORTA->DOUT = 0 /* Bit 0 */
\r
38 | (0 << 1) /* Bit 1 */
\r
39 | (0 << 2) /* Bit 2 */
\r
40 | (0 << 3) /* Bit 3 */
\r
41 | (0 << 4) /* Bit 4 */
\r
42 | (0 << 5) /* Bit 5 */
\r
43 | (0 << 6) /* Bit 6 */
\r
44 | (0 << 7); /* Bit 7 */
\r
46 /** - Port A direction */
\r
47 gioPORTA->DIR = 0 /* Bit 0 */
\r
48 | (0 << 1) /* Bit 1 */
\r
49 | (0 << 2) /* Bit 2 */
\r
50 | (0 << 3) /* Bit 3 */
\r
51 | (0 << 4) /* Bit 4 */
\r
52 | (0 << 5) /* Bit 5 */
\r
53 | (0 << 6) /* Bit 6 */
\r
54 | (0 << 7); /* Bit 7 */
\r
56 /** - Port A open drain enable */
\r
57 gioPORTA->PDR = 0 /* Bit 0 */
\r
58 | (0 << 1) /* Bit 1 */
\r
59 | (0 << 2) /* Bit 2 */
\r
60 | (0 << 3) /* Bit 3 */
\r
61 | (0 << 4) /* Bit 4 */
\r
62 | (0 << 5) /* Bit 5 */
\r
63 | (0 << 6) /* Bit 6 */
\r
64 | (0 << 7); /* Bit 7 */
\r
66 /** - Port A pullup / pulldown selection */
\r
67 gioPORTA->PSL = 0 /* Bit 0 */
\r
68 | (0 << 1) /* Bit 1 */
\r
69 | (0 << 2) /* Bit 2 */
\r
70 | (0 << 3) /* Bit 3 */
\r
71 | (0 << 4) /* Bit 4 */
\r
72 | (0 << 5) /* Bit 5 */
\r
73 | (0 << 6) /* Bit 6 */
\r
74 | (0 << 7); /* Bit 7 */
\r
76 /** - Port A pullup / pulldown enable*/
\r
77 gioPORTA->PULDIS = 0 /* Bit 0 */
\r
78 | (0 << 1) /* Bit 1 */
\r
79 | (0 << 2) /* Bit 2 */
\r
80 | (0 << 3) /* Bit 3 */
\r
81 | (0 << 4) /* Bit 4 */
\r
82 | (0 << 5) /* Bit 5 */
\r
83 | (0 << 6) /* Bit 6 */
\r
84 | (0 << 7); /* Bit 7 */
\r
86 /** @b initalise @b Port @b B */
\r
88 /** - Port B output values */
\r
89 gioPORTB->DOUT = 0 /* Bit 0 */
\r
90 | (0 << 1) /* Bit 1 */
\r
91 | (0 << 2) /* Bit 2 */
\r
92 | (0 << 3) /* Bit 3 */
\r
93 | (0 << 4) /* Bit 4 */
\r
94 | (0 << 5) /* Bit 5 */
\r
95 | (0 << 6) /* Bit 6 */
\r
96 | (0 << 7); /* Bit 7 */
\r
98 /** - Port B direction */
\r
99 gioPORTB->DIR = 1 /* Bit 0 */
\r
100 | (1 << 1) /* Bit 1 */
\r
101 | (1 << 2) /* Bit 2 */
\r
102 | (1 << 3) /* Bit 3 */
\r
103 | (1 << 4) /* Bit 4 */
\r
104 | (1 << 5) /* Bit 5 */
\r
105 | (1 << 6) /* Bit 6 */
\r
106 | (1 << 7); /* Bit 7 */
\r
108 /** - Port B open drain enable */
\r
109 gioPORTB->PDR = 1 /* Bit 0 */
\r
110 | (1 << 1) /* Bit 1 */
\r
111 | (0 << 2) /* Bit 2 */
\r
112 | (0 << 3) /* Bit 3 */
\r
113 | (1 << 4) /* Bit 4 */
\r
114 | (1 << 5) /* Bit 5 */
\r
115 | (0 << 6) /* Bit 6 */
\r
116 | (0 << 7); /* Bit 7 */
\r
118 /** - Port B pullup / pulldown selection */
\r
119 gioPORTB->PSL = 0 /* Bit 0 */
\r
120 | (0 << 1) /* Bit 1 */
\r
121 | (0 << 2) /* Bit 2 */
\r
122 | (0 << 3) /* Bit 3 */
\r
123 | (0 << 4) /* Bit 4 */
\r
124 | (0 << 5) /* Bit 5 */
\r
125 | (0 << 6) /* Bit 6 */
\r
126 | (0 << 7); /* Bit 7 */
\r
128 /** - Port B pullup / pulldown enable*/
\r
129 gioPORTB->PULDIS = 1 /* Bit 0 */
\r
130 | (1 << 1) /* Bit 1 */
\r
131 | (0 << 2) /* Bit 2 */
\r
132 | (0 << 3) /* Bit 3 */
\r
133 | (1 << 4) /* Bit 4 */
\r
134 | (1 << 5) /* Bit 5 */
\r
135 | (0 << 6) /* Bit 6 */
\r
136 | (0 << 7); /* Bit 7 */
\r
138 /* USER CODE BEGIN (3) */
\r
139 /* USER CODE END */
\r
141 /** @b initalise @b interrupts */
\r
143 /** - interrupt polarity */
\r
144 gioREG->POL = 0 /* Bit 0 */
\r
145 | (0 << 1) /* Bit 1 */
\r
146 | (0 << 2) /* Bit 2 */
\r
147 | (0 << 3) /* Bit 3 */
\r
148 | (0 << 4) /* Bit 4 */
\r
149 | (0 << 5) /* Bit 5 */
\r
150 | (0 << 6) /* Bit 6 */
\r
151 | (0 << 7) /* Bit 7 */
\r
153 | (0 << 8) /* Bit 8 */
\r
154 | (0 << 9) /* Bit 9 */
\r
155 | (0 << 10) /* Bit 10 */
\r
156 | (0 << 11) /* Bit 11 */
\r
157 | (0 << 12) /* Bit 12 */
\r
158 | (0 << 13) /* Bit 13 */
\r
159 | (0 << 14) /* Bit 14 */
\r
160 | (0 << 15);/* Bit 15 */
\r
163 /** - interrupt level */
\r
164 gioREG->LVLSET = 0 /* Bit 0 */
\r
165 | (0 << 1) /* Bit 1 */
\r
166 | (0 << 2) /* Bit 2 */
\r
167 | (0 << 3) /* Bit 3 */
\r
168 | (0 << 4) /* Bit 4 */
\r
169 | (0 << 5) /* Bit 5 */
\r
170 | (0 << 6) /* Bit 6 */
\r
171 | (0 << 7) /* Bit 7 */
\r
173 | (0 << 8) /* Bit 8 */
\r
174 | (0 << 9) /* Bit 9 */
\r
175 | (0 << 10) /* Bit 10 */
\r
176 | (0 << 11) /* Bit 11 */
\r
177 | (0 << 12) /* Bit 12 */
\r
178 | (0 << 13) /* Bit 13 */
\r
179 | (0 << 14) /* Bit 14 */
\r
180 | (0 << 15);/* Bit 15 */
\r
185 /** - clear all pending interrupts */
\r
186 gioREG->FLG = 0xFF;
\r
188 /** - enable interrupts */
\r
189 gioREG->INTENASET = 0 /* Bit 0 */
\r
190 | (0 << 1) /* Bit 1 */
\r
191 | (0 << 2) /* Bit 2 */
\r
192 | (0 << 3) /* Bit 3 */
\r
193 | (0 << 4) /* Bit 4 */
\r
194 | (0 << 5) /* Bit 5 */
\r
195 | (0 << 6) /* Bit 6 */
\r
196 | (0 << 7) /* Bit 7 */
\r
198 | (0 << 8) /* Bit 8 */
\r
199 | (0 << 9) /* Bit 9 */
\r
200 | (0 << 10) /* Bit 10 */
\r
201 | (0 << 11) /* Bit 11 */
\r
202 | (0 << 12) /* Bit 12 */
\r
203 | (0 << 13) /* Bit 13 */
\r
204 | (0 << 14) /* Bit 14 */
\r
205 | (0 << 15);/* Bit 15 */
\r
207 /* USER CODE BEGIN (4) */
\r
208 /* USER CODE END */
\r
212 /** @fn void gioSetDirection(gioPORT_t *port, uint32_t dir)
\r
213 * @brief Set Port Direction
\r
214 * @param[in] port pointer to GIO port:
\r
215 * - gioPORTA: PortA pointer
\r
216 * - gioPORTB: PortB pointer
\r
217 * @param[in] dir value to write to DIR register
\r
219 * Set the direction of GIO pins at runtime.
\r
221 void gioSetDirection(gioPORT_t *port, uint32_t dir)
\r
227 /** @fn void gioSetBit(gioPORT_t *port, uint32_t bit, uint32_t value)
\r
229 * @param[in] port pointer to GIO port:
\r
230 * - gioPORTA: PortA pointer
\r
231 * - gioPORTB: PortB pointer
\r
232 * @param[in] bit number 0-7 that specifies the bit to be written to.
\r
235 * @param[in] value binrary value to write to bit
\r
237 * Writes a value to the specified pin of the given GIO port
\r
239 void gioSetBit(gioPORT_t *port, uint32_t bit, uint32_t value)
\r
241 /* USER CODE BEGIN (5) */
\r
242 /* USER CODE END */
\r
246 port->DSET = 1 << bit;
\r
250 port->DCLR = 1 << bit;
\r
255 /** @fn void gioSetPort(gioPORT_t *port, uint32_t value)
\r
256 * @brief Write Port Value
\r
257 * @param[in] port pointer to GIO port:
\r
258 * - gioPORTA: PortA pointer
\r
259 * - gioPORTB: PortB pointer
\r
260 * @param[in] value value to write to port
\r
262 * Writes a value to all pin of a given GIO port
\r
264 void gioSetPort(gioPORT_t *port, uint32_t value)
\r
266 /* USER CODE BEGIN (6) */
\r
267 /* USER CODE END */
\r
269 port->DOUT = value;
\r
271 /* USER CODE BEGIN (7) */
\r
272 /* USER CODE END */
\r
277 /** @fn uint32_t gioGetBit(gioPORT_t *port, uint32_t bit)
\r
279 * @param[in] port pointer to GIO port:
\r
280 * - gioPORTA: PortA pointer
\r
281 * - gioPORTB: PortB pointer
\r
282 * @param[in] bit number 0-7 that specifies the bit to be written to.
\r
286 * Reads a the current value from the specified pin of the given GIO port
\r
288 uint32_t gioGetBit(gioPORT_t *port, uint32_t bit)
\r
290 /* USER CODE BEGIN (8) */
\r
291 /* USER CODE END */
\r
293 return (port->DIN >> bit) & 1U;
\r
297 /** @fn uint32_t gioGetPort(gioPORT_t *port)
\r
298 * @brief Read Port Value
\r
299 * @param[in] port pointer to GIO port:
\r
300 * - gioPORTA: PortA pointer
\r
301 * - gioPORTB: PortB pointer
\r
303 * Reads a the current value of a given GIO port
\r
305 uint32_t gioGetPort(gioPORT_t *port)
\r
307 /* USER CODE BEGIN (9) */
\r
308 /* USER CODE END */
\r
313 /** @fn void gioToggleBit(gioPORT_t *port, uint32_t bit)
\r
315 * @param[in] port pointer to GIO port:
\r
316 * - gioPORTA: PortA pointer
\r
317 * - gioPORTB: PortB pointer
\r
318 * @param[in] bit number 0-7 that specifies the bit to be written to.
\r
322 * Toggle a value to the specified pin of the given GIO port
\r
324 void gioToggleBit(gioPORT_t *port, uint32_t bit)
\r
326 /* USER CODE BEGIN (10) */
\r
327 /* USER CODE END */
\r
329 if ((port->DIN & (1 << bit)) != 0)
\r
331 port->DCLR = 1 << bit;
\r
335 port->DSET = 1 << bit;
\r
339 /** @fn void gioEnableNotification(uint32_t bit)
\r
340 * @brief Enable Interrupt
\r
341 * @param[in] bit interrupt pin to enable
\r
345 * Enables an innterrupt pin of PortA
\r
347 void gioEnableNotification(uint32_t bit)
\r
349 /* USER CODE BEGIN (11) */
\r
350 /* USER CODE END */
\r
352 gioREG->INTENASET = 1 << bit;
\r
356 /** @fn void gioDisableNotification(uint32_t bit)
\r
357 * @brief Disable Interrupt
\r
358 * @param[in] bit interrupt pin to enable
\r
362 * Disables an innterrupt pin of PortA
\r
364 void gioDisableNotification(uint32_t bit)
\r
366 /* USER CODE BEGIN (12) */
\r
367 /* USER CODE END */
\r
369 gioREG->INTENACLR = 1 << bit;
\r
373 /** @fn void gioHighLevelInterrupt(void)
\r
374 * @brief GIO Interrupt Handler
\r
376 * High Level Interrupt handler for GIO pin interrupt
\r
379 #pragma INTERRUPT(gioHighLevelInterrupt, IRQ)
\r
381 void gioHighLevelInterrupt(void)
\r
383 int offset = gioREG->OFFSET0 - 1U;
\r
385 /* USER CODE BEGIN (13) */
\r
386 /* USER CODE END */
\r
390 gioNotification(offset);
\r
393 /* USER CODE BEGIN (14) */
\r
394 /* USER CODE END */
\r
399 /** @fn void gioLowLevelInterrupt(void)
\r
400 * @brief GIO Interrupt Handler
\r
402 * Low Level Interrupt handler for GIO pin interrupt
\r
405 #pragma INTERRUPT(gioLowLevelInterrupt, IRQ)
\r
407 void gioLowLevelInterrupt(void)
\r
409 int offset = gioREG->OFFSET1 - 1U;
\r
411 /* USER CODE BEGIN (15) */
\r
412 /* USER CODE END */
\r
416 gioNotification(offset);
\r
419 /* USER CODE BEGIN (16) */
\r
420 /* USER CODE END */
\r