📄 vxworks 借助看门狗实现中断处理.txt
字号:
/*head file*/
#include "vxworks.h"
#include "logLib.h"
#include "taskLib.h"
#include "wdLib.h"
#include "stdio.h"
#include "sysLib.h"
#include "ioLib.h"
#include "string.h"
/*macro declare*/
#define DELAY_SECONDS 1/*延迟1秒*/
#define STACK_SIZE 20000
/*varible*/
WDOG_ID wdogid;/*看门狗ID*/
int tidReceive;/*Task ID*/
int tidPrint;
int delay_sec;/*延迟时间*/
int clk_rate;
SEM_ID synchron;/*同步信号量*/
char string[20];/*存放输入数据*/
/*func declare*/
void watchdog_service();/*中断服务程序*/
void watchdog_routine();/*延时程序*/
void progStart();
void taskReceive();
void taskPrint();/*打印程序*/
void progStop();
/**********/
void progStart()
{
synchron = semBCreate(SEM_Q_FIFO, SEM_EMPTY);
tidPrint = taskSpawn("tPrint", 220, 0, STACK_SIZE, (FUNCPTR)taskPrint, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
tidReceive = taskSpawn("tReceive", 200, 0, STACK_SIZE, (FUNCPTR)taskReceive, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
if((wdogid=wdCreate())==NULL)
{
printf("create watchdog fail\n");
}
return;
}
void taskReceive()
{
while(1)
{
int i = 0;
char rr[20];
read(STD_IN,rr,20);
for(;i<20;i++)
{
string[i] = '\0';
}
strcpy(string,rr);
/*看门狗将引发中断*/
clk_rate=sysClkRateGet();
delay_sec=clk_rate*DELAY_SECONDS;
wdStart(wdogid,delay_sec,(FUNCPTR)watchdog_service,0);
watchdog_routine();
/*释放信号量*/
semGive(synchron);
taskDelay(10);
}
return;
}
void watchdog_routine()
{
int i = 0;
for(;i<2;i++)
{
taskDelay(clk_rate);
}
return;
}
void watchdog_service()
{
int m = strlen(string)-1;
int n = 0;
logMsg("\nthis message is sent by wdogtimer!\n",0,0,0,0,0,0);
for(;n<m;n++)
{
string[n] -= ('a'-'A');
}
return;
}
void taskPrint()
{
while(1)
{
semTake(synchron,WAIT_FOREVER);
int l = 0;
while(string[l])
{
printf("%c",string[l++]);
}
}
return;
}
void progStop()
{
taskDelete(tidReceive);
taskDelete(tidPrint);
semDelete(synchron);
printf("The End \n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -