BitSet *bitset_create(size_t bits) { size_t words = calc_words(bits); BitSet *rv = (BitSet *)calloc(words + 2, sizeof(*rv)); rv[0].word = 1; rv[1].word = bits; return rv + 2; }
static size_t bitset_words(BitSet *b) { return calc_words(bitset_bits(b)); }
int main(int argc, char** argv){ //select loggin level logger_default_config(log4cxx::Level::getInfo()); std::string adc_id; std::string filename; size_t offset = 0x08000000; // 128M * 4 -> second memory bank size_t block_size = 2048; size_t data_size = 4096; bool simple_mode = false; bool halbe_mode = false; bool statistic_mode = false; { namespace po = boost::program_options; po::options_description desc("Allowed options"); desc.add_options() ("help", "produce help message") ("adc", po::value<std::string>(&adc_id)->required(), "specify ADC board") ("data_size", po::value<size_t>(&data_size), "Amount of data to read (kB), default 4096kB") ("block_size", po::value<size_t>(&block_size), "Read data in blocks of this size(kB), default 2048kB") ("simple_mode", po::bool_switch(&simple_mode), "Run forever and collect statistics.") ("halbe_mode ", po::bool_switch(&halbe_mode), "Run forever and collect statistics.") ("statistic_mode", po::bool_switch(&statistic_mode), "Run forever and collect statistics.") ; po::variables_map vm; po::store(po::command_line_parser(argc, argv) .options(desc) .run() , vm); if (vm.count("help")) { std::cout << std::endl << desc << std::endl; return 0; } po::notify(vm); } if (simple_mode) { //create the top of the tree Vmoduleusb io(usbcomm::note); if(io.open(usb_vendorid, usb_deviceid, adc_id)){ std::cout << "Open failed" << std::endl; return -1; } else { std::cout << "Board " << adc_id << " opened" << std::endl; } //create sp6 class tree Vusbmaster usb(&io); //usbmaster knows three clients, must be in this order!!! Vusbstatus status(&usb); Vmemory mem(&usb); Vocpfifo ocp(&usb); //ocpfifo clients Vspiconfrom confrom(&ocp); Vspigyro gyro(&ocp); Vspiwireless wireless(&ocp); std::cout << "Transfering " << data_size << "kB in " << calc_blocks(data_size * 1024, block_size * 1024) << " block(s) of " << calc_words(block_size) << " words." << std::endl; size_t errorcnt = memtest(mem, calc_words(data_size), offset, calc_words(block_size)); std::cout << "Transmission errors: " << errorcnt << std::endl; if (errorcnt > 0) return -1; } if (halbe_mode) { Vmoduleusb io(usbcomm::note, usb_vendorid, usb_deviceid, adc_id); std::cout << "Board " << adc_id << " opened" << std::endl; Vusbmaster usb(&io); Vusbstatus status(&usb); Vmemory mem(&usb); Vocpfifo ocp(&usb); Vmux_board mux_board(&ocp, mux_board_mode(adc_id)); Vflyspi_adc adc(&ocp); // write configuration to adc adc.configure(0); adc.setup_controller(0, calc_words(data_size), 0 /* single mode */, 0 /* trigger enable */, 0 /* trigger */); const uint32_t startaddr = adc.get_startaddr(); const uint32_t endaddr = adc.get_endaddr(); const uint32_t num_words = endaddr - startaddr; if (startaddr != 0 or endaddr != calc_words(data_size)) { std::cout << "Invalid start or end addresses: startaddr=" << startaddr << " endaddr=" << endaddr; exit(-1); } std::cout << "Transfering " << num_words << " words in " << calc_blocks(data_size * 1024, block_size * 1024) << " block(s) of " << num_words << " words." << std::endl; size_t errorcnt = memtest(mem, num_words, offset, calc_words(block_size)); std::cout << "Transmission errors: " << errorcnt << std::endl; if (errorcnt > 0) return -1; } }