Hello there,

as far as embedded programming goes I am a complete noob and have only just recently got to (slight) grips with C. I have been working on a uni project for a double conveyor box sorting problem, but have come across a error that i cannot understand or get around. Unfortunately i do not have the error as i am not on vxworks at home. but below is my code if anyone would be kind enough to have a peruse over.

VMT

Daz

------------------------------------------------
/*reading the sensors*/

#include "cinterface.h"
#include <vxWorks.h>
#include <sysLib.h>
#include <taskLib.h>
#include <stdio.h>
#include <stdlib.h>
#include <semLib.h>


SEM_ID sensorSEM; /*stores semaphore ID*/
SEM_ID closegate0;
SEM_ID closegate1;
WDOG_ID timerBelt; /* Timer ID */
WDOG_ID timerRead; /* Timer ID */

void semaphoregate(void) {
/* Set the flag */
semGive(closegate0);
}


void closegatezero(void)
{
while(1){
printf("Task2: Waiting for semaphore!\n");
semTake(closegate0, WAIT_FOREVER);
printf("Task2: took the semaphore!\n");
setGates(1);
}
}

void Sensor(void)
{
char state0; /* reading size sensors*/
char state1;
int res;
timerBelt = wdCreate(); /* Create the watchdog timer */
closegate0=semBCreate(SEM_Q_FIFO, SEM_EMPTY);
closegate1=semBCreate(SEM_Q_FIFO, SEM_EMPTY);
sensorSEM=semBCreate(SEM_Q_FIFO, SEM_EMPTY);
while (1)
{
printf("Task2: Waiting for semaphore!\n");
semTake(sensorSEM, WAIT_FOREVER);
printf("Task2: took the semaphore!\n");
state0 = readSizeSensors (0);
state1 = readSizeSensors (1);
printf("Value for conveyor0 is: %i\n", state0); /*print current reading of sensor*/
printf("Value for conveyor1 is: %i\n", state1); /*print current reading of sensor*/

if (state0 == 1) /* if block in front of first or second sensor */
{puts ("Block at sensor 1, waiting for sensor 2");}
else if (state0 == 3) /* if block in front of first or second sensor */
{puts ("Long Block!");
break;}
else if (state0 == 2) /* if block in front of both sensors*/
{puts ("Little Block!");
res = wdStart(timerBelt, 3 * sysClkRateGet(), (FUNCPTR)semaphoregate, 0);
resetSizeSensors(0); /* reset size sensor so lagging edge of block isnt seen as small block*/
break;}/*close gate 1 open gate 0 to allow big block to pass*/

else /*else keep both gates ope*/
{puts ("No Block!");

}
}
}

void sensorsem (void)
{
sensorSEM=semBCreate(SEM_Q_FIFO, SEM_EMPTY);
semGive(sensorSEM);
}
void main(void)
{
int taskSensor;
int taskGates;
int res1;
timerRead = wdCreate(); /* Create the watchdog timer */
sensorSEM=semBCreate(SEM_Q_FIFO, SEM_EMPTY);
startMotor();

res1 = wdStart(timerRead, 0.5 * sysClkRateGet(), (FUNCPTR)sensorsem, 0);
resetSizeSensors(0); /* reset sensors conveyor 0*/
resetSizeSensors(1); /* reset sensors conveyor 1*/
taskSensor = taskSpawn("Sensor Read Task", 100, 0, 20000, (FUNCPTR)Sensor, 0,0,0,0,0,0,0,0,0,0);
taskGates = taskSpawn("Gate0 close Task", 100, 0, 20000, (FUNCPTR)closegatezero, 0,0,0,0,0,0,0,0,0,0);
semTake(sensorSEM, WAIT_FOREVER);

}