The branch, master has been updated
via f9df39f525b9ffebb43bd5a0cfca998f681aed02 (commit)
via 3c9ef8f8c6951ac8245b3b6c6eb98758fe06ec4e (commit)
via e0d70e3556d3648f09f61d7d0922dc746251dade (commit)
via b63d5c9ec4145317ef66fb65cad252b56bad1593 (commit)
via 90933196a1d2306342a1a3a21b55a0f0eeca0f3c (commit)
via 93de2301b262afa86af6c48076c1d6c89888eb0f (commit)
via 0d119163cc334fcc4063e85f39c964c6ed4a3679 (commit)
via aae08071a70ead6cf550921fbad399f0d7d796d2 (commit)
via 6777cc7098a69f8cfab6fc3a7baa7c4745709d96 (commit)
via e03f60a12cd4233197fc4e11c26f3b61e7e78f58 (commit)
via 6645ac5e981a05b8758e76a8f3745936535cb5a8 (commit)
via 9956d4289d04f1c67a8738a7b8b32e1345ab0968 (commit)
via 3db4042e16d398b8803a236d2735df99e76bea27 (commit)
via c4a2bc3a1f41e0b7882241aa7db448adb7dc5f5e (commit)
via f15786e4a4fdb935f639e16ab69d717f3d29bd2b (commit)
via cb2a07f2532267cf178e6565e1419039a43219ed (commit)
from 4e494b76c44b82fc04cbe9939bc10a74f051fad5 (commit)
- Log -----------------------------------------------------------------
commit f9df39f525b9ffebb43bd5a0cfca998f681aed02
Merge: 4e494b76c44b82fc04cbe9939bc10a74f051fad5
3c9ef8f8c6951ac8245b3b6c6eb98758fe06ec4e
Author: Thomas Jarosch <thomas.jarosch@xxxxxxxxxxxxx>
Date: Fri Sep 9 11:45:10 2011 +0200
Merge branch 'new-baudrate-code'
-----------------------------------------------------------------------
Summary of changes:
TODO | 23 ++++
libftdi.lnt | 17 +++
src/ftdi.c | 181 +++++++++++++++++++++++--------
test/baudrate.cpp | 316 +++++++++++++++++++++++++++--------------------------
4 files changed, 338 insertions(+), 199 deletions(-)
create mode 100644 TODO
diff --git a/TODO b/TODO
new file mode 100644
index 0000000..369ae12
--- /dev/null
+++ b/TODO
@@ -0,0 +1,23 @@
+*** TODO for 1.0 release ***
+Build related:
+- Rename the library and header file,
+ so libftdi 0.x and 1.x can co-exist
+- Remove autoconf support
+
+API extentions:
+- Make EEPROM structure opaque
+- Function to query the library version,
+ either as string or as integers. Maybe both.
+- TO DECIDE: Make ftdi structure opaque?
+
+Misc:
+- Fix baudrate unit test for AM type chips
+- Resolve TODO entries in ftdi_eeprom
+- Look into merging ftdi_eeprom and examples/eeprom
+- "To deal with ftdi_context" <-- Xiaofan: What was meant by this?
+ Maybe the same as "Make ftdi structure opaque?"
+
+Documentation:
+- Mention libusb-1.0 dependency
+- Comparison between 1.0 and 0.19
+- Document the new EEPROM function
diff --git a/libftdi.lnt b/libftdi.lnt
index 2682b95..4ff6280 100644
--- a/libftdi.lnt
+++ b/libftdi.lnt
@@ -1,5 +1,7 @@
// PC-Lint 9.00 settings
--iz:\usr\include\libusb-1.0
+--i../src
+--i../ftdipp
-emacro(527, ftdi_error_return) // ignore "unreachable code"
-emacro(717, ftdi_error_return)
@@ -9,3 +11,18 @@
+fie // Allow enum to int conversion
-ecall(534, usb_close) // silence ignored return value from
usb_close
+
+// Disable bogus BOOST warnings
+-emacro(58,BOOST_ASSERT)
+-emacro(506, BOOST_FOREACH)
+-emacro(666, BOOST_FOREACH)
+-esym(666, BOOST_FOREACH)
+-emacro(1023, BOOST_FOREACH)
+-emacro(1793, BOOST_FOREACH)
+-esym(665, BOOST_FOREACH)
+-e123
+
+// Don't complain we are running with -wlib(0)
+// as the boost headers can't be parsed properly
+-estring(686, -wlib(0))
+-wlib(0)
diff --git a/src/ftdi.c b/src/ftdi.c
index dca79e1..fba5288 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -964,34 +964,30 @@ int ftdi_usb_close(struct ftdi_context *ftdi)
return rtn;
}
-/**
- ftdi_convert_baudrate returns nearest supported baud rate to that
requested.
+/* ftdi_to_clkbits_AM For the AM device, convert a requested baudrate
+ to encoded divisor and the achievable baudrate
Function is only used internally
\internal
+
+ See AN120
+ clk/1 -> 0
+ clk/1.5 -> 1
+ clk/2 -> 2
+ From /2, 0.125/ 0.25 and 0.5 steps may be taken
+ The fractional part has frac_code encoding
*/
-static int ftdi_convert_baudrate(int baudrate, struct ftdi_context *ftdi,
- unsigned short *value, unsigned short *index)
+static int ftdi_to_clkbits_AM(int baudrate, unsigned long *encoded_divisor)
+
{
+ static const char frac_code[8] = {0, 3, 2, 4, 1, 5, 6, 7};
static const char am_adjust_up[8] = {0, 0, 0, 1, 0, 3, 2, 1};
static const char am_adjust_dn[8] = {0, 0, 0, 1, 0, 1, 2, 3};
- static const char frac_code[8] = {0, 3, 2, 4, 1, 5, 6, 7};
int divisor, best_divisor, best_baud, best_baud_diff;
- unsigned long encoded_divisor;
- int i;
-
- if (baudrate <= 0)
- {
- // Return error
- return -1;
- }
-
divisor = 24000000 / baudrate;
+ int i;
- if (ftdi->type == TYPE_AM)
- {
- // Round down to supported fraction (AM only)
- divisor -= am_adjust_dn[divisor & 7];
- }
+ // Round down to supported fraction (AM only)
+ divisor -= am_adjust_dn[divisor & 7];
// Try this divisor and the one above it (because division rounds down)
best_divisor = 0;
@@ -1009,11 +1005,6 @@ static int ftdi_convert_baudrate(int baudrate, struct
ftdi_context *ftdi,
// Round up to minimum supported divisor
try_divisor = 8;
}
- else if (ftdi->type != TYPE_AM && try_divisor < 12)
- {
- // BM doesn't support divisors 9 through 11 inclusive
- try_divisor = 12;
- }
else if (divisor < 16)
{
// AM doesn't support divisors 9 through 15 inclusive
@@ -1021,23 +1012,12 @@ static int ftdi_convert_baudrate(int baudrate, struct
ftdi_context *ftdi,
}
else
{
- if (ftdi->type == TYPE_AM)
- {
- // Round up to supported fraction (AM only)
- try_divisor += am_adjust_up[try_divisor & 7];
- if (try_divisor > 0x1FFF8)
- {
- // Round down to maximum supported divisor value (for AM)
- try_divisor = 0x1FFF8;
- }
- }
- else
+ // Round up to supported fraction (AM only)
+ try_divisor += am_adjust_up[try_divisor & 7];
+ if (try_divisor > 0x1FFF8)
{
- if (try_divisor > 0x1FFFF)
- {
- // Round down to maximum supported divisor value (for BM)
- try_divisor = 0x1FFFF;
- }
+ // Round down to maximum supported divisor value (for AM)
+ try_divisor = 0x1FFF8;
}
}
// Get estimated baud rate (to nearest integer)
@@ -1065,19 +1045,128 @@ static int ftdi_convert_baudrate(int baudrate, struct
ftdi_context *ftdi,
}
}
// Encode the best divisor value
- encoded_divisor = (best_divisor >> 3) | (frac_code[best_divisor & 7] <<
14);
+ *encoded_divisor = (best_divisor >> 3) | (frac_code[best_divisor & 7] <<
14);
// Deal with special cases for encoded value
- if (encoded_divisor == 1)
+ if (*encoded_divisor == 1)
+ {
+ *encoded_divisor = 0; // 3000000 baud
+ }
+ else if (*encoded_divisor == 0x4001)
{
- encoded_divisor = 0; // 3000000 baud
+ *encoded_divisor = 1; // 2000000 baud (BM only)
}
- else if (encoded_divisor == 0x4001)
+ return best_baud;
+}
+
+/* ftdi_to_clkbits Convert a requested baudrate for a given system clock and
predivisor
+ to encoded divisor and the achievable baudrate
+ Function is only used internally
+ \internal
+
+ See AN120
+ clk/1 -> 0
+ clk/1.5 -> 1
+ 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)
+{
+ static const char frac_code[8] = {0, 3, 2, 4, 1, 5, 6, 7};
+ int best_baud = 0;
+ int divisor, best_divisor;
+ if (baudrate >= clk/clk_div)
+ {
+ *encoded_divisor = 0;
+ best_baud = clk/clk_div;
+ }
+ else if (baudrate >= clk/(clk_div + clk_div/2))
+ {
+ *encoded_divisor = 1;
+ best_baud = clk/(clk_div + clk_div/2);
+ }
+ else if (baudrate >= clk/(2*clk_div))
+ {
+ *encoded_divisor = 2;
+ best_baud = clk/(2*clk_div);
+ }
+ else
+ {
+ /* We divide by 16 to have 3 fractional bits and one bit for rounding
*/
+ divisor = clk*16/clk_div / baudrate;
+ if (divisor & 1) /* Decide if to round up or down*/
+ best_divisor = divisor /2 +1;
+ else
+ best_divisor = divisor/2;
+ if(best_divisor > 0x20000)
+ best_divisor = 0x1ffff;
+ 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;
+}
+/**
+ ftdi_convert_baudrate returns nearest supported baud rate to that
requested.
+ Function is only used internally
+ \internal
+*/
+static int ftdi_convert_baudrate(int baudrate, struct ftdi_context *ftdi,
+ unsigned short *value, unsigned short *index)
+{
+ int best_baud;
+ unsigned long encoded_divisor;
+
+ if (baudrate <= 0)
+ {
+ // Return error
+ return -1;
+ }
+
+#define H_CLK 120000000
+#define C_CLK 48000000
+ if ((ftdi->type == TYPE_2232H) || (ftdi->type == TYPE_4232H) ||
(ftdi->type == TYPE_232H ))
+ {
+ if(baudrate*10 > H_CLK /0x3fff)
+ {
+ /* On H Devices, use 12 000 000 Baudrate when possible
+ We have a 14 bit divisor, a 1 bit divisor switch (10 or 16)
+ three fractional bits and a 120 MHz clock
+ Assume AN_120 "Sub-integer divisors between 0 and 2 are not
allowed" holds for
+ DIV/10 CLK too, so /1, /1.5 and /2 can be handled the same*/
+ best_baud = ftdi_to_clkbits(baudrate, H_CLK, 10, &encoded_divisor);
+ encoded_divisor |= 0x20000; /* switch on CLK/10*/
+ }
+ else
+ best_baud = ftdi_to_clkbits(baudrate, C_CLK, 16, &encoded_divisor);
+ }
+ else if ((ftdi->type == TYPE_BM) || (ftdi->type == TYPE_2232C) ||
(ftdi->type == TYPE_R ))
+ {
+ best_baud = ftdi_to_clkbits(baudrate, C_CLK, 16, &encoded_divisor);
+ }
+ else
{
- encoded_divisor = 1; // 2000000 baud (BM only)
+ best_baud = ftdi_to_clkbits_AM(baudrate, &encoded_divisor);
}
// Split into "value" and "index" values
*value = (unsigned short)(encoded_divisor & 0xFFFF);
- if (ftdi->type == TYPE_2232C || ftdi->type == TYPE_2232H || ftdi->type ==
TYPE_4232H || ftdi->type == TYPE_232H )
+ if (ftdi->type == TYPE_2232H ||
+ ftdi->type == TYPE_4232H || ftdi->type == TYPE_232H )
{
*index = (unsigned short)(encoded_divisor >> 8);
*index &= 0xFF00;
diff --git a/test/baudrate.cpp b/test/baudrate.cpp
index 7db5d43..29bbd20 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
*/
/***************************************************************************
@@ -17,7 +17,9 @@
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include <boost/foreach.hpp>
+#include <vector>
#include <map>
+#include <math.h>
using namespace std;
@@ -37,7 +39,7 @@ public:
ftdi = ftdi_new();
}
- ~BaseFTDIFixture()
+ virtual ~BaseFTDIFixture()
{
delete ftdi;
ftdi = NULL;
@@ -50,20 +52,23 @@ BOOST_FIXTURE_TEST_SUITE(Baudrate, BaseFTDIFixture)
struct calc_result
{
int actual_baudrate;
- unsigned short expected_value;
- unsigned short expected_index;
+ unsigned short divisor;
+ unsigned short fractional_bits;
+ unsigned short clock;
- calc_result(int actual, int my_value, int my_index)
+ calc_result(int actual, unsigned short my_divisor, unsigned short
my_fractional_bits, unsigned short my_clock)
: actual_baudrate(actual)
- , expected_value(my_value)
- , expected_index(my_index)
+ , divisor(my_divisor)
+ , fractional_bits(my_fractional_bits)
+ , clock(my_clock)
{
}
calc_result()
: actual_baudrate(0)
- , expected_value(0)
- , expected_index(0)
+ , divisor(0)
+ , fractional_bits(0)
+ , clock(0)
{
}
};
@@ -83,13 +88,34 @@ static void test_baudrates(ftdi_context *ftdi, const
map<int, calc_result> &baud
const calc_result *res = &baudrate.second;
+ 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->expected_value == calc_value && res->expected_index == calc_index,
+ BOOST_CHECK_MESSAGE(res->actual_baudrate == calc_baudrate &&
res->divisor == divisor && res->fractional_bits == fractional_bits
+ && res->clock == clock,
"\n\nERROR: baudrate calculation failed for --" <<
baudrate.first << " baud--. Details below: ");
BOOST_CHECK_EQUAL(res->actual_baudrate, calc_baudrate);
- BOOST_CHECK_EQUAL(res->expected_value, calc_value);
- BOOST_CHECK_EQUAL(res->expected_index, calc_index);
+ BOOST_CHECK_EQUAL(res->divisor, divisor);
+ BOOST_CHECK_EQUAL(res->fractional_bits, fractional_bits);
+ BOOST_CHECK_EQUAL(res->clock, clock);
}
}
@@ -98,160 +124,144 @@ BOOST_AUTO_TEST_CASE(TypeAMFixedBaudrates)
ftdi->type = TYPE_AM;
map<int, calc_result> baudrates;
- baudrates[300] = calc_result(300, 10000, 0);
- baudrates[600] = calc_result(600, 5000, 0);
- baudrates[600] = calc_result(600, 5000, 0);
- baudrates[1200] = calc_result(1200, 2500, 0);
- baudrates[2400] = calc_result(2400, 1250, 0);
- baudrates[4800] = calc_result(4800, 625, 0);
- baudrates[9600] = calc_result(9600, 16696, 0);
- baudrates[19200] = calc_result(19200, 32924, 0);
- baudrates[38400] = calc_result(38400, 49230, 0);
- baudrates[57600] = calc_result(57554, 49204, 0);
- baudrates[115200] = calc_result(115385, 26, 0);
- baudrates[230400] = calc_result(230769, 13, 0);
- baudrates[460800] = calc_result(461538, 16390, 0);
- baudrates[921600] = calc_result(923077, 32771, 0);
+ baudrates[183] = calc_result(183, 16383, 0, 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, 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, 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(1000000, 3, 0, 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(1500000, 2, 0, 48);
+ baudrates[3000000] = calc_result(3000000, 0, 0, 48);
test_baudrates(ftdi, baudrates);
}
BOOST_AUTO_TEST_CASE(TypeBMFixedBaudrates)
{
- ftdi->type = TYPE_BM;
-
- map<int, calc_result> baudrates;
- baudrates[300] = calc_result(300, 10000, 0);
- baudrates[600] = calc_result(600, 5000, 0);
- baudrates[600] = calc_result(600, 5000, 0);
- baudrates[1200] = calc_result(1200, 2500, 0);
- baudrates[2400] = calc_result(2400, 1250, 0);
- baudrates[4800] = calc_result(4800, 625, 0);
- baudrates[9600] = calc_result(9600, 16696, 0);
- baudrates[19200] = calc_result(19200, 32924, 0);
- baudrates[38400] = calc_result(38400, 49230, 0);
- baudrates[57600] = calc_result(57554, 49204, 0);
- baudrates[115200] = calc_result(115385, 26, 0);
- baudrates[230400] = calc_result(230769, 13, 0);
- baudrates[460800] = calc_result(461538, 16390, 0);
- baudrates[921600] = calc_result(923077, 32771, 0);
-
- test_baudrates(ftdi, baudrates);
-}
-
-BOOST_AUTO_TEST_CASE(Type2232CFixedBaudrates)
-{
- ftdi->type = TYPE_2232C;
+ // Unify testing of chips behaving the same
+ std::vector<enum ftdi_chip_type> test_types;
+ test_types.push_back(TYPE_BM);
+ test_types.push_back(TYPE_2232C);
+ test_types.push_back(TYPE_R);
map<int, calc_result> baudrates;
- baudrates[300] = calc_result(300, 10000, 1);
- baudrates[600] = calc_result(600, 5000, 1);
- baudrates[600] = calc_result(600, 5000, 1);
- baudrates[1200] = calc_result(1200, 2500, 1);
- baudrates[2400] = calc_result(2400, 1250, 1);
- baudrates[4800] = calc_result(4800, 625, 1);
- baudrates[9600] = calc_result(9600, 16696, 1);
- baudrates[19200] = calc_result(19200, 32924, 1);
- baudrates[38400] = calc_result(38400, 49230, 1);
- baudrates[57600] = calc_result(57554, 49204, 1);
- baudrates[115200] = calc_result(115385, 26, 1);
- baudrates[230400] = calc_result(230769, 13, 1);
- baudrates[460800] = calc_result(461538, 16390, 1);
- baudrates[921600] = calc_result(923077, 32771, 1);
-
- test_baudrates(ftdi, baudrates);
-}
-
-BOOST_AUTO_TEST_CASE(TypeRFixedBaudrates)
-{
- ftdi->type = TYPE_R;
-
- map<int, calc_result> baudrates;
- baudrates[300] = calc_result(300, 10000, 0);
- baudrates[600] = calc_result(600, 5000, 0);
- baudrates[600] = calc_result(600, 5000, 0);
- baudrates[1200] = calc_result(1200, 2500, 0);
- baudrates[2400] = calc_result(2400, 1250, 0);
- baudrates[4800] = calc_result(4800, 625, 0);
- baudrates[9600] = calc_result(9600, 16696, 0);
- baudrates[19200] = calc_result(19200, 32924, 0);
- baudrates[38400] = calc_result(38400, 49230, 0);
- baudrates[57600] = calc_result(57554, 49204, 0);
- baudrates[115200] = calc_result(115385, 26, 0);
- baudrates[230400] = calc_result(230769, 13, 0);
- baudrates[460800] = calc_result(461538, 16390, 0);
- baudrates[921600] = calc_result(923077, 32771, 0);
-
- test_baudrates(ftdi, baudrates);
-}
-
-BOOST_AUTO_TEST_CASE(Type2232HFixedBaudrates)
-{
- ftdi->type = TYPE_2232H;
-
- map<int, calc_result> baudrates;
- baudrates[300] = calc_result(300, 10000, 1);
- baudrates[600] = calc_result(600, 5000, 1);
- baudrates[600] = calc_result(600, 5000, 1);
- baudrates[1200] = calc_result(1200, 2500, 1);
- baudrates[2400] = calc_result(2400, 1250, 1);
- baudrates[4800] = calc_result(4800, 625, 1);
- baudrates[9600] = calc_result(9600, 16696, 1);
- baudrates[19200] = calc_result(19200, 32924, 1);
- baudrates[38400] = calc_result(38400, 49230, 1);
- baudrates[57600] = calc_result(57554, 49204, 1);
- baudrates[115200] = calc_result(115385, 26, 1);
- baudrates[230400] = calc_result(230769, 13, 1);
- baudrates[460800] = calc_result(461538, 16390, 1);
- baudrates[921600] = calc_result(923077, 32771, 1);
-
- test_baudrates(ftdi, baudrates);
-}
-
-BOOST_AUTO_TEST_CASE(Type4232HFixedBaudrates)
-{
- ftdi->type = TYPE_4232H;
-
- map<int, calc_result> baudrates;
- baudrates[300] = calc_result(300, 10000, 1);
- baudrates[600] = calc_result(600, 5000, 1);
- baudrates[600] = calc_result(600, 5000, 1);
- baudrates[1200] = calc_result(1200, 2500, 1);
- baudrates[2400] = calc_result(2400, 1250, 1);
- baudrates[4800] = calc_result(4800, 625, 1);
- baudrates[9600] = calc_result(9600, 16696, 1);
- baudrates[19200] = calc_result(19200, 32924, 1);
- baudrates[38400] = calc_result(38400, 49230, 1);
- baudrates[57600] = calc_result(57554, 49204, 1);
- baudrates[115200] = calc_result(115385, 26, 1);
- baudrates[230400] = calc_result(230769, 13, 1);
- baudrates[460800] = calc_result(461538, 16390, 1);
- baudrates[921600] = calc_result(923077, 32771, 1);
-
- test_baudrates(ftdi, 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);
+ baudrates[2400] = calc_result(2400, 1250, 0, 48);
+ baudrates[4800] = calc_result(4800, 625, 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, 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)
+ {
+ ftdi->type = test_chip_type;
+ test_baudrates(ftdi, baudrates);
+ }
}
-BOOST_AUTO_TEST_CASE(Type232HFixedBaudrates)
+BOOST_AUTO_TEST_CASE(TypeHFixedBaudrates)
{
- ftdi->type = TYPE_232H;
+ // Unify testing of chips behaving the same
+ std::vector<enum ftdi_chip_type> test_types;
+ test_types.push_back(TYPE_2232H);
+ test_types.push_back(TYPE_4232H);
+ test_types.push_back(TYPE_232H);
map<int, calc_result> baudrates;
- baudrates[300] = calc_result(300, 10000, 1);
- baudrates[600] = calc_result(600, 5000, 1);
- baudrates[600] = calc_result(600, 5000, 1);
- baudrates[1200] = calc_result(1200, 2500, 1);
- baudrates[2400] = calc_result(2400, 1250, 1);
- baudrates[4800] = calc_result(4800, 625, 1);
- baudrates[9600] = calc_result(9600, 16696, 1);
- baudrates[19200] = calc_result(19200, 32924, 1);
- baudrates[38400] = calc_result(38400, 49230, 1);
- baudrates[57600] = calc_result(57554, 49204, 1);
- baudrates[115200] = calc_result(115385, 26, 1);
- baudrates[230400] = calc_result(230769, 13, 1);
- baudrates[460800] = calc_result(461538, 16390, 1);
- baudrates[921600] = calc_result(923077, 32771, 1);
-
- test_baudrates(ftdi, 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, 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, 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)
+ {
+ ftdi->type = test_chip_type;
+ test_baudrates(ftdi, baudrates);
+ }
}
BOOST_AUTO_TEST_SUITE_END()
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
|