Showing results for 
Search instead for 
Did you mean: 
Honored Contributor I

Control NIOS II program from "NIOS II Console" (without HAL functions)



I'm trying to implement control of NIOS II program from nios ii console

Here is snippet of code: 


void sw_get_command(cmd_type *cmd) { alt_u8 btn; btn = (alt_u8) btn_read(BTN_BASE) & 0xf; // read 4 pushbuttons if (btn != 0) { // a button pressed if (btn & 0x01) // button 0 pressed cmd->pause = cmd->pause ^ 1; // toggle pause bit if (btn & 0x02) // button 1 pressed cmd->prd = pio_read(SWITCH_BASE) & 0x03ff; // load new interval if (btn & 0x04) { alt_u8 rvalid = 0; alt_u32 data_reg = 0; do{ data_reg = IORD(JTAG_UART_BASE, JUART_DATA_REG_OFT); rvalid = data_reg >> 15 & 0x01; } while (rvalid == 0); printf("data = %c\n", (char)data_reg & 0xff); printf("ravail = %d\n", (data_reg >> 16) & 0xffff); } btn_clear(BTN_BASE); } }  


The sw_get_command is called from while(1) loop. 

If button 2 is pressed (condition btn & 0x04), user is invited to type some value in NIOS II Console. 

The value can have multiple symbols. 

I'm faced to problem how to read all symbols. Actually when I read a symbol (in the command data_reg = iord(jtag_uart_base, juart_data_reg_oft)), it seems that read fifo is erased. 

Otherwise how to explain that after leaving the do-while loop, the value of ravail (number of characters remaining in the read fifo) is 0 (1st image - screenshot of NIOS II console). 

Another question: after some "exercises" with button 2, the communication crashes and Eclipse becomes unavailable (2nd screenshot - fragment of Windows Task Manager screenshot). 


Thanks in advance.
0 Kudos
0 Replies