Bar Logo 4kW dsPIC33C PSFB DC-DC DA (Part-No. )
 
Content
     
Loading...
Searching...
No Matches
tmr1.c
Go to the documentation of this file.
1
17/*
18© [2025] 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
49static void (*TMR1_TimeoutHandler)(void) = NULL;
50
51// Section: Driver Interface
52
53const 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
71void 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
81
82 TMR1_Start();
83}
84
86{
87 TMR1_Stop();
88
89 T1CON = 0x0;
90 TMR1 = 0x0;
91 PR1 = 0xFFFF;
92}
93
94void 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
105void TMR1_Stop( void )
106{
107 // Stop the Timer
108 T1CONbits.TON = 0;
109
110 //Disable the interrupt
111 IEC0bits.T1IE = 0;
112}
113
114void TMR1_PeriodSet(uint32_t count)
115{
116 PR1 = (uint16_t)(count & MASK_32_BIT_LOW);
117}
118
119void TMR1_InterruptPrioritySet(enum INTERRUPT_PRIORITY priority)
120{
121 IPC0bits.T1IP = priority;
122}
123
124void TMR1_TimeoutCallbackRegister(void (*handler)(void))
125{
126 if(NULL != handler)
127 {
128 TMR1_TimeoutHandler = handler;
129 }
130}
131
133{
134
135}
136
137void __attribute__ ((interrupt, no_auto_psv)) _T1Interrupt(void)
138{
139 (*TMR1_TimeoutHandler)();
140 IFS0bits.T1IF = 0;
141}
142
143void TMR1_PeriodCountSet(size_t count)
144{
145 PR1 = count & MASK_32_BIT_LOW;
146}
147
static void(* TMR1_TimeoutHandler)(void)
Definition tmr1.c:49
void __attribute__((weak))
Definition tmr1.c:132
void TMR1_PeriodCountSet(size_t count)
Definition tmr1.c:143
#define MASK_32_BIT_LOW
Definition tmr1.c:44
This is the generated driver header file for the TMR1 driver.
static uint32_t TMR1_PeriodGet(void)
This inline function gets the TMR1 period count value.
Definition tmr1.h:170
void TMR1_Stop(void)
Stops the timer.
Definition tmr1.c:105
void TMR1_Deinitialize(void)
Deinitializes the TMR1 to POR values.
Definition tmr1.c:85
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
static uint32_t TMR1_CounterGet(void)
This inline function gets the TMR1 elapsed time value.
Definition tmr1.h:181
void TMR1_TimeoutCallback(void)
This is the default callback with weak attribute. The user can override and implement the default cal...
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
void TMR1_InterruptPrioritySet(enum INTERRUPT_PRIORITY priority)
Sets the TMR1 interrupt priority value.
Definition tmr1.c:119
void TMR1_Initialize(void)
Initializes the TMR1 module.
Definition tmr1.c:71
void TMR1_PeriodSet(uint32_t count)
Sets the TMR1 period count value.
Definition tmr1.c:114
void TMR1_Start(void)
Starts the timer.
Definition tmr1.c:94
Structure containing the function pointers of TIMER driver.