lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /** |
| 2 | * @file rtc_timer.h |
| 3 | * @brief Public APIs of Sanechips |
| 4 | * |
| 5 | * Copyright (C) 2017 Sanechips Technology Co., Ltd. |
| 6 | * @author Linxu Gebin |
| 7 | * @defgroup si_id Sanechips |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | ************************************************************************* |
| 13 | */ |
| 14 | |
| 15 | #ifndef _RTC_TIMER_H |
| 16 | #define _RTC_TIMER_H |
| 17 | |
| 18 | /******************************************************************************* |
| 19 | * Include header files * |
| 20 | ******************************************************************************/ |
| 21 | #include <sys/time.h> |
| 22 | #include "message.h" |
| 23 | |
| 24 | /******************************************************************************* |
| 25 | * Macro definitions * |
| 26 | ******************************************************************************/ |
| 27 | |
| 28 | #ifndef DOXYGEN_SHOULD_SKIP_THIS |
| 29 | /******************************************************************************* |
| 30 | * Type definitions * |
| 31 | ******************************************************************************/ |
| 32 | /** |
| 33 | * @brief rtc message type |
| 34 | * @note |
| 35 | */ |
| 36 | enum RTC_CPU { |
| 37 | RTC_CPU_CP = 0, //rtcÓÉcp·¢Æð |
| 38 | RTC_CPU_AP, //rtcÓÉAP·¢Æð |
| 39 | }; |
| 40 | |
| 41 | /** |
| 42 | * @brief rtc type |
| 43 | * @note |
| 44 | */ |
| 45 | typedef enum { |
| 46 | RTC_ID_START = 0, |
| 47 | WIFI_INTERVAL_SLEEP, |
| 48 | WIFI_PWR_SAVE, |
| 49 | WIFI_WAKE_UP_SYSTEM, |
| 50 | WIFI_WPS_RESULT_CHECK, |
| 51 | WIFI_TSW_SLEEP, |
| 52 | WIFI_TSW_WAKEUP, |
| 53 | WIFI_ACL_SERVICE, |
| 54 | WDT_TEMP_PROTECT, |
| 55 | RTC_SAFECARE_CONTIME, |
| 56 | RTC_SAFECARE_DELAY, |
| 57 | RTC_ID_FP_CLOCK, |
| 58 | RTC_ID_NOTDISTURB_BEGIN, |
| 59 | RTC_ID_NOTDISTURB_END, |
| 60 | RTC_ID_MMI_ALARM, |
| 61 | RTC_ID_MMI_CLOCK_MODE_CHECK, |
| 62 | RTC_ID_TRACK_BEGIN, |
| 63 | RTC_ID_TRACK_UPLOAD=RTC_ID_TRACK_BEGIN, |
| 64 | RTC_ID_TRACK_BASE, |
| 65 | RTC_ID_TRACK_SERVER_CON, |
| 66 | RTC_ID_TRACK_SLAVE_SERVER_CON, |
| 67 | RTC_ID_TRACK_SLAVE_SERVER_CMD, |
| 68 | RTC_ID_TRACK_DEBUG_SERVER_CON, |
| 69 | RTC_ID_TRACK_LINK, |
| 70 | RTC_ID_TRACK_LINK_TIMEOUT, |
| 71 | RTC_ID_TRACK_AGPS, |
| 72 | RTC_ID_TRACK_WEATHER_UPDATE, |
| 73 | RTC_ID_TRACK_END, |
| 74 | RTC_ID_END, |
| 75 | } RTC_ID; |
| 76 | #endif |
| 77 | |
| 78 | /** |
| 79 | * @brief rtc ÏûÏ¢ÀàÐÍ |
| 80 | * @param RTC_MSG_ALARM_ELAPSED µ±¶¨Ê±Æ÷´¥·¢Ê±»á·¢Õâ¸öÏûÏ¢¸ø¶¨Ê±Æ÷ÓµÓÐÕß |
| 81 | * @param RTC_MSG_TIME_CHANGED RTCʱ¼ä¸üÐÂ:±íʾÊÀ½çʱ¼ä·¢Éú±ä»¯£¬¼´Ê±¼äͬ²½Íê³É»òÕßÓû§ÊÖ¶¯ÖØÐÂÉèÖõ±Ç°µÄÊÀ½çʱ¼äÁË£¬´ËʱRTC½ø³Ì»á¹ã²¥¸øÒÑ×¢²áÊÀ½çʱ¼äµÄÄ£¿é£¬ÒÔÈÃÏà¹ØÄ£¿é½øÐÐÊÀ½çʱ¼ä¶¨Ê±Æ÷µÄÖØÐÂÉèÖà |
| 82 | * @note |
| 83 | */ |
| 84 | #ifndef DOXYGEN_SHOULD_SKIP_THIS |
| 85 | enum RTC_MSG_CMD { |
| 86 | RTC_MSG_GET_TIME = MSG_CMD_RTC_BASE, //»ñȡʱ¼ä£¬Ö±½Óµ÷ÓÃlinuxϵͳʱ¼ä½Ó¿Ú |
| 87 | RTC_MSG_SET_TIME, //ÉèÖÃʱ¼ä |
| 88 | RTC_MSG_ADD_ALARM, //Ìí¼Órtc¶¨Ê±Æ÷ |
| 89 | RTC_MSG_DEL_ALARM, //ɾ³ýrtc¶¨Ê±Æ÷ |
| 90 | RTC_MSG_ALARM_TIMEOUT, //RTC alarm¶¨Ê±Æ÷ʱ¼ä³¬Ê± |
| 91 | RTC_MSG_TIMER_TIMEOUT, //RTC timer¶¨Ê±Æ÷ʱ¼ä³¬Ê± |
| 92 | RTC_MSG_ALARM_ELAPSED, //µ±¶¨Ê±Æ÷´¥·¢Ê±»á·¢Õâ¸öÏûÏ¢¸ø¶¨Ê±Æ÷ÓµÓÐÕß |
| 93 | RTC_MSG_DEL_ALL, //Çå³ýËùÓйػú²»±£´æµÄ¶¨Ê±Æ÷£¬·ñÔòrtc¶¨Ê±Æ÷µ½µã»¹»áÉϱ¨ |
| 94 | RTC_MSG_TIME_CHANGED, //RTCʱ¼ä¸üÐÂ:±íʾÊÀ½çʱ¼ä·¢Éú±ä»¯£¬¼´Ê±¼äͬ²½Íê³É»òÕßÓû§ÊÖ¶¯ÖØÐÂÉèÖõ±Ç°µÄÊÀ½çʱ¼äÁË£¬´ËʱRTC½ø³Ì»á¹ã²¥¸øÒÑ×¢²áÊÀ½çʱ¼äµÄÄ£¿é£¬ÒÔÈÃÏà¹ØÄ£¿é½øÐÐÊÀ½çʱ¼ä¶¨Ê±Æ÷µÄÖØÐÂÉèÖà |
| 95 | }; |
| 96 | #endif |
| 97 | |
| 98 | /** |
| 99 | * @brief rtc data buffer |
| 100 | * @param srcModule ´´½¨¶¨Ê±Æ÷µÄÄ£¿é |
| 101 | * @param module ¶¨Ê±Æ÷id |
| 102 | * @param ulSec ¼ä¸ôʱ¼ä£¬µ¥Î»:s |
| 103 | * @param time_val µ±Ç°Ê±¼ä |
| 104 | * @param wakeup ¹Ø»ú»½ÐÑ£¬1:´ò¿ª£¬0:¹Ø±Õ |
| 105 | * @param is_utc ÊÇ·ñutcʱ¼ä£¬ |
| 106 | * @param cpu rtc·¢ÆðµÄcpu£¬ 0: cp, 1:ap |
| 107 | * @note utcʱ¼äÕý³£±È½Ï³¤£¬ÓÃWKALM¶¨Ê±Æ÷ |
| 108 | */ |
| 109 | typedef struct tag_RTC_DATA_BUF { |
| 110 | int srcModule; |
| 111 | unsigned int module; |
| 112 | unsigned long ulSec; |
| 113 | unsigned long time_val; |
| 114 | int wakeup; |
| 115 | int is_utc; |
| 116 | int cpu; |
| 117 | } RTC_DATA_BUF; |
| 118 | |
| 119 | |
| 120 | /******************************************************************************* |
| 121 | * Global function declarations * |
| 122 | ******************************************************************************/ |
| 123 | /** |
| 124 | * @brief Ìí¼Ó¶¨Ê±Æ÷ |
| 125 | * @param ulSec ¶¨Ê±Æ÷ʱ¼ä£¬µ¥Î»Ãë |
| 126 | * @param rtc_id ¶¨Ê±Æ÷ID |
| 127 | * @param src_id ´´½¨¶¨Ê±Æ÷µÄÄ£¿éID |
| 128 | * @return ³É¹¦·µ»Ø0£¬Ê§°Ü·µ»Ø-1 |
| 129 | */ |
| 130 | int rtc_timer_add(unsigned long ulSec, RTC_ID rtc_id, int src_id); |
| 131 | |
| 132 | /** |
| 133 | * @brief Ìí¼Ó¶¨Ê±Æ÷ |
| 134 | * @param time ¶¨Ê±Æ÷ʱ¼ä£¬µ¥Î»ÊÀ½çʱÖÓ,ÐèÒªÌî: tm_sec/tm_min/tm_hour/tm_mday/tm_mon/tm_year |
| 135 | * @param rtc_id ¶¨Ê±Æ÷ID£¬ |
| 136 | * @param src_id ´´½¨¶¨Ê±Æ÷µÄÄ£¿éID |
| 137 | * @param wakeup ¹Ø»úÊÇ·ñ»½ÐÑ |
| 138 | * @note wakeup ÊÇ0²»»½ÐÑ, 1 »½ÐÑ |
| 139 | * @return ³É¹¦·µ»Ø0£¬Ê§°Ü·µ»Ø-1 |
| 140 | */ |
| 141 | int rtc_timer_add_utc(struct tm *time, RTC_ID rtc_id, int src_id, int wakeup); |
| 142 | |
| 143 | |
| 144 | /** |
| 145 | * @brief ɾ³ý¶¨Ê±Æ÷ |
| 146 | * @param rtc_id ¶¨Ê±Æ÷ID |
| 147 | * @param src_id ´´½¨¶¨Ê±Æ÷µÄÄ£¿éID |
| 148 | * @return ³É¹¦·µ»Ø0£¬Ê§°Ü·µ»Ø-1 |
| 149 | */ |
| 150 | int rtc_timer_del(RTC_ID rtc_id, int src_id); |
| 151 | |
| 152 | |
| 153 | /** |
| 154 | * @brief ɾ³ýËùÓж¨Ê±Æ÷ |
| 155 | * @param src_id ɾ³ý¶¨Ê±Æ÷µÄÄ£¿éID |
| 156 | * @param req_cmd »Ø¸´µÄÏûÏ¢cmd |
| 157 | * @return ³É¹¦·µ»Ø0£¬Ê§°Ü·µ»Ø-1 |
| 158 | */ |
| 159 | int rtc_timer_del_all(int src_id, unsigned short req_cmd); |
| 160 | |
| 161 | |
| 162 | /** |
| 163 | * @brief ÉèÖÃrtcµ±Ç°Ê±¼ä |
| 164 | * @param src_id ÉèÖÃʱ¼äµÄÄ£¿éID |
| 165 | * @return ÉèÖÃrtcµ±Ç°Ê±¼ä |
| 166 | */ |
| 167 | int rtc_set_time(int src_id); |
| 168 | |
| 169 | #endif |
| 170 | |
| 171 | |