Page 1 of 1

Pass arguments to the target application (xC)

Posted: Wed May 25, 2016 11:41 pm
by dsdanielko
Hi

I was following this AN10127 in http://www.xmos.com/support/examples, but after I compile (with no errors or warnings) and try the xrun command given in the example xrun just crashes. I have a STARTKIT connected to the computer which I have checked works using xrun -l and other projects.

Image

The xsim command given works fine however. Could someone help me out here?
Also, I plan to apply this to xC (the example is in C). Is there a way to do this? It seems you can't have input arguments in the main function of .xc files.

Thanks

Re: Pass arguments to the target application (xC)

Posted: Thu May 26, 2016 10:03 am
by peter
Sorry about this. I have just tested this my end and can confirm that this is broken. I will investigate why and see whether there is a work-around I can give you.

Re: Pass arguments to the target application (xC)

Posted: Thu May 26, 2016 10:52 am
by peter
Thanks for reporting this. Unfortunately it doesn't look like there is a work-around for this.

I have fixed this, so it should be working in the next tools release.

Re: Pass arguments to the target application (xC)

Posted: Thu May 26, 2016 11:06 am
by dsdanielko
So would I be able to work this in .xc? Do you have any idea when the tool will be released?

Thanks

Re: Pass arguments to the target application (xC)

Posted: Thu May 26, 2016 11:11 am
by peter
The bug is in the xrun on the host, so doing it in .xc will not work any better.

Re: Pass arguments to the target application (xC)

Posted: Thu May 26, 2016 11:12 am
by dsdanielko
Is it possible to modify the code to get this working in .xc? Sorry I am relatively new to xc

Re: Pass arguments to the target application (xC)

Posted: Thu May 26, 2016 11:26 am
by peter
You can rename the c file as a .xc file and change the main to:

Code: Select all

#include <stdio.h>

int main(unsigned int argc, char *unsafe argv[argc]) {
    printf("argc = %d\n", argc);
    for (unsigned int i = 0; i < argc; ++i) {
        printf("argv[%d] = %s\n", i, argv[i]);
    }
    return 0;
}
This will run on the simulator, but will still crash in xrun.

If you have a multi-tile main then the argument parsing in XC is not the same as you can't pass arguments to a multi-tile main. Instead you'd need to have two files, the main.xc:

Code: Select all

#include <xs1.h>
#include <platform.h>

void parse_command_line(int id);

int main () {
  par {
    on tile[0] : parse_command_line(1);
    on tile[1] : parse_command_line(2);
  }
  return 0;
}
And a parse.c:

Code: Select all

#include <stdio.h>
#include <syscall.h>

void parse_command_line(int id) {
  char buf[256];
  int argc = _get_cmdline(buf, 256);
  char **argv = (char **)&buf;

  for (int i = 0; i < argc; i++) {
    printf("%d: %s\n", id, argv[i]);
  }
}
Again, this will compile and run on the simulator, but not on the hardware.