--
Uwe Bonnes bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Institut fuer Kernphysik Schlossgartenstrasse 9 64289 Darmstadt
--------- Tel. 06151 162516 -------- Fax. 06151 164321 ----------
>From 8a313e47383faf2b0cb7bd90a3b4fb468491eee9 Mon Sep 17 00:00:00 2001
From: Uwe Bonnes <bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 6 Sep 2011 12:58:18 +0200
Subject: Round the returned baudrate in ftdi_to_clkbits and adjust the changed
values in test/baurate.cpp
---
src/ftdi.c | 6 +++++-
test/baudrate.cpp | 13 +++++++------
2 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/src/ftdi.c b/src/ftdi.c
index a2337ed..fba5288 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -1112,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;
diff --git a/test/baudrate.cpp b/test/baudrate.cpp
index 248b4a6..b7d0282 100644
--- a/test/baudrate.cpp
+++ b/test/baudrate.cpp
@@ -160,6 +160,7 @@ BOOST_AUTO_TEST_CASE(TypeBMFixedBaudrates)
map<int, calc_result> baudrates;
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);
@@ -168,14 +169,14 @@ BOOST_AUTO_TEST_CASE(TypeBMFixedBaudrates)
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(57553, 52, 3, 48);
- baudrates[115200] = calc_result(115384, 26, 0, 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, 1, 48);
- baudrates[921600] = calc_result(923076, 3, 2, 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(1411764, 2, 3, 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);
@@ -207,9 +208,9 @@ BOOST_AUTO_TEST_CASE(TypeHFixedBaudrates)
baudrates[38400] = calc_result(38400, 312, 1, 120);
baudrates[57600] = calc_result(57588, 208, 4, 120);
baudrates[115200] = calc_result(115246, 104, 3, 120);
- baudrates[230400] = calc_result(230215, 52, 3, 120);
+ baudrates[230400] = calc_result(230216, 52, 3, 120);
baudrates[460800] = calc_result(461538, 26, 0, 120);
- baudrates[921600] = calc_result(923076, 13, 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);
--
1.7.3.4
--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx
|