summaryrefslogtreecommitdiff
path: root/cesar/cp/beacon
diff options
context:
space:
mode:
authorNélio Laranjeiro2010-12-01 17:13:52 +0100
committerNélio Laranjeiro2011-01-11 15:38:35 +0100
commit224594457d46d928d94ee26990a510db3e301f9e (patch)
treea4e8b8daf7271f97dd91163da515da0ddd1ca8cd /cesar/cp/beacon
parent914df2a99b98f55c244f84c2583a9a2c6f66ef29 (diff)
cesar/cp/beacon: remove shared memory to update beacon to BSU, closes #2126
Diffstat (limited to 'cesar/cp/beacon')
-rw-r--r--cesar/cp/beacon/beacon.h10
-rw-r--r--cesar/cp/beacon/inc/beacon.h6
-rw-r--r--cesar/cp/beacon/src/beacon.c52
-rw-r--r--cesar/cp/beacon/stub/src/beacon.c17
-rw-r--r--cesar/cp/beacon/test/src/beacon.c80
5 files changed, 66 insertions, 99 deletions
diff --git a/cesar/cp/beacon/beacon.h b/cesar/cp/beacon/beacon.h
index 480b016baf..6986372c33 100644
--- a/cesar/cp/beacon/beacon.h
+++ b/cesar/cp/beacon/beacon.h
@@ -182,12 +182,12 @@ bool
cp_beacon_any_countdown_active (cp_t *ctx);
/**
- * Store all beacon parameters necessary for bsu in the next memory storage.
- * \param ctx the control plane context.
- * \return the pointer to the memory storage where are the new data.
+ * Fill a beacon structure to provide it to the BSU.
+ * \param ctx the module context.
+ * \param beacon the bsu_beacon_t structure to fill.
*/
-bsu_beacon_t *
-cp_beacon_fill_share_memory (cp_t *ctx);
+void
+cp_beacon_fill (cp_t *ctx, bsu_beacon_t *beacon);
END_DECLS
diff --git a/cesar/cp/beacon/inc/beacon.h b/cesar/cp/beacon/inc/beacon.h
index 54ac3a103e..f52962f5cf 100644
--- a/cesar/cp/beacon/inc/beacon.h
+++ b/cesar/cp/beacon/inc/beacon.h
@@ -155,12 +155,6 @@ struct cp_beacon_t
/** EKS change structure. */
struct cp_beacon_eks_t eks;
- /** Shared memory. */
- bsu_beacon_t shared_mem[CP_SHARED_MEM_SLOT_NB];
-
- /** Shared memory slot id. */
- cp_shared_mem_slot_id_t shared_mem_slot_id;
-
/** Countown limit date, this is the time after which the countown
* counters must be decremented. */
u32 countdown_limit_date;
diff --git a/cesar/cp/beacon/src/beacon.c b/cesar/cp/beacon/src/beacon.c
index d8cca0da67..836c14323b 100644
--- a/cesar/cp/beacon/src/beacon.c
+++ b/cesar/cp/beacon/src/beacon.c
@@ -54,23 +54,6 @@ cp_beacon_timer_expires (cp_t *ctx)
}
/**
- * Get the next beacon shared memory to update.
- * \param ctx the control plane context.
- * \return a pointer on the next slot.
- */
-static bsu_beacon_t *
-cp_get_next_beacon_shared_memory (cp_t *ctx)
-{
- bsu_beacon_t *next_beacon_shared_memory =
- &ctx->beacon.shared_mem[ctx->beacon.shared_mem_slot_id];
-
- ctx->beacon.shared_mem_slot_id++;
- ctx->beacon.shared_mem_slot_id %= CP_SHARED_MEM_SLOT_NB;
-
- return next_beacon_shared_memory;
-}
-
-/**
* Fill the discover info beacon entry.
* \param ctx the module context.
* \param beacon the beacon to fill.
@@ -114,15 +97,12 @@ cp_beacon_clk_sync_call_spoc (cp_t *ctx, u32 fe)
pbproc_spoc_coeff_set (ctx->pbproc, coeff);
}
-bsu_beacon_t *
-cp_beacon_fill_share_memory (cp_t *ctx)
+void
+cp_beacon_fill (cp_t *ctx, bsu_beacon_t *beacon)
{
- bsu_beacon_t *beacon;
cp_sta_own_data_t *sta;
cp_net_t *net = NULL;
uint nb, ns;
-
- beacon = cp_get_next_beacon_shared_memory (ctx);
dbg_assert (beacon);
beacon->beacon_period_start_date =
bsu_aclf_beacon_period_start_date_next (ctx->bsu_aclf);
@@ -271,8 +251,6 @@ cp_beacon_fill_share_memory (cp_t *ctx)
beacon->bmis.aclsc.present = false;
beacon->bmis.cns.present = false;
beacon->bmis.mac_address_present.present = true;
-
- return beacon;
}
/**
@@ -574,8 +552,6 @@ cp_beacon_init (cp_t *ctx)
hal_timer_instance_init (ctx->hal_timer, &ctx->beacon.leon_timer,
ctx,
(hal_timer_instance_cb_t)cp_beacon_timer_expires);
- // Initialise the mem_share_slot_id so that the next slot is 0.
- ctx->beacon.shared_mem_slot_id = CP_SHARED_MEM_SLOT_NB - 1;
/* Setup beacon indicator. */
GPIO_SETUP (LED_BEACON_TX_RX, GPIO_DIRECTION_OUT);
GPIO_SET (LED_BEACON_TX_RX, 0);
@@ -602,16 +578,21 @@ cp_beacon_uninit (cp_t *ctx)
hal_timer_instance_uninit (ctx->hal_timer, &ctx->beacon.leon_timer);
}
-static bsu_beacon_t*
-cp_beacon_update_beacon_data (cp_t *ctx, bool cco)
+/**
+ * Prepare the beacon and reconfigure the timer of the beacon module.
+ * \param ctx the module context.
+ * \param beacon the bsu_beacon_t structure to fill.
+ * \param cco the cco status.
+ */
+static void
+cp_beacon_update_beacon_data (cp_t *ctx, bsu_beacon_t *beacon, bool cco)
{
cp_beacon_countdowns (ctx);
/** Generate the beacon and send. */
- bsu_beacon_t *beacon = cp_beacon_fill_share_memory (ctx);
+ cp_beacon_fill (ctx, beacon);
/** Program the timer to awake and send another central beacon. */
cp_beacon_reconfigure_timer (ctx, cco);
GPIO_TOGGLE (LED_BEACON_TX_RX);
- return beacon;
}
void
@@ -626,21 +607,22 @@ cp_beacon_sta_update_beacon_data (cp_t *ctx)
void
cp_beacon_cco_update_beacon_data (cp_t *ctx)
{
+ bsu_beacon_t beacon;
dbg_assert (ctx);
- bsu_beacon_t *beacon = cp_beacon_update_beacon_data (ctx, true);
- bsu_update (beacon, BSU_UPDATE_STA_TYPE_CCO);
+ cp_beacon_update_beacon_data (ctx, &beacon, true);
+ bsu_update (&beacon, BSU_UPDATE_STA_TYPE_CCO);
}
void
cp_beacon_poweron_init (cp_t *ctx)
{
+ bsu_beacon_t beacon;
dbg_assert (ctx);
ctx->beacon.countdown_limit_date =
ctx->beacon.last_countdown_date = phy_date ();
/* Generate the beacon and send. */
- bsu_beacon_t *beacon = cp_beacon_fill_share_memory (ctx);
- bsu_update (beacon, BSU_UPDATE_STA_TYPE_STA);
-
+ cp_beacon_fill (ctx, &beacon);
+ bsu_update (&beacon, BSU_UPDATE_STA_TYPE_STA);
GPIO_TOGGLE (LED_BEACON_TX_RX);
}
diff --git a/cesar/cp/beacon/stub/src/beacon.c b/cesar/cp/beacon/stub/src/beacon.c
index fc587f688b..2efb3fce84 100644
--- a/cesar/cp/beacon/stub/src/beacon.c
+++ b/cesar/cp/beacon/stub/src/beacon.c
@@ -29,12 +29,6 @@ void
cp_beacon_uninit (cp_t *ctx){}
void
-cp_beacon_update_beacon_data (cp_t *ctx) __attribute__((weak));
-
-void
-cp_beacon_update_beacon_data (cp_t *ctx){}
-
-void
cp_beacon_create_default_schedules (cp_t *ctx) __attribute__((weak));
void
@@ -136,11 +130,8 @@ cp_beacon_discover_uninit (cp_t *ctx) __attribute__ ((weak));
void
cp_beacon_discover_uninit (cp_t *ctx) {};
-bsu_beacon_t *
-cp_beacon_fill_share_memory (cp_t *ctx) __attribute__ ((weak));
+void
+cp_beacon_fill (cp_t *ctx, bsu_beacon_t *beacon) __attribute__ ((weak));
-bsu_beacon_t *
-cp_beacon_fill_share_memory (cp_t *ctx)
-{
- return INVALID_PTR;
-};
+void
+cp_beacon_fill (cp_t *ctx, bsu_beacon_t *beacon) { };
diff --git a/cesar/cp/beacon/test/src/beacon.c b/cesar/cp/beacon/test/src/beacon.c
index a0475d1562..e9f91e74c4 100644
--- a/cesar/cp/beacon/test/src/beacon.c
+++ b/cesar/cp/beacon/test/src/beacon.c
@@ -243,7 +243,7 @@ test_beacon_bentries (test_t test, bsu_beacon_t *beacon,
void
test_suite_beacon__beacon_generation (test_t test)
{
- bsu_beacon_t *beacon;
+ bsu_beacon_t beacon;
mac_config_t mac_config;
cl_t cl;
@@ -319,19 +319,19 @@ test_suite_beacon__beacon_generation (test_t test)
slab_release (region);
/* Fill the beacon data share memory */
- beacon = cp_beacon_fill_share_memory (&cp);
+ cp_beacon_fill (&cp, &beacon);
test_suite_begin (test, "Beacon generation");
test_case_begin (test, "fill share memory");
/* Check the variant fields */
- test_beacon_variant_field (test, beacon, nid_1, hm_1, (1 << slot_id_1),
+ test_beacon_variant_field (test, &beacon, nid_1, hm_1, (1 << slot_id_1),
slot_id_1, hoip_flag_1);
/* Check the discover info field */
- test_beacon_discover_info (test, beacon, true, cco_flag_1, pco_flag_1,
+ test_beacon_discover_info (test, &beacon, true, cco_flag_1, pco_flag_1,
0, 0, authen_1);
/* Check most bentry fields */
- test_beacon_bentries (test, beacon,
+ test_beacon_bentries (test, &beacon,
true, tei_1,
hoip_cd, hoip_tei,
kc_cd, kbc, eks,
@@ -340,18 +340,18 @@ test_suite_beacon__beacon_generation (test_t test)
/* Check regions bentries */
test_begin (test, "Region")
{
- test_fail_unless (beacon->bmis.region.nb == 1);
- test_fail_unless (beacon->bmis.region.region[0].rt ==
+ test_fail_unless (beacon.bmis.region.nb == 1);
+ test_fail_unless (beacon.bmis.region.region[0].rt ==
CP_BEACON_REGION_TYPE_SHARED_CSMA);
- test_fail_unless (beacon->bmis.region.region[0].end_time_atu ==
+ test_fail_unless (beacon.bmis.region.region[0].end_time_atu ==
end_time_atu);
}
test_end;
/* Check schedule bentries */
test_begin (test, "schedule")
{
- test_fail_unless (beacon->bmis.ps.nb == 0);
- test_fail_unless (beacon->bmis.nps.ns == 0);
+ test_fail_unless (beacon.bmis.ps.nb == 0);
+ test_fail_unless (beacon.bmis.nps.ns == 0);
}
test_end;
@@ -433,37 +433,37 @@ test_suite_beacon__beacon_generation (test_t test)
}
/* Fill the beacon data share memory */
- beacon = cp_beacon_fill_share_memory (&cp);
+ cp_beacon_fill (&cp, &beacon);
test_suite_begin (test, "Beacon generation 2");
test_case_begin (test, "fill share memory 2");
/* Check the variant fields */
- test_beacon_variant_field (test, beacon, nid_2, hm_2,
+ test_beacon_variant_field (test, &beacon, nid_2, hm_2,
(1 << slot_id_2) + (1 << slot_id_1),
slot_id_2, hoip_flag_2);
/* Check the discover info field */
- test_beacon_discover_info (test, beacon, true, cco_flag_2, pco_flag_2,
+ test_beacon_discover_info (test, &beacon, true, cco_flag_2, pco_flag_2,
0, 1, authen_2);
/* Check most bentry fields */
- test_beacon_bentries (test, beacon,
+ test_beacon_bentries (test, &beacon,
false, tei_2, 0, 0, 0, 0, 0, 0, 0, 0);
/* Check regions bentries */
test_begin (test, "Region 2")
{
- test_fail_unless (beacon->bmis.region.nb == 3);
- test_fail_unless (beacon->bmis.region.region[0].rt ==
+ test_fail_unless (beacon.bmis.region.nb == 3);
+ test_fail_unless (beacon.bmis.region.region[0].rt ==
CP_BEACON_REGION_TYPE_BEACON);
- test_fail_unless (beacon->bmis.region.region[0].end_time_atu ==
+ test_fail_unless (beacon.bmis.region.region[0].end_time_atu ==
end_time_atu - 10);
- test_fail_unless (beacon->bmis.region.region[1].rt ==
+ test_fail_unless (beacon.bmis.region.region[1].rt ==
CP_BEACON_REGION_TYPE_SHARED_CSMA);
- test_fail_unless (beacon->bmis.region.region[1].end_time_atu ==
+ test_fail_unless (beacon.bmis.region.region[1].end_time_atu ==
end_time_atu);
- test_fail_unless (beacon->bmis.region.region[2].rt ==
+ test_fail_unless (beacon.bmis.region.region[2].rt ==
CP_BEACON_REGION_TYPE_STAYOUT);
- test_fail_unless (beacon->bmis.region.region[2].end_time_atu ==
+ test_fail_unless (beacon.bmis.region.region[2].end_time_atu ==
end_time_atu + 10);
}
test_end;
@@ -473,41 +473,41 @@ test_suite_beacon__beacon_generation (test_t test)
{
for (i = 1, nb = 0; i < 8; i += 6, nb++)
{
- test_fail_unless (beacon->bmis.ps.ps[nb].pscd == i);
- test_fail_unless (beacon->bmis.ps.ps[nb].cscd == i);
- test_fail_unless (beacon->bmis.ps.ps[nb].ns == 2);
+ test_fail_unless (beacon.bmis.ps.ps[nb].pscd == i);
+ test_fail_unless (beacon.bmis.ps.ps[nb].cscd == i);
+ test_fail_unless (beacon.bmis.ps.ps[nb].ns == 2);
for (ns = 0; ns < 2; ns++)
{
- test_fail_unless (beacon->bmis.ps.ps[nb].sais[ns].stpf ==
+ test_fail_unless (beacon.bmis.ps.ps[nb].sais[ns].stpf ==
false);
- test_fail_unless (beacon->bmis.ps.ps[nb].sais[ns].glid ==
+ test_fail_unless (beacon.bmis.ps.ps[nb].sais[ns].glid ==
0x55 + nb);
test_fail_unless (
- beacon->bmis.ps.ps[nb].sais[ns].start_time_atu ==
+ beacon.bmis.ps.ps[nb].sais[ns].start_time_atu ==
end_time_atu + nb * 10 + ns * 5 - 4);
test_fail_unless (
- beacon->bmis.ps.ps[nb].sais[ns].end_time_atu ==
+ beacon.bmis.ps.ps[nb].sais[ns].end_time_atu ==
end_time_atu + nb * 10 + ns * 5);
}
}
- test_fail_unless (beacon->bmis.ps.nb == nb);
+ test_fail_unless (beacon.bmis.ps.nb == nb);
for (i = BSU_BEACON_BMIS_SCHEDULES_SAI_MAX - 1, ns = 0; i >= 0;
i--, ns++)
{
- test_fail_unless (beacon->bmis.nps.sais[ns].stpf ==
+ test_fail_unless (beacon.bmis.nps.sais[ns].stpf ==
false);
- test_fail_unless (beacon->bmis.nps.sais[ns].glid ==
+ test_fail_unless (beacon.bmis.nps.sais[ns].glid ==
0x45 + i);
test_fail_unless (
- beacon->bmis.nps.sais[ns].start_time_atu ==
+ beacon.bmis.nps.sais[ns].start_time_atu ==
end_time_atu - (i + 1) * 10 - 9);
test_fail_unless (
- beacon->bmis.nps.sais[ns].end_time_atu ==
+ beacon.bmis.nps.sais[ns].end_time_atu ==
end_time_atu - (i + 1) * 10);
}
- test_fail_unless (beacon->bmis.nps.ns == ns);
+ test_fail_unless (beacon.bmis.nps.ns == ns);
}
test_end;
@@ -577,7 +577,7 @@ test_case_beacon_snid_change_cco (test_t test)
cp_cco_bw_alloc_t *alloc;
set_t set_schedules;
set_t set_regions;
- bsu_beacon_t *beacon;
+ bsu_beacon_t beacon;
set_init (&set_schedules, cp_cco_bw_alloc_less);
set_init (&set_regions, cp_cco_region_alloc_less);
@@ -602,16 +602,16 @@ test_case_beacon_snid_change_cco (test_t test)
cp_cco_bw_alloc_add (&cp, &cp.bw.alloc_list, alloc);
slab_release (alloc);
- beacon = cp_beacon_fill_share_memory (&cp);
+ cp_beacon_fill (&cp, &beacon);
- test_fail_unless (beacon->bmis.change_snid.present == true);
- test_fail_unless (beacon->bmis.change_snid.snidccd == cp.beacon.snids.snidcd);
- test_fail_unless (beacon->bmis.change_snid.new_snid == cp.beacon.snids.snid);
+ test_fail_unless (beacon.bmis.change_snid.present == true);
+ test_fail_unless (beacon.bmis.change_snid.snidccd == cp.beacon.snids.snidcd);
+ test_fail_unless (beacon.bmis.change_snid.new_snid == cp.beacon.snids.snid);
cp_cco_bw_alloc_clean (&cp, &set_schedules);
cp_cco_region_alloc_clean (&cp, &set_regions);
- cp_beacon_sta_compute_schedules (&cp, beacon);
+ cp_beacon_sta_compute_schedules (&cp, &beacon);
alloc = cp_cco_bw_alloc_get_first (&cp, &cp.bw.alloc_list);
test_fail_unless (alloc->persistence ==
CP_CCO_BW_ALLOC_PERSISTENCE_PERSISTENT);