lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /** |
| 2 | * @file rtc-service.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_SERVICE_H |
| 16 | #define _RTC_SERVICE_H |
| 17 | |
| 18 | |
| 19 | /******************************************************************************* |
| 20 | * Include header files * |
| 21 | ******************************************************************************/ |
| 22 | #include <stdlib.h> |
| 23 | #include <stdio.h> |
| 24 | #include <string.h> |
| 25 | #include <fcntl.h> |
| 26 | #include <signal.h> |
| 27 | #include <sys/time.h> |
| 28 | #include <pthread.h> |
| 29 | #include <errno.h> |
| 30 | #include <linux/rtc.h> |
| 31 | #include <sys/ioctl.h> |
| 32 | #include <unistd.h> |
| 33 | #include <sys/stat.h> |
| 34 | #include <sys/ioctl.h> |
| 35 | #include <sys/types.h> |
| 36 | #include <sys/ipc.h> |
| 37 | #include <sys/msg.h> |
| 38 | #include <stdarg.h> //for rtc_log variable para |
| 39 | #include <linux/prctl.h> |
| 40 | #include <sys/prctl.h> |
| 41 | |
| 42 | #include "softap_api.h" |
| 43 | #include "message.h" |
| 44 | #include "rtc_timer.h" |
| 45 | #include <linux/netlink.h> |
| 46 | #include <sys/socket.h> |
| 47 | /******************************************************************************* |
| 48 | * Macro definitions * |
| 49 | ******************************************************************************/ |
| 50 | #define RTC_MSG_PARAM_SIZE 16 |
| 51 | #define RTC_MSG_PARAM_MAC 16 //13 for align |
| 52 | #define RTC_ALARM_DATA "/etc_rw/rtc_alarm.dat" |
| 53 | #define DATA_S 0xA5A5 |
| 54 | #define DATA_E 0x5A5A |
| 55 | /* |
| 56 | sleep process |
| 57 | 1. rtc no elapsed |
| 58 | 2. sta linked in |
| 59 | 3. no timer |
| 60 | |
| 61 | wps process |
| 62 | 1. no timer can be used |
| 63 | |
| 64 | xx xx xx xx |
| 65 | |
| 66 | */ |
| 67 | #ifdef __ZTE_UCLINUX__ |
| 68 | #define ROOT_DIR "/mnt/jffs2" |
| 69 | #else |
| 70 | #define ROOT_DIR "" |
| 71 | #endif |
| 72 | |
| 73 | |
| 74 | #define MAX_ALARM_NUM 256 |
| 75 | |
| 76 | #define RTC_DEV_NAME "/dev/rtc0" |
| 77 | #define NV_STRING_LEN_20 20 |
| 78 | |
| 79 | #define WLAN_RTC_LOG1_FILE_PATH ROOT_DIR"/wifi/rtclog1" |
| 80 | #define WLAN_RTC_LOG2_FILE_PATH ROOT_DIR"/wifi/rtclog2" |
| 81 | |
| 82 | #define WLAN_RTC_MAX_LOG_LENGTH 262144 |
| 83 | |
| 84 | #define _RTC_SERVICE_DEBUG 1 |
| 85 | #define RTC_MSG_BUFFER_SIZE 2048 |
| 86 | /******************************************************************************* |
| 87 | * Type definitions * |
| 88 | ******************************************************************************/ |
| 89 | typedef enum { |
| 90 | WF_SLEEP_SET_TIMER = 0x01,// rtc-service add alarm ok |
| 91 | WF_SLEEP_RTC_HW_SEND_ELAPSED = 0x02, |
| 92 | WF_SLEEP_RTC_HANDLE_ELAPSED = 0x04, |
| 93 | WF_SLEEP_RECEIVE_ELAPSED_MSG = 0x08, |
| 94 | WF_SLEEP_HANDLE_SLEEP_MSG = 0x10, |
| 95 | |
| 96 | WF_WPS_SET_TIMER = 0x0100,// rtc-service add alarm ok |
| 97 | WF_WPS_RTC_HW_ELAPSED = 0x0200, |
| 98 | WF_WPS_RTC_HANDLE_ELAPSED = 0x0400, |
| 99 | WF_WPS_RECEIVE_ELAPSED_MSG = 0x0800, |
| 100 | WF_WPS_HANDLE_SLEEP_MSG = 0x1000, |
| 101 | |
| 102 | WF_RTC_HW_SET_TIMER_OK = 0x00010000, // rtc ioctl set timer ok |
| 103 | WF_RTC_HW_SET_TIMER_FAILED = 0x00020000, // rtc ioctl set timer failed |
| 104 | WF_RTC_HW_HAVE_ELAPSED = 0x00040000, // rtc hw elapsed normal |
| 105 | WF_RTC_SERVICE_NO_FREE_TIMER = 0x00080000, // no enough free timer |
| 106 | WF_HAVE_STA_LINKED_IN = 0x00100000, // sta linked in |
| 107 | |
| 108 | |
| 109 | } wf_rtc_debug; |
| 110 | |
| 111 | enum RTC_TYPE { |
| 112 | RTC_TYPE_NONE = 0, |
| 113 | RTC_TYPE_TIME, // RTC_RD_TIME¡¢ RTC_SET_TIME |
| 114 | RTC_TYPE_ALM, // RTC_ALM_READ¡¢ RTC_ALM_SET |
| 115 | RTC_TYPE_WKALM, // RTC_WKALM_READ¡¢ RTC_WKALM_SET |
| 116 | }; |
| 117 | |
| 118 | /* count down timer */ |
| 119 | typedef enum { |
| 120 | ZX234290_SET_TIMER = ('r' << 24 | 't' << 16 | 'c' << 8 | 0), |
| 121 | ZX234290_GET_TIMER = ('r' << 24 | 't' << 16 | 'c' << 8 | 1), |
| 122 | ZX234290_TIMER_ENABLED = ('r' << 24 | 't' << 16 | 'c' << 8 | 2), |
| 123 | ZX234290_GET_TIMER_REMAIN = ('r' << 24 | 't' << 16 | 'c' << 8 | 3), |
| 124 | ZX234290_GET_TIMER_STATUS = ('r' << 24 | 't' << 16 | 'c' << 8 | 4), |
| 125 | ZX234290_FUNCTION_MAX = ('r' << 24 | 't' << 16 | 'c' << 8 | 5), |
| 126 | } zx234290_rtc_timer; |
| 127 | |
| 128 | /** |
| 129 | * @brief ¶¨Ê±Æ÷ÐÅÏ¢ |
| 130 | * @param list Á´±íÍ· |
| 131 | * @param time_val µ±Ç°Ê±¼ä£¬µ¥Î»:s |
| 132 | * @param rtc_tm µ±Ç°ÊÀ½çʱÖÓʱ¼ä |
| 133 | * @param interval ¼ä¸ôʱ¼ä£¬µ¥Î»:s |
| 134 | * @param remain_time Ê£Óàʱ¼ä£¬µ¥Î»:s |
| 135 | * @param rtc_id ¶¨Ê±Æ÷id |
| 136 | * @param module_id ´´½¨¶¨Ê±Æ÷Ä£¿éid |
| 137 | * @param wakeup ¹Ø»ú»½ÐÑ£¬1:´ò¿ª£¬0:¹Ø±Õ |
| 138 | * @param is_utc ÊÇ·ñutcʱ¼ä£¬utcʱ¼äÕý³£±È½Ï³¤£¬ÓÃWKALM¶¨Ê±Æ÷ |
| 139 | * @param cpu rtc·¢ÆðµÄcpu£¬ 0: cp, 1:ap |
| 140 | * @note |
| 141 | */ |
| 142 | /* count down timer */ |
| 143 | typedef struct tag_ALARM { |
| 144 | struct list_head list; |
| 145 | long time_val; |
| 146 | struct rtc_time rtc_tm; |
| 147 | long interval; |
| 148 | long remain_time; |
| 149 | int rtc_id; |
| 150 | int module_id; |
| 151 | int wakeup; |
| 152 | int is_utc; |
| 153 | int cpu; |
| 154 | } ALARM_T; |
| 155 | |
| 156 | typedef enum _TIME_CONVERT_TYPE { |
| 157 | CONVERT_TYPE_NONE = 0, //³õʼֵ£¬²»×öʱ¼äÀàÐÍת»¯ |
| 158 | CONVERT_TYPE_RTC, //ת»¯Îªutc0ʱ¼ä |
| 159 | CONVERT_TYPE_OS //ת»¯ÎªËùÔÚÊ±ÇøÊ±¼ä |
| 160 | } TIME_CONVERT_TYPE; |
| 161 | #endif |