?? uart.c
字號(hào):
/*************************************************************************/
/* */
/* FILE NAME VERSION */
/* */
/* uart.c KS32C5000(A)/50100 SNDS100 Ver1.0 */
/* */
/* COMPONENT */
/* */
/* */
/* DESCRIPTION */
/* */
/* UART library functions. */
/* */
/* AUTHOR */
/* */
/* Young Sun KIM, Samsung Electronics, Inc. */
/* */
/* DATA STRUCTURES */
/* */
/* */
/* FUNCTIONS */
/* */
/* UART_Initialize Initialize serial driver */
/* i_getc Get a character from buffer */
/* i_gets Get a string from buffer */
/* i_putc print a character */
/* i_puts Print a string */
/* i_printf formmatted print */
/* BaudRateVal return baudrate divisor val. */
/* */
/* DEPENDENCIES */
/* */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* in4maker 05-31-1999 Created initial version 1.0 */
/* */
/*************************************************************************/
#include "stdarg.h"
#include "lwip/def.h"
#include "Hardware.h"
#include "lwipopts.h"
#include "serial/uart.h"
int G_UartCmd1;
/********************************************************************/
/* INITIALIZE UART GLOBAL VARIABLE */
/********************************************************************/
/* Define references to external structures */
SERIAL_DEV uart_dev_init;
const BaudTable U_BaudRate[BAUD_TABLE] = {
//#if CPUCLK==24*MHz
2400, 0x14, 0x00,
4800, 0x0a, 0x00,
9600, 0x05, 0x00,
19200,0x02, 0x80,
38400,0x01, 0x40,
51200,0x00, 0xf0,
57600,0x00, 0xd5,
102400, 0x00, 0x78,
115200, 0x00, 0x6b,
//#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 */
/* */
/************************************************************************/
u16_t UART_Initialize()
{
asm("int off");
PIOBAttr = 0xFFFF;
PIOBDir = 0xFF7F;
PIOBData = 0x0000;
// PUartCmd1 =0;
// PUartCmd2 =0;
uart_dev_init.baud_rate = BAUDRATE; /*Default baudrate is 38400 which defined in Uart.h*/
uart_dev_init.data_mode = (UCON_RXM_INT|UCON_TXM_INT); /*Enable recieve and transimit intterupt*/
uart_dev_init.parity = ULCON_PMD_NO; /* No parity */
UART_Init(&uart_dev_init);
asm("int fiq,irq");
return;
}
/***************************/
/* Uart main Init function */
/***************************/
u16_t
UART_Init(SERIAL_DEV *s)
{
u16_t rUARTBRD;
/* UART interrupt off */
UARTRxIntOff();
UARTTxIntOff();
/* Initialize UART transmit & receive Queue */
/* default baud rate will be set. sysconf.h */
PUartBaudL=U_BaudRate[BaudRateVal(s->baud_rate)].divL;
PUartBaudH= U_BaudRate[BaudRateVal(s->baud_rate)].divH;
PUartCmd1 = s->parity|s->data_mode;
PUartCmd1=G_UartCmd1;
PUartCmd2 = UCON_SEND | UCON_RECEIVE ;
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 */
/* */
/************************************************************************/
void UARTTxIntOn()
{
/* Enable Interrupt */
G_UartCmd1 |= UCON_TXM_INT;
// G_UartCmd1 &= 0xbf;
PUartCmd1 =G_UartCmd1;
}
void UARTRxIntOn()
{
/* Enable Interrupt */
G_UartCmd1 |= UCON_RXM_INT;
// G_UartCmd1 &= 0xbf;
PUartCmd1 =G_UartCmd1;// UCON_RXM_INT ;
}
void UARTTxIntOff()
{
/* Disable Interrupt */
G_UartCmd1 &= ~UCON_TXM_INT;
// G_UartCmd1 &= 0xbf;
PUartCmd1 =G_UartCmd1;
}
void UARTRxIntOff()
{
/* Disable Interrupt */
G_UartCmd1 &= ~UCON_RXM_INT;
// G_UartCmd1 &= 0xbf;
PUartCmd1 =G_UartCmd1;// UCON_RXM_INT ;
}
u16_t BaudRateVal(u32_t baud)
{
u16_t index;
for(index = 0; index < BAUD_TABLE; index++)
{
if(U_BaudRate[index].baud == baud) return(index);
}
return(0); /* baudrate data doesn't in table */
}
u16_t BaudRate(u16_t divH , u16_t divL)
{
u16_t index;
for(index = 0; index < BAUD_TABLE; index++)
{
if ((U_BaudRate[index].divH== divH) && (U_BaudRate[index].divL == divL))
return(index);
}
return(0); /* baudrate data doesn't in table */
}
void put_char(u8_t ch)
{
WaitXmitter();
PUartData = ch;
}
char get_char()
{
u8_t ch;
WaitRcver();
ch = PUartData;
return ch;
}
void put_string(char *ptr )
{
while(*ptr )
{
put_byte(*ptr++ );
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -