From a9cc822d9657101532683041846e5d17134c1aff Mon Sep 17 00:00:00 2001 From: Minh-Quang Nguyen Date: Thu, 1 Sep 2016 09:27:33 -0400 Subject: LC15: fix coding style Change-Id: I18d07822df1f36a6855b72f83e2d73d221aa8735 --- src/osmo-bts-litecell15/calib_file.c | 345 +++++++++++++++++------------------ 1 file changed, 172 insertions(+), 173 deletions(-) diff --git a/src/osmo-bts-litecell15/calib_file.c b/src/osmo-bts-litecell15/calib_file.c index ac39e464..0714bc9e 100644 --- a/src/osmo-bts-litecell15/calib_file.c +++ b/src/osmo-bts-litecell15/calib_file.c @@ -42,10 +42,9 @@ #include "lc15bts.h" #include "utils.h" -/** - * * Maximum calibration data chunk size - * */ +/* Maximum calibration data chunk size */ #define MAX_CALIB_TBL_SIZE 65536 +/* Calibration header version */ #define CALIB_HDR_V1 0x01 struct calib_file_desc { @@ -93,19 +92,19 @@ struct calTbl_t { struct { - uint8_t u8Version; // Header version (1) - uint8_t u8Parity; // Parity byte (xor) - uint8_t u8Type; // Table type (0:TX Downlink, 1:RX-A Uplink, 2:RX-B Uplink) - uint8_t u8Band; // GSM Band (0:GSM-850, 1:EGSM-900, 2:DCS-1800, 3:PCS-1900) - uint32_t u32Len; // Table length in bytes including the header + uint8_t u8Version; /* Header version (1) */ + uint8_t u8Parity; /* Parity byte (xor) */ + uint8_t u8Type; /* Table type (0:TX Downlink, 1:RX-A Uplink, 2:RX-B Uplink) */ + uint8_t u8Band; /* GSM Band (0:GSM-850, 1:EGSM-900, 2:DCS-1800, 3:PCS-1900) */ + uint32_t u32Len; /* Table length in bytes including the header */ struct { - uint32_t u32DescOfst; // Description section offset - uint32_t u32DateOfst; // Date section offset - uint32_t u32StationOfst; // Calibration test station section offset - uint32_t u32FpgaFwVerOfst; // Calibration FPGA firmware version section offset - uint32_t u32DspFwVerOfst; // Calibration DSP firmware section offset - uint32_t u32DataOfst; // Calibration data section offset + uint32_t u32DescOfst; /* Description section offset */ + uint32_t u32DateOfst; /* Date section offset */ + uint32_t u32StationOfst; /* Calibration test station section offset */ + uint32_t u32FpgaFwVerOfst; /* Calibration FPGA firmware version section offset */ + uint32_t u32DspFwVerOfst; /* Calibration DSP firmware section offset */ + uint32_t u32DataOfst; /* Calibration data section offset */ } toc; } v1; } hdr; @@ -137,7 +136,7 @@ static int calib_file_open(struct lc15l1_hdl *fl1h, { struct calib_send_state *st = &fl1h->st; char *calib_path = fl1h->phy_inst->u.lc15.calib_path; - char fname[PATH_MAX]; + char fname[PATH_MAX]; if (st->fp) { LOGP(DL1C, LOGL_NOTICE, "L1 calibration file was left opened !!\n"); @@ -145,9 +144,9 @@ static int calib_file_open(struct lc15l1_hdl *fl1h, st->fp = NULL; } - fname[0] = '\0'; - snprintf(fname, sizeof(fname)-1, "%s/%s", calib_path, desc->fname); - fname[sizeof(fname)-1] = '\0'; + fname[0] = '\0'; + snprintf(fname, sizeof(fname)-1, "%s/%s", calib_path, desc->fname); + fname[sizeof(fname)-1] = '\0'; st->fp = fopen(fname, "rb"); if (!st->fp) { @@ -225,14 +224,14 @@ static int calib_file_send(struct lc15l1_hdl *fl1h, rc = calib_file_open(fl1h, desc); if (rc < 0) { /* still, we'd like to continue trying to load - * calibration for all other bands */ - st->last_file_idx = get_next_calib_file_idx(fl1h, st->last_file_idx); - if (st->last_file_idx >= 0) - return calib_file_send(fl1h, - &calib_files[st->last_file_idx]); + * calibration for all other bands */ + st->last_file_idx = get_next_calib_file_idx(fl1h, st->last_file_idx); + if (st->last_file_idx >= 0) + return calib_file_send(fl1h, + &calib_files[st->last_file_idx]); LOGP(DL1C, LOGL_INFO, "L1 calibration table loading complete!\n"); - return 0; + return 0; } rc = calib_verify(fl1h, desc); @@ -269,8 +268,8 @@ static int calib_send_compl_cb(struct gsm_bts_trx *trx, struct msgb *l1_msg, /* Skip this one and try the next one */ st->last_file_idx = get_next_calib_file_idx(fl1h, st->last_file_idx); - if (st->last_file_idx >= 0) { - return calib_file_send(fl1h, + if (st->last_file_idx >= 0) { + return calib_file_send(fl1h, &calib_files[st->last_file_idx]); } @@ -307,152 +306,152 @@ int calib_load(struct lc15l1_hdl *fl1h) static int calib_verify(struct lc15l1_hdl *fl1h, const struct calib_file_desc *desc) { - int rc, sz; - struct calib_send_state *st = &fl1h->st; - struct phy_link *plink = fl1h->phy_inst->phy_link; - char *rbuf; - struct calTbl_t *calTbl; - char calChkSum ; - - - //calculate file size in bytes - fseek(st->fp, 0L, SEEK_END); - sz = ftell(st->fp); - - //rewind read poiner - fseek(st->fp, 0L, SEEK_SET); - - //read file - rbuf = (char *) malloc( sizeof(char) * sz ); - - rc = fread(rbuf, 1, sizeof(char) * sz, st->fp); - if ( rc != sz) { - - LOGP(DL1C, LOGL_ERROR, "%s reading error\n", desc->fname); - free(rbuf); - - //close file - rc = calib_file_close(fl1h); - if (rc < 0 ) { - LOGP(DL1C, LOGL_ERROR, "%s can not close\n", desc->fname); - return rc; - } - - return -2; - } - - - calTbl = (struct calTbl_t*) rbuf; - //calcualte file checksum - calChkSum = 0; - while ( sz-- ) { - calChkSum ^= rbuf[sz]; - } - - //validate Tx calibration parity - if ( calChkSum ) { - LOGP(DL1C, LOGL_ERROR, "%s has invalid checksum %x.\n", desc->fname, calChkSum); - return -4; - } - - //validate Tx calibration header - if ( calTbl->hdr.v1.u8Version != CALIB_HDR_V1 ) { - LOGP(DL1C, LOGL_ERROR, "%s has invalid header version %u.\n", desc->fname, calTbl->hdr.v1.u8Version); - return -5; - } - - //validate calibration description - if ( calTbl->hdr.v1.toc.u32DescOfst == 0xFFFFFFFF ) { - LOGP(DL1C, LOGL_ERROR, "%s has invalid calibration description offset.\n", desc->fname); - return -6; - } - - //validate calibration date - if ( calTbl->hdr.v1.toc.u32DateOfst == 0xFFFFFFFF ) { - LOGP(DL1C, LOGL_ERROR, "%s has invalid calibration date offset.\n", desc->fname); - return -7; - } - - LOGP(DL1C, LOGL_INFO, "L1 calibration table %s created on %s\n", - desc->fname, - calTbl->u8RawData + calTbl->hdr.v1.toc.u32DateOfst); - - //validate calibration station - if ( calTbl->hdr.v1.toc.u32StationOfst == 0xFFFFFFFF ) { - LOGP(DL1C, LOGL_ERROR, "%s has invalid calibration station ID offset.\n", desc->fname); - return -8; - } - - //validate FPGA FW version - if ( calTbl->hdr.v1.toc.u32FpgaFwVerOfst == 0xFFFFFFFF ) { - LOGP(DL1C, LOGL_ERROR, "%s has invalid FPGA FW version offset.\n", desc->fname); - return -9; - } - //validate DSP FW version - if ( calTbl->hdr.v1.toc.u32DspFwVerOfst == 0xFFFFFFFF ) { - LOGP(DL1C, LOGL_ERROR, "%s has invalid DSP FW version offset.\n", desc->fname); - return -10; - } - - //validate Tx calibration data offset - if ( calTbl->hdr.v1.toc.u32DataOfst == 0xFFFFFFFF ) { - LOGP(DL1C, LOGL_ERROR, "%s has invalid calibration data offset.\n", desc->fname); - return -11; - } - - if ( !desc->rx ) { - - //parse min/max Tx power - fl1h->phy_inst->u.lc15.minTxPower = calTbl->u8RawData[calTbl->hdr.v1.toc.u32DataOfst + (5 << 2)]; - fl1h->phy_inst->u.lc15.maxTxPower = calTbl->u8RawData[calTbl->hdr.v1.toc.u32DataOfst + (6 << 2)]; - - //override nominal Tx power of given TRX if needed - if ( fl1h->phy_inst->trx->nominal_power > fl1h->phy_inst->u.lc15.maxTxPower) { - LOGP(DL1C, LOGL_INFO, "Set TRX %u nominal Tx power to %d dBm (%d)\n", - plink->num, - fl1h->phy_inst->u.lc15.maxTxPower, - fl1h->phy_inst->trx->nominal_power); - - fl1h->phy_inst->trx->nominal_power = fl1h->phy_inst->u.lc15.maxTxPower; - } - - if ( fl1h->phy_inst->trx->nominal_power < fl1h->phy_inst->u.lc15.minTxPower) { - LOGP(DL1C, LOGL_INFO, "Set TRX %u nominal Tx power to %d dBm (%d)\n", - plink->num, - fl1h->phy_inst->u.lc15.minTxPower, - fl1h->phy_inst->trx->nominal_power); - - fl1h->phy_inst->trx->nominal_power = fl1h->phy_inst->u.lc15.minTxPower; - } - - if ( fl1h->phy_inst->trx->power_params.trx_p_max_out_mdBm > to_mdB(fl1h->phy_inst->u.lc15.maxTxPower) ) { - LOGP(DL1C, LOGL_INFO, "Set TRX %u Tx power parameter to %d dBm (%d)\n", - plink->num, - to_mdB(fl1h->phy_inst->u.lc15.maxTxPower), - fl1h->phy_inst->trx->power_params.trx_p_max_out_mdBm); - - fl1h->phy_inst->trx->power_params.trx_p_max_out_mdBm = to_mdB(fl1h->phy_inst->u.lc15.maxTxPower); - } - - if ( fl1h->phy_inst->trx->power_params.trx_p_max_out_mdBm < to_mdB(fl1h->phy_inst->u.lc15.minTxPower) ) { - LOGP(DL1C, LOGL_INFO, "Set TRX %u Tx power parameter to %d dBm (%d)\n", - plink->num, - to_mdB(fl1h->phy_inst->u.lc15.minTxPower), - fl1h->phy_inst->trx->power_params.trx_p_max_out_mdBm); - - fl1h->phy_inst->trx->power_params.trx_p_max_out_mdBm = to_mdB(fl1h->phy_inst->u.lc15.minTxPower); - } - - LOGP(DL1C, LOGL_DEBUG, "%s: minTxPower=%d, maxTxPower=%d\n", - desc->fname, - fl1h->phy_inst->u.lc15.minTxPower, - fl1h->phy_inst->u.lc15.maxTxPower ); - } - - //rewind read poiner for subsequence tasks - fseek(st->fp, 0L, SEEK_SET); - free(rbuf); - - return 0; + int i, rc, sz; + struct calib_send_state *st = &fl1h->st; + struct phy_link *plink = fl1h->phy_inst->phy_link; + char *rbuf; + struct calTbl_t *calTbl; + char calChkSum ; + + + /* calculate file size in bytes */ + fseek(st->fp, 0L, SEEK_END); + sz = ftell(st->fp); + + /* rewind read poiner */ + fseek(st->fp, 0L, SEEK_SET); + + /* read file */ + rbuf = (char *) malloc( sizeof(char) * sz ); + + rc = fread(rbuf, 1, sizeof(char) * sz, st->fp); + if (rc != sz) { + LOGP(DL1C, LOGL_ERROR, "%s reading error\n", desc->fname); + free(rbuf); + + /* close file */ + rc = calib_file_close(fl1h); + if (rc < 0 ) { + LOGP(DL1C, LOGL_ERROR, "%s can not close\n", desc->fname); + return rc; + } + + return -2; + } + + + calTbl = (struct calTbl_t*) rbuf; + /* calculate file checksum */ + calChkSum = 0; + while (sz--) { + calChkSum ^= rbuf[sz]; + } + + /* validate Tx calibration parity */ + if (calChkSum) { + LOGP(DL1C, LOGL_ERROR, "%s has invalid checksum %x.\n", desc->fname, calChkSum); + return -4; + } + + /* validate Tx calibration header */ + if (calTbl->hdr.v1.u8Version != CALIB_HDR_V1) { + LOGP(DL1C, LOGL_ERROR, "%s has invalid header version %u.\n", desc->fname, calTbl->hdr.v1.u8Version); + return -5; + } + + /* validate calibration description */ + if (calTbl->hdr.v1.toc.u32DescOfst == 0xFFFFFFFF) { + LOGP(DL1C, LOGL_ERROR, "%s has invalid calibration description offset.\n", desc->fname); + return -6; + } + + /* validate calibration date */ + if (calTbl->hdr.v1.toc.u32DateOfst == 0xFFFFFFFF) { + LOGP(DL1C, LOGL_ERROR, "%s has invalid calibration date offset.\n", desc->fname); + return -7; + } + + LOGP(DL1C, LOGL_INFO, "L1 calibration table %s created on %s\n", + desc->fname, + calTbl->u8RawData + calTbl->hdr.v1.toc.u32DateOfst); + + /* validate calibration station */ + if (calTbl->hdr.v1.toc.u32StationOfst == 0xFFFFFFFF) { + LOGP(DL1C, LOGL_ERROR, "%s has invalid calibration station ID offset.\n", desc->fname); + return -8; + } + + /* validate FPGA FW version */ + if (calTbl->hdr.v1.toc.u32FpgaFwVerOfst == 0xFFF) { + LOGP(DL1C, LOGL_ERROR, "%s has invalid FPGA FW version offset.\n", desc->fname); + return -9; + } + + /* validate DSP FW version */ + if (calTbl->hdr.v1.toc.u32DspFwVerOfst == 0xFFFFFFFF) { + LOGP(DL1C, LOGL_ERROR, "%s has invalid DSP FW version offset.\n", desc->fname); + return -10; + } + + /* validate Tx calibration data offset */ + if (calTbl->hdr.v1.toc.u32DataOfst == 0xFFFFFFFF) { + LOGP(DL1C, LOGL_ERROR, "%s has invalid calibration data offset.\n", desc->fname); + return -11; + } + + if (!desc->rx) { + + /* parse min/max Tx power */ + fl1h->phy_inst->u.lc15.minTxPower = calTbl->u8RawData[calTbl->hdr.v1.toc.u32DataOfst + (5 << 2)]; + fl1h->phy_inst->u.lc15.maxTxPower = calTbl->u8RawData[calTbl->hdr.v1.toc.u32DataOfst + (6 << 2)]; + + /* override nominal Tx power of given TRX if needed */ + if (fl1h->phy_inst->trx->nominal_power > fl1h->phy_inst->u.lc15.maxTxPower) { + LOGP(DL1C, LOGL_INFO, "Set TRX %u nominal Tx power to %d dBm (%d)\n", + plink->num, + fl1h->phy_inst->u.lc15.maxTxPower, + fl1h->phy_inst->trx->nominal_power); + + fl1h->phy_inst->trx->nominal_power = fl1h->phy_inst->u.lc15.maxTxPower; + } + + if (fl1h->phy_inst->trx->nominal_power < fl1h->phy_inst->u.lc15.minTxPower) { + LOGP(DL1C, LOGL_INFO, "Set TRX %u nominal Tx power to %d dBm (%d)\n", + plink->num, + fl1h->phy_inst->u.lc15.minTxPower, + fl1h->phy_inst->trx->nominal_power); + + fl1h->phy_inst->trx->nominal_power = fl1h->phy_inst->u.lc15.minTxPower; + } + + if (fl1h->phy_inst->trx->power_params.trx_p_max_out_mdBm > to_mdB(fl1h->phy_inst->u.lc15.maxTxPower) ) { + LOGP(DL1C, LOGL_INFO, "Set TRX %u Tx power parameter to %d dBm (%d)\n", + plink->num, + to_mdB(fl1h->phy_inst->u.lc15.maxTxPower), + fl1h->phy_inst->trx->power_params.trx_p_max_out_mdBm); + + fl1h->phy_inst->trx->power_params.trx_p_max_out_mdBm = to_mdB(fl1h->phy_inst->u.lc15.maxTxPower); + } + + if (fl1h->phy_inst->trx->power_params.trx_p_max_out_mdBm < to_mdB(fl1h->phy_inst->u.lc15.minTxPower) ) { + LOGP(DL1C, LOGL_INFO, "Set TRX %u Tx power parameter to %d dBm (%d)\n", + plink->num, + to_mdB(fl1h->phy_inst->u.lc15.minTxPower), + fl1h->phy_inst->trx->power_params.trx_p_max_out_mdBm); + + fl1h->phy_inst->trx->power_params.trx_p_max_out_mdBm = to_mdB(fl1h->phy_inst->u.lc15.minTxPower); + } + + LOGP(DL1C, LOGL_DEBUG, "%s: minTxPower=%d, maxTxPower=%d\n", + desc->fname, + fl1h->phy_inst->u.lc15.minTxPower, + fl1h->phy_inst->u.lc15.maxTxPower ); + } + + /* rewind read pointer for subsequence tasks */ + fseek(st->fp, 0L, SEEK_SET); + free(rbuf); + + return 0; } -- cgit v1.2.3