#include <fcntl.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <ioctl.h>
#include <apbuart.h>
#include <rtems.h>
#include <drvmgr/drvmgr.h>
#include <unistd.h>
#define size 1024
#define APBUART_databits 8
int writetoport(int fd, char *b, size_t count)
{
if(!write(fd, &b[0], sizeof(count)))
{
//printLastError();
return -1;
}
return 1;
}
int main()
{
char a[size] = {'h','e','l','l','o'};
int fd;
fd = open("/dev/apbuart2", O_WRONLY );
ioctl(fd, APBUART_SET_BAUDRATE, 9600);
ioctl(fd, APBUART_START, NULL);
ioctl(fd, APBUART_STOP, 1);
ioctl(fd, APBUART_databits, 8);
writetoport(fd, &a[size], sizeof(a));
return 0;
}
我正在研究 Aeroflex Gaisler(带有 leon2 处理器的 RTEMS)。尝试通过 UART 接口(interface)发送字符。但是我无法发送角色。下面是代码行。
#include <fcntl.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <ioctl.h>
#include <apbuart.h>
#include <rtems.h>
#include <drvmgr/drvmgr.h>
#include <unistd.h>
#define size 1024
#define APBUART_databits 8
int writetoport(int fd, char *b, size_t count)
{
if(!write(fd, &b[0], sizeof(count)))
{
//printLastError();
return -1;
}
return 1;
}
int main()
{
char a[size] = {'h','e','l','l','o'};
int fd;
fd = open("/dev/apbuart2", O_WRONLY );
ioctl(fd, APBUART_SET_BAUDRATE, 9600);
ioctl(fd, APBUART_START, NULL);
ioctl(fd, APBUART_STOP, 1);
ioctl(fd, APBUART_databits, 8);
writetoport(fd, &a[size], sizeof(a));
return 0;
}
我根据回复更改了我的代码,但仍然无法正常工作。
最佳答案
您的代码看起来是递归的,我所期望的只是缓冲区溢出。
write()
中的代码也很奇怪,局部参数的地址不是很有趣,重新计算大小只是局部参数的大小来电者的尺寸,那不可能是对的。
如果这个系统运行一个内核并且有一个类似 POSIX 的库,我不确定你为什么要重新实现 write()
。
关于c - Aeroflex gaisler(带 leon2 处理器的 RTEMS)无法通过 UART 接口(interface)发送字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16980886/