static void ClkSet(sys_clk_t clock) { switch (clock) { case sysclk_XTAL16M: if (!hw_cpm_check_xtal16m_status()) // XTAL16M disabled { hw_cpm_enable_xtal16m(); // Enable XTAL16M } hw_cpm_set_sysclk(SYS_CLK_IS_XTAL16M); // Set XTAL16 as sys_clk hw_watchdog_unfreeze(); // Start watchdog while (!hw_cpm_is_xtal16m_started()); // Block until XTAL16M starts hw_qspi_set_div(HW_QSPI_DIV_1); hw_watchdog_freeze(); // Stop watchdog hw_cpm_set_hclk_div(0); hw_cpm_set_pclk_div(0); break; case sysclk_PLL48: if (hw_cpm_is_pll_locked() == 0) { hw_watchdog_unfreeze(); // Start watchdog hw_cpm_pll_sys_on(); // Turn on PLL hw_watchdog_freeze(); // Stop watchdog } hw_cpm_enable_pll_divider(); // Enable divider (div by 2) hw_qspi_set_div(HW_QSPI_DIV_1); hw_cpm_set_sysclk(SYS_CLK_IS_PLL); hw_cpm_set_hclk_div(0); hw_cpm_set_pclk_div(0); break; case sysclk_PLL96: if (hw_cpm_is_pll_locked() == 0) { hw_watchdog_unfreeze(); // Start watchdog hw_cpm_pll_sys_on(); // Turn on PLL hw_watchdog_freeze(); // Stop watchdog } hw_cpm_disable_pll_divider(); // Disable divider (div by 1) hw_qspi_set_div(HW_QSPI_DIV_2); hw_cpm_set_sysclk(SYS_CLK_IS_PLL); hw_cpm_set_hclk_div(0); hw_cpm_set_pclk_div(0); break; default: break; } }
/** * @brief Basic initialization and creation of the system initialization task. */ int main( void ) { OS_TASK handle; BaseType_t status; hw_qspi_set_div(HW_QSPI_DIV_1); cm_clk_init_low_level(); /* Basic clock initializations. */ /* Start SysInit task. */ status = OS_TASK_CREATE("SysInit", /* The text name assigned to the task, for debug only; not used by the kernel. */ system_init, /* The System Initialization task. */ ( void * ) 0, /* The parameter passed to the task. */ 1024, /* The number of bytes to allocate to the stack of the task. */ configMAX_PRIORITIES - 1, /* The priority assigned to the task. */ handle ); /* The task handle */ configASSERT(status == OS_TASK_CREATE_SUCCESS); /* Start the tasks and timer running. */ vTaskStartScheduler(); /* If all is well, the scheduler will now be running, and the following line will never be reached. If the following line does execute, then there was insufficient FreeRTOS heap memory available for the idle and/or timer tasks to be created. See the memory management section on the FreeRTOS web site for more details. */ for( ;; ); }