Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
19 years ago

Beginners problems. i need assistance...

Before you read this: it may look like i am ranting and raving. That is not the case.

I am just frustrated after a week of problems, that's all.

All the questions i have are very simple basic questions. Things that take 1 click or 1 line of code in the IDE and C compilers from Keil or Tasking, yet turn out to be a complete nightmare in this NIOS IDE if you are starting with this tool coming from a diffrent environment ( 8051 C compiler from Keil )

I am sure that they are very easy for someone who knows this development environment. But for a starting idiot like me this is a friggin nightmare.

For the past week i have been trying to get support from Altera on my questions.

The mysupport is no good. I have now 6 open cases. None of them have been answered to my satisfaction. I have been playing ping-pong with them and ave only gotten half answers. I want to move forward.

I have serious 'beginners' problems with the nios development tools.

a simple example:

Make a new C/C++ project.

Add a file called main_program.c with the following code : void main(void) {}

Click build. The builder crashes with some cryptic error. Now what ?

Other questions i have that go unanswered :

- How do i assign a variable to a specific address. ( like the _at_ directive in Keil's C51 )

- How do i write an interrupt handler ? ( in the 8051 world this is easy just write 'interrupt x) after your function header and you are done. the linkers know what to do)

- What is the layout in memory of a progam ? I need to know exactly how a program is stored in RAM and how to put a binary file there. All the solutions given are only half solutions that either don't work or are plain wrong. Solutions like 'you need to make an SREC file' are not solutions. I need to see a step by step example. I don't know these command line tools. It took me a while to find out that this is a motorola S record and i need to use some tool called nios2-elf-objcopy to generate one. I played with the nios2-elf-objcopy a bit but can't get it to work. First it crashed because it couldnt find some DLL ( cygwin-whatever) after finding that and putting it in the same directory it still crashes.

I want a step by step example. Besides, i don't want a motorola format. i need a simple binary file or intel hex file i can load into ram. ( i have access to the nios main SRAM through an avalon master. So i can read 4 bytes from the binary file at a time and store them as 32 bit words. When all is done i bring the nios out of reset and the program should begin executing. ( hopefully ... )

I want to know what the layout of the file is. If i read the first four bytes in the binary file

these should go to the first 32 bit word ( my SRAM is 32 bit wide ) What is the byte layout ?

suppose the file looks like this

0xaa

0xbb

0xcc

0xdd

do i store DDCCBBAA into the first 32 bit word or do is store AABBCCDD into the first 32 bit word ?

On the demo program : I don't need an operating system , i dont need the jtag debugger, i dont need 'printf' ( why is the printf demo 70 kilobyte when compiled ? it should be 25 bytes ... 12 to store the string 'hello world' and a couple of instructions to send them one by one to the uart and wait for the transmit flag to clear. anyway , back tot he point)

i need nothing. The demo program i need is 20 lines of C code ( if i have such a demo i can adapt and extend it to handle the real job i want to run on the nios. i don't expect anyone to write my whole system. I have the system running on an 8051 but want to port to nios so i can do 32 bit arithmetic faster.

All i need is a simple skeleton. I can take it from there.

The program needs to react to 2 hardware interrupts, read data from some memory locations, do some simple calculations ( integer math ) perform a simple decision and write some output to some other memory locations. The compiled machine language program is maybe 30 instructions.

here is the program in pseudo code :

int a _at_ 0x00100000; // in the DPRAM

int b _at_ 0x00100004; // in the DPRAM

int c _at_ 0x00100008; // in the DPRAM

int d _at_ 0x001F0008; // a hardware IO port ( register )

int e _at_ 0x001F0000; // a hardware IO port ( combinatorial block)

void int_1_handler(void) handles interrupt 1

{

c = ((b+1) << 4) +a;

e=1;

}

void int_2_handler(void) handles interrupt 2

{

if c > 0 : c = c -1;

e=1;

}

void main (void)

{ while 1

{

if (d == 1) d = 0 else d =1;

}

}

I have the nio shardwar ealready defined in SOPc builder and it synthesizes

The nios has SRAM from 0000000 to 001FFFFF That is where the program ,stack and all other stuff needs to resides.

0x001F00008 is a hardware io port. ( there is a peripheral mapped there )

Locations 0x001000000 and the others reside in an on board dual port ram. an external system loads data into A and B and triggers either interrupt 1 or 2.

0x001F00008 is also a hardware port. (a custom peripheral. there is no 'memory' there. no flipflops are there, only an address decoder and some combinatorial logic. if a write is detected to bit 0 if that address a block of hardware is triggered that reads memory location 8 in the dual port ram to retrieve the data belonging to variable 'c'.

After posting on various forums someone explained that i can use a define construction like :

# define a (*(volatile unsigned int *) (0x00100000))

# define b (*(volatile unsigned int *) (0x00100004))

etcetera. is this correct ? Will the linker know it needs to stay away form those locations ? Will it know that it can not use those specific addresses to store anything ?

What if i map variables in the main memory ( the main SRAM ) lets say i map something like this :

# define global_q (*(volatile unsigned int *) (0x00004000))

this falls in the middle of the SRAM. will the linker know that this is no-go area and map both program and data around this specific location ?

i have a bunch of variables that need to reside at very specific locations in SRAM because they get written through an avalon master port that can stop the NIOS, change the contents of those locations and let the NIOS resume. For some other storage is use dual port ram so i don't need to stop the nios. ( the nios will be busy in another memory region at that time. that is guaranteed by the way my hardware is built. ) DMA is not an option. i wan ttht nios to do one thing while i load a part of its memory with information for the next thing.

More questions :

How can i see the compiled output as machine language ( ASM opcodes ) (The Keil compiler can show you every single line of 'c' code and the machine language created for it. I would like to see what the compiler does with the code i write.)

Is there ANYONE available who can spend half a day sitting next to me and guide me step by step on how to create a blank project with only an empty main routine and 2 interrupt handlers. I really need to 'see' how it is done.

A big thanks upfront for the brave soul who want to help me. Oh, and it doesn't need to be for free. I am located in San Jose.

desperate ...

14 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks for replying.

    1) ok . i'll try that.

    2) HAL.... that leads me to believe 'operating system' which is not something i want.... ( i also have visions of a faint glowing red eye .. but that may be a figment of my imagination :) ). I read page 8-9 in that ISr document. 485 cycles to enter the interrupt and 222 to clean up? and 10 before it even vectors off ? what is wrong with the world....

    an 8051 takes 4 clockpulses to vector off... and that thing is a 25 year old 8 bit 'toy' ....

    All that the cpu does is push the return vector on the stack and 1 or 2 registers. and off it goes. returning is the reverse. it takes a maximum of 10 cycles to enter and exit. Whats the point of having a 32 bit 500 MHz processor if an 12 MHz 8 bit runs faster... In my application the NIOs will get bombarded with interrupts. ( about 60.000 a second... ) this means i need a minimum of 60.000 x 700 ... 42 MHz just to enter exit the handler.... yikes. my system clock is 48 MHz .... looks like the good people form altera will have some explaining to do here ....

    3) The lack of a method to 'lock' a variable to a specific address would make the compiler for the NIOS the biggest piece of useless junk available. So i can't believe that this does not exist...

    Anyone who does memory mapped IO needs such a construction. My whole system is built around memory mapped IO. Heck, all the systems i have built the last 20 years use memoy mapped io. Whether they used 6802 6809 68000 8051 8096 i960 80166 80188 ARM in all its flavours , MIPS and a number of other processors as their base is irrelevant. All the compilers i have used ( assembly , PL/M , C ) have a provision to do this.

    4) i have no time to read all this stuff. I have a block of code that runs on an 8051 . it needs porting to NIOS so i can speed up the 32 bit arithmetic. The code is very very simple. ( about 1 kilobyte when compiled on an 8051 ) It just needs to be able to handle a couple of interrupts and deal with memory mapped i/o. And those 2 things seem to be a virtual impossibility on the NIOS 'monstrosity'... I have always been told that 'c' is the most portable language in the world .... right. and pigs can fly when the temperature in hell drops below 0 ... anyone has a BASIC compiler for this thing ? it would have been written in 2 minutes...

    5) i have watched that completely.But even that thing assumes to much. I have never used GCC in my life ( right now i am disgusted at that toolchain. Its full of loose ends and very poorly documented. Support is inexisting. All you can do is post your question on the internet and hope someone will answer .. I prefer tools i have to pay lots of money for. At least then i can call someone and yell at them if it does't work ( It may accomplish nothing, but it makes me feel better :) haha ) and they can solve the problem.

    Anyway, thanks for the suggestions.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    1. I have run into the system crash before as well. I find that if you build the project before you *** any files the problem goes away.

    2. NIOS II HAL already has an interrupt handler you can find information on how to use it here (http://www.altera.com/literature/hb/nios2/n2sw_nii52006.pdf).

    3. I don't think you can put a variable at a specfic address (some else may correct me); however, you can put it into a specific memory area.

    example:

    
    alt_u32 foo __attribute__((.section(".sdram"))); // usually a global variable
    

    you can find out which memory areas there are in the system library properties.

    4. Most of your question can be anwered in the nios ii software development handbook (http://www.altera.com/literature/hb/nios2/n2sw_nii5v2.pdf).

    5. Also I suggest you take the time to watch the Altera Demonstrations Course: nios ii integrated development environment (ide) overview (http://www.demosondemand.com/trainingapp/player/index.asp?sessid=alt075&promotion_id=1626&starttime=0), it will help you better understand the NIOS II IDE.

    6. All NIOS II Literature is here (http://www.altera.com/literature/lit-nio2.jsp).

    Hope this will answer your questions.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    yes i should.... unfortunately not.

    I have been playing hide and seek with the NIOs support and altera support for 2 weeks now. I have posted so many mysupport tickets and questions on forums ....
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    You should be able to find a good help related to Nios II questions in the "Nios Forum".

    -BD