gpt4 book ai didi

c - Aeroflex gaisler(带 leon2 处理器的 RTEMS)无法通过 UART 接口(interface)发送字符

转载 作者:太空宇宙 更新时间:2023-11-04 03:55:16 25 4
gpt4 key购买 nike

#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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com