Compiler crashes with I2C combinable example

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm
Contact:

Compiler crashes with I2C combinable example

Post by Folknology »

I have been having real problem using the lib_i2c in combined pars, the problem is the compiler craps out with :

Code: Select all

xcc1: terminated due to internal unrecoverable error
After much experimentation I narrowed it down to lib_i2c and created the following simpler example to illustrate it:

Code: Select all

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

#define SAMPLEPERIOD 4000
#define ADC 0x34

on tile[0] : port  scl = XS1_PORT_1L;
on tile[0] : port  sda = XS1_PORT_1K;

[[combinable]]
void test(client interface i2c_master_if i2c){

	timer stmr;
	unsigned stm;
	i2c_regop_res_t res;
	uint8_t data[6] = {0xAA,0,0,0,0,0}; // SETUP 
	int values[3];
	unsigned bytes = 0;

	res = i2c.write(ADC, data, 1, bytes, 1); // setup ADC

	stmr :> stm;
  stm += stm + SAMPLEPERIOD;

	while(1){
		select{
			case stmr when timerafter(stm) :> void:
        res = i2c.read(ADC,data,6,1); // read 3 * 2 byte ADC values
        for (int r  = 0; r < 6; r+=2) 
          values[r>>1] = ((data[r] & 0x0F) << 8) | data[r+1];

        stmr :> stm;
        stm += stm + SAMPLEPERIOD;
        break;
		}
	}
}

int main(void) {
	interface i2c_master_if i2c[1];

	[[combine]]
	par {
		i2c_master(i2c, 1, scl, sda, 400);
		test(i2c[0]);
	}

	return 0;
}
I have also got the same issues when I tried the async combined I2C version.

This issue has caused my current project (with an already over running deadline) to come to a halt. Any chance someone at Xmos can take a look at this please.

Code: Select all

$> xcc --version
Community_14.1.2 (build 17961, Dec-04-2015)
Compiler version: 14.1.1
Copyright (C) XMOS Limited 2008-2015. All Rights Reserved.


User avatar
mon2
XCore Legend
Posts: 1913
Joined: Thu Jun 10, 2010 11:43 am
Contact:

Post by mon2 »

What are the results if you comment out the perm loop ? Does it compile without errors ?

Code: Select all

while(1){  // remove the outside perm loop
.
.
}
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm
Contact:

Post by Folknology »

mon2 wrote:What are the results if you comment out the perm loop ? Does it compile without errors ?

Code: Select all

while(1){  // remove the outside perm loop
.
.
}
Unfortunately Mon, it doesn't pass the combinable requirements if you do that:

Code: Select all

$>xmake        
Checking build modules
Using build modules: lib_i2c(3.1.4) lib_xassert(2.0.1) lib_logging(2.0.1)
Analyzing main.xc
../src/main.xc:12:46: error: combinable function must end in a `while(1){select{..}}' or combined `par' statement
void test(client interface i2c_master_if i2c){
                                             ^
xmake[1]: *** [.build/src//main.xc.pca.xml] Error 1
xmake: *** [analyze] Error 2
As it looks for the while(1){select{...}} pattern
User avatar
mon2
XCore Legend
Posts: 1913
Joined: Thu Jun 10, 2010 11:43 am
Contact:

Post by mon2 »

:(

If in a pinch, while waiting on XMOS to reply, perhaps consider the following I2C code which we recall using with success a few years ago on an I2C optical sensor:

http://www.xcore.com/projects/basic-i2c ... ng-adt7410

Not sure if your project is time sensitive on the I2C bus use but these I2C routines worked fine for our testing against Silabs, Panasonic and Osram I2C devices.
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm
Contact:

Post by Folknology »

mon2 wrote::(

If in a pinch, while waiting on XMOS to reply, perhaps consider the following I2C code which we recall using with success a few years ago on an I2C optical sensor:

http://www.xcore.com/projects/basic-i2c ... ng-adt7410

Not sure if your project is time sensitive on the I2C bus use but these I2C routines worked fine for our testing against Silabs, Panasonic and Osram I2C devices.
Thanks for the link/idea Mon if push comes to shove then maybe we could try this route, however we have written all of our hardware test cases along with functional code around the current (and partially fixed) lib_i2c, changing at this point would be a rather large refactor not to mention testing phase which we would like to avoid..
User avatar
mon2
XCore Legend
Posts: 1913
Joined: Thu Jun 10, 2010 11:43 am
Contact:

Post by mon2 »

Hi Al.

The compiler error appears to go away if you comment out the [[combine]] compiler keyword before the par in the main. Not sure if the results are desirable without the [[combine]] for your project.

Code: Select all

int main(void) {
    interface i2c_master_if i2c[1];

// [[combine]]
   par {
      i2c_master(i2c, 1, scl, sda, 400);
      test(i2c[0]);
   }
   return 0;
}
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm
Contact:

Post by Folknology »

mon2 wrote:Hi Al.

The compiler error appears to go away if you comment out the [[combine]] compiler keyword before the par in the main. Not sure if the results are desirable without the [[combine]] for your project.

Code: Select all

int main(void) {
    interface i2c_master_if i2c[1];

// [[combine]]
   par {
      i2c_master(i2c, 1, scl, sda, 400);
      test(i2c[0]);
   }
   return 0;
}
Sure without combining all is well with the world, this is how we test most of the code as we develop it. However during our optimisation of the code we have to combine it into a limited number of cores (or virtual cores) that we have available on our boards. We have always relied on combine/distribute for many of the state tasks sharing cores with the lower level drivers in this manner since these great features became available.
robertxmos
XCore Addict
Posts: 169
Joined: Fri Oct 23, 2015 10:23 am

Post by robertxmos »

Hi,

Could I bother you to capture the failing command line so I can recreate the issue?

Please could you alter your makefile flags to include "-v -save-temps"
I am interested in the '.build/main.xi' file and the final 'xcc1llvm ....' command line.

cheers
robert
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm
Contact:

Post by Folknology »

Hi Robert here are the outputs as requested

The output is rather noisy as a lot of it includes the warnings from the Xmos I2C and Assert libraries, I have include the files with all my warning turned on as attachments to this reply.

Here is the relevant output part you requested with warnings turned off

Code: Select all

Compiling main.xc
 "/home/awood/XMOS/xTIMEcomposer/Community_14.1.2/libexec/xcc1llvm" -E -march=xs2a "-I../." "-I.././src" "-I/home/awood/Projects/lib_i2c/lib_i2c" "-I/home/awood/Projects/lib_i2c/lib_i2c/api" "-I/home/awood/Projects/lib_i2c/lib_i2c/doc" "-I/home/awood/Projects/lib_i2c/lib_i2c/doc/pdf" "-I/home/awood/Projects/lib_i2c/lib_i2c/src" "-I/home/awood/Projects/lib_xassert/lib_xassert" "-I/home/awood/Projects/lib_xassert/lib_xassert/api" "-I/home/awood/Projects/lib_xassert/lib_xassert/doc" "-I/home/awood/Projects/lib_xassert/lib_xassert/doc/pdf" "-I/home/awood/Projects/lib_xassert/lib_xassert/src" "-I/home/awood/Projects/lib_logging/lib_logging" "-I/home/awood/Projects/lib_logging/lib_logging/api" "-I/home/awood/Projects/lib_logging/lib_logging/doc" "-I/home/awood/Projects/lib_logging/lib_logging/doc/pdf" "-I/home/awood/Projects/lib_logging/lib_logging/src" "-DCONFIG=Default"  -isystem "/home/awood/XMOS/xTIMEcomposer/Community_14.1.2/target/include/xc" -isystem "/home/awood/XMOS/xTIMEcomposer/Community_14.1.2/target/include" -isystem "/home/awood/XMOS/xTIMEcomposer/Community_14.1.2/target/include/clang" -D__xcore__ -D__XS2A__ -DXCC_VERSION_YEAR=14 -DXCC_VERSION_MONTH=1 -DXCC_VERSION_MAJOR=1401 -DXCC_VERSION_MINOR=1 -D__XCC_HAVE_FLOAT__ "-D_PLATFORM_INCLUDE_FILE=\"/home/awood/Projects/Example/.build/XCORE-200-EXPLORER.h\"" "-D_XSCOPE_PROBES_INCLUDE_FILE=\"/home/awood/Projects/Example/.build/xscope_probes.h\"" -o "main.xi" "../src/main.xc"
 "/home/awood/XMOS/xTIMEcomposer/Community_14.1.2/libexec/xcc1llvm" "-I../." "-I.././src" "-I/home/awood/Projects/lib_i2c/lib_i2c" "-I/home/awood/Projects/lib_i2c/lib_i2c/api" "-I/home/awood/Projects/lib_i2c/lib_i2c/doc" "-I/home/awood/Projects/lib_i2c/lib_i2c/doc/pdf" "-I/home/awood/Projects/lib_i2c/lib_i2c/src" "-I/home/awood/Projects/lib_xassert/lib_xassert" "-I/home/awood/Projects/lib_xassert/lib_xassert/api" "-I/home/awood/Projects/lib_xassert/lib_xassert/doc" "-I/home/awood/Projects/lib_xassert/lib_xassert/doc/pdf" "-I/home/awood/Projects/lib_xassert/lib_xassert/src" "-I/home/awood/Projects/lib_logging/lib_logging" "-I/home/awood/Projects/lib_logging/lib_logging/api" "-I/home/awood/Projects/lib_logging/lib_logging/doc" "-I/home/awood/Projects/lib_logging/lib_logging/doc/pdf" "-I/home/awood/Projects/lib_logging/lib_logging/src" "-DCONFIG=Default"  -isystem "/home/awood/XMOS/xTIMEcomposer/Community_14.1.2/target/include/xc" -isystem "/home/awood/XMOS/xTIMEcomposer/Community_14.1.2/target/include" -isystem "/home/awood/XMOS/xTIMEcomposer/Community_14.1.2/target/include/clang"  -D__xcore__ -D__XS2A__ -DXCC_VERSION_YEAR=14 -DXCC_VERSION_MONTH=1 -DXCC_VERSION_MAJOR=1401 -DXCC_VERSION_MINOR=1 -D__XCC_HAVE_FLOAT__ "-D_PLATFORM_INCLUDE_FILE=\"/home/awood/Projects/Example/.build/XCORE-200-EXPLORER.h\"" "-D_XSCOPE_PROBES_INCLUDE_FILE=\"/home/awood/Projects/Example/.build/xscope_probes.h\"" -Wall "-quiet" "-g" "-O2" "-version" "-analysis" ".././.build/pca.xml" -march=xs2a -o "main.s" "../src/main.xc"
XMOS 32-bit XC Compiler Community_14.1.2 (build 17961, Dec-04-2015)
Copyright (C) XMOS Limited 2008-2015. All Rights Reserved.
xcc1: terminated due to internal unrecoverable error
For bug reporting instructions, please see:
http://www.xmos.com/support
xmake[1]: *** [.build/src//main.xc.o] Error 1
xmake: *** [bin//example.xe] Error 2
I haven't shown the main.xi file as too long, but I have attached the file for your perusal

regards
Al
Attachments
make.log
Make output
(54.97 KiB) Downloaded 269 times
make.log
Make output
(54.97 KiB) Downloaded 269 times
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm
Contact:

Post by Folknology »

For some reason it didn't include my second attachment, so added it here..

Apparently I cannot attach files with an .xi extension so I have renamed it main.txt
(You might want to get the xcore devops to change this as it's clearly useful to be able to upload .xi files)

P.S. Can you not replicate the issue locally with this example?

regards
Al
Attachments
main.txt
(33.62 KiB) Downloaded 297 times
main.txt
(33.62 KiB) Downloaded 297 times
Post Reply