FreeCalypso > hg > freecalypso-tools
view librftab/rftablewr.c @ 582:deda54106c0e
doc/Target-boot-control: first draft
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 03 Feb 2020 01:25:31 +0000 |
parents | 329c31f7c797 |
children | 059649902c7f |
line wrap: on
line source
/* * Here we implement the writing of RF tables into ASCII text files * in our defined format. This module will also be linked by the * standalone fc-cal2text utility, hence our code here needs to be * independent of rvinterf and fc-tmsh specifics. */ #include <sys/types.h> #include <stdio.h> #include <stdint.h> #include <endian.h> static unsigned get_u32(bin) u_char *bin; { return le32toh(*(uint32_t *)bin); } static unsigned get_u16(bin) u_char *bin; { return le16toh(*(uint16_t *)bin); } static int get_s16(bin) u_char *bin; { int i; i = le16toh(*(uint16_t *)bin); if (i >= 32768) i -= 65536; return(i); } void write_afcparams_table(bin, outf) u_char *bin; FILE *outf; { fputs("rf_table afcparams\n\n", outf); /* 32-bit parameters */ fprintf(outf, "%10u\t# psi_sta_inv\n", get_u32(bin)); fprintf(outf, "%10u\t# psi_st\n", get_u32(bin + 4)); fprintf(outf, "%10u\t# psi_st_32\n", get_u32(bin + 8)); fprintf(outf, "%10u\t# psi_st_inv\n\n", get_u32(bin + 12)); /* 16-bit parameters */ fprintf(outf, "%10d\t# dac_center\n", get_s16(bin + 16)); fprintf(outf, "%10d\t# dac_min\n", get_s16(bin + 18)); fprintf(outf, "%10d\t# dac_max\n", get_s16(bin + 20)); fprintf(outf, "%10d\t# snr_thr\n", get_s16(bin + 22)); } void write_agcwords_table(bin, outf) u_char *bin; FILE *outf; { int i, j; u_char *p = bin; fputs("rf_table agc-table\n\n", outf); for (i = 0; i < 4; i++) { for (j = 0; j < 5; j++) { if (j) putc(' ', outf); fprintf(outf, "0x%04X", get_u16(p)); p += 2; } putc('\n', outf); } } void write_agcglobals_table(bin, outf) u_char *bin; FILE *outf; { fputs("rf_table agc-global-params\n\n", outf); fprintf(outf, "%5u\t# low_agc_noise_thr\n", get_u16(bin)); fprintf(outf, "%5u\t# high_agc_sat_thr\n", get_u16(bin + 2)); fprintf(outf, "%5u\t# low_agc\n", get_u16(bin + 4)); fprintf(outf, "%5u\t# high_agc\n", get_u16(bin + 6)); } void write_il2agc_table(bin, outf) u_char *bin; FILE *outf; { int idx; fputs("rf_table il2agc\n\n", outf); for (idx = 0; idx < 121; idx++) fprintf(outf, "%3u\t# IL=%d\n", bin[idx], -idx); } void write_tx_levels_table(bin, outf) u_char *bin; FILE *outf; { int i; u_char *p = bin; fputs("rf_table tx-levels\n\n", outf); fputs("# Fields in each entry: apc, ramp_index, chan_cal_index\n\n", outf); for (i = 0; i < 32; i++) { fprintf(outf, "%5u %3u %3u\t# entry %d\n", get_u16(p), p[2], p[3], i); p += 4; } } void write_tx_calchan_table(bin, outf) u_char *bin; FILE *outf; { int i, j; u_char *p = bin; fputs("rf_table tx-calchan\n", outf); for (i = 0; i < 4; i++) { fprintf(outf, "\n# Channel calibration table %d:\n\n", i); for (j = 0; j < 8; j++) { fprintf(outf, "%5u %6d\n", get_u16(p), get_s16(p + 2)); p += 4; } } } void write_tx_caltemp_table(bin, outf) u_char *bin; FILE *outf; { int i; u_char *p = bin; fputs("rf_table tx-caltemp\n\n", outf); for (i = 0; i < 5; i++) { fprintf(outf, "%6d %6d %6d %6d\n", get_s16(p), get_s16(p + 2), get_s16(p + 4), get_s16(p + 6)); p += 8; } } void write_rx_calchan_table(bin, outf) u_char *bin; FILE *outf; { int i; u_char *p = bin; fputs("rf_table rx-calchan\n\n", outf); for (i = 0; i < 10; i++) { fprintf(outf, "%5u %6d\n", get_u16(p), get_s16(p + 2)); p += 4; } } void write_rx_caltemp_table(bin, outf) u_char *bin; FILE *outf; { int i; u_char *p = bin; fputs("rf_table rx-caltemp\n\n", outf); for (i = 0; i < 11; i++) { fprintf(outf, "%6d %6d\n", get_s16(p), get_s16(p + 2)); p += 4; } } void write_rx_agcparams_table(bin, outf) u_char *bin; FILE *outf; { fputs("rf_table rx-agc-params\n\n", outf); fprintf(outf, "%5u\t# g_magic\n", get_u16(bin)); fprintf(outf, "%5u\t# lna_att\n", get_u16(bin + 2)); fprintf(outf, "%5u\t# lna_switch_thr_low\n", get_u16(bin + 4)); fprintf(outf, "%5u\t# lna_switch_thr_high\n", get_u16(bin + 6)); } void write_tx_ramp(bin, outf) u_char *bin; FILE *outf; { int i; fputs("ramp-up ", outf); for (i = 0; i < 16; i++) fprintf(outf, " %3u", bin[i]); putc('\n', outf); fputs("ramp-down", outf); for (i = 0; i < 16; i++) fprintf(outf, " %3u", bin[i+16]); putc('\n', outf); } void write_tx_ramps_table(bin, outf) u_char *bin; FILE *outf; { int i; u_char *p = bin; fputs("rf_table tx-ramps\n", outf); for (i = 0; i < 16; i++) { fprintf(outf, "\n# Tx ramp template %d:\n\n", i); write_tx_ramp(p, outf); p += 32; } }