Forum Discussion
Program runs in loop
I have written a program that writes to the user through nios 2 console (jtag uart) and takes user input as well. However, the program does not pause to accept user input. Instead it continues to run the main in a loop. Is there a way to get the console to pause and wait for user input as it does in local console applications.
If code is needed I will be happy to post. Thank you for any help5 Replies
- Altera_Forum
Honored Contributor
Any blocking input call should work. Try getline or getc.
Jake - Altera_Forum
Honored Contributor
Do these functions work with only small c library? I have limited memory resources for the system. I chose not to support c++ in the BSP options
- Altera_Forum
Honored Contributor
Ahhh, if you're using the small C library, you're going to have to get trickier.
If I remember right, you may may be able to use the regular "read()" function which I think will block. You may also want to access the UART driver directly ...
Jakedata = IORD_ALTERA_AVALON_JTAG_UART_DATA(JTAG_UART_0_BASE); if(data & ALTERA_AVALON_JTAG_UART_DATA_RVALID_MSK){ // If you're here you've got data to read. data = data & ALTERA_AVALON_JTAG_UART_DATA_DATA_MSK; }else{ // No data try again } - Altera_Forum
Honored Contributor
Yes i tried using the read() function which doesnt seem to pause. I will try accessing the UART directly but if you could explain a little why those masks are used in the code snippet I think I could better understand where exactly to access the UART in my code.
Thank you for your help. Chase - Altera_Forum
Honored Contributor
You can read the user's guide for the JTAG UART to gain a better understanding:
http://www.altera.com/literature/ug/ug_embedded_ip.pdf The masks are simply bits masks for analyzing the data read from the UART register. Jake