]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_R4_RM48_TMS570_CCS5/Library/gio.c
commit 9f316c246baafa15c542a5aea81a94f26e3d6507
[freertos] / FreeRTOS / Demo / CORTEX_R4_RM48_TMS570_CCS5 / Library / gio.c
1 /** @file gio.c \r
2 *   @brief GIO Driver Inmplmentation File\r
3 *   @date 10.June.2010\r
4 *   @version 1.01.000\r
5 *\r
6 */\r
7 \r
8 /* (c) Texas Instruments 2009-2010, All rights reserved. */\r
9 \r
10 \r
11 #include "gio.h"\r
12 \r
13 \r
14 /** @fn void gioInit(void)\r
15 *   @brief Initializes the GIO Driver\r
16 *\r
17 *   This function initializes the GIO module and set the GIO ports \r
18 *   to the inital values.\r
19 */\r
20 void gioInit(void)\r
21 {\r
22     /** bring GIO module out of reset */\r
23     gioREG->GCR0      = 1;\r
24     gioREG->INTENACLR = 0xFF;\r
25     gioREG->LVLCLR    = 0xFF;              \r
26 \r
27     /** @b initalise @b Port @b A */\r
28 \r
29     /** - Port A output values */\r
30     gioPORTA->DOUT =  0        /* Bit 0 */\r
31                    | (0 << 1)  /* Bit 1 */\r
32                    | (0 << 2)  /* Bit 2 */\r
33                    | (0 << 3)  /* Bit 3 */\r
34                    | (0 << 4)  /* Bit 4 */\r
35                    | (0 << 5)  /* Bit 5 */\r
36                    | (0 << 6)  /* Bit 6 */\r
37                    | (0 << 7); /* Bit 7 */\r
38 \r
39     /** - Port A direction */\r
40     gioPORTA->DIR  =  1        /* Bit 0 */\r
41                    | (1 << 1)  /* Bit 1 */\r
42                    | (0 << 2)  /* Bit 2 */\r
43                    | (0 << 3)  /* Bit 3 */\r
44                    | (0 << 4)  /* Bit 4 */\r
45                    | (0 << 5)  /* Bit 5 */\r
46                    | (0 << 6)  /* Bit 6 */\r
47                    | (0 << 7); /* Bit 7 */\r
48 \r
49     /** - Port A open drain enable */\r
50     gioPORTA->PDR  =  0        /* Bit 0 */\r
51                    | (0 << 1)  /* Bit 1 */\r
52                    | (0 << 2)  /* Bit 2 */\r
53                    | (0 << 3)  /* Bit 3 */\r
54                    | (0 << 4)  /* Bit 4 */\r
55                    | (0 << 5)  /* Bit 5 */\r
56                    | (0 << 6)  /* Bit 6 */\r
57                    | (0 << 7); /* Bit 7 */\r
58 \r
59     /** - Port A pullup / pulldown selection */\r
60     gioPORTA->PSL  =  0        /* Bit 0 */\r
61                    | (0 << 1)  /* Bit 1 */\r
62                    | (0 << 2)  /* Bit 2 */\r
63                    | (0 << 3)  /* Bit 3 */\r
64                    | (0 << 4)  /* Bit 4 */\r
65                    | (0 << 5)  /* Bit 5 */\r
66                    | (0 << 6)  /* Bit 6 */\r
67                    | (0 << 7); /* Bit 7 */\r
68 \r
69     /** - Port A pullup / pulldown enable*/\r
70     gioPORTA->PULDIS  =  0        /* Bit 0 */\r
71                       | (0 << 1)  /* Bit 1 */\r
72                       | (0 << 2)  /* Bit 2 */\r
73                       | (0 << 3)  /* Bit 3 */\r
74                       | (0 << 4)  /* Bit 4 */\r
75                       | (0 << 5)  /* Bit 5 */\r
76                       | (0 << 6)  /* Bit 6 */\r
77                       | (0 << 7); /* Bit 7 */\r
78 \r
79     /** @b initalise @b Port @b B */\r
80 \r
81     /** - Port B output values */\r
82     gioPORTB->DOUT =  0        /* Bit 0 */\r
83                    | (0 << 1)  /* Bit 1 */\r
84                    | (0 << 2)  /* Bit 2 */\r
85                    | (0 << 3)  /* Bit 3 */\r
86                    | (0 << 4)  /* Bit 4 */\r
87                    | (0 << 5)  /* Bit 5 */\r
88                    | (0 << 6)  /* Bit 6 */\r
89                    | (0 << 7); /* Bit 7 */\r
90 \r
91     /** - Port B direction */\r
92     gioPORTB->DIR  =  0        /* Bit 0 */\r
93                    | (0 << 1)  /* Bit 1 */\r
94                    | (0 << 2)  /* Bit 2 */\r
95                    | (0 << 3)  /* Bit 3 */\r
96                    | (0 << 4)  /* Bit 4 */\r
97                    | (0 << 5)  /* Bit 5 */\r
98                    | (0 << 6)  /* Bit 6 */\r
99                    | (0 << 7); /* Bit 7 */\r
100 \r
101     /** - Port B open drain enable */\r
102     gioPORTB->PDR  =  0        /* Bit 0 */\r
103                    | (0 << 1)  /* Bit 1 */\r
104                    | (0 << 2)  /* Bit 2 */\r
105                    | (0 << 3)  /* Bit 3 */\r
106                    | (0 << 4)  /* Bit 4 */\r
107                    | (0 << 5)  /* Bit 5 */\r
108                    | (0 << 6)  /* Bit 6 */\r
109                    | (0 << 7); /* Bit 7 */\r
110 \r
111     /** - Port B pullup / pulldown selection */\r
112     gioPORTB->PSL  =  0        /* Bit 0 */\r
113                    | (0 << 1)  /* Bit 1 */\r
114                    | (0 << 2)  /* Bit 2 */\r
115                    | (0 << 3)  /* Bit 3 */\r
116                    | (0 << 4)  /* Bit 4 */\r
117                    | (0 << 5)  /* Bit 5 */\r
118                    | (0 << 6)  /* Bit 6 */\r
119                    | (0 << 7); /* Bit 7 */\r
120 \r
121     /** - Port B pullup / pulldown enable*/\r
122     gioPORTB->PULDIS  =  0        /* Bit 0 */\r
123                       | (0 << 1)  /* Bit 1 */\r
124                       | (0 << 2)  /* Bit 2 */\r
125                       | (0 << 3)  /* Bit 3 */\r
126                       | (0 << 4)  /* Bit 4 */\r
127                       | (0 << 5)  /* Bit 5 */\r
128                       | (0 << 6)  /* Bit 6 */\r
129                       | (0 << 7); /* Bit 7 */\r
130 \r
131 \r
132     /** @b initalise @b interrupts */\r
133 \r
134     /** - interrupt polarity */\r
135     gioREG->POL =  0        /* Bit 0 */\r
136                 | (0 << 1)  /* Bit 1 */\r
137                 | (0 << 2)  /* Bit 2 */\r
138                 | (0 << 3)  /* Bit 3 */\r
139                 | (0 << 4)  /* Bit 4 */\r
140                 | (0 << 5)  /* Bit 5 */\r
141                 | (0 << 6)  /* Bit 6 */\r
142                 | (0 << 7); /* Bit 7 */\r
143 \r
144     /** - interrupt level */\r
145     gioREG->LVLSET =  0        /* Bit 0 */\r
146                    | (0 << 1)  /* Bit 1 */\r
147                    | (0 << 2)  /* Bit 2 */\r
148                    | (0 << 3)  /* Bit 3 */\r
149                    | (0 << 4)  /* Bit 4 */\r
150                    | (0 << 5)  /* Bit 5 */\r
151                    | (0 << 6)  /* Bit 6 */\r
152                    | (0 << 7); /* Bit 7 */\r
153 \r
154 \r
155     /** - clear all pending interrupts */\r
156     gioREG->FLG = 0xFF;\r
157 \r
158     /** - enable interrupts */\r
159     gioREG->INTENASET =  0        /* Bit 0 */\r
160                       | (0 << 1)  /* Bit 1 */\r
161                       | (0 << 2)  /* Bit 2 */\r
162                       | (0 << 3)  /* Bit 3 */\r
163                       | (0 << 4)  /* Bit 4 */\r
164                       | (0 << 5)  /* Bit 5 */\r
165                       | (0 << 6)  /* Bit 6 */\r
166                       | (0 << 7); /* Bit 7 */\r
167 }\r
168 \r
169 \r
170 /** @fn void gioSetDirection(gioPORT_t *port, unsigned dir)\r
171 *   @brief Set Port Direction\r
172 *   @param[in] port pointer to GIO port:\r
173 *              - gioPORTA: PortA pointer\r
174 *              - gioPORTB: PortB pointer\r
175 *   @param[in] dir value to write to DIR register\r
176 *\r
177 *   Set the direction of GIO pins at runtime.\r
178 */\r
179 void gioSetDirection(gioPORT_t *port, unsigned dir)\r
180 {\r
181     port->DIR = dir;\r
182 }\r
183 \r
184 \r
185 /** @fn void gioSetBit(gioPORT_t *port, unsigned bit, unsigned value)\r
186 *   @brief Write Bit\r
187 *   @param[in] port pointer to GIO port:\r
188 *              - gioPORTA: PortA pointer\r
189 *              - gioPORTB: PortB pointer\r
190 *   @param[in] bit number 0-7 that specifies the bit to be written to.\r
191 *              - 0: LSB\r
192 *              - 7: MSB\r
193 *   @param[in] value binrary value to write to bit\r
194 *\r
195 *   Writes a value to the specified pin of the given GIO port\r
196 */\r
197 void gioSetBit(gioPORT_t *port, unsigned bit, unsigned value)\r
198 {\r
199     if (value)\r
200     {\r
201         port->DSET = 1 << bit;\r
202     }\r
203     else\r
204     {\r
205         port->DCLR = 1 << bit;\r
206     }\r
207 }\r
208 \r
209 \r
210 /** @fn void gioSetPort(gioPORT_t *port, unsigned value)\r
211 *   @brief Write Port Value\r
212 *   @param[in] port pointer to GIO port:\r
213 *              - gioPORTA: PortA pointer\r
214 *              - gioPORTB: PortB pointer\r
215 *   @param[in] value value to write to port\r
216 *\r
217 *   Writes a value to all pin of a given GIO port\r
218 */\r
219 void gioSetPort(gioPORT_t *port, unsigned value)\r
220 {\r
221     port->DOUT = value;\r
222 }\r
223 \r
224 \r
225 /** @fn unsigned gioGetBit(gioPORT_t *port, unsigned bit)\r
226 *   @brief Read Bit\r
227 *   @param[in] port pointer to GIO port:\r
228 *              - gioPORTA: PortA pointer\r
229 *              - gioPORTB: PortB pointer\r
230 *   @param[in] bit number 0-7 that specifies the bit to be written to.\r
231 *              - 0: LSB\r
232 *              - 7: MSB\r
233 *\r
234 *   Reads a the current value from the specified pin of the given GIO port\r
235 */\r
236 unsigned gioGetBit(gioPORT_t *port, unsigned bit)\r
237 {\r
238     return (port->DIN >> bit) & 1U;\r
239 }\r
240 \r
241 \r
242 /** @fn unsigned gioGetPort(gioPORT_t *port)\r
243 *   @brief Read Port Value\r
244 *   @param[in] port pointer to GIO port:\r
245 *              - gioPORTA: PortA pointer\r
246 *              - gioPORTB: PortB pointer\r
247 *\r
248 *   Reads a the current value of a given GIO port\r
249 */\r
250 unsigned gioGetPort(gioPORT_t *port)\r
251 {\r
252     return port->DIN;\r
253 }\r
254 \r
255 \r
256 /** @fn void gioEnableNotification(unsigned bit)\r
257 *   @brief Enable Interrupt\r
258 *   @param[in] bit interrupt pin to enable\r
259 *              - 0: LSB\r
260 *              - 7: MSB\r
261 *\r
262 *   Enables an innterrupt pin of PortA\r
263 */\r
264 void gioEnableNotification(unsigned bit)\r
265 {\r
266     gioREG->INTENASET = 1 << bit;\r
267 }\r
268 \r
269 \r
270 /** @fn void gioDisableNotification(unsigned bit)\r
271 *   @brief Disable Interrupt\r
272 *   @param[in] bit interrupt pin to enable\r
273 *              - 0: LSB\r
274 *              - 7: MSB\r
275 *\r
276 *   Disables an innterrupt pin of PortA\r
277 */\r
278 void gioDisableNotification(unsigned bit)\r
279 {\r
280     gioREG->INTENACLR = 1 << bit;\r
281 }\r