summaryrefslogtreecommitdiff
path: root/cesar/mac/pbproc/test/maximus/src/test_pbproc.c
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/mac/pbproc/test/maximus/src/test_pbproc.c')
-rw-r--r--cesar/mac/pbproc/test/maximus/src/test_pbproc.c303
1 files changed, 303 insertions, 0 deletions
diff --git a/cesar/mac/pbproc/test/maximus/src/test_pbproc.c b/cesar/mac/pbproc/test/maximus/src/test_pbproc.c
new file mode 100644
index 0000000000..65c9198610
--- /dev/null
+++ b/cesar/mac/pbproc/test/maximus/src/test_pbproc.c
@@ -0,0 +1,303 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/test_pbproc.c
+ * \brief PBProc test on Maximus.
+ * \ingroup test
+ */
+#include "common/std.h"
+
+#include "lib/trace.h"
+
+#include "mac/common/mfs.h"
+
+#include "inc/test_pbproc.h"
+#include "inc/context.h"
+
+#include "hal/phy/maximus/inc/maximus_phy_ctx.h"
+#include "mac/ca/inc/context.h"
+#include "mac/pbproc/inc/context.h"
+
+#define TEST_PBPROC_PRIORITY 16
+
+/** Global test PBProc context. */
+static test_pbproc_t test_pbproc_global;
+
+static void
+test_pbproc_init (test_pbproc_t *ctx);
+
+static void
+test_pbproc_init_pbproc (test_pbproc_t *ctx);
+
+void
+test_pbproc_uninit_pbproc (test_pbproc_t *ctx);
+
+static void
+test_pbproc_thread (cyg_addrword_t data);
+
+void
+test_pbproc_rx_cb (void *user, mfs_t *mfs, mfs_t *mfs_mme,
+ const pbproc_rx_params_t *rx_params,
+ pb_t *pb_first, pb_t *pb_last,
+ uint pb_nb, pb_t *chandata_first, uint chandata_nb)
+{
+ dbg_assert_ptr (user);
+ test_pbproc_t *ctx = user;
+ dbg_assert_ptr (rx_params);
+ if (pb_nb)
+ {
+ dbg_assert_ptr (pb_first);
+ dbg_assert_ptr (pb_last);
+ }
+ else
+ dbg_assert (pb_first == NULL && pb_last == NULL);
+ uint pb_null = 0, pb_valid = 0;
+ pb_t *pb, *pbl;
+ for (pb = pb_first, pbl = NULL;
+ pbl != pb_last;
+ pbl = pb, pb = pb->next)
+ {
+ if (pb->header.vpbf)
+ pb_valid++;
+ else
+ pb_null++;
+ }
+ dbg_assert (pb_valid + pb_null == pb_nb);
+ ctx->rx_pb_nb += pb_valid;
+ if (ctx->rx_cb)
+ ctx->rx_cb (user, mfs, mfs_mme, rx_params, pb_first, pb_last, pb_nb,
+ chandata_first, chandata_nb);
+ else
+ dbg_assert (0);
+}
+
+void
+test_pbproc_default_rx_cb (void *user, mfs_t *mfs, mfs_t *mfs_mme,
+ const pbproc_rx_params_t *rx_params,
+ pb_t *pb_first, pb_t *pb_last, uint pb_nb,
+ pb_t *chandata_first, uint chandata_nb)
+{
+ dbg_assert_ptr (user);
+ dbg_assert_print (chandata_nb == 0, "Not handled yet");
+ test_pbproc_t *ctx = user;
+ pbproc_rx_segment_refill (ctx->pbproc, pb_first, pb_last, pb_nb);
+ /* This is forbidden if running under ISR. */
+ cyg_semaphore_post (&ctx->event_sem);
+}
+
+void
+test_pbproc_rx_beacon_cb (void *user, pb_beacon_t *pb,
+ pbproc_rx_beacon_params_t *params)
+{
+ dbg_assert_ptr (user);
+ dbg_assert_ptr (pb);
+ dbg_assert (params == (void *) (pb->data + MAC_PB136_BYTES));
+ blk_release_desc (&pb->blk);
+}
+
+static int
+test_pbproc_activate_fcall (fcall_ctx_t *fcall, fcall_param_t **param,
+ sci_msg_t **msg, void *data)
+{
+ dbg_assert (fcall);
+ dbg_assert (param && *param);
+ dbg_assert (msg && *msg);
+ test_pbproc_t *ctx = (void *) data;
+ dbg_assert (ctx);
+ /* Read message. */
+ bool activate;
+ if (!test_pbproc_fcall_bind ("activate", activate))
+ activate = true;
+ /* Activate. */
+ pbproc_activate (ctx->pbproc, activate);
+ /* Return. */
+ fcall_param_reset (*param);
+ return 0;
+}
+
+static int
+test_pbproc_set_config_fcall (fcall_ctx_t *fcall, fcall_param_t **param,
+ sci_msg_t **msg, void *data)
+{
+ dbg_assert (fcall);
+ dbg_assert (param && *param);
+ dbg_assert (msg && *msg);
+ test_pbproc_t *ctx = (void *) data;
+ dbg_assert (ctx);
+ /* Read message. */
+ uint tei, snid;
+ if (test_pbproc_fcall_bind_long ("tei", tei))
+ ctx->config.tei = tei;
+ if (test_pbproc_fcall_bind_long ("snid", snid))
+ ctx->config.snid = snid;
+ /* Initialise PBProc. */
+ if (!ctx->pbproc)
+ {
+ ctx->config.seed = ctx->config.snid << 8 | ctx->config.tei;
+ test_pbproc_init_pbproc (ctx);
+ }
+ /* Return. */
+ fcall_param_reset (*param);
+ return 0;
+}
+
+static int
+test_pbproc_rx_seg_refill_fcall (fcall_ctx_t *fcall, fcall_param_t **param,
+ sci_msg_t **msg, void *data)
+{
+ dbg_assert (fcall);
+ dbg_assert (param && *param);
+ dbg_assert (msg && *msg);
+ test_pbproc_t *ctx = (void *) data;
+ dbg_assert (ctx);
+ /* Read message. */
+ uint seg_nb;
+ if (!test_pbproc_fcall_bind_long ("seg_nb", seg_nb))
+ return -1;
+ /* Refill. */
+ blk_t *first, *last;
+ first = blk_alloc_desc_range (seg_nb, &last);
+ pbproc_rx_segment_refill (ctx->pbproc, PB_FROM_BLK (first),
+ PB_FROM_BLK (last), seg_nb);
+ /* Return. */
+ fcall_param_reset (*param);
+ return 0;
+}
+
+static int
+test_pbproc_trace_dump_fcall (fcall_ctx_t *fcall, fcall_param_t **param,
+ sci_msg_t **msg, void *data)
+{
+ dbg_assert (fcall);
+ dbg_assert (param && *param);
+ dbg_assert (msg && *msg);
+ test_pbproc_t *ctx = (void *) data;
+ dbg_assert (ctx);
+ /* Read message. */
+ bool phy, ca, pbproc;
+ if (!test_pbproc_fcall_bind ("phy", phy))
+ phy = false;
+ if (!test_pbproc_fcall_bind ("ca", ca))
+ ca = false;
+ if (!test_pbproc_fcall_bind ("pbproc", pbproc))
+ pbproc = false;
+ /* Dump traces. */
+ if (!phy && !ca && !pbproc)
+ pbproc = true;
+ if (phy)
+ trace_buffer_dbg_dump (&ctx->pbproc->phy->trace);
+ if (ca)
+ trace_buffer_dbg_dump (&ctx->pbproc->ca->trace);
+ if (pbproc)
+ trace_buffer_dbg_dump (&ctx->pbproc->trace);
+ /* Return. */
+ fcall_param_reset (*param);
+ return 0;
+}
+
+static void
+test_pbproc_init (test_pbproc_t *ctx)
+{
+ dbg_assert (ctx);
+ /* Rnd, config, PBProc (initialised later)... */
+ lib_rnd_init (ctx->rnd, 1234);
+ mac_config_init (&ctx->config);
+ ctx->config.tei = 1;
+ ctx->config.snid = 1;
+ ctx->store = NULL;
+ ctx->pbproc = NULL;
+ ctx->ca = NULL;
+ /* Beacon period. */
+ ctx->beacon_periods_nb = 0;
+ /* Semaphore, mbox... */
+ cyg_semaphore_init (&ctx->event_sem, 0);
+ cyg_mbox_create (&ctx->mbox, &ctx->mbox_storage);
+ ctx->static_msg.id = TEST_PBPROC_MSG_ID_NONE;
+ int i;
+ for (i = 0; i < TEST_PBPROC_MSG_ID_NONE; i++)
+ ctx->msg_handlers[i] = NULL;
+ /* Callbacks... */
+ ctx->rx_cb = NULL;
+ ctx->rx_pb_nb = 0;
+ /* Fcall... */
+ ctx->fcall = NULL;
+ ctx->fcall_msg_id = 0;
+ /* Init modules. */
+ test_pbproc_add_seg_init (ctx);
+ test_pbproc_prepare_beacon_init (ctx);
+ test_pbproc_get_seg_init (ctx);
+ test_pbproc_add_beacon_period_init (ctx);
+ test_pbproc_set_tonemap_init (ctx);
+ fcall_register (my_station.fcall, "activate", test_pbproc_activate_fcall,
+ ctx);
+ fcall_register (my_station.fcall, "set_config",
+ test_pbproc_set_config_fcall, ctx);
+ fcall_register (my_station.fcall, "rx_seg_refill",
+ test_pbproc_rx_seg_refill_fcall, ctx);
+ fcall_register (my_station.fcall, "trace_dump",
+ test_pbproc_trace_dump_fcall, ctx);
+ /* Go. */
+ cyg_thread_create (TEST_PBPROC_PRIORITY, &test_pbproc_thread,
+ (cyg_addrword_t) ctx, "test_pbproc", ctx->thread_stack,
+ COUNT (ctx->thread_stack), &ctx->thread,
+ &ctx->thread_storage);
+ cyg_thread_resume (ctx->thread);
+}
+
+static void
+test_pbproc_init_pbproc (test_pbproc_t *ctx)
+{
+ trace_init ();
+ ctx->store = mac_store_init ();
+ ctx->pbproc = pbproc_init (&ctx->config, ctx->store);
+ pbproc_init_cb (ctx->pbproc, ctx, test_pbproc_rx_cb,
+ test_pbproc_rx_beacon_cb);
+ ctx->ca = pbproc_get_ca (ctx->pbproc);
+}
+
+void
+test_pbproc_uninit_pbproc (test_pbproc_t *ctx)
+{
+ dbg_assert (ctx);
+ dbg_assert_ptr (ctx->ca);
+ ctx->ca = NULL;
+ dbg_assert_ptr (ctx->pbproc);
+ pbproc_uninit (ctx->pbproc);
+ ctx->pbproc = NULL;
+ dbg_assert_ptr (ctx->store);
+ mac_store_uninit (ctx->store);
+ ctx->store = NULL;
+ trace_uninit ();
+}
+
+static void
+test_pbproc_thread (cyg_addrword_t data)
+{
+ test_pbproc_t *ctx = (void *) data;
+ dbg_assert (ctx);
+ /* Handle messages. */
+ test_pbproc_msg_t *msg;
+ while ((msg = cyg_mbox_get (ctx->mbox)))
+ {
+ dbg_assert (msg->id < TEST_PBPROC_MSG_ID_NONE);
+ dbg_assert (ctx->msg_handlers[msg->id]);
+ ctx->msg_handlers[msg->id] (ctx, msg);
+ msg->id = TEST_PBPROC_MSG_ID_NONE;
+ }
+}
+
+/** Entry point. */
+void
+cyg_user_start (void)
+{
+ //my_station.pipe_log_fd = 1;
+ //my_station.log_level = STATION_LOG_DEBUG;
+ //my_station.log_mask = STATION_LOGTYPE_FCALL;
+ test_pbproc_init (&test_pbproc_global);
+}
+