|  | Dual Active Bridge Development Board (Part-No. ) |
Content |  |  |  |  |  |

Loading...
Searching...
No Matches
sccp1.c
Go to the documentation of this file.
1
17/*
18© [2024] Microchip Technology Inc. and its subsidiaries.
19
20 Subject to your compliance with these terms, you may use Microchip
21 software and any derivatives exclusively with Microchip products.
22 You are responsible for complying with 3rd party license terms
23 applicable to your use of 3rd party software (including open source
24 software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
25 NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
26 SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
27 MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
28 WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
29 INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
30 KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
31 MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
32 FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
33 TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
34 EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
35 THIS SOFTWARE.
36*/
37
38// Section: Included Files
39
40#include <stddef.h>
41#include "../sccp1.h"
42#include "../timer_interface.h"
43
44// Section: Data Type Definitions
45
46#define MASK_32_BIT_LOW 0x0000FFFFU
47#define MASK_32_BIT_HIGH 0xFFFF0000U
48
49// Section: File specific functions
50
51 static void (*SCCP1_TimeoutHandler)(void) = NULL;
52
53// Section: Driver Interface
54
55// Defines an object for TIMER_INTERFACE
56
57 const struct TIMER_INTERFACE CTRLLOOP_EXE = {
58 .Initialize = &SCCP1_Timer_Initialize,
59 .Deinitialize = &SCCP1_Timer_Deinitialize,
60 .Start = &SCCP1_Timer_Start,
61 .Stop = &SCCP1_Timer_Stop,
62 #if TIMER_PERIODCOUNTSET_API_SUPPORT
63 .PeriodCountSet = &SCCP1_Timer_PeriodCountSet,
64 #endif
65 .PeriodSet = &SCCP1_Timer_PeriodSet,
66 .CounterGet = &SCCP1_Timer_CounterGet,
67 .PeriodGet = &SCCP1_Timer_PeriodGet,
68 .InterruptPrioritySet = &SCCP1_Timer_InterruptPrioritySet,
69 .TimeoutCallbackRegister = &SCCP1_Timer_TimeoutCallbackRegister,
70 .Tasks = NULL,
71};
72
73// Section: Driver Interface Function Definitions
74
75 void SCCP1_Timer_Initialize(void)
76{
77 // MOD 16-Bit/32-Bit Timer; CCSEL disabled; TMR32 16 Bit; TMRPS 1:1; CLKSEL FOSC/2; TMRSYNC disabled; CCPSLP disabled; CCPSIDL disabled; CCPON disabled;
78 CCP1CON1L = 0x0; //The module is disabled, till other settings are configured
79 //SYNC None; ALTSYNC disabled; ONESHOT disabled; TRIGEN disabled; IOPS Each Time Base Period Match; RTRGEN disabled; OPSRC Timer Interrupt Event;
80 CCP1CON1H = 0x0;
81 //ASDG 0x0; SSDG disabled; ASDGM disabled; PWMRSEN disabled;
82 CCP1CON2L = 0x0;
83 //ICSEL ; AUXOUT Disabled; ICGSM Level-Sensitive mode; OCAEN disabled; OENSYNC disabled;
84 CCP1CON2H = 0x0;
85 //PSSACE Tri-state; POLACE disabled; OSCNT None; OETRIG disabled;
86 CCP1CON3H = 0x0;
87 //ICOV disabled; ICDIS disabled; SCEVT disabled; ASEVT disabled; TRCLR disabled; TRSET disabled; ICGARM disabled;
88 CCP1STATL = 0x0;
89 //TMRL 0x0000;
90 CCP1TMRL = 0x0;
91 //TMRH 0x0000;
92 CCP1TMRH = 0x0;
93 //PRL 999;
94 CCP1PRL = 0x3E7;
95 //PRH 0;
96 CCP1PRH = 0x0;
97 //CMPA 0;
98 CCP1RA = 0x0;
99 //CMPB 0;
100 CCP1RB = 0x0;
101 //BUFL 0x0000;
102 CCP1BUFL = 0x0;
103 //BUFH 0x0000;
104 CCP1BUFH = 0x0;
105
106 SCCP1_Timer_TimeoutCallbackRegister(&SCCP1_TimeoutCallback);
107
108 IFS0bits.CCT1IF = 0;
109 // Enabling SCCP1 interrupt
110 IEC0bits.CCT1IE = 1;
111
112 CCP1CON1Lbits.CCPON = 1; //Enable Module
113}
114
115 void SCCP1_Timer_Deinitialize(void)
116{
117 CCP1CON1Lbits.CCPON = 0;
118
119 IFS0bits.CCT1IF = 0;
120 IEC0bits.CCT1IE = 0;
121
122 CCP1CON1L = 0x0;
123 CCP1CON1H = 0x0;
124 CCP1CON2L = 0x0;
125 CCP1CON2H = 0x100;
126 CCP1CON3H = 0x0;
127 CCP1STATL = 0x0;
128 CCP1TMRL = 0x0;
129 CCP1TMRH = 0x0;
130 CCP1PRL = 0xFFFF;
131 CCP1PRH = 0xFFFF;
132 CCP1RA = 0x0;
133 CCP1RB = 0x0;
134 CCP1BUFL = 0x0;
135 CCP1BUFH = 0x0;
136}
137
138 void SCCP1_Timer_Start(void)
139{
140 IFS0bits.CCT1IF = 0;
141 // Enable SCCP1 interrupt
142 IEC0bits.CCT1IE = 1;
143
144 CCP1CON1Lbits.CCPON = 1;
145}
146
147 void SCCP1_Timer_Stop(void)
148{
149 CCP1CON1Lbits.CCPON = 0;
150
151 IFS0bits.CCT1IF = 0;
152 // Disable SCCP1 interrupt
153 IEC0bits.CCT1IE = 0;
154}
155
156 void SCCP1_Timer_PeriodSet(uint32_t count)
157{
158 if(count > 0xFFFFU)
159 {
160 CCP1PRL = (uint16_t)(count & MASK_32_BIT_LOW);
161 CCP1PRH = (uint16_t)((count & MASK_32_BIT_HIGH) >> 16);
162 CCP1CON1Lbits.T32 = 1;
163 }
164 else
165 {
166 CCP1PRL = (uint16_t)(count & MASK_32_BIT_LOW);
167 CCP1CON1Lbits.T32 = 0;
168 }
169}
170
171 void SCCP1_Timer_InterruptPrioritySet(enum INTERRUPT_PRIORITY priority)
172{
173 IPC1bits.CCT1IP = priority;
174}
175
176 void SCCP1_Timer_TimeoutCallbackRegister(void (*handler)(void))
177{
178 if(NULL != handler)
179 {
180 SCCP1_TimeoutHandler = handler;
181 }
182}
183
184 void SCCP1_TimeoutCallbackRegister(void* handler)
185{
186 if(NULL != handler)
187 {
188 SCCP1_TimeoutHandler = handler;
189 }
190}
191
192 void __attribute__ ((weak)) SCCP1_TimeoutCallback (void)
193{
194
195}
196
197 void __attribute__ ( ( interrupt, no_auto_psv ) ) _CCT1Interrupt (void)
198{
199 if(NULL != SCCP1_TimeoutHandler)
200 {
201 (*SCCP1_TimeoutHandler)();
202 }
203 IFS0bits.CCT1IF = 0;
204}
205
206 void SCCP1_Timer_PeriodCountSet(size_t count)
207{
208 CCP1PRL = (uint16_t)(count & MASK_32_BIT_LOW);
209 CCP1CON1Lbits.T32 = 0;
210}
211
SCCP1_Timer_PeriodCountSet
void SCCP1_Timer_PeriodCountSet(size_t count)
Definition sccp1.c:206
__attribute__
void __attribute__((weak))
Definition sccp1.c:192
MASK_32_BIT_HIGH
#define MASK_32_BIT_HIGH
Definition sccp1.c:47
SCCP1_TimeoutHandler
static void(* SCCP1_TimeoutHandler)(void)
Definition sccp1.c:51
MASK_32_BIT_LOW
#define MASK_32_BIT_LOW
Definition sccp1.c:46
SCCP1_Timer_Stop
void SCCP1_Timer_Stop(void)
Stops the timer.
Definition sccp1.c:147
SCCP1_Timer_PeriodSet
void SCCP1_Timer_PeriodSet(uint32_t count)
Sets the SCCP1-Timer period count value.
Definition sccp1.c:156
SCCP1_TimeoutCallback
void SCCP1_TimeoutCallback(void)
This is the default callback with weak attribute. The user can override and implement the default cal...
CTRLLOOP_EXE
const struct TIMER_INTERFACE CTRLLOOP_EXE
Structure object of type TIMER_INTERFACE with the custom name given by the user in the Melody Driver ...
Definition sccp1.c:57
SCCP1_Timer_PeriodGet
static uint32_t SCCP1_Timer_PeriodGet(void)
This inline function gets the SCCP1-Timer period count value.
Definition sccp1.h:179
SCCP1_Timer_Deinitialize
void SCCP1_Timer_Deinitialize(void)
Deinitializes the SCCP1 to POR values.
Definition sccp1.c:115
SCCP1_Timer_TimeoutCallbackRegister
void SCCP1_Timer_TimeoutCallbackRegister(void(*handler)(void))
This function can be used to override default callback and to define custom callback for SCCP1 Timeou...
Definition sccp1.c:176
SCCP1_TimeoutCallbackRegister
void SCCP1_TimeoutCallbackRegister(void *handler)
This function can be used to override default callback and to define custom callback for SCCP1 Timeou...
Definition sccp1.c:184
SCCP1_Timer_Start
void SCCP1_Timer_Start(void)
Starts the timer.
Definition sccp1.c:138
SCCP1_Timer_CounterGet
static uint32_t SCCP1_Timer_CounterGet(void)
This inline function gets the SCCP1-Timer elapsed count value.
Definition sccp1.h:197
SCCP1_Timer_Initialize
void SCCP1_Timer_Initialize(void)
Initializes the SCCP1 module.
Definition sccp1.c:75
SCCP1_Timer_InterruptPrioritySet
void SCCP1_Timer_InterruptPrioritySet(enum INTERRUPT_PRIORITY priority)
Sets the Interrupt Priority Value.
Definition sccp1.c:171
TIMER_INTERFACE
Structure containing the function pointers of TIMER driver.
Definition timer_interface.h:61
TIMER_INTERFACE::Initialize
void(* Initialize)(void)
Pointer to MCCPx_Timer_Initialize or SCCPx_Timer_Initialize or TMRx_Initialize e.g....
Definition timer_interface.h:62