![]() |
PDL for FM0+
Version1.0
Peripheral Driverl Library for FM0+
|
00001 /******************************************************************************* 00002 * Copyright (C) 2013 Spansion LLC. All Rights Reserved. 00003 * 00004 * This software is owned and published by: 00005 * Spansion LLC, 915 DeGuigne Dr. Sunnyvale, CA 94088-3453 ("Spansion"). 00006 * 00007 * BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND 00008 * BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT. 00009 * 00010 * This software contains source code for use with Spansion 00011 * components. This software is licensed by Spansion to be adapted only 00012 * for use in systems utilizing Spansion components. Spansion shall not be 00013 * responsible for misuse or illegal use of this software for devices not 00014 * supported herein. Spansion is providing this software "AS IS" and will 00015 * not be responsible for issues arising from incorrect user implementation 00016 * of the software. 00017 * 00018 * SPANSION MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE, 00019 * REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS), 00020 * ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING, 00021 * WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED 00022 * WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED 00023 * WARRANTY OF NONINFRINGEMENT. 00024 * SPANSION SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT, 00025 * NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT 00026 * LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, 00027 * LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR 00028 * INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT, 00029 * INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA, 00030 * SAVINGS OR PROFITS, 00031 * EVEN IF SPANSION HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 00032 * YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR 00033 * INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED 00034 * FROM, THE SOFTWARE. 00035 * 00036 * This software may be replicated in part or whole for the licensed use, 00037 * with the restriction that this Disclaimer and Copyright notice must be 00038 * included with each copy of this software, whether used in part or whole, 00039 * at all times. 00040 */ 00041 /******************************************************************************/ 00052 #ifndef __RTC_H__ 00053 #define __RTC_H__ 00054 00055 /******************************************************************************/ 00056 /* Include files */ 00057 /******************************************************************************/ 00058 #include "mcu.h" 00059 #include "pdl_user.h" 00060 #include "time.h" 00061 00062 #if (defined(PDL_PERIPHERAL_RTC_ACTIVE)) 00063 00064 /* C binding of definitions if building with C++ compiler */ 00065 #ifdef __cplusplus 00066 extern "C" 00067 { 00068 #endif 00069 00130 00136 /****************************************************************************** 00137 * Global definitions 00138 ******************************************************************************/ 00143 #define RTC_MAX_FREQ_CORR_VALUE (0x3FFu) 00144 00149 #define RTC_MAX_FREQ_CORR_CYCLE_SET_VALUE (0x3Fu) 00150 00155 #define RTC_MAX_TIMER_SET_VALUE (0x20000) 00156 00157 /****************************************************************************** 00158 * Global type definitions 00159 ******************************************************************************/ 00164 typedef enum en_rtc_clk_sel 00165 { 00166 RtcUseSubClk = 0u, 00167 RtcuseMainClk = 1u, 00168 00169 }en_rtc_clk_sel_t; 00170 00178 typedef enum en_rtc_rtcco_sel 00179 { 00180 RtccoOutput2Hz = 0, 00181 RtccoOutput1Hz = 1, 00182 00183 }en_rtc_rtcco_sel_t; 00184 00189 typedef struct stc_rtc_freq_corr 00190 { 00191 uint16_t u16FreqCorrValue; 00192 uint16_t u16FreqCorrCycle; 00193 00194 }stc_rtc_freq_corr_t; 00195 00200 typedef enum en_rtc_func 00201 { 00202 RtcCount = 0u, 00203 RtcTimer = 1u, 00204 RtcFreqCorr = 2u, 00205 RtcAlarmYearEn = 3u, 00206 RtcAlarmMonthEn = 4u, 00207 RtcAlarmDayEn = 5u, 00208 RtcAlarmHourEn = 6u, 00209 RtcAlarmMinEn = 7u, 00210 00211 }en_rtc_func_t; 00212 00217 typedef enum en_rtc_day_of_week 00218 { 00219 RtcSunday = 0, 00220 RtcMonday = 1, 00221 RtcTuesday = 2, 00222 RtcWednesday = 3, 00223 RtcThursday = 4, 00224 RtcFriday = 5, 00225 RtcSaturday = 6 00226 } en_rtc_day_of_week_t; 00227 00233 typedef enum en_rtc_month 00234 { 00235 RtcJanuary = 1, 00236 RtcFebuary = 2, 00237 RtcMarch = 3, 00238 RtcApril = 4, 00239 RtcMay = 5, 00240 RtcJune = 6, 00241 RtcJuly = 7, 00242 RtcAugust = 8, 00243 RtcSeptember = 9, 00244 RtcOctober = 10, 00245 RtcNovember = 11, 00246 RtcDecember = 12 00247 } en_rtc_month_t; 00248 00253 typedef enum en_rtc_time_mode 00254 { 00255 RtcTimerOneshot = 0u, 00256 RtcTimerPeriod = 1u, 00257 00258 }en_rtc_time_mode_t; 00259 00264 typedef struct stc_rtc_timer 00265 { 00266 en_rtc_time_mode_t enMode; 00267 uint32_t u32TimerCycle; 00268 00269 }stc_rtc_timer_t; 00270 00278 typedef enum en_rtc_div_ratio 00279 { 00280 RtcDivRatio1 = 0x00u, 00281 RtcDivRatio2 = 0x01u, 00282 RtcDivRatio4 = 0x02u, 00283 RtcDivRatio8 = 0x03u, 00284 RtcDivRatio16 = 0x04u, 00285 RtcDivRatio32 = 0x05u, 00286 RtcDivRatio64 = 0x06u, 00287 RtcDivRatio128 = 0x07u, 00288 RtcDivRatio256 = 0x08u, 00289 RtcDivRatio512 = 0x09u, 00290 RtcDivRatio1024 = 0x0Au, 00291 RtcDivRatio2048 = 0x0Bu, 00292 RtcDivRatio4096 = 0x0Cu, 00293 RtcDivRatio8192 = 0x0Du, 00294 RtcDivRatio16384 = 0x0Eu, 00295 RtcDivRatio32768 = 0x0Fu, 00296 } en_rtc_div_ratio_t ; 00297 00302 typedef struct stc_rtc_int_sel 00303 { 00304 uint8_t HalfSecondInt : 1; 00305 00306 uint8_t OneSecondInt : 1; 00307 00308 uint8_t OneMinuteInt : 1; 00309 00310 uint8_t OneHourInt : 1; 00311 00312 uint8_t TimerInt : 1; 00313 00314 uint8_t AlarmInt : 1; 00315 00316 uint8_t TimeRewriteErrorInt : 1; 00317 00318 } stc_rtc_int_sel_t; 00319 00324 typedef struct stc_rtc_int_cb 00325 { 00326 func_ptr_t pfnTimeWrtErrCallback; 00327 func_ptr_t pfnAlarmCallback; 00328 func_ptr_t pfnTimerCallback; 00329 func_ptr_t pfnHalfSecondCallback; 00330 func_ptr_t pfnOneSecondCallback; 00331 func_ptr_t pfnOneMinuteCallback; 00332 func_ptr_t pfnOneHourCallback; 00333 00334 }stc_rtc_int_cb_t; 00335 00340 typedef struct stc_rtc_time 00341 { 00342 uint8_t u8Second; 00343 uint8_t u8Minute; 00344 uint8_t u8Hour; 00345 uint8_t u8Day; 00346 uint8_t u8DayOfWeek; 00347 uint8_t u8Month; 00348 uint16_t u16Year; 00349 } stc_rtc_time_t; 00350 00355 typedef enum en_rtc_status 00356 { 00357 RtcRewriteError = 0u, 00358 RtcAlarmElementMatch = 1u, 00359 RtcTimerUnderFlow = 2u, 00360 RtcOneHourFlag = 3u, 00361 RtcOneMiniteFlag = 4u, 00362 RtcOneSecondFlag = 5u, 00363 RtcHalfSecondFlag = 6u, 00364 RtcRunStatus = 7u, 00365 RtcTimerStatus = 8u, 00366 00367 }en_rtc_status_t; 00368 00373 typedef struct stc_rtc_alarm 00374 { 00375 uint8_t u8Minute; 00376 uint8_t u8Hour; 00377 uint8_t u8Day; 00378 uint8_t u8Month; 00379 uint16_t u16Year; 00380 } stc_rtc_alarm_t; 00381 00388 typedef struct stc_rtc_config 00389 { 00390 en_rtc_clk_sel_t enClkSel; 00391 boolean_t bEnSuboutDivider; 00392 00393 en_rtc_div_ratio_t enDividerRatio; 00394 en_rtc_rtcco_sel_t enRtccoSel; 00395 00396 boolean_t bInitFreqCorr; 00397 00398 stc_rtc_freq_corr_t stcFreqCorrConfig; 00399 00400 boolean_t bInitTimeDate; 00401 00402 stc_rtc_time_t stcTimeDate; 00403 00404 boolean_t bInitAlarm; 00405 00406 stc_rtc_alarm_t stcAlarm; 00407 00408 boolean_t bInitTimer; 00409 00410 stc_rtc_timer_t stcTimer; 00411 00412 } stc_rtc_config_t; 00413 00414 00415 /******************************************************************************/ 00416 /* Local type definitions ('typedef') */ 00417 /******************************************************************************/ 00419 typedef struct stc_rtc_intern_data 00420 { 00421 func_ptr_t pfnTimeWrtErrCallback; 00422 func_ptr_t pfnAlarmCallback; 00423 func_ptr_t pfnTimerCallback; 00424 func_ptr_t pfnHalfSecondCallback; 00425 func_ptr_t pfnOneSecondCallback; 00426 func_ptr_t pfnOneMinuteCallback; 00427 func_ptr_t pfnOneHourCallback; 00428 00429 } stc_rtc_intern_data_t ; 00430 00431 /******************************************************************************/ 00432 /* Global function prototypes (definition in C source) */ 00433 /******************************************************************************/ 00434 #if (PDL_INTERRUPT_ENABLE_RTC == PDL_ON) 00435 void Rtc_IrqHandler(void); 00436 en_result_t Rtc_EnableInt(stc_rtc_int_sel_t* pstcIntSel, stc_rtc_int_cb_t* pstcIntCb); 00437 en_result_t Rtc_DisableInt(stc_rtc_int_sel_t* pstcIntSel); 00438 #endif 00439 00440 /* Init/De-Init */ 00441 en_result_t Rtc_Init(stc_rtc_config_t* pstcConfig); 00442 en_result_t Rtc_DeInit(void); 00443 00444 /* Function enable/disable */ 00445 en_result_t Rtc_EnableFunc(en_rtc_func_t enFunc); 00446 en_result_t Rtc_DisableFunc(en_rtc_func_t enFunc); 00447 00448 /* Rtc Reset */ 00449 void Rtc_Reset(void); 00450 00451 /* Get/Clr RTC status */ 00452 boolean_t Rtc_GetStatus(en_rtc_status_t enStatus); 00453 en_result_t Rtc_ClrStatus(en_rtc_status_t enStatus); 00454 00455 /* Calendar/Alarm set/get */ 00456 en_result_t Rtc_SetDateTime(stc_rtc_time_t* pstcTimeDate, boolean_t bContinue); 00457 en_result_t Rtc_ReadDateTime(stc_rtc_time_t* pstcTimeDate); 00458 en_result_t Rtc_SetAlarmDateTime(stc_rtc_alarm_t* pstcAlarm); 00459 en_result_t Rtc_GetAlarmDateTime(stc_rtc_alarm_t* pstcAlarm); 00460 00461 /* Set timer cycle */ 00462 en_result_t Rtc_SetTimerCycle(uint32_t u32TimerCycle); 00463 00464 /* Set frequency correction value */ 00465 en_result_t Rtc_SetFreqCorrValue(uint16_t u16Value); 00466 00467 /* Set day of week */ 00468 en_result_t Rtc_SetDayOfWeek(stc_rtc_time_t* pstcRtcTime); 00469 00470 00472 00473 #ifdef __cplusplus 00474 } 00475 #endif 00476 00477 #endif /* #if (defined(PDL_PERIPHERAL_RTC_ACTIVE)) */ 00478 00479 #endif /* __RTC_H__ */ 00480 /******************************************************************************/ 00481 /* EOF (not truncated) */ 00482 /******************************************************************************/