Digital Power Starter Kit 3 Firmware
dsPIC33C Buck Converter Voltage Mode Control Example
p33c_pps.c
1 /* Software License Agreement
2  * ************************************************************************************************
3  *
4  * Software License Agreement
5  *
6  * Copyright © 2020 Microchip Technology Inc. All rights reserved. Microchip licenses to you the
7  * right to use, modify, copy and distribute Software only when embedded on a Microchip
8  * microcontroller or digital signal controller, which is integrated into your product or third
9  * party product (pursuant to the sublicense terms in the accompanying license agreement).
10  *
11  * You should refer to the license agreement accompanying this Software for additional information
12  * regarding your rights and obligations.
13  *
14  * SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR
15  * IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT
16  * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR
17  * OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR
18  * OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES INCLUDING BUT NOT
19  * LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS
20  * OR LOST DATA, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY
21  * THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
22  *
23  * ***********************************************************************************************/
24 
25 // Include Header Files
26 #include "p33c_pps.h"
27 
28 
29 /* ************************************************************************************************
30  * @file p33c_pps.c
31  * @brief Generic Peripheral Pin Select (PPS) Driver Module
32  * @see p33c_pps.h
33  *
34  * @details
35  * Some low-pin count devices have the capability to assign digital functions to a range of
36  * free configurable pins (RPx). This driver module offers functions to read from and write to
37  * the configuration registers, which will connect a digital peripheral bock with a selected
38  * pin.
39  *
40  * @ref dsPIC33F Reference Manual, Section 10: I/O Ports, Chapter 10.3: Peripheral Multiplexing
41  *
42  * Author: M91406
43  * Version: 1.3
44  *
45  * History:
46  * 11/04/2008 First Release
47  * 08/25/2009 Added definitions for new peripherals
48  * 02/05/2012 Format transfer
49  * 04/11/2016 Added definitions and compile switches for dsPIC33EP GS
50  * 05/29/2019 Added RPx pin configuration lock/unlock sequence for dsPIC33C
51  * 10/14/2020 Removed support for dsPIC33F and dsPIC33E
52  * ***********************************************************************************************/
53 
54 
75 volatile uint16_t PPS_LockIO(void){
76 
77  __builtin_write_RPCON(0x0800); // lock PPS
78  return(RPCONbits.IOLOCK);
79 
80 }
81 
82 
102 volatile uint16_t PPS_UnlockIO(void){
103 
104  __builtin_write_RPCON(0x0000); // unlock PPS
105  return(1 - RPCONbits.IOLOCK);
106 
107 }
108 
109 
133 volatile uint16_t PPS_RemapOutput(volatile uint8_t pinno, volatile uint8_t peripheral){
134 
135  volatile uint16_t retval = 0;
136  volatile uint8_t *regptr;
137  volatile uint8_t pin_offset=0;
138 
139  pin_offset = (pinno - RP_PINNO_MIN); // Determine pin-offset
140  regptr = (volatile uint8_t *)&RPOR0; // get register block base address
141  regptr += (volatile uint8_t)pin_offset; // add offset
142  *regptr = (volatile uint8_t)peripheral; // copy configuration into register location
143  retval = (bool)(*regptr == (volatile uint8_t)peripheral); // Check if contents have been written correctly
144 
145  return (retval);
146 
147 }
148 
149 
174 volatile uint16_t PPS_RemapInput(volatile uint8_t pinno, volatile uint8_t *peripheral)
175 {
176 
177  // Map selected pin function
178  *peripheral = pinno;
179 
180  return 1;
181 
182 }
183 
184 
207 volatile uint16_t PPS_UnmapOutput(volatile uint8_t pinno)
208 {
209  volatile uint16_t retval=0;
210 
211  // Unmap selected pin function
212  retval = PPS_RemapOutput(pinno, PPSPIN_NULL);
213  return retval;
214 
215 }
216 
217 
240 volatile uint16_t PPS_UnmapInput(volatile uint8_t *peripheral)
241 {
242  volatile uint16_t retval=0;
243 
244  // Unmap selected pin function
245  retval = PPS_RemapInput(PPSPIN_NULL, peripheral);
246  return retval;
247 
248 }
249 
250 
251 // end of file
PPS_UnmapInput
volatile uint16_t PPS_UnmapInput(volatile uint8_t *peripheral)
Disconnects a pin from a digital function input.
Definition: p33c_pps.c:240
PPS_LockIO
volatile uint16_t PPS_LockIO(void)
Locks the Peripheral Pin Select Configuration registers against accidental changes.
Definition: p33c_pps.c:75
PPS_UnlockIO
volatile uint16_t PPS_UnlockIO(void)
Unlocks the Peripheral Pin Select Configuration registers to enable changes.
Definition: p33c_pps.c:102
PPS_RemapInput
volatile uint16_t PPS_RemapInput(volatile uint8_t pinno, volatile uint8_t *peripheral)
Assigns a pin to a digital function input.
Definition: p33c_pps.c:174
PPS_RemapOutput
volatile uint16_t PPS_RemapOutput(volatile uint8_t pinno, volatile uint8_t peripheral)
Assigns a digital function output to a pin.
Definition: p33c_pps.c:133
PPS_UnmapOutput
volatile uint16_t PPS_UnmapOutput(volatile uint8_t pinno)
Disconnects a pin from a digital function output.
Definition: p33c_pps.c:207