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

📄 serial.c

📁 这是arm10上面的linux环境下的串口通信源程序,方便学习和调试
💻 C
字号:
#include "serial.h"#include "pxa-regs.h"/* * Initialise the serial port with the given baudrate. The settings * are always 8 data bits, no parity, 1 stop bit, no start bits. * */void SerialInit(eBauds baudrate){	/* Theory of operations:	 * - Flush the output buffer	 * - switch receiver and transmitter off	 * - clear all sticky bits in control register 3	 * - set the port to sensible defaults (no break, no interrupts,	 *   no parity, 8 databits, 1 stopbit, transmitter and receiver 	 *   enabled	 * - set the baudrate to the requested value	 * - turn the receiver and transmitter back on	 */	while((FFLSR & (0x1 << 5)) == 0) ;	FFLCR = 0x00;	FFLCR = 0x80;	FFDLL = baudrate &0xff;	FFDLH = baudrate >> 8;	FFLCR = 0x00;	FFLCR = 0x03;	FFFCR = 0x00;	FFIER = FFIER | 0x40;}/* * Output a single byte to the serial port. */void SerialOutputByte(const char c){	/* wait for room in the tx FIFO */	while((FFLSR & (0x1 << 5)) == 0) ;	FFRBR = c;	/* If \n, also do \r */	if(c == '\n')		SerialOutputByte('\r');}/* * Write a null terminated string to the serial port. */void SerialOutputString(const char *s) {	while(*s != 0)		SerialOutputByte(*s++);		} /* SerialOutputString *//* * 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 SerialInputByte(char *c){	if(FFLSR & 0x01) {		*c = (char)FFRBR;		return(1);	} else {		/* no bit ready */		return(0);	}} /* SerialInputByte */

⌨️ 快捷键说明

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