Nios/uartread
From ASMBits
nios/memmovePrevious
Nextnios/cacheblock
Write a function to read a string (terminated with character '\n', or 0x0d) from a UART device and writes that string into memory. You will need to poll the UART device to read each character as it becomes available. Replace the \n character with a null character in the output string. Return the length of the string.
unsigned int uartgets (char *output);
You are provided a function to read the status of the UART:
unsigned int read_uart();
The 32-bit word includes information about the state of the UART and the received character, if available:
- bit [15]: 1 if the character in bits [7:0] is valid. If valid, the character is also dequeued from the UART so that the next read will return the next character, if available. If not valid, bits [7:0] in the word are undefined. You need to poll the device to read each character in the string.
- bits [7:0]: The character received from the UART, if there was a character available.
To make this problem easier, read_uart only clobbers r2 (the return value) (and ra, of course).
Expected solution length: Around 20 lines.
Sample Input
"Hello world"
Sample Output
r2=11
nios/memmovePrevious
Nextnios/cacheblock