Nios II application hang/lockup with an exception
Hello, All,
While we run the program, we randomly got an exception with the cause of -1 (unknown reason). The exception happened in the same statement but not always happened when the statement is executed. If no exception handler is added, the software just hang or lockup.
1. The exception:
The exception-causing statement is:
// Enable to raise the fifo almost empty (AE) interrupt.
altera_avalon_fifo_write_ienable(FIFO_CSR_BASE, ALTERA_AVALON_FIFO_IENABLE_AE_MSK);
its corresponding assembly code are shown below (or in the attached picture named ExceptionAssemblyCode.png)
The exact exception code line is “mov r2,zero”.
The following statement is called before calling altera_avalon_fifo_write_ienable():
// Clear the fifo almost empty (AE) interrupt.
altera_avalon_fifo_clear_event(FIFO_CSR_BASE, ALTERA_AVALON_FIFO_EVENT_AE_MSK);
2. Function altera_avalon_fifo_write_ienable() implementation:
int altera_avalon_fifo_write_ienable(alt_u32 address, alt_u32 mask)
{
IOWR_ALTERA_AVALON_FIFO_IENABLE(address, mask);
if(IORD_ALTERA_AVALON_FIFO_IENABLE(address) == mask)
return ALTERA_AVALON_FIFO_OK;
else
return ALTERA_AVALON_FIFO_IENABLE_WRITE_ERROR;
}
#define IOWR_ALTERA_AVALON_FIFO_IENABLE(base, data) \
IOWR(base, ALTERA_AVALON_FIFO_IENABLE_REG, data)
#define IORD_ALTERA_AVALON_FIFO_IENABLE(base) \
IORD(base, ALTERA_AVALON_FIFO_IENABLE_REG)
3. Processor and Development Environment:
It runs in the Cyclone V NIOS II processor. One fifo driver for 2K fifo peripheral is developed with the altera_avalon_fifo functions.
It uses the uCOS-II real-time OS. The application was developed with Quartus II Software version 13.0.1.123,
which is installed with QuartusSetup-13.0.1.232.exe. The Nios II 13.0sp1 Software Build Tools for Eclipse was part of the installation and was used.
4. What we have done:
4.1 Turned on the stack overflow debug, no stack overflow exception occurred.
4.2 Tried to use the hard-coded values instead of symbolic constants and added the critical section as flows, the same exception still occurred.
// FIFO_CSR_BASE = 0x610020
// ALTERA_AVALON_FIFO_EVENT_AE_MSK = 0x08
// ALTERA_AVALON_FIFO_IENABLE_AE_MSK = 0x08
OS_ENTER_CRITICAL();
altera_avalon_fifo_clear_event(0x610020, 0x08);
altera_avalon_fifo_write_ienable(0x610020, 0x08);
OS_EXIT_CRITICAL();
4.3 Tried to add the time-delay or yield as follows. The same exception still occurred.
IOWR_ALTERA_AVALON_FIFO_EVENT(0x610020, 0x08);
__asm("nop");
if((IORD_ALTERA_AVALON_FIFO_EVENT(0x610020) & 0x08) != 0)
{
printf("ALTERA_AVALON_FIFO_EVENT_CLEAR_ERROR\n");
}
__asm("nop");
IOWR_ALTERA_AVALON_FIFO_IENABLE(0x610020, 0x08);
__asm("nop");
if(IORD_ALTERA_AVALON_FIFO_IENABLE(0x610020) != 0x08)
{
printf("ALTERA_AVALON_FIFO_IENABLE_WRITE_ERROR\n");
}
__asm("nop");
4.4 After turn on the “enable_instrtruction_related_exceptions” with the re-issue of the exception-causing
statement in the added exception handler, the same exception still occurred but kept moving forward
without any impact to the software performance, that is, the software completed what expected to do.
Could you help to find the root cause of the exception? Any solution to it?
Thanks.
Sincerely
Patrick