Collaboration diagram for AHDLC:
![]() |
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. | |
NUTFILE * | AhdlcAvrOpen (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 IN_ACC_MAP | ( | c, | |||
m | ) | (( ((u_char) (c)) < 0x20) && ((m) & (1UL << (c))) != 0) |
Checks the 32-bit ACCM to see if the byte needs un-escaping
Definition at line 150 of file ahdlcavr.c.
#define NUT_THREAD_AHDLCRXSTACK 512 |
Send HDLC frame.
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(). |
Definition at line 346 of file ahdlcavr.c.
References AHDLC_FLAG, AHDLC_INITFCS, _AHDLCDCB::dcb_modeflags, _AHDLCDCB::dcb_tx_mru, _NUTDEVICE::dev_dcb, _NETBUF::nb_ap, _NETBUF::nb_dl, _NETBUF::nb_nw, _NETBUF::nb_tp, _NBDATA::sz, UART_MF_RAWMODE, and _NBDATA::vp.
AhdlcRx | ( | void * | arg | ) |
Asynchronous HDLC receiver thread.
Running at high priority.
Definition at line 401 of file ahdlcavr.c.
References AHDLC_INITFCS, _AHDLCDCB::dcb_mf_evt, _AHDLCDCB::dcb_rtimeout, _AHDLCDCB::dcb_rx_mru, _NUTDEVICE::dev_dcb, _NUTDEVICE::dev_icb, NutEventWait(), NutHeapAlloc(), NutSleep(), and NutThreadSetPriority().
Referenced by AhdlcAvrInit().
int AhdlcAvrIOCtl | ( | NUTDEVICE * | dev, | |
int | req, | |||
void * | conf | |||
) |
Perform on-chip UART control functions.
dev | Identifies the device that receives the device-control function. | |
req | Requested control function. May be set to one of the following constants:
| |
conf | Points to a buffer that contains any data required for the given control function or receives data from that function. |
Definition at line 778 of file ahdlcavr.c.
References _AHDLCDCB::dcb_mf_evt, _AHDLCDCB::dcb_modeflags, _AHDLCDCB::dcb_rtimeout, _AHDLCDCB::dcb_rx_rdy, _AHDLCDCB::dcb_wtimeout, _NUTDEVICE::dev_base, _NUTDEVICE::dev_dcb, _NUTDEVICE::dev_icb, _NUTDEVICE::dev_type, devUart0, HDLC_GETIFNET, HDLC_SETIFNET, IFTYP_CHAR, IFTYP_NET, inp, NutEventPost(), NutGetCpuClock(), outp, UART_GETDATABITS, UART_GETFLOWCONTROL, UART_GETLOCALECHO, UART_GETPARITY, UART_GETRAWMODE, UART_GETREADTIMEOUT, UART_GETSPEED, UART_GETSTATUS, UART_GETSTOPBITS, UART_GETWRITETIMEOUT, UART_MF_LOCALECHO, UART_SETDATABITS, UART_SETFLOWCONTROL, UART_SETLOCALECHO, UART_SETPARITY, UART_SETRAWMODE, UART_SETREADTIMEOUT, UART_SETSPEED, UART_SETSTATUS, UART_SETSTOPBITS, UART_SETWRITETIMEOUT, and UBRR.
Referenced by AhdlcAvrInit().
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.
dev | Identifies the device to initialize. |
Definition at line 1023 of file ahdlcavr.c.
References AhdlcAvrIOCtl(), AhdlcRx(), cbi, _AHDLCDCB::dcb_base, _AHDLCDCB::dcb_rx_buf, _AHDLCDCB::dcb_rx_mru, _AHDLCDCB::dcb_tx_accm, _AHDLCDCB::dcb_tx_buf, _AHDLCDCB::dcb_tx_mru, _NUTDEVICE::dev_base, _NUTDEVICE::dev_dcb, EICR, memset(), NUT_THREAD_AHDLCRXSTACK, NutHeapAlloc(), NutHeapFree(), NutRegisterIrqHandler(), NutThreadCreate(), sbi, sig_UART0_DATA, sig_UART0_RECV, sig_UART1_DATA, sig_UART1_RECV, and UART_SETSPEED.
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.
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. |
Definition at line 1161 of file ahdlcavr.c.
References _AHDLCDCB::dcb_rd_idx, _AHDLCDCB::dcb_rtimeout, _AHDLCDCB::dcb_rx_buf, _AHDLCDCB::dcb_rx_idx, _AHDLCDCB::dcb_rx_rdy, _NUTDEVICE::dev_dcb, _NUTFILE::nf_dev, and NutEventWait().
int AhdlcAvrPut | ( | NUTDEVICE * | dev, | |
CONST void * | buffer, | |||
int | len, | |||
int | pflg | |||
) |
Write to the asynchronous HDLC device.
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. |
Definition at line 1201 of file ahdlcavr.c.
References CONST, _NUTDEVICE::dev_base, _NUTDEVICE::dev_dcb, PRG_RDB, sbi, UCR, and UDRIE.
Referenced by AhdlcAvrWrite(), and AhdlcAvrWrite_P().
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.
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. |
Definition at line 1255 of file ahdlcavr.c.
References AhdlcAvrPut(), and _NUTFILE::nf_dev.
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.
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. |
Definition at line 1281 of file ahdlcavr.c.
References AhdlcAvrPut(), CONST, and _NUTFILE::nf_dev.
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.
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. |
Definition at line 1302 of file ahdlcavr.c.
References cbi, _NUTDEVICE::dev_base, _NUTFILE::nf_dev, _NUTFILE::nf_fcb, _NUTFILE::nf_next, NUTFILE_EOF, and NutHeapAlloc().
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.
fp | Pointer to a _NUTFILE structure, obtained by a previous call to UsartOpen(). |
Definition at line 1348 of file ahdlcavr.c.
References _NUTDEVICE::dev_base, _NUTFILE::nf_dev, NUTFILE_EOF, NutHeapFree(), and sbi.
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 }
A pointer to this structure must be passed to NutRegisterDevice() to bind this device driver to the Nut/OS kernel.
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 }
A pointer to this structure must be passed to NutRegisterDevice() to bind this device driver to the Nut/OS kernel.