I have a question about a weird reaction of the XMOS.
I have a simple code with a function that reads an I2C digital sensor and one tat prints those values. They both run on different threads. sense() sends the values to print() through a streaming channel. Since that is the case, I expect sense() not to block while print() prints.
Below you can find my code and a series of pics. I run this code two times with one small difference. The printintln() line was first active and then commented out.
Code: Select all
#include <platform.h>
#include <print.h>
#include <xs1.h>
#include "i2c.h"
#define GE_ADDR 0x68
#define GE_PIX_LOW 0x80
#define GE_PIX_HIGH 0x81
r_i2c i2cOne = {on tile[1]:XS1_PORT_1F, on tile[1]:XS1_PORT_1B, 1000};
void sense(streaming chanend pix_temp_chan){
int adc_value;
int i=0;
unsigned char pix_temp_low[1];
unsigned char pix_temp_high[1];
int pix_temp[64];
/************************************************
* PANASONIC GRID-EYE
************************************************/
while(1){
pix_temp_low[0]=0;pix_temp_high[0]=0;
for(i=0;i<64;i++){
i2c_master_read_reg(GE_ADDR, GE_PIX_LOW, pix_temp_low, 1, i2cOne);
i2c_master_read_reg(GE_ADDR, GE_PIX_HIGH, pix_temp_high, 1, i2cOne);
pix_temp[i] = (pix_temp_high[0] << 8) | pix_temp_low[0];
if(pix_temp_high[0] != 0){
pix_temp[i] = - (2048 - pix_temp[i]);
}
pix_temp_chan <: pix_temp[i];
}
}
}
void print(streaming chanend pix_temp_data){
int data;
while(1){
pix_temp_data :> data;
printintln(data);
}
}
int main() {
streaming chan pix_temp_chan;
par {
on tile[1]: sense(pix_temp_chan);
on tile[1]: print(pix_temp_chan);
}
return 0;
}
In the first picture you can see that the I2C clock only works for a short period. The rest of the time it is dead (i assume that the sense() function is blocked while the print() function prints).
If I comment the printintln() line, then the scope gives the second picture. There you can see that the I2C clock is really dense, meaning that there is no blocking.
My question is, since I am using two parallel cores, with a streaming channel, shouldn't both functions work without blocking?
Kind regards,
Dimitris