/*****************************************************************************
 *   uarttest.c:  main C entry file for Philips LPC214x Family Microprocessors
 *
 *   Copyright(C) 2006, Philips Semiconductor
 *   All rights reserved.
 *
 *   History
 *   2005.10.01  ver 1.00    Prelimnary version, first Release
 *
******************************************************************************/

// arm-elf-gcc/WinARM-port by Martin Thomas 
// extern->header, volatiles, startup-gimmik

#include <startup.h>
#include <LPC214X.h>
#include <armVIC.h>
#include <type.h>
#include <irq.h>
#include "uart.h"

#include <string.h>

#define BAUD_RATE	115200
#define	INT_VECT_NUM	0

static char Hello[]="\r\nHello from the WinARM-Port\r\nHave Fun,\r\nMartin Thomas\r\n";

/*****************************************************************************
**   Main Function  main()
*****************************************************************************/
int main (void)
{
	Initialize();
    UARTInit(60000000 / (16 * BAUD_RATE));	/* baud rate setting */
	VICIntSelect &= ~(1<<UART0_INT);
	VICIntEnable |= (1<<UART0_INT);

	(*(&VICVectCntl0+INT_VECT_NUM)) = 0x20 | UART0_INT; // choose highest priority ISR slot 	
	(*(&VICVectAddr0+INT_VECT_NUM)) = (int)UART0Handler;
	enableIRQ();

    U0IER = IER_RBR | IER_THRE | IER_RLS;	/* Enable UART0 interrupt */
	
	U0IER = IER_THRE | IER_RLS;			/* Disable RBR */
	UARTSend( (BYTE*)Hello, strlen(Hello) );
	UART0Count = 0;
	U0IER = IER_THRE | IER_RLS | IER_RBR;	/* Re-enable RBR */
	
    while (1) 
    {				/* Loop forever */
	if ( UART0Count != 0 )
	{
		U0IER = IER_THRE | IER_RLS;			/* Disable RBR */
	    UARTSend( UART0Buffer, UART0Count );
	    UART0Count = 0;
	    U0IER = IER_THRE | IER_RLS | IER_RBR;	/* Re-enable RBR */
	}
    }
    return 0;
}

/*****************************************************************************
**                            End Of File
*****************************************************************************/
