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

p33c_pmd.c
1 #include <xc.h> // include processor files - each processor file is guarded.
2 #include <stdint.h> // include standard integer data types
3 #include <stdbool.h> // include standard boolean data types
4 #include <stddef.h> // include standard definition data types
5
6 #include "p33c_pmd.h"
7
8
9 /*********************************************************************************
10 * @ingroup lib-layer-pral-properties-private-pmd
11 * @var pmdConfigDefault
12 * @brief PMD Register Set reset state template
13 *
14 * @details
15 * This P33C_PMD_s data object provides a template of register
16 * configuration values for the Peripheral Module Disable module.
17 *
18 * Default configuration:
19 * - all options are reset to their default state (on)
20 *
21 *********************************************************************************/
24 volatile struct P33C_PMD_MODULE_s pmdConfigDefault = {
25
26 #ifdef PMD1
27 .pmd1.value = 0xffff,
28 #endif
29 #ifdef PMD2
30 .pmd2.value = 0xffff,
31 #endif
32 #ifdef PMD3
33 .pmd3.value = 0xffff,
34 #endif
35 #ifdef PMD4
36 .pmd4.value = 0xffff,
37 #endif
38 #ifdef PMD5
39 .pmd5.value = 0xffff,
40 #endif
41 #ifdef PMD6
42 .pmd6.value = 0xffff,
43 #endif
44 #ifdef PMD7
45 .pmd7.value = 0xffff,
46 #endif
47 #ifdef PMD8
48 .pmd8.value = 0xffff,
49 #endif
50 #ifdef PMD9
51 .pmd9.value = 0xffff,
52 #endif
53
54 };
55
56 /* PRIVATE FUNCTION CALL PROTOTYPES*/
57 // (none)
58
59
60 /*********************************************************************************
61 * @fn volatile struct P33C_CCP_INSTANCE_s p33c_CcpInstance_ConfigRead(volatile uint16_t ccpInstance)
62 * @ingroup lib-layer-pral-functions-public-pmd
63 * @brief Read the current configuration from the CCP instance registers
64 * @param ccpInstance Index of the Capture/Compare peripheral instance of type unsinged integer
65 * @return SCCP/MCCP instance special function register data object of type struct P33C_CCP_INSTANCE_s
66 *
67 * @details
68 * This function reads all registers with their current configuration into
69 * a data structure of type P33C_CCP_MODULE_SFRSET_s. Users can read and
70 * verify of modify the configuration to write it back to any other CCP
71 * peripheral instance.
72 *
73 *********************************************************************************/
74
75 volatile struct P33C_PMD_MODULE_s p33c_PmdInstance_ConfigRead(void){
76
77 volatile struct P33C_PMD_MODULE_s* pmd;
78
79 // Capture Handle: set pointer to memory address of the Peripheral Module Disable module
80 pmd = p33c_Pmd_GetHandle();
81
82 return(*pmd);
83 }
84
85 /********************************************************************************
86 * @fn volatile uint16_t p33c_CcpInstance_ConfigWrite(volatile uint16_t ccpInstance, volatile struct P33C_CCP_INSTANCE_s ccpConfig)
87 * @ingroup lib-layer-pral-functions-public-pmd
88 * @brief Writes a user-defined configuration to the Peripheral Module Disable registers
89 * @param pmdConfig Peripheral Module Disable special function register data object of type struct P33C_PMD_s
90 * @return 0 = failure, writing to PMD module was not successful
91 * @return 1 = success, writing to PMD module was successful
92 *
93 * @details
94 * This function writes a user-defined PMD module configuration of type
95 * P33C_PMD_s to the Peripheral Module Disable module registers. The
96 * individual register configurations have to be set in user-code
97 * before calling this function. To simplify the configuration process
98 * of standard functions, this driver provides templates, which can be
99 * loaded and written directly
100 *
101 *********************************************************************************/
102
103 volatile uint16_t p33c_Pmd_ConfigWrite(volatile struct P33C_PMD_MODULE_s pmdConfig)
104 {
105 volatile uint16_t retval=1;
106 volatile struct P33C_PMD_MODULE_s* pmd;
107
108 // Set pointer to memory address of the Peripheral Module Disable module
109 pmd = p33c_Pmd_GetHandle();
110
111 // Disable all peripheral modules
112 #ifdef PMDCON
113 pmd->pmdcon.bits.PMDLOCK = 0; // Unlock writes to PMD registers
114 #endif
115
116 // Load user configuration into PDM register set
117 *pmd = pmdConfig;
118
119 #ifdef PMDCON
120 pmd->pmdcon.bits.PMDLOCK = 1; // Lock writes to PMD registers
121 #endif
122
123 return(retval);
124
125 }
126
127 // end of file
P33C_PMD_MODULE_s
Definition: p33c_pmd.h:37