驅動程式 - VxWorks - 使用範例 - C/C++ - Create Pipe



參考資訊:
https://zhuanlan.zhihu.com/p/597577575
https://studies.ac.upc.edu/doctorat/ENGRAP/VxWorks-device-drivers.htm
https://forums.windriver.com/t/vxworks-software-development-kit-sdk/43
https://mail.prz-rzeszow.pl/~ssamolej/vxworks/vxworks_kernel_programmers_guide_6.6.pdf
https://d13321s3lxgewa.cloudfront.net/downloads/wrsdk-vxworks7-docs/2309/README_qemu.html
https://learning.windriver.com/path/vxworks7-essentials-workbench-and-tools/vxworks-kernel-shell
https://www.ee.torontomu.ca/~courses/ee8205/Data-Sheets/Tornado-VxWorks/vxworks/ref/pipeDrv.html#pipeDevCreate

main.c

#include <sysLib.h>
#include <pipeDrv.h>

int create_pipe(void)
{
    pipeDrv(10);
    pipeDevCreate("/pipe/hello", 10, 100);
    return OK;
}

app.c

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

int main(int argc, char **argv)
{
    char buf[100] = {0};
    int fd = open("/pipe/hello", O_RDWR);

    if (fd > 0){
        buf[0] = 0x12;
        buf[1] = 0x34;
        write(fd, buf, sizeof(buf));

        memset(buf, 0, sizeof(buf));
        read(fd, buf, sizeof(buf));

        printf("Read 0x%x, 0x%x\n", buf[0], buf[1]);
        close(fd);
    }
    return 0;
}

編譯

$ wr-cc app.c -o app
$ wr-cc main.c -o main -dkm

執行

-> ld < main

-> create_pipe

-> devs
    drv refs name
      4 [ 5] /pipe/hello

-> cmd

[vxWorks *]# app
    Read 0x12, 0x34

[vxWorks *]# C

-> unld "main"