Nut/OS  4.10.3
API Reference
Device Management

Device driver support. More...

Collaboration diagram for Device Management:

Data Structures

struct  _NUTDEVICE
 Device structure. More...
struct  _NUTVIRTUALDEVICE
 Virtual device structure. More...
struct  _IFSTREAM
 Stream interface information structure. More...
struct  _NUTFILE
 File structure. More...

Defines

#define IFTYP_RAM   0
 RAM device.
#define IFTYP_ROM   1
 ROM device.
#define IFTYP_STREAM   2
 Stream device.
#define IFTYP_NET   3
 Net device.
#define IFTYP_TCPSOCK   4
 TCP socket.
#define IFTYP_CHAR   5
 Character stream device.
#define IFTYP_CAN   6
 CAN device.
#define IFTYP_BLKIO   7
 Block I/O device.
#define IFTYP_FS   16
 file system device
#define NUTFILE_EOF   ((NUTFILE *)(-1))

Typedefs

typedef struct _NUTDEVICE NUTDEVICE
 Device structure type.
typedef struct _NUTVIRTUALDEVICE NUTVIRTUALDEVICE
 Device structure type.
typedef struct _IFSTREAM IFSTREAM
 Stream interface type.
typedef struct _NUTFILE NUTFILE
 File structure type.

Functions

NUTDEVICENutDeviceLookup (CONST char *name)
 Find device entry by name.
int NutRegisterDevice (NUTDEVICE *dev, uintptr_t base, uint8_t irq)
 Register and initialize a device.
int NullIOCTL (NUTDEVICE *dev, int req, void *conf)
 Perform control functions.

Variables

NUTDEVICEnutDeviceList = 0
 Linked list of all registered devices.
NUTDEVICE devNull
 Null device information structure.

Detailed Description

Device driver support.


Define Documentation

#define IFTYP_RAM   0

RAM device.

Definition at line 135 of file device.h.

#define IFTYP_ROM   1

ROM device.

Definition at line 136 of file device.h.

#define IFTYP_STREAM   2

Stream device.

Definition at line 137 of file device.h.

Referenced by AceInit(), and UartAvrInit().

#define IFTYP_NET   3
#define IFTYP_TCPSOCK   4

TCP socket.

Definition at line 139 of file device.h.

Referenced by NutTcpCreateSocket().

#define IFTYP_CHAR   5

Character stream device.

Definition at line 140 of file device.h.

Referenced by AhdlcAt91IOCtl(), and AhdlcAvrIOCtl().

#define IFTYP_CAN   6

CAN device.

Definition at line 141 of file device.h.

#define IFTYP_BLKIO   7

Block I/O device.

Definition at line 142 of file device.h.

#define IFTYP_FS   16

file system device

Definition at line 143 of file device.h.

Referenced by MmCardMount(), NutBlockDeviceOpen(), and SpiMmcMount().


Typedef Documentation

typedef struct _NUTDEVICE NUTDEVICE

Device structure type.

Definition at line 148 of file device.h.

Device structure type.

Definition at line 269 of file device.h.

typedef struct _IFSTREAM IFSTREAM

Stream interface type.

Definition at line 289 of file device.h.

typedef struct _NUTFILE NUTFILE

File structure type.

Definition at line 65 of file file.h.


Function Documentation

NUTDEVICE* NutDeviceLookup ( CONST char *  name)

Find device entry by name.

Parameters:
nameUnique device name.
Returns:
Pointer to the NUTDEVICE structure.

Definition at line 90 of file devreg.c.

References _NUTDEVICE::dev_name, _NUTDEVICE::dev_next, NUTASSERT, and strcmp().

Referenced by _open(), NutBlockDeviceOpen(), NutDhcpIfConfig(), NutNetIfAddMcastAddr(), NutNetIfConfig2(), NutNetIfDelMcastAddr(), NutRegisterDevice(), opendir(), rename(), stat(), and upnp_Init().

Here is the call graph for this function:

int NutRegisterDevice ( NUTDEVICE dev,
uintptr_t  base,
uint8_t  irq 
)

Register and initialize a device.

Initializes the device and adds it to the system device list. Applications should call this function during initialization for each device they intend to use.

Parameters:
devPointer to the NUTDEVICE structure, which is provided by the device driver. This structure contains a hardware device name, which must be unique among all registered devices. Drivers may operate in a different mode using the same hardware, like interrupt driven or polling UART drivers. Only one of those drivers can be registered, because they specify the same hardware device name.
baseHardware base address of this device. Set to 0, if the device driver has a fixed hardware address.
irqHardware interrupt used by this device. Set to 0, if the device driver doesn't support configurable interupts.
Returns:
0 if the device has been registered for the first time and initialization was successful. The function returns -1 if any device with the same name had been registered previously, if the NUTDEVICE structure is invalid or if the device initialization failed.

Definition at line 129 of file devreg.c.

References _NUTDEVICE::dev_base, _NUTDEVICE::dev_init, _NUTDEVICE::dev_irq, _NUTDEVICE::dev_name, _NUTDEVICE::dev_next, NUTASSERT, nutDeviceList, and NutDeviceLookup().

Referenced by InitDebugDevice(), main(), and NutRegisterSpiDevice().

Here is the call graph for this function:

int NullIOCTL ( NUTDEVICE dev,
int  req,
void *  conf 
)

Perform control functions.

This function is called by the ioctl() function of the C runtime library.

Parameters:
devIdentifies the device that receives the device-control function.
reqRequested control function. We do return ok for any function
confPoints to a buffer that contains any data required for the given control function or receives data from that function.
Returns:
0 on success, -1 otherwise.

Definition at line 136 of file null.c.


Variable Documentation

Linked list of all registered devices.

Definition at line 81 of file devreg.c.

Referenced by MmCardMount(), NutIpOutput(), NutRegisterDevice(), and SpiMmcMount().

Initial value:
 {
    0,                          
    {'n', 'u', 'l', 'l', 0, 0, 0, 0, 0},
                                
    0,                          
    0,                          
    0,                          
    0,                          

    0,                          
    0,                          
    
    NullIOCTL,                  
    NullRead,
    NullWrite,

    NullWriteP,

    NullOpen,
    NullClose,
    0
}

Null device information structure.

Definition at line 145 of file null.c.