?? tuartlow.c.svn-base
字號:
/**
* This code and information is part of Trident DPTV API (TDAPI)
*
* Copyright (C) Trident Multimedia Technologies (Shanghai) Co., Ltd.
* 2005 All rights reserved.
*
* This file contains routines for hardware related UART operations.
*
* Revision:
* 12/10/2005 Created by Lewis and Archie
*
*/
#include "tdefs.h"
#include "TUartLow.h"
#include "TUtils.h"
#include "ioctrl.h"
#include "tvdebug.h"
#ifdef _USE_STi7710_
#include "UartCommand.h"
#include "..\data\n009_k.h"
#include "TVKey.h"
#endif
#define RI0 (INTES0 & 0x08)
#define TI0 (INTES0 & 0x80)
#define RI1 (INTES1 & 0x08)
#define TI1 (INTES1 & 0x80)
#define CLRRI0 __DI();INTCLR = 0x21;__EI() //INTES1 &= (~0x08) //Clear the rIRQ bit
#define CLRTI0 __DI();INTCLR = 0x22;__EI() //INTES1 &= (~0x80) //Clear the tIRQ bit
#define CLRRI1 __DI();INTCLR = 0x23;__EI() //INTES1 &= (~0x08) //Clear the rIRQ bit
#define CLRTI1 __DI();INTCLR = 0x24;__EI() //INTES1 &= (~0x80) //Clear the tIRQ bit
static Byte ucUartPort;
#ifdef _USE_STi7710_
void OnEventReceive(void);
#endif
void Int_uart1transmit()
{
//Must rid UART1 transmit interrupt flag
/*
Byte bINTES1Temp;
bINTES1Temp = INTES1;
bINTES1Temp &= (~0x80);
INTES1 = bINTES1Temp;
*/
__DI();
INTCLR = 0x24;
__EI();
}
void Int_uart1receive()
{
#ifdef _USE_STi7710_
OnEventReceive();
#endif
}
void Int_uart0transmit()
{
//Must rid UART1 transmit interrupt flag
/*
Byte bINTES1Temp;
bINTES1Temp = INTES1;
bINTES1Temp &= (~0x80);
INTES1 = bINTES1Temp;
*/
__DI();
INTCLR = 0x24;
__EI();
}
void Int_uart0receive()
{
}
/*@param ucPort can only be 0x1.
@param ucBaud, may be UART_BAUD_1200, UART_BAUD_2400, ... etc.
@return Bool, true when sucess, or false.
*/
Bool tdUARTLowInit(Byte ucPort, Byte ucBaud)
{
Byte temp;
#ifndef USE_T_QUAD
ucUartPort = ucPort;
switch(ucPort)
{
case UART_COM0:
//UART0 MCU Registers Setting
//__DI();
#ifndef USE_T_QUAD
INTRX0 = INT_PRIORITY_OFF;
INTTX0 = INT_PRIORITY_OFF;
#endif
INTCLR = 0x21;
INTCLR = 0x22;
//__EI();
//-------------UART0 mode setting
SC0MOD0 = 0x29; //0 0 1 0 10 01
//Disable hardshake
//Enable receive
//Disable Wakeup
//8 Bits UART
//Baudrate gerenator
SC0CR = 0x00; //0x20; //0010 0000
//Odd
//disable Parity addition
//SC0BUF = 0xFF; // Writing dummy data
//------uart_1_set_baudrate(ucBaud)
if(ucBaud == UART_BAUD_9600)
{
BR0CR = 0x1B; //00011011
// Disable +(16-k)/16 division
//T2(fc/16 )
//N = 11 =0x0B
//Devider = 11(Baudrate=fc/16/16/11=9588)
// Baudrate = fc/T2/16/n
}
else if(ucBaud==UART_BAUD_19200) /// maybe something mistake ,please recheck
{
BR0CR = 0x55; //01010101
// enable +(16-k)/16 division
//T2(fc/16 )
// N = 5 = 0x05
BR0ADD = 0x08;
// K = 8
//Baudrate = fc/T2/16/(n+((16-k)/16) = 27000000/16/16/(5+(16-8)/16)= 19176
}
else if(ucBaud==UART_BAUD_38400)
{
BR0CR = 0x52; //01010010
// enable +(16-k)/16 division
//T2(fc/16 )
// N = 2 = 0x02
BR0ADD = 0x04;
// K = 4
//Baudrate = fc/T2/16/(n+((16-k)/16) = 27000000/16/16/(2+(16-4)/16)= 38352
}
else if(ucBaud==UART_BAUD_57600)
{
BR0CR = 0x47; //01000111
// enable +(16-k)/16 division
//T0(fc/4 )
// N = 7 = 0x07
BR0ADD = 0x0B;
// K = 11
//Baudrate = fc/T0/16/(n+((16-k)/16) = 27000000/4/16/(7+(16-11)/16)= 57692
}
else if(ucBaud==UART_BAUD_115200)
{
BR0CR = 0x43; //01000111
// enable +(16-k)/16 division
//T0(fc/4 )
// N = 7 = 0x07
BR0ADD = 0x05;
// K = 11
//Baudrate = fc/T0/16/(n+((16-k)/16) = 27000000/4/16/(3+(16-5)/16)= 114406.78
}
else if(ucBaud > UART_BAUD_115200)
{
ucBaud = UART_BAUD_115200;
}
temp = SC0BUF;
break;
case UART_COM1:
//UART1 MCU Registers Setting
//__DI();
#ifndef USE_T_QUAD
INTRX1 = INT_PRIORITY_OFF;
INTTX1 = INT_PRIORITY_OFF;
#endif
INTCLR = 0x23;
INTCLR = 0x24;
//__EI();
//-------------UART1 mode setting
SC1MOD0 = 0x29; //0 0 1 0 10 01
//Disable hardshake
//Enable receive
//Disable Wakeup
//8 Bits UART
//Baudrate gerenator
SC1CR = 0x00; //0x20; //0010 0000
//Odd
//disable Parity addition
//SC1BUF = 0xFF; // Writing dummy data
//------uart_1_set_baudrate(ucBaud)
if(ucBaud == UART_BAUD_9600)
{
BR1CR = 0x1B; //00011011
// Disable +(16-k)/16 division
//T2(fc/16 )
//N = 11 =0x0B
//Devider = 11(Baudrate=fc/16/16/11=9588)
// Baudrate = fc/T2/16/n
}
else if(ucBaud==UART_BAUD_19200) /// maybe something mistake ,please recheck
{
BR1CR = 0x55; //01010101
// enable +(16-k)/16 division
//T2(fc/16 )
// N = 5 = 0x05
BR1ADD = 0x08;
// K = 8
//Baudrate = fc/T2/16/(n+((16-k)/16) = 27000000/16/16/(5+(16-8)/16)= 19176
}
else if(ucBaud==UART_BAUD_38400)
{
BR1CR = 0x52; //01010010
// enable +(16-k)/16 division
//T2(fc/16 )
// N = 2 = 0x02
BR1ADD = 0x04;
// K = 4
//Baudrate = fc/T2/16/(n+((16-k)/16) = 27000000/16/16/(2+(16-4)/16)= 38352
}
else if(ucBaud==UART_BAUD_57600)
{
BR1CR = 0x47; //01000111
// enable +(16-k)/16 division
//T0(fc/4 )
// N = 7 = 0x07
BR1ADD = 0x0B;
// K = 11
//Baudrate = fc/T0/16/(n+((16-k)/16) = 27000000/4/16/(7+(16-11)/16)= 57692
}
else if(ucBaud==UART_BAUD_115200)
{
BR1CR = 0x43; //01000111
// enable +(16-k)/16 division
//T0(fc/4 )
// N = 7 = 0x07
BR1ADD = 0x05;
// K = 11
//Baudrate = fc/T0/16/(n+((16-k)/16) = 27000000/4/16/(3+(16-5)/16)= 114406.78
}
else if(ucBaud > UART_BAUD_115200)
{
ucBaud = UART_BAUD_115200;
}
temp = SC1BUF;
#ifdef _USE_STi7710_
//__DI();
//INTRX1 = INT_PRIORITY_F;//
//INTCLR = 0x23;
//__EI();
SendUartCommandinit();//YYM_06_06_19 add for[]
#endif
break;
default:
return _FALSE_;
}
#endif
return _TRUE_;
//#else
// return _FALSE_;
//#endif
}
/*@return byUartGet is a data saving the data received by UART.
*/
Byte getChar(void)
{
Byte byUartGet;
if(ucUartPort == UART_COM0)
{
while (!RI0);
byUartGet = SC0BUF;
CLRRI0;
}
else //UART_COM1
{
while (!RI1);
byUartGet = SC1BUF;
CLRRI1;
}
return(byUartGet);
}
/*@param byUartPut is a data shall be sent by UART.
*/
void putchar(Byte byUartPut)
{
switch(ucUartPort)
{
case UART_COM0:
if(byUartPut == '\n')
{
SC0BUF = '\r';//0x0D;
while (!TI0);
CLRTI0;
}
SC0BUF = byUartPut;
while (!TI0);
CLRTI0;
break;
case UART_COM1:
if(byUartPut == '\n')
{
SC1BUF = '\r';//0x0D;
while (!TI1);
CLRTI1;
}
SC1BUF = byUartPut;
while (!TI1);
CLRTI1;
break;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -