Pass arguments to the target application (xC) Topic is solved

All technical discussions and projects around startKIT
dsdanielko
Active Member
Posts: 33
Joined: Sat Mar 12, 2016 3:12 pm

Pass arguments to the target application (xC)

Post 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
View Solution
peter
XCore Addict
Posts: 230
Joined: Wed Mar 10, 2010 12:46 pm

Post 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.
peter
XCore Addict
Posts: 230
Joined: Wed Mar 10, 2010 12:46 pm

Post 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.
dsdanielko
Active Member
Posts: 33
Joined: Sat Mar 12, 2016 3:12 pm

Post by dsdanielko »

So would I be able to work this in .xc? Do you have any idea when the tool will be released?

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

Post by peter »

The bug is in the xrun on the host, so doing it in .xc will not work any better.
dsdanielko
Active Member
Posts: 33
Joined: Sat Mar 12, 2016 3:12 pm

Post by dsdanielko »

Is it possible to modify the code to get this working in .xc? Sorry I am relatively new to xc
peter
XCore Addict
Posts: 230
Joined: Wed Mar 10, 2010 12:46 pm

Post 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.