0

我正在尝试用 c 进行睡眠理发练习,但我不知道出了什么问题。有人请用外行术语向我解释我需要做什么来解决它。我不断收到此消息:

app_main.c,第 72 行:错误:void 值没有被忽略,因为它应该是 app_main.c,第 73 行:错误:void 值没有被忽略,因为它应该是

#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);

那就是问题所在。下面你可以看到整个代码。

   /*
    **********************************************************
    * 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;
    }

    }
4

1 回答 1

2

OSSemPend 返回 void 并且您将返回的值分配给valueandvalue2

看起来你可能想要

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

或者你想使用

value = OSSemPend(Barber,1);
value2 = OSSemPend(FreeSeats,1,);
于 2012-11-28T21:05:00.280 回答