Bar Logo 3.8/7.6 kw Totem pole Demonstration Application (Part-No. (not specified))
 
Content
     
Loading...
Searching...
No Matches
reset.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#include <stdbool.h>
39#include <stdint.h>
40#include <xc.h>
41#include "../reset.h"
42
43// Section: File specific functions
44
45
51static bool RESET_CauseFromTrap(uint16_t resetCause)
52{
53 bool resetStatus = false;
54
55 if((uint16_t)(resetCause & (uint16_t) RESET_MASK_TRAPR) == (uint16_t) RESET_MASK_TRAPR)
56 {
57 resetStatus = true;
58 }
59
60 return resetStatus;
61}
62
68static bool RESET_CauseFromIllegalOpcode(uint16_t resetCause)
69{
70 bool resetStatus = false;
71
72 if((uint16_t)(resetCause & (uint16_t) RESET_MASK_IOPUWR) == (uint16_t) RESET_MASK_IOPUWR)
73 {
74 resetStatus = true;
75 }
76
77 return resetStatus;
78}
79
85static bool RESET_CauseFromConfigurationMismatch(uint16_t resetCause)
86{
87 bool resetStatus = false;
88
89 if((uint16_t)(resetCause & (uint16_t) RESET_MASK_CM) == (uint16_t) RESET_MASK_CM)
90 {
91 resetStatus = true;
92 }
93
94 return resetStatus;
95}
96
102static bool RESET_CauseFromExternal(uint16_t resetCause)
103{
104 bool resetStatus = false;
105
106 if((uint16_t)(resetCause & (uint16_t) RESET_MASK_EXTR) == (uint16_t) RESET_MASK_EXTR)
107 {
108 resetStatus = true;
109 }
110
111 return resetStatus;
112}
113
119static bool RESET_CauseFromSoftware(uint16_t resetCause)
120{
121 bool resetStatus = false;
122
123 if((uint16_t)(resetCause & (uint16_t) RESET_MASK_SWR) == (uint16_t) RESET_MASK_SWR)
124 {
125 resetStatus = true;
126 }
127
128 return resetStatus;
129}
130
136static bool RESET_CauseFromWatchdogTimer(uint16_t resetCause)
137{
138 bool resetStatus = false;
139
140 if((uint16_t)(resetCause & (uint16_t) RESET_MASK_WDTO) == (uint16_t) RESET_MASK_WDTO)
141 {
142 resetStatus = true;
143 }
144
145 return resetStatus;
146}
147
153static void RESET_CauseClear(enum RESET_MASKS resetFlagMask)
154{
155 RCON = RCON & (~resetFlagMask);
156}
157
158uint16_t RESET_CauseGet(void)
159{
160 return RCON;
161}
162
163void __attribute__ ((weak)) RESET_CauseHandler(void)
164{
165 uint16_t resetCause = RESET_CauseGet();
166
167 if(RESET_CauseFromTrap(resetCause))
168 {
170 }
171
172 if(RESET_CauseFromIllegalOpcode(resetCause))
173 {
175 }
176
178 {
180 }
181
182 if(RESET_CauseFromExternal(resetCause))
183 {
185 }
186
187 if(RESET_CauseFromSoftware(resetCause))
188 {
190 }
191
192 if(RESET_CauseFromWatchdogTimer(resetCause))
193 {
195 }
196}
197
199{
200 RCON = 0x00;
201}
static void RESET_CauseClear(enum RESET_MASKS resetFlagMask)
RESET cause from Clear
Definition reset.c:153
static bool RESET_CauseFromExternal(uint16_t resetCause)
RESET cause from External
Definition reset.c:102
static bool RESET_CauseFromTrap(uint16_t resetCause)
RESET cause from trap.
Definition reset.c:51
RESET_MASKS
Defines the RESET cause mask location
Definition reset_types.h:60
void RESET_CauseHandler(void)
It handles the reset cause by clearing the cause register values. This is a weak attribute function....
Definition reset.c:163
static bool RESET_CauseFromWatchdogTimer(uint16_t resetCause)
RESET cause from Watchdog Time
Definition reset.c:136
static bool RESET_CauseFromSoftware(uint16_t resetCause)
RESET cause from Software
Definition reset.c:119
uint16_t RESET_CauseGet(void)
Returns the cause of previous reset.
Definition reset.c:158
void RESET_CauseClearAll(void)
Clears the Reset Cause register.
Definition reset.c:198
static bool RESET_CauseFromConfigurationMismatch(uint16_t resetCause)
RESET cause from Configuration Mismatch
Definition reset.c:85
static bool RESET_CauseFromIllegalOpcode(uint16_t resetCause)
RESET cause from Illegal Opcode
Definition reset.c:68
@ RESET_MASK_WDTO
Definition reset_types.h:62
@ RESET_MASK_EXTR
Definition reset_types.h:64
@ RESET_MASK_SWR
Definition reset_types.h:63
@ RESET_MASK_CM
Definition reset_types.h:65
@ RESET_MASK_IOPUWR
Definition reset_types.h:66
@ RESET_MASK_TRAPR
Definition reset_types.h:67