UART Interrupt and timer interrupt at the same time
- 5 years ago
Hi Junbum, sorry for the late response. I was looking for the right answer.
Here you have an example code with the UART and Timer interruptions, the only difference is that it uses a timer init, could you compare your code with this.
/*
* "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 <fcntl.h># include "sys/alt_stdio.h"# include "system.h"# include "alt_types.h"# include "altera_avalon_uart_regs.h"# include "altera_avalon_timer_regs.h"# include "sys/alt_irq.h"
# define Switches (volatile char *) 0x00041040# define LEDs (char *) 0x00041050# define UART0_BASE (char *) 0x00041000# define UART0_IRQ 1# define TIMER0_IRQ 2# define TIMER0_BASE (char *) 0x00041020
void uart0_put_char(unsigned char ch)
{
while((IORD_ALTERA_AVALON_UART_STATUS(UART0_BASE) & 0x040) != 0x040){ ;}
IOWR_ALTERA_AVALON_UART_TXDATA(UART0_BASE,ch);
}
void uart0_put_str(unsigned char * str){
while(*str){
uart0_put_char(*str);
str++;
}
}
void uart_handle(void *context,alt_u32 interrupt)
{
unsigned short int data,status;
status = IORD_ALTERA_AVALON_UART_STATUS(UART0_BASE);
data =IORD_ALTERA_AVALON_UART_RXDATA(UART0_BASE);
*LEDs=(char)data;
}
void uart_init()
{
alt_u32 control;
volatile unsigned long uart_capture;
control = ALTERA_AVALON_UART_CONTROL_TRDY_MSK | ALTERA_AVALON_UART_CONTROL_RRDY_MSK | ALTERA_AVALON_UART_CONTROL_E_MSK;
IOWR_ALTERA_AVALON_UART_CONTROL(UART0_BASE, control);
if (alt_irq_register(UART0_IRQ, (void*)uart_capture, uart_handle)){
alt_putstr("UART0_IRQ Register Successful\n");
}else{
alt_putstr("UART0_IRQ Register UnSuccessful\n");
}
}
void handle_timer_interrupt (void* context, alt_u32 id){
static alt_u32 value = 0x00;
value = value + 1;
if(value % 1000 == 0){
*LEDs=(char)value;
}
IOWR_ALTERA_AVALON_TIMER_STATUS(TIMER0_BASE,0); // Clear the interrupt flag
}
void timer_init(){
IOWR_ALTERA_AVALON_TIMER_CONTROL (TIMER0_BASE,ALTERA_AVALON_TIMER_CONTROL_ITO_MSK | ALTERA_AVALON_TIMER_CONTROL_CONT_MSK | ALTERA_AVALON_TIMER_CONTROL_START_MSK);
alt_irq_register(TIMER0_IRQ, 0, handle_timer_interrupt);
}
int main(){
printf("Hello from NIOS II \n");
uart_init();
printf("uart init successful");
timer_init();
printf("timer init successful");
//usleep(1000000);
printf("Hello from NIOS III \n");
*LEDs = 0xAA;
printf("Switch Status : %x " , (char)*Switches);
uart0_put_str("Hello World");
while(1){
//*LEDs = *Switches;
printf("hello");
}
return 0;
}
Regards,
Isaac