summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cesar/mac/ca/inc/context.h4
-rw-r--r--cesar/mac/ca/mfs.h2
-rw-r--r--cesar/mac/ca/src/access.c27
-rw-r--r--cesar/mac/ca/src/ca.c53
-rw-r--r--cesar/mac/common/defs.h3
-rw-r--r--cesar/mac/common/mfs.h7
-rw-r--r--cesar/mac/common/src/mfs.c3
7 files changed, 37 insertions, 62 deletions
diff --git a/cesar/mac/ca/inc/context.h b/cesar/mac/ca/inc/context.h
index 3f283415b8..614fc64cbc 100644
--- a/cesar/mac/ca/inc/context.h
+++ b/cesar/mac/ca/inc/context.h
@@ -74,8 +74,8 @@ struct ca_t
uint current_allocation_index;
/** Current allocation parameters. */
ca_alloc_param_t current_allocation_param;
- /** Priority sorted MFS heap. */
- heap_t mfs_heap;
+ /** Priority sorted MFS lists. */
+ list_t prio[MAC_CAP_NB];
/** List of MFS held until the next beacon period. */
list_t held;
};
diff --git a/cesar/mac/ca/mfs.h b/cesar/mac/ca/mfs.h
index ee657ec99e..47ca594d50 100644
--- a/cesar/mac/ca/mfs.h
+++ b/cesar/mac/ca/mfs.h
@@ -17,7 +17,7 @@
enum ca_mfs_state_t
{
CA_MFS_STATE_UNKNOWN, /*< MFS unknown to CA or containing no PB. */
- CA_MFS_STATE_PRIO_QUEUED, /*< MFS queued to CSMA CA MFS heap. */
+ CA_MFS_STATE_PRIO_QUEUED, /*< MFS queued to CSMA CA MFS lists. */
CA_MFS_STATE_CFP_QUEUED, /*< MFS available for TDMA. */
CA_MFS_STATE_HELD, /*< MFS held until next beacon period. */
CA_MFS_STATE_REMOVED, /*< MFS was removed and should not be used
diff --git a/cesar/mac/ca/src/access.c b/cesar/mac/ca/src/access.c
index 3b74baceb1..588e7efcd1 100644
--- a/cesar/mac/ca/src/access.c
+++ b/cesar/mac/ca/src/access.c
@@ -83,7 +83,7 @@ ca_access_hold (ca_t *ctx)
* \param glid global link identifier
* \return MFS or NULL if none match
*/
-static mfs_tx_t *
+static inline mfs_tx_t *
ca_access_choose_mfs_tx (ca_t *ctx, uint glid);
/**
@@ -333,11 +333,9 @@ ca_access_grant (ca_t *ctx, mfs_tx_t *mfs, u32 date, uint duration_tck)
/* Select an MFS. */
if (!mfs)
{
- dbg_assert (!heap_empty (&ctx->mfs_heap)); /* TODO */
/* Choose an MFS. */
- mfs = PARENT_OF (mfs_tx_t, ca_prio_link, heap_get_root
- (&ctx->mfs_heap));
- dbg_assert (mfs->ca_state == CA_MFS_STATE_PRIO_QUEUED);
+ mfs = ca_access_choose_mfs_tx (ctx, MAC_LID_SHARED_CSMA);
+ dbg_assert (mfs); /* TODO */
}
else
{
@@ -436,7 +434,7 @@ ca_access_update (ca_t *ctx)
}
}
-static mfs_tx_t * ARCH_ILRAM
+static inline mfs_tx_t *
ca_access_choose_mfs_tx (ca_t *ctx, uint glid)
{
mfs_tx_t *mfs;
@@ -463,15 +461,18 @@ ca_access_choose_mfs_tx (ca_t *ctx, uint glid)
}
else
{
- if (!heap_empty (&ctx->mfs_heap))
+ int cap;
+ for (cap = MAC_CAP_NB - 1; cap >= 0; cap--)
{
- mfs = PARENT_OF (mfs_tx_t, ca_prio_link,
- heap_get_root (&ctx->mfs_heap));
- dbg_assert (mfs->ca_state == CA_MFS_STATE_PRIO_QUEUED);
- return mfs;
+ if (!list_empty (&ctx->prio[cap]))
+ {
+ mfs = PARENT_OF (mfs_tx_t, ca_link,
+ list_begin (&ctx->prio[cap]));
+ dbg_assert (mfs->ca_state == CA_MFS_STATE_PRIO_QUEUED);
+ return mfs;
+ }
}
- else
- return NULL;
+ return NULL;
}
}
diff --git a/cesar/mac/ca/src/ca.c b/cesar/mac/ca/src/ca.c
index a7affa8ad1..21fe3cd7ba 100644
--- a/cesar/mac/ca/src/ca.c
+++ b/cesar/mac/ca/src/ca.c
@@ -20,19 +20,11 @@
ca_t ARCH_DLRAM_BSS ca_global;
-/**
- * MFS priority comparaison function.
- * \param left left hand MFS
- * \param right right hand MFS
- * \return true iff left has a greater priority than right
- */
-static bool
-ca_mfs_less (heap_node_t *left, heap_node_t *right);
-
ca_t *
ca_init (phy_t *phy, mac_config_t *config, mac_store_t *store,
uint anticipation_tck)
{
+ int cap;
dbg_assert (phy);
dbg_assert (config);
dbg_assert (store);
@@ -55,7 +47,8 @@ ca_init (phy_t *phy, mac_config_t *config, mac_store_t *store,
ctx->beacon_periods_nb = 0;
ctx->current_beacon_period = NULL;
ctx->current_allocation_index = 0;
- heap_init (&ctx->mfs_heap, ca_mfs_less);
+ for (cap = 0; cap < MAC_CAP_NB; cap++)
+ list_init (&ctx->prio[cap]);
list_init (&ctx->held);
CA_TRACE (INIT);
return ctx;
@@ -64,8 +57,10 @@ ca_init (phy_t *phy, mac_config_t *config, mac_store_t *store,
void
ca_uninit (ca_t *ctx)
{
+ int cap;
dbg_assert (ctx && ctx->state == CA_STATE_IDLE);
- dbg_assert (heap_empty (&ctx->mfs_heap));
+ for (cap = 0; cap < MAC_CAP_NB; cap++)
+ dbg_assert (list_empty (&ctx->prio[cap]));
CA_TRACE (UNINIT);
ca_trace_uninit (ctx);
}
@@ -91,10 +86,10 @@ ca_mfs_remove (ca_t *ctx, mfs_tx_t *mfs)
switch (mfs->ca_state)
{
case CA_MFS_STATE_PRIO_QUEUED:
- heap_remove (&ctx->mfs_heap, &mfs->ca_prio_link);
+ list_remove (&ctx->prio[mfs->cap], &mfs->ca_link);
break;
case CA_MFS_STATE_HELD:
- list_remove (&ctx->held, &mfs->ca_held_link);
+ list_remove (&ctx->held, &mfs->ca_link);
break;
default:
;
@@ -133,14 +128,12 @@ ca_mfs_update_common (ca_t *ctx, mfs_tx_t *mfs, bool locked)
/* ...and execute the corresponding transition. */
if (mfs->ca_state == CA_MFS_STATE_PRIO_QUEUED)
{
- if (new_state == CA_MFS_STATE_PRIO_QUEUED)
- heap_adjust (&ctx->mfs_heap, &mfs->ca_prio_link);
- else
- heap_remove (&ctx->mfs_heap, &mfs->ca_prio_link);
+ if (new_state != CA_MFS_STATE_PRIO_QUEUED)
+ list_remove (&ctx->prio[mfs->cap], &mfs->ca_link);
}
else if (new_state == CA_MFS_STATE_PRIO_QUEUED)
{
- heap_insert (&ctx->mfs_heap, &mfs->ca_prio_link);
+ list_push (&ctx->prio[mfs->cap], &mfs->ca_link);
}
/* Done. */
mfs->ca_state = new_state;
@@ -184,10 +177,10 @@ ca_mfs_hold_common (ca_t *ctx, mfs_tx_t *mfs, bool locked)
{
/* Remove from priority queue. */
if (mfs->ca_state == CA_MFS_STATE_PRIO_QUEUED)
- heap_remove (&ctx->mfs_heap, &mfs->ca_prio_link);
+ list_remove (&ctx->prio[mfs->cap], &mfs->ca_link);
/* Add to hold list. */
mfs->ca_state = CA_MFS_STATE_HELD;
- list_push (&ctx->held, &mfs->ca_held_link);
+ list_push (&ctx->held, &mfs->ca_link);
/* Unlock. */
if (!locked) arch_isr_unlock (flags);
/* The current ACCESS may have changed. */
@@ -220,27 +213,9 @@ ca_mfs_next_beacon_period (ca_t *ctx)
/* Unhold MFS. */
while (!list_empty (&ctx->held))
{
- mfs_tx_t *mfs = PARENT_OF (mfs_tx_t, ca_held_link,
- list_pop (&ctx->held));
+ mfs_tx_t *mfs = PARENT_OF (mfs_tx_t, ca_link, list_pop (&ctx->held));
mfs->ca_state = CA_MFS_STATE_UNKNOWN;
ca_mfs_update_locked (ctx, mfs);
}
}
-static bool
-ca_mfs_less (heap_node_t *left, heap_node_t *right)
-{
- mfs_tx_t *l = PARENT_OF (mfs_tx_t, ca_prio_link, left);
- mfs_tx_t *r = PARENT_OF (mfs_tx_t, ca_prio_link, right);
- /* Prefer MFS with something to send. */
- if (l->seg_nb != 0 && r->seg_nb == 0)
- return true;
- if (l->seg_nb == 0 && r->seg_nb != 0)
- return false;
- /* Prefer better cap. */
- if (l->cap != r->cap)
- return l->cap > r->cap;
- /* Prefer MME. */
- return l->common.mme > r->common.mme;
-}
-
diff --git a/cesar/mac/common/defs.h b/cesar/mac/common/defs.h
index 29f1804a06..d797f5d1bf 100644
--- a/cesar/mac/common/defs.h
+++ b/cesar/mac/common/defs.h
@@ -25,6 +25,9 @@
/** Maximum number of physical PHY blocks per MPDU. */
#define MAC_MAX_PB_PER_MPDU 236
+/** Number of channel access priority. */
+#define MAC_CAP_NB 4
+
/** Link identifiers. */
enum mac_lid_t
{
diff --git a/cesar/mac/common/mfs.h b/cesar/mac/common/mfs.h
index 2c05ae6576..316a1a659b 100644
--- a/cesar/mac/common/mfs.h
+++ b/cesar/mac/common/mfs.h
@@ -15,7 +15,6 @@
#include "mac/common/pb.h"
#include "mac/ca/mfs.h"
-#include "lib/heap.h"
#include "lib/list.h"
#include "mac/common/link_stats.h"
@@ -125,11 +124,9 @@ struct mfs_tx_t
/** Burst count for global links. */
u8 burst_count;
- /** Heap link used by Channel Access. */
- heap_node_t ca_prio_link;
/** List link used by Channel Access for MFS to be held until next beacon
- * period. */
- list_node_t ca_held_link;
+ * period or priority sorted MFS. */
+ list_node_t ca_link;
/** Channel Access MFS state. */
ca_mfs_state_t ca_state;
diff --git a/cesar/mac/common/src/mfs.c b/cesar/mac/common/src/mfs.c
index a684e8949e..2a4fbfe4bd 100644
--- a/cesar/mac/common/src/mfs.c
+++ b/cesar/mac/common/src/mfs.c
@@ -81,8 +81,7 @@ mfs_tx_init (mfs_tx_t *mfs, bool bcast, bool mme, uint lid, uint tei)
mfs_common_init (&mfs->common, true, bcast, mme, lid, tei);
mfs->cfp = false;
mfs->burst_count = 0;
- heap_node_init (&mfs->ca_prio_link);
- list_init_node (&mfs->ca_held_link);
+ list_init_node (&mfs->ca_link);
mfs->ca_state = CA_MFS_STATE_UNKNOWN;
mfs->seg_nb = 0;
mfs->pending_seg_nb = 0;