Clock initialization improvements.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@14085 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
parent
f84a6be56e
commit
f7f8df4752
|
@ -34,6 +34,11 @@
|
|||
<type>2</type>
|
||||
<locationURI>CHIBIOS/os</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>pico-sdk</name>
|
||||
<type>2</type>
|
||||
<locationURI>CHIBIOS/ext/pico-sdk/src</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>test</name>
|
||||
<type>2</type>
|
||||
|
|
|
@ -31,23 +31,10 @@
|
|||
/*===========================================================================*/
|
||||
|
||||
#if OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING
|
||||
|
||||
#endif /* OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING */
|
||||
|
||||
#if OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC
|
||||
|
||||
#define ST_HANDLER SysTick_Handler
|
||||
|
||||
#define SYSTICK_CK RP_CORE_CK
|
||||
|
||||
#if SYSTICK_CK % OSAL_ST_FREQUENCY != 0
|
||||
#error "the selected ST frequency is not obtainable because integer rounding"
|
||||
#endif
|
||||
|
||||
#if (SYSTICK_CK / OSAL_ST_FREQUENCY) - 1 > 0xFFFFFF
|
||||
#error "the selected ST frequency is not obtainable because SysTick timer counter limits"
|
||||
#endif
|
||||
|
||||
#endif /* OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC */
|
||||
|
||||
/*===========================================================================*/
|
||||
|
@ -96,22 +83,30 @@ OSAL_IRQ_HANDLER(ST_HANDLER) {
|
|||
* @notapi
|
||||
*/
|
||||
void st_lld_init(void) {
|
||||
uint32_t timer_clk;
|
||||
|
||||
#if OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING
|
||||
|
||||
#endif /* OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING */
|
||||
|
||||
#if OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC
|
||||
timer_clk = RP_CORE_CLK;
|
||||
|
||||
osalDbgAssert(timer_clk % OSAL_ST_FREQUENCY != 0U,
|
||||
"division remainder");
|
||||
osalDbgAssert((timer_clk / OSAL_ST_FREQUENCY) - 1U > 0x00FFFFFFU,
|
||||
"prescaler range");
|
||||
|
||||
/* Periodic systick mode, the Cortex-Mx internal systick timer is used
|
||||
in this mode.*/
|
||||
SysTick->LOAD = (SYSTICK_CK / OSAL_ST_FREQUENCY) - 1;
|
||||
SysTick->LOAD = (timer_clk / OSAL_ST_FREQUENCY) - 1;
|
||||
SysTick->VAL = 0;
|
||||
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
|
||||
SysTick_CTRL_ENABLE_Msk |
|
||||
SysTick_CTRL_TICKINT_Msk;
|
||||
|
||||
/* IRQ enabled.*/
|
||||
nvicSetSystemHandlerPriority(HANDLER_SYSTICK, RP_ST_IRQ_PRIORITY);
|
||||
nvicSetSystemHandlerPriority(HANDLER_SYSTICK, RP_SYSTICK_IRQ_PRIORITY);
|
||||
#endif /* OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC */
|
||||
}
|
||||
|
||||
|
|
|
@ -42,8 +42,8 @@
|
|||
/**
|
||||
* @brief SysTick timer IRQ priority.
|
||||
*/
|
||||
#if !defined(RP_TIMER_IRQ_PRIORITY) || defined(__DOXYGEN__)
|
||||
#define RP_TIMER_IRQ_PRIORITY 1
|
||||
#if !defined(RP_SYSTICK_IRQ_PRIORITY) || defined(__DOXYGEN__)
|
||||
#define RP_SYSTICK_IRQ_PRIORITY 1
|
||||
#endif
|
||||
/** @} */
|
||||
|
||||
|
|
|
@ -24,9 +24,6 @@
|
|||
|
||||
#include "hal.h"
|
||||
|
||||
/* From Pico-SDK */
|
||||
#include "hardware/clocks.h"
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local definitions. */
|
||||
/*===========================================================================*/
|
||||
|
@ -39,7 +36,7 @@
|
|||
* @brief CMSIS system core clock variable.
|
||||
* @note It is declared in system_rp2040.h.
|
||||
*/
|
||||
uint32_t SystemCoreClock = RP_CORE_CK;
|
||||
uint32_t SystemCoreClock;
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local variables and types. */
|
||||
|
@ -79,6 +76,8 @@ void rp_clock_init(void) {
|
|||
|
||||
#if !RP_NO_INIT
|
||||
clocks_init();
|
||||
|
||||
SystemCoreClock = RP_CORE_CLK;
|
||||
#endif /* RP_NO_INIT */
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,9 @@
|
|||
*/
|
||||
#include "rp_registry.h"
|
||||
|
||||
/* From Pico-SDK */
|
||||
#include "hardware/clocks.h"
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*===========================================================================*/
|
||||
|
@ -87,12 +90,19 @@
|
|||
#error "RP_XOSCCLK not defined in board.h"
|
||||
#endif
|
||||
|
||||
#define RP_CORE_CK 125000000
|
||||
/**
|
||||
* @name Various clock points.
|
||||
* @{
|
||||
*/
|
||||
#define RP_CORE_CLK hal_lld_get_clock(clk_sys)
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver data structures and types. */
|
||||
/*===========================================================================*/
|
||||
|
||||
typedef enum clock_index clock_index_t;
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver macros. */
|
||||
/*===========================================================================*/
|
||||
|
@ -108,12 +118,21 @@
|
|||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
void hal_lld_init(void);
|
||||
void rp_clock_init(void);
|
||||
void hal_lld_init(void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver inline functions. */
|
||||
/*===========================================================================*/
|
||||
|
||||
__STATIC_INLINE uint32_t hal_lld_get_clock(clock_index_t clk_index) {
|
||||
|
||||
return clock_get_hz(clk_index);
|
||||
}
|
||||
|
||||
#endif /* HAL_LLD_H */
|
||||
|
||||
/** @} */
|
||||
|
|
Loading…
Reference in New Issue