caffeine-hal 0.6.6
A Header-Defined Interface c library, it provides the hal layer for the Caffeine framework
Loading...
Searching...
No Matches
cfn_hal_clock.h
Go to the documentation of this file.
1
26#ifndef CAFFEINE_HAL_HAL_CLOCK_H
27#define CAFFEINE_HAL_HAL_CLOCK_H
28
29#ifdef __cplusplus
30extern "C"
31{
32#endif
33
34/* Includes ---------------------------------------------------------*/
35#include "cfn_hal.h"
36#include "cfn_hal_base.h"
37#include "cfn_hal_types.h"
38
39/* Defines ----------------------------------------------------------*/
40
41/* Types Enums ------------------------------------------------------*/
42
51
62
63/* Types Structs ----------------------------------------------------*/
64
68typedef struct
69{
72
76typedef struct
77{
78 void *instance;
79 void *user_arg;
81
82typedef struct cfn_hal_clock_s cfn_hal_clock_t;
84
93 uint32_t event_mask,
94 uint32_t error_mask,
95 void *user_arg);
96
101{
103
104 /* Clock Specific Extensions */
108 cfn_hal_error_code_t (*get_peripheral_freq)(cfn_hal_clock_t *driver, uint32_t peripheral_id, uint32_t *freq_hz);
109 cfn_hal_error_code_t (*enable_gate)(cfn_hal_clock_t *driver, uint32_t peripheral_id);
110 cfn_hal_error_code_t (*disable_gate)(cfn_hal_clock_t *driver, uint32_t peripheral_id);
111};
112
114
117
118/* Functions inline ------------------------------------------------- */
120 uint32_t peripheral_id,
121 struct cfn_hal_clock_s *clock,
122 void *dependency,
123 const cfn_hal_clock_api_t *api,
124 const cfn_hal_clock_phy_t *phy,
125 const cfn_hal_clock_config_t *config,
127 void *user_arg)
128{
130 driver, CFN_HAL_PERIPHERAL_TYPE_CLOCK, peripheral_id, clock, dependency, api, phy, config, callback, user_arg);
131}
132
140 const cfn_hal_clock_config_t *config)
141{
142 if (driver == NULL || config == NULL)
143 {
145 }
146
147 return cfn_hal_base_config_validate(&driver->base, CFN_HAL_PERIPHERAL_TYPE_CLOCK, config);
148}
149
156{
157 if (!driver)
158 {
160 }
161 driver->base.vmt = (const struct cfn_hal_api_base_s *) driver->api;
162 cfn_hal_error_code_t error = cfn_hal_clock_config_validate(driver, driver->config);
163 if (error != CFN_HAL_ERROR_OK)
164 {
165 return error;
166 }
168}
169
183
191 const cfn_hal_clock_config_t *config)
192{
193 if (!driver)
194 {
196 }
197 {
198 driver->config = config;
199 }
200 return cfn_hal_base_config_set(&driver->base, CFN_HAL_PERIPHERAL_TYPE_CLOCK, (const void *) config);
201}
202
210{
211 if (!driver || !config || !driver->config)
212 {
214 }
215 *config = *(driver->config);
216 return CFN_HAL_ERROR_OK;
217}
218
227 const cfn_hal_clock_callback_t callback,
228 void *user_arg)
229{
230 if (!driver)
231 {
233 }
234 {
235 driver->cb = callback;
236 driver->cb_user_arg = user_arg;
237 }
239 &driver->base, CFN_HAL_PERIPHERAL_TYPE_CLOCK, (cfn_hal_callback_t) callback, user_arg);
240}
241
256
264{
265 if (!driver)
266 {
268 }
269 return cfn_hal_base_event_enable(&driver->base, CFN_HAL_PERIPHERAL_TYPE_CLOCK, event_mask);
270}
271
279{
280 if (!driver)
281 {
283 }
284 return cfn_hal_base_event_disable(&driver->base, CFN_HAL_PERIPHERAL_TYPE_CLOCK, event_mask);
285}
286
294{
295 if (!driver)
296 {
298 }
299 return cfn_hal_base_event_get(&driver->base, CFN_HAL_PERIPHERAL_TYPE_CLOCK, event_mask);
300}
301
309{
310 if (!driver)
311 {
313 }
314 return cfn_hal_base_error_enable(&driver->base, CFN_HAL_PERIPHERAL_TYPE_CLOCK, error_mask);
315}
316
324{
325 if (!driver)
326 {
328 }
329 return cfn_hal_base_error_disable(&driver->base, CFN_HAL_PERIPHERAL_TYPE_CLOCK, error_mask);
330}
331
339{
340 if (!driver)
341 {
343 }
344 return cfn_hal_base_error_get(&driver->base, CFN_HAL_PERIPHERAL_TYPE_CLOCK, error_mask);
345}
346
347/* Clock Specific Functions ----------------------------------------- */
348
360
372
380{
382 CFN_HAL_CHECK_AND_CALL_FUNC_VARG(CFN_HAL_PERIPHERAL_TYPE_CLOCK, get_system_freq, driver, error, freq_hz);
383 return error;
384}
385
394 uint32_t peripheral_id,
395 uint32_t *freq_hz)
396{
399 CFN_HAL_PERIPHERAL_TYPE_CLOCK, get_peripheral_freq, driver, error, peripheral_id, freq_hz);
400 return error;
401}
402
410{
412 CFN_HAL_CHECK_AND_CALL_FUNC_VARG(CFN_HAL_PERIPHERAL_TYPE_CLOCK, enable_gate, driver, error, peripheral_id);
413 return error;
414}
415
423{
425 CFN_HAL_CHECK_AND_CALL_FUNC_VARG(CFN_HAL_PERIPHERAL_TYPE_CLOCK, disable_gate, driver, error, peripheral_id);
426 return error;
427}
429 const cfn_hal_clock_config_t *config,
430 const cfn_hal_clock_phy_t *phy,
431 struct cfn_hal_clock_s *clock,
432 void *dependency,
434 void *user_arg);
436#ifdef __cplusplus
437}
438#endif
439
440#endif // CAFFEINE_HAL_HAL_CLOCK_H
Core Hardware Abstraction Layer definitions and macros.
#define CFN_HAL_CHECK_AND_CALL_FUNC_VARG(expected_peripheral_type, func, driver, result,...)
Definition cfn_hal.h:134
#define CFN_HAL_CHECK_AND_CALL_FUNC(expected_peripheral_type, func, driver, result)
Definition cfn_hal.h:114
#define CFN_HAL_INLINE
Macro for inlining HAL wrapper functions. Can be overridden with attribute((always_inline)) for perfo...
Definition cfn_hal.h:61
#define CFN_HAL_BIT(x)
Definition cfn_hal.h:79
#define CFN_HAL_CREATE_DRIVER_TYPE(prefix, config_type, api_type, phy_type, cb_type)
Definition cfn_hal.h:102
Base driver Hardware Abstraction Layer declarations.
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_error_disable(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, uint32_t error_mask)
Generic error disable for any driver. Deactivates exception-flow hardware triggers based on the provi...
Definition cfn_hal_base_impl.h:436
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_callback_register(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, cfn_hal_callback_t callback, void *user_arg)
Generic callback registration for any driver.
Definition cfn_hal_base_impl.h:254
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_error_enable(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, uint32_t error_mask)
Generic error enable for any driver. Activates exception-flow hardware triggers based on the provided...
Definition cfn_hal_base_impl.h:411
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_event_enable(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, uint32_t event_mask)
Generic event enable for any driver. Activates nominal hardware triggers based on the provided mask.
Definition cfn_hal_base_impl.h:331
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_event_get(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, uint32_t *event_mask)
Generic event status getter for any driver. Retrieves the current nominal hardware triggers/flags.
Definition cfn_hal_base_impl.h:386
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_error_get(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, uint32_t *error_mask)
Generic error status getter for any driver. Retrieves current exception-flow hardware flags/errors.
Definition cfn_hal_base_impl.h:461
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_config_set(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, const void *config)
Generic configuration setter for any driver.
Definition cfn_hal_base_impl.h:196
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_power_state_set(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, cfn_hal_power_state_t state)
Generic power state transition for any driver.
Definition cfn_hal_base_impl.h:279
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_deinit(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type)
Generic deinitialization for any driver. Returns the driver to the CONSTRUCTED state and releases boa...
Definition cfn_hal_base_impl.h:144
#define CFN_HAL_VMT_CHECK(api_struct_type)
Compile-time check to ensure a peripheral API struct is compatible with the base layer....
Definition cfn_hal_base.h:91
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_init(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type)
Generic initialization for any driver. Handles board-level hooks, type validation,...
Definition cfn_hal_base_impl.h:85
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_config_validate(const cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, const void *config)
Generic validation for a configuration.
Definition cfn_hal_base_impl.h:234
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_event_disable(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, uint32_t event_mask)
Generic event disable for any driver. Deactivates nominal hardware triggers based on the provided mas...
Definition cfn_hal_base_impl.h:361
#define CFN_HAL_POPULATE_DRIVER( driver_ptr, periph_type, periph_id, clock_ptr, dep_ptr, api_ptr, phy_ptr, cfg_ptr, cb_func, cb_arg)
Standardizes the population of a peripheral driver structure. This macro ensures that the base driver...
Definition cfn_hal_base_impl.h:45
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_clock_error_get(cfn_hal_clock_t *driver, uint32_t *error_mask)
Retrieves the current Clock exception error status.
Definition cfn_hal_clock.h:338
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_clock_event_enable(cfn_hal_clock_t *driver, uint32_t event_mask)
Enables one or more Clock nominal events.
Definition cfn_hal_clock.h:263
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_clock_callback_register(cfn_hal_clock_t *driver, const cfn_hal_clock_callback_t callback, void *user_arg)
Registers a callback for Clock events and errors.
Definition cfn_hal_clock.h:226
cfn_hal_error_code_t cfn_hal_clock_construct(cfn_hal_clock_t *driver, const cfn_hal_clock_config_t *config, const cfn_hal_clock_phy_t *phy, struct cfn_hal_clock_s *clock, void *dependency, cfn_hal_clock_callback_t callback, void *user_arg)
Definition cfn_hal_clock_port.c:71
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_clock_power_state_set(cfn_hal_clock_t *driver, cfn_hal_power_state_t state)
Sets the Clock power state.
Definition cfn_hal_clock.h:248
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_clock_init(cfn_hal_clock_t *driver)
Initializes the Clock driver.
Definition cfn_hal_clock.h:155
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_clock_config_get(cfn_hal_clock_t *driver, cfn_hal_clock_config_t *config)
Gets the current Clock configuration.
Definition cfn_hal_clock.h:209
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_clock_get_peripheral_freq(cfn_hal_clock_t *driver, uint32_t peripheral_id, uint32_t *freq_hz)
Gets the clock frequency for a specific peripheral domain.
Definition cfn_hal_clock.h:393
CFN_HAL_INLINE void cfn_hal_clock_populate(cfn_hal_clock_t *driver, uint32_t peripheral_id, struct cfn_hal_clock_s *clock, void *dependency, const cfn_hal_clock_api_t *api, const cfn_hal_clock_phy_t *phy, const cfn_hal_clock_config_t *config, cfn_hal_clock_callback_t callback, void *user_arg)
Definition cfn_hal_clock.h:119
cfn_hal_clock_event_t
Clock nominal event flags.
Definition cfn_hal_clock.h:47
@ CFN_HAL_CLOCK_EVENT_NONE
Definition cfn_hal_clock.h:48
@ CFN_HAL_CLOCK_EVENT_READY
Definition cfn_hal_clock.h:49
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_clock_enable_gate(cfn_hal_clock_t *driver, uint32_t peripheral_id)
Enables the clock gate for a specific peripheral.
Definition cfn_hal_clock.h:409
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_clock_error_disable(cfn_hal_clock_t *driver, uint32_t error_mask)
Disables one or more Clock exception errors.
Definition cfn_hal_clock.h:323
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_clock_suspend_tick(cfn_hal_clock_t *driver)
Suspends the system tick (e.g. before entering sleep).
Definition cfn_hal_clock.h:354
cfn_hal_error_code_t cfn_hal_clock_destruct(cfn_hal_clock_t *driver)
Definition cfn_hal_clock_port.c:87
void(* cfn_hal_clock_callback_t)(cfn_hal_clock_t *driver, uint32_t event_mask, uint32_t error_mask, void *user_arg)
Clock callback signature.
Definition cfn_hal_clock.h:92
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_clock_deinit(cfn_hal_clock_t *driver)
Deinitializes the Clock driver.
Definition cfn_hal_clock.h:175
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_clock_config_set(cfn_hal_clock_t *driver, const cfn_hal_clock_config_t *config)
Sets the Clock configuration.
Definition cfn_hal_clock.h:190
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_clock_error_enable(cfn_hal_clock_t *driver, uint32_t error_mask)
Enables one or more Clock exception errors.
Definition cfn_hal_clock.h:308
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_clock_config_validate(const cfn_hal_clock_t *driver, const cfn_hal_clock_config_t *config)
Validates the Clock configuration.
Definition cfn_hal_clock.h:139
struct cfn_hal_clock_s cfn_hal_clock_t
Definition cfn_hal_clock.h:82
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_clock_resume_tick(cfn_hal_clock_t *driver)
Resumes the system tick (e.g. after waking up).
Definition cfn_hal_clock.h:366
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_clock_event_disable(cfn_hal_clock_t *driver, uint32_t event_mask)
Disables one or more Clock nominal events.
Definition cfn_hal_clock.h:278
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_clock_get_system_freq(cfn_hal_clock_t *driver, uint32_t *freq_hz)
Gets the current main system clock frequency.
Definition cfn_hal_clock.h:379
cfn_hal_clock_error_t
Clock exception error flags.
Definition cfn_hal_clock.h:56
@ CFN_HAL_CLOCK_ERROR_NONE
Definition cfn_hal_clock.h:57
@ CFN_HAL_CLOCK_ERROR_GENERAL
Definition cfn_hal_clock.h:60
@ CFN_HAL_CLOCK_ERROR_HSE_FAIL
Definition cfn_hal_clock.h:59
@ CFN_HAL_CLOCK_ERROR_LSE_FAIL
Definition cfn_hal_clock.h:58
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_clock_event_get(cfn_hal_clock_t *driver, uint32_t *event_mask)
Retrieves the current Clock nominal event status.
Definition cfn_hal_clock.h:293
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_clock_disable_gate(cfn_hal_clock_t *driver, uint32_t peripheral_id)
Disables the clock gate for a specific peripheral.
Definition cfn_hal_clock.h:422
Common type definitions and enums for the HAL.
void(* cfn_hal_callback_t)(void)
Generic function pointer for HAL callbacks. Used as a standard-compliant carrier in the base layer.
Definition cfn_hal_types.h:98
enum cfn_hal_error_codes cfn_hal_error_code_t
cfn_hal_power_state_t
Definition cfn_hal_types.h:156
@ CFN_HAL_ERROR_OK
Definition cfn_hal_types.h:50
@ CFN_HAL_ERROR_BAD_PARAM
Definition cfn_hal_types.h:53
#define CFN_HAL_PERIPHERAL_TYPE_CLOCK
Definition cfn_hal_types.h:122
Base API structure for all peripheral drivers. Every peripheral-specific API struct MUST have this as...
Definition cfn_hal_base.h:63
Clock Virtual Method Table (VMT).
Definition cfn_hal_clock.h:101
cfn_hal_error_code_t(* resume_tick)(cfn_hal_clock_t *driver)
Definition cfn_hal_clock.h:106
cfn_hal_error_code_t(* suspend_tick)(cfn_hal_clock_t *driver)
Definition cfn_hal_clock.h:105
cfn_hal_error_code_t(* enable_gate)(cfn_hal_clock_t *driver, uint32_t peripheral_id)
Definition cfn_hal_clock.h:109
cfn_hal_error_code_t(* get_peripheral_freq)(cfn_hal_clock_t *driver, uint32_t peripheral_id, uint32_t *freq_hz)
Definition cfn_hal_clock.h:108
cfn_hal_error_code_t(* get_system_freq)(cfn_hal_clock_t *driver, uint32_t *freq_hz)
Definition cfn_hal_clock.h:107
cfn_hal_error_code_t(* disable_gate)(cfn_hal_clock_t *driver, uint32_t peripheral_id)
Definition cfn_hal_clock.h:110
cfn_hal_api_base_t base
Definition cfn_hal_clock.h:102
Clock configuration structure.
Definition cfn_hal_clock.h:69
void * user_config
Definition cfn_hal_clock.h:70
Clock hardware physical mapping.
Definition cfn_hal_clock.h:77
void * user_arg
Definition cfn_hal_clock.h:79
void * instance
Definition cfn_hal_clock.h:78