BLE5.2 1.0
开发文档说明
xc_drv_rtc.h
浏览该文件的文档.
1
25#ifndef _XC_DRV_RTC_H_
26#define _XC_DRV_RTC_H_
27
28/*-----------------------------------------------------------------------------------
29 INCLUDE HEADE FILES
30 ------------------------------------------------------------------------------------*/
31
32#include "xc6xxx.h"
33#include <stdbool.h>
34#include <stdio.h>
35/*------------------------------------------------------------------------------------
36 Macros
37 -------------------------------------------------------------------------------------*/
38#define RTC_ICR_DAE_ENABLE (1UL)
39#define RTC_ICR_DAE_DISABLE (0UL)
40
41#define RTC_ICR_HOE_ENABLE (1UL)
42#define RTC_ICR_HOE_DISABLE (0UL)
43
44#define RTC_ICR_MIE_ENABLE (1UL)
45#define RTC_ICR_MIE_DISABLE (0UL)
46
47#define RTC_ICR_SEE_ENABLE (1UL)
48#define RTC_ICR_SEE_DISABLE (0UL)
49
50#define RTC_ICR_T2E_ENABLE (1UL)
51#define RTC_ICR_T2E_DISABLE (0UL)
52
53#define RTC_ICR_T1E_ENABLE (1UL)
54#define RTC_ICR_T1E_DISABLE (0UL)
55
56#define RTC_ICR_T3E_ENABLE (1UL)
57#define RTC_ICR_T3E_DISABLE (0UL)
58
59#define RTC_ICR_MASK_ALL_ENABLE (1UL)
60#define RTC_ICR_MASK_ALL_DISABLE (0UL)
61
62#define RTC_ICR_CNTE_ENABLE (1UL)
63#define RTC_ICR_CNTE_DISABLE (0UL)
64
65#define RTC_AO_TIMER_CTL_AO_TIMER_CLR_SET (1UL)
66#define RTC_AO_TIMER_CTL_AO_TIMER_CLR_RESET (0UL)
67
68#define RTC_AO_TIMER_CTL_AO_TIMER_EN_ENABLE (1UL)
69#define RTC_AO_TIMER_CTL_AO_TIMER_EN_DISABLE (0UL)
70
71
72#define RTC_ICR_T1E_Msk (0x1UL << 5UL)
73#define RTC_ICR_T2E_Msk (0x1UL << 4UL)
74#define RTC_ICR_T3E_Msk (0x1UL << 6UL)
75#define RTC_ICR_DaE_Msk (0x1UL << 0UL)
76#define RTC_ICR_HoE_Msk (0x1UL << 1UL)
77#define RTC_ICR_MiE_Msk (0x1UL << 2UL)
78#define RTC_ICR_SeE_Msk (0x1UL << 3UL)
80#define RTC_AO_ALL_INTR_AO_TIMER_INTR_Msk (0x1UL << 5UL)
82/*------------------------------------------------------------------------------------
83 TypeDef
84 -------------------------------------------------------------------------------------*/
85typedef enum
86{
87 RTC_MATCH_SUNDAY = (0x01 << 0), /*Interrupt from TIME1 event. */
88 RTC_MATCH_MONDAY = (0x01 << 1), /*Interrupt from TIME2 event. */
89 RTC_MATCH_TUESDAY = (0x01 << 2), /*Interrupt from TIME3 event. */
90 RTC_MATCH_WEDNESDAY = (0x01 << 3), /*Interrupt from SEC event. */
91 RTC_MATCH_THURSDAY = (0x01 << 4), /*Interrupt from MIN event. */
92 RTC_MATCH_FRIDAY = (0x01 << 5), /*Interrupt from HOUR event. */
93 RTC_MATCH_SATURDAY = (0x01 << 6) /*Interrupt from DAY event. */
95
96typedef enum
97{
98 RTC_MATCH_T1 = (0x01 << 5),
99 RTC_MATCH_T2 = (0x01 << 4),
100 RTC_MATCH_T3 = (0x01 << 6),
102
103typedef struct
104{
105 uint8_t Sec;
106 uint8_t Min;
107 uint8_t Hour;
108 uint8_t Week;
109 uint16_t Day;
111
112typedef struct
113{
114 uint8_t HourLimit;
115 uint8_t MinLimit;
116 uint8_t SecLimit;
118
119typedef struct
120{
121 uint8_t ch;
122 uint8_t Sec;
123 uint8_t Min;
124 uint8_t Hour;
125 uint8_t Week;
127
128typedef struct
129{
139
140typedef struct RTC_Intr_Cb_s
141{
142 uint8_t (*AO_Timer_Callback)(uint8_t calib_flag);
143 uint8_t (*T1_CMR_Callback)(void);
144 uint8_t (*T2_CMR_Callback)(void);
145 uint8_t (*T3_CMR_Callback)(void);
146 uint8_t (*Sec_Callback)(void);
147 uint8_t (*Min_Callback)(void);
148 uint8_t (*Hour_Callback)(void);
149 uint8_t (*Day_Callback)(void);
151
152/*------------------------------------------------------------------------------------
153 Global Variables
154 -------------------------------------------------------------------------------------*/
155/*------------------------------------------------------------------------------------
156 Inline Functions
157 -------------------------------------------------------------------------------------*/
158static __inline void __rtc_dateget(Rtc_DateTypeDef_t *Date)
159{
160 Date->Sec = rtc_ccvr__rtc_ccvr_sec__getf();
161 Date->Min = rtc_ccvr__rtc_ccvr_min__getf();
162 Date->Hour = rtc_ccvr__rtc_ccvr_hour__getf();
163 Date->Day = rtc_ccvr__rtc_ccvr_day__getf();
164 Date->Week = rtc_wvr__getf();
165}
166
167static __inline void rtc_datelimitSet(RTC_InitCfg_t *rtc_cfg)
168{
169 rtc_hour_limit__setf(rtc_cfg->DateLimit.HourLimit);
170 rtc_minute_limit__setf(rtc_cfg->DateLimit.MinLimit);
171 rtc_second_limit__setf(rtc_cfg->DateLimit.SecLimit);
172}
173
174static __inline void rtc_dateSet(RTC_InitCfg_t *rtc_cfg)
175{
176 rtc_clr__rtc_clr_day__setf(rtc_cfg->Date.Day);
177 rtc_clr__rtc_clr_hour__setf(rtc_cfg->Date.Hour);
178 rtc_clr__rtc_clr_min__setf(rtc_cfg->Date.Min);
179 rtc_clr__rtc_clr_sec__setf(rtc_cfg->Date.Sec);
180 rtc_wlr__setf(rtc_cfg->Date.Week);
181}
182
183static __inline void rtc_config_matchtimeit(RTC_InitCfg_t *rtc_cfg)
184{
185 if (rtc_cfg->MatchTime.ch == RTC_MATCH_T1) {
186 if (rtc_cfg->MatchTimeEnable) {
187 rtc_icr__rtc_t1e__setf(1);
188
189 } else {
190 rtc_icr__rtc_t1e__setf(0);
191 }
192 } else if (rtc_cfg->MatchTime.ch == RTC_MATCH_T2) {
193 if (rtc_cfg->MatchTimeEnable) {
194 rtc_icr__rtc_t2e__setf(1);
195 } else {
196 rtc_icr__rtc_t2e__setf(0);
197 }
198 } else if (rtc_cfg->MatchTime.ch == RTC_MATCH_T3) {
199 if (rtc_cfg->MatchTimeEnable) {
200 rtc_icr__rtc_t3e__setf(1);
201 } else {
202 rtc_icr__rtc_t3e__setf(1);
203 }
204 }
205}
206
207static __inline void rtc_config_secit(RTC_InitCfg_t *rtc_cfg)
208{
209 if (rtc_cfg->SecIT_Enable) {
210 rtc_icr__rtc__se_e__setf(1);
211 } else {
212 rtc_icr__rtc__se_e__setf(0);
213 }
214}
215
216static __inline void rtc_config_minit(RTC_InitCfg_t *rtc_cfg)
217{
218 if (rtc_cfg->SecIT_Enable) {
219 rtc_icr__rtc__mi_e__setf(1);
220 } else {
221 rtc_icr__rtc__mi_e__setf(0);
222 }
223}
224
225static __inline void rtc_config_hourit(RTC_InitCfg_t *rtc_cfg)
226{
227 if (rtc_cfg->SecIT_Enable) {
228 rtc_icr__rtc__ho_e__setf(1);
229 } else {
230 rtc_icr__rtc__ho_e__setf(0);
231 }
232}
233
234static __inline void rtc_config_dayit(RTC_InitCfg_t *rtc_cfg)
235{
236 if (rtc_cfg->SecIT_Enable) {
237 rtc_icr__rtc__da_e__setf(1);
238 } else {
239 rtc_icr__rtc__da_e__setf(0);
240 }
241}
242/*------------------------------------------------------------------------------------
243 Exported Functions
244 -------------------------------------------------------------------------------------*/
245
246void xc_rtc_init(RTC_InitCfg_t *rtc_cfg);
247void xc_rtc_start(void);
248void xc_rtc_stop(void);
250uint8_t AO_Timer_Callback(uint8_t calib_flag);
251uint8_t T1_CMR_Callback(void);
252uint8_t T2_CMR_Callback(void);
253uint8_t T3_CMR_Callback(void);
254uint8_t Sec_Callback(void);
255uint8_t Min_Callback(void);
256uint8_t Hour_Callback(void);
257uint8_t Day_Callback(void);
258
259void rtc_intr_callback(uint64_t intr_sta);
260#endif // _XC_DRV_RTC_H_
Rtc_MatchTimeTypeDef_t MatchTime
Definition xc_drv_rtc.h:132
Rtc_DateLimitTypeDef_t DateLimit
Definition xc_drv_rtc.h:131
Rtc_DateTypeDef_t Date
Definition xc_drv_rtc.h:130
bool MatchTimeEnable
Definition xc_drv_rtc.h:133
uint8_t(* T3_CMR_Callback)(void)
Definition xc_drv_rtc.h:145
uint8_t(* T2_CMR_Callback)(void)
Definition xc_drv_rtc.h:144
uint8_t(* Hour_Callback)(void)
Definition xc_drv_rtc.h:148
uint8_t(* AO_Timer_Callback)(uint8_t calib_flag)
Definition xc_drv_rtc.h:142
uint8_t(* Sec_Callback)(void)
Definition xc_drv_rtc.h:146
uint8_t(* Min_Callback)(void)
Definition xc_drv_rtc.h:147
uint8_t(* T1_CMR_Callback)(void)
Definition xc_drv_rtc.h:143
uint8_t(* Day_Callback)(void)
Definition xc_drv_rtc.h:149
static __inline void __rtc_dateget(Rtc_DateTypeDef_t *Date)
Definition xc_drv_rtc.h:158
void xc_rtc_stop(void)
Definition xc_drv_rtc.c:59
static __inline void rtc_config_minit(RTC_InitCfg_t *rtc_cfg)
Definition xc_drv_rtc.h:216
uint8_t T2_CMR_Callback(void)
Definition xc_drv_rtc.c:160
static __inline void rtc_dateSet(RTC_InitCfg_t *rtc_cfg)
Definition xc_drv_rtc.h:174
struct RTC_Intr_Cb_s RTC_Intr_Cb_t
uint8_t Sec_Callback(void)
Definition xc_drv_rtc.c:164
uint8_t Day_Callback(void)
Definition xc_drv_rtc.c:170
RTC_MatchTimeCh_TypeDef_t
Definition xc_drv_rtc.h:97
@ RTC_MATCH_T3
Definition xc_drv_rtc.h:100
@ RTC_MATCH_T1
Definition xc_drv_rtc.h:98
@ RTC_MATCH_T2
Definition xc_drv_rtc.h:99
static __inline void rtc_config_secit(RTC_InitCfg_t *rtc_cfg)
Definition xc_drv_rtc.h:207
void xc_rtc_date_get(Rtc_DateTypeDef_t *Date)
Definition xc_drv_rtc.c:75
static __inline void rtc_config_dayit(RTC_InitCfg_t *rtc_cfg)
Definition xc_drv_rtc.h:234
uint8_t T1_CMR_Callback(void)
Definition xc_drv_rtc.c:158
static __inline void rtc_config_matchtimeit(RTC_InitCfg_t *rtc_cfg)
Definition xc_drv_rtc.h:183
void xc_rtc_start(void)
Definition xc_drv_rtc.c:57
void rtc_intr_callback(uint64_t intr_sta)
static __inline void rtc_config_hourit(RTC_InitCfg_t *rtc_cfg)
Definition xc_drv_rtc.h:225
uint8_t Min_Callback(void)
Definition xc_drv_rtc.c:166
uint8_t T3_CMR_Callback(void)
Definition xc_drv_rtc.c:162
uint8_t AO_Timer_Callback(uint8_t calib_flag)
Definition xc_drv_rtc.c:109
uint8_t Hour_Callback(void)
Definition xc_drv_rtc.c:168
static __inline void rtc_datelimitSet(RTC_InitCfg_t *rtc_cfg)
Definition xc_drv_rtc.h:167
void xc_rtc_init(RTC_InitCfg_t *rtc_cfg)
Definition xc_drv_rtc.c:77
RTC_MatchWeek_TypeDef_t
Definition xc_drv_rtc.h:86
@ RTC_MATCH_SATURDAY
Definition xc_drv_rtc.h:93
@ RTC_MATCH_THURSDAY
Definition xc_drv_rtc.h:91
@ RTC_MATCH_SUNDAY
Definition xc_drv_rtc.h:87
@ RTC_MATCH_FRIDAY
Definition xc_drv_rtc.h:92
@ RTC_MATCH_MONDAY
Definition xc_drv_rtc.h:88
@ RTC_MATCH_WEDNESDAY
Definition xc_drv_rtc.h:90
@ RTC_MATCH_TUESDAY
Definition xc_drv_rtc.h:89