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_rtc.h
Go to the documentation of this file.
1
26#ifndef CAFFEINE_HAL_HAL_RTC_H
27#define CAFFEINE_HAL_HAL_RTC_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#include <time.h>
39
40/* Defines ----------------------------------------------------------*/
41
42/* Types Enums ------------------------------------------------------*/
43
55
65
76
88
89/* Types Structs ----------------------------------------------------*/
90
94typedef struct tm cfn_hal_rtc_time_t;
95
99typedef struct
100{
101 void *instance;
102 void *user_arg;
104
115
116typedef struct cfn_hal_rtc_s cfn_hal_rtc_t;
118
128 cfn_hal_rtc_t *driver, uint32_t event_mask, uint32_t error_mask, uint32_t id, void *user_arg);
129
144
146
148/* Functions inline ------------------------------------------------- */
150 uint32_t peripheral_id,
151 struct cfn_hal_clock_s *clock,
152 void *dependency,
153 const cfn_hal_rtc_api_t *api,
154 const cfn_hal_rtc_phy_t *phy,
155 const cfn_hal_rtc_config_t *config,
156 cfn_hal_rtc_callback_t callback,
157 void *user_arg)
158{
160 driver, CFN_HAL_PERIPHERAL_TYPE_RTC, peripheral_id, clock, dependency, api, phy, config, callback, user_arg);
161}
169 const cfn_hal_rtc_config_t *config)
170{
171 if (driver == NULL || config == NULL)
172 {
174 }
175
177 {
179 }
180
181 return cfn_hal_base_config_validate(&driver->base, CFN_HAL_PERIPHERAL_TYPE_RTC, config);
182 ;
183}
184
191{
192 if (!driver)
193 {
195 }
196 driver->base.vmt = (const struct cfn_hal_api_base_s *) driver->api;
197 cfn_hal_error_code_t error = cfn_hal_rtc_config_validate(driver, driver->config);
198 if (error != CFN_HAL_ERROR_OK)
199 {
200 return error;
201 }
202 return cfn_hal_base_init(&driver->base, CFN_HAL_PERIPHERAL_TYPE_RTC);
203}
204
211{
212 if (!driver)
213 {
215 }
217}
218
226{
227 if (!driver)
228 {
230 }
232 if (error != CFN_HAL_ERROR_OK)
233 {
234 return error;
235 }
236 {
237 driver->config = config;
238 }
239 return cfn_hal_base_config_set(&driver->base, CFN_HAL_PERIPHERAL_TYPE_RTC, (const void *) config);
240}
241
249{
250 if (!driver || !config || !driver->config)
251 {
253 }
254 *config = *(driver->config);
255 return CFN_HAL_ERROR_OK;
256}
257
266 const cfn_hal_rtc_callback_t callback,
267 void *user_arg)
268{
269 if (!driver)
270 {
272 }
273 {
274 driver->cb = callback;
275 driver->cb_user_arg = user_arg;
276 }
278 &driver->base, CFN_HAL_PERIPHERAL_TYPE_RTC, (cfn_hal_callback_t) callback, user_arg);
279}
280
295
303{
304 if (!driver)
305 {
307 }
308 return cfn_hal_base_event_enable(&driver->base, CFN_HAL_PERIPHERAL_TYPE_RTC, event_mask);
309}
310
318{
319 if (!driver)
320 {
322 }
323 return cfn_hal_base_event_disable(&driver->base, CFN_HAL_PERIPHERAL_TYPE_RTC, event_mask);
324}
325
333{
334 if (!driver)
335 {
337 }
338 return cfn_hal_base_event_get(&driver->base, CFN_HAL_PERIPHERAL_TYPE_RTC, event_mask);
339}
340
348{
349 if (!driver)
350 {
352 }
353 return cfn_hal_base_error_enable(&driver->base, CFN_HAL_PERIPHERAL_TYPE_RTC, error_mask);
354}
355
363{
364 if (!driver)
365 {
367 }
368 return cfn_hal_base_error_disable(&driver->base, CFN_HAL_PERIPHERAL_TYPE_RTC, error_mask);
369}
370
378{
379 if (!driver)
380 {
382 }
383 return cfn_hal_base_error_get(&driver->base, CFN_HAL_PERIPHERAL_TYPE_RTC, error_mask);
384}
385
386/* RTC Specific Functions ------------------------------------------- */
387
400
413
427
437 uint32_t id,
438 bool *elapsed,
439 cfn_hal_rtc_time_t *time)
440{
442 CFN_HAL_CHECK_AND_CALL_FUNC_VARG(CFN_HAL_PERIPHERAL_TYPE_RTC, get_alarm, driver, error, id, elapsed, time);
443 return error;
444}
445
459 const cfn_hal_rtc_config_t *config,
460 const cfn_hal_rtc_phy_t *phy,
461 struct cfn_hal_clock_s *clock,
462 void *dependency,
463 cfn_hal_rtc_callback_t callback,
464 void *user_arg);
466#ifdef __cplusplus
467}
468#endif
469
470#endif // CAFFEINE_HAL_HAL_RTC_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_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_rtc_deinit(cfn_hal_rtc_t *driver)
Deinitializes the RTC driver.
Definition cfn_hal_rtc.h:210
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_rtc_stop_alarm(cfn_hal_rtc_t *driver, uint32_t id)
Disables a previously configured alarm.
Definition cfn_hal_rtc.h:452
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_rtc_config_get(cfn_hal_rtc_t *driver, cfn_hal_rtc_config_t *config)
Gets the current RTC configuration.
Definition cfn_hal_rtc.h:248
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_rtc_event_disable(cfn_hal_rtc_t *driver, uint32_t event_mask)
Disables one or more RTC nominal events.
Definition cfn_hal_rtc.h:317
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_rtc_set_alarm(cfn_hal_rtc_t *driver, uint32_t id, cfn_hal_rtc_time_t *time)
Configures an alarm event for a specific time.
Definition cfn_hal_rtc.h:421
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_rtc_callback_register(cfn_hal_rtc_t *driver, const cfn_hal_rtc_callback_t callback, void *user_arg)
Registers a callback for RTC events and errors.
Definition cfn_hal_rtc.h:265
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_rtc_get_alarm(cfn_hal_rtc_t *driver, uint32_t id, bool *elapsed, cfn_hal_rtc_time_t *time)
Retrieves configuration and status of a specific alarm.
Definition cfn_hal_rtc.h:436
cfn_hal_rtc_config_format_t
RTC time format.
Definition cfn_hal_rtc.h:70
@ CFN_HAL_RTC_CONFIG_FORMAT_24H
Definition cfn_hal_rtc.h:72
@ CFN_HAL_RTC_CONFIG_FORMAT_12H
Definition cfn_hal_rtc.h:71
@ CFN_HAL_RTC_CONFIG_FORMAT_MAX
Definition cfn_hal_rtc.h:74
cfn_hal_rtc_config_mode_t
RTC clocking mode.
Definition cfn_hal_rtc.h:81
@ CFN_HAL_RTC_CONFIG_MODE_MAX
Definition cfn_hal_rtc.h:86
@ CFN_HAL_RTC_CONFIG_MODE_BINARY_BCD
Definition cfn_hal_rtc.h:84
@ CFN_HAL_RTC_CONFIG_MODE_BINARY
Definition cfn_hal_rtc.h:83
@ CFN_HAL_RTC_CONFIG_MODE_BCD
Definition cfn_hal_rtc.h:82
cfn_hal_rtc_error_t
RTC exception error flags.
Definition cfn_hal_rtc.h:60
@ CFN_HAL_RTC_ERROR_NONE
Definition cfn_hal_rtc.h:61
@ CFN_HAL_RTC_ERROR_GENERAL
Definition cfn_hal_rtc.h:63
@ CFN_HAL_RTC_ERROR_INIT
Definition cfn_hal_rtc.h:62
struct tm cfn_hal_rtc_time_t
RTC time representation (std tm).
Definition cfn_hal_rtc.h:94
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_rtc_error_disable(cfn_hal_rtc_t *driver, uint32_t error_mask)
Disables one or more RTC exception errors.
Definition cfn_hal_rtc.h:362
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_rtc_config_set(cfn_hal_rtc_t *driver, const cfn_hal_rtc_config_t *config)
Sets the RTC configuration.
Definition cfn_hal_rtc.h:225
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_rtc_config_validate(const cfn_hal_rtc_t *driver, const cfn_hal_rtc_config_t *config)
Validates the RTC configuration.
Definition cfn_hal_rtc.h:168
cfn_hal_error_code_t cfn_hal_rtc_construct(cfn_hal_rtc_t *driver, const cfn_hal_rtc_config_t *config, const cfn_hal_rtc_phy_t *phy, struct cfn_hal_clock_s *clock, void *dependency, cfn_hal_rtc_callback_t callback, void *user_arg)
Definition cfn_hal_rtc_port.c:70
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_rtc_set_time(cfn_hal_rtc_t *driver, cfn_hal_rtc_time_t *time)
Sets the RTC current wall-clock time.
Definition cfn_hal_rtc.h:394
void(* cfn_hal_rtc_callback_t)(cfn_hal_rtc_t *driver, uint32_t event_mask, uint32_t error_mask, uint32_t id, void *user_arg)
RTC callback signature.
Definition cfn_hal_rtc.h:127
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_rtc_power_state_set(cfn_hal_rtc_t *driver, cfn_hal_power_state_t state)
Sets the RTC power state.
Definition cfn_hal_rtc.h:287
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_rtc_get_time(cfn_hal_rtc_t *driver, cfn_hal_rtc_time_t *time)
Retrieves the current wall-clock time from the RTC.
Definition cfn_hal_rtc.h:407
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_rtc_event_get(cfn_hal_rtc_t *driver, uint32_t *event_mask)
Retrieves the current RTC nominal event status.
Definition cfn_hal_rtc.h:332
cfn_hal_rtc_event_t
RTC nominal event flags.
Definition cfn_hal_rtc.h:48
@ CFN_HAL_RTC_EVENT_TAMPER
Definition cfn_hal_rtc.h:53
@ CFN_HAL_RTC_EVENT_WAKEUP
Definition cfn_hal_rtc.h:51
@ CFN_HAL_RTC_EVENT_TIMESTAMP
Definition cfn_hal_rtc.h:52
@ CFN_HAL_RTC_EVENT_ALARM
Definition cfn_hal_rtc.h:50
@ CFN_HAL_RTC_EVENT_NONE
Definition cfn_hal_rtc.h:49
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_rtc_error_enable(cfn_hal_rtc_t *driver, uint32_t error_mask)
Enables one or more RTC exception errors.
Definition cfn_hal_rtc.h:347
CFN_HAL_INLINE void cfn_hal_rtc_populate(cfn_hal_rtc_t *driver, uint32_t peripheral_id, struct cfn_hal_clock_s *clock, void *dependency, const cfn_hal_rtc_api_t *api, const cfn_hal_rtc_phy_t *phy, const cfn_hal_rtc_config_t *config, cfn_hal_rtc_callback_t callback, void *user_arg)
Definition cfn_hal_rtc.h:149
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_rtc_init(cfn_hal_rtc_t *driver)
Initializes the RTC driver.
Definition cfn_hal_rtc.h:190
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_rtc_event_enable(cfn_hal_rtc_t *driver, uint32_t event_mask)
Enables one or more RTC nominal events.
Definition cfn_hal_rtc.h:302
cfn_hal_error_code_t cfn_hal_rtc_destruct(cfn_hal_rtc_t *driver)
Definition cfn_hal_rtc_port.c:86
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_rtc_error_get(cfn_hal_rtc_t *driver, uint32_t *error_mask)
Retrieves the current RTC exception error status.
Definition cfn_hal_rtc.h:377
struct cfn_hal_rtc_s cfn_hal_rtc_t
Definition cfn_hal_rtc.h:116
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_RTC
Definition cfn_hal_types.h:128
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
Base API structure for all peripheral drivers. Every peripheral-specific API struct MUST have this as...
Definition cfn_hal_base.h:63
RTC Virtual Method Table (VMT).
Definition cfn_hal_rtc.h:134
cfn_hal_error_code_t(* get_alarm)(cfn_hal_rtc_t *driver, uint32_t id, bool *elapsed, cfn_hal_rtc_time_t *time)
Definition cfn_hal_rtc.h:141
cfn_hal_error_code_t(* get_time)(cfn_hal_rtc_t *driver, cfn_hal_rtc_time_t *time)
Definition cfn_hal_rtc.h:139
cfn_hal_error_code_t(* set_alarm)(cfn_hal_rtc_t *driver, uint32_t id, cfn_hal_rtc_time_t *time)
Definition cfn_hal_rtc.h:140
cfn_hal_error_code_t(* stop_alarm)(cfn_hal_rtc_t *driver, uint32_t id)
Definition cfn_hal_rtc.h:142
cfn_hal_error_code_t(* set_time)(cfn_hal_rtc_t *driver, cfn_hal_rtc_time_t *time)
Definition cfn_hal_rtc.h:138
cfn_hal_api_base_t base
Definition cfn_hal_rtc.h:135
RTC configuration structure.
Definition cfn_hal_rtc.h:109
void * custom
Definition cfn_hal_rtc.h:113
cfn_hal_rtc_config_format_t format
Definition cfn_hal_rtc.h:110
uint32_t target_rtc_clock
Definition cfn_hal_rtc.h:112
cfn_hal_rtc_config_mode_t mode
Definition cfn_hal_rtc.h:111
RTC hardware physical mapping.
Definition cfn_hal_rtc.h:100
void * instance
Definition cfn_hal_rtc.h:101
void * user_arg
Definition cfn_hal_rtc.h:102