/** * @brief Port-related initialization code. */ void _port_init(void) { /* Initialization of the vector table and priority related settings.*/ SCB_VTOR = CORTEX_VTOR_INIT; SCB_AIRCR = AIRCR_VECTKEY | AIRCR_PRIGROUP(CORTEX_PRIGROUP_INIT); #if CORTEX_USE_FPU { /* Initializing the FPU context save in lazy mode.*/ SCB_FPCCR = FPCCR_ASPEN | FPCCR_LSPEN; /* CP10 and CP11 set to full access.*/ SCB_CPACR |= 0x00F00000; /* Enables FPU context save/restore on exception entry/exit (FPCA bit).*/ __set_CONTROL(__get_CONTROL() | 4); /* FPSCR and FPDSCR initially zero.*/ __set_FPSCR(0); SCB_FPDSCR = 0; } #endif /* Initialization of the system vectors used by the port.*/ nvicSetSystemHandlerPriority(HANDLER_SVCALL, CORTEX_PRIORITY_MASK(CORTEX_PRIORITY_SVCALL)); nvicSetSystemHandlerPriority(HANDLER_PENDSV, CORTEX_PRIORITY_MASK(CORTEX_PRIORITY_PENDSV)); nvicSetSystemHandlerPriority(HANDLER_SYSTICK, CORTEX_PRIORITY_MASK(CORTEX_PRIORITY_SYSTICK)); }
/** * @brief Port-related initialization code. */ void _port_init(void) { /* Initialization of the vector table and priority related settings.*/ SCB_VTOR = CORTEX_VTOR_INIT; SCB_AIRCR = AIRCR_VECTKEY | AIRCR_PRIGROUP(CORTEX_PRIGROUP_INIT); #if CORTEX_USE_FPU { register uint32_t control __asm("control"); register uint32_t fpscr __asm("fpscr"); /* Initializing the FPU context save in lazy mode.*/ SCB_FPCCR = FPCCR_ASPEN | FPCCR_LSPEN; /* CP10 and CP11 set to full access in the startup code.*/ /* SCB_CPACR |= 0x00F00000;*/ /* Enables FPU context save/restore on exception entry/exit (FPCA bit).*/ control |= 4; /* FPSCR and FPDSCR initially zero.*/ fpscr = 0; SCB_FPDSCR = 0; } #endif /* Initialization of the system vectors used by the port.*/ nvicSetSystemHandlerPriority(HANDLER_SVCALL, CORTEX_PRIORITY_MASK(CORTEX_PRIORITY_SVCALL)); nvicSetSystemHandlerPriority(HANDLER_PENDSV, CORTEX_PRIORITY_MASK(CORTEX_PRIORITY_PENDSV)); nvicSetSystemHandlerPriority(HANDLER_SYSTICK, CORTEX_PRIORITY_MASK(CORTEX_PRIORITY_SYSTICK)); }
/*----------------------------------------------------------------------------*/ void nvicSetPriorityGrouping(uint8_t groupBits) { assert(groupBits < 7 && groupBits <= NVIC_PRIORITY_SIZE); uint32_t value; value = SCB->AIRCR & ~(AIRCR_VECTKEY_MASK | AIRCR_PRIGROUP_MASK); value |= AIRCR_VECTKEY(0x5FA) | AIRCR_PRIGROUP(GROUPS_TO_VALUE(groupBits)); SCB->AIRCR = value; }