Download 1 - Moxa

Transcript
V2101 Series Linux
Programmer’s Guide
N is the multiplier for the standard UART register; here, it is any integer between 1 (912,600 bps)
and 18432 (50 bps).
To calculate non-standard baudrates, use formula B:
(B) Baudrate = 921600 ÷ (N+(M/8)) bps, where:
N is a the standard register divisor; this will be an integer between 1 and 18,432.
M is an integer between 0 and 7; the fraction M/8 will calculate the fractional rate to which the
secondary register will be adjusted to compensate for non-standard baudrates.
Sample Code Showing a Typical UART Configuration Script:
#define SET_MOXA_MUST_ENUM_VALUE(baseio, Value) { \
UCHAR
__oldlcr, __efr;
\
__oldlcr = inb((baseio)+UART_LCR);
\
outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
__efr = inb((baseio)+MOXA_MUST_EFR_REGISTER);
\
__efr &= ~MOXA_MUST_EFR_BANK_MASK;
\
__efr |= MOXA_MUST_EFR_BANK2;
\
outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
outb((UCHAR)(Value), (baseio)+MOXA_MUST_ENUM_REGISTER);\
outb(__oldlcr, (baseio)+UART_LCR);
\
}
quot =921600 / 100000; // here 100000 is want to set baud rate, 921600 is a constant
which is depended on hardware
outb(cval | UART_LCR_DLAB, info->base + UART_LCR); /* set DLAB *
/
outb(quot & 0xff, info->base + UART_DLL);
/* LS of divisor */
outb(quot >> 8, info->base + UART_DLM);
/* MS of divisor */
outb(cval, info->base + UART_LCR);
/* reset DLAB */
quot = 921600 % 100000;
quot *= 8;
if ( (quot % 100000) > (100000 / 2) ) {
quot /= 100000;
quot++;
} else {
quot /= 100000;
}
SET_MOXA_MUST_ENUM_VALUE(info->base, quot);
Example: Your serial device requires using a baudrate of 5340 bps and has a transmission tolerance of ±2 bps.
Can this computer be used with this device?
Solution: Set formula B to the desired baudrate and then solve for M.
5338 = 8 x 921600/K ==>
M = 1367.703259…
This shows that the supported baudrate closest to 5340 comes from setting K to 1367 or 1368.
M=1368
==>
Baudrate1 = 5336.842105...
M=1367
==>
Baudrate2 = 5340.746159…
Because (5338 – Baudrate1) < 2, this computer will transmit at this non-standard rate (Baudrate 1) within the
accuracy tolerance specified by the device.
Note that we can also use formula A to generate the so-called “standard” baudrates, which come from setting
M=0, and setting N equal to certain integers.
4-4