diff --git a/framework/rsc_enum.h b/framework/rsc_enum.h index db312c9..9013406 100644 --- a/framework/rsc_enum.h +++ b/framework/rsc_enum.h @@ -66,10 +66,34 @@ enum hw_resource { typedef uint8_t ResourceMap[RSCMAP_LEN]; -#define RSC_IS_FREE(rscmap, rsc) (0 == (rscmap[((rsc)>>3)&0xFF] & (1<<((rsc)&0x7)))) -#define RSC_IS_HELD(rscmap, rsc) (!RSC_IS_FREE(rscmap, rsc)) -#define RSC_CLAIM(rscmap, rsc) do { rscmap[((rsc)>>3)&0xFF] |= (1<<((rsc)&0x7)); } while(0) -#define RSC_FREE(rscmap, rsc) do { rscmap[((rsc)>>3)&0xFF] &= ~(1<<((rsc)&0x7)); } while(0) +static inline bool rscmap_is_free(ResourceMap *rscmap, Resource rsc) +{ + return (0 == (*rscmap[((rsc)>>3)&0xFF] & (1<<((rsc)&0x7)))); +} +static inline bool rscmap_is_held(ResourceMap *rscmap, Resource rsc) +{ + return !rscmap_is_free(rscmap, rsc); +} + +static inline void rscmap_claim(ResourceMap *rscmap, Resource rsc) +{ + *rscmap[((rsc)>>3)&0xFF] |= (1<<((rsc)&0x7)); +} + +static inline void rscmap_free(ResourceMap *rscmap, Resource rsc) +{ + *rscmap[((rsc)>>3)&0xFF] &= ~(1<<((rsc)&0x7)); +} + +//#define RSC_IS_FREE(rscmap, rsc) (0 == (rscmap[((rsc)>>3)&0xFF] & (1<<((rsc)&0x7)))) +//#define RSC_IS_HELD(rscmap, rsc) (!RSC_IS_FREE(rscmap, rsc)) +//#define RSC_CLAIM(rscmap, rsc) do { rscmap[((rsc)>>3)&0xFF] |= (1<<((rsc)&0x7)); } while(0) +//#define RSC_FREE(rscmap, rsc) do { rscmap[((rsc)>>3)&0xFF] &= ~(1<<((rsc)&0x7)); } while(0) + +#define RSC_IS_FREE(rscmap, rsc) rscmap_is_free(&rscmap, (rsc)) +#define RSC_IS_HELD(rscmap, rsc) rscmap_is_held(&rscmap, (rsc)) +#define RSC_CLAIM(rscmap, rsc) rscmap_claim(&rscmap, (rsc)) +#define RSC_FREE(rscmap, rsc) rscmap_free(&rscmap, (rsc)) #endif //GEX_F072_RSC_ENUM_H diff --git a/gex.mk b/gex.mk index 0b7e2fe..84ff98e 100644 --- a/gex.mk +++ b/gex.mk @@ -88,7 +88,7 @@ GEX_CDEFS = $(GEX_CDEFS_BASE) \ -DDEBUG_VFS=0 \ -DDEBUG_FLASH_WRITE=0 \ -DVERBOSE_HARDFAULT=1 \ - -DUSE_STACK_MONITOR=0 \ + -DUSE_STACK_MONITOR=1 \ -DUSE_DEBUG_UART=1 \ -DDEBUG_MALLOC=0 \ -DDEBUG_RSC=0 diff --git a/platform/irq_dispatcher.c b/platform/irq_dispatcher.c index 40715a1..7f00d8e 100644 --- a/platform/irq_dispatcher.c +++ b/platform/irq_dispatcher.c @@ -2,12 +2,50 @@ // Created by MightyPork on 2018/01/14. // -#include +#include #include "platform.h" #include "irq_dispatcher.h" +struct cbslot { + IrqCallback callback; + void *arg; +}; + +static struct callbacks_ { + struct cbslot usart1; + struct cbslot usart2; + struct cbslot usart3; +#ifdef USART4 + struct cbslot usart4; +#endif +#ifdef USART5 + struct cbslot usart5; +#endif + struct cbslot dma1_1; + struct cbslot dma1_2; + struct cbslot dma1_3; + struct cbslot dma1_4; + struct cbslot dma1_5; + struct cbslot dma1_6; + struct cbslot dma1_7; + struct cbslot dma1_8; + + struct cbslot dma2_1; + struct cbslot dma2_2; + struct cbslot dma2_3; + struct cbslot dma2_4; + struct cbslot dma2_5; + struct cbslot dma2_6; + struct cbslot dma2_7; + struct cbslot dma2_8; + + // XXX add more callbacks here when needed +} callbacks; + void irqd_init(void) { + memset(&callbacks, 0, sizeof(callbacks)); + // NVIC_EnableIRQ(WWDG_IRQn); /*!< Window WatchDog Interrupt */ // NVIC_EnableIRQ(PVD_VDDIO2_IRQn); /*!< PVD & VDDIO2 Interrupt through EXTI Lines 16 and 31 */ // NVIC_EnableIRQ(RTC_IRQn); /*!< RTC Interrupt through EXTI Lines 17, 19 and 20 */ @@ -47,6 +85,8 @@ void irqd_init(void) // NVIC_EnableIRQ(TIM1_BRK_UP_TRG_COM_IRQn); /*!< TIM1 Break, Update, Trigger and Commutation Interrupt */ // - handled by hal msp init // NVIC_EnableIRQ(TIM1_CC_IRQn); /*!< TIM1 Capture Compare Interrupt */ // NVIC_EnableIRQ(USB_IRQn); /*!< USB global Interrupt & EXTI Line18 Interrupt */ // - USB IRQ is handled by the USB library + + hexDump("Callbacks", &callbacks, sizeof(callbacks)); } //void Default_Handler(void) @@ -54,41 +94,6 @@ void irqd_init(void) // warn("Missing IRQHandler, ISPR[0]=0x%p", (void*)NVIC->ISPR[0]); //} -struct cbslot { - IrqCallback callback; - void *arg; -}; - -static struct callbacks_ { - struct cbslot usart1; - struct cbslot usart2; - struct cbslot usart3; -#ifdef USART4 - struct cbslot usart4; -#endif -#ifdef USART5 - struct cbslot usart5; -#endif - struct cbslot dma1_1; - struct cbslot dma1_2; - struct cbslot dma1_3; - struct cbslot dma1_4; - struct cbslot dma1_5; - struct cbslot dma1_6; - struct cbslot dma1_7; - struct cbslot dma1_8; - - struct cbslot dma2_1; - struct cbslot dma2_2; - struct cbslot dma2_3; - struct cbslot dma2_4; - struct cbslot dma2_5; - struct cbslot dma2_6; - struct cbslot dma2_7; - struct cbslot dma2_8; - - // XXX add more callbacks here when needed -} callbacks = {0}; static struct cbslot *get_slot_for_periph(void *periph) { @@ -142,7 +147,12 @@ static struct cbslot *get_slot_for_periph(void *periph) void irqd_attach(void *periph, IrqCallback callback, void *arg) { + dbg("Attach irqd for periph %p, cb %p()", periph, callback); + + hexDump("Callbacks", &callbacks, sizeof(callbacks)); + struct cbslot *slot = get_slot_for_periph(periph); + dbg("slot %p cb is %p()", slot, slot->callback); assert_param(slot->callback == NULL); slot->callback = callback; slot->arg = arg; diff --git a/platform/plat_init.c b/platform/plat_init.c index 743babd..12bf0cb 100644 --- a/platform/plat_init.c +++ b/platform/plat_init.c @@ -26,10 +26,11 @@ void plat_init(void) Indicator_Init(); DebugUart_Init(); // <- only the resource claim + irqd_init(); + dbg("Loading settings ..."); // Load settings from Flash and apply (includes System settings and all Unit settings) settings_load(); // XXX maybe this should be moved to the main task comm_init(); - irqd_init(); }