PDL for FM4  Version1.2
Peripheral Driverl Library for FM4
rtc.h
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright (C) 2013 Spansion LLC. All Rights Reserved.
3 *
4 * This software is owned and published by:
5 * Spansion LLC, 915 DeGuigne Dr. Sunnyvale, CA 94088-3453 ("Spansion").
6 *
7 * BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
8 * BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
9 *
10 * This software contains source code for use with Spansion
11 * components. This software is licensed by Spansion to be adapted only
12 * for use in systems utilizing Spansion components. Spansion shall not be
13 * responsible for misuse or illegal use of this software for devices not
14 * supported herein. Spansion is providing this software "AS IS" and will
15 * not be responsible for issues arising from incorrect user implementation
16 * of the software.
17 *
18 * SPANSION MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
19 * REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
20 * ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
21 * WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
22 * WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
23 * WARRANTY OF NONINFRINGEMENT.
24 * SPANSION SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
25 * NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
26 * LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
27 * LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
28 * INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
29 * INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
30 * SAVINGS OR PROFITS,
31 * EVEN IF SPANSION HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
32 * YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
33 * INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
34 * FROM, THE SOFTWARE.
35 *
36 * This software may be replicated in part or whole for the licensed use,
37 * with the restriction that this Disclaimer and Copyright notice must be
38 * included with each copy of this software, whether used in part or whole,
39 * at all times.
40 */
41 /******************************************************************************/
55 #ifndef __RTC_H__
56 #define __RTC_H__
57 
58 /******************************************************************************/
59 /* Include files */
60 /******************************************************************************/
61 #include "pdl.h"
62 #include "time.h"
63 
64 #if (defined(PDL_PERIPHERAL_RTC_ACTIVE))
65 
66 /* C binding of definitions if building with C++ compiler */
67 #ifdef __cplusplus
68 extern "C"
69 {
70 #endif
71 
134 
140 /******************************************************************************
141  * Global definitions
142  ******************************************************************************/
143 
144 #define RTC0 (*((volatile stc_rtcn_t *)FM4_RTC_BASE))
145 
146 #define RTC_INTERRUPT_ENABLE_MASK (0xFFu)
147 #define RTC_POLLING_TIMEOUT (100000u)
148 #define RTC_BUSY_POLLING_TIMEOUT (200000u)
149 #define RTC_TRANS_POLLING_TIMEOUT (500000u)
150 
151 
155 #define Rtc_Year(a) ((a) - 2000)
156 
166 #define RTC_WTCR11_MIEN_FLAG_POSITION (0x01u)
167 #define RTC_WTCR11_HEN_FLAG_POSITION (0x02u)
168 #define RTC_WTCR11_DEN_FLAG_POSITION (0x04u)
169 #define RTC_WTCR11_MOEN_FLAG_POSITION (0x08u)
170 #define RTC_WTCR11_YEN_FLAG_POSITION (0x10u)
171 #define RTC_WTCR11_ALL_FLAG_POSITION (0x1Fu)
172 
177 #define RTC_WTCR12_INTSSI_FLAG_POSITION (0x01u)
178 #define RTC_WTCR12_INTSI_FLAG_POSITION (0x02u)
179 #define RTC_WTCR12_INTMI_FLAG_POSITION (0x04u)
180 #define RTC_WTCR12_INTHI_FLAG_POSITION (0x08u)
181 #define RTC_WTCR12_INTTMI_FLAG_POSITION (0x10u)
182 #define RTC_WTCR12_INTALI_FLAG_POSITION (0x20u)
183 #define RTC_WTCR12_INTERI_FLAG_POSITION (0x40u)
184 #define RTC_WTCR12_INTCRI_FLAG_POSITION (0x80u)
185 
190 #define RTC_MAX_FREQ_CORR_VALUE (0x3FFu)
191 
196 #define RTC_MAX_FREQ_CORR_CYCLE_SET_VALUE (0x3Fu)
197 
202 #define RTC_MAX_TIMER_SET_VALUE (0x2A2FFu)
203 
208 #define RTC_BKUP_REG_BASE (FM4_PERIPH_BASE + 0x3B200UL) /* Backup registers */
209 
210 /******************************************************************************
211  * Global type definitions
212  ******************************************************************************/
213 typedef FM4_RTC_TypeDef stc_rtcn_t;
214 
216 typedef void (*func_ptr_rtc_arglist_t)(uint8_t, /* Second */
217  uint8_t, /* Minute */
218  uint8_t, /* Hour */
219  uint8_t, /* Day */
220  uint8_t, /* Day of Week */
221  uint8_t, /* Month */
222  uint8_t); /* Year */
223 
229 typedef enum en_rtc_month
230 {
235  Rtc_May = 5,
236  Rtc_June = 6,
237  Rtc_July = 7,
244 
250 typedef enum en_rtc_day_of_week
251 {
260 
268 {
273 
281 {
286 
295 {
296  RtcDivRatio1 = 0x00,
297  RtcDivRatio2 = 0x01,
298  RtcDivRatio4 = 0x02,
299  RtcDivRatio8 = 0x03,
300  RtcDivRatio16 = 0x04,
301  RtcDivRatio32 = 0x05,
302  RtcDivRatio64 = 0x06,
303  RtcDivRatio128 = 0x07,
304  RtcDivRatio256 = 0x08,
305  RtcDivRatio512 = 0x09,
313 
318 typedef enum en_rtc_co_div
319 {
320  RtcCoDiv1 = 0,
322 } en_rtc_co_div_t ;
323 
329 {
334 
340 {
373 #if (PDL_DEVICE_TYPE != PDL_TYPE0)
374  RtcBkupRegArea20,
375  RtcBkupRegArea21,
376  RtcBkupRegArea22,
377  RtcBkupRegArea23,
378  RtcBkupRegArea24,
379  RtcBkupRegArea25,
380  RtcBkupRegArea26,
381  RtcBkupRegArea27,
382  RtcBkupRegArea28,
383  RtcBkupRegArea29,
384  RtcBkupRegArea2A,
385  RtcBkupRegArea2B,
386  RtcBkupRegArea2C,
387  RtcBkupRegArea2D,
388  RtcBkupRegArea2E,
389  RtcBkupRegArea2F,
390  RtcBkupRegArea30,
391  RtcBkupRegArea31,
392  RtcBkupRegArea32,
393  RtcBkupRegArea33,
394  RtcBkupRegArea34,
395  RtcBkupRegArea35,
396  RtcBkupRegArea36,
397  RtcBkupRegArea37,
398  RtcBkupRegArea38,
399  RtcBkupRegArea39,
400  RtcBkupRegArea3A,
401  RtcBkupRegArea3B,
402  RtcBkupRegArea3C,
403  RtcBkupRegArea3D,
404  RtcBkupRegArea3E,
405  RtcBkupRegArea3F,
406  RtcBkupRegArea40,
407  RtcBkupRegArea41,
408  RtcBkupRegArea42,
409  RtcBkupRegArea43,
410  RtcBkupRegArea44,
411  RtcBkupRegArea45,
412  RtcBkupRegArea46,
413  RtcBkupRegArea47,
414  RtcBkupRegArea48,
415  RtcBkupRegArea49,
416  RtcBkupRegArea4A,
417  RtcBkupRegArea4B,
418  RtcBkupRegArea4C,
419  RtcBkupRegArea4D,
420  RtcBkupRegArea4E,
421  RtcBkupRegArea4F,
422  RtcBkupRegArea50,
423  RtcBkupRegArea51,
424  RtcBkupRegArea52,
425  RtcBkupRegArea53,
426  RtcBkupRegArea54,
427  RtcBkupRegArea55,
428  RtcBkupRegArea56,
429  RtcBkupRegArea57,
430  RtcBkupRegArea58,
431  RtcBkupRegArea59,
432  RtcBkupRegArea5A,
433  RtcBkupRegArea5B,
434  RtcBkupRegArea5C,
435  RtcBkupRegArea5D,
436  RtcBkupRegArea5E,
437  RtcBkupRegArea5F,
438  RtcBkupRegArea60,
439  RtcBkupRegArea61,
440  RtcBkupRegArea62,
441  RtcBkupRegArea63,
442  RtcBkupRegArea64,
443  RtcBkupRegArea65,
444  RtcBkupRegArea66,
445  RtcBkupRegArea67,
446  RtcBkupRegArea68,
447  RtcBkupRegArea69,
448  RtcBkupRegArea6A,
449  RtcBkupRegArea6B,
450  RtcBkupRegArea6C,
451  RtcBkupRegArea6D,
452  RtcBkupRegArea6E,
453  RtcBkupRegArea6F,
454  RtcBkupRegArea70,
455  RtcBkupRegArea71,
456  RtcBkupRegArea72,
457  RtcBkupRegArea73,
458  RtcBkupRegArea74,
459  RtcBkupRegArea75,
460  RtcBkupRegArea76,
461  RtcBkupRegArea77,
462  RtcBkupRegArea78,
463  RtcBkupRegArea79,
464  RtcBkupRegArea7A,
465  RtcBkupRegArea7B,
466  RtcBkupRegArea7C,
467  RtcBkupRegArea7D,
468  RtcBkupRegArea7E,
469  RtcBkupRegArea7F,
470 #endif
473 
480 typedef struct stc_rtc_interrupts
481 {
482  uint8_t HalfSecondIrqEn : 1;
483 
484  uint8_t OneSecondIrqEn : 1;
485 
486  uint8_t OneMinuteIrqEn : 1;
487 
488  uint8_t OneHourIrqEn : 1;
489 
490  uint8_t TimerIrqEn : 1;
491 
492  uint8_t AlarmIrqEn : 1;
493 
494  uint8_t TimeRewriteErrorIrqEn : 1;
495 
496  uint8_t ReadCompletionIrqEn : 1;
497 
499 
506 typedef struct stc_rtc_alarm_enable
507 {
508  uint8_t AlarmYearEnable : 1;
509 
510  uint8_t AlarmMonthEnable : 1;
511 
512  uint8_t AlarmDayEnable : 1;
513 
514  uint8_t AlarmHourEnable : 1;
515 
516  uint8_t AlarmMinuteEnable : 1;
517 
518  uint8_t Reserved : 3;
520 
525 typedef struct stc_rtc_time
526 {
527  uint8_t u8Second;
528  uint8_t u8Minute;
529  uint8_t u8Hour;
530  uint8_t u8Day;
531  uint8_t u8DayOfWeek;
532  uint8_t u8Month;
533  uint8_t u8Year;
535 
540 typedef struct stc_rtc_alarm
541 {
542  uint8_t u8AlarmMinute;
543  uint8_t u8AlarmHour;
544  uint8_t u8AlarmDay;
545  uint8_t u8AlarmMonth;
546  uint8_t u8AlarmYear;
548 
555 typedef struct stc_rtc_config
556 {
558 
560 
561  union
562  {
563  uint16_t u16FreqCorrValue;
564  struct
565  {
568  };
569  };
570  uint8_t u8DividerRatio;
571  uint8_t u8FreqCorrCycle;
572  uint8_t u8CoSignalDiv;
573  union
574  {
576  uint8_t u8AllInterrupts;
577  };
588 
595 typedef struct stc_rtc_timer_config
596 {
597  union {
598  uint32_t u32TimerValue;
599  struct {
600  uint8_t u8TimerValue0;
601  uint8_t u8TimerValue1;
602  uint8_t u8TimerValue2;
603  uint8_t Reserved;
604  };
605  };
607 
609 
610 /******************************************************************************/
611 /* Local type definitions ('typedef') */
612 /******************************************************************************/
614 typedef struct stc_rtc_intern_data
615 {
624 
626  uint32_t u32RawTime;
627  struct tm* pstcCalendar;
629 
630 /******************************************************************************/
631 /* Global variable definitions ('extern') */
632 /******************************************************************************/
633 
634 /******************************************************************************/
635 /* Global function prototypes (definition in C source) */
636 /******************************************************************************/
637 extern void RtcIrqHandler(void);
638 
639 extern en_result_t Rtc_Init(stc_rtc_config_t* pstcConfig,
640  stc_rtc_time_t* pstcTime,
641  stc_rtc_alarm_t* pstcAlarm,
642  boolean_t bTouchNvic,
643  boolean_t bResetNoReInit
644  );
645 
646 extern boolean_t Rtc_GetRunStatus(void);
647 
648 extern en_result_t Rtc_SetDateTime(stc_rtc_time_t* pstcRtcTime);
649 
650 extern en_result_t Rtc_SetAlarmDateTime(stc_rtc_alarm_t* pstcRtcAlarm);
651 
653 
655 
657 
658 extern en_result_t Rtc_RequestDateTime(void);
659 
661 
662 extern en_result_t Rtc_TimerStart(void);
663 
664 extern en_result_t Rtc_TimerStop(void);
665 
667 
669 
670 extern en_result_t Rtc_DeInit(void);
671 
672 extern time_t Rtc_GetRawTime(stc_rtc_time_t* pstcRtcTime);
673 
674 extern en_result_t Rtc_SetDayOfWeek(stc_rtc_time_t* pstcRtcTime);
675 
676 extern en_result_t Rtc_SetTime(stc_rtc_time_t* pstcRtcTime,
677  time_t tRawTime
678  );
679 
680 /* Access to back up register */
681 extern en_result_t Rtc_WriteBkupReg8(uint8_t u8Data,
682  uint8_t u8Area
683  );
684 extern en_result_t Rtc_WriteBkupReg16(uint16_t u16Data,
685  uint8_t u8Area
686  );
687 extern en_result_t Rtc_WriteBkupReg32(uint32_t u32Data,
688  uint8_t u8Area
689  );
690 
691 extern uint8_t Rtc_ReadBkupReg8 (uint8_t u8Area);
692 extern uint16_t Rtc_ReadBkupReg16(uint8_t u8Area);
693 extern uint32_t Rtc_ReadBkupReg32(uint8_t u8Area);
694 
696 
697 #ifdef __cplusplus
698 }
699 #endif
700 
701 #endif /* #if (defined(PDL_PERIPHERAL_RTC_ACTIVE)) */
702 
703 #endif /* __RTC_H__ */
704 /******************************************************************************/
705 /* EOF (not truncated) */
706 /******************************************************************************/