diff --git a/os/hal/include/hal.h b/os/hal/include/hal.h index 55f92bff8..f91516b61 100644 --- a/os/hal/include/hal.h +++ b/os/hal/include/hal.h @@ -42,6 +42,10 @@ #define HAL_USE_CAN FALSE #endif +#if !defined(HAL_USE_CLK) +#define HAL_USE_CLK FALSE +#endif + #if !defined(HAL_USE_CRY) #define HAL_USE_CRY FALSE #endif @@ -268,6 +272,41 @@ extern "C" { } #endif +/*===========================================================================*/ +/* Driver inline functions. */ +/*===========================================================================*/ + +#if defined(HAL_LLD_USE_CLOCK_MANAGEMENT) || defined(__DOXYGEN__) +/** + * @brief Switches to a different clock configuration + * + * @param[in] ccp pointer to clock a @p halclkcfg_t structure + * @return The clock switch result. + * @retval false if the clock switch succeeded + * @retval true if the clock switch failed + * + * @special + */ +static inline bool halClockSwitchMode(const halclkcfg_t *ccp) { + + return hal_clock_switch_mode(ccp); +} + +/** + * @brief Returns the frequency of a clock point in Hz. + * + * @param[in] clkpt clock point to be returned + * @return The clock point frequency in Hz or zero if the + * frequency is unknown. + * + * @xclass + */ +static inline halfreq_t halClockGetPointX(halclkpoint_t clkpt) { + + return hal_lld_get_clock_point(clkpt); +} +#endif /* defined(HAL_LLD_USE_CLOCK_MANAGEMENT) */ + #endif /* HAL_H */ /** @} */ diff --git a/os/hal/templates/hal_lld.c b/os/hal/templates/hal_lld.c index 84a768025..2cef02481 100644 --- a/os/hal/templates/hal_lld.c +++ b/os/hal/templates/hal_lld.c @@ -32,6 +32,22 @@ /* Driver exported variables. */ /*===========================================================================*/ +#if defined(HAL_LLD_USE_CLOCK_MANAGEMENT) && !defined(__DOXYGEN__) +/** + * @brief Post-reset configuration, must be implemented. + */ +const halclkcfg_t hal_clkcfg_reset = { + .dummy = 0U +}; + +/** + * @brief Configuration from mcuconf.h, must be implemented. + */ +const halclkcfg_t hal_clkcfg_default = { + .dummy = 0U +}; +#endif + /*===========================================================================*/ /* Driver local variables and types. */ /*===========================================================================*/ @@ -57,4 +73,39 @@ void hal_lld_init(void) { } +#if defined(HAL_LLD_USE_CLOCK_MANAGEMENT) || defined(__DOXYGEN__) +/** + * @brief Switches to a different clock configuration + * + * @param[in] ccp pointer to clock a @p halclkcfg_t structure + * @return The clock switch result. + * @retval false if the clock switch succeeded + * @retval true if the clock switch failed + * + * @notapi + */ +bool hal_clock_switch_mode(const halclkcfg_t *ccp) { + + (void)ccp; + + return false; +} + +/** + * @brief Returns the frequency of a clock point in Hz. + * + * @param[in] clkpt clock point to be returned + * @return The clock point frequency in Hz or zero if the + * frequency is unknown. + * + * @notapi + */ +halfreq_t hal_lld_get_clock_point(halclkpoint_t clkpt) { + + (void)clkpt; + + return 0U; +} +#endif /* defined(HAL_LLD_USE_CLOCK_MANAGEMENT) */ + /** @} */ diff --git a/os/hal/templates/hal_lld.h b/os/hal/templates/hal_lld.h index 3dfe041c4..3bb909c64 100644 --- a/os/hal/templates/hal_lld.h +++ b/os/hal/templates/hal_lld.h @@ -29,6 +29,11 @@ /* Driver constants. */ /*===========================================================================*/ +/** + * @brief Specifies implementation of dynamic clock management. + */ +#define HAL_LLD_USE_CLOCK_MANAGEMENT + /** * @name Platform identification macros * @{ @@ -61,6 +66,28 @@ /* Driver data structures and types. */ /*===========================================================================*/ +#if defined(HAL_LLD_USE_CLOCK_MANAGEMENT) || defined(__DOXYGEN__) +/** + * @brief Type of clock point names. + */ +typedef enum { + clk_core = 0, + clk_peripherals = 1 +} halclkpoint_t; + +/** + * @brief Type of a clock point frequency in Hz. + */ +typedef uint32_t halfreq_t; + +/** + * @brief Type of a clock configuration structure. + */ +typedef struct { + uint32_t dummy; +} halclkcfg_t; +#endif /* defined(HAL_LLD_USE_CLOCK_MANAGEMENT) */ + /*===========================================================================*/ /* Driver macros. */ /*===========================================================================*/ @@ -69,10 +96,19 @@ /* External declarations. */ /*===========================================================================*/ +#if defined(HAL_LLD_USE_CLOCK_MANAGEMENT) && !defined(__DOXYGEN__) +extern const halclkcfg_t hal_clkcfg_reset; +extern const halclkcfg_t hal_clkcfg_default; +#endif + #ifdef __cplusplus extern "C" { #endif void hal_lld_init(void); +#if defined(HAL_LLD_USE_CLOCK_MANAGEMENT) || defined(__DOXYGEN__) + bool hal_clock_switch_mode(const halclkcfg_t *ccp); + halfreq_t hal_lld_get_clock_point(halclkpoint_t clkpt); +#endif /* defined(HAL_LLD_USE_CLOCK_MANAGEMENT) */ #ifdef __cplusplus } #endif