1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
#include <iostream> #include <stdio.h> #include <math.h> #include <thread>
using namespace std;
#define ACCURACY 1000000000
typedef double CLK; typedef unsigned short COFF;
CLK CLK_IN = 16.6; CLK CLK_OUT = 24.576;
struct TargetCofficient { COFF Numerator; COFF Denominator; };
COFF Maxiator = 65535; COFF InputClockDivider = 4; COFF IntegerSetting = 8;
int isSafe(COFF, COFF); int isOK(CLK); int CofficientCalculate(CLK, COFF, COFF);
void ICD1(void); void ICD2(void); void ICD3(void); void ICD4(void); void SysPrintf(void);
int main(){ cout << "SYSTEM: Procedure starts." << endl; thread thread1(ICD1); thread thread2(ICD2); thread thread3(ICD3); thread thread4(ICD4);
thread1.join(); thread2.join(); thread3.join(); thread4.join();
cout << "SYSTEM: Procedure ends up." << endl; return 0; }
int isSafe(COFF N, COFF D){ double result = (double)N / (double)D; if( (result >= 0.1) && (result <= 0.9) ) return 1; else return 0; }
int isOK(CLK clock){ CLK integerClock , fractClock; fractClock = modf(clock , &integerClock);
if( ((int)(fractClock * ACCURACY) == (int)(576/(double)1000 * ACCURACY)) && ((int)integerClock == (int)CLK_OUT) ) { return 1; } else return 0; }
int CofficientCalculate(CLK ClockInput, COFF ICD, COFF IS){ CLK tempCLK;
for(COFF i = 0; i < Maxiator; i++){ for(COFF j = 0; j < Maxiator; j++){ if(isSafe(j, i)){ #ifdef HALFCOFF tempCLK = ClockInput /(double)ICD * ((double)IS + ((double)j/(double)i)) *1/2; #else tempCLK = ClockInput /(double)ICD * ((double)IS + ((double)j/(double)i)) ; #endif
#ifdef DEBUG_MODE cout << "SYSTEM:IDC = " << ICD << ", IS = " << IS << hex <<", Numerator = 0x"<< j << ", Denominator = 0x" << i << ", OutputClock = " << tempCLK << endl; #endif } else continue;
if( isOK(tempCLK)) { cout << "SYSTEM:IDC = " << ICD << ", IS = " << IS << hex <<", Numerator = 0x"<< j << ", Denominator = 0x" << i << ", OutputClock = " << tempCLK << endl; } } } return 0; }
void ICD1(void){ for(COFF enumIS = 2; enumIS <= IntegerSetting; enumIS++) CofficientCalculate(CLK_IN , 1, enumIS); }
void ICD2(void){ for(COFF enumIS = 2; enumIS <= IntegerSetting; enumIS++) CofficientCalculate(CLK_IN , 2, enumIS); }
void ICD3(void){ for(COFF enumIS = 2; enumIS <= IntegerSetting; enumIS++) CofficientCalculate(CLK_IN , 3, enumIS); }
void ICD4(void){ for(COFF enumIS = 2; enumIS <= IntegerSetting; enumIS++) CofficientCalculate(CLK_IN , 4, enumIS); }
void SysPrintf(void){ while(1){ printf("Calculating..."); printf("\r\003"); } }
|