AHDLC Driver. More...
Defines | |
#define | IN_ACC_MAP(c, m) (( ((uint8_t) (c)) < 0x20) && ((m) & (1UL << (c))) != 0) |
#define | NUT_THREAD_AHDLCRXSTACK 2048 |
Functions | |
int | AhdlcOutput (NUTDEVICE *dev, NETBUF *nb) |
Send HDLC frame. | |
int | AhdlcAt91IOCtl (NUTDEVICE *dev, int req, void *conf) |
Perform on-chip UART control functions. | |
int | AhdlcAt91Init (NUTDEVICE *dev) |
Initialize asynchronous HDLC device. | |
int | AhdlcAt91Read (NUTFILE *fp, void *buffer, int size) |
Read from the asynchronous HDLC device. | |
int | AhdlcAt91Put (NUTDEVICE *dev, const void *buffer, int len, int pflg) |
Write to the asynchronous HDLC device. | |
int | AhdlcAt91Write (NUTFILE *fp, const void *buffer, int len) |
Write to the asynchronous HDLC device. | |
int | AhdlcAt91Write_P (NUTFILE *fp, PGM_P buffer, int len) |
Write to the asynchronous HDLC device. | |
NUTFILE * | AhdlcAt91Open (NUTDEVICE *dev, const char *name, int mode, int acc) |
Open the asynchronous HDLC device. | |
int | AhdlcAt91Close (NUTFILE *fp) |
Close the asynchronous HDLC device. | |
Variables | |
NUTDEVICE | devAhdlc1 |
Device information structure. | |
NUTDEVICE | devAhdlc0 |
Device information structure. | |
NUTDEVICE | devAhdlc1 |
Device information structure. | |
UART1 RTS Handshake Control | |
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. | |
#define | IN_ACC_MAP(c, m) in_acc_map(c, &(m)) |
#define | NUT_THREAD_AHDLCRXSTACK 512 |
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).
#define IN_ACC_MAP | ( | c, | |
m | |||
) | (( ((uint8_t) (c)) < 0x20) && ((m) & (1UL << (c))) != 0) |
Checks the 32-bit ACCM to see if the byte needs un-escaping
#define NUT_THREAD_AHDLCRXSTACK 2048 |
Referenced by AhdlcAt91Init().
#define IN_ACC_MAP | ( | c, | |
m | |||
) | in_acc_map(c, &(m)) |
Checks the 32-bit ACCM to see if the byte needs un-escaping
#define NUT_THREAD_AHDLCRXSTACK 512 |
Referenced by AhdlcAvrInit().
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(). |
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.
Referenced by AhdlcRx().
void AhdlcRx | ( | void * | arg | ) |
Asynchronous HDLC receiver thread.
Running at high priority.
References AHDLC_ESCAPE, AHDLC_FLAG, AHDLC_GOODFCS, AHDLC_INITFCS, AHDLC_TRANS, AhdlcOutput(), _AHDLCDCB::dcb_mf_evt, _AHDLCDCB::dcb_modeflags, _AHDLCDCB::dcb_rd_idx, _AHDLCDCB::dcb_rtimeout, _AHDLCDCB::dcb_rx_buf, _AHDLCDCB::dcb_rx_idx, _AHDLCDCB::dcb_rx_mru, _AHDLCDCB::dcb_rx_rdy, _NUTDEVICE::dev_dcb, _NUTDEVICE::dev_icb, _NUTDEVICE::dev_ioctl, ifnet::if_recv, ifnet::if_send, LCP_LOWERDOWN, LCP_LOWERUP, memcpy(), _NETBUF::nb_dl, NBAF_DATALINK, NutEventWait(), NutHeapAlloc, NutHeapFree, NutNetBufAlloc(), NutSleep(), NutThreadSetPriority(), PRG_RDB, UART_MF_RAWMODE, and _NBDATA::vp.
Referenced by AhdlcAt91Init(), and AhdlcAvrInit().
int AhdlcAt91IOCtl | ( | 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. |
References _AHDLCDCB::dcb_base, _AHDLCDCB::dcb_mf_evt, _AHDLCDCB::dcb_modeflags, _AHDLCDCB::dcb_rtimeout, _AHDLCDCB::dcb_rx_rdy, _AHDLCDCB::dcb_wtimeout, _NUTDEVICE::dev_dcb, _NUTDEVICE::dev_icb, _NUTDEVICE::dev_type, devUsartAt910, HDLC_GETIFNET, HDLC_SETIFNET, IFTYP_CHAR, IFTYP_NET, inr, NutEventPost(), NutGetCpuClock(), outr, rc, UART_GETFLOWCONTROL, UART_GETLOCALECHO, UART_GETRAWMODE, UART_GETREADTIMEOUT, UART_GETSPEED, UART_GETSTATUS, UART_GETWRITETIMEOUT, UART_MF_LOCALECHO, UART_MF_RAWMODE, UART_SETFLOWCONTROL, UART_SETLOCALECHO, UART_SETRAWMODE, UART_SETREADTIMEOUT, UART_SETSPEED, UART_SETSTATUS, UART_SETWRITETIMEOUT, US_BRGR_OFF, US_CLKS, US_CLKS_MCK, US_CLKS_MCK8, US_MR_OFF, and USART1_BASE.
int AhdlcAt91Init | ( | 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. |
References _BV, AhdlcRx(), _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, memset(), NUT_AHDLC_RECV_DMA_SIZE, NUT_THREAD_AHDLCRXSTACK, NUT_THREAD_STACK_ADD, NUT_THREAD_STACK_MULT, NutGetCpuClock(), NutHeapAlloc, NutHeapFree, NutRegisterIrqHandler(), NutThreadCreate(), outr, PDC_RXTDIS, PERIPH_PTCR_OFF, PERIPH_RCR_OFF, PERIPH_RNCR_OFF, PERIPH_RNPR_OFF, PERIPH_RPR_OFF, PMC_PCER, rc, SIG_UART, US1_BRGR, US1_CR, US1_ID, US1_IDR, US1_MR, US_CHMODE_NORMAL, US_CHRL_8, US_GPIO_PINS, US_NBSTOP_1, US_PAR_NO, US_RSTRX, US_RSTTX, US_RXDIS, US_TXDIS, and USART1_BASE.
int AhdlcAt91Read | ( | 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. |
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, NutEventWait(), and rc.
int AhdlcAt91Put | ( | 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. |
References _NUTDEVICE::dev_dcb, NutEnterCritical, NutExitCritical, outr, PRG_RDB, rc, US1_IER, and US_TXRDY.
Referenced by AhdlcAt91Write(), and AhdlcAt91Write_P().
int AhdlcAt91Write | ( | 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. |
References AhdlcAt91Put(), and _NUTFILE::nf_dev.
int AhdlcAt91Write_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. |
References AhdlcAt91Put(), 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. |
References _NUTFILE::nf_dev, _NUTFILE::nf_fcb, _NUTFILE::nf_next, NutEnterCritical, NutExitCritical, NUTFILE_EOF, NutHeapAlloc, NutIrqEnable(), outr, PDC_RXTEN, PERIPH_PTCR_OFF, SIG_UART, UART_RECEIVER_TIMEOUT, US1_CR, US1_IER, US1_RTOR, US_ENDRX, US_RXBUFF, US_RXEN, US_STTTO, US_TIMEOUT, US_TXEN, and USART1_BASE.
int AhdlcAt91Close | ( | 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(). |
References NUTFILE_EOF, and NutHeapFree.
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. |
References _AHDLCDCB::dcb_mf_evt, _AHDLCDCB::dcb_modeflags, _AHDLCDCB::dcb_rtimeout, _AHDLCDCB::dcb_rx_mru, _AHDLCDCB::dcb_rx_rdy, _AHDLCDCB::dcb_tx_accm, _AHDLCDCB::dcb_tx_mru, _AHDLCDCB::dcb_wtimeout, _NUTDEVICE::dev_base, _NUTDEVICE::dev_dcb, _NUTDEVICE::dev_icb, _NUTDEVICE::dev_type, devUart0, HDLC_GETIFNET, HDLC_GETTXACCM, HDLC_SETIFNET, HDLC_SETTXACCM, IFTYP_CHAR, IFTYP_NET, inb, NutEventPost(), NutGetCpuClock(), outb, rc, UART_GETDATABITS, UART_GETFLOWCONTROL, UART_GETLOCALECHO, UART_GETPARITY, UART_GETRAWMODE, UART_GETREADTIMEOUT, UART_GETSPEED, UART_GETSTATUS, UART_GETSTOPBITS, UART_GETWRITETIMEOUT, UART_MF_LOCALECHO, UART_MF_RAWMODE, 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. |
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, _NUTDEVICE::dev_icb, EICR, memset(), NUT_THREAD_AHDLCRXSTACK, NUT_THREAD_STACK_ADD, NUT_THREAD_STACK_MULT, NutHeapAlloc, NutHeapFree, NutRegisterIrqHandler(), NutThreadCreate(), rc, 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. |
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, NutEventWait(), and rc.
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. |
References _NUTDEVICE::dev_base, _NUTDEVICE::dev_dcb, PRG_RDB, rc, 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. |
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. |
References AhdlcAvrPut(), 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. |
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(). |
References _NUTDEVICE::dev_base, _NUTFILE::nf_dev, NUTFILE_EOF, NutHeapFree, and sbi.
{ 0, {'u', 'a', 'r', 't', '1', 0, 0, 0, 0}, IFTYP_CHAR, 1, 0, 0, &dcb_ahdlc, AhdlcAt91Init, AhdlcAt91IOCtl, AhdlcAt91Read, AhdlcAt91Write, AhdlcAt91Open, AhdlcAt91Close, 0 }
Device information structure.
A pointer to this structure must be passed to NutRegisterDevice() to bind this device driver to the Nut/OS kernel.
{ 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.
{ 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.