
//MEGA单片机组件
unit MEGA
{
	public const uint16 ID = 0;
	
	#.COM_MCU = RES;
	public RES =
	#include <system/cpu/avr/register_$chip$.txt>
	
	//---------------------------------------------------
	//[i] var_uint8 OS_time;
	public uint8 OS_time;
	
	//[i] var_uint8 OS_EventFlag;
	uint8 OS_EventFlag;
	//[i] event StartEvent;
	//[i] event IdleEvent;
	
	uint8 WatchDogTick;
	
	//---------------------------------------------------
	//[i] function_void OS_init;
	public void OS_init()
	{
		WatchDogTick = 0;
		OS_time = 50;
		OS_EventFlag = 0;
		OS_EventFlag.0(bit) = 1;
		
		//开机用于等待外设准备好(带有阻容复位的外设)
		loop( 10 ) {
			delay();
		}
	}
	//---------------------------------------------------
	//[i] function_void OS_thread;
	public void OS_thread()
	{
		OS_EventFlag.1(bit) = 1;
	}
	//---------------------------------------------------
	//[i] function_void OS_run;
	public void OS_run()
	{
		//判断系统事件调度是否卡住, 其中低四位表示时间累加, 高四位用来报警闪烁计时
		if( WatchDogTick >= 15 ) {
			WatchDogTick + 16;
			//LED_PORT = WatchDogTick.7(bit);
			return;
		}
		WatchDogTick + 1;
	}
	//---------------------------------------------------
	//[i] function_void OS_ClearWatchDog;
	public void OS_ClearWatchDog()
	{
		WatchDogTick = 0;
	}
	//---------------------------------------------------
	void delay()
	{
		loop( 250 ) loop( 250 ) {}
	}
}

#include "mio_$run$.txt"









