fixeria has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/libosmo-gprs/+/34627?usp=email )


Change subject: rlcmac: migrate from fn_cmp() to gsm0502_fncmp()
......................................................................

rlcmac: migrate from fn_cmp() to gsm0502_fncmp()

Change-Id: I3030d00c6881713a088b1739b2b5ba77bac84e46
Depends: libosmocore.git I9590f2e836fc48650decf1564b6ab46306c4fe2d
Depends: libosmocore.git Ie8bb9c49c6f81b8f4a1766547d6943f9880d1186
---
M include/osmocom/gprs/rlcmac/sched.h
M src/rlcmac/pdch_ul_controller.c
M src/rlcmac/tbf_dl_ass_fsm.c
M src/rlcmac/tbf_ul_ass_fsm.c
4 files changed, 27 insertions(+), 28 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmo-gprs refs/changes/27/34627/1

diff --git a/include/osmocom/gprs/rlcmac/sched.h 
b/include/osmocom/gprs/rlcmac/sched.h
index a90cbc1..9e03c01 100644
--- a/include/osmocom/gprs/rlcmac/sched.h
+++ b/include/osmocom/gprs/rlcmac/sched.h
@@ -20,20 +20,6 @@
        return f == 0 || f == 4 || f == 8;
 }

-#define GSM_MAX_FN_THRESH (GSM_MAX_FN >> 1)
-/* 0: equal, -1: fn1 BEFORE fn2, 1: fn1 AFTER fn2 */
-static inline int fn_cmp(uint32_t fn1, uint32_t fn2)
-{
-       if (fn1 == fn2)
-               return 0;
-       /* FN1 goes before FN2: */
-       if ((fn1 < fn2 && (fn2 - fn1) < GSM_MAX_FN_THRESH) ||
-           (fn1 > fn2 && (fn1 - fn2) > GSM_MAX_FN_THRESH))
-               return -1;
-       /* FN1 goes after FN2: */
-       return 1;
-}
-
 static inline uint32_t fn2bn(uint32_t fn)
 {
        return (fn % 52) / 4;
diff --git a/src/rlcmac/pdch_ul_controller.c b/src/rlcmac/pdch_ul_controller.c
index 7c5e41a..b6859b1 100644
--- a/src/rlcmac/pdch_ul_controller.c
+++ b/src/rlcmac/pdch_ul_controller.c
@@ -22,6 +22,7 @@
 #include <osmocom/core/linuxlist.h>
 #include <osmocom/core/linuxrbtree.h>
 #include <osmocom/gsm/gsm_utils.h>
+#include <osmocom/gsm/gsm0502.h>

 #include <osmocom/gprs/rlcmac/pdch_ul_controller.h>
 #include <osmocom/gprs/rlcmac/rlcmac_private.h>
@@ -61,7 +62,7 @@

        while (node) {
                it = rb_entry(node, struct gprs_rlcmac_pdch_ulc_node, node);
-               res = fn_cmp(it->fn, fn);
+               res = gsm0502_fncmp(it->fn, fn);
                if (res > 0) /* it->fn AFTER fn */
                        node = node->rb_left;
                else if (res < 0) /* it->fn BEFORE fn */
@@ -105,7 +106,7 @@
                it = container_of(*n, struct gprs_rlcmac_pdch_ulc_node, node);

                parent = *n;
-               res = fn_cmp(item->fn, it->fn);
+               res = gsm0502_fncmp(item->fn, it->fn);
                if (res < 0) { /* item->fn "BEFORE" it->fn */
                        n = &((*n)->rb_left);
                } else if (res > 0) { /* item->fn "AFTER" it->fn */
@@ -180,7 +181,7 @@
        struct rb_node *first;
        while ((first = rb_first(&ulc->tree_root))) {
                item = container_of(first, struct gprs_rlcmac_pdch_ulc_node, 
node);
-               res = fn_cmp(item->fn, fn);
+               res = gsm0502_fncmp(item->fn, fn);
                if (res > 0) /* item->fn AFTER fn */
                        break;
                if (res < 0) { /* item->fn BEFORE fn */
diff --git a/src/rlcmac/tbf_dl_ass_fsm.c b/src/rlcmac/tbf_dl_ass_fsm.c
index 9acf723..fec375f 100644
--- a/src/rlcmac/tbf_dl_ass_fsm.c
+++ b/src/rlcmac/tbf_dl_ass_fsm.c
@@ -24,6 +24,7 @@
 #include <osmocom/core/tdef.h>
 #include <osmocom/core/fsm.h>
 #include <osmocom/core/bitvec.h>
+#include <osmocom/gsm/gsm0502.h>

 #include <osmocom/gprs/rlcmac/types.h>
 #include <osmocom/gprs/rlcmac/tbf_dl_ass_fsm.h>
@@ -141,7 +142,7 @@
                        return;
                memcpy(&ctx->iaro, ev_ccch_imm_ass->iaro, sizeof(ctx->iaro));
                if (ctx->tbf_starting_time_exists &&
-                   fn_cmp(ctx->tbf_starting_time, ev_ccch_imm_ass->fn) > 0)
+                   gsm0502_fncmp(ctx->tbf_starting_time, ev_ccch_imm_ass->fn) 
> 0)
                        tbf_dl_ass_fsm_state_chg(fi, 
GPRS_RLCMAC_TBF_DL_ASS_ST_WAIT_TBF_STARTING_TIME);
                else
                        tbf_dl_ass_fsm_state_chg(fi, 
GPRS_RLCMAC_TBF_DL_ASS_ST_COMPL);
@@ -152,7 +153,7 @@
                        return;
                memcpy(&ctx->dl_block, ev_pacch_pkt_ass->dl_block, 
sizeof(ctx->dl_block));
                if (ctx->tbf_starting_time_exists &&
-                   fn_cmp(ctx->tbf_starting_time, ev_pacch_pkt_ass->fn) > 0)
+                   gsm0502_fncmp(ctx->tbf_starting_time, ev_pacch_pkt_ass->fn) 
> 0)
                        tbf_dl_ass_fsm_state_chg(fi, 
GPRS_RLCMAC_TBF_DL_ASS_ST_WAIT_TBF_STARTING_TIME);
                else
                        tbf_dl_ass_fsm_state_chg(fi, 
GPRS_RLCMAC_TBF_DL_ASS_ST_COMPL);
@@ -175,7 +176,7 @@
                        return;
                memcpy(&ctx->iaro, ev_ccch_imm_ass->iaro, sizeof(ctx->iaro));
                if (ctx->tbf_starting_time_exists &&
-                   fn_cmp(ctx->tbf_starting_time, ev_ccch_imm_ass->fn) > 0)
+                   gsm0502_fncmp(ctx->tbf_starting_time, ev_ccch_imm_ass->fn) 
> 0)
                        tbf_dl_ass_fsm_state_chg(fi, 
GPRS_RLCMAC_TBF_DL_ASS_ST_WAIT_TBF_STARTING_TIME);
                else
                        tbf_dl_ass_fsm_state_chg(fi, 
GPRS_RLCMAC_TBF_DL_ASS_ST_COMPL);
@@ -186,7 +187,7 @@
                        return;
                memcpy(&ctx->dl_block, ev_pacch_pkt_ass->dl_block, 
sizeof(ctx->dl_block));
                if (ctx->tbf_starting_time_exists &&
-                   fn_cmp(ctx->tbf_starting_time, ev_pacch_pkt_ass->fn) > 0)
+                   gsm0502_fncmp(ctx->tbf_starting_time, ev_pacch_pkt_ass->fn) 
> 0)
                        tbf_dl_ass_fsm_state_chg(fi, 
GPRS_RLCMAC_TBF_DL_ASS_ST_WAIT_TBF_STARTING_TIME);
                else
                        tbf_dl_ass_fsm_state_chg(fi, 
GPRS_RLCMAC_TBF_DL_ASS_ST_COMPL);
diff --git a/src/rlcmac/tbf_ul_ass_fsm.c b/src/rlcmac/tbf_ul_ass_fsm.c
index b1be58c..5957d35 100644
--- a/src/rlcmac/tbf_ul_ass_fsm.c
+++ b/src/rlcmac/tbf_ul_ass_fsm.c
@@ -303,7 +303,7 @@
                if (handle_imm_ass(ctx, ev_rx_ccch_imm_ass_ctx) < 0)
                        return;
                if (ctx->tbf_starting_time_exists &&
-                   fn_cmp(ctx->tbf_starting_time, ev_rx_ccch_imm_ass_ctx->fn) 
> 0) {
+                   gsm0502_fncmp(ctx->tbf_starting_time, 
ev_rx_ccch_imm_ass_ctx->fn) > 0) {
                        tbf_ul_ass_fsm_state_chg(fi, 
GPRS_RLCMAC_TBF_UL_ASS_ST_WAIT_TBF_STARTING_TIME1);
                        return;
                }
@@ -338,7 +338,7 @@
                if (handle_imm_ass(ctx, ev_rx_ccch_imm_ass_ctx) < 0)
                        return;
                if (ctx->tbf_starting_time_exists &&
-                   fn_cmp(ctx->tbf_starting_time, ev_rx_ccch_imm_ass_ctx->fn) 
> 0) {
+                   gsm0502_fncmp(ctx->tbf_starting_time, 
ev_rx_ccch_imm_ass_ctx->fn) > 0) {
                        tbf_ul_ass_fsm_state_chg(fi, 
GPRS_RLCMAC_TBF_UL_ASS_ST_WAIT_TBF_STARTING_TIME1);
                        return;
                }
@@ -399,14 +399,14 @@
                        /* We need to wait at least until sending the PKT CTRL
                         * ACK (in the old CTRL TS) before completing the
                         * assignment and using the new TS assignment. */
-                       if (!ctx->tbf_starting_time_exists && 
fn_cmp(ctx->tbf_starting_time, next_blk) < 0) {
+                       if (!ctx->tbf_starting_time_exists && 
gsm0502_fncmp(ctx->tbf_starting_time, next_blk) < 0) {
                                ctx->tbf_starting_time_exists = true;
                                ctx->tbf_starting_time = next_blk;
                        }
                }

                if (ctx->tbf_starting_time_exists &&
-                   fn_cmp(ctx->tbf_starting_time, d->fn) > 0) {
+                   gsm0502_fncmp(ctx->tbf_starting_time, d->fn) > 0) {
                        tbf_ul_ass_fsm_state_chg(fi, 
GPRS_RLCMAC_TBF_UL_ASS_ST_WAIT_TBF_STARTING_TIME2);
                } else {
                        tbf_ul_ass_fsm_state_chg(fi, 
GPRS_RLCMAC_TBF_UL_ASS_ST_COMPL);
@@ -460,14 +460,14 @@
                        /* We need to wait at least until sending the PKT CTRL
                         * ACK (in the old CTRL TS) before completing the
                         * assignment and using the new TS assignment. */
-                       if (!ctx->tbf_starting_time_exists && 
fn_cmp(ctx->tbf_starting_time, next_blk) < 0) {
+                       if (!ctx->tbf_starting_time_exists && 
gsm0502_fncmp(ctx->tbf_starting_time, next_blk) < 0) {
                                ctx->tbf_starting_time_exists = true;
                                ctx->tbf_starting_time = next_blk;
                        }
                }

                if (ctx->tbf_starting_time_exists &&
-                   fn_cmp(ctx->tbf_starting_time, d->fn) > 0) {
+                   gsm0502_fncmp(ctx->tbf_starting_time, d->fn) > 0) {
                        tbf_ul_ass_fsm_state_chg(fi, 
GPRS_RLCMAC_TBF_UL_ASS_ST_WAIT_TBF_STARTING_TIME2);
                } else {
                        tbf_ul_ass_fsm_state_chg(fi, 
GPRS_RLCMAC_TBF_UL_ASS_ST_COMPL);
@@ -732,7 +732,7 @@
        default:
                OSMO_ASSERT(0);
        }
-       res = fn_cmp(fn, ul_tbf->ul_ass_fsm.tbf_starting_time);
+       res = gsm0502_fncmp(fn, ul_tbf->ul_ass_fsm.tbf_starting_time);
        if (res < 0) {/* fn BEFORE tbf_starting_time */
                LOGPTBFUL(ul_tbf, LOGL_DEBUG, "TS=%" PRIu8 " FN=%u Waiting for 
tbf_starting_time=%u\n",
                          ts_nr, fn, ul_tbf->ul_ass_fsm.tbf_starting_time);

--
To view, visit https://gerrit.osmocom.org/c/libosmo-gprs/+/34627?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmo-gprs
Gerrit-Branch: master
Gerrit-Change-Id: I3030d00c6881713a088b1739b2b5ba77bac84e46
Gerrit-Change-Number: 34627
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <[email protected]>
Gerrit-MessageType: newchange

Reply via email to