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

📄 putchar.c

📁 altera串口源代码程序
💻 C
字号:
/**************************************************/
// _putchar(int in_char)
//		Take a char and puts it in the Transmit buffer.
//		In the simple case it can actually stuff a 
//		char into the UART. 
//		After putting a char into the buffer it
//			Increments the the TxHead index and   
//			Watches for wrap around.  If the buffer 
//			gets too full the chars are thrown away.
//
// Version 1.1 SEP-19-2001 CRUBEN
/**************************************************/

#include "excalibur.h"
#include "buffer.h"

//Globals variables
extern unsigned char TxBuf[TXBUFSIZE];	// the transmit buffer.
extern int TxHead;			// the circular buffer index
extern int TxTail;

int _putchar(int in_char) 
{
	int size;

	int  sr = na_uart1->np_uartstatus;	// get the status register	

	if ((TxHead == TxTail) && (sr & np_uartstatus_trdy_mask)) 
		{
		na_uart1->np_uarttxdata = in_char;   // send directly
		}
	else
		{
		if (TxHead >= TxTail)		// Find out how full the TX buffer is
			size = TxHead - TxTail;
		else
			size = ((TXBUFSIZE-1) - TxTail) + TxHead;

		if (size > (TXBUFSIZE - 3))   // don't overflow TxBuf[]
			return (-1);	      // just throw the char away

		TxBuf[TxHead] = in_char;
		if (++TxHead > (TXBUFSIZE-1))
			TxHead = 0;
		
		na_uart1->np_uartcontrol = na_uart1->np_uartcontrol | np_uartcontrol_itrdy_mask;   // enable trdy interrupt
	}
	return(1);
}

⌨️ 快捷键说明

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