summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cesar/cp/beacon/inc/beacon.h6
-rw-r--r--cesar/cp/beacon/src/beacon.c30
-rw-r--r--cesar/cp/beacon/test/src/beacon.c16
3 files changed, 18 insertions, 34 deletions
diff --git a/cesar/cp/beacon/inc/beacon.h b/cesar/cp/beacon/inc/beacon.h
index 2338ddfacd..99d697bb8b 100644
--- a/cesar/cp/beacon/inc/beacon.h
+++ b/cesar/cp/beacon/inc/beacon.h
@@ -130,10 +130,8 @@ typedef struct cp_beacon_list_t cp_beacon_list_t;
*/
struct cp_beacon_t
{
- /** circular list manager for the beacon reception. */
- pb_beacon_t *list;
- pb_beacon_t *list_tail;
-
+ /** Received beacon list. */
+ cp_beacon_list_t list;
/**
* The leon timer to be programmed and awake each beacon period.
* Each time the timer expires, the function register by the beacon
diff --git a/cesar/cp/beacon/src/beacon.c b/cesar/cp/beacon/src/beacon.c
index d5e039198f..587f6e2c15 100644
--- a/cesar/cp/beacon/src/beacon.c
+++ b/cesar/cp/beacon/src/beacon.c
@@ -17,6 +17,7 @@
*/
#include "common/std.h"
#include "lib/fixed.h"
+#include "lib/slist.h"
#include "string.h"
#include "hal/arch/arch.h"
#include "cp/defs.h"
@@ -278,17 +279,7 @@ cp_beacon_receive (void *ul, pb_beacon_t * beacon, bsu_params_t *params)
if (params->direction == BSU_BEACON_DIRECTION_FROM_PLC)
{
beacon->next = NULL;
- if (ctx->beacon.list)
- {
- ctx->beacon.list_tail->next = beacon;
- ctx->beacon.list_tail = beacon;
- }
- else
- {
- ctx->beacon.list = beacon;
- ctx->beacon.list_tail = beacon;
- }
- // Raise the flag.
+ slist_push_back (ctx->beacon.list., beacon, bare);
cp_sta_core_signal_recv_beacon_event (ctx);
}
else
@@ -574,6 +565,7 @@ cp_beacon_init (cp_t *ctx)
dbg_assert (ctx);
// Initialise the beacon module.
memset (&ctx->beacon, 0, sizeof (cp_beacon_t));
+ slist_init (ctx->beacon.list., bare);
// Initialise the instance of the leon timer.
hal_timer_instance_init (ctx->hal_timer, &ctx->beacon.leon_timer,
ctx,
@@ -672,11 +664,8 @@ cp_beacon_get_and_process_beacon (cp_t *ctx)
/** check the countdowns. */
cp_beacon_countdowns (ctx);
-
- dbg_assert (ctx->beacon.list);
arch_dsr_lock ();
- pb_beacon = ctx->beacon.list;
- ctx->beacon.list = ctx->beacon.list->next;
+ pb_beacon = slist_pop_front (ctx->beacon.list., bare);
arch_dsr_unlock ();
bsu_params_t *bsu_params =
@@ -869,18 +858,15 @@ cp_beacon_change_nek (cp_t *ctx, uint eks, cp_key_t nek, bool now)
void
cp_beacon_deactivate (cp_t *ctx)
{
+ pb_beacon_t *beacon;
dbg_assert (ctx);
-
/* Stop the hal timer. */
hal_timer_instance_cancel (ctx->hal_timer, &ctx->beacon.leon_timer);
-
/* Release pending beacons. */
- if (ctx->beacon.list)
+ while (!slist_empty (ctx->beacon.list., bare))
{
- blk_release_desc_range ((blk_t *) ctx->beacon.list,
- (blk_t *) ctx->beacon.list_tail);
- ctx->beacon.list = NULL;
- ctx->beacon.list_tail = NULL;
+ beacon = slist_pop_front (ctx->beacon.list., bare);
+ blk_release_desc ((blk_t *) beacon);
}
cp_beacon_discover_uninit (ctx);
}
diff --git a/cesar/cp/beacon/test/src/beacon.c b/cesar/cp/beacon/test/src/beacon.c
index 8d8bd930e7..6d42fbcc13 100644
--- a/cesar/cp/beacon/test/src/beacon.c
+++ b/cesar/cp/beacon/test/src/beacon.c
@@ -13,7 +13,7 @@
* « long description »
*/
#include "common/std.h"
-
+#include "lib/slist.h"
#include "lib/test.h"
#include "lib/circular_buffer.h"
@@ -111,15 +111,15 @@ test_case_beacon__deactivate (test_t test)
cp.beacon.leon_timer.status = true;
/* Allocate some beacons. */
- cp.beacon.list = (pb_beacon_t*)blk_alloc_desc_range (
- nb_beacons, (blk_t**)&cp.beacon.list_tail);
-
+ uint i;
+ for (i = 0; i < nb_beacons; i++)
+ {
+ pb_beacon_t *beacon = (pb_beacon_t *) blk_alloc_desc ();
+ slist_push_back (cp.beacon.list., beacon, bare);
+ }
/* test. */
cp_beacon_deactivate (&cp);
-
- test_fail_if (cp.beacon.list != NULL);
- test_fail_if (cp.beacon.list_tail != NULL);
-
+ test_fail_unless (slist_empty (cp.beacon.list., bare));
mac_store_uninit (mac_store);
test_fail_if (blk_check_memory () != true, "Memory leaks");
}