Digital Power Starter Kit 3 Firmware
dsPIC33C Buck Converter Voltage Mode Control Example
p33c_dsp.h
1 /*LICENSE *****************************************************************************************
2  *
3  * Software License Agreement
4  *
5  * Copyright (R) 2012 Microchip Technology Inc. All rights reserved. Microchip licenses to you the
6  * right to use, modify, copy and distribute Software only when embedded on a Microchip
7  * microcontroller or digital signal controller, which is integrated into your product or third
8  * party product (pursuant to the sublicense terms in the accompanying license agreement).
9  *
10  * You should refer to the license agreement accompanying this Software for additional information
11  * regarding your rights and obligations.
12  *
13  * SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR
14  * IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT
15  * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR
16  * OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR
17  * OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES INCLUDING BUT NOT
18  * LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS
19  * OR LOST DATA, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY
20  * THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
21  *
22  * ***********************************************************************************************/
23 
24 #ifndef P33C_DSP_SFR_ABSTRACTION_H
25 #define P33C_DSP_SFR_ABSTRACTION_H
26 
27 
38 // CORCON: CORE CONTROL REGISTER
39 
40 #define REG_CORCON_UNUSED_MSK 0b0100000000000000
41 #define REG_CORCON_VALID_DATA_WRITE_MSK 0b1011100011110011
42 #define REG_CORCON_VALID_DATA_READ_MSK 0b1011111111111111
43 
44 #define REG_CORCON_VAR_VARIABLE 0b1000000000000000
45 #define REG_CORCON_VAR_FIXED 0b0000000000000000
46 
47 enum CORCON_VAR_e{
48  CORCON_VAR_VARIABLE = 0b1, // Variable exception processing is enabled
49  CORCON_VAR_FIXED = 0b0 // Fixed exception processing is enabled
50 };
51 typedef enum CORCON_VAR_e CORCON_VAR_t; // Variable Exception Processing Latency Control bit
52 
53 #define REG_CORCON_US_MIXED 0b0010000000000000 // DSP engine multiplies are mixed sign
54 #define REG_CORCON_US_UNSIGNED 0b0001000000000000 // DSP engine multiplies are unsigned
55 #define REG_CORCON_US_SIGNED 0b0000000000000000 // DSP engine multiplies are signed
56 
57 enum CORCON_US_e{
58  CORCON_US_MIXED = 0b10, // DSP engine multiplies are mixed sign
59  CORCON_US_UNSIGNED = 0b01, // DSP engine multiplies are unsigned
60  CORCON_US_SIGNED = 0b00 // DSP engine multiplies are signed
61 };
62 typedef enum CORCON_US_e CORCON_US_t; // DSP Multiply Unsigned/Signed Control bits
63 
64 #define REG_CORCON_EDT_TERMINATE 0b0000100000000000
65 #define REG_CORCON_EDT_RUN 0b0000000000000000
66 
67 enum CORCON_EDT_e{
68  CORCON_EDT_TERMINATE = 0b1, // Terminates executing DO loop at the end of the current loop iteration
69  CORCON_EDT_RUN = 0b0 // No effect
70 };
71 typedef enum CORCON_EDT_e CORCON_EDT_t; // Early DO Loop Termination Control bit
72 
73 #define REG_CORCON_DL_7 0b0000011100000000 // Seven DO loops are active
74 #define REG_CORCON_DL_6 0b0000011100000000 // Six DO loops are active
75 #define REG_CORCON_DL_5 0b0000011100000000 // Five DO loops are active
76 #define REG_CORCON_DL_4 0b0000011100000000 // Four DO loops are active
77 #define REG_CORCON_DL_3 0b0000011100000000 // Three DO loops are active
78 #define REG_CORCON_DL_2 0b0000011100000000 // Two DO loops are active
79 #define REG_CORCON_DL_1 0b0000011100000000 // One DO loops are active
80 #define REG_CORCON_DL_0 0b0000011100000000 // Zero DO loops are active
81 
82 enum CORCON_DL_STAT_e{
83  CORCON_DL_7 = 0b111, // Seven DO loops are active
84  CORCON_DL_6 = 0b110, // Six DO loops are active
85  CORCON_DL_5 = 0b101, // Five DO loops are active
86  CORCON_DL_4 = 0b100, // Four DO loops are active
87  CORCON_DL_3 = 0b011, // Three DO loops are active
88  CORCON_DL_2 = 0b010, // Two DO loops are active
89  CORCON_DL_1 = 0b001, // One DO loops are active
90  CORCON_DL_0 = 0b000 // Zero DO loops are active
91 };
92 typedef enum CORCON_DL_STAT_e CORCON_DL_STAT_t; // DO Loop Nesting Level Status bits
93 
94 #define REG_CORCON_SATA_ON 0b0000000010000000 // Accumulator A saturation is enabled
95 #define REG_CORCON_SATA_OFF 0b0000000000000000 // Accumulator A saturation is disabled
96 
97 enum CORCON_SATA_e{
98  CORCON_SATA_ON = 0b1, // Accumulator A saturation is enabled
99  CORCON_SATA_OFF = 0b0 // Accumulator A saturation is disabled
100 };
101 typedef enum CORCON_SATA_e CORCON_SATA_t; // ACCA Saturation Enable bit
102 
103 #define REG_CORCON_SATB_ON 0b0000000001000000 // Accumulator B saturation is enabled
104 #define REG_CORCON_SATB_OFF 0b0000000000000000 // Accumulator B saturation is disabled
105 
106 enum CORCON_SATB_e{
107  CORCON_SATB_ON = 0b1, // Accumulator B saturation is enabled
108  CORCON_SATB_OFF = 0b0 // Accumulator B saturation is disabled
109 };
110 typedef enum CORCON_SATB_e CORCON_SATB_t; // ACCB Saturation Enable bit
111 
112 #define REG_CORCON_SATDW_ON 0b0000000000100000 // Data Space write saturation is enabled
113 #define REG_CORCON_SATDW_OFF 0b0000000000000000 // Data Space write saturation is disabled
114 
115 enum CORCON_SATDW_e{
116  CORCON_SATDW_ON = 0b1, // Data Space write saturation is enabled
117  CORCON_SATDW_OFF = 0b0 // Data Space write saturation is disabled
118 };
119 typedef enum CORCON_SATDW_e CORCON_SATDW_t; // Data Space Write from DSP Engine Saturation Enable bit
120 
121 #define REG_CORCON_ACCSAT_931 0b0000000000010000 // 9.31 saturation (super saturation)
122 #define REG_CORCON_ACCSAT_131 0b0000000000000000 // 1.31 saturation (normal saturation)
123 
124 enum CORCON_ACCSAT_e{
125  CORCON_ACCSAT_931 = 0b1, // 9.31 saturation (super saturation)
126  CORCON_ACCSAT_131 = 0b0 // 1.31 saturation (normal saturation)
127 };
128 typedef enum CORCON_ACCSAT_e CORCON_ACCSAT_t; // Accumulator Saturation Mode Select bit
129 
130 #define REG_CORCON_IPL3_STAT_GT7 0b0000000000001000
131 #define REG_CORCON_IPL3_STAT_LT7 0b0000000000000000
132 
133 enum CORCON_IPL3_STAT_e{
134  CORCON_IPL3_STAT_GT7 = 0b1, // CPU Interrupt Priority Level is greater than 7
135  CORCON_IPL3_STAT_LT7 = 0b0 // CPU Interrupt Priority Level is 7 or less
136 };
137 typedef enum CORCON_IPL3_STAT_e CORCON_IPL3_STAT_t; // CPU Interrupt Priority Level Status bit 3
138 
139 #define REG_CORCON_SFA_ACTIVE 0b0000000000000100 // Stack frame is active; W14 and W15 address 0x0000 to 0xFFFF, regardless of DSRPAG
140 #define REG_CORCON_SFA_INACTIVE 0b0000000000000000 // Stack frame is not active; W14 and W15 address the base Data Space
141 
142 enum CORCON_SFA_e{
143  CORCON_SFA_ACTIVE = 0b1, // Stack frame is active; W14 and W15 address 0x0000 to 0xFFFF, regardless of DSRPAG
144  CORCON_SFA_INACTIVE = 0b0 // Stack frame is not active; W14 and W15 address the base Data Space
145 };
146 typedef enum CORCON_SFA_e CORCON_SFA_t; // Stack Frame Active Status bit
147 
148 #define REG_CORCON_RND_BIASED 0b0000000000000010 // Biased (conventional) rounding is enabled
149 #define REG_CORCON_RND_UNBIASED 0b0000000000000000 // Unbiased (convergent) rounding is enabled
150 
151 enum CORCON_RND_e{
152  CORCON_RND_BIASED = 0b1, // Biased (conventional) rounding is enabled
153  CORCON_RND_UNBIASED = 0b0 // Unbiased (convergent) rounding is enabled
154 };
155 typedef enum CORCON_RND_e CORCON_RND_t; // Rounding Mode Select bit
156 
157 #define REG_CORCON_IF_INTEGER 0b0000000000000001 // Integer mode is enabled for DSP multiply
158 #define REG_CORCON_IF_FRACTIONAL 0b0000000000000000 // Fractional mode is enabled for DSP multiply
159 
160 enum CORCON_IF_e{
161  CORCON_IF_INTEGER = 0b1, // Integer mode is enabled for DSP multiply
162  CORCON_IF_FRACTIONAL = 0b0 // Fractional mode is enabled for DSP multiply
163 };
164 typedef enum CORCON_IF_e CORCON_IF_t; // Integer or Fractional Multiplier Mode Select bit
165 
167 {
168  union {
169  struct {
170  volatile CORCON_IF_t IF : 1; // Integer or Fractional Multiplier Mode Select bit
171  volatile CORCON_RND_t RND : 1; // Rounding Mode Select bit
172  volatile CORCON_SFA_t SFA : 1; // Stack Frame Active Status bit
173  volatile CORCON_IPL3_STAT_t IPL3 : 1; // CPU Interrupt Priority Level Status bit 3
174  volatile CORCON_ACCSAT_t ACCSAT : 1; // Accumulator Saturation Mode Select bit
175  volatile CORCON_SATDW_t SATDW : 1; // Data Space Write from DSP Engine Saturation Enable bit
176  volatile CORCON_SATB_t SATB : 1; // ACCB Saturation Enable bit
177  volatile CORCON_SATA_t SATA : 1; // ACCA Saturation Enable bit
178 
179  volatile CORCON_DL_STAT_t DL : 3; // DO Loop Nesting Level Status bits
180  volatile CORCON_EDT_t EDT : 1; // Early DO Loop Termination Control bit
181  volatile CORCON_US_t US : 2; // DSP Multiply Unsigned/Signed Control bits
182  volatile unsigned : 1; // reserved
183  volatile CORCON_VAR_t VAR : 1; // Variable Exception Processing Latency Control bit
184  } __attribute__((packed)) bits; // CORCON: CORE CONTROL REGISTER BITFIELD
185 
186  volatile uint16_t value; // CORCON: CORE CONTROL REGISTER VALUE
187  };
188 };
189 typedef struct DSP_CONFIG_s DSP_CONFIG_t; // CORCON: CORE CONTROL REGISTER
190 
191 /* PROTOTYPES */
192 extern volatile uint16_t Dsp_SetConfig(volatile struct DSP_CONFIG_s dsp_cfg);
193 extern volatile struct DSP_CONFIG_s Dsp_GetConfig(void);
194 
195 #endif /* end of P33C_DSP_SFR_ABSTRACTION_H */
196 
197 // end of file
DSP_CONFIG_s::IPL3
volatile CORCON_IPL3_STAT_t IPL3
Definition: p33c_dsp.h:173
DSP_CONFIG_s::IF
volatile CORCON_IF_t IF
Definition: p33c_dsp.h:170
DSP_CONFIG_s::DL
volatile CORCON_DL_STAT_t DL
Definition: p33c_dsp.h:179
DSP_CONFIG_s
Definition: p33c_dsp.h:167
DSP_CONFIG_s::EDT
volatile CORCON_EDT_t EDT
Definition: p33c_dsp.h:180
DSP_CONFIG_s::SFA
volatile CORCON_SFA_t SFA
Definition: p33c_dsp.h:172
DSP_CONFIG_s::ACCSAT
volatile CORCON_ACCSAT_t ACCSAT
Definition: p33c_dsp.h:174
DSP_CONFIG_s::SATDW
volatile CORCON_SATDW_t SATDW
Definition: p33c_dsp.h:175
Dsp_SetConfig
volatile uint16_t Dsp_SetConfig(volatile struct DSP_CONFIG_s dsp_cfg)
Initializes the DSP engine in accordance to user settings.
Definition: p33c_dsp.c:53
DSP_CONFIG_s::RND
volatile CORCON_RND_t RND
Definition: p33c_dsp.h:171
DSP_CONFIG_s::unsigned
volatile unsigned
Definition: p33c_dsp.h:182
DSP_CONFIG_s::VAR
volatile CORCON_VAR_t VAR
Definition: p33c_dsp.h:183
DSP_CONFIG_s::value
volatile uint16_t value
Definition: p33c_dsp.h:186
DSP_CONFIG_s::SATA
volatile CORCON_SATA_t SATA
Definition: p33c_dsp.h:177
DSP_CONFIG_s::US
volatile CORCON_US_t US
Definition: p33c_dsp.h:181
Dsp_GetConfig
volatile struct DSP_CONFIG_s Dsp_GetConfig(void)
Reads the DSP engine configuration.
Definition: p33c_dsp.c:78
DSP_CONFIG_s::SATB
volatile CORCON_SATB_t SATB
Definition: p33c_dsp.h:176