Skip to content

Commit

Permalink
mimxrt/pendsv: Clean up PendSV code.
Browse files Browse the repository at this point in the history
The dispatch active flag is only set once and never reset, so it will
always call the dispatch handler (once enabled), and it's not really
needed because it doesn't make things more efficient.

Also remove unused included headers.
  • Loading branch information
iabdalkader authored and dpgeorge committed Apr 5, 2023
1 parent eb6e514 commit db4b416
Showing 1 changed file with 1 addition and 15 deletions.
16 changes: 1 addition & 15 deletions ports/mimxrt/pendsv.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,27 @@
#include <stdlib.h>

#include "py/runtime.h"
#include "shared/runtime/interrupt_char.h"
#include "pendsv.h"
#include "lib/nxp_driver/sdk/CMSIS/Include/core_cm7.h"

#define NVIC_PRIORITYGROUP_4 ((uint32_t)0x00000003)
#define IRQ_PRI_PENDSV NVIC_EncodePriority(NVIC_PRIORITYGROUP_4, 15, 0)

#if defined(PENDSV_DISPATCH_NUM_SLOTS)
uint32_t pendsv_dispatch_active;
pendsv_dispatch_t pendsv_dispatch_table[PENDSV_DISPATCH_NUM_SLOTS];
#endif

void pendsv_init(void) {
#if defined(PENDSV_DISPATCH_NUM_SLOTS)
pendsv_dispatch_active = false;
#endif

// set PendSV interrupt at lowest priority
NVIC_SetPriority(PendSV_IRQn, IRQ_PRI_PENDSV);
}

#if defined(PENDSV_DISPATCH_NUM_SLOTS)
void pendsv_schedule_dispatch(size_t slot, pendsv_dispatch_t f) {
pendsv_dispatch_table[slot] = f;
pendsv_dispatch_active = true;
SCB->ICSR = SCB_ICSR_PENDSVSET_Msk;
}

void pendsv_dispatch_handler(void) {
void PendSV_Handler(void) {
for (size_t i = 0; i < PENDSV_DISPATCH_NUM_SLOTS; ++i) {
if (pendsv_dispatch_table[i] != NULL) {
pendsv_dispatch_t f = pendsv_dispatch_table[i];
Expand All @@ -64,10 +56,4 @@ void pendsv_dispatch_handler(void) {
}
}
}

void PendSV_Handler(void) {
if (pendsv_dispatch_active) {
pendsv_dispatch_handler();
}
}
#endif

0 comments on commit db4b416

Please sign in to comment.