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.
Post Reply
avrobot
Member++
Posts: 17
Joined: Mon Jun 04, 2018 4:26 am

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

Post by avrobot »

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
XCore Addict
Posts: 186
Joined: Tue Jan 17, 2017 9:25 pm

Post by RitchRock »

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: 17
Joined: Mon Jun 04, 2018 4:26 am

Post by avrobot »

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
XCore Addict
Posts: 186
Joined: Tue Jan 17, 2017 9:25 pm

Post by RitchRock »

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
XCore Addict
Posts: 186
Joined: Tue Jan 17, 2017 9:25 pm

Post by RitchRock »

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

Post by avrobot »

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
XCore Addict
Posts: 186
Joined: Tue Jan 17, 2017 9:25 pm

Post by RitchRock »

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: 17
Joined: Mon Jun 04, 2018 4:26 am

Post by avrobot »

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
XCore Addict
Posts: 186
Joined: Tue Jan 17, 2017 9:25 pm

Post by RitchRock »

Not entirely sure. Here is the thread where I got it working: http://www.xcore.com/viewtopic.php?f=8& ... 220#p28220
Post Reply