/* * "Hello World" example. * * This example prints ‘Hello from Nios II‘ to the STDOUT stream. It runs on * the Nios II ‘standard‘, ‘full_featured‘, ‘fast‘, and ‘low_cost‘ example * designs. It runs with or without the MicroC/OS-II RTOS and requires a STDOUT * device in your system‘s hardware. * The memory footprint of this hosted application is ~69 kbytes by default * using the standard reference design. * * For a reduced footprint version of this template, and an explanation of how * to reduce the memory footprint for a given application, see the * "small_hello_world" template. * */ #include <stdio.h> #include <unistd.h> #include <io.h> #include <string.h> #include "system.h" #include "alt_types.h" #include "altera_avalon_uart_regs.h" #include "sys\alt_irq.h" ? static alt_u8 txdata =0; static alt_u8 rxdata =0; //UART中斷服務函數 staticvoid uart_isr(void* context,alt_u32 id) { rxdata = IORD_ALTERA_AVALON_UART_RXDATA(UART_BASE); txdata = rxdata; //查詢發送準備好訊號,如果沒有準備好,則等待 while(!((IORD_ALTERA_AVALON_UART_STATUS(UART_BASE)&ALTERA_AVALON_UART_STATUS_TRDY_MSK))); //發送準備好,發送txdata IOWR_ALTERA_AVALON_UART_TXDATA(UART_BASE,txdata); } void uart_init() { //清除狀態寄存器 IOWR_ALTERA_AVALON_UART_STATUS(UART_BASE,0); //使能接受準備好中斷 IOWR_ALTERA_AVALON_UART_CONTROL(UART_BASE,0X80); } int main() { printf("Please Start!\n"); //註冊UART中斷服務函數 alt_ic_isr_register(UART_IRQ_INTERRUPT_CONTROLLER_ID, UART_IRQ,uart_isr,NULL,0x00); uart_init(); while(1){} return0; } |