Bar Logo 3.8/7.6 kw Totem pole Demonstration Application (Part-No. (not specified))
 
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
49static void (*TMR1_TimeoutHandler)(void) = NULL;
50
51// Section: Driver Interface
52
53const struct TIMER_INTERFACE Timer1 = {
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 = &TMR1_Tasks
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}
83
85{
86 TMR1_Stop();
87
88 T1CON = 0x0;
89 TMR1 = 0x0;
90 PR1 = 0x0;
91}
92
93void TMR1_Start( void )
94{
95 // Start the Timer
96 T1CONbits.TON = 1;
97}
98
99void TMR1_Stop( void )
100{
101 // Stop the Timer
102 T1CONbits.TON = 0;
103}
104
105void TMR1_PeriodSet(uint32_t count)
106{
107 PR1 = (uint16_t)(count & MASK_32_BIT_LOW);
108}
109
110void TMR1_InterruptPrioritySet(enum INTERRUPT_PRIORITY priority)
111{
112 IPC0bits.T1IP = priority;
113}
114
115void TMR1_TimeoutCallbackRegister(void (*handler)(void))
116{
117 if(NULL != handler)
118 {
119 TMR1_TimeoutHandler = handler;
120 }
121}
122
123void __attribute__ ((weak)) TMR1_TimeoutCallback( void )
124{
125
126}
127
128void TMR1_Tasks( void )
129{
130 if(IFS0bits.T1IF == 1)
131 {
132 (*TMR1_TimeoutHandler)();
133 IFS0bits.T1IF = 0;
134 }
135}
136
137void TMR1_PeriodCountSet(size_t count)
138{
139 PR1 = count & MASK_32_BIT_LOW;
140}
141
static uint32_t TMR1_PeriodGet(void)
This inline function gets the TMR1 period count value.
Definition tmr1.h:183
void TMR1_Tasks(void)
This function is used to implement the tasks for polled implementations.
Definition tmr1.c:129
void TMR1_Stop(void)
Stops the timer.
Definition tmr1.c:100
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:194
void TMR1_TimeoutCallback(void)
This is the default callback with weak attribute. The user can override and implement the default cal...
Definition tmr1.c:124
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:116
void TMR1_InterruptPrioritySet(enum INTERRUPT_PRIORITY priority)
Sets the TMR1 interrupt priority value.
Definition tmr1.c:111
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:106
void TMR1_Start(void)
Starts the timer.
Definition tmr1.c:94
Structure containing the function pointers of TIMER driver.
void(* Initialize)(void)
Pointer to MCCPx_Timer_Initialize or SCCPx_Timer_Initialize or TMRx_Initialize e.g....
static void(* TMR1_TimeoutHandler)(void)
Definition tmr1.c:49
void TMR1_PeriodCountSet(size_t count)
Definition tmr1.c:138
#define MASK_32_BIT_LOW
Definition tmr1.c:44
This is the generated driver header file for the TMR1 driver.