📄 downdemo.c
字号:
/* tdemo.c - demonstration program */
#include "vxWorks.h"
#include "stdio.h"
#include "stdlib.h"
#include "msgQLib.h"
#include "taskLib.h"
#include "math.h"
#define PI (3.1416)
#define WAIT_TIME 10
#define MSG_TIME_OUT 20
float angle, sineVal, *nxtval, outputVal, val = 0;
MSG_Q_ID dataQId;
int tidProducer;
int tidConsumer;
int tDemoPrintFlag = 0;
int consumer();
int producer();
/*
* tDemoStart() - start tdemo
*/
int k=0;
void demoPrint(void){
logMsg("\nThis is demoPrint\n");
}
int tDemoStart(int count)
{
/* Initialize Message Queue (dataQId) */
dataQId = msgQCreate(4, sizeof(float *), MSG_Q_PRIORITY);
/* Spawn Producer Task */
tidProducer = taskSpawn("tProducer", 80, 0, 2000, (FUNCPTR)producer,
0,0,0,0,0,0,0,0,0,0);
/* Spawn Consumer Task */
tidConsumer = taskSpawn("tConsumer", 70, 0, 2000, (FUNCPTR)consumer,
0,0,0,0,0,0,0,0,0,0);
return (OK);
}
/*
* producer() - producer task
*/
int producer (void)
{
register int i = 0;
float *buf;
while(1) {
/* Allocate Data Buffer */
buf=malloc(10);
if (i++ < 50)
angle = (float)((2 * PI) * (i / 50.0));
else
angle = (float)(i = 0);
/* Generate Sine Wave Data */
*buf = sineVal = sin((double)angle);
/* Send Pointer to Data through Message Queue */
if (msgQSend(dataQId, (char *)&buf, sizeof(float *),
10, MSG_PRI_NORMAL) != OK)
printf("tProducer: msgQSend error\n");
/*free(buf);*/
taskDelay(WAIT_TIME); /* wait a few milliseconds */
}
}
/*
* consumer() - consumer task
*/
int consumer(void)
{
while(1){
/* Read Message Queue */
tDemoPrintFlag = msgQReceive(dataQId, (char *)&nxtval, sizeof(float *),
MSG_TIME_OUT);
if (tDemoPrintFlag!=ERROR){
printf("Consumer: received a message!! (val=%f)\n", val);
printf("k=%d\n",k);
}
else printf("Msg time out!\n");
/* Condition Data */
outputVal = (val * 0.85);
/* Save Data */
val = *nxtval;
}
}
/*
* tDemoStop() - Stop tdemo
*/
STATUS tDemoStop()
{
/* delete tasks */
taskDelete (tidProducer);
taskDelay(WAIT_TIME); /* just to make sure producer is done producing */
taskDelete (tidConsumer);
return(OK);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -