driver to read a string on data over a uart in c using register map [duplicate]


I'm trying to write a driver to send and recieve a string over a UART (implimented on a fpga). Here is a picture of the register map for the UART. enter image description here I have been able to write a function to send a string. It checks the transmit read bit (trdy) in the status register and if it is set it then puts the data into the txdata register.

#define UART_BASE 0x00021000

int putstring(char *str) {

    volatile uint32_t *uart = (volatile uint32_t*) UART_BASE;

    while (1)
    {
        while (*str != '\0')
        {
            while ((uart[2] & (1<<6)) == 0);
             uart[1] = *str;
             str++;
          }
       }
}

My question is that I'm trying to now a read a string but I'm struggling with the logic. I want it to keep reading characters until the user hits Enter. This is for a menu.

I was wondering if somebody could advise?

void getstring(char *str) {

volatile uint32_t *uart = (volatile uint32_t*) UART_BASE;

char c = 0;
do
{
    while ((uart[2] & (1<<5)) == 0);
    c = uart[0];
    *str++ = c;
}
while (c!='\0');


}

This is my main function. It outputs the word "test" to the console. Then I was expecting to enter a b Ctrl - @ and then I was expecting it to display ab on the console but it doesn't work.

Am I doing something stupid wrong?

Thanks

int main(void)
{
    char output[] = "Test";
    char input[2];

    putstring(output);

    getstring(input);

    putstring(input);

    return 0;
}

Answers:


This should read the string to str; till the symbol '\0' received.

char c = 0;
do
{
      while ((uart[2] & (1<<5)) == 0);
         c = uart[0];
         *str++ = c;
} while (c!='\0');