#include <stdio.h>
#include <gl_task.h>
#include "types.h"
#include "watchdog_ioctl.h"
#include "umf_debug.h"
#include <umf_ir.h>

#define THREAD_PRIORITY_BASE    20

void wdog_Receive(void *p)
{
	int counter = 0;
	
	while(1)
	{
		if(counter == 10)
		{
			Cmd_WatchdogKeepAlive();
			counter = 0;
		}
		else
		{
			counter++;
			umfsleep(0, 100000000);
		}
	}
}

void wdog_init(void)
{
	GL_Task_t taskId = NULL;
	if(Cmd_WatchdogCreate(8000) == -1)
	{
		UMFDBG(0,"wdog_init create fail \n");
		
	}
	else
	{
		if(GL_SUCCESS != GL_TaskCreate((char*)"WDOG", wdog_Receive, NULL, 3, 4096, TRUE, &taskId))
		{
			UMFDBG(0,"wdog pthread_create fail \n");
		}
	}
}

void wdog_remove(void)
{
	Cmd_WatchdogRemove();
}

void wdog_add(void)
{
	Cmd_WatchdogAdd(8000);
}


