📄 async.doc
字号:
/* alloc port structure & ring buffer memory */
port = malloc(sizeof(ASYNC));
AllocRingBuffer(port, 4096, 2048, 1);
/* empty parameter string causes port to be opened at
its current settings */
rcode = async_open(port, COM1, "");
if (rcode != R_OK)
{
printf("\nAsync_open failed, exit code = %d", rcode);
exit(rcode);
}
printf(
"\nBaud, parity, data, stop bits = %s\n", port->BPDSstr);
async_open
---------------------------------------------------------------
Returns:
R_OK (0) - the port was opened with no errors.
R_NOMEM - a NULL pointer was passed as the address
of the ring buffers. Probable causes are either
failing to initialize the port structure ring
buffer variables or assigning the RingSeg and
RingOfst structure a NULL pointer. This could
occur if you use the AllocRingBuffer function or
something similar and the call to malloc fails.
R_BAUDERR - the passed baud rate in the BPDS string
was invalid. Some possible reasons for this error
are leading spaces in the parameter string or use
of commas. "115200N81" is correct. " 115200N81"
and "115,200N81" are both incorrect.
R_PARITYERR - an invalid character was found in the
parameter string where the parity should have
been. Commas or spaces in the parameter string
are possible causes. Valid parity settings are N
- none, E - even, or O - odd. See R_BAUDERR.
R_DTABITERR - an invalid number of data bits was spec-
ified. Only settings of 7 or 8 are supported.
R_STPBITERR - an invalid number of stop bits was spec-
ified. Stop bits must be set to either 1 or 2.
R_IRQUSED - an attempt was made to open two ports that
use the same IRQ line.
R_VCTRUSED - an attempt was made to open two ports
that use the same interrupt vector.
R_NOPORT - an attempt was made to open more than 2
simultaneous ports.
R_PORTUSED - an attempt was made to open two ports
that have the same I/O address.
R_UARTERR - an attempt was made to open a port that is
stuck in an interrupt condition (see the notes on
problems with the WD16550 at the beginning of this
documentation ).
async_open
---------------------------------------------------------------
Remarks (16550 support):
This function now automatically detects the presence
of a 16550 UART and enables FIFO operation if one is
detected. By ORing either 0x8000 or 0x4000 with the
ComBase argument, you can change the default of auto-
enabling FIFO mode. If 0x8000 is ORed with the
ComBase argument (ex: 0x8000|0x3f8), no attempt is
made to detect a 16550 and no changes are made to the
mode of operation of the 16550 if one is present. If
this bit is set, none of the functions or bits
relating to the 16550 UART will be valid. If 0x4000
is ORed with the ComBase, the 16550 will be forced
into non-FIFO mode.
ORing 0x2000 with the ComBase parameter will open the
port with MSR interrupts disabled. ORing the ComBase
parameter with 0x1000 will open the port with LSR
interrupts disabled. See the notes on the WD16550 at
the beginning of this documentation for why this may
be desired and the side effects of opening a port with
MSR interrupts disabled.
When async_open is called, the FIFOs are momentarily
disabled and then re-enabled with the receive trigger
level set to 1 byte. In versions of MCOMM prior to
5.40, the FIFOs were not reset if they were already
on. Resetting the FIFOs was added to correct
occasional rare problems with the port not opening.
/* detect 16550, enable FIFOs if present */
async_open(PortPtr, 0x3f8, IRQ, Vector, Params);
/* do not attempt to detect 16550 */
async_open(PortPtr, 0x8000|0x3f8, IRQ, Vctr, Params);
/* detect 16550, disable FIFOs if present */
async_open(PortPtr, 0x4000|0x3f8, IRQ, Vctr, Params);
/* open port, disable MSR interrupts */
async_open(PortPtr, 0x2000|0x3f8, IRQ, Vctr, Params);
/* open port, disable MSR interrupts and FIFOs */
async_open(PortPtr, 0x6000|0x3f8, IRQ, Vctr, Params);
async_open
---------------------------------------------------------------
Remarks (versions previous to 5.00):
There are some major differences in the async_open
function in MCOMM5 and previous versions of the rou-
tines. The two most major ones are that the parame-
ters passed to the function are different and it is
now necessary to allocate the memory for the ring
buffers before calling the function. To make things
simpler, COM1 and COM2 are defined in COMM.H and the
function, AllocRingBuffer, is provided. The COM1 and
COM2 definitions satisfy the requirements for the 2nd,
3rd, and 4th parameters required by the function. For
ports other than the standard COM1 and COM2, it is
necessary to list the individual arguments. The func-
tion, AllocRingBuffer, is provided in C source form on
the disk and included in the COMM_x libraries. This
function allocates the ring buffer memory and initial-
izes the required port structure members.
The return values for async_open are different and may
have a different meaning than in earlier versions.
If a port is opened with an empty parameter string
(using "" for the parameters), then the port is opened
at its current settings and the port member BPDSstr is
set to the string representation of those values.
Async_open no longer checks the BIOS ram area at 40:0
to verify that a port actually exists. There were too
many compatibles that did not store the proper values
there.
The maximum combined size of the receive and transmit
buffers for each port is 32K - 1.
FAR ring buffers in small and medium memory model
programs is now supported. Use of FAR buffers does
not in any way affect the speed of the routines.
async_peek
---------------------------------------------------------------
Purpose: Indexed receive ring buffer look ahead function.
Format: int async_peek(port, index);
ASYNC *port; Pointer to ASYNC structure
int index; Index value
Examples:
ASYNC *port;
char ch, buf[10];
int i;
/* peek next char in receive ring buffer */
ch = async_peek(port, 0);
/* peek next 10 chars in receive ring buffer */
for (i = 0; i < 10; i++)
buf[i] = async_peek(port, i);
Returns: This function returns the character in the receive
ring buffer at the indexed position. If an attempt is
made to peek deeper in the ring buffer than there are
characters in the ring buffer, -1 (0xffff) is
returned.
Remarks: No characters are removed from the ring buffer by this
function.
The index value is 0 based.
To avoid confusing the character, '\0xff', from the
error return value, 0xffff, use an integer size
variable for the return value. The character '\0xff'
is returned as 0x00ff and the error condition is
returned as 0xffff.
async_regs
---------------------------------------------------------------
Purpose: Provides direct access to the UART registers.
Format: int async_regs(port, reg_ofst, value);
ASYNC *port; Pointer to ASYNC structure
int reg_ofst; Offset of register from base adrs
int value; Value to write or -1 if reading
Examples:
ASYNC *port;
int LCRvalue;
/* read the line control register */
LCRvalue = async_regs(port, LCRreg, RDreg);
/* write a 0 to the modem control register */
async_regs(port, MCRreg, 0);
Returns: When reading a register, the return value is the value
of the UART register that was read. When writing a
register, the return value is undefined.
Remarks: The following values for register offsets are defined
in COMM.H for use with async_regs:
RXreg, TXreg - receive & transmit regs, value = 0
IERreg - interrupt enable register, value = 1
IIDreg - interrupt identification reg, value = 2
FCRreg - FIFO control register value = 2
LCRreg - line control register, value = 3
MCRreg - modem control register, value = 4
LSRreg - line status register, value = 5
MSRreg - modem status register, value = 6
LObaud - offset of low baud divisor, value = 0
HIbaud - offset of high baud divisor, value = 1
Also RDreg is defined as -1 for use when reading one
of the UART registers. See the examples. See
cautions on the following page before using this
function.
async_regs
---------------------------------------------------------------
Remarks (continued):
This function is provided primarily as a debugging
tool. Reading or writing to the UART registers while
operating in an interrupt driven mode can cause
several types of problems. Do not use this function
unless you know what you are doing. Do not read the
RXreg, IIDreg, LSRreg, or MSRreg on an open port
except for debugging purposes. Do not write any of
the registers.
The function may be used on a port that has not yet
been opened if the ComBase member of the port struc-
ture has been set. When async_regs is used with an
unopened port the UART registers may be read or writ-
ten without restriction.
async_reset
---------------------------------------------------------------
Purpose: Clear parity error bit, framing error bit, character
overrun bit, receive buffer overflow bit, and break
signal received bit in the the Stat1 byte.
Format: void async_reset(port);
ASYNC *port; Pointer to ASYNC structure
Example:
ASYNC *port;
if (error)
async_reset(port);
Returns: No return value
Remarks: This function is implemented as a macro. See also
async_rx and async_stat.
async_restart
---------------------------------------------------------------
Purpose: Re-initialize an already opened serial port
Format: void async_restart(port);
ASYNC *port; Pointer to ASYNC structure
Example:
ASYNC *port;
async_restart(port);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -