【解析新特性】300W单路输出工业电源>>
电子产品世界 » 论坛首页 » 嵌入式开发 » MCU » 大家一起过来瞧瞧这个定时器,看门狗程序

共2条 1/1 1 跳转至

大家一起过来瞧瞧这个定时器,看门狗程序

菜鸟
2004-08-15 19:14:00    评分
大虾帮忙看看下面的程序,(《vxworks高级程序员设计》-李方敏p80-82)在sim里运行,编译没错,下载出错,下面时错误提示 Errors while downloading C:/Tornado/target/proj/Project0/SIMNTgnu/Project0.out:
_timer_settime
_timer_delete
_timer_create 不管下载错误提示,在shell中敲sp timer_demo后回车,如下 -> sp timer_demo
task spawned: id = 11792b8, name = s1u0
value = 18322104 = 0x11792b8
-> sp timer_demo
task spawned: id = 1171140, name = s1u1
value = 18288960 = 0x1171140
-> sp timer_demo
task spawned: id = 1168fc8, name = s1u2
value = 18255816 = 0x1168fc8
-> sp timer_demo
task spawned: id = 1160e50, name = s1u3
value = 18222672 = 0x1160e50
->
Exception number 0: Task: 0x1160e50 (s1u3) General Protection Fault
Program Counter: 0x00000000
Status Register: 0x00010202 此时vxsim0中的输出如下: urrent time: fffffff0 s 0 ns
current time: fffffff0 s 0 ns
current time: fffffff0 s 0 ns
current time: fffffff0 s 0 ns
current time: fffffff0 s 0 ns
current time: fffffff0 s 0 ns
current time: fffffff0 s 0 ns
Exception !
Vector 13 : General Protection Fault
Program Counter : 0x00000000
Status Register : 0x00010202
^C 程序代码: #include "vxWorks.h"
#include "semLib.h"
#include "time.h"
#include "signal.h"
#include "errno.h"
/*#include "iostream.h"*/
#define TIMER_SIG SIGALRM
#define TEST_NUM 8
#define FATAL_ERROR(s){\
printf("%s [errno: 0x%x]\n", s, errno);\
taskSuspend(0);\
}
SEM_ID semaphore;
void timer_handler (int signo, siginfo_t * pInfo, void *pContext); void show_time (void); void timer_demo() /*Ö÷º¯Êý*/
{ struct itimerspec itmsp;
struct sigevent tmevent;
timer_t tm;
struct sigaction tmact;
int i; struct timespec tp; tp.tv_sec=0xfffffff0;
tp.tv_nsec=0;
clock_settime(0, &tp);
show_time();
if ((semaphore=semCCreate(SEM_Q_FIFO,0))==0)
FATAL_ERROR("create semaphore failed")
sigemptyset (&tmact.sa_mask);
tmact.sa_u.__sa_sigaction=timer_handler;
tmact.sa_flags=SA_SIGINFO;
sigaction (TIMER_SIG,&tmact, NULL);
tmevent.sigev_signo=TIMER_SIG;
tmevent.sigev_value.sival_int=(int)&tm;
tmevent.sigev_notify=SIGEV_SIGNAL;
if(timer_create (CLOCK_REALTIME, &tmevent, &tm) != 0) /************************/
FATAL_ERROR("create timer failed") itmsp.it_value.tv_sec=6;
itmsp.it_value.tv_nsec=123;
itmsp.it_interval.tv_sec=2;
itmsp.it_interval.tv_nsec=123;
timer_settime (tm, TIMER_ABSTIME+1, &itmsp, NULL); /************************/

show_time(); for (i=0; i<TEST_NUM; i++)
{
if (semTake(semaphore, WAIT_FOREVER)==-1)
FATAL_ERROR("error wait for semaphore")
show_time();
}
semDelete (semaphore);
timer_delete (tm); /************************/
} void timer_handler (int signo, siginfo_t *pInfo, void * pContext)
{
static test_num=0;
timer_t *tm=(timer_t *)pInfo->si_value.sival_int;
struct itimerspec itmsp; if (++test_num >= TEST_NUM)
{ itmsp.it_value.tv_sec=0;
itmsp.it_value.tv_nsec=0;
timer_settime (*tm, TIMER_ABSTIME+1, &itmsp, NULL); /*************************/
}
semGive(semaphore);
}
void show_time()
{
struct timespec tp;
clock_gettime(0, &tp);
printf ("current time: %x s %x ns\n", tp.tv_sec, tp.tv_nsec);
/* cout<<"hello";*/
}



关键词: 大家     一起     过来     瞧瞧     这个     定时器     看门狗     程序    

菜鸟
2004-08-16 22:17:00    评分
2楼
假定程序没有问题,你可以下载到目标机(不是仿真器)上试试。 [align=right][color=#000066][此贴子已经被作者于2004-8-16 14:18:47编辑过][/color][/align]

共2条 1/1 1 跳转至

回复

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