📄 uart.c.bak
字号:
/*************************************************************************/
/* */
/* FILE NAME VERSION */
/* */
/* uart.c KS32C50100 SNDS100 Ver1.0 */
/* */
/* COMPONENT */
/* */
/* */
/* DESCRIPTION */
/* */
/* */
/*************************************************************************/
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "apdialog.h"
#include "snds.h"
#include "uart.h"
#include "isr.h"
#include "pollio.h"
#include "sysconf.h"
#define KS32C50100 1
//#define EX_UCLK 0
/********************************************************************/
/* INITIALIZE UART GLOBAL VARIABLE */
/********************************************************************/
/* Define references to external structures */
SERIAL_DEV uart_dev_init;
UART_BUFFER RxQ[NUM_OF_SERIAL_DEV],TxQ[NUM_OF_SERIAL_DEV];
BaudTable U_BaudRate[BAUD_TABLE] = {
#ifdef EX_UCLK
/* for 29.4912MHz UART clock */
9600, 0x000bf,
19200, 0x0005f,
38400, 0x0002f,
57600, 0x0001f,
115200, 0x0000f,
230400, 0x00007,
460800, 0x00003
#else
#ifdef KS32C50100
/* for 50MHz/2 UART clock */
9600, 0x00a20,
19200, 0x00500,
38400, 0x00280,
57600, 0x001a0,
115200, 0x000d0,
230400, 0x00060,
460800, 0x00020 // not available
#else
/* for 33MHz UART clock */
9600, 0x000d6,
19200, 0x0006a,
38400, 0x00035,
57600, 0x00023,
115200, 0x00011,
230400, 0x00008,
460800, 0x00008 // not available
#endif
#endif
};
/************************************************************************/
/* */
/* FUNCTION "UART_Initialize" */
/* */
/* */
/* DESCRIPTION */
/* */
/* This function is used to initialize the input and output */
/* control variables. */
/* */
/* AUTHOR */
/* */
/* */
/* CALLED FROM */
/* */
/* */
/* ROUTINES CALLED */
/* */
/* None */
/* */
/* INPUTS */
/* */
/* None */
/* */
/* OUTPUTS */
/* */
/* Initialization of global structures */
/* */
/************************************************************************/
uint32 UART_Initialize()
{
Disable_Int(nGLOBAL_INT); /* Global interrupt disabled */
/*****************************/
/* Initialize UART channel 0 */
/*****************************/
uart_dev_init.com_port = SERIAL_DEV0; /* com 0 */
uart_dev_init.baud_rate = baudrate;
uart_dev_init.data_mode = (UCON_RXM_INTREQ|UCON_TXM_INTREQ|UCON_RXSTAT_INT);
uart_dev_init.parity = ULCON_PMD_NO; /* No parity */
// uart_dev_init.parity = ULCON_PMD_ODD; /* No parity */
// uart_dev_init.parity = ULCON_PMD_EVEN; /* No parity */
uart_dev_init.stop_bits = 0; /* one bit */
uart_dev_init.data_bits = ULCON_WL8; /* 8bits */
#ifdef EX_UCLK
uart_dev_init.clk_sel = ULCON_UCLK; /* external clock,29.4912MHz */
#else
uart_dev_init.clk_sel = 0; /* internal clock */
#endif
UART_Init(&uart_dev_init);
/*****************************/
/* Initialize UART channel 1 */
/*****************************/
uart_dev_init.com_port = SERIAL_DEV1; /* com 0 */
uart_dev_init.baud_rate = baudrate;
uart_dev_init.data_mode = (UCON_RXM_INTREQ|UCON_TXM_INTREQ|UCON_RXSTAT_INT);
uart_dev_init.parity = ULCON_PMD_NO; /* No parity */
uart_dev_init.stop_bits = 0; /* one bit */
uart_dev_init.data_bits = ULCON_WL8; /* 8bits */
#ifdef EX_UCLK
uart_dev_init.clk_sel = ULCON_UCLK; /* external clock,29.4912MHz */
#else
uart_dev_init.clk_sel = 0; /* internal clock */
#endif
UART_Init(&uart_dev_init);
Enable_Int(nGLOBAL_INT); /* Global interrupt disabled */
return(SUCCESS);
}
/***************************/
/* Uart main Init function */
/***************************/
uint32 UART_Init(SERIAL_DEV *s)
{
uint32 rUARTBRD;
/* UART interrupt off */
UARTRxIntOff(s->com_port);
UARTTxIntOff(s->com_port);
/* Initialize UART transmit & receive Queue */
TxQInit(s->com_port);
RxQInit(s->com_port);
/* default baud rate will be set. sysconf.h */
rUARTBRD = U_BaudRate[BaudRateVal(s->baud_rate)].div;
if(s->com_port)
{
/* Interrupt service routine setup */
SysSetInterrupt(nUART1_TX_INT, Uart1TxLisr);
SysSetInterrupt(nUART1_RX_ERR_INT, Uart1RxErrLisr);
UARTLCON1 = s->data_bits|s->stop_bits|s->parity|s->clk_sel;
UARTCONT1 = s->data_mode;
UARTBRD1 = rUARTBRD;
}
else
{
/* Interrupt service routine setup */
//SysSetInterrupt(nUART0_TX_INT, Uart0TxLisr);
//SysSetInterrupt(nUART0_RX_ERR_INT, Uart0RxErrLisr);
/* UART mode, default baud rate setup */
UARTLCON0 = s->data_bits|s->stop_bits|s->parity|s->clk_sel;
UARTCONT0 = s->data_mode;
UARTBRD0 = rUARTBRD;
}
//UARTRxIntOn(s->com_port);
//UARTTxIntOn(s->com_port);
return(SUCCESS);
}
/************************************************************************/
/* */
/* FUNCTION "UART_Que_Init" */
/* */
/* */
/* DESCRIPTION */
/* */
/* This function is used to initialize the input and output */
/* control variables. */
/* */
/* AUTHOR */
/* */
/* */
/* CALLED FROM */
/* */
/* */
/* ROUTINES CALLED */
/* */
/* None */
/* */
/* INPUTS */
/* */
/* None */
/* */
/* OUTPUTS */
/* */
/* Initialization of global structures */
/* */
/************************************************************************/
/* Transmit Que initialize */
void TxQInit(uint32 channel)
{
int i;
for(i=0; i < MAXEVENT; i++)
{
TxQ[channel].buff[i] = '\0';
}
TxQ[channel].wptr = 0;
TxQ[channel].rptr = 0;
}
/* Receive Que initialize */
void RxQInit(uint32 channel)
{
int i;
for(i=0; i < MAXEVENT; i++)
{
RxQ[channel].buff[i] = '\0';
}
RxQ[channel].wptr = 0;
RxQ[channel].rptr = 0;
}
/************************************************************************/
/* */
/* FUNCTION "UART_INT_LISR" */
/* */
/* Uart0TxLisr() */
/* Uart0RxErrLisr() */
/* Uart1TxLisr() */
/* Uart1RxErrLisr() */
/* UARTRxIntOn() */
/* UARTTxIntOn() */
/* UARTRxIntOff() */
/* UARTTxIntOff() */
/* */
/* DESCRIPTION */
/* */
/* */
/* AUTHOR */
/* */
/* */
/* CALLED FROM */
/* */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -