simple_rx_isr.c

来自「altera串口源代码程序」· C语言 代码 · 共 48 行

C
48
字号
//
#include "buffer.h"  // defines RXBUFSIZE and TXBUFSIZE
#include "excalibur.h"

//Global variables
unsigned char RxBuf[RXBUFSIZE];	// the receiver buffer.
int RxHead = 0;			// the circular buffer index
int RxTail = 0;
unsigned char TxBuf[TXBUFSIZE];	// the transmit buffer.
int TxHead = 0;			// the circular buffer index
int TxTail = 0;

void simpleReceiver1(int context);
unsigned char _getchar();

int main(void)
	{
	int context = 0;
	unsigned char rxchar;
	
	nr_installuserisr(na_uart1_irq, simpleReceiver1, context); // install UART ISR (receiver)
	na_uart1->np_uartcontrol = np_uartcontrol_irrdy_mask; // enable rrdy interrupt
	
	while(1)
		{
		rxchar = _getchar();
		printf("\nfrom RxBuf: %c \n",rxchar);
		}

	return 0;
	}


// pass an int to make it compatible with nr_installuserisr2 routine
// contents of third argument ("context") in nr_installuserisr is passed to ISR
void simpleReceiver1(int data)
	{
	// put new char into buffer from UART
	RxBuf[RxHead] = na_uart1->np_uartrxdata; 
	// clear the errors and interrupts
	na_uart1->np_uartstatus=0; 

	if ((++RxHead) > (RXBUFSIZE-1))		
		{
		RxHead = 0;
		}
	}

⌨️ 快捷键说明

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