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
32SI_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
73SI_INTERRUPT (TIMER0_ISR, TIMER0_IRQn)
74{
75 TCON_TF0 = 0;
76
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 {
88 // reset timer counter (should be a define)
90
91 // clear the modbus receiver
92 PetitRxBufferReset();
93
94 // transceiver on receive mode
96
98 }
100}
101
102
116SI_INTERRUPT (TIMER1_ISR, TIMER1_IRQn)
117{
118 static unsigned char t1c = 0;
119 TCON_TF1 = 0;
120
121 TH0 = (0x80 << TH0_TH0__SHIFT);
122
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
137}
138
139
155SI_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 {
178 }
179 }
180
182}
183
184
196SI_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
#define WDT_RESET()
Definition Interrupts.c:18
SI_INTERRUPT(CMP1_ISR, CMP1_IRQn)
Definition Interrupts.c:32
void PetitPortDirRx()
void PetitPortTimerStop()
uint8_t T0C_TOP
volatile t1Count_t t1Count
volatile uint8_t t0Count
void mbWDTsm(void)
bool cprif
void VinSm(void)
#define UART0_PIN_OFF()
Definition hardware.h:91
#define TIMER0_PINO_OFF()
Definition hardware.h:85
#define TIMER0_PINO_ON()
Definition hardware.h:84
#define nLED
Definition hardware.h:49
#define TIMER1_PIN_OFF()
Definition hardware.h:89
#define TIMER0_PINI_OFF()
Definition hardware.h:87
#define ADC0_PIN_OFF()
Definition hardware.h:93
#define ADC0_PIN_ON()
Definition hardware.h:92
#define TIMER1_PIN_ON()
Definition hardware.h:88
#define TIMER0_PINI_ON()
Definition hardware.h:86
#define UART0_PIN_ON()
Definition hardware.h:90
#define RESET_P
Definition hardware.h:48