I am trying to send printf data to my uart
device.
I have suitablely written write_r() funciton.
The problems that I am having is,
printf(" My name is sam \n I am fine ");
printf(" I am back ");
1st problem : I can see only "My name is Sam", then the cursor goes to next line and stops there.
2nd problem : "I am back" is not getting printed at all.
I tried by removing \n
, still the 2nd printf
doesn't get printed.
There is nothing wrong with the uart
.
Looks like then \
is reached the pointer is lost.
My Code
int write(int file, char *ptr, int len) {
#if !defined( OUT_8 )
#define OUT_8(p,d) (*(volatile char *)(p) = (char)(d))
#endif
#if !defined( IN_8 )
#define IN_8(p) ((*(volatile char *)(p)))
#endif
OUT_8(DUART1_UMCR1, 0x02); //Informs external modem or peripheral that the UART is ready for sending data
OUT_8(DUART1_ULCR1, 0x03);
OUT_8(DUART1_UIER1, 0x0f);
OUT_8(DUART1_UFCR1, 0x8f);
OUT_8(DUART1_UTHR, '\n');
OUT_8(DUART1_UTHR, '\r');
while (ptr!=NULL)
{
if (*ptr=='\n') // JUST A TRY to avoid \n bug
{
OUT_8(DUART1_UTHR, '\n');
wait();
*ptr++;
*ptr++;
OUT_8(DUART1_UTHR, *ptr++); // \n & \r when given through printf isNot working
wait();
}
OUT_8(DUART1_UTHR, *ptr++); // \n & \r when given through printf is not working
wait(); // TODO:
if(len==0)
break;
else
len--;
}
OUT_8(DUART1_UMCR1, 0x00); // say that modem is not not ready. Connection over
OUT_8(DUART1_UFCR1, 0x87);
OUT_8(DUART1_ULCR1, 0x00); // Clear all the interrupts ! virtually shut the UART port
errno = ENOSYS;
return -1;
}
Confident that OP's I/O is buffered somewhere.
Output does not appear until a \r
and/or \n
is sent.
#if !defined( OUT_8 )
#define OUT_8(p,d) (*(volatile char *)(p) = (char)(d))
#endif
// make ptr a `const char *`
int write(int file, const char *ptr, int len) {
OUT_8(DUART1_UMCR1, 0x02); //Informs UART is ready for sending data
OUT_8(DUART1_ULCR1, 0x03);
OUT_8(DUART1_UIER1, 0x0f);
OUT_8(DUART1_UFCR1, 0x8f);
while (len-- > 0) {
OUT_8(DUART1_UTHR, *ptr++);
wait();
}
// Force an EOL at the _end_ of transmission.
OUT_8(DUART1_UTHR, '\n');
OUT_8(DUART1_UTHR, '\r');
wait();
OUT_8(DUART1_UMCR1, 0x00); // say that modem is not not ready. Connection over
OUT_8(DUART1_UFCR1, 0x87);
OUT_8(DUART1_ULCR1, 0x00); // Clear all interrupts! virtually shut UART port
errno = ENOSYS;
return -1;
}
I suspect that the buffering is occurring in the receiving side, either the UART or more likely in the terminal viewing the data. OP said "the curser goes to next line". There is no "cursor" in a UART.