Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages   Examples  

Device I/O
[I/O Management]

Input and output device functions. More...

Data Structures

struct  _NUTDEVICE
 Device structure. More...

struct  _NUTDEVICE
 Device structure. More...

struct  _NUTVIRTUALDEVICE
 Virtual device structure. More...

struct  _NUTVIRTUALDEVICE
 Virtual device structure. More...


Defines

#define IFTYP_RAM
 RAM device.

#define IFTYP_ROM
 ROM device.

#define IFTYP_STREAM
 Stream device.

#define IFTYP_NET
 Net device.

#define IFTYP_TCPSOCK
 TCP socket.

#define IFTYP_CHAR
 Character stream device.


Typedefs

typedef _NUTDEVICE NUTDEVICE
 Device structure type.

typedef _NUTVIRTUALDEVICE NUTVIRTUALDEVICE
 Device structure type.


Functions

int NutDeviceClose (NUTDEVICE *dev)
 Closes a previously opened stream device.

int NutDeviceIOCtl (NUTDEVICE *dev, int req, void *conf)
 Perform device specific control functions.

NUTDEVICENutDeviceOpen (CONST char *name)
 Open a device by name.

int NutDeviceRead (NUTDEVICE *dev, void *data, int size)
 Read up to a specified number of bytes from a device.

int NutDeviceGetLine (NUTDEVICE *dev, void *data, int size)
 Get a line from a specified device.

NUTDEVICENutDeviceLookup (CONST char *name)
 Find device entry by name.

int NutRegisterDevice (NUTDEVICE *dev, u_short base, u_char irq)
 Register and initialize a device.

int NutDeviceWrite (NUTDEVICE *dev, CONST void *data, int len)
 Write a buffer to a specified device.

int NutDeviceWrite_P (NUTDEVICE *dev, PGM_P data, int len)
 Write a buffer in program space to a specified device.


Variables

NUTDEVICEnutDeviceList
 Linked list of all registered devices.


Detailed Description

Input and output device functions.


Typedef Documentation

typedef struct _NUTDEVICE NUTDEVICE
 

Device structure type.

typedef struct _NUTVIRTUALDEVICE NUTVIRTUALDEVICE
 

Device structure type.


Function Documentation

int NutDeviceClose NUTDEVICE   dev
 

Closes a previously opened stream device.

The calling thread may be suspended until all buffered output data has been sent.

Deprecated:
Use _close() or fclose() in new programs.
Parameters:
dev Identifies the device to close. This pointer must have been retrieved by calling NutDeviceOpen().
Returns:
0 on success, -1 otherwise.

int NutDeviceGetLine NUTDEVICE   dev,
void *    data,
int    size
 

Get a line from a specified device.

Reads a string from the specified device. Characters are read up to and including the first newline character, up to the end of the stream, or until the number of characters read is equal to the specified size, whichever comes first.

Deprecated:
Use fscanf() in new programs.
Parameters:
dev Identifies the device to read from. A null pointer may be used for unbuffered output to the first on-chip UART. If this pointer is not null, it must have been retrieved by directly or indirectly calling NutDeviceOpen() for real devices. For virtual devices this pointer is returned by the function that creates the device.
data Pointer to the buffer that receives the data.
size Size of the buffer.
Returns:
The number of bytes read or -1 in case of an error.

int NutDeviceIOCtl NUTDEVICE   dev,
int    req,
void *    conf
 

Perform device specific control functions.

Deprecated:
Use _iocntl() in new programs.
Parameters:
dev Identifies the device to control. This pointer must have been retrieved by directly or indirectly calling NutDeviceOpen().
req Requested control function.
conf Points to a buffer that contains any data required for the given control function or receives data from that function.
Examples:
rs232d/rs232d.c.

NUTDEVICE* NutDeviceLookup CONST char *    name
 

Find device entry by name.

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

NUTDEVICE* NutDeviceOpen CONST char *    name
 

Open a device by name.

This function must be called after registering the device with NutRegisterDevice() and before calling any read or write function.

Deprecated:
Use _open() or fopen() in new programs.
Parameters:
name Case sensitiv name of the device. This name is fixed by the specific device driver.
Returns:
Pointer to the device structure or null if the device has not been registered.
Examples:
rs232d/rs232d.c.

int NutDeviceRead NUTDEVICE   dev,
void *    data,
int    size
 

Read up to a specified number of bytes from a device.

The function may read fewer than the given number of bytes.

Deprecated:
Use _read() or fread() in new programs.
Parameters:
dev Identifies the device to read from. A null pointer may be used for unbuffered input from the first on-chip UART. If this pointer is not null, it must have been retrieved by directly or indirectly calling NutDeviceOpen() for real devices. For virtual devices this pointer is returned by the function that creates the device.
data Pointer to the buffer that receives the data.
size Size of the buffer.
Returns:
The number of bytes read, 0 on timeouts and broken connections or -1 in case of an error.
Examples:
rs232d/rs232d.c.

int NutDeviceWrite NUTDEVICE   dev,
CONST void *    data,
int    len
 

Write a buffer to a specified device.

This is a raw output without any character translation like EOL (end of line).

Deprecated:
Use _write() or fwrite() in new programs.
Parameters:
dev Identifies the device to write to. A null pointer may be used for unbuffered output to the first on-chip UART. If this pointer is not null, it must have been retrieved by directly or indirectly calling NutDeviceOpen() for real devices. For virtual devices this pointer is returned by the function that creates the device.
data Buffer to be written.
len Number of characters to be printed.
Returns:
If successful, the number of bytes added to the output buffer. This may be less than the specified number of bytes to print. The return value -1 indicates an error.
Examples:
rs232d/rs232d.c.

int NutDeviceWrite_P NUTDEVICE   dev,
PGM_P    data,
int    len
 

Write a buffer in program space to a specified device.

This is a raw output without any character translation like EOL (end of line).

Deprecated:
Use _write_P() or fwrite_P() in new programs..
Parameters:
dev Identifies the device to write to. A null pointer may be used for unbuffered output to the first on-chip UART. If this pointer is not null, it must have been retrieved by directly or indirectly calling NutDeviceOpen() for real devices. For virtual devices this pointer is returned by the function that creates the device.
data Buffer to be written.
len Number of characters to be printed.
Returns:
If successful, the number of bytes added to the output buffer. This may be less than the specified number of bytes to print. The return value -1 indicates an error.

int NutRegisterDevice NUTDEVICE   dev,
u_short    base,
u_char    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:
dev Pointer 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.
base Hardware base address of this device. Set to 0, if the device driver has a fixed hardware address.
irq Hardware 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.
Examples:
httpd/httpserv.c, inetq/inetq.c, playmp3/playmp3.c, portdio/portdio.c, rs232d/rs232d.c, tcps/tcps.c, threads/threads.c, timers/timers.c, and uart/uart.c.


Variable Documentation

NUTDEVICE* nutDeviceList
 

Linked list of all registered devices.


© 2000-2003 by egnite Software GmbH - visit http://www.ethernut.de/