Skip to content
16 changes: 15 additions & 1 deletion hal/inc/exrtc_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,32 @@
#if HAL_PLATFORM_EXTERNAL_RTC

#include "rtc_hal.h"
#include "i2c_hal.h"
#include "system_tick_hal.h"
#include <stdint.h>
#include <time.h>

#define HAL_EXRTC_CONFIG_VERSION 1

typedef struct hal_exrtc_config_t {
uint16_t version;
uint16_t size;
uint8_t wdi_pin;
uint8_t int_pin;
hal_i2c_interface_t i2c_if;
uint8_t i2c_addr;
int8_t osc_cal_xt;
uint8_t reserved[7];
} hal_exrtc_config_t;

#ifdef __cplusplus
extern "C" {
#endif

typedef hal_rtc_alarm_handler hal_exrtc_alarm_handler;
typedef hal_rtc_alarm_flags hal_exrtc_alarm_flags;

int hal_exrtc_init(void* reserved);
int hal_exrtc_init(const hal_exrtc_config_t* config, void* reserved);
int hal_exrtc_set_time(const struct timeval* tv, void* reserved);
int hal_exrtc_get_time(struct timeval* tv, void* reserved);
int hal_exrtc_set_alarm(const struct timeval* tv, uint32_t flags, hal_exrtc_alarm_handler handler, void* context, void* reserved);
Expand Down
18 changes: 13 additions & 5 deletions hal/inc/hal_dynalib.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
#include "rtc_hal.h"
#include "interrupts_hal.h"

#if PLATFORM_ID == PLATFORM_TRACKER
#if HAL_PLATFORM_EXTERNAL_RTC
#include "exrtc_hal.h"
#endif // PLATFORM_ID == PLATFORM_TRACKER
#endif // HAL_PLATFORM_EXTERNAL_RTC

#endif

Expand Down Expand Up @@ -99,15 +99,23 @@ DYNALIB_FN(BASE_IDX + 22, hal, hal_timer_micros, uint64_t(void*))
DYNALIB_FN(BASE_IDX + 23, hal, hal_rtc_get_time, int(struct timeval*, void*))
DYNALIB_FN(BASE_IDX + 24, hal, hal_rtc_set_time, int(const struct timeval*, void*))

#if PLATFORM_ID == PLATFORM_TRACKER
#if HAL_PLATFORM_EXTERNAL_RTC
DYNALIB_FN(BASE_IDX + 25, hal, hal_exrtc_enable_watchdog, int(system_tick_t, void*))
DYNALIB_FN(BASE_IDX + 26, hal, hal_exrtc_feed_watchdog, int(void*))
DYNALIB_FN(BASE_IDX + 27, hal, hal_exrtc_disable_watchdog, int(void*))
DYNALIB_FN(BASE_IDX + 28, hal, hal_exrtc_get_watchdog_limits, void(system_tick_t*, system_tick_t*, void*))
#define BASE_IDX2 (BASE_IDX + 29)
DYNALIB_FN(BASE_IDX + 29, hal, hal_exrtc_init, int(const hal_exrtc_config_t*, void*))
DYNALIB_FN(BASE_IDX + 30, hal, hal_exrtc_set_time, int(const struct timeval*, void*))
DYNALIB_FN(BASE_IDX + 31, hal, hal_exrtc_get_time, int(struct timeval*, void*))
DYNALIB_FN(BASE_IDX + 32, hal, hal_exrtc_set_alarm, int(const struct timeval*, uint32_t, hal_exrtc_alarm_handler, void*, void*))
DYNALIB_FN(BASE_IDX + 33, hal, hal_exrtc_cancel_alarm, int(void*))
DYNALIB_FN(BASE_IDX + 34, hal, hal_exrtc_time_is_valid, bool(void*))
DYNALIB_FN(BASE_IDX + 35, hal, hal_exrtc_sleep_timer, int(system_tick_t, void*))
DYNALIB_FN(BASE_IDX + 36, hal, hal_exrtc_calibrate_xt, int(int, void*))
#define BASE_IDX2 (BASE_IDX + 37)
#else
#define BASE_IDX2 (BASE_IDX + 25)
#endif // PLATFORM_ID == PLATFORM_TRACKER
#endif // HAL_PLATFORM_EXTERNAL_RTC

DYNALIB_END(hal)

Expand Down
14 changes: 3 additions & 11 deletions hal/inc/hal_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,17 +399,9 @@
#define HAL_PLATFORM_EXTERNAL_RTC (0)
#endif // HAL_PLATFORM_EXTERNAL_RTC

#if HAL_PLATFORM_EXTERNAL_RTC
# ifndef HAL_PLATFORM_EXTERNAL_RTC_I2C
# error "HAL_PLATFORM_EXTERNAL_RTC_I2C is not defined"
# endif /* HAL_PLATFORM_EXTERNAL_RTC_I2C */
# ifndef HAL_PLATFORM_EXTERNAL_RTC_I2C_ADDR
# error "HAL_PLATFORM_EXTERNAL_RTC_I2C_ADDR is not defined"
# endif /* HAL_PLATFORM_EXTERNAL_RTC_I2C_ADDR */
# ifndef HAL_PLATFORM_EXTERNAL_RTC_CAL_XT
# define HAL_PLATFORM_EXTERNAL_RTC_CAL_XT (0)
# endif /* HAL_PLATFORM_EXTERNAL_RTC_CAL_XT */
#endif /* HAL_PLATFORM_EXTERNAL_RTC */
#ifndef HAL_PLATFORM_EXTERNAL_RTC_OPTIONAL
#define HAL_PLATFORM_EXTERNAL_RTC_OPTIONAL (0)
#endif // HAL_PLATFORM_EXTERNAL_RTC_OPTIONAL

#ifndef HAL_PLATFORM_FILE_MAXIMUM_FD
#define HAL_PLATFORM_FILE_MAXIMUM_FD (65535)
Expand Down
Loading