Digital Power Starter Kit 3 Firmware
dsPIC33C Buck 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 
45 volatile struct P33C_GPIO_INSTANCE_s* p33c_GpioInstance_GetHandle(volatile uint16_t gpioInstance)
46 {
47  volatile struct P33C_GPIO_INSTANCE_s* gpio;
48 
49  // Capture Handle: set pointer to memory address of desired GPIO instance
50  gpio = (volatile struct P33C_GPIO_INSTANCE_s*)
51  ((volatile uint8_t*) &ANSELA + (gpioInstance * P33C_GPIO_SFR_OFFSET));
52 
53  return(gpio);
54 }
55 
56 
77 volatile uint16_t p33c_GpioInstance_Dispose(volatile uint16_t gpioInstance)
78 {
79  volatile uint16_t retval=1;
80 
81  retval = p33c_GpioInstance_ConfigWrite(gpioInstance, gpioConfigClear);
82 
83  return(retval);
84 }
85 
86 
102 volatile struct P33C_GPIO_INSTANCE_s p33c_GpioInstance_ConfigRead(volatile uint16_t gpioInstance)
103 {
104  volatile struct P33C_GPIO_INSTANCE_s* gpio;
105 
106  // Set pointer to memory address of desired GPIO instance
107  gpio = (volatile struct P33C_GPIO_INSTANCE_s*)
108  ((volatile uint8_t*) &ANSELA + (gpioInstance * P33C_GPIO_SFR_OFFSET));
109 
110  return(*gpio);
111 
112 }
113 
114 
134  volatile uint16_t gpioInstance,
135  volatile struct P33C_GPIO_INSTANCE_s gpioConfig
136 )
137 {
138  volatile uint16_t retval=1;
139  volatile struct P33C_GPIO_INSTANCE_s* gpio;
140 
141  // Set pointer to memory address of desired GPIO instance
142  gpio = (volatile struct P33C_GPIO_INSTANCE_s*)
143  ((volatile uint8_t*) &ANSELA + (gpioInstance * P33C_GPIO_SFR_OFFSET));
144  *gpio = gpioConfig;
145 
146  return(retval);
147 
148 }
149 
150 
151 /* ============================================================================== */
152 /* ============================================================================== */
153 /* ============================================================================== */
154 
155 
169 volatile struct P33C_GPIO_INSTANCE_s gpioConfigClear = {
170 
171  .ANSELx.value = 0x0000, // Disable all analog functions
172  .CNCONx.value = 0x0000, // Reset all change notification configurations
173  .CNEN0x.value = 0x0000, // Disable all change notification functions
174  .CNEN1x.value = 0x0000, // Disable all change notification functions
175  .CNFx.value = 0x0000, // Clear all change notification interrupt flags
176  .CNPDx.value = 0x0000, // Disable all dull-down resistors
177  .CNPUx.value = 0x0000, // Disable all dull-up resistors
178  .CNSTATx.value = 0x0000, // Clear all change notification status notifications
179  .LATx.value = 0x0000, // Set all IOs of selected instance LOW
180  .ODCx.value = 0x0000, // Clear all open-drain configurations of instance
181  .PORTx.value = 0x0000, // CLear port registers of all IOs of instance
182  .TRISx.value = 0x1111, // Set all IOs of instance to INPUT
183 
184  };
185 
186 
187 // end of file
P33C_GPIO_INSTANCE_s::ANSELx
union P33C_GPIO_INSTANCE_s::@0 ANSELx
p33c_GpioInstance_Dispose
volatile uint16_t p33c_GpioInstance_Dispose(volatile uint16_t gpioInstance)
Resets all GPIO Instance registers to their RESET default values.
Definition: p33c_gpio.c:77
P33C_GPIO_INSTANCE_s::value
volatile uint16_t value
Definition: p33c_gpio.h:54
p33c_GpioInstance_ConfigWrite
volatile uint16_t p33c_GpioInstance_ConfigWrite(volatile uint16_t gpioInstance, volatile struct P33C_GPIO_INSTANCE_s gpioConfig)
Writes a user-defined configuration to the GPIO instance registers.
Definition: p33c_gpio.c:133
p33c_GpioInstance_GetHandle
volatile struct P33C_GPIO_INSTANCE_s * p33c_GpioInstance_GetHandle(volatile uint16_t gpioInstance)
Gets pointer to GPIO Instance SFR set.
Definition: p33c_gpio.c:45
gpioConfigClear
volatile struct P33C_GPIO_INSTANCE_s gpioConfigClear
Default RESET configuration of one GPIO instance SFRs.
Definition: p33c_gpio.c:169
P33C_GPIO_INSTANCE_s
Definition: p33c_gpio.h:51
p33c_GpioInstance_ConfigRead
volatile struct P33C_GPIO_INSTANCE_s p33c_GpioInstance_ConfigRead(volatile uint16_t gpioInstance)
Read the current configuration from the GPIO instance registers
Definition: p33c_gpio.c:102