int main(void) { int m,od,ext_div; int fvco,fout; int ret; int * freq_table = NULL; int flag; freq_table = init_freq_table(F_MIN, F_MAX, crystal); #ifdef DEBUG printf(" === Freq table before ===\n"); show_freq(freq_table); #endif for(ext_div = 0; ext_div < 1024; ext_div++){ for(od = 0; od <= 2; od++){ for(m = 1; m < 512; m++){ fvco = calc_fvco(m, 1); if(fvco < FVCO_MIN || fvco > FVCO_MAX){ continue; } fout = calc_fout(fvco, od, ext_div); debug("--- fvco: %d, fout: %d, od: %d, m: %d, ext_div: %d\n",fvco,fout, od, m, ext_div); if(fout < F_MIN || fout > F_MAX){ debug("=== skip fout %d\n",fout); continue; } debug("--- fout: %d, od: %d, m: %d, ext_div: %d\n",fout,od, m, ext_div); if((fout / (crystal / 1000)) != ((fout / crystal) * 1000)) continue; /* get a poper fout */ debug("=== found fvco %d, fout %d, m %d, od %d, ext_div, %d\n", fvco,fout,m, od, ext_div); ret = add_freq_to_table(freq_table, fout, fvco, m, od, ext_div); if(ret == 0)// Add successful continue; if(ret == -1)// Alread have this item continue; if(ret == -2) goto FINISH; } } } FINISH: printf(" ======= Meson8 syspll freq table =======\n"); show_freq(freq_table); printf(" ======= Meson8 syspll freq table finished =======\n"); free(freq_table); return 0; }
void find_best_coeffs(double fvco) { double br, fvco_err; double min_fvco_err=100.0; int min_n, min_m, min_p, min_q, min_r; int n, m, nstroke, p, q , r; br=calc_target_br(fvco, fin); //printf("Fvco=%f; target BR: %f\n", fvco, br); for(m=511; m>0; m--) { n=(int)((double)m*br); if(n>4095) continue; fvco_err=fabs(calc_fvco(fin, m, n)-fvco); p=calc_p(n, m); nstroke=calc_nstroke(n, p); q=calc_q(nstroke, m); r=calc_r(nstroke, m, q); if(is_valid(fvco, q, p, r)) { if(fvco_err<min_fvco_err) { min_fvco_err=fvco_err; min_n=n; min_m=m; min_p=p; min_q=q; min_r=r; } } } //printf("[N=%d|M=%d] Fvco=%0.3f, P=%d, Q=%d, R=%d\n", min_n, min_m, fvco, min_p, min_q, min_r); //printf("Error: %f (%.2f %%)\n", min_fvco_err, (min_fvco_err/fvco)*100.0); printf("%0.6f;%0.3f;%d;%d;%d;[%d;%d]\n", fvco, min_fvco_err*1000.0, min_p, min_q, min_r, min_n, min_m); }