|
//***************************[ UART ]******************************
static int whichUart=0;
void Uart_Init(int pclk,int baud)
{
int i;
if(pclk == 0)
pclk = PCLK;
rUFCON0 = 0x0; //UART channel 0 FIFO control register, FIFO disable
rUFCON1 = 0x0; //UART channel 1 FIFO control register, FIFO disable
rUFCON2 = 0x0; //UART channel 2 FIFO control register, FIFO disable
rUMCON0 = 0x0; //UART chaneel 0 MODEM control register, AFC disable
rUMCON1 = 0x0; //UART chaneel 1 MODEM control register, AFC disable
//UART0
rULCON0 = 0x3; //Line control register : Normal,No parity,1 stop,8 bits
// [10] [9] [8] [7] [6] [5] [4] [3:2] [1:0]
// Clock Sel, Tx Int, Rx Int, Rx Time Out, Rx err, Loop-back, Send break, Transmit Mode, Receive Mode
// 0 1 0 , 0 1 0 0 , 01 01
// PCLK Level Pulse Disable Generate Normal Normal Interrupt or Polling
rUCON0 = 0x245; // Control register
rUBRDIV0=( (int)(pclk/16./baud+0.5) -1 ); //Baud rate divisior register 0
//UART1
rULCON1 = 0x3;
rUCON1 = 0x245;
rUBRDIV1=( (int)(pclk/16./baud+0.5) -1 );
//UART2
rULCON2 = 0x3;
rUCON2 = 0x245;
rUBRDIV2=( (int)(pclk/16./baud+0.5) -1 );
for(i=0;i<100;i++);
}
//===================================================================
void Uart_Select(int ch)
{
whichUart = ch;
}
int Main(int argc, char **argv)
{
int i;
U32 mpll_val=0;
U16 data;
U16 data0;
U16 data1;
U16 data2;
mpll_val = (92<<12)|(1<<4)|(1);
//init FCLK=400M, so change MPLL first
ChangeMPllValue((mpll_val>>12)&0xff, (mpll_val>>4)&0x3f, mpll_val&3);
ChangeClockDivider(key, 12);
//cal_cpu_bus_clk();
//ChangeClockDivider(1,1); // 1:2:4 FCLK:HCLK:PCLK
// rCLKDIVN=0x4; // 1:4:4
//ChangeMPllValue(82,2,1); //FCLK=135.0Mhz
//ChangeMPllValue(82,1,1); //FCLK=180.0Mhz
//ChangeMPllValue(161,3,1); //FCLK=202.8Mhz
//ChangeMPllValue(117,1,1); //FCLK=250.0Mhz
//ChangeMPllValue(122,1,1); //FCLK=260.0Mhz
//ChangeMPllValue(125,1,1); //FCLK=266.0Mhz
//ChangeMPllValue(127,1,1); //FCLK=270.0Mhz
//MMU_EnableICache();
//MMU_EnableDCache();
MMU_DisableICache();
MMU_DisableDCache();
KeyScan_Test();
rGPBCON = 0x155555;
consoleNum = 0; // Uart 1 select for debug.
Uart_Init( 0,115200 );
Uart_Select( consoleNum );
data = 0x06;
data = 0x0;
while(1)
{
//Key_Scan();
rGPBDAT = (rGPBDAT&(data1))|(data2);
switch(key)
{
case 1:
data+=20;
if(data==0x200)
data=0x0;
data0=~data;
data1=((0xffff)&(data0))|(0xfe1f);//取0位
data2=((0x0000)|(data0))&(0x1e0);//取1位
dely(50);
break;
case 2:
data*=2;
if(data>=0x200)
data=0x20;
data0=~data;
data1=((0xffff)&(data0))|(0xfe1f);//取0位
data2=((0x0000)|(data0))&(0x1e0);//取1位
dely(20);
break;
case 3:
data=0x20;
data0=~data;
data1=((0xffff)&(data0))|(0xfe1f);//取0位
data2=((0x0000)|(data0))&(0x1e0);//取1位
break;
case 4:
data=0x40;
data0=~data;
data1=((0xffff)&(data0))|(0xfe1f);//取0位
data2=((0x0000)|(data0))&(0x1e0);//取1位
break;
case 5:
data=0x80;
data0=~data;
data1=((0xffff)&(data0))|(0xfe1f);//取0位
data2=((0x0000)|(data0))&(0x1e0);//取1位
break;
case 6:
data=0x100;
data0=~data;
data1=((0xffff)&(data0))|(0xfe1f);//取0位
data2=((0x0000)|(data0))&(0x1e0);//取1位
break;
}
}
return 0;
} |
|