这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » MCU » [请教]一段简单的代码

共5条 1/1 1 跳转至

[请教]一段简单的代码

菜鸟
2006-04-20 18:32:11     打赏

/* includes */
#include "vxWorks.h"
#include "sigLib.h"
#include "taskLib.h"
#include "stdio.h"
#include "errnoLib.h"
#include "logLib.h"

/* function prototypes */
void catchSIGINT(int);
void sigCatcher(void);

/* globals */
#define NO_OPTIONS 0
#define ITER1 100
#define LONG_TIME 1000000
#define HIGHPRIORITY 100
#define LOWPRIORITY 101

int ownId;

void sigGenerator(void) /* task to generate the SIGINT signal */
{
int i, j, taskId;
STATUS taskAlive;

if ((taskId = taskSpawn("signal", 100, 0x100, 20000, (FUNCPTR)sigCatcher, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)) == ERROR)
printf("taskSpawn sigCatcher failed\n");

ownId = taskIdSelf(); /* get sigGenerator's task id */

taskDelay(50); /* allow time to get sigCatcher to run */

for (i = 0; i < ITER1; i++)
{
if((taskAlive = taskIdVerify(taskId)) == OK)
{
printf("+++++++++++++++++++++++++++++++SIGINT sinal generated\n");
kill(taskId, SIGINT); /* generate signal */
/* lower sigGenerator priority to allow sigCatcher to run */
taskPrioritySet(ownId, LOWPRIORITY);
}
else
break;
}

printf("\n***************sigGenerator Exited***************\n");
}

void sigCatcher(void) /* task to handle the SIGINT signal */
{
struct sigaction newAction;
int i, j;
newAction.sa_handler = catchSIGINT; /* set the new handler */
sigemptyset(&newAction.sa_mask); /* no other signals blocked */
newAction.sa_flags = NO_OPTIONS; /* no special options */

signal(SIGINT, catchSIGINT);
/* printf("Could not install signal handler\n");*/
for (i = 0; i < ITER1; i++)
{
for (j = 0; j < LONG_TIME; j++)
;
printf("Normal processing in sigCatcher\n");
}

printf("\n+++++++++++++++sigCatcher Exited+++++++++++++++\n");

}

void catchSIGINT(int signal) /* signal handler code */
{
printf("-------------------------------SIGINT signal caught\n");
/* increase sigGenerator priority to allow sigGenerator to run */
taskPrioritySet(ownId, HIGHPRIORITY);
}

运行上述程序,输出结果为:

Normal processing in sigCatcher

… //大量的Normal processing in sigCatcher

Normal processing in sigCatcher

+++++++++++++++sigCatcher Exited+++++++++++++++

想问下,为什么

printf("+++++++++++++++++++++++++++++++SIGINT sinal enerated\n");以及

printf("-------------------------------SIGINT signal caught\n");不会被输出,改为logMsg依然不行。在catchSIGINT下断点发现该函数根本没有被运行,

我想第一个printf没有被运行大概是因为被signal这个任务阻塞了吧,可是程序运行完了也没有输出一次,而且改为logMsg输出也不行,就应该不是被阻塞了吧。(是不是函数不存在阻塞一说-_-!!)

小弟刚开始接触vxworks,望各位DX多多指教!




关键词: 请教     一段     简单     代码     sigCatcher     si    

菜鸟
2006-04-20 19:55:00     打赏
2楼
在你的taskDelay(50)时候,sigCatcher已经运行完了。所以当你判断sigCatcher是否存在,然后再发送signal的时候,就发现sigCatcher已经over了,就不发送signal了。

菜鸟
2006-04-20 20:13:00     打赏
3楼
谢谢斑竹啊,怪不得我在sigCatcher下断点以后就可以正常输出了

菜鸟
2006-04-20 20:29:00     打赏
4楼
能不能再问个问题,当我在sigCatcher和catchSIGINT下全局断点时,并不能阻止函数sigGenerator的运行,和windows编程不同。是不是在vxworks上只能这样,可不可以实现windows编程一样的断点?

菜鸟
2006-04-20 21:25:00     打赏
5楼
vxworks是多线程,你只能中断某个任务。

共5条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]