| Digital Power Starter Kit 3 Firmware dsPIC33C Boost Converter Voltage Mode Control Example |

p33c_gpio.c
1 /* Microchip Technology Inc. and its subsidiaries. You may use this software
2 * and any derivatives exclusively with Microchip products.
3 *
4 * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
5 * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
6 * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
7 * PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
8 * WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
9 *
10 * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
11 * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
12 * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
13 * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
14 * FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS
15 * IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF
16 * ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
17 *
18 * MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
19 * TERMS.
20 */
21
22 // Include standard header files
23 #include <xc.h> // include processor files - each processor file is guarded.
24 #include <stdint.h> // include standard integer data types
25 #include <stdbool.h> // include standard boolean data types
26 #include <stddef.h> // include standard definition data types
27
28 #include "p33c_gpio.h"
29
30 #if defined (ANSELE)
31 volatile uint16_t* p33c_GpioInstance_Handles[5]={
32 &ANSELA, &ANSELB, &ANSELC, &ANSELD,
33 &ANSELE
34 };
35 #elif defined (ANSELD)
36 volatile uint16_t* p33c_GpioInstance_Handles[4]={
37 &ANSELA, &ANSELB, &ANSELC, &ANSELD
38 };
39 #elif defined (ANSELC)
40 volatile uint16_t* p33c_GpioInstance_Handles[3]={
41 &ANSELA, &ANSELB, &ANSELC
42 };
43 #elif defined (ANSELB)
44 volatile uint16_t* p33c_GpioInstance_Handles[2]={
45 &ANSELA, &ANSELB
46 };
47 #elif defined (ANSELA)
48 volatile uint16_t* p33c_GpioInstance_Handles[1]={
49 &ANSELA
50 };
51 #else
52 #pragma message "selected device has no supported ports"
53 #endif
54
55 /*********************************************************************************
56 * @fn uint16_t p33c_GpioInstance_Dispose(volatile uint16_t gpioInstance)
57 * @ingroup lib-layer-pral-functions-public-gpio
58 * @brief Resets all GPIO Instance registers to their RESET default values
59 * @param gpioInstance Index of the selected GPIO Instance (1=Port A, 2=Port B, etc.)
60 * @return 0 = failure, disposing GPIO instance was not successful
61 * @return 1 = success, disposing GPIO instance was successful
62 *
63 * @details
64 * This function clears all GPIO Instance registers to their
65 * default values set when the device comes out of RESET.
66 *
67 * Default configuration:
68 * - all outputs are set to logic functions
69 * - all analog functions are disabled
70 * - all pull-up and pull-down resistors are disabled
71 * - all GPIOs are operating in push-pull mode (open drain disabled)
72 * - all GPIOs are configured as input with their signal level HIGH
73 *
74 *********************************************************************************/
75
76 volatile uint16_t p33c_GpioInstance_Dispose(volatile uint16_t gpioInstance)
77 {
78 volatile uint16_t retval=1;
79
80 retval = p33c_GpioInstance_ConfigWrite(gpioInstance, gpioConfigClear);
81
82 return(retval);
83 }
84
85 /*********************************************************************************
86 * @fn struct P33C_GPIO_INSTANCE_s p33c_GpioInstance_ConfigRead(volatile uint16_t gpioInstance)
87 * @ingroup lib-layer-pral-functions-public-gpio
88 * @brief Read the current configuration from the GPIO instance registers
89 * @param gpioInstance Index of the selected GPIO Instance (1=Port A, 2=Port B, etc.)
90 * @return 0 = failure, reading GPIO instance was not successful (returns NULL)
91 * @return n = success, reading GPIO instance was successful (returns 16-bit wide pointer)
92 *
93 * @details
94 * This function reads all registers with their current configuration into
95 * a data structure of type P33C_GPIO_INSTANCE_s. Users can read and
96 * verify or modify the configuration to write it back to the GPIO instance
97 * registers or copy configurations to other instances of the same type.
98 *
99 * ********************************************************************************/
100
101 volatile struct P33C_GPIO_INSTANCE_s p33c_GpioInstance_ConfigRead(volatile uint16_t gpioInstance)
102 {
103 volatile struct P33C_GPIO_INSTANCE_s* gpio;
104
105 // Set pointer to memory address of desired GPIO instance
106 gpio = p33c_GpioInstance_GetHandle(gpioInstance);
107
108 return(*gpio);
109
110 }
111
112 /*********************************************************************************
113 * @fn uint16_t p33c_GpioInstance_ConfigWrite(volatile uint16_t gpioInstance,volatile struct P33C_GPIO_INSTANCE_s gpioConfig)
114 * @ingroup lib-layer-pral-functions-public-gpio
115 * @brief Writes a user-defined configuration to the GPIO instance registers
116 * @param gpioInstance Index of the selected GPIO Instance (1=Port A, 2=Port B, etc.)
117 * @param gpioConfig GPIO peripheral instance SFR object of type struct P33C_GPIO_INSTANCE_s
118 * @return 0 = failure, writing GPIO instance was not successful
119 * @return 1 = success, writing GPIO instance was successful
120 *
121 * @details
122 * This function writes a user-defined GPIO instance configuration of type
123 * P33C_GPIO_INSTANCE_s to the GPIO instance registers. The
124 * individual register configurations have to be set in user-code
125 * before calling this function. To simplify the configuration process
126 * of standard functions, this driver provides templates, which can be
127 * loaded and written directly.
128 *
129 *********************************************************************************/
130
131 volatile uint16_t p33c_GpioInstance_ConfigWrite(
132 volatile uint16_t gpioInstance,
133 volatile struct P33C_GPIO_INSTANCE_s gpioConfig
134 )
135 {
136 volatile uint16_t retval=1;
137 volatile struct P33C_GPIO_INSTANCE_s* gpio;
138
139 // Set pointer to memory address of desired GPIO instance
140 gpio = p33c_GpioInstance_GetHandle(gpioInstance);
141 *gpio = gpioConfig;
142
143 return(retval);
144
145 }
146
147
148 /* ============================================================================== */
149 /* ============================================================================== */
150 /* ============================================================================== */
151
152 /*********************************************************************************
153 * @var gpioConfigClear
154 * @ingroup lib-layer-pral-properties-private-gpio
155 * @brief Default RESET configuration of one GPIO instance SFRs
156 *
157 * @details
158 * Default configuration of the GPIO instance SFRs with all its registers
159 * being reset to their default state when the device comes out of RESET.
160 * Programmers can use this template to reset (dispose) a previously used
161 * GPIO instance when it's not used anymore or to secure a known startup
162 * condition before writing individual configurations to its SFRs.
163 *
164 ********************************************************************************/
165
166 volatile struct P33C_GPIO_INSTANCE_s gpioConfigClear = {
167
168 .ANSELx.value = 0x0000, // Disable all analog functions
169 .CNCONx.value = 0x0000, // Reset all change notification configurations
170 .CNEN0x.value = 0x0000, // Disable all change notification functions
171 .CNEN1x.value = 0x0000, // Disable all change notification functions
172 .CNFx.value = 0x0000, // Clear all change notification interrupt flags
173 .CNPDx.value = 0x0000, // Disable all dull-down resistors
174 .CNPUx.value = 0x0000, // Disable all dull-up resistors
175 .CNSTATx.value = 0x0000, // Clear all change notification status notifications
176 .LATx.value = 0x0000, // Set all IOs of selected instance LOW
177 .ODCx.value = 0x0000, // Clear all open-drain configurations of instance
178 .PORTx.value = 0x0000, // CLear port registers of all IOs of instance
179 .TRISx.value = 0x1111, // Set all IOs of instance to INPUT
180
181 };
182
183
184 // Device pin declarations
185 // Port A
186 #if defined (_TRISA0)
187 volatile struct GPIO_PORT_PIN_s PIN_RA0 = { .port=0, .pin=0, .rpid=0 };
188 #endif
189 #if defined (_TRISA1)
190 volatile struct GPIO_PORT_PIN_s PIN_RA1 = { .port=0, .pin=1, .rpid=0 };
191 #endif
192 #if defined (_TRISA2)
193 volatile struct GPIO_PORT_PIN_s PIN_RA2 = { .port=0, .pin=2, .rpid=0 };
194 #endif
195 #if defined (_TRISA3)
196 volatile struct GPIO_PORT_PIN_s PIN_RA3 = { .port=0, .pin=3, .rpid=0 };
197 #endif
198 #if defined (_TRISA4)
199 volatile struct GPIO_PORT_PIN_s PIN_RA4 = { .port=0, .pin=3, .rpid=0 };
200 #endif
201 #if defined (_TRISA5)
202 volatile struct GPIO_PORT_PIN_s PIN_RA5 = { .port=0, .pin=5, .rpid=0 };
203 #endif
204 #if defined (_TRISA6)
205 volatile struct GPIO_PORT_PIN_s PIN_RA6 = { .port=0, .pin=6, .rpid=0 };
206 #endif
207 #if defined (_TRISA7)
208 volatile struct GPIO_PORT_PIN_s PIN_RA7 = { .port=0, .pin=7, .rpid=0 };
209 #endif
210 #if defined (_TRISA8)
211 volatile struct GPIO_PORT_PIN_s PIN_RA8 = { .port=0, .pin=8, .rpid=0 };
212 #endif
213 #if defined (_TRISA9)
214 volatile struct GPIO_PORT_PIN_s PIN_RA9 = { .port=0, .pin=9, .rpid=0 };
215 #endif
216 #if defined (_TRISA10)
217 volatile struct GPIO_PORT_PIN_s PIN_RA10 = { .port=0, .pin=10, .rpid=0 };
218 #endif
219 #if defined (_TRISA12)
220 volatile struct GPIO_PORT_PIN_s PIN_RA11 = { .port=0, .pin=11, .rpid=0 };
221 #endif
222 #if defined (_TRISA12)
223 volatile struct GPIO_PORT_PIN_s PIN_RA12 = { .port=0, .pin=12, .rpid=0 };
224 #endif
225 #if defined (_TRISA13)
226 volatile struct GPIO_PORT_PIN_s PIN_RA13 = { .port=0, .pin=13, .rpid=0 };
227 #endif
228 #if defined (_TRISA14)
229 volatile struct GPIO_PORT_PIN_s PIN_RA14 = { .port=0, .pin=14, .rpid=0 };
230 #endif
231 #if defined (_TRISA15)
232 volatile struct GPIO_PORT_PIN_s PIN_RA15 = { .port=0, .pin=15, .rpid=0 };
233 #endif
234
235 // Port B
236 #if defined (_TRISB0)
237 volatile struct GPIO_PORT_PIN_s PIN_RB0 = { .port=1, .pin=0, .rpid=32 };
238 #endif
239 #if defined (_TRISB1)
240 volatile struct GPIO_PORT_PIN_s PIN_RB1 = { .port=1, .pin=1, .rpid=33 };
241 #endif
242 #if defined (_TRISB2)
243 volatile struct GPIO_PORT_PIN_s PIN_RB2 = { .port=1, .pin=2, .rpid=34 };
244 #endif
245 #if defined (_TRISB3)
246 volatile struct GPIO_PORT_PIN_s PIN_RB3 = { .port=1, .pin=3, .rpid=35 };
247 #endif
248 #if defined (_TRISB4)
249 volatile struct GPIO_PORT_PIN_s PIN_RB4 = { .port=1, .pin=4, .rpid=36 };
250 #endif
251 #if defined (_TRISB5)
252 volatile struct GPIO_PORT_PIN_s PIN_RB5 = { .port=1, .pin=5, .rpid=37 };
253 #endif
254 #if defined (_TRISB6)
255 volatile struct GPIO_PORT_PIN_s PIN_RB6 = { .port=1, .pin=6, .rpid=38 };
256 #endif
257 #if defined (_TRISB7)
258 volatile struct GPIO_PORT_PIN_s PIN_RB7 = { .port=1, .pin=7, .rpid=39 };
259 #endif
260 #if defined (_TRISB8)
261 volatile struct GPIO_PORT_PIN_s PIN_RB8 = { .port=1, .pin=8, .rpid=40 };
262 #endif
263 #if defined (_TRISB9)
264 volatile struct GPIO_PORT_PIN_s PIN_RB9 = { .port=1, .pin=9, .rpid=41 };
265 #endif
266 #if defined (_TRISB10)
267 volatile struct GPIO_PORT_PIN_s PIN_RB10 = { .port=1, .pin=10, .rpid=42 };
268 #endif
269 #if defined (_TRISB11)
270 volatile struct GPIO_PORT_PIN_s PIN_RB11 = { .port=1, .pin=11, .rpid=43 };
271 #endif
272 #if defined (_TRISB12)
273 volatile struct GPIO_PORT_PIN_s PIN_RB12 = { .port=1, .pin=12, .rpid=44 };
274 #endif
275 #if defined (_TRISB13)
276 volatile struct GPIO_PORT_PIN_s PIN_RB13 = { .port=1, .pin=13, .rpid=45 };
277 #endif
278 #if defined (_TRISB14)
279 volatile struct GPIO_PORT_PIN_s PIN_RB14 = { .port=1, .pin=14, .rpid=46 };
280 #endif
281 #if defined (_TRISB15)
282 volatile struct GPIO_PORT_PIN_s PIN_RB15 = { .port=1, .pin=15, .rpid=47 };
283 #endif
284
285 // Port C
286 #if defined (_TRISC0)
287 volatile struct GPIO_PORT_PIN_s PIN_RC0 = { .port=2, .pin=0, .rpid=48 };
288 #endif
289 #if defined (_TRISC1)
290 volatile struct GPIO_PORT_PIN_s PIN_RC1 = { .port=2, .pin=1, .rpid=49 };
291 #endif
292 #if defined (_TRISC2)
293 volatile struct GPIO_PORT_PIN_s PIN_RC2 = { .port=2, .pin=2, .rpid=50 };
294 #endif
295 #if defined (_TRISC3)
296 volatile struct GPIO_PORT_PIN_s PIN_RC3 = { .port=2, .pin=3, .rpid=51 };
297 #endif
298 #if defined (_TRISC4)
299 volatile struct GPIO_PORT_PIN_s PIN_RC4 = { .port=2, .pin=4, .rpid=52 };
300 #endif
301 #if defined (_TRISC5)
302 volatile struct GPIO_PORT_PIN_s PIN_RC5 = { .port=2, .pin=5, .rpid=53 };
303 #endif
304 #if defined (_TRISC6)
305 volatile struct GPIO_PORT_PIN_s PIN_RC6 = { .port=2, .pin=6, .rpid=54 };
306 #endif
307 #if defined (_TRISC7)
308 volatile struct GPIO_PORT_PIN_s PIN_RC7 = { .port=2, .pin=7, .rpid=55 };
309 #endif
310 #if defined (_TRISC8)
311 volatile struct GPIO_PORT_PIN_s PIN_RC8 = { .port=2, .pin=8, .rpid=56 };
312 #endif
313 #if defined (_TRISC9)
314 volatile struct GPIO_PORT_PIN_s PIN_RC9 = { .port=2, .pin=9, .rpid=57 };
315 #endif
316 #if defined (_TRISC10)
317 volatile struct GPIO_PORT_PIN_s PIN_RC10 = { .port=2, .pin=10, .rpid=58 };
318 #endif
319 #if defined (_TRISC11)
320 volatile struct GPIO_PORT_PIN_s PIN_RC11 = { .port=2, .pin=11, .rpid=59 };
321 #endif
322 #if defined (_TRISC12)
323 volatile struct GPIO_PORT_PIN_s PIN_RC12 = { .port=2, .pin=12, .rpid=60 };
324 #endif
325 #if defined (_TRISC13)
326 volatile struct GPIO_PORT_PIN_s PIN_RC13 = { .port=2, .pin=13, .rpid=61 };
327 #endif
328 #if defined (_TRISC14)
329 volatile struct GPIO_PORT_PIN_s PIN_RC14 = { .port=2, .pin=14, .rpid=62 };
330 #endif
331 #if defined (_TRISC15)
332 volatile struct GPIO_PORT_PIN_s PIN_RC15 = { .port=2, .pin=15, .rpid=63 };
333 #endif
334
335 // Port D
336 #if defined (_TRISD0)
337 volatile struct GPIO_PORT_PIN_s PIN_RD0 = { .port=3, .pin=0, .rpid=64 };
338 #endif
339 #if defined (_TRISD1)
340 volatile struct GPIO_PORT_PIN_s PIN_RD1 = { .port=3, .pin=1, .rpid=65 };
341 #endif
342 #if defined (_TRISD2)
343 volatile struct GPIO_PORT_PIN_s PIN_RD2 = { .port=3, .pin=2, .rpid=66 };
344 #endif
345 #if defined (_TRISD3)
346 volatile struct GPIO_PORT_PIN_s PIN_RD3 = { .port=3, .pin=3, .rpid=67 };
347 #endif
348 #if defined (_TRISD4)
349 volatile struct GPIO_PORT_PIN_s PIN_RD4 = { .port=3, .pin=4, .rpid=68 };
350 #endif
351 #if defined (_TRISD5)
352 volatile struct GPIO_PORT_PIN_s PIN_RD5 = { .port=3, .pin=5, .rpid=69 };
353 #endif
354 #if defined (_TRISD6)
355 volatile struct GPIO_PORT_PIN_s PIN_RD6 = { .port=3, .pin=6, .rpid=70 };
356 #endif
357 #if defined (_TRISD7)
358 volatile struct GPIO_PORT_PIN_s PIN_RD7 = { .port=3, .pin=7, .rpid=71 };
359 #endif
360 #if defined (_TRISD8)
361 volatile struct GPIO_PORT_PIN_s PIN_RD8 = { .port=3, .pin=8, .rpid=72 };
362 #endif
363 #if defined (_TRISD9)
364 volatile struct GPIO_PORT_PIN_s PIN_RD9 = { .port=3, .pin=9, .rpid=73 };
365 #endif
366 #if defined (_TRISD10)
367 volatile struct GPIO_PORT_PIN_s PIN_RD10 = { .port=3, .pin=10, .rpid=74 };
368 #endif
369 #if defined (_TRISD11)
370 volatile struct GPIO_PORT_PIN_s PIN_RD11 = { .port=3, .pin=11, .rpid=75 };
371 #endif
372 #if defined (_TRISD12)
373 volatile struct GPIO_PORT_PIN_s PIN_RD12 = { .port=3, .pin=12, .rpid=76 };
374 #endif
375 #if defined (_TRISD13)
376 volatile struct GPIO_PORT_PIN_s PIN_RD13 = { .port=3, .pin=13, .rpid=77 };
377 #endif
378 #if defined (_TRISD14)
379 volatile struct GPIO_PORT_PIN_s PIN_RD14 = { .port=3, .pin=14, .rpid=78 };
380 #endif
381 #if defined (_TRISD15)
382 volatile struct GPIO_PORT_PIN_s PIN_RD15 = { .port=3, .pin=15, .rpid=79 };
383 #endif
384
385 // Port E
386 #if defined (_TRISE0)
387 volatile struct GPIO_PORT_PIN_s PIN_RE0 = { .port=4, .pin=0, .rpid=0 };
388 #endif
389 #if defined (_TRISE1)
390 volatile struct GPIO_PORT_PIN_s PIN_RE1 = { .port=4, .pin=1, .rpid=0 };
391 #endif
392 #if defined (_TRISE2)
393 volatile struct GPIO_PORT_PIN_s PIN_RE2 = { .port=4, .pin=2, .rpid=0 };
394 #endif
395 #if defined (_TRISE3)
396 volatile struct GPIO_PORT_PIN_s PIN_RE3 = { .port=4, .pin=3, .rpid=0 };
397 #endif
398 #if defined (_TRISE4)
399 volatile struct GPIO_PORT_PIN_s PIN_RE4 = { .port=4, .pin=4, .rpid=0 };
400 #endif
401 #if defined (_TRISE5)
402 volatile struct GPIO_PORT_PIN_s PIN_RE5 = { .port=4, .pin=5, .rpid=0 };
403 #endif
404 #if defined (_TRISE6)
405 volatile struct GPIO_PORT_PIN_s PIN_RE6 = { .port=4, .pin=6, .rpid=0 };
406 #endif
407 #if defined (_TRISE7)
408 volatile struct GPIO_PORT_PIN_s PIN_RE7 = { .port=4, .pin=7, .rpid=0 };
409 #endif
410 #if defined (_TRISE8)
411 volatile struct GPIO_PORT_PIN_s PIN_RE8 = { .port=4, .pin=8, .rpid=0 };
412 #endif
413 #if defined (_TRISE9)
414 volatile struct GPIO_PORT_PIN_s PIN_RE9 = { .port=4, .pin=9, .rpid=0 };
415 #endif
416 #if defined (_TRISE10)
417 volatile struct GPIO_PORT_PIN_s PIN_RE10 = { .port=4, .pin=10, .rpid=0 };
418 #endif
419 #if defined (_TRISE11)
420 volatile struct GPIO_PORT_PIN_s PIN_RE11 = { .port=4, .pin=11, .rpid=0 };
421 #endif
422 #if defined (_TRISE12)
423 volatile struct GPIO_PORT_PIN_s PIN_RE12 = { .port=4, .pin=12, .rpid=0 };
424 #endif
425 #if defined (_TRISE13)
426 volatile struct GPIO_PORT_PIN_s PIN_RE13 = { .port=4, .pin=13, .rpid=0 };
427 #endif
428 #if defined (_TRISE14)
429 volatile struct GPIO_PORT_PIN_s PIN_RE14 = { .port=4, .pin=14, .rpid=0 };
430 #endif
431 #if defined (_TRISE15)
432 volatile struct GPIO_PORT_PIN_s PIN_RE15 = { .port=4, .pin=15, .rpid=0 };
433 #endif
434
435 // end of file
P33C_GPIO_INSTANCE_s::value
volatile uint16_t value
Definition: p33c_gpio.h:274
GPIO_PORT_PIN_s::port
volatile uint16_t port
Definition: p33c_gpio.h:367
P33C_GPIO_INSTANCE_s::ANSELx
union P33C_GPIO_INSTANCE_s::@123 ANSELx
GPIO_PORT_PIN_s
Definition: p33c_gpio.h:366
P33C_GPIO_INSTANCE_s
Definition: p33c_gpio.h:271