28#ifndef CAFFEINE_HAL_HAL_BASE_IMPL_H
29#define CAFFEINE_HAL_HAL_BASE_IMPL_H
45#define CFN_HAL_POPULATE_DRIVER( \
46 driver_ptr, periph_type, periph_id, clock_ptr, dep_ptr, api_ptr, phy_ptr, cfg_ptr, cb_func, cb_arg) \
51 cfn_hal_base_populate( \
52 &(driver_ptr)->base, (periph_type), (periph_id), &(api_ptr)->base, (clock_ptr), (dep_ptr)); \
53 (driver_ptr)->api = (api_ptr); \
54 (driver_ptr)->phy = (phy_ptr); \
55 (driver_ptr)->config = (cfg_ptr); \
56 (driver_ptr)->cb = (cb_func); \
57 (driver_ptr)->cb_user_arg = (cb_arg); \
63 uint32_t peripheral_id,
65 struct cfn_hal_clock_s *clock,
87 if (!base || base->
type != expected_type || !base->
vmt)
118 error = api->
init(base);
147 if (!base || base->
type != expected_type || !base->
vmt)
170 error = api->
deinit(base);
200 if (!base || base->
type != expected_type || !config)
238 if (!base || base->
type != expected_type)
259 if (!base || base->
type != expected_type)
283 if (!base || base->
type != expected_type)
335 if (!base || base->
type != expected_type || !base->
vmt)
365 if (!base || base->
type != expected_type || !base->
vmt)
388 uint32_t *event_mask)
390 if (!base || base->
type != expected_type || !event_mask || !base->
vmt)
405 error = api->
event_get(base, event_mask);
415 if (!base || base->
type != expected_type || !base->
vmt)
440 if (!base || base->
type != expected_type || !base->
vmt)
463 uint32_t *error_mask)
465 if (!base || base->
type != expected_type || !error_mask || !base->
vmt)
480 error = api->
error_get(base, error_mask);
486#if (CFN_HAL_USE_LOCK == 1)
489 if (!base || !base->
vmt)
500 return api->lock(base, timeout);
505 if (!base || !base->
vmt)
516 return api->unlock(base);
#define CFN_HAL_INLINE
Macro for inlining HAL wrapper functions. Can be overridden with attribute((always_inline)) for perfo...
Definition cfn_hal.h:61
Base driver Hardware Abstraction Layer declarations.
#define CFN_HAL_BASE_API
API visibility macro for the base driver.
Definition cfn_hal_base.h:53
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_INLINE void cfn_hal_base_populate(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t type, uint32_t peripheral_id, const struct cfn_hal_api_base_s *vmt, struct cfn_hal_clock_s *clock, void *dependency)
Definition cfn_hal_base_impl.h:61
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_power_state_t cfn_hal_power_state_get(const cfn_hal_driver_t *base)
Generic power state getter. Returns the current power state from the software shadow.
Definition cfn_hal_base_impl.h:321
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
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
@ CFN_HAL_CONFIG_PHASE_INIT
Definition cfn_hal_types.h:45
@ CFN_HAL_CONFIG_PHASE_DEINIT
Definition cfn_hal_types.h:44
@ CFN_HAL_DRIVER_STATUS_CONSTRUCTED
Definition cfn_hal_types.h:146
@ CFN_HAL_DRIVER_STATUS_INITIALIZED
Definition cfn_hal_types.h:148
@ CFN_HAL_DRIVER_STATUS_UNKNOWN
Definition cfn_hal_types.h:145
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
uint32_t cfn_hal_peripheral_type_t
Definition cfn_hal_types.h:85
cfn_hal_power_state_t
Definition cfn_hal_types.h:156
@ CFN_HAL_POWER_STATE_UNKNOWN
Definition cfn_hal_types.h:157
@ CFN_HAL_ERROR_OK
Definition cfn_hal_types.h:50
@ CFN_HAL_ERROR_BAD_PARAM
Definition cfn_hal_types.h:53
@ CFN_HAL_ERROR_DRIVER_ALREADY_INIT
Definition cfn_hal_types.h:68
@ CFN_HAL_ERROR_DRIVER_NOT_INIT
Definition cfn_hal_types.h:67
@ CFN_HAL_ERROR_NOT_SUPPORTED
Definition cfn_hal_types.h:57
Base API structure for all peripheral drivers. Every peripheral-specific API struct MUST have this as...
Definition cfn_hal_base.h:63
cfn_hal_error_code_t(* power_state_set)(cfn_hal_driver_t *base, cfn_hal_power_state_t state)
Definition cfn_hal_base.h:67
cfn_hal_error_code_t(* error_disable)(cfn_hal_driver_t *base, uint32_t error_mask)
Definition cfn_hal_base.h:77
cfn_hal_error_code_t(* callback_register)(cfn_hal_driver_t *base, cfn_hal_callback_t callback, void *user_arg)
Definition cfn_hal_base.h:70
cfn_hal_error_code_t(* event_enable)(cfn_hal_driver_t *base, uint32_t event_mask)
Definition cfn_hal_base.h:72
cfn_hal_error_code_t(* error_enable)(cfn_hal_driver_t *base, uint32_t error_mask)
Definition cfn_hal_base.h:76
cfn_hal_error_code_t(* config_set)(cfn_hal_driver_t *base, const void *config)
Definition cfn_hal_base.h:68
cfn_hal_error_code_t(* config_validate)(const cfn_hal_driver_t *base, const void *config)
Definition cfn_hal_base.h:69
cfn_hal_error_code_t(* error_get)(cfn_hal_driver_t *base, uint32_t *error_mask)
Definition cfn_hal_base.h:78
cfn_hal_error_code_t(* event_get)(cfn_hal_driver_t *base, uint32_t *event_mask)
Definition cfn_hal_base.h:74
cfn_hal_error_code_t(* init)(cfn_hal_driver_t *base)
Definition cfn_hal_base.h:64
cfn_hal_error_code_t(* event_disable)(cfn_hal_driver_t *base, uint32_t event_mask)
Definition cfn_hal_base.h:73
cfn_hal_error_code_t(* deinit)(cfn_hal_driver_t *base)
Definition cfn_hal_base.h:65
Base structure for all peripheral drivers. Contains common state and polymorphic interface linkage.
Definition cfn_hal_types.h:171
struct cfn_hal_clock_s * clock_driver
Definition cfn_hal_types.h:176
uint32_t flags
Definition cfn_hal_types.h:197
void * dependency
Definition cfn_hal_types.h:192
void * extension
Definition cfn_hal_types.h:194
cfn_hal_error_code_t(* on_config)(struct cfn_hal_driver_s *base, void *user_arg, cfn_hal_config_phase_t phase)
Board-level configuration hook (BSP). Called by the generic HAL to handle hardware-specific setup lik...
Definition cfn_hal_types.h:188
cfn_hal_power_state_t power_state
Definition cfn_hal_types.h:174
cfn_hal_peripheral_type_t type
Definition cfn_hal_types.h:172
const struct cfn_hal_api_base_s * vmt
Definition cfn_hal_types.h:199
uint32_t peripheral_id
Definition cfn_hal_types.h:198
void * on_config_arg
Definition cfn_hal_types.h:190
cfn_hal_driver_status_t status
Definition cfn_hal_types.h:173