summaryrefslogtreecommitdiff
path: root/mac/ca/src/ca.c
diff options
context:
space:
mode:
Diffstat (limited to 'mac/ca/src/ca.c')
-rw-r--r--mac/ca/src/ca.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/mac/ca/src/ca.c b/mac/ca/src/ca.c
new file mode 100644
index 0000000000..a5785ff882
--- /dev/null
+++ b/mac/ca/src/ca.c
@@ -0,0 +1,97 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file mac/ca/src/ca.c
+ * \brief Channel Access main implementation file.
+ * \ingroup mac_ca
+ */
+#include "common/std.h"
+
+#include "mac/ca/inc/context.h"
+#include "mac/common/timings.h"
+
+ca_t 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)
+{
+ dbg_assert (phy);
+ dbg_assert (config);
+ dbg_assert (store);
+ ca_t *ctx = &ca_global;
+ ctx->phy = phy;
+ ctx->config = config;
+ ctx->store = store;
+ ctx->access_param.mfs = NULL;
+ ctx->access_param.access_date = 0;
+ ctx->access_param.duration_tck = 0;
+ ctx->access_param.cfp = false;
+ ctx->access_param.content = false;
+ ctx->vcs_start_date = 0;
+ ctx->vcs_length_tck = 0;
+ ctx->vcs_eifs = false;
+ ctx->anticipation_tck = 0;
+ ca_backoff_init (ctx);
+ ctx->beacon_periods_head = ctx->beacon_periods_tail = 0;
+ heap_init (&ctx->mfs_heap, ca_mfs_less);
+ return ctx;
+}
+
+void
+ca_uninit (ca_t *ctx)
+{
+ dbg_assert (ctx);
+}
+
+void
+ca_mfs_init (ca_t *ctx, mfs_tx_t *mfs)
+{
+ dbg_assert (ctx);
+ dbg_assert (mfs);
+ heap_node_init (&mfs->link);
+ mfs->ca_state = CA_MFS_STATE_UNKNOWN;
+}
+
+void
+ca_mfs_uninit (ca_t *ctx, mfs_tx_t *mfs)
+{
+ dbg_assert (ctx);
+ dbg_assert (mfs);
+ if (mfs->ca_state == CA_MFS_STATE_PRIO_QUEUED)
+ {
+ heap_remove (&ctx->mfs_heap, &mfs->link);
+ }
+ mfs->ca_state = CA_MFS_STATE_UNKNOWN;
+}
+
+void
+ca_mfs_update (ca_t *ctx, mfs_tx_t *mfs)
+{
+ dbg_assert (ctx);
+ dbg_assert (mfs);
+ //heap_adjust (&ctx->mfs_heap, &mfs->link);
+}
+
+static bool
+ca_mfs_less (heap_node_t *left, heap_node_t *right)
+{
+ mfs_tx_t *lmfs = PARENT_OF (mfs_tx_t, link, left);
+ mfs_tx_t *rmfs = PARENT_OF (mfs_tx_t, link, right);
+ /* TODO: write a real comparison function. */
+ return lmfs->cap < rmfs->cap;
+}
+