驅動程式 - VxWorks - 23.09 - C/C++ - Watchdog



參考資訊:
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

main.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iosLib.h>
#include <vxWorks.h>
#include <sysLib.h>
#include <wdLib.h>

#define SEC 1

static int val = 0;
static WDOG_ID wid = NULL;

int wdg_handler(void *param)
{
    val += 1;
    wdStart(wid, sysClkRateGet() * SEC, wdg_handler, 0);
    return OK;
}

int start_dkm(void)
{
    wid = wdCreate();
    wdStart(wid, sysClkRateGet() * SEC, wdg_handler, 0);
    return OK;
}

int get_val(void)
{
    printf("%d\n", val);
    return OK;
}

int stop_dkm(void)
{
    wdCancel(wid);
    return OK;
}

編譯

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

執行

-> ld < main

-> start_dkm

-> get_val
4

-> get_val
8

-> stop_dkm

-> get_val
12

-> get_val
12

-> unld "main"