ELRS - Fix EXTI irq clash and SPI transfer failure.
[betaflight.git] / src / main / drivers / nvic.h
blob216ed7ae05d885683f1f815eb2b5e5e120338281
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #pragma once
24 // can't use 0
25 #define NVIC_PRIO_MAX NVIC_BUILD_PRIORITY(0, 1)
26 #define NVIC_PRIO_TIMER NVIC_BUILD_PRIORITY(1, 1)
27 #define NVIC_PRIO_BARO_EXTI NVIC_BUILD_PRIORITY(0x0f, 0x0f)
28 #define NVIC_PRIO_SONAR_EXTI NVIC_BUILD_PRIORITY(2, 0) // maybe increase slightly
29 #define NVIC_PRIO_DSHOT_DMA NVIC_BUILD_PRIORITY(2, 1)
30 #define NVIC_PRIO_TRANSPONDER_DMA NVIC_BUILD_PRIORITY(3, 0)
32 // RX_SPI must be lower priority than SPI DMA so EXTI ISRs don't interfere with SPI transfers and transfer complete callbacks
33 #define NVIC_PRIO_RX_SPI_INT_EXTI NVIC_BUILD_PRIORITY(3, 0x0f)
34 #define NVIC_PRIO_RX_INT_EXTI NVIC_BUILD_PRIORITY(3, 0x0f)
35 #define NVIC_PRIO_RX_BUSY_EXTI NVIC_BUILD_PRIORITY(3, 0x0f)
37 #define NVIC_PRIO_MPU_INT_EXTI NVIC_BUILD_PRIORITY(0x0f, 0x0f)
38 #define NVIC_PRIO_MAG_INT_EXTI NVIC_BUILD_PRIORITY(0x0f, 0x0f)
39 #define NVIC_PRIO_WS2811_DMA NVIC_BUILD_PRIORITY(1, 2) // TODO - is there some reason to use high priority? (or to use DMA IRQ at all?)
40 #define NVIC_PRIO_SERIALUART_TXDMA NVIC_BUILD_PRIORITY(1, 1) // Highest of all SERIALUARTx_TXDMA
41 #define NVIC_PRIO_SERIALUART1_TXDMA NVIC_BUILD_PRIORITY(1, 1)
42 #define NVIC_PRIO_SERIALUART1_RXDMA NVIC_BUILD_PRIORITY(1, 1)
43 #define NVIC_PRIO_SERIALUART1 NVIC_BUILD_PRIORITY(1, 1)
44 #define NVIC_PRIO_SERIALUART2_TXDMA NVIC_BUILD_PRIORITY(1, 0)
45 #define NVIC_PRIO_SERIALUART2_RXDMA NVIC_BUILD_PRIORITY(1, 1)
46 #define NVIC_PRIO_SERIALUART2 NVIC_BUILD_PRIORITY(1, 2)
47 #define NVIC_PRIO_SERIALUART3_TXDMA NVIC_BUILD_PRIORITY(1, 0)
48 #define NVIC_PRIO_SERIALUART3_RXDMA NVIC_BUILD_PRIORITY(1, 1)
49 #define NVIC_PRIO_SERIALUART3 NVIC_BUILD_PRIORITY(1, 2)
50 #define NVIC_PRIO_SERIALUART4_TXDMA NVIC_BUILD_PRIORITY(1, 0)
51 #define NVIC_PRIO_SERIALUART4_RXDMA NVIC_BUILD_PRIORITY(1, 1)
52 #define NVIC_PRIO_SERIALUART4 NVIC_BUILD_PRIORITY(1, 2)
53 #define NVIC_PRIO_SERIALUART5_TXDMA NVIC_BUILD_PRIORITY(1, 0)
54 #define NVIC_PRIO_SERIALUART5_RXDMA NVIC_BUILD_PRIORITY(1, 1)
55 #define NVIC_PRIO_SERIALUART5 NVIC_BUILD_PRIORITY(1, 2)
56 #define NVIC_PRIO_SERIALUART6_TXDMA NVIC_BUILD_PRIORITY(1, 0)
57 #define NVIC_PRIO_SERIALUART6_RXDMA NVIC_BUILD_PRIORITY(1, 1)
58 #define NVIC_PRIO_SERIALUART6 NVIC_BUILD_PRIORITY(1, 2)
59 #define NVIC_PRIO_SERIALUART7_TXDMA NVIC_BUILD_PRIORITY(1, 0)
60 #define NVIC_PRIO_SERIALUART7_RXDMA NVIC_BUILD_PRIORITY(1, 1)
61 #define NVIC_PRIO_SERIALUART7 NVIC_BUILD_PRIORITY(1, 2)
62 #define NVIC_PRIO_SERIALUART8_TXDMA NVIC_BUILD_PRIORITY(1, 0)
63 #define NVIC_PRIO_SERIALUART8_RXDMA NVIC_BUILD_PRIORITY(1, 1)
64 #define NVIC_PRIO_SERIALUART8 NVIC_BUILD_PRIORITY(1, 2)
65 #define NVIC_PRIO_SERIALUART9_TXDMA NVIC_BUILD_PRIORITY(1, 0)
66 #define NVIC_PRIO_SERIALUART9_RXDMA NVIC_BUILD_PRIORITY(1, 1)
67 #define NVIC_PRIO_SERIALUART9 NVIC_BUILD_PRIORITY(1, 2)
68 #define NVIC_PRIO_SERIALUART10_TXDMA NVIC_BUILD_PRIORITY(1, 0)
69 #define NVIC_PRIO_SERIALUART10_RXDMA NVIC_BUILD_PRIORITY(1, 1)
70 #define NVIC_PRIO_SERIALUART10 NVIC_BUILD_PRIORITY(1, 2)
71 #define NVIC_PRIO_SERIALLPUART1_TXDMA NVIC_BUILD_PRIORITY(1, 0)
72 #define NVIC_PRIO_SERIALLPUART1_RXDMA NVIC_BUILD_PRIORITY(1, 1)
73 #define NVIC_PRIO_SERIALLPUART1 NVIC_BUILD_PRIORITY(1, 2)
74 #define NVIC_PRIO_I2C_ER NVIC_BUILD_PRIORITY(0, 0)
75 #define NVIC_PRIO_I2C_EV NVIC_BUILD_PRIORITY(0, 0)
76 #define NVIC_PRIO_USB NVIC_BUILD_PRIORITY(2, 0)
77 #define NVIC_PRIO_USB_WUP NVIC_BUILD_PRIORITY(1, 0)
78 #define NVIC_PRIO_SONAR_ECHO NVIC_BUILD_PRIORITY(0x0f, 0x0f)
79 #define NVIC_PRIO_MPU_DATA_READY NVIC_BUILD_PRIORITY(0, 1)
80 #define NVIC_PRIO_MAG_DATA_READY NVIC_BUILD_PRIORITY(0x0f, 0x0f)
81 #define NVIC_PRIO_CALLBACK NVIC_BUILD_PRIORITY(0x0f, 0x0f)
82 #define NVIC_PRIO_SPI_DMA NVIC_BUILD_PRIORITY(0, 0)
83 #define NVIC_PRIO_SDIO_DMA NVIC_BUILD_PRIORITY(0, 0)
85 #ifdef USE_HAL_DRIVER
86 // utility macros to join/split priority
87 #define NVIC_PRIORITY_GROUPING NVIC_PRIORITYGROUP_2
88 #define NVIC_BUILD_PRIORITY(base,sub) (((((base)<<(4-(7-(NVIC_PRIORITY_GROUPING))))|((sub)&(0x0f>>(7-(NVIC_PRIORITY_GROUPING)))))<<4)&0xf0)
89 #define NVIC_PRIORITY_BASE(prio) (((prio)>>(4-(7-(NVIC_PRIORITY_GROUPING))))>>4)
90 #define NVIC_PRIORITY_SUB(prio) (((prio)&(0x0f>>(7-(NVIC_PRIORITY_GROUPING))))>>4)
91 #else
92 // utility macros to join/split priority
93 #define NVIC_PRIORITY_GROUPING NVIC_PriorityGroup_2
94 #define NVIC_BUILD_PRIORITY(base,sub) (((((base)<<(4-(7-(NVIC_PRIORITY_GROUPING>>8))))|((sub)&(0x0f>>(7-(NVIC_PRIORITY_GROUPING>>8)))))<<4)&0xf0)
95 #define NVIC_PRIORITY_BASE(prio) (((prio)>>(4-(7-(NVIC_PRIORITY_GROUPING>>8))))>>4)
96 #define NVIC_PRIORITY_SUB(prio) (((prio)&(0x0f>>(7-(NVIC_PRIORITY_GROUPING>>8))))>>4)
97 #endif