Disable timer from an other tile

New to XMOS and XCore? Get started here.
y0lo
Member
Posts: 12
Joined: Tue Sep 08, 2015 8:47 am

Disable timer from an other tile

Post by y0lo »

Suppose:

We have two tiles 0 and 1;

Tile 1 - has a periodical timer

Tile 0 - has to enable or disable the timer on Tile 1.

Tile 1 code:

Code: Select all

while(1){
  select {
    case if_timer0_en_flag => timer0 when timerafter(time0) :> timer0:
    time0 += PERIOD;
    /*Do Something*/
    break;
    ...
  }
}

void tile1_enable_timer0(){ if_timer0_en_flag = 1; }

void tile1_disable_timer0(){ if_timer0_en_flag = 0; }
Tile 0 - just call
tile1_enable_timer0()
and
tile1_disable_timer0()
functions, when it is needed.

Is it ok?

Perhaps there is a better way?


will1979
Member
Posts: 12
Joined: Mon Oct 26, 2015 11:06 am

Post by will1979 »

You will need to use a channel for that.

In the select, put an extra case

Code: Select all

  case disable_channel :> en_flag:
    break;
and from the other tile send the new value:

Code: Select all

  disable_channel <: 1 or 0;
This assumes that the first task is always in the select ready to pick up the disable/enable state.
y0lo
Member
Posts: 12
Joined: Tue Sep 08, 2015 8:47 am

Post by y0lo »

Channels if fine.
But what if I need to use enable/disable functions from C code?
User avatar
larry
Respected Member
Posts: 275
Joined: Fri Mar 12, 2010 6:03 pm

Post by larry »

You could use an XC function to do an output on a opaque chanend resource. There is a compatibility header that defines chanend in C as int and the linker does necessary casting from actual chanend to int and back.

Example:

Code: Select all

main.xc:

f(chanend c);
g(chanend c);

main() {
  chan c;
  par {
    f(c);
    g(c);
  }
}

Code: Select all

f.xc:
#include <print.h>

outxc(chanend c, int x) {
  c <: x;
}

f(chanend c) {
  while (1) {
    int x;
    c :> x;
    printintln(x);
  }
}

Code: Select all

#include <stdlib.h>
#include <xccompat.h>

outxc(chanend c, int x);

g(chanend c)
{
  outxc(c, 0);
  outxc(c, 1);
  exit(0);
}
Alternatively you could have the outxc function only take a value, and save/restore the chanend in XC scope as unsafe global variable. That only works for one instance (can't have multiple channels), but doesn't require passing chanend around.