Using i2c shared module on XCORE-200 MCA
Posted: Thu Aug 12, 2021 2:12 pm
Hi,
I have developed application code for an XMOS based digital (audio) mixer and have encountered a build error (use of ‘r_i2C’ violates parallel usage rules) on XCORE-200 MCA (app_usb_aud_xk_216_mc).
My issue is due to using r_i2c in two parallel tasks; the audioHW driver, and a button matrix reading task that is also on the i2c bus. I understand the XMOS architecture does not support accessing the same memory location from separate tasks, tiles or cores, hence the error, although I am using the i2c shared module which is developed for multiple access, due to use of swlock.
My button matrix code is in my audioHW driver. ADC/DAC calls and button matrix calls are separate tasks from main.xc into my audioHW driver, and from audioHW.xc they call the same i2c shared routine.
I encountered the same issue several years ago while developing a high end audio XMOS based DAC with digital preamp, which had iap running, and the reference design when including iap uses r_i2c in parallel tasks. I noticed a workaround employed having the i2c function in a 'c' driver, and connecting via a channel (c_aud_cfg) from main(). I copied the i2c function to coprocessor.c which was already in use (by the iap task), and I added #include coprocessor.h to the audioHW driver, so I did not have to create a new c driver. At the time I tried the same code in and .xc driver which didn’t work, and not using the c_aud_cfg chanend also didn’t work. This worked very reliably and commercial pressures meant the product was launched without fully understanding the workaround.
I have seen several threads on xcore.com regarding shared i2c which detail setting up i2c calls in custom drivers, although I would love to understand how to use the i2c shared module as intended. The XMOS device is a fantastic processor and understanding how to share resources will be a massive help.
Thanks.
I have developed application code for an XMOS based digital (audio) mixer and have encountered a build error (use of ‘r_i2C’ violates parallel usage rules) on XCORE-200 MCA (app_usb_aud_xk_216_mc).
My issue is due to using r_i2c in two parallel tasks; the audioHW driver, and a button matrix reading task that is also on the i2c bus. I understand the XMOS architecture does not support accessing the same memory location from separate tasks, tiles or cores, hence the error, although I am using the i2c shared module which is developed for multiple access, due to use of swlock.
My button matrix code is in my audioHW driver. ADC/DAC calls and button matrix calls are separate tasks from main.xc into my audioHW driver, and from audioHW.xc they call the same i2c shared routine.
I encountered the same issue several years ago while developing a high end audio XMOS based DAC with digital preamp, which had iap running, and the reference design when including iap uses r_i2c in parallel tasks. I noticed a workaround employed having the i2c function in a 'c' driver, and connecting via a channel (c_aud_cfg) from main(). I copied the i2c function to coprocessor.c which was already in use (by the iap task), and I added #include coprocessor.h to the audioHW driver, so I did not have to create a new c driver. At the time I tried the same code in and .xc driver which didn’t work, and not using the c_aud_cfg chanend also didn’t work. This worked very reliably and commercial pressures meant the product was launched without fully understanding the workaround.
I have seen several threads on xcore.com regarding shared i2c which detail setting up i2c calls in custom drivers, although I would love to understand how to use the i2c shared module as intended. The XMOS device is a fantastic processor and understanding how to share resources will be a massive help.
Thanks.