Digital Power Starter Kit 3 Firmware
dsPIC33C Boost Converter Voltage Mode Control Example
p33c_mpuart.h
1 /*
2  (c) 2021 Microchip Technology Inc. and its subsidiaries. You may use this
3  software and any derivatives exclusively with Microchip products.
4 
5  THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
6  EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
7  WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
8  PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
9  WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
10 
11  IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
12  INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
13  WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
14  BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
15  FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
16  ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
17  THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
18 
19  MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
20  TERMS.
21 */
22 
23 /**************************************************************************************************
24  * @file: p33c_mpuart.h
25  * @brief: Generic Universal Asynchronous Receiver/Transmitter (UART) Driver Module & Generator Instances (header file)
26  * @detail
27  * This additional header file contains defines for all required bit-settings of all related
28  * special function registers of a peripheral module and/or instance.
29  * This file is an additional header file on top of the generic device header file.
30  *
31  * See Also:
32  * p33c_mpuart.c
33  *
34  * ***********************************************************************************************#
35  * Revision history:
36  * 06/22/20 1.0 initial release
37  * 09/16/20 1.1 Simplified uart instance addressing
38  *************************************************************************************************/
39 
40 // This is a guard condition so that contents of this file are not included
41 // more than once.
42 #ifndef P33C_MPUART_SFR_ABSTRACTION_H
43 #define P33C_MPUART_SFR_ABSTRACTION_H
44 
45 // Include standard header files
46 #include <xc.h> // include processor files - each processor file is guarded.
47 #include <stdint.h> // include standard integer data types
48 #include <stdbool.h> // include standard boolean data types
49 #include <stddef.h> // include standard definition data types
50 
51 
52 //#ifndef __dsPIC33C__
53 // #error "peripheral driver p33c_uart.h does not support the selected device"
54 //#endif
55 
56 
57 /* GENERIC SPECIAL FUNCTION REGISTER (SFR) SETS
58  * ============================================
59  *
60  * Direct addressing of Special Function Registers (SFR) in user code is good
61  * enough for a specific application but makes it harder to maintain the code
62  * or migrate the code across devices and applications.
63  *
64  * Especially with complex configurations with multiple dependencies across various
65  * peripherals, migrating configurations can become very challenging to review,
66  * debug and migrate.
67  *
68  * Therefore this UART configuration example uses a 'virtual UART port' to set up
69  * the required UART configuration but provides a function allowing users to write this
70  * configuration to any UART port of choice. Hence, pre-defined configurations
71  * can be mapped on specific peripheral instance by using their index defined by the
72  * data sheet (e.g. uartInstance = 1 maps pre-defined configuration to UART1)
73  *
74  * The data types used for each SFR in the P33C_UART_PORT_t data structure below,
75  * are data types declared in the common C-header file of the device (e.g. <d33CK256MP506.h>).
76  * These header files are provided with the XC16 C-Compiler installation and don't have to be
77  * written nor changed manually.
78  *
79  */
80 
81 // GENERIC PWM GENERATOR SPECIAL FUNCTION REGISTER SET
82 
83 #ifndef P33C_UART_INSTANCE_s
84 
86  union {
87  struct tagU1MODEBITS bits; // Register bit-field
88  uint16_t value; // 16-bit wide register value
89  } UxMODE; // UxMODE: UARTx CONFIGURATION REGISTER
90  union {
91  struct tagU1MODEHBITS bits; // Register bit-field
92  uint16_t value; // 16-bit wide register value
93  } UxMODEH; // UxMODE: UARTx CONFIGURATION REGISTER HIGH
94  union {
95  struct tagU1STABITS bits; // Register bit-field
96  uint16_t value; // 16-bit wide register value
97  } UxSTA; // UxSTA: UARTx STATUS REGISTER
98  union {
99  struct tagU1STAHBITS bits; // Register bit-field
100  uint16_t value; // 16-bit wide register value
101  } UxSTAH; // UxSTAH: UARTx STATUS REGISTER HIGH
102  union {
103  struct {
104  uint16_t BRG : 16; // Register bit-field
105  } bits; // Register bit-field
106  uint16_t value; // 16-bit wide register value
107  }UxBRG; // UxBRG: UARTx BAUD RATE REGISTER
108  union {
109  struct {
110  uint16_t BRGH : 4; // Register bit-field
111  unsigned : 12; // (reserved)
112  } bits; // Register bit-field
113  uint16_t value; // 16-bit wide register value
114  }UxBRGH; // UxBRG: UARTx BAUD RATE REGISTER HIGH
115  union {
116  struct {
117  uint16_t RXREG : 8; // Register bit-field
118  unsigned : 8; // (reserved)
119  } bits; // Register bit-field
120  uint16_t value; // 16-bit wide register value
121  }UxRXREG; // UxRXREG: UARTx RECEIVE BUFFER REGISTER
122  unsigned : 16; // (reserved/unused memory section)
123  union {
124  struct {
125  uint16_t TXREG : 8; // Register bit-field
126  unsigned : 8; // (reserved)
127  } bits; // Register bit-field
128  uint16_t value; // 16-bit wide register value
129  }UxTXREG; // UxTXREG: UARTx TRANSMIT BUFFER REGISTER
130  unsigned : 16; // (reserved/unused memory section)
131  union {
132  struct {
133  uint16_t P1 : 8; // Register bit-field
134  unsigned : 8; // (reserved)
135  } bits; // Register bit-field
136  uint16_t value; // 16-bit wide register value
137  }UxP1; // UxP1: UARTx TIMING PARAMETER 1 REGISTER
138  union {
139  struct {
140  uint16_t P2 : 8; // Register bit-field
141  unsigned : 8; // (reserved)
142  } bits; // Register bit-field
143  uint16_t value; // 16-bit wide register value
144  }UxP2; // UxP2: UARTx TIMING PARAMETER 2 REGISTER
145  union {
146  struct {
147  uint16_t P3 : 8; // Register bit-field
148  unsigned : 8; // (reserved)
149  } bits; // Register bit-field
150  uint16_t value; // 16-bit wide register value
151  }UxP3; // UxP3: UARTx TIMING PARAMETER 3 REGISTER
152  union {
153  struct {
154  uint16_t P3H : 8; // Register bit-field
155  unsigned : 8; // (reserved)
156  } bits; // Register bit-field
157  uint16_t value; // 16-bit wide register value
158  }UxP3H; // UxP3H: UARTx TIMING PARAMETER 3H REGISTER
159  union {
160  struct {
161  uint16_t TXCHK : 8; // Register bit-field
162  unsigned : 8; // (reserved)
163  } bits; // Register bit-field
164  uint16_t value; // 16-bit wide register value
165  }UxTXCHK; // UxTXCHK: UARTx TRANSMIT CHECKSUM REGISTER
166  union {
167  struct {
168  uint16_t RXCHK : 8; // Register bit-field
169  unsigned : 8; // (reserved)
170  } bits; // Register bit-field
171  uint16_t value; // 16-bit wide register value
172  }UxRXCHK; // UxRXCHK: UARTx RECEIVE CHECKSUM REGISTER
173  union {
174  struct tagU1SCCONBITS bits; // Register bit-field
175  uint16_t value; // 16-bit wide register value
176  } UxSCCON; // UxSCCON: UARTx SMART CARD CONFIGURATION REGISTER
177  union {
178  struct tagU1SCINTBITS bits; // Register bit-field
179  uint16_t value; // 16-bit wide register value
180  } UxSCINT; // UxSCINT: UARTx SMART CARD INTERRUPT REGISTER
181  union {
182  struct tagU1INTBITS bits; // Register bit-field
183  uint16_t value; // 16-bit wide register value
184  } UxINT; // UxINT: UARTx INTERRUPT REGISTER
185 
186  } __attribute__((packed)); // PWM GENERATOR INSTANCE SPECIAL FUNCTION REGISTER SET
187  typedef struct P33C_UART_INSTANCE_s P33C_UART_PORT_t; // PWM GENERATOR INSTANCE SPECIAL FUNCTION REGISTER SET DATA TYPE
188 
189  // PWM generator instance Special Function Register set address offset
190  #define P33C_UART_SFR_START_ADDR (volatile uint16_t)&U1MODE
191  #define P33C_UARTPORT_SFR_OFFSET ((volatile uint16_t)&U2MODE - (volatile uint16_t)&U1MODE)
192 
193  // Determine number of available PWM generators on the selected device
194  #if defined (U8MODE)
195  #define P33C_UART_COUNT 8
196 
197  #elif defined (U7MODE)
198  #define P33C_UART_COUNT 7
199 
200  #elif defined (U6MODE)
201  #define P33C_UART_COUNT 6
202 
203  #elif defined (U5MODE)
204  #define P33C_UART_COUNT 5
205 
206  #elif defined (U4MODE)
207  #define P33C_UART_COUNT 4
208 
209  #elif defined (U3MODE)
210  #define P33C_UART_COUNT 3
211 
212  #elif defined (U2MODE)
213  #define P33C_UART_COUNT 2
214 
215  #elif defined (U1MODE)
216  #define P33C_UART_COUNT 1
217 
218  #endif
219 
220  // Public macro to derive pointer address to UART port register block
221  extern volatile uint16_t* p33c_MpUartPort_Handles[];
222  #define p33c_MpUartPort_GetHandle(x) (struct P33C_UART_INSTANCE_s*)p33c_MpUartPort_Handles[(x-1)]
223 
224 
225 #endif
226 
227 
228 
229 /* ********************************************************************************************* *
230  * API FUNCTION PROTOTYPES
231  * ********************************************************************************************* */
232 
233 // UART port essential functions
234 extern volatile uint16_t p33c_MpUartPort_GetInstance(volatile struct P33C_UART_INSTANCE_s* uart);
235 extern volatile struct P33C_UART_INSTANCE_s p33c_MpUartPortConfigRead(volatile uint16_t uartInstance);
236 extern volatile uint16_t p33c_MpUartPort_ConfigWrite(volatile uint16_t uartInstance,
237  volatile struct P33C_UART_INSTANCE_s uartConfig);
238 
239 // Standard Generator Functions API
240 extern volatile uint16_t p33c_MpUartPort_Initialize(volatile uint16_t uartInstance);
241 extern volatile uint16_t p33c_MpUartPort_Dispose(volatile uint16_t uartInstance);
242 
243 extern volatile uint16_t p33c_MpUartPort_Enable(volatile struct P33C_UART_INSTANCE_s* uart);
244 extern volatile uint16_t p33c_MpUartPort_Disable(volatile struct P33C_UART_INSTANCE_s* uart);
245 
246 
247 /* ********************************************************************************************* *
248  * UART INSTANCE CONFIGURATION TEMPLATES
249  * ********************************************************************************************* */
250 extern volatile struct P33C_UART_INSTANCE_s uartConfigClear;
251 extern volatile struct P33C_UART_INSTANCE_s uartConfigSerialRxTx;
252 
253 #endif /* P33C_MPUART_SFR_ABSTRACTION_H */
254 
255 // end of file
union P33C_UART_INSTANCE_s::@150 UxSTAH
union P33C_UART_INSTANCE_s::@155 UxP1
union P33C_UART_INSTANCE_s::@148 UxMODEH
union P33C_UART_INSTANCE_s::@163 UxINT
union P33C_UART_INSTANCE_s::@156 UxP2
union P33C_UART_INSTANCE_s::@151 UxBRG
union P33C_UART_INSTANCE_s::@147 UxMODE
union P33C_UART_INSTANCE_s::@160 UxRXCHK
union P33C_UART_INSTANCE_s::@162 UxSCINT
union P33C_UART_INSTANCE_s::@161 UxSCCON
union P33C_UART_INSTANCE_s::@157 UxP3
union P33C_UART_INSTANCE_s::@149 UxSTA
union P33C_UART_INSTANCE_s::@153 UxRXREG
union P33C_UART_INSTANCE_s::@152 UxBRGH
struct tagU1MODEBITS bits
Definition: p33c_mpuart.h:87
union P33C_UART_INSTANCE_s::@158 UxP3H
union P33C_UART_INSTANCE_s::@159 UxTXCHK
union P33C_UART_INSTANCE_s::@154 UxTXREG