summaryrefslogtreecommitdiff
path: root/cesar
diff options
context:
space:
mode:
Diffstat (limited to 'cesar')
-rw-r--r--cesar/cp/sta/action/src/misc.c91
-rw-r--r--cesar/cp/sta/action/test/utest/src/misc.c136
-rw-r--r--cesar/mac/common/src/tonemap.c41
-rw-r--r--cesar/mac/common/tonemap.h16
4 files changed, 269 insertions, 15 deletions
diff --git a/cesar/cp/sta/action/src/misc.c b/cesar/cp/sta/action/src/misc.c
index 5318cb5b53..3630c9868f 100644
--- a/cesar/cp/sta/action/src/misc.c
+++ b/cesar/cp/sta/action/src/misc.c
@@ -506,6 +506,92 @@ cp_sta_action_process_cm_sta_cap_req (cp_t *ctx, cp_mme_rx_t *rx_mme)
}
}
+/**
+ * Get ble value from tone map in TX.
+ * \param ctx control plane context
+ * \param sta distant station
+ * \param tmi tonemap index
+ * \return the ble for this station in this tonemap
+ */
+static u8
+cp_sta_action_get_ble (cp_t *ctx, sta_t *sta, int tmi)
+{
+ dbg_assert (ctx);
+
+ if (TONEMAP_INDEX_IS_NEGOTIATED(tmi))
+ {
+ dbg_assert (sta);
+ dbg_assert (sta->tx_tonemaps);
+ dbg_assert (sta->tx_tonemaps->tm[tmi]);
+ return sta->tx_tonemaps->tm[tmi]->ble;
+ }
+ else
+ {
+ dbg_assert (tmi < PHY_MOD_ROBO_NB);
+ dbg_assert (ctx->mac_config);
+ return ctx->mac_config->tonemask_info.tonemap_robo[tmi].ble;
+ }
+}
+
+/**
+ * Get the average ble value for one station.
+ * \param ctx control plane context
+ * \param tei the tei of the distant station
+ * \return the average ble for this station
+ */
+static u8
+cp_sta_action_get_average_ble (cp_t *ctx, cp_tei_t tei)
+{
+ sta_t *sta = mac_store_sta_get (ctx->mac_store, tei);
+ u8 average_ble;
+
+ if (sta)
+ {
+ u8 int_nb = sta->tx_tonemaps->intervals->intervals_nb;
+
+ if (int_nb)
+ {
+ int i;
+ uint ble_sum = 0;
+ u16 offset_atu;
+ u16 last_offset_atu = 0;
+
+ for (i = 0; i < int_nb; i++)
+ {
+ int tmi = sta->tx_tonemaps->intervals->interval[i].tmi;
+ offset_atu =
+ sta->tx_tonemaps->intervals->interval[i].end_offset_atu;
+
+ ble_sum +=
+ tonemap_ble_mant_2_uf5 (cp_sta_action_get_ble (ctx, sta,
+ tmi))
+ * (offset_atu - last_offset_atu);
+
+ last_offset_atu = offset_atu;
+ }
+
+ dbg_assert (last_offset_atu);
+
+ average_ble =
+ tonemap_ble_uf5_2_mant (ble_sum / last_offset_atu);
+ }
+ else
+ {
+ average_ble =
+ cp_sta_action_get_ble (ctx, sta,
+ sta->tx_tonemaps->default_tmi);
+ }
+
+ blk_release (sta);
+ }
+ else
+ {
+ average_ble = 0;
+ }
+
+ return average_ble;
+}
+
void
cp_sta_action_process_cc_discover_list_req (cp_t *ctx, cp_mme_rx_t *rx_mme)
{
@@ -571,7 +657,10 @@ cp_sta_action_process_cc_discover_list_req (cp_t *ctx, cp_mme_rx_t *rx_mme)
list.pco_status = cp_sta_get_pco_status (cp_sta);
list.backup_cco_status = cp_sta->is_backup_cco;
list.signal_level = 0x00;
- list.average_ble = 0x00;
+
+ /** Compute average ble of the sta. */
+ list.average_ble =
+ cp_sta_action_get_average_ble (ctx, list.tei);
cp_msg_cc_discover_list_cnf_send_station (ctx, tx_mme,
&list);
diff --git a/cesar/cp/sta/action/test/utest/src/misc.c b/cesar/cp/sta/action/test/utest/src/misc.c
index 491fa18b05..dc06813805 100644
--- a/cesar/cp/sta/action/test/utest/src/misc.c
+++ b/cesar/cp/sta/action/test/utest/src/misc.c
@@ -220,12 +220,18 @@ misc_cc_discover_list_test_case (test_t t)
scenario_run (t, entries, &globals);
} test_end;
- /* One station is created in our network. */
+ /** One station is created in our network with no interval and
+ * default tmi = 0. */
cp_sta_t *sta_2 = cp_sta_mgr_sta_add (cp, my_net, tei + 2, mac + 2);
other_net->network_mode = CP_NET_NM_COORDINATED;
other_net->avln_slot_id = 2;
my_net->avln_slot_id = 1;
+ sta_t *sta2 = mac_store_sta_get (cp->mac_store, tei+2);
+ sta2->tx_tonemaps->intervals->intervals_nb = 0;
+ sta2->tx_tonemaps->default_tmi = PHY_MOD_ROBO;
+ cp->mac_config->tonemask_info.tonemap_robo[PHY_MOD_ROBO].ble = 0x12;
+
test_begin (t, "two stations and one network")
{
scenario_entry_t entries[] = {
@@ -263,7 +269,128 @@ misc_cc_discover_list_test_case (test_t t)
.pco_status = 0,
.backup_cco_status = 0,
.signal_level = 0,
+ .average_ble = 0x12),
+ SCENARIO_EVENT (cp_msg_cc_discover_list_cnf_send_net_begin,
+ .disc_ctxc = &disc_ctx),
+ SCENARIO_EVENT (cp_msg_cc_discover_list_cnf_send_net,
+ .nid = nid,
+ .snid = snid,
+ .access = 0,
+ .hm = other_net->hm,
+ .numslots = other_net->avln_num_slots,
+ .coordinated_status =
+ CC_DISCOVER_LIST_COORD_COORDINATED_GROUP_UNKNOWN,
+ .offset = 0),
+ SCENARIO_EVENT (cp_msg_cc_discover_list_cnf_send_end),
+ SCENARIO_END
+ };
+ scenario_run (t, entries, &globals);
+ } test_end;
+
+ /** A new station is created in our network with no interval and
+ * negociated default tmi. */
+ cp_sta_t *sta_3 = cp_sta_mgr_sta_add (cp, my_net, tei + 3, mac + 3);
+
+ sta_t *sta3 = mac_store_sta_get (cp->mac_store, tei+3);
+ sta3->tx_tonemaps->intervals->intervals_nb = 0;
+ sta3->tx_tonemaps->default_tmi = TONEMAP_INDEX_NEGOTIATED_FIRST;
+ sta3->tx_tonemaps->tm[TONEMAP_INDEX_NEGOTIATED_FIRST] = tonemap_alloc ();
+ sta3->tx_tonemaps->tm[TONEMAP_INDEX_NEGOTIATED_FIRST]->ble = 0x23;
+
+ /** A new station is created in our network with 4 intervals . */
+ cp_sta_t *sta_4 = cp_sta_mgr_sta_add (cp, my_net, tei + 4, mac + 4);
+
+ sta_t *sta4 = mac_store_sta_get (cp->mac_store, tei+4);
+ sta4->tx_tonemaps->intervals->intervals_nb = 4;
+ sta4->tx_tonemaps->default_tmi = TONEMAP_INDEX_NEGOTIATED_FIRST;
+ sta4->tx_tonemaps->tm[TONEMAP_INDEX_NEGOTIATED_FIRST] = tonemap_alloc ();
+ sta4->tx_tonemaps->tm[TONEMAP_INDEX_NEGOTIATED_FIRST]->ble = 0xFF;
+ sta4->tx_tonemaps->tm[TONEMAP_INDEX_NEGOTIATED_FIRST + 1] = tonemap_alloc ();
+ sta4->tx_tonemaps->tm[TONEMAP_INDEX_NEGOTIATED_FIRST + 1]->ble = 0x00;
+ sta4->tx_tonemaps->tm[TONEMAP_INDEX_NEGOTIATED_FIRST + 2] = tonemap_alloc ();
+ sta4->tx_tonemaps->tm[TONEMAP_INDEX_NEGOTIATED_FIRST + 2]->ble = 0x08;
+ sta4->tx_tonemaps->tm[TONEMAP_INDEX_NEGOTIATED_FIRST + 3] = tonemap_alloc ();
+ sta4->tx_tonemaps->tm[TONEMAP_INDEX_NEGOTIATED_FIRST + 3]->ble = 0x0F;
+
+ sta4->tx_tonemaps->intervals->interval[0].tmi =
+ TONEMAP_INDEX_NEGOTIATED_FIRST;
+ sta4->tx_tonemaps->intervals->interval[0].end_offset_atu = 10;
+ sta4->tx_tonemaps->intervals->interval[1].tmi =
+ TONEMAP_INDEX_NEGOTIATED_FIRST + 1;
+ sta4->tx_tonemaps->intervals->interval[1].end_offset_atu = 100;
+ sta4->tx_tonemaps->intervals->interval[2].tmi =
+ TONEMAP_INDEX_NEGOTIATED_FIRST + 2;
+ sta4->tx_tonemaps->intervals->interval[2].end_offset_atu = 400;
+ sta4->tx_tonemaps->intervals->interval[3].tmi =
+ TONEMAP_INDEX_NEGOTIATED_FIRST + 3;
+ sta4->tx_tonemaps->intervals->interval[3].end_offset_atu = 500;
+
+ test_begin (t, "two stations and one network")
+ {
+ scenario_entry_t entries[] = {
+ SCENARIO_ACTION (process_cc_discover_list_req, .peer = peer),
+ SCENARIO_EVENT (cp_msg_cc_discover_list_req_receive, .ok = true),
+ SCENARIO_EVENT (cp_msg_cc_discover_list_cnf_send_begin,
+ .nb_sta = 4, .nb_net = 1, .disc_ctx = &disc_ctx),
+ SCENARIO_EVENT (cp_msg_cc_discover_list_cnf_send_stations_begin,
+ .disc_ctxc = &disc_ctx),
+ SCENARIO_EVENT (cp_msg_cc_discover_list_cnf_send_station,
+ .mac_addr = mac,
+ .tei = tei,
+ .same_network =
+ CC_DISCOVER_LIST_NET_DIFFERENT_NETWORK,
+ .snid = snid,
+ .access = 0,
+ .cco_cap = 0,
+ .proxy_cap = 0,
+ .backup_cco_cap = 0,
+ .cco_status = 0,
+ .pco_status = 0,
+ .backup_cco_status = 0,
+ .signal_level = 0,
.average_ble = 0),
+ SCENARIO_EVENT (cp_msg_cc_discover_list_cnf_send_station,
+ .mac_addr = mac+2,
+ .tei = tei+2,
+ .same_network = CC_DISCOVER_LIST_NET_SAME_NETWORK,
+ .snid = snid+1,
+ .access = 0,
+ .cco_cap = 0,
+ .proxy_cap = 0,
+ .backup_cco_cap = 0,
+ .cco_status = 0,
+ .pco_status = 0,
+ .backup_cco_status = 0,
+ .signal_level = 0,
+ .average_ble = 0x12),
+ SCENARIO_EVENT (cp_msg_cc_discover_list_cnf_send_station,
+ .mac_addr = mac+3,
+ .tei = tei+3,
+ .same_network = CC_DISCOVER_LIST_NET_SAME_NETWORK,
+ .snid = snid+1,
+ .access = 0,
+ .cco_cap = 0,
+ .proxy_cap = 0,
+ .backup_cco_cap = 0,
+ .cco_status = 0,
+ .pco_status = 0,
+ .backup_cco_status = 0,
+ .signal_level = 0,
+ .average_ble = 0x23),
+ SCENARIO_EVENT (cp_msg_cc_discover_list_cnf_send_station,
+ .mac_addr = mac+4,
+ .tei = tei+4,
+ .same_network = CC_DISCOVER_LIST_NET_SAME_NETWORK,
+ .snid = snid+1,
+ .access = 0,
+ .cco_cap = 0,
+ .proxy_cap = 0,
+ .backup_cco_cap = 0,
+ .cco_status = 0,
+ .pco_status = 0,
+ .backup_cco_status = 0,
+ .signal_level = 0,
+ .average_ble = 0xFC),
SCENARIO_EVENT (cp_msg_cc_discover_list_cnf_send_net_begin,
.disc_ctxc = &disc_ctx),
SCENARIO_EVENT (cp_msg_cc_discover_list_cnf_send_net,
@@ -282,10 +409,17 @@ misc_cc_discover_list_test_case (test_t t)
} test_end;
/* Cleanup. */
+ blk_release (sta4);
+ blk_release (sta3);
+ blk_release (sta2);
slab_release (sta_1);
cp_sta_mgr_sta_remove_from_mac (cp, mac);
slab_release (sta_2);
cp_sta_mgr_sta_remove_from_mac (cp, mac + 2);
+ slab_release (sta_3);
+ cp_sta_mgr_sta_remove_from_mac (cp, mac + 3);
+ slab_release (sta_4);
+ cp_sta_mgr_sta_remove_from_mac (cp, mac + 4);
test_sta_action_uninit (&ctx);
}
diff --git a/cesar/mac/common/src/tonemap.c b/cesar/mac/common/src/tonemap.c
index 4f6d4f4d31..eda0fc9a27 100644
--- a/cesar/mac/common/src/tonemap.c
+++ b/cesar/mac/common/src/tonemap.c
@@ -293,6 +293,33 @@ tonemap_tcc_halfit (uint bits_per_symbol, uint bits_per_pb, phy_gil_t gil)
return MIN (halfit, 31u);
}
+uint
+tonemap_ble_mant_2_uf5 (u8 ble)
+{
+ u8 mant = ble >> 3;
+ u8 exp = ble & ((1 << 3) - 1);
+
+ return (mant + 31) * (1 << (exp + 1)) + (1 << (exp));
+}
+
+u8
+tonemap_ble_uf5_2_mant (uint ble_uf5)
+{
+ if (ble_uf5 >= TONEMAP_BLE_MAX * (1u << 5))
+ return 0xff;
+ else if (ble_uf5 < (2 * (1u << 5)) + 1)
+ return 0;
+ else
+ {
+ uint exp, mant;
+ exp = tonemap_ble_log2 (ble_uf5 >> 5) - 1;
+ dbg_assert (exp < (1u << 3));
+ mant = (ble_uf5 >> (exp + 1)) - 32;
+ dbg_assert (mant < (1u << 5));
+ return mant << 3 | exp;
+ }
+}
+
u8
tonemap_ble (uint bits_per_symbol, phy_fecrate_t fecrate, u32 p_pberror_uf32,
phy_gil_t gil)
@@ -329,19 +356,7 @@ tonemap_ble (uint bits_per_symbol, phy_fecrate_t fecrate, u32 p_pberror_uf32,
dbg_assert_default ();
}
/* Convert to BLE floating point format. */
- if (ble_uf5 >= TONEMAP_BLE_MAX * (1u << 5))
- return 0xff;
- else if (ble_uf5 < (2 * (1u << 5)) + 1)
- return 0;
- else
- {
- uint exp, mant;
- exp = tonemap_ble_log2 (ble_uf5 >> 5) - 1;
- dbg_assert (exp < (1u << 3));
- mant = (ble_uf5 >> (exp + 1)) - 32;
- dbg_assert (mant < (1u << 5));
- return mant << 3 | exp;
- }
+ return tonemap_ble_uf5_2_mant (ble_uf5);
}
void
diff --git a/cesar/mac/common/tonemap.h b/cesar/mac/common/tonemap.h
index 29d14f953e..39b2442b7e 100644
--- a/cesar/mac/common/tonemap.h
+++ b/cesar/mac/common/tonemap.h
@@ -633,6 +633,22 @@ uint
tonemap_tcc_halfit (uint bits_per_symbol, uint bits_per_pb, phy_gil_t gil);
/**
+ * Convert ble in FC representation to floating point representation.
+ * \param ble ble in FC representation (5 bits mantissa, 3 bits exponent)
+ * \return ble in floating point representation (real value << 5)
+ */
+uint
+tonemap_ble_mant_2_uf5 (u8 ble);
+
+/**
+ * Convert ble in floating point representation to FC representation.
+ * \param ble ble in floating point representation (real value << 5)
+ * \return ble in FC representation (5 bits mantissa, 3 bits exponent)
+ */
+u8
+tonemap_ble_uf5_2_mant (uint ble);
+
+/**
* Compute floating point representation of BLE for frame control field.
* \param bits_per_symbol number of bits per symbol
* \param fecrate FEC encoding rate