Question

I am trying to do the sleeping barber exercise with c and I can´t figure out what is going wrong. Would someone please be so kind as explain me in laymans term what do I need do to fix it. I keep getting this message:

app_main.c, line 72: error: void value not ignored as it ought to be app_main.c, line 73: error: void value not ignored as it ought to be

#define TASK0_PIN 0x80
INT8U err;
INT8U  err2;
void Task0(void *dptr)
{


       int value = OSSemPend(Barber,1,err); //aquire semaphore to perform barber
       int value2 = OSSemPend(FreeSeats,1,err2);

That is the problem area. Below you can see the whole code.

   /*
    **********************************************************
    * uCOSII example 0
    *
    * uCOS uses prioritized preemptive scheduling.
    *
    * This example program contains 2 tasks:
    * Task0 has lower priority (5) and can be preempted by task1.
    * Task1 has higher priority (3).
    **********************************************************
    */
    #include "ucos_ii.h"
    #include <stdio.h>
    #include <avr/io.h>
    #include <avr/interrupt.h>
     OS_EVENT *Barber;
     OS_EVENT *FreeSeats;


    int Customers;
    //int Barber;
    //int FreeSeats; //total number of seats

    int Ready;
    int  Ready2;
    int value;
    int value2;


    OS_STK Task0Stk[TASK0_STK_SIZE] __attribute__ ((section (".bss.stacks")));
    OS_STK Task1Stk[TASK1_STK_SIZE] __attribute__ ((section (".bss.stacks")));
    OS_STK Task2Stk[TASK2_STK_SIZE] __attribute__ ((section (".bss.stacks")));
    int status;

    void   Task0(void *objdata);
    void   Task1(void *objdata);
    void   Task2(void *objdata);

    int main(void)
    {
      OSInit();
      status=OSTaskCreate(Task0,(void *)NULL,(OS_STK *)&Task0Stk[TASK0_STK_SIZE - 1], TASK0_PRIO);
      status=OSTaskCreate(Task1,(void *)NULL,(OS_STK *)&Task1Stk[TASK1_STK_SIZE - 1], TASK1_PRIO);
      status=OSTaskCreate(Task2,(void *)NULL,(OS_STK *)&Task2Stk[TASK2_STK_SIZE - 1], TASK2_PRIO);




     Customers = 0;
      Barber = OSSemCreate(1); //total nro of barbers
    FreeSeats = OSSemCreate(2); //total number of seats

    Ready= OSSemPost(Barber); // release semaphore
   Ready2= OSSemPost(FreeSeats);

      OSStart();  //OSStart never returns
      return 0;
    }

    //------------------------------------------------------------------
    // Task0 toggles pin PD7 every 3. OS tick (=3 msec with default tick 1 msec)
    //------------------------------------------------------------------
    #define TASK0_PIN 0x80
    INT8U err;
    INT8U  err2;
    void Task0(void *dptr)
    {
    //||



               value = OSSemPend(Barber,1,err); //aquire semaphore to perform barber
                  value2 = OSSemPend(FreeSeats,1,err2);

     if (value<1 || value2<1 )//if barber or seat are not available then wait
      {
      OSTimeDly(3);
      }
      else
    {


      DDRD|=TASK0_PIN;
      for (;;) {
        PORTD^=TASK0_PIN;
        OSTimeDly(3); //wait 3 msec

     Ready;  //increment the semaphore and remove the task with highest priority from list and make it ready to run
     Ready2;
      }
    }
    }
    //------------------------------------------------------------------
    // Task0 toggles pin PD6 every OS tick (default 1 msec)
    //------------------------------------------------------------------
    #define TASK1_PIN 0x40
    void Task1(void *dptr)
    {

     Customers +1;
      if (FreeSeats >= 2)
      {
        FreeSeats -2;
      dptr=dptr;
      DDRD|=TASK1_PIN;
      for (;;) {
        PORTD^=TASK1_PIN;
      FreeSeats  +2;
      Customers -1;
        OSTimeDly(1); //wait 1 system tick
      }
       }
       else
    {
     OSTimeDly(3);
     Task1;
    }

    }

    //------------------------------------------------------------------
    // Task2 toggles pin PD6 every OS tick (default 1 msec)
    //------------------------------------------------------------------
    #define TASK2_PIN 0x20
    void Task2(void *dptr)
    {
       Customers +1;
      if (FreeSeats >= 2)
      {
        FreeSeats -2;

      dptr=dptr;
      DDRD|=TASK2_PIN;
      for (;;) {
        PORTD^=TASK2_PIN;
          FreeSeats  +2;
             Customers -1;
        OSTimeDly(2); //wait 1 system tick
      }
      }

     else
    {
     OSTimeDly(3);
     Task2;
    }

    }
Was it helpful?

Solution

OSSemPend returns void and you are assigning the returned value to value and value2

It looks like perhaps you want

OSSemPend(Barber,1,&err); //aquire semaphore to perform barber
OSSemPend(FreeSeats,1,&err2);
if (err != 0 || err2 != 0 )//if barber or seat are not available then wait

Either that or you want to use

value = OSSemPend(Barber,1);
value2 = OSSemPend(FreeSeats,1,);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top