blob: e289b5f99401fe2d723ec243fe8db3ecbf479fad [file] [log] [blame]
#include "ext_regist.h"
#include "NvParam_drv.h"
#include "libcpnv.h"
#define ZOSS_ERROR 0xffffffff
#define ZOSS_SUCCESS 0x0
/*wdt nv flag*/
#define WDT_OFF (0x57445446) //ascii:WDTF
#define WDT_ON (0x5744544F) //ascii:WDTO
#define ZX_WDT_IOC_MAGIC 'W'
/*ioctl cmd usd by device*/
#define ZX_WDT_SET_INTERNAL _IOW(ZX_WDT_IOC_MAGIC, 1, char *)
#define ZX_WDT_SET_WAKEUP _IOW(ZX_WDT_IOC_MAGIC, 2, char *)
#define ZX_WDT_FEED_DOG _IOW(ZX_WDT_IOC_MAGIC, 3, char *)
#define ZX_WDT_GET_HANDLE_TIMEOUT _IOWR(ZX_WDT_IOC_MAGIC, 4, char *)
#define ZX_WDT_GET_GLOBAL_CNT _IOWR(ZX_WDT_IOC_MAGIC, 5, char *)
#define ZX_WDT_GET_AP_TIMEOUT _IOWR(ZX_WDT_IOC_MAGIC, 6, char *)
#define ZX_WDT_SET_AP_SWITCH _IOWR(ZX_WDT_IOC_MAGIC, 7, char *)
#define ZX_WDT_SET_NV _IOWR(ZX_WDT_IOC_MAGIC, 8, char *)
#define ZX_WDT_GET_NV _IOWR(ZX_WDT_IOC_MAGIC, 9, char *)
#define ZX_WDT_SET_CHECK _IOWR(ZX_WDT_IOC_MAGIC, 10, char *)
#define ZX_SOFT_WDT_DEV "/dev/zx_soft_wdt"
extern int zx_wdt_set_nv(BOOL nv_flag);
extern BOOL zx_wdt_get_wdtnv_for_ctrm(void);
//static long int wdt_fd;
int wdt_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
{
char *at_str = NULL;
unsigned long retCode = ZOSS_ERROR;
int nv_value = 0;
unsigned int wdt_nvdata = 0;
assert(at_paras!=NULL);
at_str = at_paras;
get_at_cmd_param_int(at_str, &nv_value, &at_str);
at_print(AT_DEBUG,"wdt_act_func:nv_value == %d\n", nv_value);
if(0 == nv_value )
{
//ioctl(wdt_fd, ZX_WDT_SET_NV, FALSE);
wdt_nvdata=WDT_OFF;
retCode = cpnv_NvItemWrite(DRV_SYS_NV_ITEM_ADDR(wdtSwitch), (unsigned char *)(&wdt_nvdata), DRV_SYS_NV_ITEM_SIZE(wdtSwitch));
if(ZOSS_SUCCESS == retCode ){
retCode= cpnv_NvramFlush();
}
}
else if(1 == nv_value )
{
//ioctl(wdt_fd, ZX_WDT_SET_NV, TRUE);
wdt_nvdata=WDT_ON;
retCode = cpnv_NvItemWrite(DRV_SYS_NV_ITEM_ADDR(wdtSwitch), (unsigned char *)(&wdt_nvdata), DRV_SYS_NV_ITEM_SIZE(wdtSwitch));
if(ZOSS_SUCCESS == retCode ){
retCode= cpnv_NvramFlush();
}
}
else
{
*res_msg = at_err_build(ATERR_PARAM_INVALID);
*res_msglen = strlen(*res_msg);
return AT_END;
}
if (retCode == ZOSS_SUCCESS)
{
*res_msg = at_query_result_build("WDT=",at_str);
}
else
{
*res_msg = at_err_build(ATERR_PROC_FAILED);
}
*res_msglen = strlen(*res_msg);
return AT_END;
}
int wdt_get_nv_state(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
{
unsigned int wdt_nvdata = 0;
long retCode = CPNV_ERROR;
//ioctl(wdt_fd, ZX_WDT_GET_NV, &retCode);
retCode =cpnv_NvItemRead(DRV_SYS_NV_ITEM_ADDR(wdtSwitch), (unsigned char *)(&wdt_nvdata), DRV_SYS_NV_ITEM_SIZE(wdtSwitch));
if(CPNV_ERROR == retCode) softap_assert("");
if (WDT_OFF == wdt_nvdata )
{
*res_msg = at_query_result_build("WDT","WDT OFF");
} else if(WDT_ON== wdt_nvdata )
{
*res_msg = at_query_result_build("WDT","WDT ON");
}
else
{
*res_msg = at_err_build(ATERR_PROC_FAILED);
}
*res_msglen = strlen(*res_msg);
return AT_END;
}
int wdt_set_nv_priority(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
{
char *at_str = NULL;
unsigned long retCode = ZOSS_ERROR;
int nv_value = 0;
char strCmd[AT_CMD_MAX] = {0};
assert(at_paras!=NULL);
at_str = at_paras;
get_at_cmd_param_int(at_str, &nv_value, &at_str);
at_print(AT_DEBUG,"wdt_set_nv_priority:nv_value == %d\n", nv_value);
if((nv_value > 0)&&(nv_value <= 99))//priority
{
retCode = cpnv_NvItemWrite(DRV_SYS_NV_ITEM_ADDR(wdtPriority), (unsigned char *)(&nv_value), DRV_SYS_NV_ITEM_SIZE(wdtPriority));
if(ZOSS_SUCCESS == retCode ){
retCode= cpnv_NvramFlush();
}
}
else
{
*res_msg = at_err_build(ATERR_PARAM_INVALID);
*res_msglen = strlen(*res_msg);
return AT_END;
}
if (retCode == ZOSS_SUCCESS)
{
sprintf(strCmd,"%d", nv_value);
*res_msg = at_query_result_build("WDTP=",strCmd);
}
else
{
*res_msg = at_err_build(ATERR_PROC_FAILED);
}
*res_msglen = strlen(*res_msg);
return AT_END;
}
int wdt_get_nv_priority(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
{
unsigned int wdt_nvdata = 0;
long retCode = CPNV_ERROR;
char strCmd[AT_CMD_MAX] = {0};
retCode =cpnv_NvItemRead(DRV_SYS_NV_ITEM_ADDR(wdtPriority), (unsigned char *)(&wdt_nvdata), DRV_SYS_NV_ITEM_SIZE(wdtPriority));
if(CPNV_ERROR == retCode) softap_assert("");
sprintf(strCmd,"%d", wdt_nvdata);
*res_msg = at_query_result_build("WDTP",strCmd);
*res_msglen = strlen(*res_msg);
return AT_END;
}
void ext_wdt_regist_init(void)
{
//wdt_fd = open(ZX_SOFT_WDT_DEV, O_RDWR);
//ioctl(wdt_fd, ZX_WDT_SET_CHECK, FALSE);
register_serv_func2("WDT=", 0, 0, 0, wdt_act_func, NULL);
register_serv_func2("WDT?", 0, 0, 0,wdt_get_nv_state,NULL);
register_serv_func2("WDTP=", 0, 0, 0, wdt_set_nv_priority, NULL);
register_serv_func2("WDTP?", 0, 0, 0,wdt_get_nv_priority,NULL);
}