-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinterrupts.c
121 lines (109 loc) · 6.87 KB
/
interrupts.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/******************************************************************************/
/* Files to Include */
/******************************************************************************/
#ifdef __XC32
#include <xc.h> /* Defines special funciton registers, CP0 regs */
#endif
#include <plib.h> /* Include to use PIC32 peripheral libraries */
#include <sys/attribs.h> /* For __ISR definition */
#include <stdint.h> /* For uint32_t definition */
#include <stdbool.h> /* For true/false definition */
#include "user.h"
#include "CommandEngine.h"
#include "../ESP8266/ESP8266.h"
/******************************************************************************/
/* Interrupt Vector Options */
/******************************************************************************/
/* */
/* VECTOR NAMES: */
/* */
/* _CORE_TIMER_VECTOR _COMPARATOR_2_VECTOR */
/* _CORE_SOFTWARE_0_VECTOR _UART_2A_VECTOR */
/* _CORE_SOFTWARE_1_VECTOR _I2C_2A_VECTOR */
/* _EXTERNAL_0_VECTOR _SPI_2_VECTOR */
/* _TIMER_1_VECTOR _SPI_2A_VECTOR */
/* _INPUT_CAPTURE_1_VECTOR _I2C_4_VECTOR */
/* _OUTPUT_COMPARE_1_VECTOR _UART_3_VECTOR */
/* _EXTERNAL_1_VECTOR _UART_2_VECTOR */
/* _TIMER_2_VECTOR _SPI_3A_VECTOR */
/* _INPUT_CAPTURE_2_VECTOR _I2C_3A_VECTOR */
/* _OUTPUT_COMPARE_2_VECTOR _UART_3A_VECTOR */
/* _EXTERNAL_2_VECTOR _SPI_4_VECTOR */
/* _TIMER_3_VECTOR _I2C_5_VECTOR */
/* _INPUT_CAPTURE_3_VECTOR _I2C_2_VECTOR */
/* _OUTPUT_COMPARE_3_VECTOR _FAIL_SAFE_MONITOR_VECTOR */
/* _EXTERNAL_3_VECTOR _RTCC_VECTOR */
/* _TIMER_4_VECTOR _DMA_0_VECTOR */
/* _INPUT_CAPTURE_4_VECTOR _DMA_1_VECTOR */
/* _OUTPUT_COMPARE_4_VECTOR _DMA_2_VECTOR */
/* _EXTERNAL_4_VECTOR _DMA_3_VECTOR */
/* _TIMER_5_VECTOR _DMA_4_VECTOR */
/* _INPUT_CAPTURE_5_VECTOR _DMA_5_VECTOR */
/* _OUTPUT_COMPARE_5_VECTOR _DMA_6_VECTOR */
/* _SPI_1_VECTOR _DMA_7_VECTOR */
/* _I2C_3_VECTOR _FCE_VECTOR */
/* _UART_1A_VECTOR _USB_1_VECTOR */
/* _UART_1_VECTOR _CAN_1_VECTOR */
/* _SPI_1A_VECTOR _CAN_2_VECTOR */
/* _I2C_1A_VECTOR _ETH_VECTOR */
/* _SPI_3_VECTOR _UART_4_VECTOR */
/* _I2C_1_VECTOR _UART_1B_VECTOR */
/* _CHANGE_NOTICE_VECTOR _UART_6_VECTOR */
/* _ADC_VECTOR _UART_2B_VECTOR */
/* _PMP_VECTOR _UART_5_VECTOR */
/* _COMPARATOR_1_VECTOR _UART_3B_VECTOR */
/* */
/* Refer to the device specific .h file in the C32 Compiler */
/* pic32mx\include\proc directory for a complete Vector and IRQ mnemonic */
/* listings for the PIC32 device. */
/* */
/* PRIORITY OPTIONS: */
/* */
/* (default) IPL0AUTO, IPL1, IPL2, ... IPL7 (highest) */
/* */
/* Example Shorthand Syntax */
/* */
/* void __ISR(<Vector Name>,<PRIORITY>) user_interrupt_routine_name(void) */
/* { */
/* <Clear Interrupt Flag> */
/* } */
/* */
/* For more interrupt macro examples refer to the C compiler User Guide in */
/* the C compiler /doc directory. */
/* */
/******************************************************************************/
/* Interrupt Routines */
/******************************************************************************/
// UART interrupt handler, set at priority level 2
void __ISR(_UART_2_VECTOR, ipl2) IntUart2Handler(void)
{
// Is this an RX interrupt?
if(INTGetFlag(INT_SOURCE_UART_RX(UART_CMD_MODULE_ID)))
{
char rchar = UARTGetDataByte(UART_CMD_MODULE_ID);
AddKeystroke(&CurrentCommandEngine, rchar);
// Clear the RX interrupt Flag
INTClearFlag(INT_SOURCE_UART_RX(UART_CMD_MODULE_ID));
}
// We don't care about TX interrupt
if ( INTGetFlag(INT_SOURCE_UART_TX(UART_CMD_MODULE_ID)) )
{
INTClearFlag(INT_SOURCE_UART_TX(UART_CMD_MODULE_ID));
}
}
void __ISR(_UART_4_VECTOR, ipl1) IntUart4Handler(void)
{
// Is this an RX interrupt?
if(INTGetFlag(INT_SOURCE_UART_RX(UART_WIFI_MODULE_ID)))
{
const char rchar = UARTGetDataByte(UART_WIFI_MODULE_ID);
PutcToWifiReceivedBuffer(rchar, &DefaultWifiService);
// Clear the RX interrupt Flag
INTClearFlag(INT_SOURCE_UART_RX(UART_WIFI_MODULE_ID));
}
// We don't care about TX interrupt
if ( INTGetFlag(INT_SOURCE_UART_TX(UART_WIFI_MODULE_ID)) )
{
INTClearFlag(INT_SOURCE_UART_TX(UART_WIFI_MODULE_ID));
}
}