/*
 *  wdt.c
 *
 *  v 0.0 2021.8.10
 *    Hardware  WDT test for LP-2841/9x81.
 */


#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include "msw.h"
#define iTalkVersion	15

int main(int argc, char **argv)
{
	int result = 0, pac_id = 0;
        
	result = linpac_read_pacid(&pac_id);

        if(result)
        {
                printf("pacid(%d) : LinPAC ID read error!\n",result);
                return FAILURE;
        }
	else
	{
		if(pac_id == LP2841 || pac_id == LP2841_4G )
                {
			printf("To enable LP-2841's WDT and time out is 8 secs.\n");
			EnableWDT(2);	//each unit is about 4s, unit '2' is about 8s
			//lp2841_enable_wdt(2);	//each unit is about 4s, unit '2' is about 8s

			printf("Press Enter to refresh hardware watch dog (ESC to Disable)\n");
			while (getchar()==10){
				printf("Refresh watchdog timer\n");
				RefreshWDT();      	/* refresh watchdog */
				//lp2841_refresh_wdt();      	/* refresh watchdog */
				sync();
			}
				
			DisableWDT();      	/* disable watchdog */
			//lp2841_disable_wdt();      	/* disable watchdog */
		}
                else
                {
                        printf("Unknown Device!\n");
			return -1;
                }
        }

	return 0;
}

