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

AHDLC
[Serial]

Collaboration diagram for AHDLC:


Detailed Description

AHDLC Driver.

This code contains a modified UART driver with some speed optimizations for PPP, like table driven FCS calculation. It also implements simple modem handshaking (RTS, CTS and DTR).


Defines

#define IN_ACC_MAP(c, m)   (( ((u_char) (c)) < 0x20) && ((m) & (1UL << (c))) != 0)
#define NUT_THREAD_AHDLCRXSTACK   512

Functions

int AhdlcOutput (NUTDEVICE *dev, NETBUF *nb)
 Send HDLC frame.
void AhdlcRx (void *arg)
 Asynchronous HDLC receiver thread.
int AhdlcAvrIOCtl (NUTDEVICE *dev, int req, void *conf)
 Perform on-chip UART control functions.
int AhdlcAvrInit (NUTDEVICE *dev)
 Initialize asynchronous HDLC device.
int AhdlcAvrRead (NUTFILE *fp, void *buffer, int size)
 Read from the asynchronous HDLC device.
int AhdlcAvrPut (NUTDEVICE *dev, CONST void *buffer, int len, int pflg)
 Write to the asynchronous HDLC device.
int AhdlcAvrWrite (NUTFILE *fp, CONST void *buffer, int len)
 Write to the asynchronous HDLC device.
int AhdlcAvrWrite_P (NUTFILE *fp, PGM_P buffer, int len)
 Write to the asynchronous HDLC device.
NUTFILEAhdlcAvrOpen (NUTDEVICE *dev, CONST char *name, int mode, int acc)
 Open the asynchronous HDLC device.
int AhdlcAvrClose (NUTFILE *fp)
 Close the asynchronous HDLC device.

Variables

NUTDEVICE devAhdlc0
 Device information structure.
NUTDEVICE devAhdlc1
 Device information structure.


Define Documentation

#define IN_ACC_MAP c,
 )     (( ((u_char) (c)) < 0x20) && ((m) & (1UL << (c))) != 0)
 

Checks the 32-bit ACCM to see if the byte needs un-escaping


Function Documentation

int AhdlcOutput NUTDEVICE dev,
NETBUF nb
 

Send HDLC frame.

Parameters:
dev Identifies the device to use.
nb Network buffer structure containing the packet to be sent. The structure must have been allocated by a previous call NutNetBufAlloc().
Returns:
0 on success, -1 in case of any errors.

AhdlcRx void *  arg  ) 
 

Asynchronous HDLC receiver thread.

Running at high priority.

int AhdlcAvrIOCtl NUTDEVICE dev,
int  req,
void *  conf
 

Perform on-chip UART control functions.

Parameters:
dev Identifies the device that receives the device-control function.
req Requested control function. May be set to one of the following constants:
  • UART_SETSPEED, conf points to an u_long value containing the baudrate.
  • UART_GETSPEED, conf points to an u_long value receiving the current baudrate.
  • UART_SETDATABITS, conf points to an u_long value containing the number of data bits, 5, 6, 7 or 8.
  • UART_GETDATABITS, conf points to an u_long value receiving the number of data bits, 5, 6, 7 or 8.
  • UART_SETPARITY, conf points to an u_long value containing the parity, 0 (no), 1 (odd) or 2 (even).
  • UART_GETPARITY, conf points to an u_long value receiving the parity, 0 (no), 1 (odd) or 2 (even).
  • UART_SETSTOPBITS, conf points to an u_long value containing the number of stop bits 1 or 2.
  • UART_GETSTOPBITS, conf points to an u_long value receiving the number of stop bits 1 or 2.
  • UART_SETSTATUS, conf points to an u_long value containing the changes for the control lines.
  • UART_GETSTATUS, conf points to an u_long value receiving the state of the control lines and the device.
  • UART_SETREADTIMEOUT, conf points to an u_long value containing the read timeout.
  • UART_GETREADTIMEOUT, conf points to an u_long value receiving the read timeout.
  • UART_SETWRITETIMEOUT, conf points to an u_long value containing the write timeout.
  • UART_GETWRITETIMEOUT, conf points to an u_long value receiving the write timeout.
  • UART_SETLOCALECHO, conf points to an u_long value containing 0 (off) or 1 (on).
  • UART_GETLOCALECHO, conf points to an u_long value receiving 0 (off) or 1 (on).
  • UART_SETFLOWCONTROL, conf points to an u_long value containing combined UART_FCTL_ values.
  • UART_GETFLOWCONTROL, conf points to an u_long value containing receiving UART_FCTL_ values.
  • UART_SETCOOKEDMODE, conf points to an u_long value containing 0 (off) or 1 (on).
  • UART_GETCOOKEDMODE, conf points to an u_long value receiving 0 (off) or 1 (on).
  • UART_SETRAWMODE, conf points to an u_long value containing 0 (off) or 1 (on).
  • UART_GETRAWMODE, conf points to an u_long value receiving 0 (off) or 1 (on).
  • HDLC_SETIFNET, conf points to a pointer containing the address of the network device's NUTDEVICE structure.
  • HDLC_GETIFNET, conf points to a pointer receiving the address of the network device's NUTDEVICE structure.
conf Points 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.
Warning:
Timeout values are given in milliseconds and are limited to the granularity of the system timer.
Note:
For ATmega103, only 8 data bits, 1 stop bit and no parity are allowed.

int AhdlcAvrInit NUTDEVICE dev  ) 
 

Initialize asynchronous HDLC device.

This function will be called during device registration. It initializes the hardware, registers all required interrupt handlers and initializes all internal data structures used by this driver.

Parameters:
dev Identifies the device to initialize.
Returns:
0 on success, -1 otherwise.

int AhdlcAvrRead NUTFILE fp,
void *  buffer,
int  size
 

Read from the asynchronous HDLC device.

This function is called by the low level input routines of the C runtime library, using the _NUTDEVICE::dev_read entry.

The function may block the calling thread until at least one character has been received or a timeout occurs.

It is recommended to set a proper read timeout with software handshake. In this case a timeout may occur, if the communication peer lost our last XON character. The application may then use ioctl() to disable the receiver and do the read again. This will send out another XON.

Parameters:
fp Pointer to a _NUTFILE structure, obtained by a previous call to AhdlcOpen().
buffer Pointer to the buffer that receives the data. If zero, then all characters in the input buffer will be removed.
size Maximum number of bytes to read.
Returns:
The number of bytes read, which may be less than the number of bytes specified. A return value of -1 indicates an error, while zero is returned in case of a timeout.

int AhdlcAvrPut NUTDEVICE dev,
CONST void *  buffer,
int  len,
int  pflg
 

Write to the asynchronous HDLC device.

Parameters:
dev Pointer to a previously registered NUTDEVICE structure.
buffer Pointer the data to write.
len Number of data bytes to write.
pflg If this flag is set, then the buffer is located in program space.
Returns:
The number of bytes written. In case of a write timeout, this may be less than the specified length.

int AhdlcAvrWrite NUTFILE fp,
CONST void *  buffer,
int  len
 

Write to the asynchronous HDLC device.

This function is called by the low level output routines of the C runtime library, using the _NUTDEVICE::dev_write entry.

The function may block the calling thread.

Parameters:
fp Pointer to a _NUTFILE structure, obtained by a previous call to AhldcOpen().
buffer Pointer to the data to be written. If zero, then the output buffer will be flushed.
len Number of bytes to write.
Returns:
The number of bytes written, which may be less than the number of bytes specified if a timeout occured. A return value of -1 indicates an error.

int AhdlcAvrWrite_P NUTFILE fp,
PGM_P  buffer,
int  len
 

Write to the asynchronous HDLC device.

Similar to AhdlcWrite() except that the data is located in program memory.

This function is called by the low level output routines of the C runtime library, using the _NUTDEVICE::dev_write_P entry.

The function may block the calling thread.

Parameters:
fp Pointer to a NUTFILE structure, obtained by a previous call to AhdlcOpen().
buffer Pointer to the data in program space to be written.
len Number of bytes to write.
Returns:
The number of bytes written, which may be less than the number of bytes specified if a timeout occured. A return value of -1 indicates an error.

NUTFILE* AhdlcAvrOpen NUTDEVICE dev,
CONST char *  name,
int  mode,
int  acc
 

Open the asynchronous HDLC device.

This function is called by the low level open routine of the C runtime library, using the _NUTDEVICE::dev_open entry.

Parameters:
dev Pointer to the NUTDEVICE structure.
name Ignored, should point to an empty string.
mode Operation mode. Any of the following values may be or-ed:
acc Ignored, should be zero.
Returns:
Pointer to a NUTFILE structure if successful or NUTFILE_EOF otherwise.

int AhdlcAvrClose NUTFILE fp  ) 
 

Close the asynchronous HDLC device.

This function is called by the low level close routine of the C runtime library, using the _NUTDEVICE::dev_close entry.

Parameters:
fp Pointer to a _NUTFILE structure, obtained by a previous call to UsartOpen().
Returns:
0 on success or -1 otherwise.

Todo:
We may support shared open and use dev_irq as an open counter.


Variable Documentation

NUTDEVICE devAhdlc0
 

Initial value:

 {
    0,                          
    {'u', 'a', 'r', 't', '0', 0, 0, 0, 0},      
    IFTYP_CHAR,                 
    0,                          
    0,                          
    0,                          
    &dcb_ahdlc,                 
    AhdlcAvrInit,               
    AhdlcAvrIOCtl,              
    AhdlcAvrRead,               
    AhdlcAvrWrite,              
    AhdlcAvrWrite_P,            
    AhdlcAvrOpen,               
    AhdlcAvrClose,              
    0                           
}
Device information structure.

A pointer to this structure must be passed to NutRegisterDevice() to bind this device driver to the Nut/OS kernel.

NUTDEVICE devAhdlc1
 

Initial value:

 {
    0,                          
    {'u', 'a', 'r', 't', '1', 0, 0, 0, 0},      
    IFTYP_CHAR,                 
    1,                          
    0,                          
    0,                          
    &dcb_ahdlc,                 
    AhdlcAvrInit,               
    AhdlcAvrIOCtl,              
    AhdlcAvrRead,               
    AhdlcAvrWrite,              
    AhdlcAvrWrite_P,            
    AhdlcAvrOpen,               
    AhdlcAvrClose,              
    0                           
}
Device information structure.

A pointer to this structure must be passed to NutRegisterDevice() to bind this device driver to the Nut/OS kernel.


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