Altera_Forum
Honored Contributor
15 years agonios+timer+uart dont work! why?
This is my code:
# 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; 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; IOWR_ALTERA_AVALON_PIO_DATA(LEDS_BASE, ~value); send_char_buffer_to_uart("hello",5); IOWR_ALTERA_AVALON_TIMER_STATUS(SYSTEM_TIMER_BASE, 0); } int main(void){ //send_char_buffer_to_uart("Hello",5); alt_irq_register(SYSTEM_TIMER_IRQ, 0, handle_timer_interrupt); while(1); } Timer fires every 100 ms. Data are not sent to the serial port and LEDs dont blink (WHY ?). If I comment out the line in bold and uncomment same line in main function, the data will be sent in serial port and LEDs will blink, so my SoPC system is configured correctly. What is my mistake? P.S. sorry for my english)