IoT Supervisor
0.0
Loading...
Searching...
No Matches
Interrupts.c
Go to the documentation of this file.
1
12
// USER INCLUDES
13
#include "
hardware.h
"
14
#include <SI_EFM8BB1_Register_Enums.h>
15
#include "PetitModbusPort.h"
16
#include "
IoT_Supervisor.h
"
17
18
#define WDT_RESET() (WDTCN = 0xA5)
19
25
32
SI_INTERRUPT
(CMP1_ISR, CMP1_IRQn)
33
{
34
static
bool
firstInterrupt =
true
;
35
// state machine immediate off
36
// clear falling edge flag (should not trigger to but whatever)
37
if
(CMP1CN0 & CMP1CN0_CPFIF__BMASK)
38
{
39
CMP1CN0 &= ~(CMP1CN0_CPFIF__BMASK);
40
}
41
// clear rising edge flag
42
// run the Vin state machine to shut down the IoT device
43
if
(CMP1CN0 & CMP1CN0_CPRIF__BMASK)
44
{
45
CMP1CN0 &= ~(CMP1CN0_CPRIF__BMASK);
46
// interrupt fires once on startup
47
if
(firstInterrupt)
48
firstInterrupt =
false
;
49
else
50
{
51
RESET_P
=
false
;
// reset now.
52
nLED
=
false
;
// light led
53
cprif
=
true
;
54
}
55
}
56
}
57
58
73
SI_INTERRUPT
(TIMER0_ISR, TIMER0_IRQn)
74
{
75
TCON_TF0 = 0;
76
77
TIMER0_PINO_ON
();
78
79
// reset timer counter
80
TL0 = (0x20 << TL0_TL0__SHIFT);
81
82
// this timer implements both a software and a hardware timer.
83
// multiple counts of the software timer are used for slower modbus speeds
84
t0Count
++;
85
if
(
t0Count
>
T0C_TOP
)
86
{
87
TIMER0_PINI_ON
();
88
// reset timer counter (should be a define)
89
PetitPortTimerStop
();
90
91
// clear the modbus receiver
92
PetitRxBufferReset();
93
94
// transceiver on receive mode
95
PetitPortDirRx
();
96
97
TIMER0_PINI_OFF
();
98
}
99
TIMER0_PINO_OFF
();
100
}
101
102
116
SI_INTERRUPT
(TIMER1_ISR, TIMER1_IRQn)
117
{
118
static
unsigned
char
t1c = 0;
119
TCON_TF1 = 0;
120
121
TH0 = (0x80 << TH0_TH0__SHIFT);
122
123
TIMER1_PIN_ON
();
124
125
t1Count
++;
126
127
// run every 8ms
128
if
((t1c & 7) == 0)
129
{
130
VinSm
();
131
mbWDTsm
();
132
WDT_RESET
();
133
}
134
t1c++;
135
136
TIMER1_PIN_OFF
();
137
}
138
139
155
SI_INTERRUPT
(UART0_ISR, UART0_IRQn)
156
{
157
//Buffer and clear flags immediately so we don't miss an interrupt while processing
158
uint8_t flags = SCON0 & (SCON0_RI__BMASK | SCON0_TI__BMASK);
159
SCON0 &= ~flags;
160
161
UART0_PIN_ON
();
162
163
if
(flags & SCON0_RI__SET)
164
{
165
PetitRxBufferInsert(SBUF0);
166
}
167
168
if
(flags & SCON0_TI__SET)
169
{
170
unsigned
char
res;
171
if
(PetitTxBufferPop(&res))
172
{
173
SBUF0 = res;
174
}
175
else
176
{
177
PetitPortDirRx
();
178
}
179
}
180
181
UART0_PIN_OFF
();
182
}
183
184
196
SI_INTERRUPT
(ADC0EOC_ISR, ADC0EOC_IRQn)
197
{
198
char
conv_count;
199
ADC0CN0_ADINT = 0;
// clear interrupt flag
200
201
ADC0_PIN_ON
();
202
203
// top 6 bits for the conversion count
204
// bottom 10 bits for the ADC value (it's a 10-bit ADC)
205
conv_count = PetitInputRegisters[0] >> 10 & 0x3F;
206
conv_count++;
207
PetitInputRegisters[0] = (uint16_t) conv_count << 10 | ADC0 >> 6;
208
209
ADC0_PIN_OFF
();
210
}
211
212
// group Application Interrupts
WDT_RESET
#define WDT_RESET()
Definition
Interrupts.c:18
IoT_Supervisor.h
SI_INTERRUPT
SI_INTERRUPT(CMP1_ISR, CMP1_IRQn)
Definition
Interrupts.c:32
PetitPortDirRx
void PetitPortDirRx()
Definition
PetitModbusPort.c:59
PetitPortTimerStop
void PetitPortTimerStop()
Definition
PetitModbusPort.c:38
T0C_TOP
uint8_t T0C_TOP
Definition
IoT Supervisor_main.c:55
t1Count
volatile t1Count_t t1Count
Definition
IoT Supervisor_main.c:50
t0Count
volatile uint8_t t0Count
Definition
IoT Supervisor_main.c:53
mbWDTsm
void mbWDTsm(void)
Definition
IoT Supervisor_main.c:308
cprif
bool cprif
Definition
IoT Supervisor_main.c:190
VinSm
void VinSm(void)
Definition
IoT Supervisor_main.c:204
hardware.h
UART0_PIN_OFF
#define UART0_PIN_OFF()
Definition
hardware.h:91
TIMER0_PINO_OFF
#define TIMER0_PINO_OFF()
Definition
hardware.h:85
TIMER0_PINO_ON
#define TIMER0_PINO_ON()
Definition
hardware.h:84
nLED
#define nLED
Definition
hardware.h:49
TIMER1_PIN_OFF
#define TIMER1_PIN_OFF()
Definition
hardware.h:89
TIMER0_PINI_OFF
#define TIMER0_PINI_OFF()
Definition
hardware.h:87
ADC0_PIN_OFF
#define ADC0_PIN_OFF()
Definition
hardware.h:93
ADC0_PIN_ON
#define ADC0_PIN_ON()
Definition
hardware.h:92
TIMER1_PIN_ON
#define TIMER1_PIN_ON()
Definition
hardware.h:88
TIMER0_PINI_ON
#define TIMER0_PINI_ON()
Definition
hardware.h:86
UART0_PIN_ON
#define UART0_PIN_ON()
Definition
hardware.h:90
RESET_P
#define RESET_P
Definition
hardware.h:48
src
Interrupts.c
Generated by
1.9.8