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

XgDevice


Data Structures

struct  _NUTDEVICE
 Device structure. More...

struct  _NUTDEVICE
 Device 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.


Typedefs

typedef _NUTDEVICE NUTDEVICE
 Device structure type.


Functions

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

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

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

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

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

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

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

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

int NutDeviceWriteTran (NUTDEVICE *dev, CONST void *data)
 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.

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


Variables

NUTDEVICEnutDeviceList = 0
 Linked list of all registered devices.


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.

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.

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.

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.

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 stream device by name.

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

Note:
Do not use this function for network devices. For these you must call NutNetIfConfig() or NutNetAutoConfig(). Also virtual stream devices need not to be opened.
Parameters:
name  Case sensitiv name of the device. This name is fixed by the device driver and may be any of the following:
  • "uart0" for the first on-chip UART.
  • "uart1" for the second on-chip UART.
  • "uarts0".."uarts7" for one of the 8 SPI UARTs.
Returns:
Pointer to the device structure or null if the device has not been registered.
Examples:
adds/app/flash, adds/app/keys, adds/app/lcd, adds/app/rtc, and adds/app/term.

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.

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.

int NutDeviceReadTran NUTDEVICE   dev,
void *    data,
int    size
 

Read up to a specified number of bytes from a device translating non printables.

This call works like NutDeviceRead(), but translates character codes below 33, above 126 or equal 34 into their hex representation prepended by a backslash and the letter x. Backslashes are duplicated and the complete string is terminated by character code zero. This offers the ability to store binary data in printable strings.

Todo:
Very specific code, should be moved to an extra module to save ROM space of ordinary applications.
Parameters:
dev  Identifies the device that read from. A null pointer specifies the first on-chip UART. If this pointer is not null, it must have been retrieved by using the NutDeviceOpen() function.
data  Pointer to the buffer that receives the translated string.
size  Size of the buffer.
Returns:
The number of bytes read, 0 on timeouts and broken connections or -1 in case of an error. Due to code translation, the number of bytes read be less than the number of characters returned in the string.

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).

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 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).

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 NutDeviceWriteTran NUTDEVICE   dev,
CONST void *    data
 

Write a buffer to a specified device.

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

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 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. Once registered, stream devices must be accessed by calling NutDeviceOpen() first. However, network devices should not be opened but configured by calling NutNetIfConfig() or NutNetAutoConfig().

If called for a device, which had been registered previously, this function will update the base address and interrupt number. However, most device drivers do not expect these itemes being changed and may crash.

Note:
Virtual stream devices don't need to be registered.
Parameters:
dev  Pointer to the NUTDEVICE structure, which is provided by the device driver. Should point to
  • devUart0 for the first on-chip UART.
  • devUart1 for the second on-chip UART.
  • devUarts[0-7] for one of the 8 SPI UARTs.
  • devEth0 for the Realtek RTL8019AS Ethernet device.
  • devEth1 for the SMSC LAN91C111 Ethernet device.
Parameters:
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. The function returns -1 if the device had been registered previously or the NUTDEVICE structure is invalid.
Examples:
adds/app/flash, adds/app/keys, adds/app/lcd, adds/app/rtc, and adds/app/term.


Generated on Thu Jan 30 22:30:58 2003 for EduNet by doxygen1.2.18