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

Loading...
Searching...
No Matches
tmr1.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 "../tmr1.h"
40#include "../timer_interface.h"
41
42// Section: Data Type Definitions
43
44#define MASK_32_BIT_LOW 0x0000FFFFU
45#define MASK_32_BIT_HIGH 0xFFFF0000U
46
47// Section: File specific functions
48
49 static void (*TMR1_TimeoutHandler)(void) = NULL;
50
51// Section: Driver Interface
52
53 const struct TIMER_INTERFACE Timer1 = {
54 .Initialize = &TMR1_Initialize,
55 .Deinitialize = &TMR1_Deinitialize,
56 .Start = &TMR1_Start,
57 .Stop = &TMR1_Stop,
58 #if TIMER_PERIODCOUNTSET_API_SUPPORT
59 .PeriodCountSet = &TMR1_PeriodCountSet,
60 #endif
61 .PeriodSet = &TMR1_PeriodSet,
62 .PeriodGet = &TMR1_PeriodGet,
63 .CounterGet = &TMR1_CounterGet,
64 .InterruptPrioritySet = &TMR1_InterruptPrioritySet,
65 .TimeoutCallbackRegister = &TMR1_TimeoutCallbackRegister,
66 .Tasks = NULL
67};
68
69// Section: TMR1 Module APIs
70
71 void TMR1_Initialize (void)
72{
73 //TCS FOSC/2; TSYNC disabled; TCKPS 1:1; TGATE disabled; TECS FOSC/2; PRWIP Write complete; TMWIP Write complete; TMWDIS disabled; TSIDL disabled; TON disabled;
74 T1CON = 0x0;
75 //TMR 0x0;
76 TMR1 = 0x0;
77 //Period 0.1 ms; Frequency 100,000,000 Hz; PR 9999;
78 PR1 = 0x270F;
79
80 TMR1_TimeoutCallbackRegister(&TMR1_TimeoutCallback);
81
82 TMR1_Start();
83}
84
85 void TMR1_Deinitialize (void)
86{
87 TMR1_Stop();
88
89 T1CON = 0x0;
90 TMR1 = 0x0;
91 PR1 = 0xFFFF;
92}
93
94 void TMR1_Start( void )
95{
96 //Clear interrupt flag
97 IFS0bits.T1IF = 0;
98 //Enable the interrupt
99 IEC0bits.T1IE = 1;
100
101 // Start the Timer
102 T1CONbits.TON = 1;
103}
104
105 void TMR1_Stop( void )
106{
107 // Stop the Timer
108 T1CONbits.TON = 0;
109
110 //Disable the interrupt
111 IEC0bits.T1IE = 0;
112}
113
114 void TMR1_PeriodSet(uint32_t count)
115{
116 PR1 = (uint16_t)(count & MASK_32_BIT_LOW);
117}
118
119 void TMR1_InterruptPrioritySet(enum INTERRUPT_PRIORITY priority)
120{
121 IPC0bits.T1IP = priority;
122}
123
124 void TMR1_TimeoutCallbackRegister(void (*handler)(void))
125{
126 if(NULL != handler)
127 {
128 TMR1_TimeoutHandler = handler;
129 }
130}
131
132 void __attribute__ ((weak)) TMR1_TimeoutCallback( void )
133{
134
135}
136
137 void __attribute__ ((interrupt, no_auto_psv)) _T1Interrupt(void)
138{
139 (*TMR1_TimeoutHandler)();
140 IFS0bits.T1IF = 0;
141}
142
143 void TMR1_PeriodCountSet(size_t count)
144{
145 PR1 = count & MASK_32_BIT_LOW;
146}
147
TMR1_TimeoutHandler
static void(* TMR1_TimeoutHandler)(void)
Definition tmr1.c:49
__attribute__
void __attribute__((weak))
Definition tmr1.c:132
TMR1_PeriodCountSet
void TMR1_PeriodCountSet(size_t count)
Definition tmr1.c:143
MASK_32_BIT_LOW
#define MASK_32_BIT_LOW
Definition tmr1.c:44
TMR1_PeriodGet
static uint32_t TMR1_PeriodGet(void)
This inline function gets the TMR1 period count value.
Definition tmr1.h:170
TMR1_Stop
void TMR1_Stop(void)
Stops the timer.
Definition tmr1.c:105
TMR1_Deinitialize
void TMR1_Deinitialize(void)
Deinitializes the TMR1 to POR values.
Definition tmr1.c:85
Timer1
const struct TIMER_INTERFACE Timer1
Structure object of type TIMER_INTERFACE with the custom name given by the user in the Melody Driver ...
Definition tmr1.c:53
TMR1_CounterGet
static uint32_t TMR1_CounterGet(void)
This inline function gets the TMR1 elapsed time value.
Definition tmr1.h:181
TMR1_TimeoutCallback
void TMR1_TimeoutCallback(void)
This is the default callback with weak attribute. The user can override and implement the default cal...
TMR1_TimeoutCallbackRegister
void TMR1_TimeoutCallbackRegister(void(*handler)(void))
This function can be used to override default callback and to define custom callback for TMR1 Timeout...
Definition tmr1.c:124
TMR1_InterruptPrioritySet
void TMR1_InterruptPrioritySet(enum INTERRUPT_PRIORITY priority)
Sets the TMR1 interrupt priority value.
Definition tmr1.c:119
TMR1_Initialize
void TMR1_Initialize(void)
Initializes the TMR1 module.
Definition tmr1.c:71
TMR1_PeriodSet
void TMR1_PeriodSet(uint32_t count)
Sets the TMR1 period count value.
Definition tmr1.c:114
TMR1_Start
void TMR1_Start(void)
Starts the timer.
Definition tmr1.c:94
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