[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 |
|
---|
[376] | 8 | //
|
---|
[526] | 9 | // XTIDE Universal BIOS and Associated Tools
|
---|
| 10 | // Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
|
---|
[376] | 11 | //
|
---|
| 12 | // This program is free software; you can redistribute it and/or modify
|
---|
| 13 | // it under the terms of the GNU General Public License as published by
|
---|
| 14 | // the Free Software Foundation; either version 2 of the License, or
|
---|
| 15 | // (at your option) any later version.
|
---|
[526] | 16 | //
|
---|
[376] | 17 | // This program is distributed in the hope that it will be useful,
|
---|
| 18 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
[526] | 20 | // GNU General Public License for more details.
|
---|
[376] | 21 | // Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
| 22 | //
|
---|
| 23 |
|
---|
[209] | 24 | #include "library.h"
|
---|
| 25 | #include <stdlib.h>
|
---|
| 26 | #include <string.h>
|
---|
| 27 |
|
---|
[526] | 28 | struct baudRate supportedBaudRates[] =
|
---|
| 29 | {
|
---|
[233] | 30 | { 2400, 0x30, "2400" },
|
---|
| 31 | { 4800, 0x18, "4800" },
|
---|
| 32 | { 9600, 0xc, "9600" },
|
---|
| 33 | { 19200, 0xff, "19.2K" },
|
---|
| 34 | { 28800, 0x4, "28.8K" },
|
---|
| 35 | { 38400, 0xff, "38.4K" },
|
---|
| 36 | { 57600, 0x2, "57.6K" },
|
---|
| 37 | { 76800, 0xff, "76.8K" },
|
---|
| 38 | { 115200, 0x1, "115.2K" },
|
---|
| 39 | { 153600, 0xff, "153.6K" },
|
---|
| 40 | { 230400, 0xff, "230.4K" },
|
---|
| 41 | { 460800, 0xff, "460.8K" },
|
---|
[488] | 42 | { 921600, 0xff, "921.6K" },
|
---|
[233] | 43 | { 0, 0, "Unknown" },
|
---|
[209] | 44 | };
|
---|
| 45 |
|
---|
| 46 | struct baudRate *baudRateMatchString( char *str )
|
---|
| 47 | {
|
---|
| 48 | struct baudRate *b;
|
---|
[526] | 49 |
|
---|
[209] | 50 | unsigned long a = atol( str );
|
---|
| 51 | if( a )
|
---|
| 52 | {
|
---|
| 53 | for( b = supportedBaudRates; b->rate; b++ )
|
---|
[215] | 54 | if( b->rate == a || (b->rate / 1000) == a || ((b->rate + 500) / 1000) == a )
|
---|
[209] | 55 | return( b );
|
---|
| 56 | }
|
---|
| 57 |
|
---|
[233] | 58 | return( b );
|
---|
[209] | 59 | }
|
---|
| 60 |
|
---|
| 61 | struct baudRate *baudRateMatchDivisor( unsigned char divisor )
|
---|
| 62 | {
|
---|
| 63 | struct baudRate *b;
|
---|
| 64 |
|
---|
[526] | 65 | for( b = supportedBaudRates; b->rate && b->divisor != divisor; b++ )
|
---|
[209] | 66 | ;
|
---|
| 67 |
|
---|
[233] | 68 | return( b );
|
---|
[209] | 69 | }
|
---|
| 70 |
|
---|
| 71 |
|
---|