/* Watchdog time test.

   Author: Moki Matsushima

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software Foundation,
   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

/* File level history (record changes for this file here.)

   v 0.0.0  27 Mar 2018 by Winson
     create, blah blah... 
     This demo support LX-serice PAC.
     Support CPU watchdog.
*/

#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)
{
	unsigned int msecond = 1000;
	int tmp;
	tmp = EnableSysWDT(msecond);	/* Enable watchdog timer, set time out 10s */

	if(tmp)
	{
		switch(tmp)
		{
			case ComPortNotOpen:
				printf("Open Com port fail!\n");
				break;
			case ExceedInputRange:
				printf("If your PAC is LX-8x31, LX-9x31 time out range is 1~510 seconds\n");
				printf("               LX-8x71, LX-9x71, LX-9x81 time out range is 7~1026 seconds\n");
				printf("               ALX-9000 time out range is 1~255 seconds\n");
				break;
			default:
				printf("Driver module does not loaded\n");
				break;
		}

		return FAILURE;
	}

	sync();
	printf("Set time out %d seconds\n",msecond / 1000);
	printf("Press Enter to kick watchdog (ESC to Disable)\n");

	while (getchar()==10){
		printf("Kick watchdog.\n");
		ReloadSysWDT();      	/* refresh watchdog timer */
		sync();
	}
	
	printf("Disable watchdog timer\n");
	DisableSysWDT();
	return SUCCESS;
}
