Skip to contentSkip to conversation

i2c_slave_send & recv?

DISCUSSION Brent Roman 3 participants 6 messages May 19, 2005

lore
Share & tools
lore
#0 lore raw

Hi,

We are developing a complex embedded instument.
It will consist of a tiny XScale board running linux attached via I2C to a variety of custom sensors and actuators that we intend to custom design.

To efficiently utilize limited I2C bus bandwidth, I had intended to have the Linux system act as an I2C slave, responding
to events detected by the intelligent sensors more or less in real-time. The alternative would be to poll each sensor continuously :-(

I'm concerned about the following in i2c.h:

/* Some adapter types (i.e. PCF 8584 based ones) may support slave behaviuor.
* This is not tested/implemented yet and will change in the future. */
extern int i2c_slave_send(struct i2c_client *,char*,int);
extern int i2c_slave_recv(struct i2c_client *,char*,int);

Even if I implement these functions for the XScale's built-in I2C hardware how would an application detect incoming messages?

I don't see any sort of event notification mechanism.
Would i2c_slave_recv simply block until it received a message from the addressed client? If so, would I need to start multiple threads to monitor multiple clients simutaneously?

Given this interface, the best I can think of right now is to define a sort of wildcard address so one thread could i2c_slave_revc from it and unblock when a message is received from any master.

But, as you probably can tell, I'm pretty confused right now. I'm hoping one of the I2C package developers can set me straight...

Regards,

Signature · 3 lines
  Brent Roman
  Software Engineer                 Tel: 831 775 1808
  mailto:[email protected]  http://www.mbari.org/~brent
#1 lore raw

those are all good questions.
The only other thing I found is a paragraph I wrote in the TODO file in the i2c tree (search for 'slave') which hints at these and some other issues.

When I was implementing SMBus 2.0 enhancements and the smbus-arp demonstration driver I looked briefly into what it would take to implement "notify ARP master" and concluded that it would take some work.

If you choose to develop slave functionality
please let us know. We can help discuss things
but sorry we don't have any good answers for you at the moment.

mds

Quoted 38 lines · Brent Roman

Hi,

We are developing a complex embedded instument.
It will consist of a tiny XScale board running linux attached via I2C to a variety of custom sensors and actuators that we intend to custom design.

To efficiently utilize limited I2C bus bandwidth, I had intended to have the Linux system act as an I2C slave, responding
to events detected by the intelligent sensors more or less in real-time. The alternative would be to poll each sensor continuously :-(

I'm concerned about the following in i2c.h:

/* Some adapter types (i.e. PCF 8584 based ones) may support slave behaviuor.
* This is not tested/implemented yet and will change in the future. */
extern int i2c_slave_send(struct i2c_client *,char*,int); extern int i2c_slave_recv(struct i2c_client *,char*,int);

Even if I implement these functions for the XScale's built-in I2C hardware how would an application detect incoming messages?

I don't see any sort of event notification mechanism.
Would i2c_slave_recv simply block until it received a message from the addressed client? If so, would I need to start multiple threads to monitor multiple clients simutaneously?

Given this interface, the best I can think of right now is to define a sort of wildcard address so one thread could i2c_slave_revc from it and unblock when a message is received from any master.

But, as you probably can tell, I'm pretty confused right now. I'm hoping one of the I2C package developers can set me straight...

Regards,

#2 lore raw
In reply to Brent Roman

Mark,

Has anyone thought about connecting I2C to the kernel as a _network_ interface rather than a character mode driver? (Or, in addition to as a character mode driver?)

If I2C could be viewed as a network interface, I think all the semantics would work out much better. You'd listen on a raw sockets to await messages, etc. Different processes could listen on different "ports" simutaneously as long as their I2C addresses were unique -- otherwise you'd get a BIND error about an address already being in use. I fear that if you were to extend the current char driver interface to achieve anything like the same flexibility, you would effectively reimplement the lower end of linux's networking stack.

Does this make sense to you?

When I first read the I2C spec, I thought of it as a _very_ Local Area Network.
Later, I found that some vendors even refer to it as a "Small Area Net".

By the way:

What exactly do you mean in your TODO by "Notify ARP Master"? What does ARP stand for in this context?

- brent

Quoted 55 lines

those are all good questions.
The only other thing I found is a paragraph I wrote in the TODO file in the i2c tree (search for 'slave') which hints at these and some other issues.

When I was implementing SMBus 2.0 enhancements and the smbus-arp demonstration driver I looked briefly into what it would take to implement "notify ARP master" and concluded that it would take some work.

If you choose to develop slave functionality
please let us know. We can help discuss things
but sorry we don't have any good answers for you at the moment.

mds

Brent Roman wrote:
Hi,

We are developing a complex embedded instument.
It will consist of a tiny XScale board running linux attached via I2C to a variety of custom sensors and actuators that we intend to custom design.

To efficiently utilize limited I2C bus bandwidth, I had intended to have the Linux system act as an I2C slave, responding
to events detected by the intelligent sensors more or less in real-time. The alternative would be to poll each sensor continuously

I'm concerned about the following in i2c.h:

/* Some adapter types (i.e. PCF 8584 based ones) may support slave behaviuor.
* This is not tested/implemented yet and will change in the future. */
extern int i2c_slave_send(struct i2c_client *,char*,int); extern int i2c_slave_recv(struct i2c_client *,char*,int);

Even if I implement these functions for the XScale's built-in I2C hardware
how would an application detect incoming messages?

I don't see any sort of event notification mechanism.
Would i2c_slave_recv simply block until it received a message from the addressed client? If so, would I need to start multiple threads to monitor multiple clients simutaneously?

Given this interface, the best I can think of right now is to define a sort of wildcard address so one thread could i2c_slave_revc from it and unblock when a message is received from any master.

But, as you probably can tell, I'm pretty confused right now. I'm hoping one of the I2C package developers can set me straight...

Signature · 4 lines
 Brent Roman                                   MBARI
 Software Engineer               Tel: (831) 775-1808
 7700 Sandholdt Road,         Moss Landing, CA 95039
 mailto:[email protected]  http://www.mbari.org/~brent
#3 lore raw
In reply to Brent Roman
Quoted 4 lines · Brent Roman

I don't know the details of the 2.5 "driver model". Would it allow for two independent processes to respond to I2C messages from different slaves?

Yes.

Quoted 1 line

Can you give me any pointers to the relevant 2.5 kernel docs?

The only thing that has changed in 2.5, from a user's point of view, is how to access the sensor data. That is documented in Documentation/i2c/sysfs-interface.

The kernel driver model only affects how the driver itself is written. For examples of that, see the many 2.5 i2c drivers.

Hope this helps,

greg k-h

#4 lore raw
In reply to Brent Roman

(going back through some old mail)
First suggestion we've heard about using a network interface. Probaly not a good fit in my opinion.
The recent conversion to the 2.5 kernel "driver model" is a better fit.
Perhaps in that model it would be more straightforward to add slave functionality and event notification... then again maybe not.

ARP is Address Resolution Protocol which is a way to assign an address to a hotplugged I2C device in the SMBus 2.0 spec.

As I said in April, if you plan to work on the slave functionality let us know.

mds

Quoted 87 lines · Brent Roman

Mark,

Has anyone thought about connecting I2C to the kernel as a _network_ interface rather than a character mode driver? (Or, in addition to as a character mode driver?)

If I2C could be viewed as a network interface, I think all the semantics would work out much better. You'd listen on a raw sockets to await messages, etc. Different processes could listen on different "ports" simutaneously as long as their I2C addresses were unique -- otherwise you'd get a BIND error about an address already being in use. I fear that if you were to extend the current char driver interface to achieve anything like the same flexibility, you would effectively reimplement the lower end of linux's networking stack.

Does this make sense to you?

When I first read the I2C spec, I thought of it as a _very_ Local Area Network.
Later, I found that some vendors even refer to it as a "Small Area Net".

By the way:

What exactly do you mean in your TODO by "Notify ARP Master"? What does ARP stand for in this context?

- brent

Quoted 55 lines

those are all good questions.
The only other thing I found is a paragraph I wrote in the TODO file in the i2c tree (search for 'slave') which hints at these and some other issues.

When I was implementing SMBus 2.0 enhancements and the smbus-arp demonstration driver I looked briefly into what it would take to implement "notify ARP master" and concluded that it would take some work.

If you choose to develop slave functionality
please let us know. We can help discuss things
but sorry we don't have any good answers for you at the moment.

mds

Brent Roman wrote:
Hi,

We are developing a complex embedded instument.
It will consist of a tiny XScale board running linux attached via I2C to a variety of custom sensors and actuators that we intend to custom design.

To efficiently utilize limited I2C bus bandwidth, I had intended to have the Linux system act as an I2C slave, responding
to events detected by the intelligent sensors more or less in real-time. The alternative would be to poll each sensor continuously

I'm concerned about the following in i2c.h:

/* Some adapter types (i.e. PCF 8584 based ones) may support slave behaviuor.
* This is not tested/implemented yet and will change in the future. */
extern int i2c_slave_send(struct i2c_client *,char*,int); extern int i2c_slave_recv(struct i2c_client *,char*,int);

Even if I implement these functions for the XScale's built-in I2C hardware
how would an application detect incoming messages?

I don't see any sort of event notification mechanism.
Would i2c_slave_recv simply block until it received a message from the addressed client? If so, would I need to start multiple threads to monitor multiple clients simutaneously?

Given this interface, the best I can think of right now is to define a sort of wildcard address so one thread could i2c_slave_revc from it and unblock when a message is received from any master.

But, as you probably can tell, I'm pretty confused right now. I'm hoping one of the I2C package developers can set me straight...

#5 lore raw
In reply to Brent Roman

Mark,

Since I wrote that last message in April, we've pretty much decided to make all the I2C peripherals in our system strictly slaves. As we're building them up out of TI MSP430 microcontrollers, this simplifies our microcontroler code and associated FPGA design.

We intend to use a ancillary open collector /INT line from all the microcontrollers to tell the main Linux processor when to poll the I2C bus for pending messages. I'll probably attempt some funky LRU-like heuristic to optimize the polling.

I don't know the details of the 2.5 "driver model". Would it allow for two independent processes to respond to I2C messages from different slaves?

Can you give me any pointers to the relevant 2.5 kernel docs?

I'm still curious, nonetheless.

Thanks,

Signature · 4 lines
  Brent Roman
  Software Engineer                 Tel: 831 775 1808
  425 Clinton St., Santa Cruz,      California, 95062
  mailto:[email protected]  http://www.mbari.org/~brent