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

📄 serial-s3c44b0.c

📁 基于S3C44B0的Bootloader源代码
💻 C
字号:
#include "..\inc\44b.h"
#include "..\inc\def.h"
#include "..\inc\drv\Serial.h"

/* flush serial input queue. returns 0 on success or negative error
 * number otherwise
 */
static int s3c44b0_serial0_flush_input(void)
{
	volatile U32 tmp;

	/* keep on reading as long as the receiver is not empty */
	while(rUTRSTAT0&0x01) {
		tmp = rURXH0;
	}
	return 0;
}




/* flush output queue. returns 0 on success or negative error number
 * otherwise
 */
static int s3c44b0_serial0_flush_output(void)
{
	/* wait until the transmitter is no longer busy */
	while(!(rUTRSTAT0&0x02));
	return 0;
}




/* initialise serial port at the request baudrate. returns 0 on
 * success, or a negative error number otherwise
 */
static int s3c44b0_serial0_init(int baud)
{
	int i;

	s3c44b0_serial0_flush_output();
	rUFCON0 = 0x0;
	rULCON0 = 0x03;
	rUCON0 = 0x05;
	rUBRDIV0 = ( (int)(MCLK/16./baud + 0.5) -1 );

	for(i=0; i<100; i++);
	return 0;
}



/* check if there is a character available to read. returns 1 if there
 * is a character available, 0 if not, and negative error number on
 * failure */
static int s3c44b0_serial0_poll(void)
{
	/* check for errors */
	if(rUERSTAT0&0x07)
		return -1;

	return (rUTRSTAT0&0x01);
}




/* read one character from the serial port. return character (between
 * 0 and 255) on success, or negative error number on failure. this
 * function is blocking */
static int s3c44b0_serial0_read(void)
{
	int rv;

	for(;;) {
		rv = s3c44b0_serial0_poll();

		if(rv < 0)
			return rv;

		if(rv > 0)
			return rURXH0;
	}
}




/* write character to serial port. return 0 on success, or negative
 * error number on failure. this function is blocking
 */
static int s3c44b0_serial0_write(int c)
{
	/* wait for room in the transmit FIFO */
	while(!(rUTRSTAT0&0x02));

	rUTXH0 = c;

	return 0;
}




/* export serial driver */
serial_driver_t s3c44b0_serial0_driver = {
	s3c44b0_serial0_init,
	s3c44b0_serial0_read,
	s3c44b0_serial0_write,
	s3c44b0_serial0_poll,
	s3c44b0_serial0_flush_input,
	s3c44b0_serial0_flush_output
};


static int s3c44b0_serial1_flush_input(void)
{
	volatile U32 tmp;

	/* keep on reading as long as the receiver is not empty */
	while(rUTRSTAT1&0x01) {
		tmp = rURXH1;
	}
	return 0;
}




/* flush output queue. returns 0 on success or negative error number
 * otherwise
 */
static int s3c44b0_serial1_flush_output(void)
{
	/* wait until the transmitter is no longer busy */
	while(!(rUTRSTAT1&0x02));
	return 0;
}




/* initialise serial port at the request baudrate. returns 0 on
 * success, or a negative error number otherwise
 */
static int s3c44b0_serial1_init(int baud)
{
	int i;

	s3c44b0_serial1_flush_output();
	rUFCON1 = 0x0;
	rULCON1 = 0x03;
	rUCON1 = 0x05;
	rUBRDIV1 = ( (int)(MCLK/16./baud + 0.5) -1 );

	for(i=0; i<100; i++);
	return 0;
}



/* check if there is a character available to read. returns 1 if there
 * is a character available, 0 if not, and negative error number on
 * failure */
static int s3c44b0_serial1_poll(void)
{
	/* check for errors */
	if(rUERSTAT1&0x07)
		return -1;

	return (rUTRSTAT1&0x01);
}




/* read one character from the serial port. return character (between
 * 0 and 255) on success, or negative error number on failure. this
 * function is blocking */
static int s3c44b0_serial1_read(void)
{
	int rv;

	for(;;) {
		rv = s3c44b0_serial1_poll();

		if(rv < 0)
			return rv;

		if(rv > 0)
			return rURXH1;
	}
}




/* write character to serial port. return 0 on success, or negative
 * error number on failure. this function is blocking
 */
static int s3c44b0_serial1_write(int c)
{
	/* wait for room in the transmit FIFO */
	while(!(rUTRSTAT1&0x02));

	rUTXH1 = c;

	return 0;
}




/* export serial driver */
serial_driver_t s3c44b0_serial1_driver = {
	s3c44b0_serial1_init,
	s3c44b0_serial1_read,
	s3c44b0_serial1_write,
	s3c44b0_serial1_poll,
	s3c44b0_serial1_flush_input,
	s3c44b0_serial1_flush_output
};

⌨️ 快捷键说明

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