This repository has been archived by the owner on Aug 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathStartupErrorCodes.c
77 lines (66 loc) · 1.74 KB
/
StartupErrorCodes.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* File: StartupErrorCodes.c
* Author: Chris Hajduk
*
* Created on October 15, 2013, 7:57 PM
*/
#include "main.h"
#include "StartupErrorCodes.h"
#include "debug.h"
unsigned int lastRuntimeErrors = 0;
void checkErrorCodes(){
lastRuntimeErrors = 0;
if (RCONbits.TRAPR == 1) {
error("TRAP Reset Occurred");
lastRuntimeErrors += (1 << 9);
RCONbits.TRAPR = 0;
}
if (RCONbits.IOPUWR == 1) {
error("Illegal Opcode Reset Occurred");
lastRuntimeErrors += (1 << 8);
RCONbits.IOPUWR = 0;
}
if (RCONbits.VREGS == 1) {
error("Voltage Reg Reset Occurred");
lastRuntimeErrors += (1 << 7);
RCONbits.VREGS = 0;
}
if (RCONbits.EXTR == 1) {
error("External Reset Occurred");
lastRuntimeErrors += (1 << 6);
RCONbits.EXTR = 0;
}
if (RCONbits.SWR == 1) {
error("Software Reset Occurred");
lastRuntimeErrors += (1 << 5);
RCONbits.SWR = 0;
}
if (RCONbits.WDTO == 1) {
error("Software WDT Reset Occurred");
lastRuntimeErrors += (1 << 4);
RCONbits.WDTO = 0;
}
if (RCONbits.SLEEP == 1) {
error("Sleep Mode Reset Occurred");
lastRuntimeErrors += (1 << 3);
RCONbits.SLEEP = 0;
}
if (RCONbits.IDLE == 1) {
error("Idle Mode Reset Occurred");
lastRuntimeErrors += (1 << 2);
RCONbits.IDLE = 0;
}
if (RCONbits.BOR == 1) {
error("Brown Out Reset Occurred");
lastRuntimeErrors += (1 << 1);
RCONbits.BOR = 0;
}
if (RCONbits.POR == 1) {
error("Power On Reset Occurred");
lastRuntimeErrors += 1;
RCONbits.POR = 0;
}
}
unsigned int getErrorCodes(){
return lastRuntimeErrors;
}