/*
 * main implementation: use this sample to create your own application
 *
 */
#include "support_common.h" /* include peripheral declarations and more */
#if (CONSOLE_IO_SUPPORT || ENABLE_UART_SUPPORT) 
/* Standard IO is only possible if Console or UART support is enabled. */
#include <stdio.h>
#endif


#define MCF_INTC_IMRH_ALL  (0x00000000)
#define MCF_INTC_IMRL_ALL  (0x00000001)
#define TBIT_TT0     (55 - 32)
#define TBIT_TT1     (56 - 32)

#define RXLED_TOGGLE     MCF_GPIO_PORTLD = (unsigned char)(MCF_GPIO_PORTLD ^ MCF_GPIO_PORTLD_PORTLD5);
#define TXLED_TOGGLE     MCF_GPIO_PORTLD = (unsigned char)(MCF_GPIO_PORTLD ^ MCF_GPIO_PORTLD_PORTLD6);
#define ACTLED_TOGGLE    MCF_GPIO_PORTLD = (unsigned char)(MCF_GPIO_PORTLD ^ MCF_GPIO_PORTLD_PORTLD0);

int timer_counter = 0;

int main(void)
{
	int counter = 0;
 	MCF_GPIO_PLDPAR = ( MCF_GPIO_PORTLD_PORTLD1 // LNKLED
						| MCF_GPIO_PORTLD_PORTLD2 // SPDLED
						| MCF_GPIO_PORTLD_PORTLD3 // DUPLED
						| MCF_GPIO_PORTLD_PORTLD4 // COLLED
                                   );
		MCF_GPIO_DDRLD =  MCF_GPIO_DDRLD_DDRLD0 // ACTLED
						| MCF_GPIO_DDRLD_DDRLD5 // RXLED
						| MCF_GPIO_DDRLD_DDRLD6 // TXLED
						;
    MCF_GPIO_PORTLD = 0x00;
#if 0
#if (CONSOLE_IO_SUPPORT || ENABLE_UART_SUPPORT) 
	printf("Hello World in C from MCF52233 derivative on MCF52233 board\n\r");
	fflush(stdout);
#endif
#endif
  /*
   *  タイマ割込みの割込みレベルを設定し，要求をクリアした後，
   *  マスクを解除する．
   */
  MCF_INTC_ICR55(0) =  (((5) << 3) | (5));
  MCF_INTC_IMRL(0) = 0xFFFFFFFE;
  MCF_INTC_IMRH(0) &= ~(1 << (TBIT_TT0));
  MCF_PIT0_PCSR = (unsigned short)(MCF_PIT_PCSR_OVW | MCF_PIT_PCSR_PIF | MCF_PIT_PCSR_RLD);
  MCF_PIT0_PMR  = (unsigned short)0xFFFF;
  MCF_PIT0_PCNTR = 0x0000;
  MCF_PIT0_PCSR |= MCF_PIT_PCSR_PIE;	//割り込み許可
  MCF_PIT0_PCSR |= MCF_PIT_PCSR_EN;

	for(;;) {	   
	    if ((timer_counter == 0x100)) {
    	  MCF_GPIO_PORTLD = MCF_GPIO_PORTLD_PORTLD0;
    	}
    	if ((timer_counter > 0x200)) {
      	timer_counter=0;
      	MCF_GPIO_PORTLD = 0;
    	}
	   	counter++;
	}
}
