The branch, new-baudrate-code has been updated
via 93de2301b262afa86af6c48076c1d6c89888eb0f (commit)
via 0d119163cc334fcc4063e85f39c964c6ed4a3679 (commit)
via aae08071a70ead6cf550921fbad399f0d7d796d2 (commit)
via 6777cc7098a69f8cfab6fc3a7baa7c4745709d96 (commit)
via e03f60a12cd4233197fc4e11c26f3b61e7e78f58 (commit)
via 6645ac5e981a05b8758e76a8f3745936535cb5a8 (commit)
via 9956d4289d04f1c67a8738a7b8b32e1345ab0968 (commit)
from 3db4042e16d398b8803a236d2735df99e76bea27 (commit)
- Log -----------------------------------------------------------------
commit 93de2301b262afa86af6c48076c1d6c89888eb0f
Author: Thomas Jarosch <thomas.jarosch@xxxxxxxxxxxxx>
Date: Wed Sep 7 10:56:01 2011 +0200
Cosmetic changes and add Uwe to authors
commit 0d119163cc334fcc4063e85f39c964c6ed4a3679
Author: Uwe Bonnes <bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Tue Sep 6 14:10:06 2011 +0200
test/baudrate.cpp: Add testcases for the rounding border cases
commit aae08071a70ead6cf550921fbad399f0d7d796d2
Author: Uwe Bonnes <bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Tue Sep 6 14:09:26 2011 +0200
Round the returned baudrate in ftdi_to_clkbits and adjust the changed
values in test/baurate.cpp
commit 6777cc7098a69f8cfab6fc3a7baa7c4745709d96
Author: Uwe Bonnes <bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Tue Sep 6 14:08:52 2011 +0200
test/baudrate.cpp: Change the expected results to the present results. AM
still has some errors in the cornercase.
commit e03f60a12cd4233197fc4e11c26f3b61e7e78f58
Author: Uwe Bonnes <bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Tue Sep 6 14:08:13 2011 +0200
2232C is a BM type chips for baudrate calculations
commit 6645ac5e981a05b8758e76a8f3745936535cb5a8
Author: Uwe Bonnes <bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Tue Sep 6 14:07:35 2011 +0200
test/baudrate.cpp: Use orthogonal names for the test-targets
commit 9956d4289d04f1c67a8738a7b8b32e1345ab0968
Author: Uwe Bonnes <bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Tue Sep 6 14:06:56 2011 +0200
Explain the index/value format baudrate setting
test/baudrate.cpp: Evaluate according to this explanation
-----------------------------------------------------------------------
Summary of changes:
src/ftdi.c | 20 ++++++-
test/baudrate.cpp | 157 ++++++++++++++++++++++++++++++++++++++++-------------
2 files changed, 136 insertions(+), 41 deletions(-)
diff --git a/src/ftdi.c b/src/ftdi.c
index 66c159e..fba5288 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -1069,6 +1069,18 @@ static int ftdi_to_clkbits_AM(int baudrate, unsigned
long *encoded_divisor)
clk/2 -> 2
From /2, 0.125 steps may be taken.
The fractional part has frac_code encoding
+
+ value[13:0] of value is the divisor
+ index[9] mean 12 MHz Base(120 MHz/10) rate versus 3 MHz (48 MHz/16) else
+
+ H Type have all features above with
+ {index[8],value[15:14]} is the encoded subdivisor
+
+ FT232R, FT2232 and FT232BM have no option for 12 MHz and with
+ {index[0],value[15:14]} is the encoded subdivisor
+
+ AM Type chips have only four fractional subdivisors at value[15:14]
+ for subdivisors 0, 0.5, 0.25, 0.125
*/
static int ftdi_to_clkbits(int baudrate, unsigned int clk, int clk_div,
unsigned long *encoded_divisor)
{
@@ -1100,7 +1112,11 @@ static int ftdi_to_clkbits(int baudrate, unsigned int
clk, int clk_div, unsigned
best_divisor = divisor/2;
if(best_divisor > 0x20000)
best_divisor = 0x1ffff;
- best_baud = clk*8/clk_div/best_divisor;
+ best_baud = clk*16/clk_div/best_divisor;
+ if (best_baud & 1) /* Decide if to round up or down*/
+ best_baud = best_baud /2 +1;
+ else
+ best_baud = best_baud /2;
*encoded_divisor = (best_divisor >> 3) | (frac_code[best_divisor &
0x7] << 14);
}
return best_baud;
@@ -1149,7 +1165,7 @@ static int ftdi_convert_baudrate(int baudrate, struct
ftdi_context *ftdi,
}
// Split into "value" and "index" values
*value = (unsigned short)(encoded_divisor & 0xFFFF);
- if (ftdi->type == TYPE_2232C || ftdi->type == TYPE_2232H ||
+ if (ftdi->type == TYPE_2232H ||
ftdi->type == TYPE_4232H || ftdi->type == TYPE_232H )
{
*index = (unsigned short)(encoded_divisor >> 8);
diff --git a/test/baudrate.cpp b/test/baudrate.cpp
index 0d2e0b8..d541ba3 100644
--- a/test/baudrate.cpp
+++ b/test/baudrate.cpp
@@ -1,7 +1,7 @@
/**@file
@brief Test baudrate calculator code
-@author Thomas Jarosch
+@author Thomas Jarosch and Uwe Bonnes
*/
/***************************************************************************
@@ -19,6 +19,7 @@
#include <boost/foreach.hpp>
#include <vector>
#include <map>
+#include <math.h>
using namespace std;
@@ -87,9 +88,24 @@ static void test_baudrates(ftdi_context *ftdi, const
map<int, calc_result> &baud
const calc_result *res = &baudrate.second;
- unsigned short divisor = calc_value & 0x3ff;
- unsigned short fractional_bits = (calc_index & 0x100) ? 4 :
(calc_value >> 12);
- unsigned short clock = (calc_index & 0x100) ? 120 : 48;
+ unsigned short divisor = calc_value & 0x3fff;
+ unsigned short fractional_bits = (calc_value >> 14);
+ unsigned short clock = (calc_index & 0x200) ? 120 : 48;
+
+ switch (ftdi->type)
+ {
+ case TYPE_232H:
+ case TYPE_2232H:
+ case TYPE_4232H:
+ fractional_bits |= (calc_index & 0x100) ? 4 : 0;
+ break;
+ case TYPE_R:
+ case TYPE_2232C:
+ case TYPE_BM:
+ fractional_bits |= (calc_index & 0x001) ? 4 : 0;
+ break;
+ default:;
+ }
// Aid debugging since this test is a generic function
BOOST_CHECK_MESSAGE(res->actual_baudrate == calc_baudrate &&
res->divisor == divisor && res->fractional_bits == fractional_bits
@@ -108,24 +124,35 @@ BOOST_AUTO_TEST_CASE(TypeAMFixedBaudrates)
ftdi->type = TYPE_AM;
map<int, calc_result> baudrates;
- baudrates[300] = calc_result(300, 784, 2, 48);
- baudrates[600] = calc_result(600, 904, 1, 48);
- baudrates[1200] = calc_result(1200, 452, 0, 48);
- baudrates[2400] = calc_result(2400, 226, 0, 48);
+ baudrates[183] = calc_result(183, 16383, 3, 48);
+ baudrates[300] = calc_result(300, 10000, 0, 48);
+ baudrates[600] = calc_result(600, 5000, 0, 48);
+ baudrates[1200] = calc_result(1200, 2500, 0, 48);
+ baudrates[2400] = calc_result(2400, 1250, 0, 48);
baudrates[4800] = calc_result(4800, 625, 0, 48);
- baudrates[9600] = calc_result(9600, 312, 4, 48);
- baudrates[19200] = calc_result(19200, 156, 8, 48);
- baudrates[38400] = calc_result(38400, 78, 12, 48);
- baudrates[57600] = calc_result(57554, 52, 12, 48);
+ baudrates[9600] = calc_result(9600, 312, 1, 48);
+ baudrates[19200] = calc_result(19200, 156, 2, 48);
+ baudrates[38400] = calc_result(38400, 78, 3, 48);
+ baudrates[57600] = calc_result(57554, 52, 3, 48);
baudrates[115200] = calc_result(115385, 26, 0, 48);
baudrates[230400] = calc_result(230769, 13, 0, 48);
- baudrates[460800] = calc_result(461538, 6, 4, 48);
- baudrates[921600] = calc_result(923077, 3, 8, 48);
+ baudrates[460800] = calc_result(461538, 6, 1, 48);
+ baudrates[921600] = calc_result(923077, 3, 2, 48);
+ baudrates[1000000] = calc_result(1000000, 3, 0, 48);
+ baudrates[1090512] = calc_result(1000000, 3, 0, 48);
+ baudrates[1090909] = calc_result(1000000, 3, 0, 48);
+ baudrates[1090910] = calc_result(1200000, 2, 1, 48);
+ baudrates[1200000] = calc_result(1200000, 2, 1, 48);
+ baudrates[1333333] = calc_result(1333333, 2, 2, 48);
+ baudrates[1411764] = calc_result(1411765, 2, 3, 48);
+ baudrates[1500000] = calc_result(1500000, 2, 0, 48);
+ baudrates[2000000] = calc_result(2000000, 1, 0, 48);
+ baudrates[3000000] = calc_result(3000000, 0, 0, 48);
test_baudrates(ftdi, baudrates);
}
-BOOST_AUTO_TEST_CASE(Type_BM_232C_R_FixedBaudrates)
+BOOST_AUTO_TEST_CASE(TypeBMFixedBaudrates)
{
// Unify testing of chips behaving the same
std::vector<enum ftdi_chip_type> test_types;
@@ -134,19 +161,45 @@ BOOST_AUTO_TEST_CASE(Type_BM_232C_R_FixedBaudrates)
test_types.push_back(TYPE_R);
map<int, calc_result> baudrates;
- baudrates[300] = calc_result(300, 784, 2, 48);
- baudrates[600] = calc_result(600, 904, 1, 48);
- baudrates[1200] = calc_result(1200, 452, 0, 48);
- baudrates[2400] = calc_result(2400, 226, 0, 48);
+ baudrates[183] = calc_result(183, 16383, 7, 48);
+ baudrates[184] = calc_result(184, 16304, 4, 48);
+ baudrates[300] = calc_result(300, 10000, 0, 48);
+ baudrates[600] = calc_result(600, 5000, 0, 48);
+ baudrates[1200] = calc_result(1200, 2500, 0, 48);
+ baudrates[2400] = calc_result(2400, 1250, 0, 48);
baudrates[4800] = calc_result(4800, 625, 0, 48);
- baudrates[9600] = calc_result(9600, 312, 4, 48);
- baudrates[19200] = calc_result(19200, 156, 8, 48);
- baudrates[38400] = calc_result(38400, 78, 12, 48);
- baudrates[57600] = calc_result(57553, 52, 12, 48);
- baudrates[115200] = calc_result(115384, 26, 0, 48);
+ baudrates[9600] = calc_result(9600, 312, 1, 48);
+ baudrates[19200] = calc_result(19200, 156, 2, 48);
+ baudrates[38400] = calc_result(38400, 78, 3, 48);
+ baudrates[57600] = calc_result(57554, 52, 3, 48);
+ baudrates[115200] = calc_result(115385, 26, 0, 48);
baudrates[230400] = calc_result(230769, 13, 0, 48);
- baudrates[460800] = calc_result(461538, 6, 4, 48);
- baudrates[921600] = calc_result(923076, 3, 8, 48);
+ baudrates[460800] = calc_result(461538, 6, 1, 48);
+ baudrates[921600] = calc_result(923077, 3, 2, 48);
+ baudrates[1000000] = calc_result(1000000, 3, 0, 48);
+ baudrates[1050000] = calc_result(1043478, 2, 7, 48);
+ baudrates[1400000] = calc_result(1411765, 2, 3, 48);
+ baudrates[1500000] = calc_result(1500000, 2, 0, 48);
+ baudrates[2000000] = calc_result(2000000, 1, 0, 48);
+ baudrates[3000000] = calc_result(3000000, 0, 0, 48);
+
+ baudrates[(3000000*16/(2*16+15))-1] = calc_result(round(3000000/3.000), 3,
0, 48);
+ baudrates[ 3000000*16/(2*16+15) ] = calc_result(round(3000000/3.000), 3,
0, 48);
+ baudrates[(3000000*16/(2*16+15))+1] = calc_result(round(3000000/2.875), 2,
7, 48);
+ baudrates[ 3000000*16/(2*16+13) ] = calc_result(round(3000000/2.875), 2,
7, 48);
+ baudrates[(3000000*16/(2*16+13))+1] = calc_result(round(3000000/2.750), 2,
6, 48);
+ baudrates[ 3000000*16/(2*16+11) ] = calc_result(round(3000000/2.750), 2,
6, 48);
+ baudrates[(3000000*16/(2*16+11))+1] = calc_result(round(3000000/2.625), 2,
5, 48);
+ baudrates[ 3000000*16/(2*16+ 9) ] = calc_result(round(3000000/2.625), 2,
5, 48);
+ baudrates[(3000000*16/(2*16+ 9))+1] = calc_result(round(3000000/2.500), 2,
1, 48);
+ baudrates[ 3000000*16/(2*16+ 7) ] = calc_result(round(3000000/2.500), 2,
1, 48);
+ baudrates[(3000000*16/(2*16+ 7))+1] = calc_result(round(3000000/2.375), 2,
4, 48);
+ baudrates[ 3000000*16/(2*16+ 5) ] = calc_result(round(3000000/2.375), 2,
4, 48);
+ baudrates[(3000000*16/(2*16+ 5))+1] = calc_result(round(3000000/2.250), 2,
2, 48);
+ baudrates[ 3000000*16/(2*16+ 3) ] = calc_result(round(3000000/2.250), 2,
2, 48);
+ baudrates[(3000000*16/(2*16+ 3))+1] = calc_result(round(3000000/2.125), 2,
3, 48);
+ baudrates[ 3000000*16/(2*16+ 1) ] = calc_result(round(3000000/2.125), 2,
3, 48);
+ baudrates[(3000000*16/(2*16+ 1))+1] = calc_result(round(3000000/2.000), 2,
0, 48);
BOOST_FOREACH(const enum ftdi_chip_type &test_chip_type, test_types)
{
@@ -155,7 +208,7 @@ BOOST_AUTO_TEST_CASE(Type_BM_232C_R_FixedBaudrates)
}
}
-BOOST_AUTO_TEST_CASE(Type_x232H_FixedBaudrates)
+BOOST_AUTO_TEST_CASE(TypeHFixedBaudrates)
{
// Unify testing of chips behaving the same
std::vector<enum ftdi_chip_type> test_types;
@@ -164,19 +217,45 @@ BOOST_AUTO_TEST_CASE(Type_x232H_FixedBaudrates)
test_types.push_back(TYPE_232H);
map<int, calc_result> baudrates;
- baudrates[300] = calc_result(300, 784, 2, 48);
- baudrates[600] = calc_result(600, 904, 1, 48);
- baudrates[1200] = calc_result(1200, 784, 2, 48);
- baudrates[2400] = calc_result(2400, 904, 1, 48);
- baudrates[4800] = calc_result(4800, 452, 0, 48);
- baudrates[9600] = calc_result(9600, 226, 0, 48);
- baudrates[19200] = calc_result(19200, 625, 0, 48);
- baudrates[38400] = calc_result(38400, 312, 4, 48);
+ baudrates[183] = calc_result(183, 16383, 7, 48);
+ baudrates[184] = calc_result(184, 16304, 4, 48);
+ baudrates[300] = calc_result(300, 10000, 0, 48);
+ baudrates[600] = calc_result(600, 5000, 0, 48);
+ baudrates[1200] = calc_result(1200, 10000, 0, 120);
+ baudrates[2400] = calc_result(2400, 5000, 0, 120);
+ baudrates[4800] = calc_result(4800, 2500, 0, 120);
+ baudrates[9600] = calc_result(9600, 1250, 0, 120);
+ baudrates[19200] = calc_result(19200, 625, 0, 120);
+ baudrates[38400] = calc_result(38400, 312, 1, 120);
baudrates[57600] = calc_result(57588, 208, 4, 120);
- baudrates[115200] = calc_result(115246, 104, 12, 48);
- baudrates[230400] = calc_result(230215, 52, 12, 48);
- baudrates[460800] = calc_result(461538, 26, 0, 48);
- baudrates[921600] = calc_result(923076, 13, 0, 48);
+ baudrates[115200] = calc_result(115246, 104, 3, 120);
+ baudrates[230400] = calc_result(230216, 52, 3, 120);
+ baudrates[460800] = calc_result(461538, 26, 0, 120);
+ baudrates[921600] = calc_result(923077, 13, 0, 120);
+ baudrates[1000000] = calc_result(1000000, 12, 0, 120);
+ baudrates[1000000] = calc_result(1000000, 12, 0, 120);
+ baudrates[6000000] = calc_result(6000000, 2, 0, 120);
+ baudrates[4173913] = calc_result(4173913, 2, 7, 120);
+ baudrates[8000000] = calc_result(8000000, 1, 0, 120);
+ baudrates[12000000] = calc_result(12000000, 0, 0, 120);
+
+ baudrates[(12000000*16/(2*16+15))-1] = calc_result(round(12000000/3.000),
3, 0, 120);
+ baudrates[ 12000000*16/(2*16+15) ] = calc_result(round(12000000/3.000),
3, 0, 120);
+ baudrates[(12000000*16/(2*16+15))+1] = calc_result(round(12000000/2.875),
2, 7, 120);
+ baudrates[ 12000000*16/(2*16+13) ] = calc_result(round(12000000/2.875),
2, 7, 120);
+ baudrates[(12000000*16/(2*16+13))+1] = calc_result(round(12000000/2.750),
2, 6, 120);
+ baudrates[ 12000000*16/(2*16+11) ] = calc_result(round(12000000/2.750),
2, 6, 120);
+ baudrates[(12000000*16/(2*16+11))+1] = calc_result(round(12000000/2.625),
2, 5, 120);
+ baudrates[ 12000000*16/(2*16+ 9) ] = calc_result(round(12000000/2.625),
2, 5, 120);
+ baudrates[(12000000*16/(2*16+ 9))+1] = calc_result(round(12000000/2.500),
2, 1, 120);
+ baudrates[ 12000000*16/(2*16+ 7) ] = calc_result(round(12000000/2.500),
2, 1, 120);
+ baudrates[(12000000*16/(2*16+ 7))+1] = calc_result(round(12000000/2.375),
2, 4, 120);
+ baudrates[ 12000000*16/(2*16+ 5) ] = calc_result(round(12000000/2.375),
2, 4, 120);
+ baudrates[(12000000*16/(2*16+ 5))+1] = calc_result(round(12000000/2.250),
2, 2, 120);
+ baudrates[ 12000000*16/(2*16+ 3) ] = calc_result(round(12000000/2.250),
2, 2, 120);
+ baudrates[(12000000*16/(2*16+ 3))+1] = calc_result(round(12000000/2.125),
2, 3, 120);
+ baudrates[ 12000000*16/(2*16+ 1) ] = calc_result(round(12000000/2.125),
2, 3, 120);
+ baudrates[(12000000*16/(2*16+ 1))+1] = calc_result(round(12000000/2.000),
2, 0, 120);
BOOST_FOREACH(const enum ftdi_chip_type &test_chip_type, test_types)
{
hooks/post-receive
--
port libftdi to libusb-1.0
--
libftdi-git - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi-git+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx
|