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

Loading...
Searching...
No Matches
dmt.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#include <xc.h>
40#include <stddef.h>
41#include "../dmt.h"
42#include "../interrupt.h"
43
44// Section: Private Variable Definitions
45 static bool bPreCleared = false;
46uint32_t calibOffset = 0;
47 static void (*DMT_EventHandler)(void) = NULL;
48
49// Section: File specific functions
50
51 void DMT_Calibrate(void);
52
53// Section: DMT Module APIs
54 void DMT_Initialize(void)
55{
56 INTERRUPT_GlobalDisable();
57 DMT_Calibrate();
58 INTERRUPT_GlobalEnable();
59
60 DMT_EventCallbackRegister(&DMT_EventCallback);
61
62 IEC2bits.DMTIE = 1U;
63}
64
65 void DMT_Enable(void)
66{
67 // Set the Bit ON = 1
68 DMTCON = 0x8000;
69}
70
71 void DMT_PreClear(void)
72{
73 DMTPRECLR = 0x4000;
74
75 // To keep track of Preclear operation is performed
76 bPreCleared = true;
77}
78
79 void DMT_Clear(void)
80{
81 bPreCleared = false;
82 while((DMTSTAT & 0x0001) != 0x0001)
83 {
84 }
85
86 DMTCLR = 0x0008;
87}
88
89 bool DMT_IsWindowOpen(void)
90{
91 bool status = false;
92
93 if((DMTSTAT & 0x0001) == 0x0001)
94 {
95 status = true;
96 }
97
98 return status;
99}
100
101 bool DMT_IsPreCleared(void)
102{
103 return bPreCleared;
104}
105
106uint32_t DMT_TimeoutCounterGet(void)
107{
108 uint32_t counter = 0;
109 counter = (uint32_t)(DMTPSCNTH & 0x0000FFFF) << 16;
110 return (counter | DMTPSCNTL);
111}
112
113uint32_t DMT_WindowTimeoutCounterGet(void)
114{
115 uint32_t winTimeoutCounter = 0;
116 winTimeoutCounter = (uint32_t)(DMTPSINTVH & 0x0000FFFF) << 16;
117 return (winTimeoutCounter | DMTPSINTVL);
118}
119
120uint16_t DMT_StatusGet(void)
121{
122 uint16_t status = 0;
123 status = (uint16_t)(DMTSTAT & 0xE1);
124 return status;
125}
126
127uint32_t DMT_CounterGet(void)
128{
129 uint32_t counter = 0;
130 counter = (uint32_t)(DMTCNTH & 0x0000FFFF) << 16;
131 return (counter | DMTCNTL);
132}
133
134 void DMT_EventCallbackRegister(void (*handler)(void))
135{
136 if(NULL != handler)
137 {
138 DMT_EventHandler = handler;
139 }
140}
141
142 void __attribute__ ((weak)) DMT_EventCallback( void )
143{
144
145}
146
147
148 void __attribute__ ((interrupt, no_auto_psv)) _DMTInterrupt(void)
149{
150 if(NULL != DMT_EventHandler)
151 {
152 (*DMT_EventHandler)();
153 }
154 IFS2bits.DMTIF = 0U;
155}
156
__attribute__
void __attribute__((weak))
Definition dmt.c:142
bPreCleared
static bool bPreCleared
Definition dmt.c:45
calibOffset
uint32_t calibOffset
Definition dmt.c:46
DMT_EventHandler
static void(* DMT_EventHandler)(void)
Definition dmt.c:47
DMT_Calibrate
void DMT_Calibrate(void)
status
size_t status
Definition uart1.c:99
DMT_StatusGet
uint16_t DMT_StatusGet(void)
Gets the DMT status.
Definition dmt.c:120
DMT_EventCallback
void DMT_EventCallback(void)
This is the default callback with weak attribute. The user can override and implement the default cal...
DMT_Initialize
void DMT_Initialize(void)
Initializes the DMT module.
Definition dmt.c:54
DMT_PreClear
void DMT_PreClear(void)
Writes the PreClear Pattern for DMTPRECLR register.
Definition dmt.c:71
DMT_IsPreCleared
bool DMT_IsPreCleared(void)
Checks for the PreClear sequence was initiated and done before the Clear sequence is done.
Definition dmt.c:101
DMT_IsWindowOpen
bool DMT_IsWindowOpen(void)
Returns the Window Open status.
Definition dmt.c:89
DMT_EventCallbackRegister
void DMT_EventCallbackRegister(void(*handler)(void))
This function can be used to override default callback and to define custom callback for DMT Event ev...
Definition dmt.c:134
DMT_WindowTimeoutCounterGet
uint32_t DMT_WindowTimeoutCounterGet(void)
Reads the DMT Window Interval Counter.
Definition dmt.c:113
DMT_CounterGet
uint32_t DMT_CounterGet(void)
Returns the current counter value.
Definition dmt.c:127
DMT_Enable
void DMT_Enable(void)
Enables the DMT module.
Definition dmt.c:65
DMT_TimeoutCounterGet
uint32_t DMT_TimeoutCounterGet(void)
Reads the DMT counter register.
Definition dmt.c:106
DMT_Clear
void DMT_Clear(void)
Checks the PreClear Status and clears the DMT Fetch Counter.
Definition dmt.c:79
INTERRUPT_GlobalEnable
static void INTERRUPT_GlobalEnable(void)
Enables the global interrupt bit.
Definition interrupt.h:65
INTERRUPT_GlobalDisable
static void INTERRUPT_GlobalDisable(void)
Disables the global interrupt bit.
Definition interrupt.h:76