lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | #include "ext_regist.h"
|
| 2 |
|
| 3 | #include "NvParam_drv.h"
|
| 4 | #include "libcpnv.h"
|
| 5 | #define ZOSS_ERROR 0xffffffff
|
| 6 | #define ZOSS_SUCCESS 0x0
|
| 7 |
|
| 8 | /*wdt nv flag*/
|
| 9 | #define WDT_OFF (0x57445446) //ascii:WDTF
|
| 10 | #define WDT_ON (0x5744544F) //ascii:WDTO
|
| 11 |
|
| 12 | #define ZX_WDT_IOC_MAGIC 'W'
|
| 13 |
|
| 14 | /*ioctl cmd usd by device*/
|
| 15 | #define ZX_WDT_SET_INTERNAL _IOW(ZX_WDT_IOC_MAGIC, 1, char *)
|
| 16 | #define ZX_WDT_SET_WAKEUP _IOW(ZX_WDT_IOC_MAGIC, 2, char *)
|
| 17 | #define ZX_WDT_FEED_DOG _IOW(ZX_WDT_IOC_MAGIC, 3, char *)
|
| 18 | #define ZX_WDT_GET_HANDLE_TIMEOUT _IOWR(ZX_WDT_IOC_MAGIC, 4, char *)
|
| 19 | #define ZX_WDT_GET_GLOBAL_CNT _IOWR(ZX_WDT_IOC_MAGIC, 5, char *)
|
| 20 | #define ZX_WDT_GET_AP_TIMEOUT _IOWR(ZX_WDT_IOC_MAGIC, 6, char *)
|
| 21 | #define ZX_WDT_SET_AP_SWITCH _IOWR(ZX_WDT_IOC_MAGIC, 7, char *)
|
| 22 | #define ZX_WDT_SET_NV _IOWR(ZX_WDT_IOC_MAGIC, 8, char *)
|
| 23 | #define ZX_WDT_GET_NV _IOWR(ZX_WDT_IOC_MAGIC, 9, char *)
|
| 24 | #define ZX_WDT_SET_CHECK _IOWR(ZX_WDT_IOC_MAGIC, 10, char *)
|
| 25 |
|
| 26 | #define ZX_SOFT_WDT_DEV "/dev/zx_soft_wdt"
|
| 27 |
|
| 28 |
|
| 29 | extern int zx_wdt_set_nv(BOOL nv_flag);
|
| 30 | extern BOOL zx_wdt_get_wdtnv_for_ctrm(void);
|
| 31 | //static long int wdt_fd;
|
| 32 |
|
| 33 | int wdt_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 34 | {
|
| 35 | char *at_str = NULL;
|
| 36 | unsigned long retCode = ZOSS_ERROR;
|
| 37 | int nv_value = 0;
|
| 38 | unsigned int wdt_nvdata = 0;
|
| 39 |
|
| 40 | assert(at_paras!=NULL);
|
| 41 | at_str = at_paras;
|
| 42 |
|
| 43 | get_at_cmd_param_int(at_str, &nv_value, &at_str);
|
| 44 | at_print(AT_DEBUG,"wdt_act_func:nv_value == %d\n", nv_value);
|
| 45 |
|
| 46 | if(0 == nv_value )
|
| 47 | {
|
| 48 |
|
| 49 | //ioctl(wdt_fd, ZX_WDT_SET_NV, FALSE);
|
| 50 | wdt_nvdata=WDT_OFF;
|
| 51 | retCode = cpnv_NvItemWrite(DRV_SYS_NV_ITEM_ADDR(wdtSwitch), (unsigned char *)(&wdt_nvdata), DRV_SYS_NV_ITEM_SIZE(wdtSwitch));
|
| 52 | if(ZOSS_SUCCESS == retCode ){
|
| 53 | retCode= cpnv_NvramFlush();
|
| 54 | }
|
| 55 |
|
| 56 | }
|
| 57 | else if(1 == nv_value )
|
| 58 | {
|
| 59 | //ioctl(wdt_fd, ZX_WDT_SET_NV, TRUE);
|
| 60 | wdt_nvdata=WDT_ON;
|
| 61 | retCode = cpnv_NvItemWrite(DRV_SYS_NV_ITEM_ADDR(wdtSwitch), (unsigned char *)(&wdt_nvdata), DRV_SYS_NV_ITEM_SIZE(wdtSwitch));
|
| 62 | if(ZOSS_SUCCESS == retCode ){
|
| 63 | retCode= cpnv_NvramFlush();
|
| 64 | }
|
| 65 | }
|
| 66 | else
|
| 67 | {
|
| 68 | *res_msg = at_err_build(ATERR_PARAM_INVALID);
|
| 69 | *res_msglen = strlen(*res_msg);
|
| 70 | return AT_END;
|
| 71 | }
|
| 72 |
|
| 73 | if (retCode == ZOSS_SUCCESS)
|
| 74 | {
|
| 75 | *res_msg = at_query_result_build("WDT=",at_str);
|
| 76 | }
|
| 77 | else
|
| 78 | {
|
| 79 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 80 | }
|
| 81 |
|
| 82 | *res_msglen = strlen(*res_msg);
|
| 83 | return AT_END;
|
| 84 | }
|
| 85 |
|
| 86 | int wdt_get_nv_state(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 87 | {
|
| 88 |
|
| 89 | unsigned int wdt_nvdata = 0;
|
| 90 | long retCode = CPNV_ERROR;
|
| 91 |
|
| 92 | //ioctl(wdt_fd, ZX_WDT_GET_NV, &retCode);
|
| 93 |
|
| 94 | retCode =cpnv_NvItemRead(DRV_SYS_NV_ITEM_ADDR(wdtSwitch), (unsigned char *)(&wdt_nvdata), DRV_SYS_NV_ITEM_SIZE(wdtSwitch));
|
| 95 | if(CPNV_ERROR == retCode) softap_assert("");
|
| 96 | if (WDT_OFF == wdt_nvdata )
|
| 97 | {
|
| 98 | *res_msg = at_query_result_build("WDT","WDT OFF");
|
| 99 |
|
| 100 | } else if(WDT_ON== wdt_nvdata )
|
| 101 | {
|
| 102 | *res_msg = at_query_result_build("WDT","WDT ON");
|
| 103 | }
|
| 104 | else
|
| 105 | {
|
| 106 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 107 | }
|
| 108 |
|
| 109 | *res_msglen = strlen(*res_msg);
|
| 110 | return AT_END;
|
| 111 | }
|
| 112 |
|
| 113 | int wdt_set_nv_priority(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 114 | {
|
| 115 | char *at_str = NULL;
|
| 116 | unsigned long retCode = ZOSS_ERROR;
|
| 117 | int nv_value = 0;
|
| 118 | char strCmd[AT_CMD_MAX] = {0};
|
| 119 |
|
| 120 | assert(at_paras!=NULL);
|
| 121 | at_str = at_paras;
|
| 122 |
|
| 123 | get_at_cmd_param_int(at_str, &nv_value, &at_str);
|
| 124 | at_print(AT_DEBUG,"wdt_set_nv_priority:nv_value == %d\n", nv_value);
|
| 125 |
|
| 126 | if((nv_value > 0)&&(nv_value <= 99))//priority
|
| 127 | {
|
| 128 | retCode = cpnv_NvItemWrite(DRV_SYS_NV_ITEM_ADDR(wdtPriority), (unsigned char *)(&nv_value), DRV_SYS_NV_ITEM_SIZE(wdtPriority));
|
| 129 | if(ZOSS_SUCCESS == retCode ){
|
| 130 | retCode= cpnv_NvramFlush();
|
| 131 | }
|
| 132 | }
|
| 133 | else
|
| 134 | {
|
| 135 | *res_msg = at_err_build(ATERR_PARAM_INVALID);
|
| 136 | *res_msglen = strlen(*res_msg);
|
| 137 | return AT_END;
|
| 138 | }
|
| 139 |
|
| 140 | if (retCode == ZOSS_SUCCESS)
|
| 141 | {
|
| 142 | sprintf(strCmd,"%d", nv_value);
|
| 143 | *res_msg = at_query_result_build("WDTP=",strCmd);
|
| 144 | }
|
| 145 | else
|
| 146 | {
|
| 147 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 148 | }
|
| 149 |
|
| 150 | *res_msglen = strlen(*res_msg);
|
| 151 | return AT_END;
|
| 152 | }
|
| 153 |
|
| 154 | int wdt_get_nv_priority(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 155 | {
|
| 156 | unsigned int wdt_nvdata = 0;
|
| 157 | long retCode = CPNV_ERROR;
|
| 158 | char strCmd[AT_CMD_MAX] = {0};
|
| 159 |
|
| 160 | retCode =cpnv_NvItemRead(DRV_SYS_NV_ITEM_ADDR(wdtPriority), (unsigned char *)(&wdt_nvdata), DRV_SYS_NV_ITEM_SIZE(wdtPriority));
|
| 161 | if(CPNV_ERROR == retCode) softap_assert("");
|
| 162 |
|
| 163 | sprintf(strCmd,"%d", wdt_nvdata);
|
| 164 |
|
| 165 | *res_msg = at_query_result_build("WDTP",strCmd);
|
| 166 | *res_msglen = strlen(*res_msg);
|
| 167 | return AT_END;
|
| 168 | }
|
| 169 |
|
| 170 | void ext_wdt_regist_init(void)
|
| 171 | {
|
| 172 | //wdt_fd = open(ZX_SOFT_WDT_DEV, O_RDWR);
|
| 173 | //ioctl(wdt_fd, ZX_WDT_SET_CHECK, FALSE);
|
| 174 |
|
| 175 | register_serv_func2("WDT=", 0, 0, 0, wdt_act_func, NULL);
|
| 176 | register_serv_func2("WDT?", 0, 0, 0,wdt_get_nv_state,NULL);
|
| 177 | register_serv_func2("WDTP=", 0, 0, 0, wdt_set_nv_priority, NULL);
|
| 178 | register_serv_func2("WDTP?", 0, 0, 0,wdt_get_nv_priority,NULL);
|
| 179 | }
|
| 180 |
|