Skip to content

Commit a73fcbc

Browse files
committed
RTC interrupt simplify
1 parent f86d632 commit a73fcbc

File tree

4 files changed

+38
-233
lines changed

4 files changed

+38
-233
lines changed

RTC/SimplRTC/APP/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ void RTC_Handler(void)
3232
{
3333
RTC_DateTime dateTime;
3434

35-
if(RTC_IntSecondStat(RTC))
35+
if(RTC_INTStat(RTC, RTC_IT_SECOND))
3636
{
37-
RTC_IntSecondClr(RTC);
37+
RTC_INTClr(RTC, RTC_IT_SECOND);
3838

3939
RTC_GetDateTime(RTC, &dateTime);
4040
printf("Now Time: %02d : %02d\r\n", dateTime.Minute, dateTime.Second);

RTC/SimplRTCAlarm/APP/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ int main(void)
4242

4343
void RTC_Handler(void)
4444
{
45-
if(RTC_IntAlarmStat(RTC))
45+
if(RTC_INTStat(RTC, RTC_IT_ALARM))
4646
{
47-
RTC_IntAlarmClr(RTC);
47+
RTC_INTClr(RTC, RTC_IT_ALARM);
4848

4949
RTC_GetDateTime(RTC, &dateTime);
5050
printf("Now Time: %02d : %02d\r\n", dateTime.Minute, dateTime.Second);

SWM320_StdPeriph_Driver/CSL/SWM320_StdPeriph_Driver/SWM320_rtc.c

+21-209
Original file line numberDiff line numberDiff line change
@@ -173,241 +173,53 @@ static uint32_t calcWeekDay(uint32_t year, uint32_t month, uint32_t date)
173173
}
174174

175175
/******************************************************************************************************************************************
176-
* 函数名称: RTC_IntSecondEn()
177-
* 功能说明: 秒中断使能
176+
* 函数名称: RTC_INTEn()
177+
* 功能说明: 中断使能
178178
* 输 入: RTC_TypeDef * RTCx 指定要被设置的RTC,可取值包括RTC
179+
* uint32_t it interrupt type,有效值RTC_IT_SECOND、RTC_IT_MINUTE、RTC_IT_HOUR、RTC_IT_DATE、RTC_IT_ALARM
179180
* 输 出: 无
180181
* 注意事项: 无
181182
******************************************************************************************************************************************/
182-
void RTC_IntSecondEn(RTC_TypeDef * RTCx)
183-
{
184-
RTCx->IE |= (1 << RTC_IE_SEC_Pos);
185-
}
186-
187-
/******************************************************************************************************************************************
188-
* 函数名称: RTC_IntSecondDis()
189-
* 功能说明: 秒中断禁止
190-
* 输 入: RTC_TypeDef * RTCx 指定要被设置的RTC,可取值包括RTC
191-
* 输 出: 无
192-
* 注意事项: 无
193-
******************************************************************************************************************************************/
194-
void RTC_IntSecondDis(RTC_TypeDef * RTCx)
195-
{
196-
RTCx->IE &= ~(1 << RTC_IE_SEC_Pos);
197-
}
198-
199-
/******************************************************************************************************************************************
200-
* 函数名称: RTC_IntSecondClr()
201-
* 功能说明: 秒中断标志清除
202-
* 输 入: RTC_TypeDef * RTCx 指定要被设置的RTC,可取值包括RTC
203-
* 输 出: 无
204-
* 注意事项: 无
205-
******************************************************************************************************************************************/
206-
void RTC_IntSecondClr(RTC_TypeDef * RTCx)
207-
{
208-
RTCx->IF = (1 << RTC_IF_SEC_Pos);
209-
}
210-
211-
/******************************************************************************************************************************************
212-
* 函数名称: RTC_IntSecondStat()
213-
* 功能说明: 秒中断状态
214-
* 输 入: RTC_TypeDef * RTCx 指定要被设置的RTC,可取值包括RTC
215-
* 输 出: uint32_t 1 秒中断发生 0 秒中断未发生
216-
* 注意事项: 无
217-
******************************************************************************************************************************************/
218-
uint32_t RTC_IntSecondStat(RTC_TypeDef * RTCx)
183+
void RTC_INTEn(RTC_TypeDef * RTCx, uint32_t it)
219184
{
220-
return (RTCx->IF & RTC_IF_SEC_Msk) ? 1 : 0;
221-
}
222-
223-
/******************************************************************************************************************************************
224-
* 函数名称: RTC_IntMinuteEn()
225-
* 功能说明: 分中断使能
226-
* 输 入: RTC_TypeDef * RTCx 指定要被设置的RTC,可取值包括RTC
227-
* 输 出: 无
228-
* 注意事项: 无
229-
******************************************************************************************************************************************/
230-
void RTC_IntMinuteEn(RTC_TypeDef * RTCx)
231-
{
232-
RTCx->IE |= (1 << RTC_IE_MIN_Pos);
185+
RTCx->IE |= it;
233186
}
234187

235188
/******************************************************************************************************************************************
236-
* 函数名称: RTC_IntMinuteDis()
237-
* 功能说明: 分中断禁止
189+
* 函数名称: RTC_INTDis()
190+
* 功能说明: 中断禁止
238191
* 输 入: RTC_TypeDef * RTCx 指定要被设置的RTC,可取值包括RTC
192+
* uint32_t it interrupt type,有效值RTC_IT_SECOND、RTC_IT_MINUTE、RTC_IT_HOUR、RTC_IT_DATE、RTC_IT_ALARM
239193
* 输 出: 无
240194
* 注意事项: 无
241195
******************************************************************************************************************************************/
242-
void RTC_IntMinuteDis(RTC_TypeDef * RTCx)
243-
{
244-
RTCx->IE &= ~(1 << RTC_IE_MIN_Pos);
245-
}
246-
247-
/******************************************************************************************************************************************
248-
* 函数名称: RTC_IntMinuteClr()
249-
* 功能说明: 分中断标志清除
250-
* 输 入: RTC_TypeDef * RTCx 指定要被设置的RTC,可取值包括RTC
251-
* 输 出: 无
252-
* 注意事项: 无
253-
******************************************************************************************************************************************/
254-
void RTC_IntMinuteClr(RTC_TypeDef * RTCx)
255-
{
256-
RTCx->IF = (1 << RTC_IF_MIN_Pos);
257-
}
258-
259-
/******************************************************************************************************************************************
260-
* 函数名称: RTC_IntMinuteStat()
261-
* 功能说明: 分中断状态
262-
* 输 入: RTC_TypeDef * RTCx 指定要被设置的RTC,可取值包括RTC
263-
* 输 出: uint32_t 1 分中断发生 0 分中断未发生
264-
* 注意事项: 无
265-
******************************************************************************************************************************************/
266-
uint32_t RTC_IntMinuteStat(RTC_TypeDef * RTCx)
196+
void RTC_INTDis(RTC_TypeDef * RTCx, uint32_t it)
267197
{
268-
return (RTCx->IF & RTC_IF_MIN_Msk) ? 1 : 0;
269-
}
270-
271-
/******************************************************************************************************************************************
272-
* 函数名称: RTC_IntHourEn()
273-
* 功能说明: 时中断使能
274-
* 输 入: RTC_TypeDef * RTCx 指定要被设置的RTC,可取值包括RTC
275-
* 输 出: 无
276-
* 注意事项: 无
277-
******************************************************************************************************************************************/
278-
void RTC_IntHourEn(RTC_TypeDef * RTCx)
279-
{
280-
RTCx->IE |= (1 << RTC_IE_HOUR_Pos);
281-
}
282-
283-
/******************************************************************************************************************************************
284-
* 函数名称: RTC_IntHourDis()
285-
* 功能说明: 时中断禁止
286-
* 输 入: RTC_TypeDef * RTCx 指定要被设置的RTC,可取值包括RTC
287-
* 输 出: 无
288-
* 注意事项: 无
289-
******************************************************************************************************************************************/
290-
void RTC_IntHourDis(RTC_TypeDef * RTCx)
291-
{
292-
RTCx->IE &= ~(1 << RTC_IE_HOUR_Pos);
198+
RTCx->IE &= ~it;
293199
}
294200

295201
/******************************************************************************************************************************************
296-
* 函数名称: RTC_IntHourClr()
297-
* 功能说明: 时中断标志清除
202+
* 函数名称: RTC_INTClr()
203+
* 功能说明: 中断标志清除
298204
* 输 入: RTC_TypeDef * RTCx 指定要被设置的RTC,可取值包括RTC
205+
* uint32_t it interrupt type,有效值RTC_IT_SECOND、RTC_IT_MINUTE、RTC_IT_HOUR、RTC_IT_DATE、RTC_IT_ALARM
299206
* 输 出: 无
300207
* 注意事项: 无
301208
******************************************************************************************************************************************/
302-
void RTC_IntHourClr(RTC_TypeDef * RTCx)
303-
{
304-
RTCx->IF = (1 << RTC_IF_HOUR_Pos);
305-
}
306-
307-
/******************************************************************************************************************************************
308-
* 函数名称: RTC_IntHourStat()
309-
* 功能说明: 时中断状态
310-
* 输 入: RTC_TypeDef * RTCx 指定要被设置的RTC,可取值包括RTC
311-
* 输 出: uint32_t 1 时中断发生 0 时中断未发生
312-
* 注意事项: 无
313-
******************************************************************************************************************************************/
314-
uint32_t RTC_IntHourStat(RTC_TypeDef * RTCx)
209+
void RTC_INTClr(RTC_TypeDef * RTCx, uint32_t it)
315210
{
316-
return (RTCx->IF & RTC_IF_HOUR_Msk) ? 1 : 0;
317-
}
318-
319-
/******************************************************************************************************************************************
320-
* 函数名称: RTC_IntDateEn()
321-
* 功能说明: 日中断使能
322-
* 输 入: RTC_TypeDef * RTCx 指定要被设置的RTC,可取值包括RTC
323-
* 输 出: 无
324-
* 注意事项: 无
325-
******************************************************************************************************************************************/
326-
void RTC_IntDateEn(RTC_TypeDef * RTCx)
327-
{
328-
RTCx->IE |= (1 << RTC_IE_DATE_Pos);
329-
}
330-
331-
/******************************************************************************************************************************************
332-
* 函数名称: RTC_IntDateDis()
333-
* 功能说明: 日中断禁止
334-
* 输 入: RTC_TypeDef * RTCx 指定要被设置的RTC,可取值包括RTC
335-
* 输 出: 无
336-
* 注意事项: 无
337-
******************************************************************************************************************************************/
338-
void RTC_IntDateDis(RTC_TypeDef * RTCx)
339-
{
340-
RTCx->IE &= ~(1 << RTC_IE_DATE_Pos);
341-
}
342-
343-
/******************************************************************************************************************************************
344-
* 函数名称: RTC_IntDateClr()
345-
* 功能说明: 日中断标志清除
346-
* 输 入: RTC_TypeDef * RTCx 指定要被设置的RTC,可取值包括RTC
347-
* 输 出: 无
348-
* 注意事项: 无
349-
******************************************************************************************************************************************/
350-
void RTC_IntDateClr(RTC_TypeDef * RTCx)
351-
{
352-
RTCx->IF = (1 << RTC_IF_DATE_Pos);
211+
RTCx->IF = it;
353212
}
354213

355214
/******************************************************************************************************************************************
356-
* 函数名称: RTC_IntDateStat()
357-
* 功能说明: 日中断状态
215+
* 函数名称: RTC_INTStat()
216+
* 功能说明: 中断状态
358217
* 输 入: RTC_TypeDef * RTCx 指定要被设置的RTC,可取值包括RTC
359-
* 输 出: uint32_t 1 日中断发生 0 日中断未发生
360-
* 注意事项: 无
361-
******************************************************************************************************************************************/
362-
uint32_t RTC_IntDateStat(RTC_TypeDef * RTCx)
363-
{
364-
return (RTCx->IF & RTC_IF_DATE_Msk) ? 1 : 0;
365-
}
366-
367-
/******************************************************************************************************************************************
368-
* 函数名称: RTC_IntAlarmEn()
369-
* 功能说明: 闹钟中断使能
370-
* 输 入: RTC_TypeDef * RTCx 指定要被设置的RTC,可取值包括RTC
371-
* 输 出: 无
372-
* 注意事项: 无
373-
******************************************************************************************************************************************/
374-
void RTC_IntAlarmEn(RTC_TypeDef * RTCx)
375-
{
376-
RTCx->IE |= (1 << RTC_IE_ALARM_Pos);
377-
}
378-
379-
/******************************************************************************************************************************************
380-
* 函数名称: RTC_IntAlarmDis()
381-
* 功能说明: 闹钟中断禁止
382-
* 输 入: RTC_TypeDef * RTCx 指定要被设置的RTC,可取值包括RTC
383-
* 输 出: 无
384-
* 注意事项: 无
385-
******************************************************************************************************************************************/
386-
void RTC_IntAlarmDis(RTC_TypeDef * RTCx)
387-
{
388-
RTCx->IE &= ~(1 << RTC_IE_ALARM_Pos);
389-
}
390-
391-
/******************************************************************************************************************************************
392-
* 函数名称: RTC_IntAlarmClr()
393-
* 功能说明: 闹钟中断标志清除
394-
* 输 入: RTC_TypeDef * RTCx 指定要被设置的RTC,可取值包括RTC
395-
* 输 出: 无
396-
* 注意事项: 无
397-
******************************************************************************************************************************************/
398-
void RTC_IntAlarmClr(RTC_TypeDef * RTCx)
399-
{
400-
RTCx->IF = (1 << RTC_IF_ALARM_Pos);
401-
}
402-
403-
/******************************************************************************************************************************************
404-
* 函数名称: RTC_IntAlarmStat()
405-
* 功能说明: 闹钟中断状态
406-
* 输 入: RTC_TypeDef * RTCx 指定要被设置的RTC,可取值包括RTC
407-
* 输 出: uint32_t 1 闹钟中断发生 0 闹钟中断未发生
218+
* uint32_t it interrupt type,有效值RTC_IT_SECOND、RTC_IT_MINUTE、RTC_IT_HOUR、RTC_IT_DATE、RTC_IT_ALARM
219+
* 输 出: uint32_t 1 秒中断发生 0 秒中断未发生
408220
* 注意事项: 无
409221
******************************************************************************************************************************************/
410-
uint32_t RTC_IntAlarmStat(RTC_TypeDef * RTCx)
222+
uint32_t RTC_INTStat(RTC_TypeDef * RTCx, uint32_t it)
411223
{
412-
return (RTCx->IF & RTC_IF_ALARM_Msk) ? 1 : 0;
224+
return (RTCx->IF & it) ? 1 : 0;
413225
}

SWM320_StdPeriph_Driver/CSL/SWM320_StdPeriph_Driver/SWM320_rtc.h

+13-20
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ typedef struct {
4040
uint8_t Second;
4141
} RTC_DateTime;
4242

43+
44+
/* Interrupt Type */
45+
#define RTC_IT_SECOND (1 << 0) //Second Interrupt
46+
#define RTC_IT_MINUTE (1 << 1)
47+
#define RTC_IT_HOUR (1 << 2)
48+
#define RTC_IT_DATE (1 << 3)
49+
#define RTC_IT_ALARM (1 << 4)
50+
51+
4352
void RTC_Init(RTC_TypeDef * RTCx, RTC_InitStructure * initStruct);
4453
void RTC_Start(RTC_TypeDef * RTCx);
4554
void RTC_Stop(RTC_TypeDef * RTCx);
@@ -49,25 +58,9 @@ void RTC_GetDateTime(RTC_TypeDef * RTCx, RTC_DateTime * dateTime);
4958
void RTC_AlarmSetup(RTC_TypeDef * RTCx, RTC_AlarmStructure * alarmStruct);
5059

5160

52-
void RTC_IntSecondEn(RTC_TypeDef * RTCx);
53-
void RTC_IntSecondDis(RTC_TypeDef * RTCx);
54-
void RTC_IntSecondClr(RTC_TypeDef * RTCx);
55-
uint32_t RTC_IntSecondStat(RTC_TypeDef * RTCx);
56-
void RTC_IntMinuteEn(RTC_TypeDef * RTCx);
57-
void RTC_IntMinuteDis(RTC_TypeDef * RTCx);
58-
void RTC_IntMinuteClr(RTC_TypeDef * RTCx);
59-
uint32_t RTC_IntMinuteStat(RTC_TypeDef * RTCx);
60-
void RTC_IntHourEn(RTC_TypeDef * RTCx);
61-
void RTC_IntHourDis(RTC_TypeDef * RTCx);
62-
void RTC_IntHourClr(RTC_TypeDef * RTCx);
63-
uint32_t RTC_IntHourStat(RTC_TypeDef * RTCx);
64-
void RTC_IntDateEn(RTC_TypeDef * RTCx);
65-
void RTC_IntDateDis(RTC_TypeDef * RTCx);
66-
void RTC_IntDateClr(RTC_TypeDef * RTCx);
67-
uint32_t RTC_IntDateStat(RTC_TypeDef * RTCx);
68-
void RTC_IntAlarmEn(RTC_TypeDef * RTCx);
69-
void RTC_IntAlarmDis(RTC_TypeDef * RTCx);
70-
void RTC_IntAlarmClr(RTC_TypeDef * RTCx);
71-
uint32_t RTC_IntAlarmStat(RTC_TypeDef * RTCx);
61+
void RTC_INTEn(RTC_TypeDef * RTCx, uint32_t it);
62+
void RTC_INTDis(RTC_TypeDef * RTCx, uint32_t it);
63+
void RTC_INTClr(RTC_TypeDef * RTCx, uint32_t it);
64+
uint32_t RTC_INTStat(RTC_TypeDef * RTCx, uint32_t it);
7265

7366
#endif //__SWM320_RTC_H__

0 commit comments

Comments
 (0)