/***********************************************************************/
/*                                                                     */
/*  FILE        :test3.c                                               */
/*  DATE        :Wed, Jun 25, 2014                                     */
/*  DESCRIPTION :Main Program                                          */
/*  CPU TYPE    :RX62N                                                 */
/*                                                                     */
/*  This file is generated by Renesas Project Generator (Ver.4.53).    */
/*  NOTE:THIS IS A TYPICAL EXAMPLE.                                    */
/*                                                                     */
/***********************************************************************/
#include <kernel.h>
#include "ssp/kernel_cfg.h"

#include <machine.h>					// Include machine.h
#include "iodefine.h"					// Include iodefine.h
                  
                  
#include<stdio.h>

//#include "typedefine.h"
#ifdef __cplusplus
//#include <ios>                        // Remove the comment when you use ios
//_SINT ios_base::Init::init_cnt;       // Remove the comment when you use ios
#endif

void main(void);
#ifdef __cplusplus
extern "C" {
void abort(void);
}
#endif

//void main(void)
//{
//	printf("hello\n");
//}

int flag;

void main(intptr_t arg)
{

	printf("hello");

	flag = 0;

	PORT1.DDR.BIT.B5 = 1;				// P15 is Output
	MSTP( CMT0 ) = 0;					// Wakeup CMT0,CMT1
	CMT0.CMCOR = 48000000/512/2 - 1;	// CMCOR is 500ms Count 
	CMT0.CMCR.WORD = 0x0043;			// CMIE is Enable,CKS is PCLK/512
	IEN( CMT0, CMI0 ) = 1;				// CMI0 Enable
	IPR( CMT0, CMI0 ) = 1;				// CMI0 Interrupt Level is 1
//	set_psw( 0x00010000 );				// Set I=1, IPL=0 of PSW
	CMT.CMSTR0.BIT.STR0 = 1;			// Start CMT0
	for(;;)
	{
		if (flag)
		{
			printf("task1---flag here-------------------------------------------\n");
			go_tsk(TASK2_ID);
			
		}
	}
}
void task2(intptr_t arg)
{
	printf("task2\n");
	flag = 1;
	printf("task2 flag =1\n");
	printf("task2 wait\n");
	wai_tsk();
	printf("task2 wakeup\n");
	flag = 0;
	printf("task2 flag =0\n");
	printf("task2 end\n");
}


void CMI0(void)							// Interrupt Function
{										// Multiple Interrupt Enable
	PORT1.DR.BIT.B5 ^= 1;				// Reverse P15(LED)
//		CMT.CMSTR0.BIT.STR0 = 0;			// Start CMT0
	iact_tsk(TASK2_ID);
}


#ifdef __cplusplus
void abort(void)
{

}
#endif
