📄 serial.c
字号:
**
**-----------------------------------------------------------------------------
*/
__interrupt void MD_INTST6( void )
{
#if 0
if( UART6_TX_CNT == 0 ){
/* send data complete */
// CALL_UART6_Send();
UART6_TX_ADDRESS = NULL;
}
else if(((ASIF6 & 0x02) == 0) && ((ASIM6 & 0x80) == 0x80)){
UART6_TX_CNT--;
if( UART6_TX_CNT != 0 ){
TXB6 = *UART6_TX_ADDRESS++;
}
}
#else
if(is_CONSOLE_TxFlag()) {
uart_tx_isr();
}
#endif
}
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function is the UART6 receive error interrupt handler.
**
** Parameters:
** None
**
** Returns:
** None
**
**-----------------------------------------------------------------------------
*/
__interrupt void MD_INTSRE6( void )
{
UCHAR err_type;
#if 0
err_type = RXB6; /* one-time read */
err_type = ASIS6;
if( err_type & 0x1 ){
err_type = MD_OVERRUNERROR; /* overrun error */
}
else if( err_type & 0x2 ){
err_type = MD_FRAMEERROR; /* framing error */
}
else{
err_type = MD_PARITYERROR; /* parity error */
}
// CALL_UART6_Error( err_type );
#else
uart_rx_isr();
#endif
}
#endif // #if ENABLE_UART6
#if ENABLE_CSI10
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function initializes CSI10 module.
**
** Parameters:
** None
**
** Returns:
** None
**
**-----------------------------------------------------------------------------
*/
void CSI10_Init( void )
{
ClrIORBit(P1, 0x04); /* port setting in transmit/receive mode */
ClrIORBit(PM1, 0x04);
ClrIORBit(CSIM10, 0x10); /* data direction MSB */
SetIORBit(CSIC10, 0x18); /* clock data phase4 */
ClrIORBit(IF0H, 0x04);
ClrIORBit(MK0H, 0x04); /* transfer end interrupt enable */
ClrIORBit(PR0H, 0x04); /* interrupt high */
SetIORBit(CSIM10, 0x40); /* transmit/receive mode */
SetIORBit(CSIM10, 0x80);
}
#if 0
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function is responsible for UART6 data receiving.
**
** Parameters:
** rxbuf: receive buffer pointer
** rxnum: buffer size
**
** Returns:
** MD_OK
** MD_ERROR
**
**-----------------------------------------------------------------------------
*/
MD_STATUS CSI10_ReceiveData( UCHAR* rxbuf, UCHAR rxnum )
{
UCHAR tmp;
if( rxnum < 1 ){
return MD_ERROR;
}
/* init CSI10 receive parameter */
CSI10_RX_LEN = rxnum; /* receive data count */
CSI10_RX_CNT = 0; /* receive data count */
CSI10_RX_ADDRESS = rxbuf; /* receive buffer pointer and head */
tmp = SIO10;
return MD_OK;
}
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function is responsible for UART6 data transfering.
**
** Parameters:
** txnum: buffer size
** txbuf: transfer buffer pointer
**
** Returns:
** MD_OK
** MD_ERROR
**
**-----------------------------------------------------------------------------
*/
MD_STATUS CSI10_SendData( UCHAR* txbuf, UCHAR txnum )
{
if( txnum < 1 ){
return MD_ERROR;
}
/* init CSI10 send parameter */
CSI10_TX_LEN = txnum; /* send data length */
CSI10_TX_CNT = 0; /* send data count */
CSI10_TX_ADDRESS = txbuf; /* send buffer pointer */
SOTB10 = *CSI10_TX_ADDRESS++; /* started by writing txbuf[0] to SOTBn */
return MD_OK;
}
#endif
// -------------------------------------------------
// CSI/SPI Read/Write
// -------------------------------------------------
UCHAR CSI10_ReadWrite(UCHAR ch)
{
while((CSIM10 & CSIM_CSOT)); // Wait TX End
CSI10_TX = ch;
NOP();
NOP();
while((CSIM10 & CSIM_CSOT)); // Wait TX End
NOP();
return CSI10_RX;
}
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function is the CSI10 interrupt handler.
**
** Parameters:
** None
**
** Returns:
** None
**
**-----------------------------------------------------------------------------
*/
__interrupt void MD_INTCSI10( void )
{
#if 0
/* send interrupt */
if( CSI10_TX_CNT < CSI10_TX_LEN ){
if( CSI10_TX_CNT == (CSI10_TX_LEN-1) ){
CALL_CSI10_Send(); /* send finish */
}
else {
SOTB10 = *CSI10_TX_ADDRESS++;
CSI10_TX_CNT++;
}
}
/* receive interrupt */
if( CSI10_RX_CNT < CSI10_RX_LEN ){
*(UCHAR*)CSI10_RX_ADDRESS ++= SIO10;
CSI10_RX_CNT++;
if( CSI10_RX_CNT == CSI10_TX_LEN ){
/* receive complete */
CALL_CSI10_Receive();
}
}
#endif
}
#endif // #if ENABLE_CSI10
#if ENABLE_CSI11
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function initializes CSI11 module.
**
** Parameters:
** None
**
** Returns:
** None
**
**-----------------------------------------------------------------------------
*/
void CSI11_Init( void )
{
ClrIORBit(P0, 0x04); /* port setting in transmit/receive mode */
ClrIORBit(PM0, 0x04);
ClrIORBit(CSIM11, 0x10); /* data direction MSB */
ClrIORBit(CSIM11, 0x20);
SetIORBit(CSIC11, 0x18); /* clock data phase4 */
SetIORBit(P0, 0x10);
ClrIORBit(PM0, 0x10);
SetIORBit(CSIC11, 0x00); /* fprs/2 */
ClrIORBit(IF1H, 0x02);
ClrIORBit(MK1H, 0x02); /* transfer end interrupt enable */
ClrIORBit(PR1H, 0x02); /* interrupt high */
SetIORBit(CSIM11, 0x40); /* transmit/receive mode */
SetIORBit(CSIM11, 0x80);
}
#if 0
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function is responsible for CSI11 data transfering.
**
** Parameters:
** txbuf: transfer buffer pointer
** txnum: buffer size
**
** Returns:
** MD_OK
** MD_ERROR
**
**-----------------------------------------------------------------------------
*/
MD_STATUS CSI11_SendData( UCHAR* txbuf ,UCHAR txnum )
{
if( txnum < 1 ){
return MD_ERROR;
}
// while(rf_spi_flag_busy);
// 2007/2/2 13:19:40, Sunny: TODO, Put the CS to Low
// rf_spi_flag_busy = TRUE;
UBEC_Activate_SEN();
/* init CSI10 send parameter */
CSI11_TX_LEN = txnum; /* send data length */
CSI11_TX_CNT = 0; /* send data count */
CSI11_TX_ADDRESS = txbuf; /* send buffer pointer */
SOTB11 = *CSI11_TX_ADDRESS++; /* started by writing txbuf[0] to SOTBn */
return MD_OK;
}
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function is responsible for CSI11 data receiving.
**
** Parameters:
** rxbuf: receive buffer pointer
** rxnum: buffer size
**
** Returns:
** MD_OK
** MD_ERROR
**
**-----------------------------------------------------------------------------
*/
MD_STATUS CSI11_ReceiveData( UCHAR* rxbuf, UCHAR rxnum )
{
UCHAR tmp;
if( rxnum < 1 ){
return MD_ERROR;
}
// while(rf_spi_flag_busy);
// 2007/2/2 13:19:40, Sunny: TODO, Put the CS to Low
// rf_spi_flag_busy = TRUE;
UBEC_Activate_SEN();
/* init CSI11 receive parameter */
CSI11_RX_LEN = rxnum; /* receive data length */
CSI11_RX_CNT = 0;
CSI11_RX_ADDRESS = rxbuf; /* receive buffer pointer */
tmp = SIO11;
return MD_OK;
}
#endif
// -------------------------------------------------
// CSI/SPI Read/Write
// -------------------------------------------------
UCHAR CSI11_ReadWrite(UCHAR ch)
{
while((CSIM11 & CSIM_CSOT)); // Wait TX End
CSI11_TX = ch;
NOP();
NOP();
while((CSIM11 & CSIM_CSOT)); // Wait TX End
NOP();
return CSI11_RX;
}
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function is the CSI11 transfer end interrupt handler.
**
** Parameters:
** None
**
** Returns:
** None
**
**-----------------------------------------------------------------------------
*/
__interrupt void MD_INTCSI11( void )
{
#if 0
/* send interrupt */
if( CSI11_TX_CNT < CSI11_TX_LEN ){
if( CSI11_TX_CNT == (CSI11_TX_LEN-1)){
CALL_CSI11_Send(); /* send finish */
}
else {
CSI11_TX_CNT++;
SOTB11 = *CSI11_TX_ADDRESS++;
}
}
/* receive interrupt */
if( CSI11_RX_CNT < CSI11_RX_LEN ){
*(UCHAR*)CSI11_RX_ADDRESS++ = SIO11;
CSI11_RX_CNT++;
if( CSI11_RX_CNT == CSI11_RX_LEN ){
/*receive complete */
CALL_CSI11_Receive();
return;
}
}
#endif
}
#endif // #if ENABLE_CSI11
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -