summaryrefslogtreecommitdiff
path: root/cesar
diff options
context:
space:
mode:
authordufour2010-05-19 14:58:17 +0000
committerdufour2010-05-19 14:58:17 +0000
commitdf65b73fd6d173cae76eb14785ea4398989a11cb (patch)
tree09ac086646094ba2921acaec35467d3a9aa2500d /cesar
parent2bf9707a081ad7b02ef44139e0303112f1cdfed6 (diff)
cesar/ce/rx: prevent the CE from restarting too soon, closes #1557
Add a minimum time to respect between too restart of the CE. This time is expressed in milliseconds and can be configured (default value set to 500ms) for both PB error rate and BER criteria. Also change the type of PB error rate frame counter which can now overflow because of this new criteria. git-svn-id: svn+ssh://pessac/svn/cesar/trunk@7117 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar')
-rw-r--r--cesar/ce/rx/bitloading/bitloading.h5
-rw-r--r--cesar/ce/rx/bitloading/inc/common.h6
-rw-r--r--cesar/ce/rx/bitloading/src/common.c13
-rw-r--r--cesar/ce/rx/bitloading/src/transition.c17
-rw-r--r--cesar/ce/rx/bitloading/test/fsm-Makefile4
-rw-r--r--cesar/ce/rx/bitloading/test/host-Makefile4
-rw-r--r--cesar/ce/rx/bitloading/test/override/cyg/kernel/kapi.h19
-rw-r--r--cesar/ce/rx/bitloading/test/src/ecos_stub.c21
-rw-r--r--cesar/ce/rx/bitloading/test/src/test_fsm.c67
-rw-r--r--cesar/ce/rx/inc/rx.h4
-rw-r--r--cesar/ce/rx/src/rx.c11
11 files changed, 160 insertions, 11 deletions
diff --git a/cesar/ce/rx/bitloading/bitloading.h b/cesar/ce/rx/bitloading/bitloading.h
index b37e31e953..8c9867bb65 100644
--- a/cesar/ce/rx/bitloading/bitloading.h
+++ b/cesar/ce/rx/bitloading/bitloading.h
@@ -45,9 +45,12 @@ typedef struct ce_rx_bitloading_t
/** Mean count. */
u32 mean_count;
/** Counter of frame with high PB error rate. */
- u8 high_pb_error_rate_frame_counter;
+ uint high_pb_error_rate_frame_counter;
/** BER sliding means (-1 if they are reseted). */
s64 ber_sliding_mean[CE_RX_BL_BER_SLIDING_MEAN_NB];
+ /** Next time we are allowed to restart the CE. First one is for
+ * PBErrorRate criteria, second one is for BER criteria. */
+ u32 next_date_min_for_restart_rtc_date[2];
} ce_rx_bitloading_t;
/**
diff --git a/cesar/ce/rx/bitloading/inc/common.h b/cesar/ce/rx/bitloading/inc/common.h
index f883355769..114c81352f 100644
--- a/cesar/ce/rx/bitloading/inc/common.h
+++ b/cesar/ce/rx/bitloading/inc/common.h
@@ -21,6 +21,12 @@
#include "mac/common/tonemap.h"
#include "ce/rx/inc/rx.h"
+/**
+ * Minimum time between two restarts of the CE, in milliseconds.
+ * First one is for PBErrorRate criteria, second one is for BER criteria.
+ */
+extern uint ce_rx_bl_min_time_between_ce_restart_ms[2];
+
BEGIN_DECLS
/**
diff --git a/cesar/ce/rx/bitloading/src/common.c b/cesar/ce/rx/bitloading/src/common.c
index 3311a0582d..0fc01b06b8 100644
--- a/cesar/ce/rx/bitloading/src/common.c
+++ b/cesar/ce/rx/bitloading/src/common.c
@@ -18,6 +18,11 @@
#include "ce/rx/cp/inc/cp.h"
#include "ce/rx/inc/trace.h"
#include "ce/debug/gpio/gpio.h"
+#include "mac/common/timings.h"
+
+#include <cyg/kernel/kapi.h>
+
+uint ce_rx_bl_min_time_between_ce_restart_ms[2] = { 500, 500 };
void
ce_rx_bl_start_bl (ce_rx_t *ce_rx, sta_t *sta, tonemask_info_t *ts)
@@ -33,9 +38,9 @@ ce_rx_bl_start_bl (ce_rx_t *ce_rx, sta_t *sta, tonemask_info_t *ts)
/* Compute initial tone map. */
tonemap_t *initial_tm = ce_rx_bl_initial (ts, &sta->ce_rx_bt);
+ uint i;
#if CONFIG_TRACE
/* Dump tone map in trace. */
- uint i = 0;
for (i = 0; i < PHY_CARRIER_NB - 8; i += 8)
{
u32 tm_words[4];
@@ -76,6 +81,12 @@ ce_rx_bl_start_bl (ce_rx_t *ce_rx, sta_t *sta, tonemask_info_t *ts)
sta->rx_tonemaps->default_tmi = tmi;
ce_rx_cp_send_mme_new_tone_map
(ce_rx, sta, TONEMAP_INDEX_IS_NEGOTIATED (tmi) ? tmi : 0, 0, true);
+ /* Store next time the CE can restart. */
+ for (i = 0; i < COUNT (ce_rx_bl_min_time_between_ce_restart_ms); i++)
+ sta->ce_rx_bt.next_date_min_for_restart_rtc_date[i]
+ = cyg_current_time ()
+ + MAC_MS_TO_TCK (ce_rx_bl_min_time_between_ce_restart_ms[i])
+ / ce_rx->tck_per_rtc;
ce_debug_gpio_event (CE_DEBUG_GPIO_EVENT_CE_RX_BL_WORKING, false);
ce_debug_gpio_event (CE_DEBUG_GPIO_EVENT_CE_RX_BL_ROBO_BETTER, false);
}
diff --git a/cesar/ce/rx/bitloading/src/transition.c b/cesar/ce/rx/bitloading/src/transition.c
index 957163a97b..325c89bace 100644
--- a/cesar/ce/rx/bitloading/src/transition.c
+++ b/cesar/ce/rx/bitloading/src/transition.c
@@ -29,6 +29,8 @@
#include "mac/pbproc/pbproc.h"
#include "cp/sta/mgr/sta_mgr.h"
+#include <cyg/kernel/kapi.h>
+
/**
* Common handler for initial CE when receiving measure for sound frames.
* \param ce_rx the context of the CE in RX
@@ -265,9 +267,12 @@ ce_rx_bl__TRACKING__measure_received (ce_rx_t *ce_rx, sta_t *sta,
CE_RX_TRACE (PB_ERR_RATE_HIGH, sta->tei,
measure->false_pb_count, measure->total_pb_count,
sta->ce_rx_bt.high_pb_error_rate_frame_counter);
- /* Enough frame in this case? */
- if (sta->ce_rx_bt.high_pb_error_rate_frame_counter
+ /* Enough frame in this case and not too soon? */
+ if ((sta->ce_rx_bt.high_pb_error_rate_frame_counter
>= ce_rx_bl_min_frame_with_high_pb_err_rate_)
+ && lesseq_mod2p32
+ (sta->ce_rx_bt.next_date_min_for_restart_rtc_date[0],
+ cyg_current_time ()))
{
ce_debug_gpio_event
(CE_DEBUG_GPIO_EVENT_CE_RX_BL_MEASURE_DATA_HIGH_PB_ERROR_RATE, true);
@@ -287,13 +292,17 @@ ce_rx_bl__TRACKING__measure_received (ce_rx_t *ce_rx, sta_t *sta,
tonemap_t *tm
= sta->rx_tonemaps->tm[measure->rx_params.tmi_av];
/* If this is not negotiated tone map (ROBO)
- or the tone map is not at the maximum. */
- if (!TONEMAP_INDEX_IS_NEGOTIATED (measure->rx_params.tmi_av)
+ or the tone map is not at the maximum
+ and not too soon. */
+ if ((!TONEMAP_INDEX_IS_NEGOTIATED (measure->rx_params.tmi_av)
||
((tm)
&& (tm->bits_per_symbol
< (ce_rx->mac_config->tonemask_info.carrier_nb
* CE_BIT_PER_MOD[CE_MOD_COUNT - 1]))))
+ && lesseq_mod2p32
+ (sta->ce_rx_bt.next_date_min_for_restart_rtc_date[1],
+ cyg_current_time ()))
{
/* Compute lower bound. */
u64 ber_target;
diff --git a/cesar/ce/rx/bitloading/test/fsm-Makefile b/cesar/ce/rx/bitloading/test/fsm-Makefile
index 649ff5819e..1307d643b7 100644
--- a/cesar/ce/rx/bitloading/test/fsm-Makefile
+++ b/cesar/ce/rx/bitloading/test/fsm-Makefile
@@ -8,13 +8,13 @@ include common-define.mk
HOST_PROGRAMS = test_ce_fsm
test_ce_fsm_SOURCES = scenario_actions.c test_fsm.c scenario_events.c \
- cp_sta_mgr_stub.c ce_rx_bl_stub.c
+ cp_sta_mgr_stub.c ce_rx_bl_stub.c ecos_stub.c
test_ce_fsm_MODULES = $(ce_rx_bl_modules_common) lib/scenario
ce_rx_bitloading_MODULE_SOURCES = transition.c
mac_common_MODULE_SOURCES =
-INCLUDES = ce/rx/bitloading/test
+INCLUDES += ce/rx/bitloading/test ce/rx/bitloading/test/override
# Include base makefile.
include $(BASE)/common/make/top.mk
diff --git a/cesar/ce/rx/bitloading/test/host-Makefile b/cesar/ce/rx/bitloading/test/host-Makefile
index 3eafe20de3..83ab3ccd8c 100644
--- a/cesar/ce/rx/bitloading/test/host-Makefile
+++ b/cesar/ce/rx/bitloading/test/host-Makefile
@@ -9,9 +9,11 @@ include common-define.mk
# List of program to build.
HOST_PROGRAMS = test_ce_host
-test_ce_host_SOURCES = $(ce_rx_bl_test_sources_common)
+test_ce_host_SOURCES = $(ce_rx_bl_test_sources_common) ecos_stub.c
test_ce_host_MODULES = $(ce_rx_bl_modules_common)
+INCLUDES += ce/rx/bitloading/test/override
+
# Include base makefile.
include $(BASE)/common/make/top.mk
diff --git a/cesar/ce/rx/bitloading/test/override/cyg/kernel/kapi.h b/cesar/ce/rx/bitloading/test/override/cyg/kernel/kapi.h
new file mode 100644
index 0000000000..13846e160d
--- /dev/null
+++ b/cesar/ce/rx/bitloading/test/override/cyg/kernel/kapi.h
@@ -0,0 +1,19 @@
+#ifndef ce_rx_bitloading_test_override_cyg_kernel_kapi_h
+#define ce_rx_bitloading_test_override_cyg_kernel_kapi_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2010 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ce/rx/bitloading/test/override/cyg/kernel/kapi.h
+ * \brief Override for test with eCos.
+ * \ingroup test
+ */
+
+u32
+cyg_current_time (void);
+
+#endif /* ce_rx_bitloading_test_override_cyg_kernel_kapi_h */
diff --git a/cesar/ce/rx/bitloading/test/src/ecos_stub.c b/cesar/ce/rx/bitloading/test/src/ecos_stub.c
new file mode 100644
index 0000000000..bbad9a07bf
--- /dev/null
+++ b/cesar/ce/rx/bitloading/test/src/ecos_stub.c
@@ -0,0 +1,21 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2010 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ce/rx/bitloading/test/src/ecos_stub.c
+ * \brief Stub for eCos functions.
+ * \ingroup test
+ */
+#include "common/std.h"
+
+#include <cyg/kernel/kapi.h>
+
+u32
+cyg_current_time (void)
+{
+ return 0;
+}
diff --git a/cesar/ce/rx/bitloading/test/src/test_fsm.c b/cesar/ce/rx/bitloading/test/src/test_fsm.c
index 093894432d..5ff6c20be7 100644
--- a/cesar/ce/rx/bitloading/test/src/test_fsm.c
+++ b/cesar/ce/rx/bitloading/test/src/test_fsm.c
@@ -23,6 +23,8 @@
#include "lib/scenario/scenario.h"
#include "lib/rnd.h"
+#include <cyg/kernel/kapi.h>
+
/* Dirty hack. */
uint ce_rx_bl_pb_false_factor_;
uint ce_rx_bl_pb_total_factor_;
@@ -85,6 +87,8 @@ test_ce_rx_bl_fsm_base (test_t t)
tm.bits_per_symbol = 1;
tm.ber_target_reached = 1;
ce_rx_bitloading_init (&sta.ce_rx_bt);
+ for (i = 0; i < COUNT (sta.ce_rx_bt.next_date_min_for_restart_rtc_date); i++)
+ sta.ce_rx_bt.next_date_min_for_restart_rtc_date[i] = 0;
ce_rx_measure_mbox_t measure;
test_case_begin (t, "sound not received yet");
@@ -416,6 +420,38 @@ test_ce_rx_bl_fsm_base (test_t t)
ce_rx_bitloading_uninit (&sta.ce_rx_bt);
} test_end;
+ test_begin (t, "TRACKING, high PB error rate, enough PB, but too soon, "
+ "not restarting CE")
+ {
+ ce_rx_bitloading_init (&sta.ce_rx_bt);
+ sta.ce_rx_bt.next_date_min_for_restart_rtc_date[0] = 42;
+ test_ce_rx_bl_reset (&sta.ce_rx_bt);
+ test_ce_rx_bl_measure_empty (&measure);
+ measure.total_pb_count = ce_rx_bl_min_pb_per_frame_ + lib_rnd_uniform
+ (&rnd, ((u8) (-1) - ce_rx_bl_min_pb_per_frame_));
+ measure.false_pb_count = measure.total_pb_count - 1;
+ uint i;
+ const uint limit = ce_rx_bl_min_frame_with_high_pb_err_rate_ * 2;
+ uint pos;
+ for (i = 0, pos = 0; i < limit; i++)
+ {
+ scenario_test[pos++] = (scenario_entry_t)
+ SCENARIO_ACTION (TRACKING__measure_received,
+ .sta = &sta,
+ .measure = measure,
+ .branch = ce_rx_bl_fsm_next_branch
+ (TRACKING, measure_received,
+ not_sound_pb_err_rate_low));
+ scenario_test[pos++] = (scenario_entry_t)
+ SCENARIO_EVENT (ce_rx_bl_ber_sliding_mean_update);
+ }
+
+ scenario_run (t, scenario_test, &globals);
+ /* Clean. */
+ ce_rx_bitloading_uninit (&sta.ce_rx_bt);
+ sta.ce_rx_bt.next_date_min_for_restart_rtc_date[0] = 0;
+ } test_end;
+
test_begin (t, "TRACKING, BER sliding means too low, restart CE")
{
ce_rx_bitloading_init (&sta.ce_rx_bt);
@@ -452,6 +488,37 @@ test_ce_rx_bl_fsm_base (test_t t)
ce_rx_bitloading_uninit (&sta.ce_rx_bt);
} test_end;
+ test_begin (t, "TRACKING, BER sliding means too low but too soon, "
+ "not restarting CE")
+ {
+ ce_rx_bitloading_init (&sta.ce_rx_bt);
+ sta.ce_rx_bt.next_date_min_for_restart_rtc_date[1] = 42;
+ test_ce_rx_bl_reset (&sta.ce_rx_bt);
+ test_ce_rx_bl_measure_empty (&measure);
+ measure.false_pb_count = 0;
+ measure.total_pb_count = 42;
+ tm.ber_target_reached = 0x4242;
+ sta.ce_rx_bt.ber_sliding_mean[CE_RX_BL_BER_SLIDING_MEAN_FAST] =
+ sta.ce_rx_bt.ber_sliding_mean[CE_RX_BL_BER_SLIDING_MEAN_SLOW] = 0x1;
+ uint pos = 0;
+ scenario_test[pos++] = (scenario_entry_t)
+ SCENARIO_ACTION (TRACKING__measure_received,
+ .sta = &sta,
+ .measure = measure,
+ .branch = ce_rx_bl_fsm_next_branch
+ (TRACKING, measure_received,
+ not_sound_pb_err_rate_low));
+ scenario_test[pos++] = (scenario_entry_t)
+ SCENARIO_EVENT (ce_rx_bl_ber_sliding_mean_update);
+ scenario_test[pos++] = (scenario_entry_t)
+ SCENARIO_END;
+
+ scenario_run (t, scenario_test, &globals);
+ /* Clean. */
+ ce_rx_bitloading_uninit (&sta.ce_rx_bt);
+ sta.ce_rx_bt.next_date_min_for_restart_rtc_date[1] = 0;
+ } test_end;
+
test_begin (t, "TRACKING, BER sliding means too low, restart CE, on ROBO")
{
ce_rx_bitloading_init (&sta.ce_rx_bt);
diff --git a/cesar/ce/rx/inc/rx.h b/cesar/ce/rx/inc/rx.h
index 9be3e1174d..a29c00b678 100644
--- a/cesar/ce/rx/inc/rx.h
+++ b/cesar/ce/rx/inc/rx.h
@@ -125,6 +125,10 @@ struct ce_rx_t
*/
trace_buffer_t trace_verbose;
#endif
+ /**
+ * Tick per RTC, for eCos timer & co.
+ */
+ u32 tck_per_rtc;
};
/**
diff --git a/cesar/ce/rx/src/rx.c b/cesar/ce/rx/src/rx.c
index 74a4591137..1605e589c2 100644
--- a/cesar/ce/rx/src/rx.c
+++ b/cesar/ce/rx/src/rx.c
@@ -22,6 +22,7 @@
#include "lib/stats.h"
#include "ce/rx/bitloading/inc/nsr.h"
#include "ce/rx/bitloading/inc/ber.h"
+#include "ce/rx/bitloading/inc/common.h"
/**
* Static context of the CE in RX.
@@ -88,6 +89,12 @@ ce_rx_init (mac_store_t *mac_store, sar_t *sar, pbproc_t *pbproc,
lib_stats_set_stat_value_notype ("CE_RX_BL_BER_LOWER_BOUND",
&ce_rx_bl_ber_lower_bound_,
LIB_STATS_ACCESS_READ_WRITE);
+ lib_stats_set_stat_value_notype ("CE_RX_BL_MIN_TIME_BETWEEN_CE_RESTART_PBER_MS",
+ &ce_rx_bl_min_time_between_ce_restart_ms[0],
+ LIB_STATS_ACCESS_READ_WRITE);
+ lib_stats_set_stat_value_notype ("CE_RX_BL_MIN_TIME_BETWEEN_CE_RESTART_BER_MS",
+ &ce_rx_bl_min_time_between_ce_restart_ms[1],
+ LIB_STATS_ACCESS_READ_WRITE);
/* ECos. */
/* No work to do. */
@@ -103,9 +110,9 @@ ce_rx_init (mac_store_t *mac_store, sar_t *sar, pbproc_t *pbproc,
&ce_rx.alarm_handler, &ce_rx.alarm);
cyg_resolution_t res = cyg_clock_get_resolution (cyg_real_time_clock ());
- u32 tck_per_rtc = MAC_MS_TO_TCK (1000LL) * res.dividend / res.divisor
+ ce_rx.tck_per_rtc = MAC_MS_TO_TCK (1000LL) * res.dividend / res.divisor
/ 1000000000LL;
- cyg_tick_count_t period = MAC_MS_TO_TCK (1000) / tck_per_rtc;
+ cyg_tick_count_t period = MAC_MS_TO_TCK (1000) / ce_rx.tck_per_rtc;
cyg_alarm_initialize (ce_rx.alarm_handler, period + cyg_current_time (),
period);