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

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

Serial Port: split single byte port and baud into two bytes, taking advantage of the two bytes in DPT_SERIAL, which supports more serial baud rates and in particular fixed a bug where a 4x client machine couldn't talk to a 115.2K server machine. This is a wide change, touching lots of files, but most are shallow changes. DetectPrint.asm took the most significant changes, now it calculates the baud rate to display instead of using characters provided by the Configurator. The Configurator now has a new menu flag, FLG_MENUITEM_CHOICESTRINGS, for specifying that values are not linear and they should be lookedup rather than indexed. Finally, another important bug fixed here is that in some error cases, the serial port code could get into an infinite loop waiting ont the hardware; now it has a timeout.

File size: 1.2 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#include "library.h"
9#include <stdlib.h>
10#include <string.h>
11
12struct 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
29struct 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
44struct 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
Note: See TracBrowser for help on using the repository browser.