标签:
代码设计具体看源工程
?
?
/* * "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中断服务函数 static void 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){} return 0; } |
标签:
原文地址:http://www.cnblogs.com/logic3/p/5228915.html