gr55xx_hal_calendar.h
Go to the documentation of this file.
1
51 /* Define to prevent recursive inclusion -------------------------------------*/
52 #ifndef __GR55xx_HAL_CALENDAR_H__
53 #define __GR55xx_HAL_CALENDAR_H__
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58
59 /* Includes ------------------------------------------------------------------*/
60 #include "gr55xx_ll_calendar.h"
61 #include "gr55xx_hal_def.h"
62
63 /* Exported types ------------------------------------------------------------*/
74 typedef enum
75 {
76 HAL_CALENDAR_STATE_RESET = 0x00,
77 HAL_CALENDAR_STATE_READY = 0x01,
78 HAL_CALENDAR_STATE_ERROR = 0x04
79 } hal_calender_state_t;
80
95 typedef struct _calendar_time
96 {
97 uint8_t sec;
100 uint8_t min;
103 uint8_t hour;
106 uint8_t date;
109 uint8_t mon;
112 uint8_t year;
115 uint8_t week;
118 uint16_t ms;
120 } calendar_time_t;
121
125 typedef struct _calendar_alarm
126 {
127 uint8_t min;
130 uint8_t hour;
133 uint8_t alarm_sel;
136 uint8_t alarm_date_week_mask;
140 } calendar_alarm_t;
141
151 typedef struct _calendar_handle
152 {
153 calendar_time_t time_init;
155 calendar_alarm_t alarm;
157 hal_lock_t lock;
159 uint32_t prev_ms;
161 uint32_t interval;
163 uint8_t mode;
165 uint8_t sec;
167 uint16_t ms;
169 hal_calender_state_t state;
170 } calendar_handle_t;
171
188 typedef struct _hal_calendar_callback
189 {
190 void (*calendar_alarm_callback)(calendar_handle_t *p_calendar);
191 void (*calendar_tick_callback)(calendar_handle_t *p_calendar);
192 void (*calendar_overflow_callback)(calendar_handle_t *p_calendar);
193 } hal_calendar_callback_t;
194
205 /* Exported constants --------------------------------------------------------*/
213 #define CALENDAR_IT_ALARM AON_CALENDAR_TIMER_CTL_ALARM_INT_EN
214 #define CALENDAR_IT_WARP AON_CALENDAR_TIMER_CTL_WRAP_INT_EN
220 #define CALENDAR_FLAG_ALARM AON_SLP_EVENT_CALENDAR_TIMER_ALARM
221 #define CALENDAR_FLAG_WARP AON_SLP_EVENT_CALENDAR_TIMER_WRAP
227 #define CALENDAR_ALARM_SEL_DATE (0UL)
228 #define CALENDAR_ALARM_SEL_WEEKDAY (1UL)
234 #define CALENDAR_ALARM_WEEKDAY_SUN (0x01ul)
235 #define CALENDAR_ALARM_WEEKDAY_MON (0x02ul)
236 #define CALENDAR_ALARM_WEEKDAY_TUE (0x04ul)
237 #define CALENDAR_ALARM_WEEKDAY_WED (0x08ul)
238 #define CALENDAR_ALARM_WEEKDAY_THU (0x10ul)
239 #define CALENDAR_ALARM_WEEKDAY_FRI (0x20ul)
240 #define CALENDAR_ALARM_WEEKDAY_SAT (0x40ul)
246 #define CALENDAR_ALARM_DISABLE_DATE (1UL)
247 #define CALENDAR_ALARM_DISABLE_TICK (2UL)
248 #define CALENDAR_ALARM_DISABLE_ALL ((CALENDAR_ALARM_DISABLE_DATE) | CALENDAR_ALARM_DISABLE_TICK)
253 /* Exported macro ------------------------------------------------------------*/
254
261 #define __HAL_CALENDAR_ENABLE() SET_BITS(AON->CALENDAR_TIMER_CTL, AON_CALENDAR_TIMER_CTL_EN)
262
266 #define __HAL_CALENDAR_DISABLE() CLEAR_BITS(AON->CALENDAR_TIMER_CTL, AON_CALENDAR_TIMER_CTL_EN)
267
275 #define __HAL_CALENDAR_ENABLE_IT(__INTERRUPT__) SET_BITS(AON->CALENDAR_TIMER_CTL, (__INTERRUPT__))
276
284 #define __HAL_CALENDAR_DISABLE_IT(__INTERRUPT__) CLEAR_BITS(AON->CALENDAR_TIMER_CTL, (__INTERRUPT__))
285
293 #define __HAL_CALENDAR_GET_IT_SOURCE(__FLAG__) (READ_BITS(AON->SLP_EVENT, (__FLAG__)) == (__FLAG__))
294
302 #define __HAL_CALENDAR_CLEAR_FLAG(__FLAG__) WRITE_REG(AON->SLP_EVENT, ~(__FLAG__))
303
306 /* Private macros ------------------------------------------------------------*/
315 #define IS_CALENDAR_ALARM_TYPE(__TYPE__) (((__TYPE__) == CALENDAR_ALARM_SEL_DATE) || \
316 ((__TYPE__) == CALENDAR_ALARM_SEL_WEEKDAY))
317
322 #define IS_CALENDAR_DATE(__DATE__) (((__DATE__) > 0) && ((__DATE__) <= 31))
323
328 #define IS_CALENDAR_WEEKDAY(__WEEKDAY__) (((__WEEKDAY__) >= 0) && ((__WEEKDAY__) <= 6))
329
334 #define IS_CALENDAR_LEAP_YEAR(__YEAR__) ((((__YEAR__) % 4) == 0 && ((__YEAR__) % 100) != 0) || \
335 ((__YEAR__) % 400) == 0)
336
341 /* Exported functions --------------------------------------------------------*/
377 hal_status_t hal_calendar_init(calendar_handle_t *p_calendar);
378
391 hal_status_t hal_calendar_deinit(calendar_handle_t *p_calendar);
392
428 hal_status_t hal_calendar_init_time(calendar_handle_t *p_calendar, calendar_time_t *p_time);
429
444 hal_status_t hal_calendar_get_time(calendar_handle_t *p_calendar, calendar_time_t *p_time);
445
460 hal_status_t hal_calendar_set_alarm(calendar_handle_t *p_calendar, calendar_alarm_t *p_alarm);
461
477 hal_status_t hal_calendar_set_tick(calendar_handle_t *p_calendar, uint32_t interval);
478
497 hal_status_t hal_calendar_disable_event(calendar_handle_t *p_calendar, uint32_t disable_mode);
498
517 void calendar_irq_handler(calendar_handle_t *p_calendar);
518
530 void hal_calendar_alarm_callback(calendar_handle_t *p_calendar);
531
543 void hal_calendar_tick_callback(calendar_handle_t *p_calendar);
544
558 void hal_calendar_overflow_callback(calendar_handle_t *p_calendar);
559
564 #ifdef __cplusplus
565 }
566 #endif
567
568 #endif /* __GR55xx_HAL_CALENDAR_H__ */
569
_calendar_time::sec
uint8_t sec
Definition: gr55xx_hal_calendar.h:97
_calendar_alarm::alarm_date_week_mask
uint8_t alarm_date_week_mask
Definition: gr55xx_hal_calendar.h:136
_calendar_time::date
uint8_t date
Definition: gr55xx_hal_calendar.h:106
_calendar_time::min
uint8_t min
Definition: gr55xx_hal_calendar.h:100
calendar_alarm_t
struct _calendar_alarm calendar_alarm_t
CALENDAR_Alarm calendar alarm structure definition.
hal_lock_t
hal_lock_t
HAL Lock structures definition.
Definition: gr55xx_hal_def.h:81
calendar_time_t
struct _calendar_time calendar_time_t
CALENDAR_Time calendar time structure definition.
_calendar_handle::state
hal_calender_state_t state
Definition: gr55xx_hal_calendar.h:169
HAL_CALENDAR_STATE_ERROR
@ HAL_CALENDAR_STATE_ERROR
Definition: gr55xx_hal_calendar.h:78
_calendar_time::hour
uint8_t hour
Definition: gr55xx_hal_calendar.h:103
hal_calendar_alarm_callback
void hal_calendar_alarm_callback(calendar_handle_t *p_calendar)
CALENDAR date count complete callback.
hal_calendar_disable_event
hal_status_t hal_calendar_disable_event(calendar_handle_t *p_calendar, uint32_t disable_mode)
Disable CALENDAR alarm event.
hal_calendar_deinit
hal_status_t hal_calendar_deinit(calendar_handle_t *p_calendar)
De-initialize the CALENDAR peripheral.
_calendar_time::ms
uint16_t ms
Definition: gr55xx_hal_calendar.h:118
hal_calender_state_t
hal_calender_state_t
HAL CALENDAR State Enumerations definition.
Definition: gr55xx_hal_calendar.h:75
hal_calendar_tick_callback
void hal_calendar_tick_callback(calendar_handle_t *p_calendar)
CALENDAR milliseconds count complete callback.
_calendar_handle::time_init
calendar_time_t time_init
Definition: gr55xx_hal_calendar.h:153
HAL_CALENDAR_STATE_RESET
@ HAL_CALENDAR_STATE_RESET
Definition: gr55xx_hal_calendar.h:76
_calendar_time::mon
uint8_t mon
Definition: gr55xx_hal_calendar.h:109
hal_calendar_get_time
hal_status_t hal_calendar_get_time(calendar_handle_t *p_calendar, calendar_time_t *p_time)
Get current CALENDAR time.
_hal_calendar_callback::calendar_alarm_callback
void(* calendar_alarm_callback)(calendar_handle_t *p_calendar)
Definition: gr55xx_hal_calendar.h:190
hal_calendar_init
hal_status_t hal_calendar_init(calendar_handle_t *p_calendar)
Initialize the CALENDAR according to the specified parameters in the calendar_init_t of associated ha...
_calendar_handle
CALENDAR handle Structure definition.
Definition: gr55xx_hal_calendar.h:152
hal_calendar_callback_t
struct _hal_calendar_callback hal_calendar_callback_t
HAL_CALENDAR Callback function definition.
hal_calendar_set_alarm
hal_status_t hal_calendar_set_alarm(calendar_handle_t *p_calendar, calendar_alarm_t *p_alarm)
Set a CALENDAR date alarm.
_calendar_handle::prev_ms
uint32_t prev_ms
Definition: gr55xx_hal_calendar.h:159
_calendar_alarm::alarm_sel
uint8_t alarm_sel
Definition: gr55xx_hal_calendar.h:133
_calendar_handle::lock
hal_lock_t lock
Definition: gr55xx_hal_calendar.h:157
_calendar_handle::alarm
calendar_alarm_t alarm
Definition: gr55xx_hal_calendar.h:155
_calendar_time::week
uint8_t week
Definition: gr55xx_hal_calendar.h:115
hal_calendar_init_time
hal_status_t hal_calendar_init_time(calendar_handle_t *p_calendar, calendar_time_t *p_time)
Initialize the CALENDAR time.
gr55xx_ll_calendar.h
Header file containing functions prototypes of CALENDAR LL library.
_calendar_handle::sec
uint8_t sec
Definition: gr55xx_hal_calendar.h:165
_calendar_handle::interval
uint32_t interval
Definition: gr55xx_hal_calendar.h:161
_calendar_alarm
CALENDAR_Alarm calendar alarm structure definition.
Definition: gr55xx_hal_calendar.h:126
hal_status_t
hal_status_t
HAL Status structures definition.
Definition: gr55xx_hal_def.h:70
HAL_CALENDAR_STATE_READY
@ HAL_CALENDAR_STATE_READY
Definition: gr55xx_hal_calendar.h:77
_calendar_alarm::hour
uint8_t hour
Definition: gr55xx_hal_calendar.h:130
hal_calendar_overflow_callback
void hal_calendar_overflow_callback(calendar_handle_t *p_calendar)
CALENDAR overflow callback.
_hal_calendar_callback
HAL_CALENDAR Callback function definition.
Definition: gr55xx_hal_calendar.h:189
hal_calendar_set_tick
hal_status_t hal_calendar_set_tick(calendar_handle_t *p_calendar, uint32_t interval)
Set a CALENDAR tick alarm.
calendar_handle_t
struct _calendar_handle calendar_handle_t
CALENDAR handle Structure definition.
_calendar_handle::ms
uint16_t ms
Definition: gr55xx_hal_calendar.h:167
_calendar_alarm::min
uint8_t min
Definition: gr55xx_hal_calendar.h:127
_hal_calendar_callback::calendar_overflow_callback
void(* calendar_overflow_callback)(calendar_handle_t *p_calendar)
Definition: gr55xx_hal_calendar.h:192
_calendar_handle::mode
uint8_t mode
Definition: gr55xx_hal_calendar.h:163
_hal_calendar_callback::calendar_tick_callback
void(* calendar_tick_callback)(calendar_handle_t *p_calendar)
Definition: gr55xx_hal_calendar.h:191
calendar_irq_handler
void calendar_irq_handler(calendar_handle_t *p_calendar)
Handle CALENDAR interrupt request.
_calendar_time
CALENDAR_Time calendar time structure definition.
Definition: gr55xx_hal_calendar.h:96
_calendar_time::year
uint8_t year
Definition: gr55xx_hal_calendar.h:112
gr55xx_hal_def.h
This file contains HAL common definitions, enumeration, macros and structures definitions.