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_wdt.h
Go to the documentation of this file.
1
26#ifndef CAFFEINE_HAL_HAL_WDT_H
27#define CAFFEINE_HAL_HAL_WDT_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
60
71
83
84/* Types Structs ----------------------------------------------------*/
85
89typedef struct
90{
91 void *instance;
92 void *user_arg;
94
105
106typedef struct cfn_hal_wdt_s cfn_hal_wdt_t;
108
116typedef void (*cfn_hal_wdt_callback_t)(cfn_hal_wdt_t *driver, uint32_t event_mask, uint32_t error_mask, void *user_arg);
117
131
133/* Functions inline ------------------------------------------------- */
135 uint32_t peripheral_id,
136 struct cfn_hal_clock_s *clock,
137 void *dependency,
138 const cfn_hal_wdt_api_t *api,
139 const cfn_hal_wdt_phy_t *phy,
140 const cfn_hal_wdt_config_t *config,
141 cfn_hal_wdt_callback_t callback,
142 void *user_arg)
143{
145 driver, CFN_HAL_PERIPHERAL_TYPE_WDT, peripheral_id, clock, dependency, api, phy, config, callback, user_arg);
146}
147
155 const cfn_hal_wdt_config_t *config)
156{
157 if (driver == NULL || config == NULL)
158 {
160 }
161
163 {
165 }
166
167 if (config->timeout_ms == 0)
168 {
170 }
171
172 return cfn_hal_base_config_validate(&driver->base, CFN_HAL_PERIPHERAL_TYPE_WDT, config);
173}
174
181{
182 if (!driver)
183 {
185 }
186 driver->base.vmt = (const struct cfn_hal_api_base_s *) driver->api;
187 cfn_hal_error_code_t error = cfn_hal_wdt_config_validate(driver, driver->config);
188 if (error != CFN_HAL_ERROR_OK)
189 {
190 return error;
191 }
192 return cfn_hal_base_init(&driver->base, CFN_HAL_PERIPHERAL_TYPE_WDT);
193}
194
201{
202 if (!driver)
203 {
205 }
207}
208
216{
217 if (!driver)
218 {
220 }
222 if (error != CFN_HAL_ERROR_OK)
223 {
224 return error;
225 }
226 {
227 driver->config = config;
228 }
229 return cfn_hal_base_config_set(&driver->base, CFN_HAL_PERIPHERAL_TYPE_WDT, (const void *) config);
230}
231
239{
240 if (!driver || !config || !driver->config)
241 {
243 }
244 *config = *(driver->config);
245 return CFN_HAL_ERROR_OK;
246}
247
256 const cfn_hal_wdt_callback_t callback,
257 void *user_arg)
258{
259 if (!driver)
260 {
262 }
263 {
264 driver->cb = callback;
265 driver->cb_user_arg = user_arg;
266 }
268 &driver->base, CFN_HAL_PERIPHERAL_TYPE_WDT, (cfn_hal_callback_t) callback, user_arg);
269}
270
285
293{
294 if (!driver)
295 {
297 }
298 return cfn_hal_base_event_enable(&driver->base, CFN_HAL_PERIPHERAL_TYPE_WDT, event_mask);
299}
300
308{
309 if (!driver)
310 {
312 }
313 return cfn_hal_base_event_disable(&driver->base, CFN_HAL_PERIPHERAL_TYPE_WDT, event_mask);
314}
315
323{
324 if (!driver)
325 {
327 }
328 return cfn_hal_base_event_get(&driver->base, CFN_HAL_PERIPHERAL_TYPE_WDT, event_mask);
329}
330
338{
339 if (!driver)
340 {
342 }
343 return cfn_hal_base_error_enable(&driver->base, CFN_HAL_PERIPHERAL_TYPE_WDT, error_mask);
344}
345
353{
354 if (!driver)
355 {
357 }
358 return cfn_hal_base_error_disable(&driver->base, CFN_HAL_PERIPHERAL_TYPE_WDT, error_mask);
359}
360
368{
369 if (!driver)
370 {
372 }
373 return cfn_hal_base_error_get(&driver->base, CFN_HAL_PERIPHERAL_TYPE_WDT, error_mask);
374}
375
376/* WDT Specific Functions ------------------------------------------- */
377
389
401
414 const cfn_hal_wdt_config_t *config,
415 const cfn_hal_wdt_phy_t *phy,
416 struct cfn_hal_clock_s *clock,
417 void *dependency,
418 cfn_hal_wdt_callback_t callback,
419 void *user_arg);
421#ifdef __cplusplus
422}
423#endif
424
425#endif // CAFFEINE_HAL_HAL_WDT_H
Core Hardware Abstraction Layer definitions and macros.
#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
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
#define CFN_HAL_PERIPHERAL_TYPE_WDT
Definition cfn_hal_types.h:132
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
@ CFN_HAL_ERROR_BAD_CONFIG
Definition cfn_hal_types.h:60
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_wdt_error_enable(cfn_hal_wdt_t *driver, uint32_t error_mask)
Enables one or more WDT exception errors.
Definition cfn_hal_wdt.h:337
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_wdt_start(cfn_hal_wdt_t *driver)
Starts the watchdog timer.
Definition cfn_hal_wdt.h:383
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_wdt_power_state_set(cfn_hal_wdt_t *driver, cfn_hal_power_state_t state)
Sets the WDT power state.
Definition cfn_hal_wdt.h:277
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_wdt_config_set(cfn_hal_wdt_t *driver, const cfn_hal_wdt_config_t *config)
Sets the WDT configuration.
Definition cfn_hal_wdt.h:215
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_wdt_init(cfn_hal_wdt_t *driver)
Initializes the Watchdog driver.
Definition cfn_hal_wdt.h:180
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_wdt_error_get(cfn_hal_wdt_t *driver, uint32_t *error_mask)
Retrieves the current WDT exception error status.
Definition cfn_hal_wdt.h:367
struct cfn_hal_wdt_s cfn_hal_wdt_t
Definition cfn_hal_wdt.h:106
cfn_hal_error_code_t cfn_hal_wdt_construct(cfn_hal_wdt_t *driver, const cfn_hal_wdt_config_t *config, const cfn_hal_wdt_phy_t *phy, struct cfn_hal_clock_s *clock, void *dependency, cfn_hal_wdt_callback_t callback, void *user_arg)
Definition cfn_hal_wdt_port.c:68
cfn_hal_wdt_event_t
WDT nominal event flags.
Definition cfn_hal_wdt.h:47
@ CFN_HAL_WDT_EVENT_NONE
Definition cfn_hal_wdt.h:48
@ CFN_HAL_WDT_EVENT_WARNING
Definition cfn_hal_wdt.h:49
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_wdt_config_validate(cfn_hal_wdt_t *driver, const cfn_hal_wdt_config_t *config)
Validates the Watchdog configuration.
Definition cfn_hal_wdt.h:154
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_wdt_callback_register(cfn_hal_wdt_t *driver, const cfn_hal_wdt_callback_t callback, void *user_arg)
Registers a callback for WDT events and errors.
Definition cfn_hal_wdt.h:255
cfn_hal_wdt_config_reset_t
WDT reset behavior.
Definition cfn_hal_wdt.h:76
@ CFN_HAL_WDT_CONFIG_RESET_NONE
Definition cfn_hal_wdt.h:77
@ CFN_HAL_WDT_CONFIG_RESET_IRQ
Definition cfn_hal_wdt.h:78
@ CFN_HAL_WDT_CONFIG_RESET_CPU
Definition cfn_hal_wdt.h:79
@ CFN_HAL_WDT_CONFIG_RESET_MAX
Definition cfn_hal_wdt.h:81
cfn_hal_wdt_error_t
WDT exception error flags.
Definition cfn_hal_wdt.h:56
@ CFN_HAL_WDT_ERROR_NONE
Definition cfn_hal_wdt.h:57
@ CFN_HAL_WDT_ERROR_GENERAL
Definition cfn_hal_wdt.h:58
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_wdt_event_get(cfn_hal_wdt_t *driver, uint32_t *event_mask)
Retrieves the current WDT nominal event status.
Definition cfn_hal_wdt.h:322
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_wdt_config_get(cfn_hal_wdt_t *driver, cfn_hal_wdt_config_t *config)
Gets the current WDT configuration.
Definition cfn_hal_wdt.h:238
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_wdt_error_disable(cfn_hal_wdt_t *driver, uint32_t error_mask)
Disables one or more WDT exception errors.
Definition cfn_hal_wdt.h:352
cfn_hal_error_code_t cfn_hal_wdt_destruct(cfn_hal_wdt_t *driver)
Definition cfn_hal_wdt_port.c:84
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_wdt_stop(cfn_hal_wdt_t *driver)
Stops the watchdog timer (if supported by hardware).
Definition cfn_hal_wdt.h:395
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_wdt_event_disable(cfn_hal_wdt_t *driver, uint32_t event_mask)
Disables one or more WDT nominal events.
Definition cfn_hal_wdt.h:307
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_wdt_deinit(cfn_hal_wdt_t *driver)
Deinitializes the Watchdog driver.
Definition cfn_hal_wdt.h:200
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_wdt_feed(cfn_hal_wdt_t *driver)
Feeds (refreshes) the watchdog timer to prevent system reset.
Definition cfn_hal_wdt.h:407
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_wdt_event_enable(cfn_hal_wdt_t *driver, uint32_t event_mask)
Enables one or more WDT nominal events.
Definition cfn_hal_wdt.h:292
cfn_hal_wdt_config_sleep_t
WDT sleep behavior.
Definition cfn_hal_wdt.h:65
@ CFN_HAL_WDT_CONFIG_SLEEP_RUN
Definition cfn_hal_wdt.h:66
@ CFN_HAL_WDT_CONFIG_SLEEP_MAX
Definition cfn_hal_wdt.h:69
@ CFN_HAL_WDT_CONFIG_SLEEP_PAUSE
Definition cfn_hal_wdt.h:67
CFN_HAL_INLINE void cfn_hal_wdt_populate(cfn_hal_wdt_t *driver, uint32_t peripheral_id, struct cfn_hal_clock_s *clock, void *dependency, const cfn_hal_wdt_api_t *api, const cfn_hal_wdt_phy_t *phy, const cfn_hal_wdt_config_t *config, cfn_hal_wdt_callback_t callback, void *user_arg)
Definition cfn_hal_wdt.h:134
void(* cfn_hal_wdt_callback_t)(cfn_hal_wdt_t *driver, uint32_t event_mask, uint32_t error_mask, void *user_arg)
WDT callback signature.
Definition cfn_hal_wdt.h:116
Base API structure for all peripheral drivers. Every peripheral-specific API struct MUST have this as...
Definition cfn_hal_base.h:63
WDT Virtual Method Table (VMT).
Definition cfn_hal_wdt.h:122
cfn_hal_error_code_t(* stop)(cfn_hal_wdt_t *driver)
Definition cfn_hal_wdt.h:127
cfn_hal_error_code_t(* feed)(cfn_hal_wdt_t *driver)
Definition cfn_hal_wdt.h:128
cfn_hal_error_code_t(* start)(cfn_hal_wdt_t *driver)
Definition cfn_hal_wdt.h:126
cfn_hal_api_base_t base
Definition cfn_hal_wdt.h:123
WDT configuration structure.
Definition cfn_hal_wdt.h:99
cfn_hal_wdt_config_sleep_t sleep
Definition cfn_hal_wdt.h:101
void * custom
Definition cfn_hal_wdt.h:103
uint32_t timeout_ms
Definition cfn_hal_wdt.h:100
cfn_hal_wdt_config_reset_t reset
Definition cfn_hal_wdt.h:102
WDT hardware physical mapping.
Definition cfn_hal_wdt.h:90
void * user_arg
Definition cfn_hal_wdt.h:92
void * instance
Definition cfn_hal_wdt.h:91