source: xtideuniversalbios/trunk/Serial_Server/library/Serial.cpp@ 469

Last change on this file since 469 was 376, checked in by gregli@…, 13 years ago

WIDE checkin... Added copyright and license information to sorce files, as per the GPL instructions for usage.

File size: 1.9 KB
Line 
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//
9// XTIDE Universal BIOS and Associated Tools
10// Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
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.
16//
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
20// GNU General Public License for more details.
21// Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22//
23
24#include "library.h"
25#include <stdlib.h>
26#include <string.h>
27
28struct baudRate supportedBaudRates[] =
29{
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" },
42 { 0, 0, "Unknown" },
43};
44
45struct baudRate *baudRateMatchString( char *str )
46{
47 struct baudRate *b;
48
49 unsigned long a = atol( str );
50 if( a )
51 {
52 for( b = supportedBaudRates; b->rate; b++ )
53 if( b->rate == a || (b->rate / 1000) == a || ((b->rate + 500) / 1000) == a )
54 return( b );
55 }
56
57 return( b );
58}
59
60struct baudRate *baudRateMatchDivisor( unsigned char divisor )
61{
62 struct baudRate *b;
63
64 for( b = supportedBaudRates; b->rate && b->divisor != divisor; b++ )
65 ;
66
67 return( b );
68}
69
70
Note: See TracBrowser for help on using the repository browser.