kingsden
Newbie level 3
i am using a program to run a round robin scheduling as soon as a counter gets to 0;
If i am initially giving the count value as 0 i do not get any prob and the round robin function works......
but when i give the count value as 3 or 4 the taskspawn for the round robin function does nt execute...... pls help me out.....demo pending in 5 hrs....no time
here's the code
#include "vxWorks.h"
#include "logLib.h"
#include "wdLib.h"
#include "sysLib.h"
#include "stdio.h"
#include "taskLib.h"
#include "kernelLib.h"
/* function prototypes */
void taskOne(void);
void taskTwo(void);
void taskThree(void);
void sched(void);
/* globals */
#define ITER1 1
#define ITER2 1
#define PRIORITY 200
#define TIMESLICE sysClkRateGet()
#define LONG_TIME 1000000
static int x,y,z,a=1,b=2,k;
int taskIdOne, taskIdTwo, taskIdThree;
/*******************************************************************************
*
* watchdog - a simple demo routine
*
* This routine sets up a timer and counts down from delay and then
* prints "AaaahhhhhOOOOOOOOO!!" after delay repetitions.
* each repetition is set for 1 less second than the previous.*/
/* this is the watchdog timer */
WDOG_ID myWatchDog;
/* this is the actual function that will be called when the timer times out
It will test to see if it has counted down to zero,
If not, it will reschedule itself for a delay of cnt-1 seconds
*/
int bark(int cnt) {
/* If this is the last invocation */
printf("the value of delay is =%d",cnt);
if(cnt==0)
{
printf("AaaahhhhhOOOOOOOOO!!\n\n");
taskIdOne=taskSpawn("main",PRIORITY,0x300,20000,(FUNCPTR)sched,0,0,0,0,0,0,0,0,0,0);
printf("assf\n\n");
return(0); /* the return is required by vxWorks */
}
/* if we are not down to zero, bark and reschedule */
printf("(%d)Bark!\n",cnt);
/* Reschedule myself, Set Timer to go off in cnt-1 SECONDS */
/* wdStart() initializes the watchdog timer,
myWatchDog is the timer,
sysClockRateGet() * cnt, sets the time to be cnt seconds,
bark is the function to invoke on timeout,
cnt-1 is the parameter to pass to the function.
wdStart returns an error code to indicate success or failure
*/
if (wdStart (myWatchDog, sysClkRateGet( ) * cnt,FUNCPTR(bark),
cnt-2)== ERROR)
/* if the reschedule failed, return the error code */
return (ERROR);
/* else return cnt */
return cnt ;
}
/* this is the main function, it will
display the signon message,
create the watchdog timer,
and call bark for the first time, with delay as the count
*/
int watchdog (int delay) {
printf("WatchDog Starting...\n");
/* Create Watchdog */
if ((myWatchDog = wdCreate( )) == NULL)
return (9999) ; /* error code if creation fails */
printf("delay=%d",delay);
delay= delay+4; //here is the count which i am specifying...to remove the delay jus comment this line
/* Invoke bark which will repeatedly schedule reinvocations of itself */
bark(delay) ;
}
//round robin task is the sched function
void sched(void) /* function to create the three tasks */
{
if(kernelTimeSlice(TIMESLICE) == OK) /* turn round-robin on */
printf("\n\n\n\n\t\t\tTIMESLICE = %d seconds\n\n\n", TIMESLICE/60);
/* spawn the three tasks */
for(k=0;k<10;k++)
{
if((taskIdOne = taskSpawn("task1",PRIORITY,0x100,20000,(FUNCPTR)taskOne,0,0,0,0,0,0,0,
0,0,0)) == ERROR)
printf("taskSpawn taskOne failed\n");
taskDelay(100);
if((taskIdTwo = taskSpawn("task2",PRIORITY,0x100,20000,(FUNCPTR)taskTwo,0,0,0,0,0,0,0,
0,0,0)) == ERROR)
printf("taskSpawn taskTwo failed\n");
taskDelay(100);
if((taskIdThree = taskSpawn("task3",PRIORITY,0x100,20000,(FUNCPTR)taskThree,0,0,0,0,0,0,0,
0,0,0)) == ERROR)
printf("taskSpawn taskThree failed\n");
taskDelay(100);
//extern unsigned sleep(10);
a++;
b++;
}
}
void taskOne(void)
{
int i,j;
for (i=0; i < ITER1; i++)
{
for (j=0; j < ITER2; j++)
printf("task1 is running\n"); /* log messages */
x=a*b;
printf("the value of x is %d\n",x);
for (j=0; j < LONG_TIME; j++); /* allow time for context switch */
}
}
void taskTwo(void)
{
int i,j;
for (i=0; i < ITER1; i++)
{
for (j=0; j < ITER2; j++)
printf("task2 is running\n");
y= x*a;
printf("the value of y is %d\n",y);
for (j=0; j < LONG_TIME; j++); /* allow time for context switch */
}
}
void taskThree(void)
{
int i,j;
for (i=0; i < ITER1; i++)
{
for (j=0; j < ITER2; j++)
printf("task3 is running\n");
z=y*b;
printf("the value of z is %d\n",z);
for (j=0; j < LONG_TIME; j++); /* allow time for context switch */
}
}[/u]
If i am initially giving the count value as 0 i do not get any prob and the round robin function works......
but when i give the count value as 3 or 4 the taskspawn for the round robin function does nt execute...... pls help me out.....demo pending in 5 hrs....no time
here's the code
#include "vxWorks.h"
#include "logLib.h"
#include "wdLib.h"
#include "sysLib.h"
#include "stdio.h"
#include "taskLib.h"
#include "kernelLib.h"
/* function prototypes */
void taskOne(void);
void taskTwo(void);
void taskThree(void);
void sched(void);
/* globals */
#define ITER1 1
#define ITER2 1
#define PRIORITY 200
#define TIMESLICE sysClkRateGet()
#define LONG_TIME 1000000
static int x,y,z,a=1,b=2,k;
int taskIdOne, taskIdTwo, taskIdThree;
/*******************************************************************************
*
* watchdog - a simple demo routine
*
* This routine sets up a timer and counts down from delay and then
* prints "AaaahhhhhOOOOOOOOO!!" after delay repetitions.
* each repetition is set for 1 less second than the previous.*/
/* this is the watchdog timer */
WDOG_ID myWatchDog;
/* this is the actual function that will be called when the timer times out
It will test to see if it has counted down to zero,
If not, it will reschedule itself for a delay of cnt-1 seconds
*/
int bark(int cnt) {
/* If this is the last invocation */
printf("the value of delay is =%d",cnt);
if(cnt==0)
{
printf("AaaahhhhhOOOOOOOOO!!\n\n");
taskIdOne=taskSpawn("main",PRIORITY,0x300,20000,(FUNCPTR)sched,0,0,0,0,0,0,0,0,0,0);
printf("assf\n\n");
return(0); /* the return is required by vxWorks */
}
/* if we are not down to zero, bark and reschedule */
printf("(%d)Bark!\n",cnt);
/* Reschedule myself, Set Timer to go off in cnt-1 SECONDS */
/* wdStart() initializes the watchdog timer,
myWatchDog is the timer,
sysClockRateGet() * cnt, sets the time to be cnt seconds,
bark is the function to invoke on timeout,
cnt-1 is the parameter to pass to the function.
wdStart returns an error code to indicate success or failure
*/
if (wdStart (myWatchDog, sysClkRateGet( ) * cnt,FUNCPTR(bark),
cnt-2)== ERROR)
/* if the reschedule failed, return the error code */
return (ERROR);
/* else return cnt */
return cnt ;
}
/* this is the main function, it will
display the signon message,
create the watchdog timer,
and call bark for the first time, with delay as the count
*/
int watchdog (int delay) {
printf("WatchDog Starting...\n");
/* Create Watchdog */
if ((myWatchDog = wdCreate( )) == NULL)
return (9999) ; /* error code if creation fails */
printf("delay=%d",delay);
delay= delay+4; //here is the count which i am specifying...to remove the delay jus comment this line
/* Invoke bark which will repeatedly schedule reinvocations of itself */
bark(delay) ;
}
//round robin task is the sched function
void sched(void) /* function to create the three tasks */
{
if(kernelTimeSlice(TIMESLICE) == OK) /* turn round-robin on */
printf("\n\n\n\n\t\t\tTIMESLICE = %d seconds\n\n\n", TIMESLICE/60);
/* spawn the three tasks */
for(k=0;k<10;k++)
{
if((taskIdOne = taskSpawn("task1",PRIORITY,0x100,20000,(FUNCPTR)taskOne,0,0,0,0,0,0,0,
0,0,0)) == ERROR)
printf("taskSpawn taskOne failed\n");
taskDelay(100);
if((taskIdTwo = taskSpawn("task2",PRIORITY,0x100,20000,(FUNCPTR)taskTwo,0,0,0,0,0,0,0,
0,0,0)) == ERROR)
printf("taskSpawn taskTwo failed\n");
taskDelay(100);
if((taskIdThree = taskSpawn("task3",PRIORITY,0x100,20000,(FUNCPTR)taskThree,0,0,0,0,0,0,0,
0,0,0)) == ERROR)
printf("taskSpawn taskThree failed\n");
taskDelay(100);
//extern unsigned sleep(10);
a++;
b++;
}
}
void taskOne(void)
{
int i,j;
for (i=0; i < ITER1; i++)
{
for (j=0; j < ITER2; j++)
printf("task1 is running\n"); /* log messages */
x=a*b;
printf("the value of x is %d\n",x);
for (j=0; j < LONG_TIME; j++); /* allow time for context switch */
}
}
void taskTwo(void)
{
int i,j;
for (i=0; i < ITER1; i++)
{
for (j=0; j < ITER2; j++)
printf("task2 is running\n");
y= x*a;
printf("the value of y is %d\n",y);
for (j=0; j < LONG_TIME; j++); /* allow time for context switch */
}
}
void taskThree(void)
{
int i,j;
for (i=0; i < ITER1; i++)
{
for (j=0; j < ITER2; j++)
printf("task3 is running\n");
z=y*b;
printf("the value of z is %d\n",z);
for (j=0; j < LONG_TIME; j++); /* allow time for context switch */
}
}[/u]