[209] | 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, 0x0, "2400", NULL },
|
---|
| 15 | { 4800, 0xff, "4800", NULL },
|
---|
| 16 | { 9600, 0x1, "9600", NULL },
|
---|
| 17 | { 19200, 0xff, "19.2K", "19K" },
|
---|
| 18 | { 38400, 0x2, "38.4K", "38K" },
|
---|
| 19 | { 115200, 0x3, "115.2K", "115K" },
|
---|
| 20 | { 230400, 0xff, "230.4K", "230K" },
|
---|
| 21 | { 460800, 0x1, "460.8K", "460K" },
|
---|
| 22 | { 0, 0, NULL, NULL }
|
---|
| 23 | };
|
---|
| 24 |
|
---|
| 25 | struct baudRate *baudRateMatchString( char *str )
|
---|
| 26 | {
|
---|
| 27 | struct baudRate *b;
|
---|
| 28 |
|
---|
| 29 | unsigned long a = atol( str );
|
---|
| 30 | if( a )
|
---|
| 31 | {
|
---|
| 32 | for( b = supportedBaudRates; b->rate; b++ )
|
---|
| 33 | if( b->rate == a )
|
---|
| 34 | return( b );
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | for( b = supportedBaudRates; b->rate; b++ )
|
---|
| 38 | if( !stricmp( str, b->display ) || (b->altSelection && !stricmp( str, b->altSelection )) )
|
---|
| 39 | return( b );
|
---|
| 40 |
|
---|
| 41 | return( NULL );
|
---|
| 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->rate ? b : NULL );
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 |
|
---|