| 1 | #include <iostream> |
| 2 | #include "adf4351_regs.hpp" |
| 3 | #include <stdint.h> |
| 4 | #include <stdio.h> |
| 5 | #include <stdlib.h> |
| 6 | #include <bitset> |
| 7 | #include <string> |
| 8 | |
| 9 | using namespace std; |
| 10 | |
| 11 | |
| 12 | int main(void) { |
| 13 | int Pass, Fail; |
| 14 | |
| 15 | Pass = Fail = 0; |
| 16 | |
| 17 | std::cout << "Library Testbench\n" << std::endl; |
| 18 | |
| 19 | { |
| 20 | std::string strBin; |
| 21 | // Starting with something simple |
| 22 | std::cout << "Testing Integer to binary conversion" << std::endl; |
| 23 | strBin = bitset<8>((int) 123).to_string(); |
| 24 | if (strBin == "01111011") { |
| 25 | std::cout << "Pass"; |
| 26 | Pass++; |
| 27 | } else { |
| 28 | std::cout << "FAIL"; |
| 29 | Fail++; |
| 30 | }; |
| 31 | std::cout << "\t123 => " << strBin << std::endl; |
| 32 | |
| 33 | // Initialization ADF4351 Registers in something safe... |
| 34 | std::cout << "\nTesting Default Safe State Initialization of ADF435{0,1} Registers." << std::endl; |
| 35 | |
| 36 | //Known Safe Values |
| 37 | std::string adf4351_saferegs[6] = { |
| 38 | "00000000000010111000000000000000", //Register 0 |
| 39 | "00000000000000001000000000010001", //Register 1 |
| 40 | "00000000000000000100000001110010", //Register 2 |
| 41 | "00000000000000000000000000000011", //Register 3 |
| 42 | "00000000000000000001100000000100", //Register 4 |
| 43 | "00000000010110000000000000000101" //Register 5 |
| 44 | }; |
| 45 | |
| 46 | //Initialize registers |
| 47 | adf4351_regs_t adf4351_regs; |
| 48 | for (int i=0;i<=5;i++){ |
| 49 | int regcontents = (int) adf4351_regs.get_reg(i); |
| 50 | strBin = bitset<32>(regcontents).to_string(); |
| 51 | //std::cout << i << flush; |
| 52 | if (strBin == adf4351_saferegs[i]) { |
| 53 | std::cout << "Pass"; |
| 54 | Pass++; |
| 55 | } else { |
| 56 | std::cout << "FAIL"; |
| 57 | Fail++; |
| 58 | }; |
| 59 | std::cout << "\tRegister " << i << "=>\t" << strBin << " == " << hex << regcontents << std::endl; |
| 60 | }; |
| 61 | |
| 62 | //Debug outputs; |
| 63 | //adf4351_regs.show_regs(); |
| 64 | |
| 65 | } |
| 66 | |
| 67 | std::cout << Pass << " tests passed, " << Fail << " tests failed." << std::endl; |
| 68 | |
| 69 | return Fail; |
| 70 | }; |