1 /** mbed Microcontroller Library 2 ****************************************************************************** 3 * @file rtc_api.h 4 * @author 5 * @version V1.0.0 6 * @brief This file provides mbed RTC API 7 ****************************************************************************** 8 * @attention 9 * 10 * Copyright (c) 2006-2013 ARM Limited 11 * 12 * Licensed under the Apache License, Version 2.0 (the "License"); 13 * you may not use this file except in compliance with the License. 14 * You may obtain a copy of the License at 15 * 16 * http://www.apache.org/licenses/LICENSE-2.0 17 * 18 * Unless required by applicable law or agreed to in writing, software 19 * distributed under the License is distributed on an "AS IS" BASIS, 20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 * See the License for the specific language governing permissions and 22 * limitations under the License. 23 ****************************************************************************** 24 */ 25 #ifndef MBED_RTC_API_H 26 #define MBED_RTC_API_H 27 28 #include "device.h" 29 #include <time.h> 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 /** @addtogroup rtc RTC 36 * @ingroup hal 37 * @brief rtc functions 38 * @{ 39 */ 40 41 #if (defined(CONFIG_PLATFORM_8711B) && CONFIG_PLATFORM_8711B) || defined(CONFIG_PLATFORM_8721D) && \ 42 CONFIG_PLATFORM_8721D || (defined(CONFIG_PLATFORM_8195BLP) && CONFIG_PLATFORM_8195BLP) 43 44 ///@name AmebaZ and AmebaPro and AmebaD 45 ///@{ 46 typedef void (*alarm_irq_handler)(void); 47 48 struct alarm_s { 49 uint32_t yday;//which day of the year 50 uint32_t hour; 51 uint32_t min; 52 uint32_t sec; 53 }; 54 55 typedef struct alarm_s alarm_t; 56 ///@} 57 #endif //CONFIG_PLATFORM_8711B || CONFIG_PLATFORM_8195BLP 58 59 ///@name Ameba Common 60 ///@{ 61 62 /** 63 * @brief Initializes the RTC device, include clock, RTC registers and function. 64 * @param none 65 * @retval none 66 */ 67 void rtc_init(void); 68 69 /** 70 * @brief Deinitializes the RTC device. 71 * @param none 72 * @retval none 73 */ 74 void rtc_free(void); 75 76 /** 77 * @brief This function tells whether RTC is enabled or not. 78 * @param none 79 * @retval 1: RTC is enable. 80 * @retval 0: RTC is disable. 81 */ 82 int rtc_isenabled(void); 83 84 /** 85 * @brief Get current timestamp in seconds from RTC. 86 * @param none 87 * @retval : The current timestamp in seconds which is calculated from 1970.1.1 00:00:00. 88 */ 89 time_t rtc_read(void); 90 91 /** 92 * @brief Set the specified timestamp in seconds to RTC. 93 * @param t: Seconds from 1970.1.1 00:00:00 to specified data and time which is to be set. 94 * @retval none 95 */ 96 void rtc_write(time_t t); 97 98 ///@} 99 100 #if ((defined(CONFIG_PLATFORM_8711B) && CONFIG_PLATFORM_8711B) || \ 101 (defined(CONFIG_PLATFORM_8195BLP) && CONFIG_PLATFORM_8195BLP)) 102 ///@name AmebaZ and AmebaPro 103 ///@{ 104 /** 105 * @brief Set the specified RTC Alarm and interrupt. 106 * @param alarm: alarm object define in application software. 107 * @param alarmHandler: alarm interrupt callback function. 108 * @retval status: 109 * - 1: success 110 * - Others: failure 111 */ 112 u32 rtc_set_alarm(alarm_t *alrm, alarm_irq_handler alarmHandler); 113 114 /** 115 * @brief Disable RTC Alarm and function. 116 * @param none 117 * @retval none 118 */ 119 void rtc_disable_alarm(void); 120 ///@} 121 #endif //CONFIG_PLATFORM_8711B || CONFIG_PLATFORM_8195BLP 122 123 /*\@}*/ 124 125 #ifdef __cplusplus 126 } 127 #endif 128 129 #endif 130