summaryrefslogtreecommitdiff
path: root/cesar/mac/pbproc/test/maximus
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/mac/pbproc/test/maximus')
-rw-r--r--cesar/mac/pbproc/test/maximus/Config2
-rw-r--r--cesar/mac/pbproc/test/maximus/Makefile10
-rw-r--r--cesar/mac/pbproc/test/maximus/ecos.ecc.sh5
-rw-r--r--cesar/mac/pbproc/test/maximus/inc/add_beacon_period.h23
-rw-r--r--cesar/mac/pbproc/test/maximus/inc/add_seg.h23
-rw-r--r--cesar/mac/pbproc/test/maximus/inc/context.h81
-rw-r--r--cesar/mac/pbproc/test/maximus/inc/get_seg.h31
-rw-r--r--cesar/mac/pbproc/test/maximus/inc/msg.h43
-rw-r--r--cesar/mac/pbproc/test/maximus/inc/prepare_beacon.h23
-rw-r--r--cesar/mac/pbproc/test/maximus/inc/set_tonemap.h23
-rw-r--r--cesar/mac/pbproc/test/maximus/inc/test_pbproc.h55
-rw-r--r--cesar/mac/pbproc/test/maximus/py/host_test_pbproc.py85
-rw-r--r--cesar/mac/pbproc/test/maximus/py/test_coll.py94
-rw-r--r--cesar/mac/pbproc/test/maximus/py/test_pbproc.py63
-rw-r--r--cesar/mac/pbproc/test/maximus/src/add_beacon_period.c101
-rw-r--r--cesar/mac/pbproc/test/maximus/src/add_seg.c111
-rw-r--r--cesar/mac/pbproc/test/maximus/src/get_seg.c104
-rw-r--r--cesar/mac/pbproc/test/maximus/src/prepare_beacon.c98
-rw-r--r--cesar/mac/pbproc/test/maximus/src/set_tonemap.c105
-rw-r--r--cesar/mac/pbproc/test/maximus/src/test_pbproc.c303
20 files changed, 1383 insertions, 0 deletions
diff --git a/cesar/mac/pbproc/test/maximus/Config b/cesar/mac/pbproc/test/maximus/Config
new file mode 100644
index 0000000000..56fc7a5571
--- /dev/null
+++ b/cesar/mac/pbproc/test/maximus/Config
@@ -0,0 +1,2 @@
+CONFIG_TRACE = y
+CONFIG_HOST_ASSERT = n \ No newline at end of file
diff --git a/cesar/mac/pbproc/test/maximus/Makefile b/cesar/mac/pbproc/test/maximus/Makefile
new file mode 100644
index 0000000000..2abbf462c8
--- /dev/null
+++ b/cesar/mac/pbproc/test/maximus/Makefile
@@ -0,0 +1,10 @@
+BASE = ../../../..
+
+ECOS = y
+
+TARGET_PROGRAMS = test_pbproc
+test_pbproc_SOURCES = test_pbproc.c get_seg.c add_seg.c prepare_beacon.c \
+ add_beacon_period.c set_tonemap.c
+test_pbproc_MODULES = hal/phy/maximus host lib mac/pbproc mac/ca mac/common
+
+include $(BASE)/common/make/top.mk
diff --git a/cesar/mac/pbproc/test/maximus/ecos.ecc.sh b/cesar/mac/pbproc/test/maximus/ecos.ecc.sh
new file mode 100644
index 0000000000..e0278271fe
--- /dev/null
+++ b/cesar/mac/pbproc/test/maximus/ecos.ecc.sh
@@ -0,0 +1,5 @@
+config=${1:-ecos-gen.ecc}
+ecosconfig --config=$config new maximus default
+cat >> $config <<'EOF'
+EOF
+ecosconfig --config=$config check
diff --git a/cesar/mac/pbproc/test/maximus/inc/add_beacon_period.h b/cesar/mac/pbproc/test/maximus/inc/add_beacon_period.h
new file mode 100644
index 0000000000..9df5a45281
--- /dev/null
+++ b/cesar/mac/pbproc/test/maximus/inc/add_beacon_period.h
@@ -0,0 +1,23 @@
+#ifndef inc_add_beacon_period_h
+#define inc_add_beacon_period_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file inc/add_beacon_period.h
+ * \brief Add beacon period fcall.
+ * \ingroup test
+ */
+
+BEGIN_DECLS
+
+void
+test_pbproc_add_beacon_period_init (test_pbproc_t *ctx);
+
+END_DECLS
+
+#endif /* inc_add_beacon_period_h */
diff --git a/cesar/mac/pbproc/test/maximus/inc/add_seg.h b/cesar/mac/pbproc/test/maximus/inc/add_seg.h
new file mode 100644
index 0000000000..37705e1a90
--- /dev/null
+++ b/cesar/mac/pbproc/test/maximus/inc/add_seg.h
@@ -0,0 +1,23 @@
+#ifndef inc_add_seg_h
+#define inc_add_seg_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file inc/add_seg.h
+ * \brief Add segments fcall.
+ * \ingroup test
+ */
+
+BEGIN_DECLS
+
+void
+test_pbproc_add_seg_init (test_pbproc_t *ctx);
+
+END_DECLS
+
+#endif /* inc_add_seg_h */
diff --git a/cesar/mac/pbproc/test/maximus/inc/context.h b/cesar/mac/pbproc/test/maximus/inc/context.h
new file mode 100644
index 0000000000..1a1fb93c6f
--- /dev/null
+++ b/cesar/mac/pbproc/test/maximus/inc/context.h
@@ -0,0 +1,81 @@
+#ifndef inc_context_h
+#define inc_context_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file inc/context.h
+ * \brief PBProc test context.
+ * \ingroup test
+ */
+
+#include <cyg/hal/hal_arch.h>
+#include <cyg/kernel/kapi.h>
+
+#include "lib/rnd.h"
+#include "host/fcall.h"
+
+#include "mac/pbproc/pbproc.h"
+
+#include "inc/msg.h"
+
+/** Number of beacon periods to keep. */
+#define TEST_PBPROC_NB_BEACON_PERIOD 3
+
+typedef void
+(*test_pbproc_msg_handler_cb_t) (test_pbproc_t *ctx, test_pbproc_msg_t *msg);
+
+/** Test PBProc context. */
+struct test_pbproc_t
+{
+ /** Random context. */
+ lib_rnd_t rnd[1];
+ /** Mac configuration. */
+ mac_config_t config;
+ /** Mac MFS and STA store. */
+ mac_store_t *store;
+ /** PBProc context. */
+ pbproc_t *pbproc;
+ /** Channel Access context. */
+ ca_t *ca;
+
+ /** Beacon periods. */
+ ca_beacon_period_t beacon_periods[TEST_PBPROC_NB_BEACON_PERIOD];
+ /** Number of beacon periods. */
+ uint beacon_periods_nb;
+
+ /** Event semaphore. */
+ cyg_sem_t event_sem;
+ /** Mailbox handle. */
+ cyg_handle_t mbox;
+ /** Mailbox storage. */
+ cyg_mbox mbox_storage;
+ /** Static message. */
+ test_pbproc_msg_t static_msg;
+ /** Messages handlers. */
+ test_pbproc_msg_handler_cb_t msg_handlers[TEST_PBPROC_MSG_ID_NONE];
+
+ /** PBProc RX callback. */
+ pbproc_rx_cb_t rx_cb;
+ /** Number of received PB. */
+ uint rx_pb_nb;
+
+ /** Function call context for return. */
+ fcall_ctx_t *fcall;
+ /** Function call identifier for return. */
+ unsigned short fcall_msg_id;
+
+ /** Kernel thread handle. */
+ cyg_handle_t thread;
+ /** Kernel thread storage. */
+ cyg_thread thread_storage;
+ /* Thread stack. */
+ u8 thread_stack[CYGNUM_HAL_STACK_SIZE_TYPICAL];
+};
+/* Forward declared in inc/test_pbproc.h. */
+
+#endif /* inc_context_h */
diff --git a/cesar/mac/pbproc/test/maximus/inc/get_seg.h b/cesar/mac/pbproc/test/maximus/inc/get_seg.h
new file mode 100644
index 0000000000..c6dccc8697
--- /dev/null
+++ b/cesar/mac/pbproc/test/maximus/inc/get_seg.h
@@ -0,0 +1,31 @@
+#ifndef inc_get_seg_h
+#define inc_get_seg_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file inc/get_seg.h
+ * \brief Get segments fcall.
+ * \ingroup test
+ */
+
+/** Get segments message. */
+struct test_pbproc_msg_get_seg_t
+{
+ /** Number of expected segments. */
+ uint seg_nb;
+};
+typedef struct test_pbproc_msg_get_seg_t test_pbproc_msg_get_seg_t;
+
+BEGIN_DECLS
+
+void
+test_pbproc_get_seg_init (test_pbproc_t *ctx);
+
+END_DECLS
+
+#endif /* inc_get_seg_h */
diff --git a/cesar/mac/pbproc/test/maximus/inc/msg.h b/cesar/mac/pbproc/test/maximus/inc/msg.h
new file mode 100644
index 0000000000..bd7ed8958a
--- /dev/null
+++ b/cesar/mac/pbproc/test/maximus/inc/msg.h
@@ -0,0 +1,43 @@
+#ifndef inc_msg_h
+#define inc_msg_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file inc/msg.h
+ * \brief PBProc test messages.
+ * \ingroup test
+ */
+
+#include "inc/test_pbproc.h"
+#include "inc/add_seg.h"
+#include "inc/prepare_beacon.h"
+#include "inc/get_seg.h"
+#include "inc/add_beacon_period.h"
+#include "inc/set_tonemap.h"
+
+/** Test PBProc messages identifiers. */
+enum test_pbproc_msg_id_t
+{
+ TEST_PBPROC_MSG_ID_GET_SEG,
+ TEST_PBPROC_MSG_ID_NONE,
+};
+typedef enum test_pbproc_msg_id_t test_pbproc_msg_id_t;
+
+/** Message union. */
+struct test_pbproc_msg_t
+{
+ /** Message identifier. */
+ test_pbproc_msg_id_t id;
+ /** Message itself. */
+ union {
+ struct test_pbproc_msg_get_seg_t get_seg;
+ } msg;
+};
+typedef struct test_pbproc_msg_t test_pbproc_msg_t;
+
+#endif /* inc_msg_h */
diff --git a/cesar/mac/pbproc/test/maximus/inc/prepare_beacon.h b/cesar/mac/pbproc/test/maximus/inc/prepare_beacon.h
new file mode 100644
index 0000000000..d2446b1ddc
--- /dev/null
+++ b/cesar/mac/pbproc/test/maximus/inc/prepare_beacon.h
@@ -0,0 +1,23 @@
+#ifndef inc_prepare_beacon_h
+#define inc_prepare_beacon_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file inc/prepare_beacon.h
+ * \brief Prepare beacon fcall.
+ * \ingroup test
+ */
+
+BEGIN_DECLS
+
+void
+test_pbproc_prepare_beacon_init (test_pbproc_t *ctx);
+
+END_DECLS
+
+#endif /* inc_prepare_beacon_h */
diff --git a/cesar/mac/pbproc/test/maximus/inc/set_tonemap.h b/cesar/mac/pbproc/test/maximus/inc/set_tonemap.h
new file mode 100644
index 0000000000..36fadbef99
--- /dev/null
+++ b/cesar/mac/pbproc/test/maximus/inc/set_tonemap.h
@@ -0,0 +1,23 @@
+#ifndef inc_set_tonemap_h
+#define inc_set_tonemap_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file inc/set_tonemap.h
+ * \brief Set tonemap fcall.
+ * \ingroup test
+ */
+
+BEGIN_DECLS
+
+void
+test_pbproc_set_tonemap_init (test_pbproc_t *ctx);
+
+END_DECLS
+
+#endif /* inc_set_tonemap_h */
diff --git a/cesar/mac/pbproc/test/maximus/inc/test_pbproc.h b/cesar/mac/pbproc/test/maximus/inc/test_pbproc.h
new file mode 100644
index 0000000000..6cb16c87d0
--- /dev/null
+++ b/cesar/mac/pbproc/test/maximus/inc/test_pbproc.h
@@ -0,0 +1,55 @@
+#ifndef inc_test_pbproc_h
+#define inc_test_pbproc_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file inc/test_pbproc.h
+ * \brief PBProc test on Maximus.
+ * \ingroup test
+ */
+#include "mac/pbproc/pbproc.h"
+
+/* Forward declaration. */
+typedef struct test_pbproc_t test_pbproc_t;
+
+/**
+ * Helper for parameter binding.
+ * \param name parameter string
+ * \param var parameter storage
+ * \return true if binding successful
+ */
+#define test_pbproc_fcall_bind(name, var) \
+ (fcall_param_bind (*param, *msg, (name), sizeof (var), &(var)) \
+ == sizeof (var))
+
+#define test_pbproc_fcall_bind_long(name, var) \
+ (fcall_param_bind_long (*param, *msg, (name), &(var)) == sizeof (var))
+
+/**
+ * Helper for parameter adding.
+ * \param name parameter string
+ * \param var parameter storage
+ */
+#define test_pbproc_fcall_add(name, var) \
+ dbg_check (fcall_param_add (&param, &msg, (name), sizeof (var), &(var)) \
+ != -1)
+
+#define test_pbproc_fcall_add_long(name, var) \
+ dbg_check (fcall_param_add_long (&param, &msg, (name), &(var)) != -1)
+
+BEGIN_DECLS
+
+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);
+
+END_DECLS
+
+#endif /* inc_test_pbproc_h */
diff --git a/cesar/mac/pbproc/test/maximus/py/host_test_pbproc.py b/cesar/mac/pbproc/test/maximus/py/host_test_pbproc.py
new file mode 100644
index 0000000000..2d55c183ee
--- /dev/null
+++ b/cesar/mac/pbproc/test/maximus/py/host_test_pbproc.py
@@ -0,0 +1,85 @@
+#!/usr/bin/python
+import sys;
+sys.path.append ('../../../../maximus/python')
+sys.path.append ('../../../../maximus/python/obj')
+
+trace = { }
+for i in ('phy', 'ca', 'pbproc'):
+ o = '--%s-trace' % i
+ if o in sys.argv:
+ trace[i] = True
+ sys.argv.remove (o)
+
+bp_tck = 25000000 / 50
+before_bp_tck = bp_tck * 3 / 4
+
+from interface import *
+from test_pbproc import *
+
+maximus = Maximus ()
+maximus.init (sys.argv + ['-e', 'obj/test_pbproc.elf'])
+
+sta1 = maximus.create_sta ()
+sta1.set_name ('sta1')
+sta2 = maximus.create_sta ()
+sta2.set_name ('sta2')
+
+t1 = TestPBProc (maximus, sta1)
+t2 = TestPBProc (maximus, sta2)
+
+sta1.debug ()
+sta2.debug ()
+
+t1.set_config (tei = 1, snid = 1)
+t2.set_config (tei = 2, snid = 1)
+
+beacon_period = dict (glid = 0xff, coex = 2)
+
+t1.add_beacon_period (start_date = 0, **beacon_period)
+t1.add_beacon_period (start_date = bp_tck, **beacon_period)
+t1.add_beacon_period (start_date = 2 * bp_tck, **beacon_period)
+t2.add_beacon_period (start_date = 0, **beacon_period)
+t2.add_beacon_period (start_date = bp_tck, **beacon_period)
+t2.add_beacon_period (start_date = 2 * bp_tck, **beacon_period)
+
+t1.seg = t2.seg = 0
+t1.add_seg (mme = False, lid = 0, tei = 2, seg_nb = 16, gen = 0); t1.seg += 16
+t1.add_seg (mme = True, lid = 0, tei = 2, seg_nb = 4, gen = 0); t1.seg += 4
+t1.add_seg (mme = False, lid = 1, tei = 2, seg_nb = 4, gen = 0); t1.seg += 4
+t2.add_seg (mme = False, lid = 0, tei = 1, seg_nb = 16, gen = 0); t2.seg += 16
+
+t1.rx_seg_refill (seg_nb = 25)
+t2.rx_seg_refill (seg_nb = 25)
+t1.activate ()
+t2.activate ()
+
+stop = 0
+
+def get_seg_cb (r, seg_nb):
+ assert (r.seg_nb == seg_nb)
+ global stop
+ stop += 1
+t1.get_seg_async (lambda r: get_seg_cb (r, t2.seg), seg_nb = t2.seg)
+t2.get_seg_async (lambda r: get_seg_cb (r, t1.seg), seg_nb = t1.seg)
+
+bp = 0
+while stop != 2:
+ bp += 1
+ maximus.wait (before_bp_tck)
+ t1.prepare_beacon (lid = 0xfd)
+ maximus.wait (bp_tck - before_bp_tck)
+ if bp == 1:
+ t2.set_tonemap (RX, tei = 1, tmi = 5, bits = 10)
+ t1.set_tonemap (TX, tei = 2, tmi = 5, bits = 10)
+ t1.set_tonemap (RX, tei = 2, tmi = 6, bits = 6)
+ t2.set_tonemap (TX, tei = 1, tmi = 6, bits = 6)
+ t1.add_beacon_period (start_date = (bp + 2) * bp_tck, **beacon_period)
+ t2.add_beacon_period (start_date = (bp + 2) * bp_tck, **beacon_period)
+
+t1.activate (False)
+t2.activate (False)
+
+print 'trace sta1:'; sys.stdout.flush ()
+t1.trace_dump (**trace)
+print '\ntrace sta2:'; sys.stdout.flush ()
+t2.trace_dump (**trace)
diff --git a/cesar/mac/pbproc/test/maximus/py/test_coll.py b/cesar/mac/pbproc/test/maximus/py/test_coll.py
new file mode 100644
index 0000000000..df3033aa7c
--- /dev/null
+++ b/cesar/mac/pbproc/test/maximus/py/test_coll.py
@@ -0,0 +1,94 @@
+#!/usr/bin/python
+import sys;
+sys.path.append ('../../../../maximus/python')
+sys.path.append ('../../../../maximus/python/obj')
+
+trace = { }
+for i in ('phy', 'ca', 'pbproc'):
+ o = '--%s-trace' % i
+ if o in sys.argv:
+ trace[i] = True
+ sys.argv.remove (o)
+
+bp_tck = 10 * 25000000 / 50
+
+from interface import *
+from test_pbproc import *
+
+maximus = Maximus ()
+maximus.init (sys.argv + ['-e', 'obj/test_pbproc.elf'])
+
+sta1 = maximus.create_sta ()
+sta1.set_name ('sta1')
+sta2 = maximus.create_sta ()
+sta2.set_name ('sta2')
+
+t1 = TestPBProc (maximus, sta1)
+t2 = TestPBProc (maximus, sta2)
+
+sta1.debug ()
+sta2.debug ()
+
+t1.set_config (tei = 1, snid = 1)
+t2.set_config (tei = 2, snid = 1)
+
+beacon_period = dict (glid = 0xff, coex = 2, beacon_period_tck = bp_tck)
+
+t1.add_beacon_period (start_date = 0, **beacon_period)
+t1.add_beacon_period (start_date = bp_tck, **beacon_period)
+t1.add_beacon_period (start_date = 2 * bp_tck, **beacon_period)
+t2.add_beacon_period (start_date = 0, **beacon_period)
+t2.add_beacon_period (start_date = bp_tck, **beacon_period)
+t2.add_beacon_period (start_date = 2 * bp_tck, **beacon_period)
+
+t1.seg = t2.seg = 0
+t1.tei = 1
+t2.tei = 2
+
+def feed (ttx, trx):
+ ttx.add_seg (mme = False, lid = 0, tei = trx.tei, seg_nb = 20, gen = 0); ttx.seg += 20
+ ttx.add_seg (mme = False, lid = 1, tei = trx.tei, seg_nb = 5, gen = 0); ttx.seg += 5
+
+feed (t1, t2)
+feed (t2, t1)
+
+t1.rx_seg_refill (seg_nb = 50)
+t2.rx_seg_refill (seg_nb = 50)
+t1.activate ()
+t2.activate ()
+
+stop = 0
+
+def get_seg_cb (r, ttx, trx):
+ assert (r.seg_nb == ttx.seg)
+ ttx.seg = 0
+ global stop
+ stop += 1
+ feed (ttx, trx)
+ trx.get_seg_async (lambda r: get_seg_cb (r, ttx, trx), seg_nb = ttx.seg)
+
+t1.get_seg_async (lambda r: get_seg_cb (r, t2, t1), seg_nb = t2.seg)
+t2.get_seg_async (lambda r: get_seg_cb (r, t1, t2), seg_nb = t1.seg)
+
+bp = 0
+while stop < 4:
+ bp += 1
+ maximus.wait (bp_tck)
+ if bp == 1:
+ t2.set_tonemap (RX, tei = 1, tmi = 5, bits = 10)
+ t1.set_tonemap (TX, tei = 2, tmi = 5, bits = 10)
+ t1.set_tonemap (RX, tei = 2, tmi = 6, bits = 6)
+ t2.set_tonemap (TX, tei = 1, tmi = 6, bits = 6)
+ t1.add_beacon_period (start_date = (bp + 2) * bp_tck, **beacon_period)
+ t2.add_beacon_period (start_date = (bp + 2) * bp_tck, **beacon_period)
+
+t1.activate (False)
+t2.activate (False)
+
+print 'trace sta1:'; sys.stdout.flush ()
+t1.trace_dump (**trace)
+print '\ntrace sta2:'; sys.stdout.flush ()
+t2.trace_dump (**trace)
+
+sta1.remove()
+sta2.remove()
diff --git a/cesar/mac/pbproc/test/maximus/py/test_pbproc.py b/cesar/mac/pbproc/test/maximus/py/test_pbproc.py
new file mode 100644
index 0000000000..3025494913
--- /dev/null
+++ b/cesar/mac/pbproc/test/maximus/py/test_pbproc.py
@@ -0,0 +1,63 @@
+RX = False
+TX = True
+
+class TestPBProc:
+ """PBProc test wrapper."""
+ def __init__ (self, maximus, sta):
+ self.maximus = maximus
+ self.sta = sta
+
+ def create_fcall (self, name, **args):
+ """Create a function call with given name and parameters."""
+ fc = self.maximus.create_fcall (name)
+ for (n, v) in args.iteritems ():
+ if type (v) is bool:
+ fc.add_param_bool (n, v)
+ elif type (v) is int:
+ fc.add_param_ulong (n, v)
+ else:
+ raise TypeError
+ return fc
+
+ def set_config (self, **args):
+ self.create_fcall ('set_config', **args).send (self.sta)
+
+ def add_seg (self, mme, lid, tei, seg_nb, gen):
+ self.create_fcall ('add_seg', mme = mme, lid = lid, tei = tei,
+ seg_nb = seg_nb, gen = gen).send (self.sta)
+
+ def prepare_beacon (self, **args):
+ self.create_fcall ('prepare_beacon', **args).send (self.sta)
+
+ def get_seg (self, **args):
+ m = self.create_fcall ('get_seg', **args)
+ m.send (self.sta)
+ class get_seg_rsp:
+ def __init__ (self, m):
+ self.seg_nb = m.bind_param_ulong ('seg_nb')
+ return get_seg_rsp (m)
+
+ def get_seg_async (self, cb, **args):
+ m = self.create_fcall ('get_seg', **args)
+ class get_seg_rsp:
+ def __init__ (self, m):
+ self.seg_nb = m.bind_param_ulong ('seg_nb')
+ def get_seg_cb (msg):
+ cb (get_seg_rsp (msg))
+ m.set_cb (get_seg_cb)
+ m.send_async (self.sta)
+
+ def rx_seg_refill (self, **args):
+ self.create_fcall ('rx_seg_refill', **args).send (self.sta)
+
+ def add_beacon_period (self, **args):
+ self.create_fcall ('add_beacon_period', **args).send (self.sta)
+
+ def set_tonemap (self, tx, **args):
+ self.create_fcall ('set_tonemap', tx = tx, **args).send (self.sta)
+
+ def activate (self, activate = True):
+ self.create_fcall ('activate', activate = activate).send (self.sta)
+
+ def trace_dump (self, **args):
+ self.create_fcall ('trace_dump', **args).send (self.sta)
diff --git a/cesar/mac/pbproc/test/maximus/src/add_beacon_period.c b/cesar/mac/pbproc/test/maximus/src/add_beacon_period.c
new file mode 100644
index 0000000000..21f1550925
--- /dev/null
+++ b/cesar/mac/pbproc/test/maximus/src/add_beacon_period.c
@@ -0,0 +1,101 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/add_beacon_period.c
+ * \brief Add beacon period fcall.
+ * \ingroup test
+ */
+#include "common/std.h"
+
+#include "host/fcall.h"
+#include "mac/common/mfs.h"
+#include "mac/common/store.h"
+#include "mac/common/timings.h"
+
+#include "inc/test_pbproc.h"
+#include "inc/add_beacon_period.h"
+#include "inc/context.h"
+
+static int
+test_pbproc_add_beacon_period_fcall (fcall_ctx_t *fcall,
+ fcall_param_t **param, sci_msg_t **msg,
+ void *data);
+
+void
+test_pbproc_add_beacon_period_init (test_pbproc_t *ctx)
+{
+ dbg_assert (ctx);
+ fcall_register (my_station.fcall, "add_beacon_period",
+ test_pbproc_add_beacon_period_fcall, ctx);
+}
+
+static void
+test_pbproc_add_beacon_period (test_pbproc_t *ctx, u32 start_date, uint glid,
+ mac_coexistence_mode_t coex,
+ uint beacon_period_tck)
+{
+ dbg_assert (ctx);
+ /* Get and fill schedule. */
+ uint schedule_index = ctx->beacon_periods_nb == 0 ? 0 :
+ ((ctx->beacon_periods[ctx->beacon_periods_nb - 1].schedule_index + 1)
+ % (TEST_PBPROC_NB_BEACON_PERIOD + 1));
+ ca_schedule_t *sched = ca_alloc_get_schedule (ctx->ca, schedule_index);
+ sched->coexistence_mode = coex;
+ sched->nek_switch = 0;
+ sched->allocations_nb = 1;
+ sched->allocations[0].end_offset_tck = beacon_period_tck
+ ? beacon_period_tck : MAC_MS_TO_TCK (1000) / 50;
+ sched->allocations[0].glid = glid;
+ /* Update the beacon period table. */
+ if (ctx->beacon_periods_nb == TEST_PBPROC_NB_BEACON_PERIOD)
+ {
+ uint i;
+ for (i = 0; i < TEST_PBPROC_NB_BEACON_PERIOD - 1; i++)
+ ctx->beacon_periods[i] = ctx->beacon_periods[i + 1];
+ ctx->beacon_periods_nb--;
+ }
+ ctx->beacon_periods[ctx->beacon_periods_nb].start_date = start_date;
+ ctx->beacon_periods[ctx->beacon_periods_nb].schedule_index =
+ schedule_index;
+ ctx->beacon_periods_nb++;
+ /* Use the new one. */
+ ca_alloc_update_beacon_periods (ctx->ca, ctx->beacon_periods,
+ ctx->beacon_periods_nb);
+}
+
+static int
+test_pbproc_add_beacon_period_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. */
+ u32 start_date;
+ uint glid;
+ uint beacon_period_tck;
+ mac_coexistence_mode_t coex;
+ if (!test_pbproc_fcall_bind_long ("start_date", start_date))
+ return -1;
+ if (!test_pbproc_fcall_bind_long ("glid", glid))
+ return -1;
+ if (!test_pbproc_fcall_bind_long ("coex", coex))
+ coex = MAC_COEXISTENCE_AV_ONLY_MODE;
+ if (!test_pbproc_fcall_bind_long ("beacon_period_tck", beacon_period_tck))
+ beacon_period_tck = 0;
+ /* Add beacon period. */
+ test_pbproc_add_beacon_period (ctx, start_date, glid, coex,
+ beacon_period_tck);
+ /* Return. */
+ fcall_param_reset (*param);
+ return 0;
+}
+
diff --git a/cesar/mac/pbproc/test/maximus/src/add_seg.c b/cesar/mac/pbproc/test/maximus/src/add_seg.c
new file mode 100644
index 0000000000..3c7e746e92
--- /dev/null
+++ b/cesar/mac/pbproc/test/maximus/src/add_seg.c
@@ -0,0 +1,111 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/add_seg.c
+ * \brief Add segments fcall.
+ * \ingroup test
+ */
+#include "common/std.h"
+
+#include "host/fcall.h"
+#include "mac/common/mfs.h"
+#include "mac/common/store.h"
+
+#include "inc/test_pbproc.h"
+#include "inc/add_seg.h"
+#include "inc/context.h"
+
+static int
+test_pbproc_add_seg_fcall (fcall_ctx_t *fcall, fcall_param_t **param,
+ sci_msg_t **msg, void *data);
+
+void
+test_pbproc_add_seg_init (test_pbproc_t *ctx)
+{
+ dbg_assert (ctx);
+ fcall_register (my_station.fcall, "add_seg", test_pbproc_add_seg_fcall,
+ ctx);
+}
+
+static void
+test_pbproc_add_seg (test_pbproc_t *ctx, bool mme, uint lid, uint tei,
+ uint seg_nb, uint gen)
+{
+ mfs_tx_t *mfs;
+ bool added;
+ dbg_assert (ctx);
+ dbg_assert (seg_nb > 0);
+ /* Locate the MFS. */
+ mfs = mac_store_mfs_add_tx (ctx->store, tei == MAC_TEI_BCAST, mme,
+ mme ? MAC_LID_NONE : lid, tei, &added);
+ if (added)
+ ca_mfs_add (ctx->ca, mfs);
+ /* Generate segments. */
+ blk_t *blk_first, *blk_last;
+ blk_first = blk_alloc_desc_range (seg_nb, &blk_last);
+ pb_t *seg_first = PB_FROM_BLK (blk_first);
+ pb_t *seg_last = PB_FROM_BLK (blk_last);
+ pb_t *seg, *lseg;
+ uint i;
+ for (lseg = NULL, seg = seg_first, i = 0;
+ lseg != seg_last;
+ lseg = seg, seg = seg->next, i++)
+ {
+ /* Fill header. */
+ seg->header.ssn = mfs->next_ssn++;
+ seg->header.mfbo = 0;
+ seg->header.vpbf = true;
+ seg->header.mmqf = mme;
+ seg->header.mfbf = false;
+ seg->header.opsf = false;
+ seg->header.rsvd = 0;
+ /* Generate pattern. */
+ seg->data[0] = 0x42;
+ seg->data[1] = 0x5a;
+ seg->data[2] = gen;
+ seg->data[3] = i;
+ }
+ /* Insert them. */
+ pbproc_mfs_insert (mfs, seg_first, seg_last, seg_nb, mfs->cap);
+ pbproc_mfs_provide (mfs, seg_nb);
+ /* Update CA. */
+ ca_mfs_update (ctx->ca, mfs);
+ /* Release the MFS reference. */
+ blk_release (mfs);
+}
+
+static int
+test_pbproc_add_seg_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, tei, lid, gen;
+ bool mme;
+ if (!test_pbproc_fcall_bind ("mme", mme))
+ return -1;
+ if (!test_pbproc_fcall_bind_long ("lid", lid) || !MAC_LID_IS_XLID (lid))
+ return -1;
+ if (!test_pbproc_fcall_bind_long ("tei", tei)
+ || !(MAC_TEI_IS_STA (tei) || tei == MAC_TEI_BCAST))
+ return -1;
+ if (!test_pbproc_fcall_bind_long ("seg_nb", seg_nb))
+ return -1;
+ if (!test_pbproc_fcall_bind_long ("gen", gen))
+ return -1;
+ /* Add segments. */
+ test_pbproc_add_seg (ctx, mme, lid, tei, seg_nb, gen);
+ /* Return. */
+ fcall_param_reset (*param);
+ return 0;
+}
+
diff --git a/cesar/mac/pbproc/test/maximus/src/get_seg.c b/cesar/mac/pbproc/test/maximus/src/get_seg.c
new file mode 100644
index 0000000000..935a0435b7
--- /dev/null
+++ b/cesar/mac/pbproc/test/maximus/src/get_seg.c
@@ -0,0 +1,104 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/get_seg.c
+ * \brief Get segments fcall.
+ * \ingroup test
+ */
+#include "common/std.h"
+
+#include "host/fcall.h"
+#include "mac/common/mfs.h"
+#include "mac/common/store.h"
+
+#include "inc/test_pbproc.h"
+#include "inc/get_seg.h"
+#include "inc/context.h"
+
+static int
+test_pbproc_get_seg_fcall (fcall_ctx_t *fcall, fcall_param_t **param,
+ sci_msg_t **msg, void *data);
+
+static void
+test_pbproc_get_seg_handler (test_pbproc_t *ctx, test_pbproc_msg_t *msg);
+
+static void
+test_pbproc_get_seg_fcall_return (test_pbproc_t *ctx, uint seg_nb);
+
+void
+test_pbproc_get_seg_init (test_pbproc_t *ctx)
+{
+ dbg_assert (ctx);
+ fcall_register (my_station.fcall, "get_seg", test_pbproc_get_seg_fcall,
+ ctx);
+ ctx->msg_handlers[TEST_PBPROC_MSG_ID_GET_SEG] =
+ test_pbproc_get_seg_handler;
+}
+
+static void
+test_pbproc_get_seg_handler (test_pbproc_t *ctx, test_pbproc_msg_t *msg)
+{
+ dbg_assert (ctx);
+ dbg_assert (msg->id == TEST_PBPROC_MSG_ID_GET_SEG);
+ uint seg_nb = msg->msg.get_seg.seg_nb;
+ dbg_assert (seg_nb > 0);
+ /* Install callback. */
+ ctx->rx_cb = test_pbproc_default_rx_cb;
+ /* Wait until enough segments are received. */
+ uint base = ctx->rx_pb_nb;
+ while (ctx->rx_pb_nb < base + seg_nb)
+ dbg_check (cyg_semaphore_wait (&ctx->event_sem));
+ /* Uninstall callback. */
+ ctx->rx_cb = NULL;
+ /* Return. */
+ test_pbproc_get_seg_fcall_return (ctx, ctx->rx_pb_nb - base);
+}
+
+static int
+test_pbproc_get_seg_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);
+ /* Only one message at a time. */
+ if (ctx->static_msg.id != TEST_PBPROC_MSG_ID_NONE)
+ return -1;
+ ctx->static_msg.id = TEST_PBPROC_MSG_ID_GET_SEG;
+ /* Read message. */
+ test_pbproc_msg_get_seg_t *m = &ctx->static_msg.msg.get_seg;
+ if (!test_pbproc_fcall_bind_long ("seg_nb", m->seg_nb))
+ return -1;
+ /* Message accepted, will return later. */
+ fcall_param_set_async (*param, 1);
+ dbg_assert (ctx->fcall == NULL);
+ ctx->fcall = fcall;
+ ctx->fcall_msg_id = fcall_param_get_msg_id (*param);
+ /* Post message. */
+ dbg_check (cyg_mbox_put (ctx->mbox, &ctx->static_msg));
+ return 0;
+}
+
+static void
+test_pbproc_get_seg_fcall_return (test_pbproc_t *ctx, uint seg_nb)
+{
+ fcall_param_t param;
+ sci_msg_t msg;
+ u8 buffer[64];
+ dbg_assert (ctx);
+ dbg_assert (ctx->fcall);
+ fcall_param_init (&param, "get_seg", ctx->fcall_msg_id);
+ sci_msg_init (&msg, buffer, sizeof (buffer));
+ fcall_param_reset (&param);
+ test_pbproc_fcall_add_long ("seg_nb", seg_nb);
+ dbg_check (fcall_return (ctx->fcall, &param, &msg) != -1);
+ ctx->fcall = NULL;
+}
+
diff --git a/cesar/mac/pbproc/test/maximus/src/prepare_beacon.c b/cesar/mac/pbproc/test/maximus/src/prepare_beacon.c
new file mode 100644
index 0000000000..c7abc2b4cf
--- /dev/null
+++ b/cesar/mac/pbproc/test/maximus/src/prepare_beacon.c
@@ -0,0 +1,98 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/prepare_beacon.c
+ * \brief Prepare beacon fcall.
+ * \ingroup test
+ */
+#include "common/std.h"
+
+#include "host/fcall.h"
+#include "mac/common/mfs.h"
+#include "mac/common/store.h"
+
+#include "inc/test_pbproc.h"
+#include "inc/prepare_beacon.h"
+#include "inc/context.h"
+
+static int
+test_pbproc_prepare_beacon_fcall (fcall_ctx_t *fcall, fcall_param_t **param,
+ sci_msg_t **msg, void *data);
+
+void
+test_pbproc_prepare_beacon_init (test_pbproc_t *ctx)
+{
+ dbg_assert (ctx);
+ fcall_register (my_station.fcall, "prepare_beacon",
+ test_pbproc_prepare_beacon_fcall, ctx);
+}
+
+static void
+test_pbproc_prepare_beacon (test_pbproc_t *ctx, uint lid, u32 gen)
+{
+ mfs_tx_t *mfs;
+ bool added;
+ dbg_assert (ctx);
+ /* Locate the MFS. */
+ mfs = mac_store_mfs_add_tx (ctx->store, MAC_TEI_BCAST, false, lid, 0xff,
+ &added);
+ if (added)
+ {
+ mfs->beacon = true;
+ mfs->cap = lid == MAC_LID_SPC_CENTRAL ? 3 : 2;
+ ca_mfs_add (ctx->ca, mfs);
+ }
+ /* Generate segments. */
+ blk_t *blk;
+ blk = blk_alloc_desc ();
+ pb_beacon_t *seg = PARENT_OF (pb_beacon_t, blk, blk);
+ /* Generate pattern. */
+ seg->first_data_word = 0x04052006;
+ seg->data[0] = 0x42;
+ seg->data[1] = 0xa5;
+ seg->data[2] = gen;
+ seg->data[3] = 0;
+ /* Prepare beacon. */
+ pbproc_tx_beacon_params_t params = {
+ { 0x0123, 0x1234, 0x2345, 0x3456 }, NULL
+ };
+ ca_mfs_hold (ctx->ca, mfs);
+ pbproc_mfs_beacon_prepare (ctx->pbproc, mfs, seg, &params);
+ /* Update CA (may be useful if the MFS is unheld before beacon payload is
+ * added.. */
+ ca_mfs_update (ctx->ca, mfs);
+ /* Release the MFS reference. */
+ blk_release (mfs);
+}
+
+static int
+test_pbproc_prepare_beacon_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. */
+ u32 gen;
+ uint lid;
+ if (!test_pbproc_fcall_bind_long ("lid", lid))
+ lid = MAC_LID_SPC_CENTRAL;
+ if (!(MAC_LID_IS_GLID (lid) || lid == MAC_LID_SPC_CENTRAL
+ || lid == MAC_LID_DISCOVER))
+ return -1;
+ if (!test_pbproc_fcall_bind_long ("gen", gen))
+ gen = 0;
+ /* Prepare beacon. */
+ test_pbproc_prepare_beacon (ctx, lid, gen);
+ /* Return. */
+ fcall_param_reset (*param);
+ return 0;
+}
+
diff --git a/cesar/mac/pbproc/test/maximus/src/set_tonemap.c b/cesar/mac/pbproc/test/maximus/src/set_tonemap.c
new file mode 100644
index 0000000000..7e7f0b60f8
--- /dev/null
+++ b/cesar/mac/pbproc/test/maximus/src/set_tonemap.c
@@ -0,0 +1,105 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/set_tonemap.c
+ * \brief Set tonemap fcall.
+ * \ingroup test
+ */
+#include "common/std.h"
+
+#include "host/fcall.h"
+#include "mac/common/store.h"
+
+#include "inc/test_pbproc.h"
+#include "inc/set_tonemap.h"
+#include "inc/context.h"
+
+#include <string.h>
+
+static int
+test_pbproc_set_tonemap_fcall (fcall_ctx_t *fcall,
+ fcall_param_t **param, sci_msg_t **msg,
+ void *data);
+
+void
+test_pbproc_set_tonemap_init (test_pbproc_t *ctx)
+{
+ dbg_assert (ctx);
+ fcall_register (my_station.fcall, "set_tonemap",
+ test_pbproc_set_tonemap_fcall, ctx);
+}
+
+static void
+test_pbproc_set_tonemap (test_pbproc_t *ctx, bool tx, uint tei, uint tmi,
+ uint bits)
+{
+ dbg_assert (ctx);
+ dbg_assert (MAC_TEI_IS_STA (tei));
+ dbg_assert (tmi < TONEMAP_INDEX_NB);
+ /* Create/get STA. */
+ mac_store_sta_add (ctx->store, tei);
+ sta_t *sta = mac_store_sta_get (ctx->store, tei);
+ dbg_assert (sta);
+ tonemaps_t *tms = tx ? sta->tx_tonemaps : sta->rx_tonemaps;
+ /* Release any older tonemap. */
+ if (tms->tm[tmi])
+ tonemap_release (tms, tmi);
+ /* Create the new tonemap. */
+ if (tmi >= PHY_MOD_ROBO_NB)
+ {
+ /* Create a tonemap. */
+ tonemap_t *tm = tonemap_alloc ();
+ tms->tm[tmi] = tm;
+ tm->strict = false;
+ tm->cpf = true;
+ tm->fecrate = PHY_FEC_RATE_16_21;
+ tm->gil = PHY_GIL_417;
+ tm->bits_per_symbol = bits * ctx->config.tonemask_info.carrier_nb;
+ tm->ble = tonemap_ble (tm->bits_per_symbol, tm->fecrate,
+ CONST_UF32 (0.0), tm->gil);
+ /* Fill tonemap. */
+ static const u8 tm_data[] = {
+ 0x00, 0x11, 0x22, 0x33, 0x44, 0, 0x55, 0, 0x66, 0, 0x77
+ };
+ dbg_assert (bits < COUNT (tm_data) && tm_data[bits]);
+ memset (tm->tmdma_desc_head->data, tm_data[bits], BLK_SIZE);
+ memset (tm->tmdma_desc_head->next->data, tm_data[bits], BLK_SIZE / 2);
+ }
+ /* Done. */
+ tms->default_tmi = tmi;
+ blk_release (sta);
+}
+
+static int
+test_pbproc_set_tonemap_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 tx;
+ uint tei, tmi, bits = 0;
+ if (!test_pbproc_fcall_bind ("tx", tx))
+ return -1;
+ if (!test_pbproc_fcall_bind_long ("tei", tei))
+ return -1;
+ if (!test_pbproc_fcall_bind_long ("tmi", tmi))
+ return -1;
+ if (!test_pbproc_fcall_bind_long ("bits", bits) && tmi >= PHY_MOD_ROBO_NB)
+ return -1;
+ /* Add beacon period. */
+ test_pbproc_set_tonemap (ctx, tx, tei, tmi, bits);
+ /* Return. */
+ fcall_param_reset (*param);
+ return 0;
+}
+
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);
+}
+