1.1 --- a/init.c Wed Oct 17 17:56:15 2018 +0200
1.2 +++ b/init.c Thu Oct 18 11:13:02 2018 +0200
1.3 @@ -228,8 +228,8 @@
1.4
1.5 /* Disable interrupt (UxRIE) and clear flag (UxRIF). */
1.6
1.7 - CLR_REG(UARTIEC, 2 << UART_INT_FLAGS(channel));
1.8 - CLR_REG(UARTIFS, 2 << UART_INT_FLAGS(channel));
1.9 + CLR_REG(UARTIEC, UART_INT_FLAGS(channel, UxRIE));
1.10 + CLR_REG(UARTIFS, UART_INT_FLAGS(channel, UxRIF));
1.11 }
1.12
1.13 /* Configure interrupts caused by the UART. */
1.14 @@ -246,7 +246,7 @@
1.15
1.16 /* Enable interrupt (UxRIE). */
1.17
1.18 - SET_REG(UARTIEC, 2 << UART_INT_FLAGS(channel));
1.19 + SET_REG(UARTIEC, UART_INT_FLAGS(channel, UxRIE));
1.20 }
1.21
1.22 /* Enable a UART. */
1.23 @@ -299,7 +299,7 @@
1.24
1.25 /* Return the UART interrupt flags shift offset. */
1.26
1.27 -int UART_INT_FLAGS(int channel)
1.28 +int UART_INT_FLAGS(int channel, uint8_t flags)
1.29 {
1.30 - return UARTINTBASE + (channel - UARTMIN) * UARTINTSTEP;
1.31 + return (flags & 0b111) << (UARTINTBASE + (channel - UARTMIN) * UARTINTSTEP);
1.32 }
2.1 --- a/init.h Wed Oct 17 17:56:15 2018 +0200
2.2 +++ b/init.h Thu Oct 18 11:13:02 2018 +0200
2.3 @@ -50,6 +50,6 @@
2.4 uint32_t UART_IPC_PRI(int channel, uint8_t pri, uint8_t sub);
2.5 uint32_t UART_IPC_REG(int channel);
2.6
2.7 -int UART_INT_FLAGS(int channel);
2.8 +int UART_INT_FLAGS(int channel, uint8_t flags);
2.9
2.10 #endif /* __INIT_H__ */
3.1 --- a/main.c Wed Oct 17 17:56:15 2018 +0200
3.2 +++ b/main.c Thu Oct 18 11:13:02 2018 +0200
3.3 @@ -89,7 +89,7 @@
3.4 {
3.5 /* Check for a UART receive interrupt condition (UxRIF). */
3.6
3.7 - if (REG(IFS1) & (1 << 8))
3.8 + if (REG(UARTIFS) & UART_INT_FLAGS(1, UxRIF))
3.9 {
3.10 /* Write the received data back. */
3.11
3.12 @@ -98,7 +98,7 @@
3.13
3.14 /* Clear the UART interrupt condition. */
3.15
3.16 - CLR_REG(IFS1, 1 << 8);
3.17 + CLR_REG(UARTIFS, UART_INT_FLAGS(1, UxRIF));
3.18 INV_REG(PORTA, 1 << 2);
3.19 }
3.20 }
4.1 --- a/pic32.h Wed Oct 17 17:56:15 2018 +0200
4.2 +++ b/pic32.h Thu Oct 18 11:13:02 2018 +0200
4.3 @@ -137,9 +137,20 @@
4.4 #define UxBRG 0x40
4.5
4.6 #define UARTIEC IEC1
4.7 +
4.8 +#define UxEIE 1
4.9 +#define UxRIE 2
4.10 +#define UxTIE 4
4.11 +
4.12 #define UARTIFS IFS1
4.13 +
4.14 +#define UxEIF 1
4.15 +#define UxRIF 2
4.16 +#define UxTIF 4
4.17 +
4.18 #define UARTINTBASE 7
4.19 #define UARTINTSTEP 14
4.20 +
4.21 #define UART1IPC IPC8
4.22 #define UART1IPCBASE 0
4.23 #define UART2IPC IPC9