gpt4 book ai didi

c - 熟睡的理发师 OSSEMPEND()

转载 作者:行者123 更新时间:2023-11-30 14:22:39 24 4
gpt4 key购买 nike

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

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

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

}

最佳答案

OSSemPend 返回 void,并且您将返回值分配给 valuevalue2

看起来也许你想要

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

关于c - 熟睡的理发师 OSSEMPEND(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13613568/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com