/*FUNCTION********************************************************************** * * Function Name : CLOCK_HAL_GetOutDiv * Description : Get all clock out dividers setting at the same time * This function will get the setting for all clock out dividers. * *END**************************************************************************/ void CLOCK_HAL_GetOutDiv(SIM_Type* base, uint8_t *outdiv1, uint8_t *outdiv2, uint8_t *outdiv3, uint8_t *outdiv4) { *outdiv1 = SIM_BRD_CLKDIV1_OUTDIV1(base); *outdiv2 = SIM_BRD_CLKDIV1_OUTDIV2(base); *outdiv4 = SIM_BRD_CLKDIV1_OUTDIV4(base); }
void init_hardware(void) { // Disable the MPU otherwise USB cannot access the bus MPU->CESR = 0; // Enable all the ports SIM->SCGC5 |= ( SIM_SCGC5_PORTA_MASK | SIM_SCGC5_PORTB_MASK | SIM_SCGC5_PORTC_MASK | SIM_SCGC5_PORTD_MASK | SIM_SCGC5_PORTE_MASK ); // Update SystemCoreClock. FOPT bits set the OUTDIV1 value. SystemCoreClock /= (SIM_BRD_CLKDIV1_OUTDIV1(SIM) + 1); }
uint32_t get_bus_clock(void) { uint32_t busClockDivider = SIM_BRD_CLKDIV1_OUTDIV2(SIM) + 1; uint32_t coreClockDivider = SIM_BRD_CLKDIV1_OUTDIV1(SIM) + 1; return (SystemCoreClock * coreClockDivider / busClockDivider); }