Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ThisThread::flags_wait_any_for has wrong flags in implementation #53

Open
philrittenhouse opened this issue May 4, 2022 · 0 comments
Open

Comments

@philrittenhouse
Copy link

Description of defect

I ran into a problem where flags_wait_any_for() is waiting for all specified flags to be set instead of all. Looking at the code in SparkFun\hardware\apollo3\2.2.1\cores\mbed-os\rtos\source\ThisThread.cpp, I think the problem is the use of the osFlagsWaitAll flag instead of osFlagsWaitAny here:

uint32_t ThisThread::flags_wait_any_for(uint32_t flags, Clock::duration_u32 rel_time, bool clear)
{
    return flags_wait_for(flags, rel_time, clear, osFlagsWaitAll);
}

I noticed that in the Sparkfun/mbed-os-ambiq-apollo3 github repo this seems to have been fixed 2 years ago:
https://github.com/sparkfun/mbed-os-amb ... 31e548eb38

I guess the fix didn't make it over to the Arduino version.

Target(s) affected by this defect ?

All Sparkfun Artemis boards using this library.

Toolchain(s) (name and version) displaying this defect ?

Arduino

What version of Mbed-os are you using (tag or sha) ?

Sparkfun Arduino Apollo3 board driver version 2.2.1

What version(s) of tools are you using. List all that apply (E.g. mbed-cli)

Arduino 1.8.16

How is this defect reproduced ?

The following program will fail to wake up because it is waiting for all flags to be set instead of any:

#define STATUS_COUNT_TOTAL (10)
#define GO_FLAG     1

rtos::Thread thread;  

void thread_fn( void ){             // create a function to run as a thread
  Serial.begin(115200);                   // perform setup related to this thread
  Serial.print("Apollo3 - Threads\n\n");
  uint32_t flags;
  rtos::Kernel::Clock::duration_u32 sleep_time;

  uint8_t status_count = 0;
  while(status_count < STATUS_COUNT_TOTAL)
  {

    Serial.println("Thread waiting for flag...");

    sleep_time = rtos::Kernel::wait_for_u32_forever;
    //flags = rtos::ThisThread::flags_wait_any_for(GO_FLAG, sleep_time, true);
    flags = rtos::ThisThread::flags_wait_any_for(GO_FLAG|4, sleep_time, true);
    Serial.printf("wait returned flags = 0x%x\n", flags);
    
    Serial.printf("time (ms): %d, status count: %d\n", millis(), status_count++);
  }

  Serial.print("Stopping status thread\n");
  Serial.end();                           // de-initialiaze for this thread
}

// setup() and loop() run within the function main() which is the first thread
void setup() {
  thread.start(thread_fn);          // assign thread_fn to the object thread and begin execution
}

void loop() {

  delay(2000);
  if (osFlagsError == thread.flags_set(GO_FLAG))
  {
    Serial.println("Failed to set flag!!!");
  }
  Serial.println("Flag set");
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant