[En-Nut-Discussion] Doubts about NutRegisterSpiDevice

Harald Kipp harald.kipp at egnite.de
Mon Sep 7 18:26:19 CEST 2015


Hi Uwe,

On 07.09.2015 12:27, Uwe Bonnes wrote:

> For SPI devices, NutRegisterSpiDevice() stores the NUTSPINODE SPI bus
> information in dev_icb. The Interface control block is used for general
> interface information, and e.g. Ethernet drivers expectes IFNET as icb. So a
> SPI-connected ethernet device can't use our present net infrastructure.

Obviously not directly.


> So I think NutRegisterSpiDevice() is the wrong approach and a better
> functionality to register a device would should store NUTSPINODE as dev_dcb.

There has been no fixed rule for using dev_dcb or dev_icb, they are just
2 general purpose pointers. By convention, most drivers use dev_dcb for
device-specific parameters and dev_icb for any kind of common interface
framework.

As you already pointed out, all Network drivers are expected to have a
common IFNET structure and all SPI bus devices are expected to have a
common NUTSPINODE structure. That's why it is called interface control
block and why dev_icb is used in both cases.

But in general, I wouldn't bet on it. As I said, just 2 GP-pointers.

In your case, the driver will be a member of two commonly used
frameworks, as a network device _and_ as an SPI bus device.

Of course we could switch one of them. I also see, that swapping the
pointers in the SPI bus drivers looks less risky. (But note, that some
SPI bus devices already make use of dev_dcb.) IMHO, swapping the
pointers will solve this special case, but doesn't solve everything.

If we look into the details, this conflict appeared more than once in
the past. UART drivers use even both, dev_dcb for UARTDCB and dev_icb
for IFSTREAM. But I still can use an UART for networking via PPP. The
technique used in this case is to create a new network driver, which can
use any UART driver for the lower level part.

This is my current view, I haven't considered all the details. If you
still think, that NutRegisterSpiDevice() uses the wrong approach, then
go ahead and change it. To an application developer it really makes no
difference, which driver uses dev_dcb or dev_icb.

Regards,

Harald



More information about the En-Nut-Discussion mailing list