diff options
author | Vadim Yanitskiy <axilirator@gmail.com> | 2018-03-02 21:24:57 +0700 |
---|---|---|
committer | Vadim Yanitskiy <axilirator@gmail.com> | 2018-03-02 21:24:57 +0700 |
commit | c066787fd5e9696e4af0a43f7bd3fd9392de4931 (patch) | |
tree | 551ded65f04e9e57b990a9865a7d073942dc3554 | |
parent | ff233256e12b370db78af29d4b283ba5e19becfa (diff) |
host/trxcon: use integer math for ToA (Timing of Arrival)
There's no need to express ToA value as a float. Let's turn it into
an int16_t with 1/256 symbol period accuracy throughout the code to
avoid both float arithmetic as well as loosing any precision.
Inspired by Idce4178e0b1f7e940ebc22b3e2f340fcd544d4ec.
Change-Id: I99c0f38db08a530d5846c474aba352aa0b68fe86
-rw-r--r-- | src/host/trxcon/sched_lchan_desc.c | 6 | ||||
-rw-r--r-- | src/host/trxcon/sched_lchan_sch.c | 2 | ||||
-rw-r--r-- | src/host/trxcon/sched_lchan_tchf.c | 6 | ||||
-rw-r--r-- | src/host/trxcon/sched_lchan_xcch.c | 6 | ||||
-rw-r--r-- | src/host/trxcon/sched_trx.c | 5 | ||||
-rw-r--r-- | src/host/trxcon/sched_trx.h | 9 | ||||
-rw-r--r-- | src/host/trxcon/trx_if.c | 10 |
7 files changed, 23 insertions, 21 deletions
diff --git a/src/host/trxcon/sched_lchan_desc.c b/src/host/trxcon/sched_lchan_desc.c index 390b1ef1..e0617a54 100644 --- a/src/host/trxcon/sched_lchan_desc.c +++ b/src/host/trxcon/sched_lchan_desc.c @@ -38,21 +38,21 @@ /* Forward declaration of handlers */ int rx_data_fn(struct trx_instance *trx, struct trx_ts *ts, struct trx_lchan_state *lchan, uint32_t fn, uint8_t bid, - sbit_t *bits, int8_t rssi, float toa); + sbit_t *bits, int8_t rssi, int16_t toa256); int tx_data_fn(struct trx_instance *trx, struct trx_ts *ts, struct trx_lchan_state *lchan, uint32_t fn, uint8_t bid); int rx_sch_fn(struct trx_instance *trx, struct trx_ts *ts, struct trx_lchan_state *lchan, uint32_t fn, uint8_t bid, - sbit_t *bits, int8_t rssi, float toa); + sbit_t *bits, int8_t rssi, int16_t toa256); int tx_rach_fn(struct trx_instance *trx, struct trx_ts *ts, struct trx_lchan_state *lchan, uint32_t fn, uint8_t bid); int rx_tchf_fn(struct trx_instance *trx, struct trx_ts *ts, struct trx_lchan_state *lchan, uint32_t fn, uint8_t bid, - sbit_t *bits, int8_t rssi, float toa); + sbit_t *bits, int8_t rssi, int16_t toa256); int tx_tchf_fn(struct trx_instance *trx, struct trx_ts *ts, struct trx_lchan_state *lchan, uint32_t fn, uint8_t bid); diff --git a/src/host/trxcon/sched_lchan_sch.c b/src/host/trxcon/sched_lchan_sch.c index b2377fa6..1b241a08 100644 --- a/src/host/trxcon/sched_lchan_sch.c +++ b/src/host/trxcon/sched_lchan_sch.c @@ -71,7 +71,7 @@ static void decode_sb(struct gsm_time *time, uint8_t *bsic, uint8_t *sb_info) int rx_sch_fn(struct trx_instance *trx, struct trx_ts *ts, struct trx_lchan_state *lchan, uint32_t fn, uint8_t bid, - sbit_t *bits, int8_t rssi, float toa) + sbit_t *bits, int8_t rssi, int16_t toa256) { sbit_t payload[2 * 39]; struct gsm_time time; diff --git a/src/host/trxcon/sched_lchan_tchf.c b/src/host/trxcon/sched_lchan_tchf.c index 45fa1c20..b023126a 100644 --- a/src/host/trxcon/sched_lchan_tchf.c +++ b/src/host/trxcon/sched_lchan_tchf.c @@ -46,7 +46,7 @@ int rx_tchf_fn(struct trx_instance *trx, struct trx_ts *ts, struct trx_lchan_state *lchan, uint32_t fn, uint8_t bid, - sbit_t *bits, int8_t rssi, float toa) + sbit_t *bits, int8_t rssi, int16_t toa256) { const struct trx_lchan_desc *lchan_desc; uint8_t rsl_cmode, tch_mode, mode; @@ -79,9 +79,9 @@ int rx_tchf_fn(struct trx_instance *trx, struct trx_ts *ts, /* Update mask and RSSI */ lchan->meas.rssi_sum += rssi; - lchan->meas.toa_sum += toa; + lchan->meas.toa256_sum += toa256; lchan->meas.rssi_num++; - lchan->meas.toa_num++; + lchan->meas.toa256_num++; /* Copy burst to end of buffer of 8 bursts */ offset = buffer + bid * 116 + 464; diff --git a/src/host/trxcon/sched_lchan_xcch.c b/src/host/trxcon/sched_lchan_xcch.c index 20153305..b2cbd223 100644 --- a/src/host/trxcon/sched_lchan_xcch.c +++ b/src/host/trxcon/sched_lchan_xcch.c @@ -43,7 +43,7 @@ int rx_data_fn(struct trx_instance *trx, struct trx_ts *ts, struct trx_lchan_state *lchan, uint32_t fn, uint8_t bid, - sbit_t *bits, int8_t rssi, float toa) + sbit_t *bits, int8_t rssi, int16_t toa256) { const struct trx_lchan_desc *lchan_desc; uint8_t l2[GSM_MACBLOCK_LEN], *mask; @@ -74,9 +74,9 @@ int rx_data_fn(struct trx_instance *trx, struct trx_ts *ts, /* Update measurements */ lchan->meas.rssi_sum += rssi; - lchan->meas.toa_sum += toa; + lchan->meas.toa256_sum += toa256; lchan->meas.rssi_num++; - lchan->meas.toa_num++; + lchan->meas.toa256_num++; /* Copy burst to buffer of 4 bursts */ offset = buffer + bid * 116; diff --git a/src/host/trxcon/sched_trx.c b/src/host/trxcon/sched_trx.c index 0a9b7f73..9ae5a8f6 100644 --- a/src/host/trxcon/sched_trx.c +++ b/src/host/trxcon/sched_trx.c @@ -568,7 +568,8 @@ static void sched_trx_a5_burst_enc(struct trx_lchan_state *lchan, } int sched_trx_handle_rx_burst(struct trx_instance *trx, uint8_t tn, - uint32_t burst_fn, sbit_t *bits, uint16_t nbits, int8_t rssi, float toa) + uint32_t burst_fn, sbit_t *bits, uint16_t nbits, + int8_t rssi, int16_t toa256) { struct trx_lchan_state *lchan; const struct trx_frame *frame; @@ -630,7 +631,7 @@ int sched_trx_handle_rx_burst(struct trx_instance *trx, uint8_t tn, sched_trx_a5_burst_dec(lchan, fn, bits); /* Put burst to handler */ - handler(trx, ts, lchan, fn, bid, bits, rssi, toa); + handler(trx, ts, lchan, fn, bid, bits, rssi, toa256); } next_frame: diff --git a/src/host/trxcon/sched_trx.h b/src/host/trxcon/sched_trx.h index b01624c8..856566c4 100644 --- a/src/host/trxcon/sched_trx.h +++ b/src/host/trxcon/sched_trx.h @@ -82,7 +82,7 @@ enum trx_lchan_type { typedef int trx_lchan_rx_func(struct trx_instance *trx, struct trx_ts *ts, struct trx_lchan_state *lchan, uint32_t fn, uint8_t bid, sbit_t *bits, - int8_t rssi, float toa); + int8_t rssi, int16_t toa256); typedef int trx_lchan_tx_func(struct trx_instance *trx, struct trx_ts *ts, struct trx_lchan_state *lchan, @@ -174,9 +174,9 @@ struct trx_lchan_state { /*! \brief Sum of RSSI values */ float rssi_sum; /*! \brief Number of TOA values */ - uint8_t toa_num; + uint8_t toa256_num; /*! \brief Sum of TOA values */ - float toa_sum; + int32_t toa256_sum; } meas; /* AMR specific */ @@ -286,7 +286,8 @@ void sched_prim_drop(struct trx_lchan_state *lchan); void sched_prim_flush_queue(struct llist_head *list); int sched_trx_handle_rx_burst(struct trx_instance *trx, uint8_t tn, - uint32_t burst_fn, sbit_t *bits, uint16_t nbits, int8_t rssi, float toa); + uint32_t burst_fn, sbit_t *bits, uint16_t nbits, + int8_t rssi, int16_t toa256); int sched_trx_handle_tx_burst(struct trx_instance *trx, struct trx_ts *ts, struct trx_lchan_state *lchan, uint32_t fn, ubit_t *bits); diff --git a/src/host/trxcon/trx_if.c b/src/host/trxcon/trx_if.c index 048b720c..cab5a9bd 100644 --- a/src/host/trxcon/trx_if.c +++ b/src/host/trxcon/trx_if.c @@ -535,8 +535,8 @@ static int trx_data_rx_cb(struct osmo_fd *ofd, unsigned int what) uint8_t buf[256]; sbit_t bits[148]; int8_t rssi, tn; + int16_t toa256; uint32_t fn; - float toa; int len; len = recv(ofd->fd, buf, sizeof(buf), 0); @@ -552,7 +552,7 @@ static int trx_data_rx_cb(struct osmo_fd *ofd, unsigned int what) tn = buf[0]; fn = (buf[1] << 24) | (buf[2] << 16) | (buf[3] << 8) | buf[4]; rssi = -(int8_t) buf[5]; - toa = ((int16_t) (buf[6] << 8) | buf[7]) / 256.0F; + toa256 = ((int16_t) (buf[6] << 8) | buf[7]); /* Copy and convert bits {254..0} to sbits {-127..127} */ osmo_ubit2sbit(bits, buf + 8, 148); @@ -567,11 +567,11 @@ static int trx_data_rx_cb(struct osmo_fd *ofd, unsigned int what) return -EINVAL; } - LOGP(DTRXD, LOGL_DEBUG, "RX burst tn=%u fn=%u rssi=%d toa=%.2f\n", - tn, fn, rssi, toa); + LOGP(DTRXD, LOGL_DEBUG, "RX burst tn=%u fn=%u rssi=%d toa=%d\n", + tn, fn, rssi, toa256); /* Poke scheduler */ - sched_trx_handle_rx_burst(trx, tn, fn, bits, 148, rssi, toa); + sched_trx_handle_rx_burst(trx, tn, fn, bits, 148, rssi, toa256); /* Correct local clock counter */ if (fn % 51 == 0) |