Altera_Forum
Honored Contributor
19 years agoUART interrupt
I'm in the process of converting an old NIOS II project over to eCos. The interrupts do not work when I use the eCos API. Here is the relevant code.
#include <cyg/hal/system.h># include <cyg/kernel/kapi.h>
unsigned char abycin;
volatile unsigned int byrxptr = 0;
unsigned int bywrptr = 0;
cyg_uint32 uart_debug_isr(cyg_vector_t vector, cyg_addrword_t data)
{
volatile int clr_int;
// Block this interrupt from occurring until this ISR completes.
cyg_interrupt_mask(vector);
// Tell the processor that we have received the interrupt.
cyg_interrupt_acknowledge(vector);
if (!(IORD_ALTERA_AVALON_UART_STATUS(UART_DEBUG_BASE) & 0x02))
{
abycin = IORD_ALTERA_AVALON_UART_RXDATA(UART_DEBUG_BASE);
if(byrxptr < (RXBUF_SIZE_DEBUG - 2)) byrxptr++;
else byrxptr = 0;
}
else clr_int = IORD_ALTERA_AVALON_UART_RXDATA(UART_DEBUG_BASE); // read UDR if framing error just to clear interrupt
// Allow this interrupt to occur again.
//cyg_interrupt_unmask (vector);
// Tell the kernel that chained interrupt processing is done.
//return CYG_ISR_HANDLED;
return CYG_ISR_HANDLED | CYG_ISR_CALL_DSR;
}
void uart_debug_dsr(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data)
{
//printf("DSR\n");
//out_str("DSR\n");
cyg_interrupt_unmask(vector);
}
void out_str(char *s)
{
unsigned char *c;
for(c = s;; c++)
{
if(*c == 0)
break;
out_char((unsigned char)*c);
}
}
void out_char(unsigned char c)
{
while(!(IORD_ALTERA_AVALON_UART_STATUS(UART_DEBUG_BASE) & 0x40));
IOWR_ALTERA_AVALON_UART_TXDATA(UART_DEBUG_BASE, c);
}
void cyg_user_start(void)
{
int divisor = 0;
int old = 0;
cyg_handle_t uart_debug_handle, timer_handle;
cyg_interrupt uart_debug_intr, timer_intr;
cyg_interrupt_create(UART_DEBUG_IRQ, 99, 0, &uart_debug_isr, &uart_debug_dsr, &uart_debug_handle, &uart_debug_intr);
cyg_interrupt_attach(uart_debug_handle);
cyg_interrupt_disable();
/* Other initialization tasks performed here */
cyg_interrupt_enable();
cyg_interrupt_unmask(UART_DEBUG_IRQ);
while(1)
{
while (bywrptr != byrxptr) // Check to see if any data has been received by the Uart
{
printf("bywrptr != byrxptr\n");
ProcessRxBuf(); // Process new data received from Uart
}
//while (rtdwrptr != rtdrxptr)
//MDP();
}
} Is there something special that needs to be done in the nios2configtool to get interrupts to work?