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:
Giovanni Di Sirio 2021-03-23 08:23:17 +00:00
parent f84a6be56e
commit f7f8df4752
5 changed files with 41 additions and 23 deletions

View File

@ -34,6 +34,11 @@
<type>2</type> <type>2</type>
<locationURI>CHIBIOS/os</locationURI> <locationURI>CHIBIOS/os</locationURI>
</link> </link>
<link>
<name>pico-sdk</name>
<type>2</type>
<locationURI>CHIBIOS/ext/pico-sdk/src</locationURI>
</link>
<link> <link>
<name>test</name> <name>test</name>
<type>2</type> <type>2</type>

View File

@ -31,23 +31,10 @@
/*===========================================================================*/ /*===========================================================================*/
#if OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING #if OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING
#endif /* OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING */ #endif /* OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING */
#if OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC #if OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC
#define ST_HANDLER SysTick_Handler #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 */ #endif /* OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC */
/*===========================================================================*/ /*===========================================================================*/
@ -96,22 +83,30 @@ OSAL_IRQ_HANDLER(ST_HANDLER) {
* @notapi * @notapi
*/ */
void st_lld_init(void) { void st_lld_init(void) {
uint32_t timer_clk;
#if OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING #if OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING
#endif /* OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING */ #endif /* OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING */
#if OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC #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 /* Periodic systick mode, the Cortex-Mx internal systick timer is used
in this mode.*/ in this mode.*/
SysTick->LOAD = (SYSTICK_CK / OSAL_ST_FREQUENCY) - 1; SysTick->LOAD = (timer_clk / OSAL_ST_FREQUENCY) - 1;
SysTick->VAL = 0; SysTick->VAL = 0;
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_ENABLE_Msk |
SysTick_CTRL_TICKINT_Msk; SysTick_CTRL_TICKINT_Msk;
/* IRQ enabled.*/ /* IRQ enabled.*/
nvicSetSystemHandlerPriority(HANDLER_SYSTICK, RP_ST_IRQ_PRIORITY); nvicSetSystemHandlerPriority(HANDLER_SYSTICK, RP_SYSTICK_IRQ_PRIORITY);
#endif /* OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC */ #endif /* OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC */
} }

View File

@ -42,8 +42,8 @@
/** /**
* @brief SysTick timer IRQ priority. * @brief SysTick timer IRQ priority.
*/ */
#if !defined(RP_TIMER_IRQ_PRIORITY) || defined(__DOXYGEN__) #if !defined(RP_SYSTICK_IRQ_PRIORITY) || defined(__DOXYGEN__)
#define RP_TIMER_IRQ_PRIORITY 1 #define RP_SYSTICK_IRQ_PRIORITY 1
#endif #endif
/** @} */ /** @} */

View File

@ -24,9 +24,6 @@
#include "hal.h" #include "hal.h"
/* From Pico-SDK */
#include "hardware/clocks.h"
/*===========================================================================*/ /*===========================================================================*/
/* Driver local definitions. */ /* Driver local definitions. */
/*===========================================================================*/ /*===========================================================================*/
@ -39,7 +36,7 @@
* @brief CMSIS system core clock variable. * @brief CMSIS system core clock variable.
* @note It is declared in system_rp2040.h. * @note It is declared in system_rp2040.h.
*/ */
uint32_t SystemCoreClock = RP_CORE_CK; uint32_t SystemCoreClock;
/*===========================================================================*/ /*===========================================================================*/
/* Driver local variables and types. */ /* Driver local variables and types. */
@ -79,6 +76,8 @@ void rp_clock_init(void) {
#if !RP_NO_INIT #if !RP_NO_INIT
clocks_init(); clocks_init();
SystemCoreClock = RP_CORE_CLK;
#endif /* RP_NO_INIT */ #endif /* RP_NO_INIT */
} }

View File

@ -30,6 +30,9 @@
*/ */
#include "rp_registry.h" #include "rp_registry.h"
/* From Pico-SDK */
#include "hardware/clocks.h"
/*===========================================================================*/ /*===========================================================================*/
/* Driver constants. */ /* Driver constants. */
/*===========================================================================*/ /*===========================================================================*/
@ -87,12 +90,19 @@
#error "RP_XOSCCLK not defined in board.h" #error "RP_XOSCCLK not defined in board.h"
#endif #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. */ /* Driver data structures and types. */
/*===========================================================================*/ /*===========================================================================*/
typedef enum clock_index clock_index_t;
/*===========================================================================*/ /*===========================================================================*/
/* Driver macros. */ /* Driver macros. */
/*===========================================================================*/ /*===========================================================================*/
@ -108,12 +118,21 @@
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
void hal_lld_init(void);
void rp_clock_init(void); void rp_clock_init(void);
void hal_lld_init(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #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 */ #endif /* HAL_LLD_H */
/** @} */ /** @} */