X-Git-Url: http://developer.intra2net.com/git/?a=blobdiff_plain;f=test%2Fbaudrate.cpp;h=fe6c63a006b52616b341466571ee18481a062da7;hb=f1b4c09a8409b0706a4b25c38e5215b8fe28c64c;hp=248b4a62c72572b73ddbbc32448e0db30d060676;hpb=6777cc7098a69f8cfab6fc3a7baa7c4745709d96;p=libftdi diff --git a/test/baudrate.cpp b/test/baudrate.cpp index 248b4a6..fe6c63a 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 #include #include +#include using namespace std; @@ -38,7 +39,7 @@ public: ftdi = ftdi_new(); } - ~BaseFTDIFixture() + virtual ~BaseFTDIFixture() { delete ftdi; ftdi = NULL; @@ -101,10 +102,12 @@ static void test_baudrates(ftdi_context *ftdi, const map &baud case TYPE_R: case TYPE_2232C: case TYPE_BM: + case TYPE_230X: 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 && res->clock == clock, @@ -122,7 +125,7 @@ BOOST_AUTO_TEST_CASE(TypeAMFixedBaudrates) ftdi->type = TYPE_AM; map baudrates; - baudrates[183] = calc_result(183, 16383, 3, 48); + 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); @@ -139,12 +142,12 @@ BOOST_AUTO_TEST_CASE(TypeAMFixedBaudrates) 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[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(2000000, 1, 0, 48); + baudrates[2000000] = calc_result(1500000, 2, 0, 48); baudrates[3000000] = calc_result(3000000, 0, 0, 48); test_baudrates(ftdi, baudrates); @@ -157,9 +160,11 @@ BOOST_AUTO_TEST_CASE(TypeBMFixedBaudrates) test_types.push_back(TYPE_BM); test_types.push_back(TYPE_2232C); test_types.push_back(TYPE_R); + test_types.push_back(TYPE_230X); map 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,18 +173,36 @@ 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); + 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; @@ -197,6 +220,7 @@ BOOST_AUTO_TEST_CASE(TypeHFixedBaudrates) map 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); @@ -207,9 +231,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); @@ -217,6 +241,24 @@ BOOST_AUTO_TEST_CASE(TypeHFixedBaudrates) 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;