1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string>
  4. #include <cstring>
  5. #include <cassert>
  6. #include <cstdlib>
  7. #include <cstdio>
  8. #include <math.h>
  9. using namespace std;
  10. double HALF_48MHz_PERIOD = 10416.7;
  11. double BAUD_OUT_PERIOD = 104167000;
  12. double time_ps = 0;
  13. unsigned int number_of_baud_clocks_passed = 0;
  14. bool finished=false;
  15. void update_clk(void) {
  16. time_ps = time_ps + HALF_48MHz_PERIOD/2;
  17. /*******************************************/
  18. time_ps = time_ps + HALF_48MHz_PERIOD;
  19. /*******************************************/
  20. time_ps = time_ps + HALF_48MHz_PERIOD/2;
  21. }
  22. int main()
  23. {
  24. while(!finished){
  25. update_clk();
  26. number_of_baud_clocks_passed = (unsigned int)(time_ps/BAUD_OUT_PERIOD);
  27. if ( (number_of_baud_clocks_passed == 974979) && ((time_ps-(double)number_of_baud_clocks_passed*BAUD_OUT_PERIOD <= BAUD_OUT_PERIOD/2+HALF_48MHz_PERIOD) && (time_ps-(double)number_of_baud_clocks_passed*BAUD_OUT_PERIOD >= BAUD_OUT_PERIOD/2-HALF_48MHz_PERIOD)) ) {
  28. cout << "number_of_baud_clocks_passed = " << number_of_baud_clocks_passed << "\ttime_ps = " << time_ps << endl;
  29. cout << "(double)number_of_baud_clocks_passed = " << (double)number_of_baud_clocks_passed << endl;
  30. cout << "(double)BAUD_OUT_PERIOD = " << BAUD_OUT_PERIOD << endl;
  31. cout << "time_ps-(double)number_of_baud_clocks_passed*(double)BAUD_OUT_PERIOD = " << time_ps-(double)number_of_baud_clocks_passed*BAUD_OUT_PERIOD << endl;
  32. cout << "(double)BAUD_OUT_PERIOD/2+(double)HALF_48MHz_PERIOD = " << BAUD_OUT_PERIOD/2+HALF_48MHz_PERIOD << endl;
  33. cout << "(double)BAUD_OUT_PERIOD/2-(double)HALF_48MHz_PERIOD = " << BAUD_OUT_PERIOD/2-HALF_48MHz_PERIOD << endl;
  34. finished=true;
  35. }
  36. }
  37. }