Ondřej Hruška 7 years ago
parent 8e9c653090
commit 63a7852554
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 32
      framework/rsc_enum.h
  2. 2
      gex.mk
  3. 82
      platform/irq_dispatcher.c
  4. 3
      platform/plat_init.c

@ -66,10 +66,34 @@ enum hw_resource {
typedef uint8_t ResourceMap[RSCMAP_LEN]; typedef uint8_t ResourceMap[RSCMAP_LEN];
#define RSC_IS_FREE(rscmap, rsc) (0 == (rscmap[((rsc)>>3)&0xFF] & (1<<((rsc)&0x7)))) static inline bool rscmap_is_free(ResourceMap *rscmap, Resource rsc)
#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) return (0 == (*rscmap[((rsc)>>3)&0xFF] & (1<<((rsc)&0x7))));
#define RSC_FREE(rscmap, rsc) do { rscmap[((rsc)>>3)&0xFF] &= ~(1<<((rsc)&0x7)); } while(0) }
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 #endif //GEX_F072_RSC_ENUM_H

@ -88,7 +88,7 @@ GEX_CDEFS = $(GEX_CDEFS_BASE) \
-DDEBUG_VFS=0 \ -DDEBUG_VFS=0 \
-DDEBUG_FLASH_WRITE=0 \ -DDEBUG_FLASH_WRITE=0 \
-DVERBOSE_HARDFAULT=1 \ -DVERBOSE_HARDFAULT=1 \
-DUSE_STACK_MONITOR=0 \ -DUSE_STACK_MONITOR=1 \
-DUSE_DEBUG_UART=1 \ -DUSE_DEBUG_UART=1 \
-DDEBUG_MALLOC=0 \ -DDEBUG_MALLOC=0 \
-DDEBUG_RSC=0 -DDEBUG_RSC=0

@ -2,12 +2,50 @@
// Created by MightyPork on 2018/01/14. // Created by MightyPork on 2018/01/14.
// //
#include <stm32f072xb.h> #include <utils/hexdump.h>
#include "platform.h" #include "platform.h"
#include "irq_dispatcher.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) void irqd_init(void)
{ {
memset(&callbacks, 0, sizeof(callbacks));
// NVIC_EnableIRQ(WWDG_IRQn); /*!< Window WatchDog Interrupt */ // NVIC_EnableIRQ(WWDG_IRQn); /*!< Window WatchDog Interrupt */
// NVIC_EnableIRQ(PVD_VDDIO2_IRQn); /*!< PVD & VDDIO2 Interrupt through EXTI Lines 16 and 31 */ // 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 */ // 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_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(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 // 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) //void Default_Handler(void)
@ -54,41 +94,6 @@ void irqd_init(void)
// warn("Missing IRQHandler, ISPR[0]=0x%p", (void*)NVIC->ISPR[0]); // 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) 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) 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); struct cbslot *slot = get_slot_for_periph(periph);
dbg("slot %p cb is %p()", slot, slot->callback);
assert_param(slot->callback == NULL); assert_param(slot->callback == NULL);
slot->callback = callback; slot->callback = callback;
slot->arg = arg; slot->arg = arg;

@ -26,10 +26,11 @@ void plat_init(void)
Indicator_Init(); Indicator_Init();
DebugUart_Init(); // <- only the resource claim DebugUart_Init(); // <- only the resource claim
irqd_init();
dbg("Loading settings ..."); dbg("Loading settings ...");
// Load settings from Flash and apply (includes System settings and all Unit 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 settings_load(); // XXX maybe this should be moved to the main task
comm_init(); comm_init();
irqd_init();
} }

Loading…
Cancel
Save