Bar Logo 3.8/7.6 kw Totem pole Demonstration Application (Part-No. (not specified))
 
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
45static bool bPreCleared = false;
46uint32_t calibOffset = 0;
47static void (*DMT_EventHandler)(void) = NULL;
48
49// Section: File specific functions
50
51void DMT_Calibrate(void);
52
53// Section: DMT Module APIs
55{
59
61
62 IEC2bits.DMTIE = 1U;
63}
64
65void DMT_Enable(void)
66{
67 // Set the Bit ON = 1
68 DMTCON = 0x8000;
69}
70
71void DMT_PreClear(void)
72{
73 DMTPRECLR = 0x4000;
74
75 // To keep track of Preclear operation is performed
76 bPreCleared = true;
77}
78
79void DMT_Clear(void)
80{
81 bPreCleared = false;
82 while((DMTSTAT & 0x0001) != 0x0001)
83 {
84 }
85
86 DMTCLR = 0x0008;
87}
88
90{
91 bool status = false;
92
93 if((DMTSTAT & 0x0001) == 0x0001)
94 {
95 status = true;
96 }
97
98 return status;
99}
100
102{
103 return bPreCleared;
104}
105
107{
108 uint32_t counter = 0;
109 counter = (uint32_t)(DMTPSCNTH & 0x0000FFFF) << 16;
110 return (counter | DMTPSCNTL);
111}
112
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
134void DMT_EventCallbackRegister(void (*handler)(void))
135{
136 if(NULL != handler)
137 {
138 DMT_EventHandler = handler;
139 }
140}
141
142void __attribute__ ((weak)) DMT_EventCallback( void )
143{
144
145}
146
147
148void __attribute__ ((interrupt, no_auto_psv)) _DMTInterrupt(void)
149{
150 if(NULL != DMT_EventHandler)
151 {
152 (*DMT_EventHandler)();
153 }
154 IFS2bits.DMTIF = 0U;
155}
156
size_t status
Definition uart1.c:99
uint16_t DMT_StatusGet(void)
Gets the DMT status.
Definition dmt.c:120
void DMT_EventCallback(void)
This is the default callback with weak attribute. The user can override and implement the default cal...
Definition dmt.c:142
void DMT_Initialize(void)
Initializes the DMT module.
Definition dmt.c:54
void DMT_PreClear(void)
Writes the PreClear Pattern for DMTPRECLR register.
Definition dmt.c:71
bool DMT_IsPreCleared(void)
Checks for the PreClear sequence was initiated and done before the Clear sequence is done.
Definition dmt.c:101
bool DMT_IsWindowOpen(void)
Returns the Window Open status.
Definition dmt.c:89
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
uint32_t DMT_WindowTimeoutCounterGet(void)
Reads the DMT Window Interval Counter.
Definition dmt.c:113
uint32_t DMT_CounterGet(void)
Returns the current counter value.
Definition dmt.c:127
void DMT_Enable(void)
Enables the DMT module.
Definition dmt.c:65
uint32_t DMT_TimeoutCounterGet(void)
Reads the DMT counter register.
Definition dmt.c:106
void DMT_Clear(void)
Checks the PreClear Status and clears the DMT Fetch Counter.
Definition dmt.c:79
static void INTERRUPT_GlobalEnable(void)
Enables the global interrupt bit.
Definition interrupt.h:65
static void INTERRUPT_GlobalDisable(void)
Disables the global interrupt bit.
Definition interrupt.h:76
static bool bPreCleared
Definition dmt.c:45
uint32_t calibOffset
Definition dmt.c:46
void _DMTInterrupt(void)
Definition dmt.c:148
static void(* DMT_EventHandler)(void)
Definition dmt.c:47
void DMT_Calibrate(void)