Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12589 Discussions

Can't access the Main function!

Altera_Forum
Honored Contributor II
1,187 Views

Hi community: 

 

Now i encounter a really strange problem. 

 

I develop a nios system. It contains SDram, Sram, Flash, and other module. There is no error while i compile it in SOPC and Quartus. 

 

When i start a Hello LED project in NIOS IDE, the Alt_main is the entry of the program, everything goes well. No matter i Debug this program in both of the Ram(Sram, SDram) , or i download the .elf to the FLASH and let the program start from FLASH, the LED program runs pretty well. 

 

BUT, when i start a new project HELLO WORLD, the main is the entry , trouble comes out!! (This HELLO WORLD project can only print a string "HELLO" using the stdout. ) 

 

The compile process finishes without any error. But after i press the DEBUG button, the program seems keeping "running" without stop in the Main function. And the "Step into, Step over, Step run" icon is gray that can't be pressed.  

 

I just wonder where is the current PC. So i press the "Suspend" button. The PC jump between alt_irq.h and alt_irq_handler.c over and over.  

 

In detail, the PC always jump from this section below in alt_irq.h  

 

static ALT_INLINE alt_u32 ALT_ALWAYS_INLINE alt_irq_pending (void) 

alt_u32 active; 

 

NIOS2_READ_IPENDING (active); 

 

return active; 

 

to this section below in alt_irq_hander.c  

 

void alt_irq_handler (void) 

alt_u32 active; 

alt_u32 mask; 

alt_u32 i; 

 

/* 

* Notify the operating system that we are at interrupt level. 

*/  

 

ALT_OS_INT_ENTER(); 

 

/*  

* Obtain from the interrupt controller a bit list of pending interrupts, 

* and then process the highest priority interrupt. This process loops,  

* loading the active interrupt list on each pass until alt_irq_pending()  

* return zero. 

*  

* The maximum interrupt latency for the highest priority interrupt is 

* reduced by finding out which interrupts are pending as late as possible. 

* Consider the case where the high priority interupt is asserted during 

* the interrupt entry sequence for a lower priority interrupt to see why 

* this is the case. 

*/ 

 

active = alt_irq_pending (); 

 

do 

i = 0; 

mask = 1; 

 

/* 

* Test each bit in turn looking for an active interrupt. Once one is  

* found, the interrupt handler asigned by a call to alt_irq_register() is 

* called to clear the interrupt condition. 

*/ 

 

do 

if (active & mask) 

{  

alt_irq.handler(alt_irq.context, i);  

break; 

mask <<= 1; 

i++; 

 

} while (1); 

 

active = alt_irq_pending (); 

 

} while (active); 

 

/* 

* Notify the operating system that interrupt processing is complete. 

*/  

 

ALT_OS_INT_EXIT(); 

and once go over the if(active & mask) in loop 

 

do 

if (active & mask) 

{  

alt_irq.handler(alt_irq.context, i);  

break; 

mask <<= 1; 

i++; 

 

} while (1); 

 

the next time will go into the if(active & mask) and break. 

 

and now the pc return to the section i mentioned first time in alt_irq.h  

 

static ALT_INLINE alt_u32 ALT_ALWAYS_INLINE alt_irq_pending (void) 

alt_u32 active; 

 

NIOS2_READ_IPENDING (active); 

 

return active; 

 

So, here comes out a infinite loop. And the program will never go to the Main() function. 

 

Why? And how to fix it? 

 

 

 

 

I would like to offer some information further more. 

 

1). The SDRAM, SRAM, FLASH works! Because in the HELLO_LED program, i let the program located in the SDRAM, SRAM and the program can run. 

 

2). This situation is not all along. I mean the HELLO_WORLD program did work in the first time i debug it. But from i debug it in the next day till now, it is dead. 

 

 

 

Please give me some advice, or solution.  

 

I will reply the information you needed as soon as possible. 

 

Thanks all of U. http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif  

 

 

Kevin.Lee
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
244 Views

It is enough to have an exercise with hello . 

Then you should jump start on uClinux. 

http://nioswiki.jot.com/wikihome/operating...ms/%c2%b5clinux (http://nioswiki.jot.com/wikihome/operatingsystems/%c2%b5clinux

There is no need to spend much time on HAL API.
0 Kudos
Altera_Forum
Honored Contributor II
244 Views

Hippo&#39;s right, if uCLinux is what you&#39;d like run, eventually. Since you didn&#39;t post this to the uCLinux Forum, I&#39;m assuming that you don&#39;t want to run uCLinux. So, here are my questions: 

 

Which interrupt is causing this problem? Also, does the initialization code, for your devices, function? (Hint: step through the code in alt_sys_init.c) 

 

You mentioned that you had it working, at one point. What have you changed? 

 

Best of luck, 

 

- slacker
0 Kudos
Reply