![]() |
Defines | |
#define | IN_ACC_MAP(c, m) (( ((uint8_t) (c)) < 0x20) && ((m) & (1UL << (c))) != 0) |
#define | NUT_THREAD_AHDLCRXSTACK 512 |
#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. | |
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. | |
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 | devAhdlc0 |
Device information structure. | |
NUTDEVICE | devAhdlc1 |
Device information structure. | |
NUTDEVICE | devAhdlc1 |
Device information structure. |
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
Definition at line 156 of file ahdlcavr.c.
#define NUT_THREAD_AHDLCRXSTACK 512 |
#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
Definition at line 170 of file at91_ahdlc.c.
#define NUT_THREAD_AHDLCRXSTACK 2048 |
Definition at line 173 of file at91_ahdlc.c.
int AhdlcOutput | ( | NUTDEVICE * | dev, | |
NETBUF * | nb | |||
) |
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 352 of file ahdlcavr.c.
References AHDLC_FLAG, AHDLC_INITFCS, and UART_MF_RAWMODE.
Referenced by AhdlcRx().
void AhdlcRx | ( | void * | arg | ) |
Asynchronous HDLC receiver thread.
Running at high priority.
Definition at line 407 of file ahdlcavr.c.
References AHDLC_ESCAPE, AHDLC_FLAG, AHDLC_GOODFCS, AHDLC_INITFCS, AHDLC_TRANS, AhdlcOutput(), LCP_LOWERDOWN, LCP_LOWERUP, memcpy(), NBAF_DATALINK, NutEventWait(), NutHeapAlloc, NutHeapFree, NutNetBufAlloc(), NutSleep(), NutThreadSetPriority(), PRG_RDB, and UART_MF_RAWMODE.
Referenced by AhdlcAt91Init(), and 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 784 of file ahdlcavr.c.
References 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_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. |
Definition at line 1029 of file ahdlcavr.c.
References AhdlcAvrIOCtl(), AhdlcRx(), cbi, EICR, memset(), NUT_THREAD_AHDLCRXSTACK, NUT_THREAD_STACK_ADD, NUT_THREAD_STACK_MULT, 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 1168 of file ahdlcavr.c.
References 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 1208 of file ahdlcavr.c.
References CONST, 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 1262 of file ahdlcavr.c.
References AhdlcAvrPut().
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 1288 of file ahdlcavr.c.
References AhdlcAvrPut(), and CONST.
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.
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 1309 of file ahdlcavr.c.
References cbi, 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 1355 of file ahdlcavr.c.
References NUTFILE_EOF, NutHeapFree, and sbi.
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. |
Definition at line 729 of file at91_ahdlc.c.
References devUsartAt910, HDLC_GETIFNET, HDLC_SETIFNET, IFTYP_CHAR, IFTYP_NET, inr, NutEventPost(), NutGetCpuClock(), outr, 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. |
Definition at line 879 of file at91_ahdlc.c.
References _BV, AhdlcRx(), 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, 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. |
Definition at line 982 of file at91_ahdlc.c.
References NutEventWait().
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. |
Definition at line 1022 of file at91_ahdlc.c.
References CONST, NutEnterCritical, NutExitCritical, outr, PRG_RDB, 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. |
Definition at line 1073 of file at91_ahdlc.c.
References AhdlcAt91Put().
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. |
Definition at line 1099 of file at91_ahdlc.c.
References AhdlcAt91Put(), and CONST.
NUTFILE* AhdlcAt91Open | ( | 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.
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 1120 of file at91_ahdlc.c.
References 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(). |
Definition at line 1160 of file at91_ahdlc.c.
References NUTFILE_EOF, and NutHeapFree.
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 }
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 }
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, AhdlcAt91Init, AhdlcAt91IOCtl, AhdlcAt91Read, AhdlcAt91Write, AhdlcAt91Open, AhdlcAt91Close, 0 }
A pointer to this structure must be passed to NutRegisterDevice() to bind this device driver to the Nut/OS kernel.
Definition at line 108 of file at91_ahdlc.c.