hiding interfaces

Technical questions regarding the XTC tools and programming with XMOS.
Post Reply
User avatar
CousinItt
Respected Member
Posts: 360
Joined: Wed May 31, 2017 6:55 pm

hiding interfaces

Post by CousinItt »

Hi all,

I'm trying to work out how to avoid having to pass the client end of an interface to every function that needs to use it.

Suppose I have a LED driver that's controlled via an I2C port. I'm using the I2C library, so the LED driver software needs to know about the client interface, but this information should be hidden from the code that makes use of it. I don't want to have to have to identify the interface to the driver functions every time.

In other words, I want to be able to call SetLed1(ON) rather than SetLed1(ON, i2c_if). Preferably this would work by having a member variable to store the interface, or a reference or pointer to it, which can then be used by functions within a module. That reference then only needs to be set up once.

I've tried creating a static interface member variable but XCC complains along the lines of "error: global variable `i2c_if' has type interface".

Any ideas?

Thanks


User avatar
infiniteimprobability
XCore Legend
Posts: 1126
Joined: Thu May 27, 2010 10:08 am
Contact:

Post by infiniteimprobability »

Would adding a proxy distributable task help? It wouldn't take any more cores (the tools will inline it all if it only has pure interface cases/calls) but it could give you some abstraction. The i2c interface only exists between your distributable task and the i2c master but you can call methods on the distributable proxy task which get translated into whatever i2c commands you wish.

Code: Select all

+-----------------+                +-------------------+                +-----------------+
|                 |                |                   |                |                 |
|                 |    i_i2c       |                   |    i_generic   |                 |
|    i2c master   |                |    distributable  |                |     app         |
|                 <----------------+       task        <----------------+                 |
|                 |                |                   |                |                 |
|                 |                |                   |                |                 |
+-----------------+                +-------------------+                +-----------------+
User avatar
CousinItt
Respected Member
Posts: 360
Joined: Wed May 31, 2017 6:55 pm

Post by CousinItt »

Only just seen this! Thanks for the idea. I'll give it some thought.
Post Reply