File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change 21
21
#include <stdint.h>
22
22
#include <string.h>
23
23
24
+ /* Number of implemented priority bits */
25
+ uint8_t g_nvic_prio_bits ;
26
+
24
27
/* Symbols exported by the mbed linker script */
25
28
UVISOR_EXTERN uint32_t __uvisor_cfgtbl_ptr_start ;
26
29
UVISOR_EXTERN uint32_t __uvisor_cfgtbl_ptr_end ;
@@ -186,7 +189,8 @@ static void uvisor_disabled_default_vector(void)
186
189
187
190
void uvisor_disabled_set_vector (uint32_t irqn , uint32_t vector )
188
191
{
189
- uint8_t box_id ;
192
+ uint8_t prio_bits , box_id ;
193
+ uint8_t volatile * prio ;
190
194
191
195
/* Check IRQn.
192
196
* We only allow user IRQs to be registered (NVIC). This is consistent with
@@ -204,6 +208,17 @@ void uvisor_disabled_set_vector(uint32_t irqn, uint32_t vector)
204
208
* user vectors explicitly set using this API are registered in the table. */
205
209
if (SCB -> VTOR != (uint32_t ) g_irq_table ) {
206
210
SCB -> VTOR = (uint32_t ) g_irq_table ;
211
+
212
+ /* Detect the number of implemented priority bits.
213
+ * The architecture specifies that unused/not implemented bits in the
214
+ * NVIC IP registers read back as 0. */
215
+ __disable_irq ();
216
+ prio = (uint8_t volatile * ) & (NVIC -> IP [0 ]);
217
+ prio_bits = * prio ;
218
+ * prio = 0xFFU ;
219
+ g_nvic_prio_bits = (uint8_t ) __builtin_popcount (* prio );
220
+ * prio = prio_bits ;
221
+ __enable_irq ();
207
222
}
208
223
209
224
/* Register IRQ.
You can’t perform that action at this time.
0 commit comments