1 | //====================================================================== |
---|
2 | // |
---|
3 | // Project: XTIDE Universal BIOS, Serial Port Server |
---|
4 | // |
---|
5 | // File: Serial.cpp - Generic functions for dealing with serial communications |
---|
6 | // |
---|
7 | |
---|
8 | #include "library.h" |
---|
9 | #include <stdlib.h> |
---|
10 | #include <string.h> |
---|
11 | |
---|
12 | struct baudRate supportedBaudRates[] = |
---|
13 | { |
---|
14 | { 2400, 0x30, "2400" }, |
---|
15 | { 4800, 0x18, "4800" }, |
---|
16 | { 9600, 0xc, "9600" }, |
---|
17 | { 19200, 0xff, "19.2K" }, |
---|
18 | { 28800, 0x4, "28.8K" }, |
---|
19 | { 38400, 0xff, "38.4K" }, |
---|
20 | { 57600, 0x2, "57.6K" }, |
---|
21 | { 76800, 0xff, "76.8K" }, |
---|
22 | { 115200, 0x1, "115.2K" }, |
---|
23 | { 153600, 0xff, "153.6K" }, |
---|
24 | { 230400, 0xff, "230.4K" }, |
---|
25 | { 460800, 0xff, "460.8K" }, |
---|
26 | { 0, 0, "Unknown" }, |
---|
27 | }; |
---|
28 | |
---|
29 | struct baudRate *baudRateMatchString( char *str ) |
---|
30 | { |
---|
31 | struct baudRate *b; |
---|
32 | |
---|
33 | unsigned long a = atol( str ); |
---|
34 | if( a ) |
---|
35 | { |
---|
36 | for( b = supportedBaudRates; b->rate; b++ ) |
---|
37 | if( b->rate == a || (b->rate / 1000) == a || ((b->rate + 500) / 1000) == a ) |
---|
38 | return( b ); |
---|
39 | } |
---|
40 | |
---|
41 | return( b ); |
---|
42 | } |
---|
43 | |
---|
44 | struct baudRate *baudRateMatchDivisor( unsigned char divisor ) |
---|
45 | { |
---|
46 | struct baudRate *b; |
---|
47 | |
---|
48 | for( b = supportedBaudRates; b->rate && b->divisor != divisor; b++ ) |
---|
49 | ; |
---|
50 | |
---|
51 | return( b ); |
---|
52 | } |
---|
53 | |
---|
54 | |
---|