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

标签 c string pointers serial-port embedded

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

相关文章:

c++ - 将迭代器取消引用到指针

c - 如何生成 [0,1] 之间具有 3 个分数的随机数

c - 编译 gcc-2.7.2.3 时出错

c - 您能想到的为计算机游戏制定简单音频均衡器的最简单方法是什么?

c - 使用 "\x"十六进制字符转义的字符串连接

python - 如何将文件名从文件夹提取到变量而不是列表?

c - 函数返回类型作为指针为什么不作为 int ,同时返回变量的地址

c - 对字符串进行最大和最小排序

python - 无法连接 'str' 和 'float' 对象?

pointers - 检查Ada中的空指针