error: use of `r_i2c' violates parallel usage rules (xCORE-200 MC)

Technical discussions related to any XMOS development kit or reference design. Eg XK-1A, sliceKIT, etc.
avrobot
Member
Posts: 10
Joined: Mon Jun 04, 2018 4:26 am

error: use of `r_i2c' violates parallel usage rules (xCORE-200 MC)

Postby avrobot » Mon Jun 04, 2018 4:46 am

I am pretty new to Xcore and customizing sw_usb_audio and have some devices in addition to the DAC/ADC on the main I2C bus that need to be accessed (HW cannot have an additional I2C bus).

I am trying to achieve: sending of a non-blocking I2C command to be triggered from inside midioutparse.xc.

By attempting to call i2c_shared routine that is defined in audiohw.xc I get "error: use of `r_i2c' violates parallel usage rules" and I understand this is due to shared thread protection.

What is the best way to achieve this goal? Channels, or interfaces? And where exactly in the code should I define these such that I can pass the info from inside midioutparse into audiohw?

I read another thread that discussed using a different i2c lib that allowed multiple thread access but this I fear is not straight forward and probably remains blocking.

Thanks for any thoughts.
RitchRock
Experienced Member
Posts: 100
Joined: Tue Jan 17, 2017 9:25 pm

Postby RitchRock » Mon Jun 04, 2018 11:48 pm

I have not used midioutparse, however I took the time to switch from the shared i2c routine used in the standard firmware to lib_i2c and I have no problems using i2C outside of audiohw.xc. I've used most of the various i2c functions (and even extended my own) without problem.

Are you using the eval board? If so, I believe I2C is on a 4-bit port, so you will be limited to using i2c_master_single_port()
avrobot
Member
Posts: 10
Joined: Mon Jun 04, 2018 4:26 am

Postby avrobot » Tue Jun 05, 2018 12:51 pm

thanks RitchRock I'll look into effort to port over the i2c functions within audiohw to lib_i2c so I can also access i2c from other tasks. Yep I'm on the 4bit port as in eval board. Will be interesting to see if its straight forward port...
The other option I see is to add some intertask communication (channels or interface coms) to manage i2c using the current i2c shared libs but still have some understanding to gain where/how to code this.
RitchRock
Experienced Member
Posts: 100
Joined: Tue Jan 17, 2017 9:25 pm

Postby RitchRock » Tue Jun 05, 2018 4:16 pm

avrobot wrote:thanks RitchRock I'll look into effort to port over the i2c functions within audiohw to lib_i2c so I can also access i2c from other tasks. Yep I'm on the 4bit port as in eval board. Will be interesting to see if its straight forward port...
The other option I see is to add some intertask communication (channels or interface coms) to manage i2c using the current i2c shared libs but still have some understanding to gain where/how to code this.


It will be easier to simply use lib_i2c rather than use the other types of communication for this. Import lib_i2c and add a few lines to main(). Then pass the interface through usb_audio_io to the 2 functions in audiohw.xc. If you want another function to use i2c, you would simply change the number of interfaces in the declaration - instead of i2c_master_if i2c[1], you could replace the 1 with a 2.

Code: Select all

...
#include "i2c.h"
...

port p_i2c = on tile[0]: XS1_PORT_4A;       //Bit 0: SCA Bit 1: SDA
...

main(){
...
i2c_master_if i2c[1];

on tile[AUDIO_IO_TILE]:
        par
        {
...
            i2c_master_single_port(i2c, 1, p_i2c, 100, 0, 1, 0);
            usb_audio_io(i2c[0], ...);
...
        }

...

....
RitchRock
Experienced Member
Posts: 100
Joined: Tue Jan 17, 2017 9:25 pm

Postby RitchRock » Tue Jun 05, 2018 4:31 pm

Also note that by using lib_i2c, you are using interface coms.
avrobot
Member
Posts: 10
Joined: Mon Jun 04, 2018 4:26 am

Postby avrobot » Mon Jun 11, 2018 1:02 am

Ok.. in trying this I've hit an issue:
I've removed the existing eval default i2c libs, imported lib_i2c into the project,added lib_i2c to USED_MODULES line in make file, moved i2c.h into system folder (for visibility to all modules - resolving <i2c.h>) and added the suggested port and declarations to main.xc.

lib_i2c does not seem to compile and spits out a a great number of errors.(starting with as below..)

I seemed to be going in circles trying to resolve this... Any ideas?


"-ID:/fp9001_tube_synced/fp2003_xmos_fD:/fp9001_tube_synced/fp2003_xmos_firmware/TPHY_V2/lib_i2c/src/i2c_master_single_port.xc:66:18: error: parse error before numeric constant
const unsigned SCL_HIGH = BIT_MASK(scl_bit_position);
^
<command line>:4:18: note: expanded from here
#define SCL_HIGH 1
^
D:/fp9001_tube_synced/fp2003_xmos_firmware/TPHY_V2/lib_i2c/src/i2c_master_single_port.xc:69:3: error: parse error before "while"
while (!(val & SCL_HIGH)) {
^
D:/fp9001_tube_synced/fp2003_xmos_firmware/TPHY_V2/lib_i2c/src/i2c_master_single_port.xc:71:3: error: parse error before '}' token
}
^
D:/fp9001_tube_synced/fp2003_xmos_firmware/TPHY_V2/lib_i2c/src/i2c_master_single_port.xc:75:3: warning: type defaults to `int' in declaration of `tmr'
tmr when timerafter(fall_time + delay) :> time;
^~~
D:/fp9001_tube_synced/fp2003_xmos_firmware/TPHY_V2/lib_i2c/src/i2c_master_single_port.xc:75:3: warning: data definition has no type or storage class
tmr when timerafter(fall_time + delay) :> time;
^~~
D:/fp9001_tube_synced/fp2003_xmos_firmware/TPHY_V2/lib_i2c/src/i2c_master_single_port.xc:75:7: error: parse error before "when"
tmr when timerafter(fall_time + delay) :> time;
^
D:/fp9001_tube_synced/fp2003_xmos_firmware/TPHY_V2/lib_i2c/src/i2c_master_single_port.xc:75:12: error: cannot redefine built in compiler function `__builtin_timer_after'
tmr when timerafter(fall_time + delay) :> time;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
... many other errors
RitchRock
Experienced Member
Posts: 100
Joined: Tue Jan 17, 2017 9:25 pm

Postby RitchRock » Mon Jun 11, 2018 5:13 pm

How are you installing lib_i2c? Are you doing it from the "libraries" window within Time Composer? Also, you may want to physically delete the old "module i2c" from your disk before doing so. I remember something along these lines getting rid of all these errors for me (it's been a while...).
avrobot
Member
Posts: 10
Joined: Mon Jun 04, 2018 4:26 am

Postby avrobot » Tue Jun 12, 2018 11:36 am

Thanks.. to install lib_i2c I tried two methods, 1. By manually importing from the archive file . 2. By adding from the Library tab in xtimecomposer... and in both cases including lib_i2c in the USED_MODULES field and copy i2c.h into system folder and doing clean each time (xassert, lib_logging also updated as required)... I have deleted module_i2c_shared, module_i2c_simple, module_i2c_shared, module_i2c_single_port
still same issue.
RitchRock
Experienced Member
Posts: 100
Joined: Tue Jan 17, 2017 9:25 pm

Postby RitchRock » Tue Jun 12, 2018 4:14 pm

Not entirely sure. Here is the thread where I got it working: viewtopic.php?f=8&t=5556&p=28220#p28220

Who is online

Users browsing this forum: No registered users and 7 guests