break/continue in select statement Topic is solved

Technical questions regarding the XTC tools and programming with XMOS.
ffomich
Experienced Member
Posts: 119
Joined: Mon Sep 15, 2014 1:32 pm

break/continue in select statement

Post by ffomich »

Hi,
please help me to understand USBAudio 2.0 project

Code: Select all

int main()
{
  par
  {
     on tile[AUDIO_IO_TILE]: usb_audio_io(...);
     ...
  }
}

void usb_audio_io(...)
{
  par
  {
    ...
    clockGen(...);
  }
}

void clockGen(...)
{
  ...
  while(1)
  {
     select
     {
            case ...:
            case ...:

#ifdef SPDIF_RX
            /* Receive sample from S/PDIF RX thread (steaming chan) */
            case c_spdif_rx :> tmp:

                /* Check parity and ignore if bad */
                if(badParity(tmp)) continue;
                ...
                break;

     } // eo select
  }// eo while

}
What program do after continue? Does it jump to select and continue to analyze cases?

If I replace continue with break program will exit from select, continue to run into while(1) loop and enter to select again, am I right?


View Solution
henk
Respected Member
Posts: 347
Joined: Wed Jan 27, 2016 5:21 pm

Post by henk »

Hi,

continue will jump to the beginning of the while loop; skipping anything after the select{}.

Cheers
Henk
peter
XCore Addict
Posts: 230
Joined: Wed Mar 10, 2010 12:46 pm

Post by peter »

As Henk said, the continue jumps straight back to the top of the loop, while the break just jumps out of the select and runs the code after it. For example:

Code: Select all

#include <xs1.h>
#include <print.h>

#define DELAY 10000000

int main() {
  timer tmr;
  int time;

  tmr :> time;
  
  for (int i = 0; i < 10; i++) {
    time += DELAY;
    select {
      case tmr when timerafter(time) :> void:
        printstr("Case\n");
        if (i & 0x1) continue;
        break;
    }
    printstr("Break\n");
  }
  return 0;
}
Produces the following output:

Code: Select all

 $ xcc continue.xc -o continue.xe -target=XCORE-200-EXPLORER
 $ xrun --xscope continue.xe
Case
Break
Case
Case
Break
Case
Case
Break
Case
Case
Break
Case
Case
Break
Case
Hope that helps...