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++
12596 Discussions

Is it possible to pass arguments to the main() function in NIOS II SBT

Altera_Forum
Honored Contributor II
1,223 Views

Hello, 

 

Just a generic question. I am using the NIOS II SBT eclipse for an application code and I would like to pass some values to the main() function. 

The syntax for a C program main() function is like: 

int main(int argc, char * argv[]) 

 

So can I pass the parameters from the NIOS II SBT or from the NIOS II command shell ? ( i am just a beginner in those two) 

Any inputs will be appreciated. 

 

 

Thank You, 

Akhil
0 Kudos
6 Replies
Altera_Forum
Honored Contributor II
474 Views

You need to ask yourself where any such parameters would actually come from in a 'real' system. 

Remember this is all code that is expected to be loaded at 'boot' time onto an fpga. 

 

IMHO Altera have added far too much code to give standalone programs what appears to be a POSIX (Unix-like) execution environment. 

This is also responsible for the 'hello world' program being 60+k, not a few 100 bytes.
0 Kudos
Altera_Forum
Honored Contributor II
474 Views

Hello dsl, 

 

Thank you for the reply! 

 

 

--- Quote Start ---  

You need to ask yourself where any such parameters would actually come from in a 'real' system. 

Remember this is all code that is expected to be loaded at 'boot' time onto an fpga. 

--- Quote End ---  

 

Akhil>> Yeah even I have the same thoughts on a real embedded system, where the application code may not need to accept 

any parameters. I am having a software RSA algorithm running on an FPGA board (just to capture the timings). So was just curious about the data which has to be encrypted and that has to be sent to the application code. Never mind, I can generate the data inside the application code itself, it is not a biggy. Thanks! 

 

 

--- Quote Start ---  

IMHO Altera have added far too much code to give standalone programs what appears to be a POSIX (Unix-like) execution environment. 

This is also responsible for the 'hello world' program being 60+k, not a few 100 bytes. 

--- Quote End ---  

 

Akhil>> I agree and I am thankful to Altera for supporting the application layer programs like C/C++. It makes the execution environment looks more neat, atleast for me. 

 

 

Best, 

Akhil
0 Kudos
Altera_Forum
Honored Contributor II
474 Views

Hi Akhil 

You can simply use jtag uart with nios-terminal to pass variable data to the application, besides showing the result, like common stdin/stdout devices
0 Kudos
Altera_Forum
Honored Contributor II
474 Views

 

--- Quote Start ---  

 

So can I pass the parameters from the NIOS II SBT or from the NIOS II command shell ? ( i am just a beginner in those two) 

 

--- Quote End ---  

 

 

No, you can't. 

 

main() is invoked by the Altera HAL wrapper "alt_main()" and it initializes argv[] with NULL and argc with zero. 

In your BSP folder, see ./HAL/src/alt_main.c They leave the door open for other software to set it to non-NULL, but it is kind of a dead-end. 

 

In addition to using stdin/stdout, if you include the altera_hostfs BSP component you can also fopen/fread/fwrite files on your PC hard drive (to take commands/arguments from, or to initialize your sample data tables in RAM, etc. etc. etc)
0 Kudos
Altera_Forum
Honored Contributor II
474 Views

Hello Ted, 

 

Thank you for the reply and pointing out the way to use file handling operations using the altera_hostfs BSP component! 

 

Regards, 

Akhil
0 Kudos
Altera_Forum
Honored Contributor II
474 Views

Hello, 

 

Just a generic question about QSYS. I am a new bie to qsys (had used SOPC before) and I had been connecting the components together in the qsys builder. 

I clicked on each component in the Component Library and added to the system. One thing I have noticed is, unlike SOPC, the qsys do not automatically create the 

connections for the added components. I had to manually connect all the components as per my requirements in the 'Connections' tab under System Contents. 

 

So is this a feature in qsys or do I get to assign the qsys builder to make connections automatically (so that I may not have to manually connect every time) ? 

 

Thank You, 

Akhil
0 Kudos
Reply