wdt_fd = /dev/watchdog0
=========this function is for stoppong the wdt============
int stop_wdt_ping_cmd(U32 argc, char **argv, contextInfo_t *c)
{
int ret;
printf("..........stop_wdt_ping_cmd..........\n");
if(wdt_fd <= 0) {
printf("WDT device is not opened\n");
return FAILURE;
}
wdt_thread_running =1;
if(wdt_thread_running){
ret = pthread_cancel(wdt_thread);
if(ret == 0) {
wdt_thread_running = 0;
printf("WDT ping thread has been terminated\n");
} else {
printf("Failed to cancel the WDT ping thread\n");
}
} else {
printf("Thread not running:::::WDT ping thread has been already terminated\n");
}
wdt_close(&wdt_fd);
SET_TIME_OUT_CALL = 0;
return 0;
}
int wdt_ping_cmd (U32 argc, char **argv, contextInfo_t *c)
{
int ret=0;
char cmd[8] = “WDT PING”;
if(wdt_fd > 0) {
printf("WDT Device is already opened\n");
}
else {
ret =wdt_open(&wdt_fd);
if(ret < 0)
return FAILURE;
}
if(SET_TIME_OUT_CALL == 1) {
if((strcmp(argv[2],"1") ==0)) {
if(wdt_thread_running == 1) {
printf(" WDT is already getting ping\n");
return SUCCESS;
}
ret = pthread_create(&wdt_thread, NULL, wdt_func, (void*) cmd);
if(ret) {
fprintf(stderr,": WDT_ERR in pthread create with %d\n",ret);
return FAILURE;
}
printf(" WDT Ping Started\n");
}else{
if((strcmp(argv[2],"0") ==0)) {
ret =wdt_keepalive(&wdt_fd);
if(ret < 0 )
return FAILURE;
}
}
}else {
printf("Time out not SET from APP--> pinging for default time \n");
if(wdt_thread_running == 0) {
if((strcmp(argv[2],"1") ==0)) {
ret = pthread_create(&wdt_thread, NULL, wdt_func, (void*) cmd);
if(ret) {
fprintf(stderr,"Error - pthread_create() return code: %d\n",ret);
return FAILURE;
}
printf(" WDT Ping Started\n");
}else if((strcmp(argv[2],"0") ==0)){
ret =wdt_keepalive(&wdt_fd);
if(ret <0 )
return FAILURE;
}
}else if(wdt_thread_running == 1) {
printf(" WDT is already getting ping for default time out\n");
return SUCCESS;
}
}
return SUCCESS;
}
void *wdt_func(void *msg)
{
wdt_thread_running = 1;
while(1) {
sleep(2);
wdt_keepalive(&wdt_fd);
}
}
=============for setting wdt==============
int wdt_set_cmd (U32 argc, char **argv, contextInfo_t *c)
{
int timeout = 0,ret=0;
timeout =atoi(argv[2]); /*Time in seconds */
printf(".............wdt_set_cmd..........\n");
if(timeout < WDT_MIN_SETTIME || timeout > WDT_MAX_SETTIME){
printf("WDT:Provide the valid timeout\n Range is 20 - 65535 seconds \n");
return FAILURE;
}
if(SET_TIME_OUT_CALL == 0) {
ret = wdt_open(&wdt_fd);
if(ret < 0)
return FAILURE;
ret=set_wdt_timeout(&wdt_fd,timeout);
if(ret<0){
return FAILURE;
}else{
printf("Watchdog timeout set success \n");
SET_TIME_OUT_CALL = 1;
return SUCCESS;
}
}else{
printf("Operation SET TIME OUT not supported-->WDT Already Set\n");
return SUCCESS;
}
}
int set_wdt_timeout(int *wdt_fd,int timeout)
{
wdt_print(LOG_ERR “%s Enter…\n”, func);
if(*wdt_fd < 0) {
wdt_print(LOG_ERR “Watchdog device not opened\n”);
return WDT_FAILURE;
}
if(timeout >= WDT_MIN_SETTIME && timeout <= WDT_MAX_SETTIME){
int ret;
/* Note the value should be within [20, 1000] */
ret = ioctl(*wdt_fd, WDIOC_SETTIMEOUT, &timeout);
if(ret) {
wdt_print(LOG_ERR "Set watchdog timeout value failed!\n");
return WDT_FAILURE * errno;
}
}else{
wdt_print(LOG_ERR "Provide the valid timeout\n Range is 20 - 65535 seconds \n");
return WDT_FAILURE;
}
wdt_print(LOG_ERR "%s Exit...\n", __func__);
return WDT_SUCCESS;
}
int wdt_keepalive(int *wdt_fd)
{
int ret=0;
wdt_print(LOG_ERR "%s Enter...\n", __func__);
if(*wdt_fd < 0) {
wdt_print(LOG_ERR "Watchdog device not opened\n");
return WDT_FAILURE;
}
ret = ioctl(*wdt_fd, WDIOC_KEEPALIVE, NULL);
if(ret) {
wdt_print(LOG_ERR "Kick watchdog failed!\n");
return WDT_FAILURE;
}
wdt_print(LOG_ERR "%s Exit...\n", __func__);
return WDT_SUCCESS;
}
can you check this