Page 1 of 1

hiding interfaces

Posted: Wed May 31, 2017 7:26 pm
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

Re: hiding interfaces

Posted: Tue Jun 13, 2017 1:14 pm
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        <----------------+                 |
|                 |                |                   |                |                 |
|                 |                |                   |                |                 |
+-----------------+                +-------------------+                +-----------------+

Re: hiding interfaces

Posted: Wed Jul 26, 2017 2:55 pm
by CousinItt
Only just seen this! Thanks for the idea. I'll give it some thought.