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 2121#include <stdint.h>
2222#include <string.h>
2323
24+ /* Number of implemented priority bits */
25+ uint8_t g_nvic_prio_bits ;
26+
2427/* Symbols exported by the mbed linker script */
2528UVISOR_EXTERN uint32_t __uvisor_cfgtbl_ptr_start ;
2629UVISOR_EXTERN uint32_t __uvisor_cfgtbl_ptr_end ;
@@ -186,7 +189,8 @@ static void uvisor_disabled_default_vector(void)
186189
187190void uvisor_disabled_set_vector (uint32_t irqn , uint32_t vector )
188191{
189- uint8_t box_id ;
192+ uint8_t prio_bits , box_id ;
193+ uint8_t volatile * prio ;
190194
191195 /* Check IRQn.
192196 * 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)
204208 * user vectors explicitly set using this API are registered in the table. */
205209 if (SCB -> VTOR != (uint32_t ) g_irq_table ) {
206210 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 ();
207222 }
208223
209224 /* Register IRQ.
You can’t perform that action at this time.
0 commit comments