From 920e24f6d7a470aa3029bd2836cf701130520674 Mon Sep 17 00:00:00 2001 From: laranjeiro Date: Mon, 17 May 2010 09:44:07 +0000 Subject: cesar/bsu: add activate function Activation should: * launch the frequency detection on the medium. * Program the first CA schedules. * Program the timer. When deactivate only the timer is canceled. git-svn-id: svn+ssh://pessac/svn/cesar/trunk@7046 017c9cb6-072f-447c-8318-d5b54f68fe89 --- cesar/bsu/bsu.h | 7 +++++++ cesar/bsu/inc/context.h | 2 ++ cesar/bsu/src/bsu.c | 33 ++++++++++++++++++++++++++++++--- cesar/bsu/test/utest/src/bsut.c | 32 +++++++++++++++++++++++++++++++- 4 files changed, 70 insertions(+), 4 deletions(-) (limited to 'cesar') diff --git a/cesar/bsu/bsu.h b/cesar/bsu/bsu.h index e971b034cd..15d619b3eb 100644 --- a/cesar/bsu/bsu.h +++ b/cesar/bsu/bsu.h @@ -105,6 +105,13 @@ bsu_update (bsu_beacon_t *beacon, bool sta); void bsu_track_avln (u64 nid, u16 snid, u8 tei); +/** + * Activates the BSU. + * \param status true to activate, false otherwise. + */ +void +bsu_activate (bool status); + END_DECLS #endif /* bsu_bsu_h */ diff --git a/cesar/bsu/inc/context.h b/cesar/bsu/inc/context.h index 09a3aae93d..0404e3b078 100644 --- a/cesar/bsu/inc/context.h +++ b/cesar/bsu/inc/context.h @@ -81,6 +81,8 @@ struct bsu_t hal_timer_t *hal_timer; /** HAL timer instance. */ hal_timer_instance_t timer; + /** Activated status. */ + bool activate; }; #endif /* bsu_inc_context_h */ diff --git a/cesar/bsu/src/bsu.c b/cesar/bsu/src/bsu.c index 589d6989ce..054815a36b 100644 --- a/cesar/bsu/src/bsu.c +++ b/cesar/bsu/src/bsu.c @@ -392,6 +392,7 @@ bsu_init (bsu_aclf_t *aclf, mac_config_t *mac_config, phy_t *phy, timer, &ctx->timer, bsu_aclf_beacon_period_start_date_next (ctx->aclf) - MAC_US_TO_TCK (BSU_WAKEUP_DELAY_MS)); + ctx->activate = false; return ctx; } @@ -510,7 +511,8 @@ bsu_update (bsu_beacon_t *beacon, bool is_sta) < beacon->bmis.ps.ps[1].pscd)); /* If the data provided are for the next beacon period. */ if (lesseq_mod2p32 (bsu_aclf_beacon_period_start_date_next (ctx->aclf), - beacon->beacon_period_start_date)) + beacon->beacon_period_start_date) + || !ctx->activate) ctx->beacon = *beacon; /* Data in the beacon are had already expired. */ else @@ -559,11 +561,36 @@ bsu_update (bsu_beacon_t *beacon, bool is_sta) } void -bsu_track_avln (bsu_t *ctx, u64 nid, u16 snid, u8 tei) +bsu_track_avln (u64 nid, u16 snid, u8 tei) { - dbg_assert (ctx); + bsu_t *ctx = &bsu_global; ctx->nid_track = nid; ctx->snid_track = snid; ctx->tei_track = tei; ctx->sta_avln = bsu_avln_add (ctx, nid, snid); } + +void +bsu_activate (bool status) +{ + bsu_t *ctx = &bsu_global; + dbg_assert (status != ctx->activate); + ctx->activate = status; + if (status) + { + u32 bpsd[BSU_BEACON_PERIOD_NB]; + /* Frequency detection. */ + bsu_aclf_acl_frequency_detection (ctx->aclf); + /* Program the first schedules in the CA. */ + bsu_aclf_ac_compute_beacon_period_start_date (ctx->aclf); + bsu_aclf_beacon_period_start_date (ctx->aclf, bpsd, COUNT (bpsd)); + bsu_ca_schedules (ctx, ctx->sta_avln); + /* Reprogram the timer. */ + hal_timer_instance_program (ctx->hal_timer, &ctx->timer, + bpsd[1] + - MAC_MS_TO_TCK (BSU_WAKEUP_DELAY_MS)); + } + /* Stops BSU. */ + else + hal_timer_instance_cancel (ctx->hal_timer, &ctx->timer); +} diff --git a/cesar/bsu/test/utest/src/bsut.c b/cesar/bsu/test/utest/src/bsut.c index 77ff1e7ed3..c937916941 100644 --- a/cesar/bsu/test/utest/src/bsut.c +++ b/cesar/bsu/test/utest/src/bsut.c @@ -30,6 +30,7 @@ test_case_bsu_process (test_t test) { bsu_test_t t; bsu_test_init (&t); + bsu_activate (true); test_case_begin (test, "BSU process"); test_begin (test, "Process function on neighbour beacon") { @@ -78,7 +79,7 @@ test_case_bsu_process (test_t test) test_fail_unless (t.bsu->avlns[0].sync.beacon_nb == 2); blk_release_desc ((blk_t*) bneighbour); /* Our AVLN. */ - bsu_track_avln (t.bsu, 0x2, 0x5, t.mac_config.tei); + bsu_track_avln (0x2, 0x5, t.mac_config.tei); bsu_test_create_beacon (&t, &beacon); beacon.vf.nid = 0x2; b = bsu_beacon_write (&beacon, BSU_BEACON_TYPE_CENTRAL, @@ -126,6 +127,7 @@ test_case_bsu_update (test_t test) bsu_test_t t; bsu_beacon_t beacon; bsu_test_init (&t); + bsu_activate (true); test_case_begin (test, "BSU Update"); test_begin (test, "update BSU in time") { @@ -231,6 +233,7 @@ test_case_bsu_timer_event (test_t test) bsu_test_t t; bsu_avln_t cmp_avln; bsu_test_init (&t); + bsu_activate (true); bsu_test_avln_create (&t, t.bsu->sta_avln); bsu_test_avln_create (&t, &cmp_avln); for (i = 0; i < BSU_ACLF_BPSD_NB; i++) @@ -262,6 +265,7 @@ test_case_bsu_timer_event (test_t test) uint i,j; bsu_avln_t cmp_avln; bsu_test_init (&t); + bsu_activate (true); bsu_test_avln_create (&t, &cmp_avln); for (i = 0; i < BSU_ACLF_BPSD_NB; i++) t.bsu->aclf->bpsd[i] = i * BSU_ACLF_BP_50HZ_TCK; @@ -312,10 +316,36 @@ test_case_bsu_timer_event (test_t test) test_end; } +void +test_case_bsu_activate (test_t test) +{ + bsu_test_t t; + bsu_test_init (&t); + test_case_begin (test, "BSU activate"); + test_begin (test, "Activate/deactivate") + { + u32 bpsd[4]; + uint i; + bsu_activate (true); + test_fail_unless (t.bsu->activate == true); + bsu_aclf_beacon_period_start_date (t.bsu->aclf, bpsd, COUNT(bpsd)); + for (i = 0; i < COUNT (bpsd) - 1; i++) + test_fail_unless (bpsd[i] != bpsd[i+1]); + test_fail_unless (t.ca.nb_beacon_periods == 4); + for (i = 0; i < COUNT (bpsd); i++) + test_fail_unless (t.ca.beacon_periods[i].start_date == bpsd[i]); + bsu_activate (false); + test_fail_unless (t.bsu->activate == false); + } + test_end; + bsu_test_uninit (&t); +} + void test_suite_bsu (test_t t) { test_suite_begin (t, "BSU test"); + test_case_bsu_activate (t); test_case_bsu_process (t); test_case_bsu_update (t); test_case_bsu_timer_event (t); -- cgit v1.2.3