//u_test.c
#define USE_UARTEXP
#define USE_UART2EXP
#define USE_UART3EXP

#define RTALE 0x100
#define RTRW 0x120
/*
Board Address is defined by jumpers on J1, 1-2 and 3-4.

                    J1, 1-2         J1, 3-4         Board Address
PAL fp04901
                    conn.           conn.           0x040000  (reserved for       
                                                             DC programming)
                    n.c.            conn.           0x040008 (uart3.lib)
                    conn.           n.c.            0x040010 (uart2.lib)
                    n.c.            n.c.            0x040018 ( uart232.lib)


*/
//uart3.lib using logical address #2	(J1 1-2 )  UART3ADDR defined as 0x040008L in uart3.lib
//uart2.lib using logical address #1	(J1 3-4 )  UART2ADDR defined as 0x040010L in uart2.lib
//uart232.lib using logical address #3 (J1 no jumpers) UARTADDR  defined as 0x040018L in uart232.lib

#define array_size 4
#define uart1 1		// for uart2.lib
#define uart2 2		// for uart3.lib
#define uart3 3		// for uart232.lib

#use cplc.lib
#use plc_exp.lib
#use drivers.lib
#use uart232.lib
#use "uart2.lib"
#use "uart3.lib"

typedef char byte;
byte baud  =  19200/1200;
byte mode  = 0x04;

byte modem  = 0;
byte echo   = 0;

char tbuf[array_size][100];
char rbuf[array_size][100];

void hello_on_1()	// 0x0400010L in uart2.lib
{
	int i;
	char a[50];

	sprintf(a, "Hello on 1\n");

	for(i = 0; i < 100; i++){
		while(!Dwrite_uart2( a, strlen(a)))
			hitwd();
	}
}
void hello_on_2()	//0x040008L in uart3.lib
{
	int i;
	char a[50];

	sprintf(a, "Hello on 2\n");

	for(i = 0; i < 100; i++){
		while(!Dwrite_uart3 ( a, strlen(a)))
			hitwd();
	}
}
void hello_on_3()	//0x040018L in uart232.lib
{
	int i;
	char a[50];

	sprintf(a, "Hello on 3\n");

	for(i = 0; i < 100; i++){
		while(!Dwrite_uart( a, strlen(a)))
			hitwd();
	}
}

								

main ( )
{
     char buf[array_size][100];
	char b[20];
	int i, key;
     
	uplc_init();
	
    reset_pbus ( ) ;
    reset_pbus_wait ( ) ;
    relocate_int1 ( ) ;
    Dinit_uart ( rbuf[uart3],tbuf[uart3],100,100,mode,baud,modem,echo);
    Dinit_uart2 ( rbuf[uart1],tbuf[uart1],100,100,mode,baud,modem,echo);
    Dinit_uart3 ( rbuf[uart2],tbuf[uart2],100,100,mode,baud,modem,echo);

	while(1){

		while(( key = lc_kxget(0)) < 0)
			hitwd();

		switch(key){

			case 1:
				hello_on_1();		
				break;
			case 2:
				hello_on_2();
				break;
			case 3:
				hello_on_3();
				break;
		}
	}
}