我正在尝试将 printf 数据发送到我的uart
设备。我已经适当地编写了 write_r() 函数。
我遇到的问题是,
- 当我说
printf(" My name is sam \n I am fine ");
- 下次我说
printf(" I am back ");
第一个问题:我只能看到"My name is Sam",然后光标转到下一行并停在那里。
第二个问题:“我回来了”根本没有打印出来。
我尝试删除\n
,仍然printf
没有打印第二个。没有任何问题uart
。
看起来然后\
到达指针丢失了。
我的代码
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;
}