Forum Discussion
Altera_Forum
Honored Contributor
15 years agoThank you kevin, I have decided this issue as follows:
# include <unistd.h> # include <fcntl.h> # include "alt_types.h" # include "altera_avalon_pio_regs.h" # include "altera_avalon_uart_regs.h" # include "altera_avalon_timer_regs.h" # include "sys/alt_irq.h" # include "system.h" unsigned char text_buffer; unsigned char int_flag; int send_char_buffer_to_uart(unsigned char *buf, int size){ int comport,status; comport=open("/dev/uart",O_WRONLY); status=(write(comport, buf, size)); close(comport); return status; } int get_char_buffer_from_uart(unsigned char *buf, int size){ int comport,received_bytes_num; comport=open("/dev/uart",O_RDONLY); received_bytes_num=(read(comport, buf, size)); close(comport); return received_bytes_num; } void handle_timer_interrupt (void* context, alt_u32 id) { static alt_u8 value = 0x00; value = value + 1; int_flag=1; IOWR_ALTERA_AVALON_PIO_DATA(LEDS_BASE, ~value); IOWR_ALTERA_AVALON_TIMER_STATUS(SYSTEM_TIMER_BASE, 0); } int main(void){ alt_irq_register(SYSTEM_TIMER_IRQ, 0, handle_timer_interrupt); int_flag=0; while(1){ if(int_flag){ send_char_buffer_to_uart("hello",5); int_flag=0; } } }