大虾帮忙看看下面的程序,(《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";*/
}
有奖活动 | |
---|---|
【有奖活动——B站互动赢积分】活动开启啦! | |
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |