diff --git a/src/host/trxcon/include/osmocom/bb/l1sched/l1sched.h b/src/host/trxcon/include/osmocom/bb/l1sched/l1sched.h index 4b743cace..0ea1ba013 100644 --- a/src/host/trxcon/include/osmocom/bb/l1sched/l1sched.h +++ b/src/host/trxcon/include/osmocom/bb/l1sched/l1sched.h @@ -436,6 +436,8 @@ enum l1sched_lchan_type l1sched_chan_nr2lchan_type(uint8_t chan_nr, void l1sched_deactivate_all_lchans(struct l1sched_ts *ts); int l1sched_set_lchans(struct l1sched_ts *ts, uint8_t chan_nr, int active, uint8_t tch_mode, uint8_t tsc); +int l1sched_lchan_set_amr_cfg(struct l1sched_lchan_state *lchan, + uint8_t codecs_bitmask, uint8_t start_codec); int l1sched_activate_lchan(struct l1sched_ts *ts, enum l1sched_lchan_type chan); int l1sched_deactivate_lchan(struct l1sched_ts *ts, enum l1sched_lchan_type chan); struct l1sched_lchan_state *l1sched_find_lchan(struct l1sched_ts *ts, diff --git a/src/host/trxcon/src/sched_trx.c b/src/host/trxcon/src/sched_trx.c index d2040c559..267f12826 100644 --- a/src/host/trxcon/src/sched_trx.c +++ b/src/host/trxcon/src/sched_trx.c @@ -452,6 +452,33 @@ int l1sched_set_lchans(struct l1sched_ts *ts, uint8_t chan_nr, return rc; } +int l1sched_lchan_set_amr_cfg(struct l1sched_lchan_state *lchan, + uint8_t codecs_bitmask, uint8_t start_codec) +{ + int n = 0; + int acum = 0; + int pos; + + while ((pos = ffs(codecs_bitmask)) != 0) { + acum += pos; + LOGP_LCHANC(lchan, LOGL_DEBUG, "AMR codec[%u] = %u\n", n, acum - 1); + lchan->amr.codec[n++] = acum - 1; + codecs_bitmask >>= pos; + } + if (n == 0) { + LOGP_LCHANC(lchan, LOGL_ERROR, "Empty AMR codec mode bitmask!\n"); + return -EINVAL; + } + + lchan->amr.codecs = n; + lchan->amr.dl_ft = start_codec; + lchan->amr.dl_cmr = start_codec; + lchan->amr.ul_ft = start_codec; + lchan->amr.ul_cmr = start_codec; + + return 0; +} + int l1sched_activate_lchan(struct l1sched_ts *ts, enum l1sched_lchan_type chan) { const struct l1sched_lchan_desc *lchan_desc = &l1sched_lchan_desc[chan]; diff --git a/src/host/trxcon/src/trxcon_fsm.c b/src/host/trxcon/src/trxcon_fsm.c index e3224a90d..0c37f35fd 100644 --- a/src/host/trxcon/src/trxcon_fsm.c +++ b/src/host/trxcon/src/trxcon_fsm.c @@ -35,7 +35,6 @@ #include #include #include -#include #define S(x) (1 << (x)) @@ -451,29 +450,9 @@ static void trxcon_st_dedicated_action(struct osmo_fsm_inst *fi, continue; lchan->tch_mode = req->mode; if (req->mode == GSM48_CMODE_SPEECH_AMR) { - uint8_t bmask = req->amr.codecs_bitmask; - int n = 0; - int acum = 0; - int pos; - while ((pos = ffs(bmask)) != 0) { - acum += pos; - LOGPFSML(fi, LOGL_DEBUG, - LOGP_LCHAN_NAME_FMT " AMR codec[%u] = %u\n", - LOGP_LCHAN_NAME_ARGS(lchan), n, acum - 1); - lchan->amr.codec[n++] = acum - 1; - bmask >>= pos; - } - if (n == 0) { - LOGPFSML(fi, LOGL_ERROR, - LOGP_LCHAN_NAME_FMT " Empty AMR codec mode bitmask!\n", - LOGP_LCHAN_NAME_ARGS(lchan)); - continue; - } - lchan->amr.codecs = n; - lchan->amr.dl_ft = req->amr.start_codec; - lchan->amr.dl_cmr = req->amr.start_codec; - lchan->amr.ul_ft = req->amr.start_codec; - lchan->amr.ul_cmr = req->amr.start_codec; + l1sched_lchan_set_amr_cfg(lchan, + req->amr.codecs_bitmask, + req->amr.start_codec); } req->applied = true; }