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

p33c_ccp.h
1 /*************************************************************************************************
2 * @file p33c_ccp.h
3 * @author I62419
4 * @date Created on October 12, 2020, 5:41 PM
5 ************************************************************************************************/
6
7 /*************************************************************************************************
8 * @brief Generic Capture Compare Driver Module (header file)
9 * @details
10 * This additional header file contains defines for all required bit-settings of all related
11 * special function registers of a peripheral module and/or instance.
12 * This file is an additional header file on top of the generic device header file.
13 ************************************************************************************************/
14
15 #ifndef P33C_CCP_SFR_ABSTRACTION_H
16 #define P33C_CCP_SFR_ABSTRACTION_H
17
18 #include <xc.h> // include processor files - each processor file is guarded.
19 #include <stdint.h> // include standard integer data types
20 #include <stdbool.h> // include standard boolean data types
21 #include <stddef.h> // include standard definition data types
22
23
24 #ifndef P33C_CCP_INSTANCE_s
25
26 /***********************************************************************************
27 * @ingroup lib-layer-pral-properties-public-ccp
28 * @struct P33C_CCP_INSTANCE_SFRSET_s
29 * @brief Abstracted set of Special Function Registers of a Capture Compare peripheral instance
30 * @details
31 * This structure defines an abstracted set of Special Function Registers of a
32 * Input Capture/Output Compare peripheral instance. Users can use this abstracted
33 * set of registers to capture register settings from or write generic register
34 * settings to a specific instance of this peripheral.
35 *
36 **********************************************************************************/
37
38 struct P33C_CCP_INSTANCE_s {
39
40 union {
41 struct tagCCP1CON1LBITS bits; // Register bit-field
42 uint16_t value; // 16-bit wide register value
43 } CCPxCON1L; // CCPxCON1L: CCPx CONTROL 1 LOW REGISTERS
44
45 union {
46 struct tagCCP1CON1HBITS bits; // Register bit-field
47 uint16_t value; // 16-bit wide register value
48 } CCPxCON1H; // CCPxCON1H: CCPx CONTROL 1 HIGH REGISTERS
49
50 union {
51 struct tagCCP1CON2LBITS bits; // Register bit-field
52 uint16_t value; // 16-bit wide register value
53 } CCPxCON2L; // CCPxCON2L: CCPx CONTROL 2 LOW REGISTERS
54
55 union {
56 struct tagCCP1CON2HBITS bits; // Register bit-field
57 uint16_t value; // 16-bit wide register value
58 } CCPxCON2H; // CCPxCON2H: CCPx CONTROL 2 HIGH REGISTERS
59
60 #if defined (CCP9CON3L)
61 union {
62 struct tagCCP9CON3LBITS bits; // Register bit-field
63 uint16_t value; // 16-bit wide register value
64 } CCPxCON3L; // CCPxCON3L: CCPx CONTROL 3 LOW REGISTERS (implemented in MCCP9 module only)
65 #else
66 volatile unsigned :16; // (reserved) Memory gap between CCPxCON2H and CCPxCON3H
67 #endif
68
69 union {
70 struct tagCCP1CON3HBITS bits; // Register bit-field
71 uint16_t value; // 16-bit wide register value
72 } CCPxCON3H; // CCPxCON3H: CCPx CONTROL 3 HIGH REGISTERS
73
74 union {
75 struct tagCCP1STATLBITS bits; // Register bit-field
76 uint16_t value; // 16-bit wide register value
77 } CCPxSTATL; // CCPxSTATL: CCPx STATUS REGISTER
78
79 volatile unsigned :16; // (reserved)
80
81 union {
82 struct {
83 volatile uint16_t CCPTMRL : 16; // Register bit-field
84 } bits; // Register bit-field
85 uint16_t value; // 16-bit wide register value
86 } CCPxTMRL; // CCPxTMRL: CCPx TIMER COUTER REGISTER LOW
87
88 union {
89 struct {
90 volatile uint16_t CCPTMRH : 16; // Register bit-field
91 } bits; // Register bit-field
92 uint16_t value; // 16-bit wide register value
93 } CCPxTMRH; // CCPxTMRH: CCPx TIMER COUTER REGISTER HIGH
94
95 union {
96 struct {
97 volatile uint16_t CCPPRL : 16; // Register bit-field
98 } bits; // Register bit-field
99 uint16_t value; // 16-bit wide register value
100 } CCPxPRL; // CCPx TIMER PERIOD REGISTER LOW
101
102 union {
103 struct {
104 volatile uint16_t CCPPRH : 16; // Register bit-field
105 } bits; // Register bit-field
106 uint16_t value; // 16-bit wide register value
107 } CCPxPRH; // CCPx TIMER PERIOD REGISTER HIGH
108
109 union {
110 struct {
111 volatile uint16_t CCPRAL : 16; // Register bit-field
112 } bits; // Register bit-field
113 uint16_t value; // 16-bit wide register value
114 } CCPxRAL; // CCPxRAL: CCPx PRIMARY OUTPUT COMPARE DATA BUFFER LOW
115
116 volatile unsigned :16;
117
118 union {
119 struct {
120 volatile uint16_t CCPRBL : 16; // Register bit-field
121 } bits; // Register bit-field
122 uint16_t value; // 16-bit wide register value
123 } CCPxRBL; // CCPxRBL: CCPx SECONDARY OUTPUT COMPARE DATA BUFFER LOW
124
125 volatile unsigned :16;
126
127 union {
128 struct {
129 volatile uint16_t CCPBUFL : 16; // Register bit-field
130 } bits; // Register bit-field
131 uint16_t value; // 16-bit wide register value
132 } CCPxBUFL; // CCPxBUFL: CCPx INPUT CAPTURE BUFFER LOW
133
134 union {
135 struct {
136 volatile uint16_t CCPBUFH : 16; // Register bit-field
137 } bits; // Register bit-field
138 uint16_t value; // 16-bit wide register value
139 } CCPxBUFH; // CCPxBUFH: CCPx INPUT CAPTURE BUFFER HIGH
140
141 } __attribute__((packed));
142
143 typedef struct P33C_CCP_INSTANCE_s P33C_CCP_INSTANCE_t;
144
145 /*********************************************************************************
146 * @ingroup lib-layer-pral-properties-public-ccp
147 * @def P33C_CCP_SFR_OFFSET
148 * @brief Derives the address offset between two peripheral instances
149 * @details
150 * This macro derives the address offset between two peripheral instances.
151 * Users can use this address offset to derive the start address to/from which
152 * the register set should be written or read.
153 **********************************************************************************/
154 #define P33C_CCP_SFR_OFFSET ((volatile uint16_t)&CCP2CON1L - (volatile uint16_t)&CCP1CON1L)
155
156 // Determine number of available PWM generators on the selected device
157 #if defined (CCP9CON1L)
158 // Array of pointers to first registers of DAC instances on this device
159 #define P33C_DAC_COUNT 9
160 #define DAC_INSTANCE_COUNT 9
161 #elif defined (CCP8CON1L)
162 // Array of pointers to first registers of DAC instances on this device
163 #define P33C_DAC_COUNT 8
164 #define DAC_INSTANCE_COUNT 8
165 #elif defined (CCP7CON1L)
166 // Array of pointers to first registers of DAC instances on this device
167 #define P33C_DAC_COUNT 7
168 #define DAC_INSTANCE_COUNT 7
169 #elif defined (CCP6CON1L)
170 // Array of pointers to first registers of DAC instances on this device
171 #define P33C_DAC_COUNT 6
172 #define DAC_INSTANCE_COUNT 6
173 #elif defined (CCP5CON1L)
174 // Array of pointers to first registers of DAC instances on this device
175 #define P33C_DAC_COUNT 5
176 #define DAC_INSTANCE_COUNT 5
177 #elif defined (CCP4CON1L)
178 // Array of pointers to first registers of DAC instances on this device
179 #define P33C_DAC_COUNT 4
180 #define DAC_INSTANCE_COUNT 4
181 #elif defined (CCP3CON1L)
182 // Array of pointers to first registers of DAC instances on this device
183 #define P33C_DAC_COUNT 3
184 #define DAC_INSTANCE_COUNT 3
185 #elif defined (CCP2CON1L)
186 // Array of pointers to first registers of DAC instances on this device
187 #define P33C_DAC_COUNT 2
188 #define DAC_INSTANCE_COUNT 2
189 #elif defined (CCP1CON1L)
190 // Array of pointers to first registers of DAC instances on this device
191 #define P33C_DAC_COUNT 1
192 #define DAC_INSTANCE_COUNT 1
193 #endif
194
195
196 /*********************************************************************************
197 * @def p33c_CcpInstance_GetHandle(x)
198 * @ingroup lib-layer-pral-functions-public-ccp
199 * @brief Gets pointer to CCP instance SFR set
200 * @param x Index of the Capture/Compare peripheral instance of type unsigned integer
201 * @return Pointer to SCCP/MCCP instance special function register data object of type struct P33C_CCP_INSTANCE_s
202 *
203 * @details
204 * This macro returns the pointer to a CCP module register set
205 * Special Function Register memory space. This pointer can be used to
206 * directly write to/read from the Special Function Registers of the
207 * CCP peripheral module configuration.
208 *
209 *********************************************************************************/
210 extern volatile uint16_t* p33c_CcpInstance_Handles[];
211 #define p33c_CcpInstance_GetHandle(x) (struct P33C_CCP_INSTANCE_s*)p33c_CcpInstance_Handles[(x-1)]
212
213
214 #endif
215
216 /* GLOBAL FUNCTION CALL PROTOTYPES */
217
218 extern volatile struct P33C_CCP_INSTANCE_s p33c_CcpInstance_ConfigRead(volatile uint16_t ccpInstance);
219 extern volatile uint16_t p33c_CcpInstance_ConfigWrite(
220 volatile uint16_t ccpInstance,
221 volatile struct P33C_CCP_INSTANCE_s ccpConfig
222 );
223
224
225 #endif /* P33C_CCP_SFR_ABSTRACTION_H */
226 // END OF FILE
P33C_CCP_INSTANCE_s::CCPxBUFL
union P33C_CCP_INSTANCE_s::@12 CCPxBUFL
P33C_CCP_INSTANCE_s::CCPxCON1L
union P33C_CCP_INSTANCE_s::@0 CCPxCON1L
P33C_CCP_INSTANCE_s::CCPRAL
volatile uint16_t CCPRAL
Definition: p33c_ccp.h:111
P33C_CCP_INSTANCE_s::CCPBUFL
volatile uint16_t CCPBUFL
Definition: p33c_ccp.h:129
P33C_CCP_INSTANCE_s::CCPxTMRL
union P33C_CCP_INSTANCE_s::@6 CCPxTMRL
P33C_CCP_INSTANCE_s::CCPBUFH
volatile uint16_t CCPBUFH
Definition: p33c_ccp.h:136
P33C_CCP_INSTANCE_s::CCPxBUFH
union P33C_CCP_INSTANCE_s::@13 CCPxBUFH
P33C_CCP_INSTANCE_s::CCPxCON1H
union P33C_CCP_INSTANCE_s::@1 CCPxCON1H
P33C_CCP_INSTANCE_s::CCPxTMRH
union P33C_CCP_INSTANCE_s::@7 CCPxTMRH
P33C_CCP_INSTANCE_s::CCPxPRL
union P33C_CCP_INSTANCE_s::@8 CCPxPRL
P33C_CCP_INSTANCE_s::bits
struct tagCCP1CON1LBITS bits
Definition: p33c_ccp.h:41
P33C_CCP_INSTANCE_s::unsigned
volatile unsigned
Definition: p33c_ccp.h:66
P33C_CCP_INSTANCE_s::CCPPRL
volatile uint16_t CCPPRL
Definition: p33c_ccp.h:97
P33C_CCP_INSTANCE_s::CCPPRH
volatile uint16_t CCPPRH
Definition: p33c_ccp.h:104
P33C_CCP_INSTANCE_s::CCPxCON2H
union P33C_CCP_INSTANCE_s::@3 CCPxCON2H
P33C_CCP_INSTANCE_s::CCPxRAL
union P33C_CCP_INSTANCE_s::@10 CCPxRAL
P33C_CCP_INSTANCE_s::CCPTMRH
volatile uint16_t CCPTMRH
Definition: p33c_ccp.h:90
P33C_CCP_INSTANCE_s::CCPRBL
volatile uint16_t CCPRBL
Definition: p33c_ccp.h:120
P33C_CCP_INSTANCE_s::CCPxCON2L
union P33C_CCP_INSTANCE_s::@2 CCPxCON2L
P33C_CCP_INSTANCE_s::CCPxCON3H
union P33C_CCP_INSTANCE_s::@4 CCPxCON3H
P33C_CCP_INSTANCE_s::value
uint16_t value
Definition: p33c_ccp.h:42
P33C_CCP_INSTANCE_s::CCPxSTATL
union P33C_CCP_INSTANCE_s::@5 CCPxSTATL
P33C_CCP_INSTANCE_s::CCPxPRH
union P33C_CCP_INSTANCE_s::@9 CCPxPRH
P33C_CCP_INSTANCE_s
Definition: p33c_ccp.h:38
P33C_CCP_INSTANCE_s::CCPTMRL
volatile uint16_t CCPTMRL
Definition: p33c_ccp.h:83
P33C_CCP_INSTANCE_s::CCPxRBL
union P33C_CCP_INSTANCE_s::@11 CCPxRBL