⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serial.c

📁 source code of armboot for s3c4510
💻 C
字号:
/* * (C) Copyright 2002 * Sysgo Real-Time Solutions, GmbH <www.elinos.com> * Marius Groeger <mgroeger@sysgo.de> * * (C) Copyright 2002 * Sysgo Real-Time Solutions, GmbH <www.elinos.com> * Alex Zuepke <azu@sysgo.de> * * Copyright (C) 1999 2000 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA * */#include "armboot.h"#include "s5n8947.h"volatile unsigned int *CUART_TxBuf;volatile unsigned int *CUART_RxBuf;int calcUartCnt(int BaudRate, int *UartCnt){	int tDIV, DivCnt0, DivCnt1, UartClk;	    /* Set Buad Rate Divisor value. */    /* You should select UART clock */#if USE_UART_CLK	UartClk = CPU_SPEED;#else	UartClk = CPU_SPEED/2;#endif	/*USE_UART_CLK*/	    tDIV = UartClk / (16 * BaudRate);    if(((tDIV%16)==0) || ((tDIV-1)>0xffff))     {		DivCnt1 = 1;		DivCnt0 = tDIV/16 -1;    }	else  	{    	DivCnt1 = 0;       	DivCnt0 = tDIV -1;    }    *UartCnt = DivCnt0*16 + DivCnt1;        return 0;}void serial_setbrg(bd_t *bd, int baudrate){    unsigned int reg = 0;      	/* UART Control Regsiter */    REG_WRITE(ULCON, (INT_CLK | PARITY_NONE | ONE_STOP | WORD_LEN));   	/* Poll Mode Set*/	REG_READ(UCON, reg);	reg &= UCON_RX_TX_RESET;	/**Reset RX and TX mode bits*/    reg |= UCON_RX | UCON_TX;    REG_WRITE(UCON, reg);	intDisable (INT_LVL_UARTTX0);    intDisable (INT_LVL_UARTRX0);	/* set baudrate */    if (baudrate == 1200) 		 calcUartCnt(1200, &reg);    else if (baudrate == 9600)   calcUartCnt(9600, &reg);    else if (baudrate == 19200)  calcUartCnt(19200, &reg);    else if (baudrate == 38400)  calcUartCnt(38400, &reg);    else if (baudrate == 57600)  calcUartCnt(57600, &reg);    else if (baudrate == 115200) calcUartCnt(115200, &reg);    else hang();	REG_WRITE(UBRDIV, reg);//	REG_WRITE(UBRDIV, 0x130);	CUART_TxBuf = &UARTTXH0;	CUART_RxBuf = &UARTRXB0;}  /* * Initialise the serial port with the given baudrate. The settings * are always 8 data bits, no parity, 1 stop bit, no start bits. * */void serial_init(bd_t *bd){    const char *baudrate;    if ((baudrate = getenv(bd, "baudrate")) != 0)	{    	bd->bi_baudrate = simple_strtoul(baudrate, NULL, 10);	}       	serial_setbrg(bd, bd->bi_baudrate);}/* * Output a single byte to the serial port. * Wait until UART transmit buffer register empty. * when it is empty, tramsmit new data... */#if 1void serial_putc(const char c){    while(!(UARTSTAT0 & UART_STAT_TXB_EMPTY)) ;    *CUART_TxBuf = c;    if(c == '\n')    {        while(!(UARTSTAT0 & UART_STAT_TXB_EMPTY)) ;        *CUART_TxBuf = '\r';    }}#elsevoid serial_putc(const char c){	uint uiReg=0x0;	REG_READ(USTAT, uiReg); 	while(!(uiReg & USTAT_TX_READY)) ;//	REG_WRITE(UTXBUF, c);		*CUART_TxBuf = c;    if(c == '\n') 	{		REG_READ(USTAT, uiReg);		while(!(uiReg & USTAT_TX_READY)) ;		*CUART_TxBuf = c;    }}#endif/* * Read a single byte from the serial port. Returns 1 on success, 0 * otherwise. When the function is succesfull, the character read is * written into its argument c. */int serial_tstc(void){ 	ulong status;     REG_READ(USTAT, status);    return (status & USTAT_RX_READY);//  return ((status & USTAT_RX_READY)>>5);}/* * Read a single byte from the serial port. Returns 1 on success, 0 * otherwise. When the function is succesfull, the character read is * written into its argument c. */#if 1int serial_getc(void){    while(!(UARTSTAT0 & USTAT_RX_AVAIL))        UARTSTAT0 = USTAT_OVER_ERR | USTAT_OVER_ERR | USTAT_RX_READY;    return UARTRXB0;}#elseint serial_getc(void){	ulong status;	char ch; 	do 	{		REG_READ (USTAT, status);	} while ((status & USTAT_RX_AVAIL) == 0x00);	/* got a character */    REG_READ(URXBUF, ch);	return (ch);}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -