summaryrefslogtreecommitdiff
path: root/cesar/mac/sar
diff options
context:
space:
mode:
authorNélio Laranjeiro2011-10-26 15:22:03 +0200
committerNélio Laranjeiro2011-11-02 17:46:32 +0100
commitf6db88b54aada34d67d4c9b0257f10bb4a6a501e (patch)
treea9df2e75b3c8c8384ce69646178c06479e4e463a /cesar/mac/sar
parent051e91123f40c3100f890d295d96361985ee52de (diff)
cesar/mac/sar: move thread behavior to thread files, refs #2813
Diffstat (limited to 'cesar/mac/sar')
-rw-r--r--cesar/mac/sar/Module2
-rw-r--r--cesar/mac/sar/inc/sar.h10
-rw-r--r--cesar/mac/sar/inc/sar_context.h6
-rw-r--r--cesar/mac/sar/inc/thread.h51
-rw-r--r--cesar/mac/sar/sar.h7
-rw-r--r--cesar/mac/sar/src/sar.c45
-rw-r--r--cesar/mac/sar/src/thread.c73
-rw-r--r--cesar/mac/sar/stub/src/sar.c6
8 files changed, 128 insertions, 72 deletions
diff --git a/cesar/mac/sar/Module b/cesar/mac/sar/Module
index ccc0d8c505..ee73caf4c4 100644
--- a/cesar/mac/sar/Module
+++ b/cesar/mac/sar/Module
@@ -1,4 +1,4 @@
-SOURCES := sar.c sar_expiration.c sar_mf.c
+SOURCES := sar.c sar_expiration.c sar_mf.c thread.c
ifeq ($(CONFIG_TRACE),y)
SOURCES += trace.c
endif
diff --git a/cesar/mac/sar/inc/sar.h b/cesar/mac/sar/inc/sar.h
index f877c85795..c40f7c0e13 100644
--- a/cesar/mac/sar/inc/sar.h
+++ b/cesar/mac/sar/inc/sar.h
@@ -14,9 +14,6 @@
* \ingroup mac/sar/inc
*
*/
-#include <cyg/hal/hal_arch.h>
-#include <cyg/kernel/kapi.h>
-
#define SAR_MPDU_RX_REFILL 1
/**
@@ -122,13 +119,6 @@ void
sar_rx_mfs_process (sar_t *ctx, mfs_rx_t * mfs,
sar_reassembly_ctx_t *rea_ctx);
-/**
- * SAR thread entry function.
- * \param data the SAR context.
- */
-void
-sar_process (cyg_addrword_t data);
-
END_DECLS
#endif /* MAC_SAR_INC_SAR_H_ */
diff --git a/cesar/mac/sar/inc/sar_context.h b/cesar/mac/sar/inc/sar_context.h
index ec3965b6de..ea6f9d5599 100644
--- a/cesar/mac/sar/inc/sar_context.h
+++ b/cesar/mac/sar/inc/sar_context.h
@@ -35,7 +35,6 @@
#include "mac/sar/inc/trace.h"
#include "config/stats.h"
#include "config/sar.h"
-#include "common/defs/priority.h"
/** Invalid SSN. */
#define SAR_SSN_INVALID 0x10000
@@ -196,11 +195,6 @@ struct sar_t
/** message context */
void *ul_msg_ctx;
- /** Thread context. */
- u8 thread_stack [MAC_SAR_THREAD_STACK_SIZE];
- cyg_handle_t thread_handle;
- cyg_thread thread;
-
/** Tracing system */
#if CONFIG_TRACE
/** SAR Trace */
diff --git a/cesar/mac/sar/inc/thread.h b/cesar/mac/sar/inc/thread.h
new file mode 100644
index 0000000000..bea39f30a1
--- /dev/null
+++ b/cesar/mac/sar/inc/thread.h
@@ -0,0 +1,51 @@
+#ifndef mac_sar_inc_thread_h
+#define mac_sar_inc_thread_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2011 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file mac/sar/inc/thread.h
+ * \brief Handle the Thread of the SAR.
+ * \ingroup mac_sar
+ */
+#include "common/defs/priority.h"
+#include <cyg/hal/hal_arch.h>
+#include <cyg/kernel/kapi.h>
+#include "mac/sar/sar.h"
+
+/* Thread structure. */
+struct sar_thread_t
+{
+ /** the Thread thread stack. */
+ u8 thread_stack [MAC_SAR_THREAD_STACK_SIZE];
+ /** the Thread handler. */
+ cyg_handle_t thread_handle;
+ /** The Thread. */
+ cyg_thread thread;
+ /** Sar context. */
+ sar_t *sar;
+};
+typedef struct sar_thread_t sar_thread_t;
+
+BEGIN_DECLS
+
+/**
+ * Initialise the sub module.
+ * \param the pointer to the SAR context.
+ */
+void
+sar_thread_init (sar_t *sar);
+
+/**
+ * Uninitialise the thread thread.
+ */
+void
+sar_thread_uninit (void);
+
+END_DECLS
+
+#endif /* mac_sar_inc_thread_h */
diff --git a/cesar/mac/sar/sar.h b/cesar/mac/sar/sar.h
index 7e76d2667d..6939f84b76 100644
--- a/cesar/mac/sar/sar.h
+++ b/cesar/mac/sar/sar.h
@@ -314,13 +314,6 @@ sar_beacon_send (sar_t *sar, pb_beacon_t *beacon, mfs_tx_t *beacon_mfs,
void *bto_bpsto);
/**
- * SAR main loop.
- * \param sar the SAR context.
- */
-void
-sar_launch (sar_t *sar);
-
-/**
* Remove a station from the SAR and the mac store.
* \param ctx the ctx context.
* \param tei the station TEI.
diff --git a/cesar/mac/sar/src/sar.c b/cesar/mac/sar/src/sar.c
index 6a9462add1..735c56fe79 100644
--- a/cesar/mac/sar/src/sar.c
+++ b/cesar/mac/sar/src/sar.c
@@ -27,15 +27,12 @@
#include "mac/sar/inc/sar_expiration.h"
#include "lib/seq_check.h"
#include "mac/sar/inc/sar_pb_stats.h"
+#include "mac/sar/inc/thread.h"
#include "hal/arch/arch.h"
-#include "common/defs/priority.h"
#include "lib/stats.h"
#include <string.h>
-/** Time SAR thread sleeps. */
-#define SAR_THREAD_DELAY_RTC 10
-
/** Define the JOB length for the second job to avoid bridgedma bug see
* maria:#905. */
#define SAR_BRGBUG_SECOND_JOB_LENGTH 16
@@ -530,18 +527,7 @@ sar_init (mac_store_t *mac_store, pbproc_t *pbproc, ca_t *ca, u32 seed)
#endif
lib_rnd_init (&ctx->rnd_gen, seed ^ 0x19257164);
- /* Resume the thread only if the SAR is not in unit test. */
-#ifndef SAR_UNIT_TEST
- /* Create the Thread for the SAR. */
- cyg_thread_create (MAC_SAR_THREAD_PRIORITY,
- &sar_process,
- (cyg_addrword_t) ctx,
- "MAC_SAR",
- ctx->thread_stack,
- MAC_SAR_THREAD_STACK_SIZE,
- &ctx->thread_handle, &ctx->thread);
- cyg_thread_resume (ctx->thread_handle);
-#endif
+ sar_thread_init (ctx);
/* Initialise the TX static job. */
static sar_job_mfs_t job_tx;
sar_global.job_tx = ARCH_CPU_TO_DMA (&job_tx);
@@ -656,10 +642,7 @@ sar_uninit (sar_t *ctx)
#if CONFIG_SAR_PB_STATS
sar_pb_stats_uninit (&ctx->pb_stats);
#endif
-#ifndef SAR_UNIT_TEST
- cyg_thread_suspend (ctx->thread_handle);
- cyg_thread_delete (ctx->thread_handle);
-#endif
+ sar_thread_uninit ();
phy_bridgedma_uninit(ctx->bridgedma_ctx);
sar_trace_uninit (ctx);
}
@@ -1990,28 +1973,6 @@ sar_mfs_cmd_process (sar_t *ctx, mfs_tx_t *mfs)
}
void
-sar_launch (sar_t *ctx)
-{
- dbg_assert (ctx);
- cyg_thread_delay (SAR_THREAD_DELAY_RTC);
- sar_expiration_mfs (ctx);
- if (ctx->pbs_missing_for_pbproc)
- {
- /* Refill the PB pool if missing block were registered. */
- arch_dsr_lock ();
- sar_pb_pool_refill (ctx, 0);
- arch_dsr_unlock ();
- }
-}
-
-void
-sar_process (cyg_addrword_t data)
-{
- while (true)
- sar_launch ((sar_t *) data);
-}
-
-void
sar_init_beacon_cb (sar_t *sar, void *user_data, sar_beacon_cb_t uf)
{
dbg_assert (sar);
diff --git a/cesar/mac/sar/src/thread.c b/cesar/mac/sar/src/thread.c
new file mode 100644
index 0000000000..485eee1a09
--- /dev/null
+++ b/cesar/mac/sar/src/thread.c
@@ -0,0 +1,73 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2011 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file mac/sar/src/thead.c
+ * \brief Handles the Thread process.
+ * \ingroup mac_sar
+ */
+#include "common/std.h"
+#include "mac/sar/inc/sar_context.h"
+#include "mac/sar/inc/sar_expiration.h"
+#include "mac/sar/inc/sar.h"
+#include "mac/sar/inc/thread.h"
+
+/** Time SAR thread sleeps. */
+#define SAR_THREAD_DELAY_RTC 10
+
+/** Global thread context. */
+static sar_thread_t sar_thread_global;
+
+/** Main Thread function.
+ * \data the word to the sar thread context.
+ */
+static void
+sar_thread_process (cyg_addrword_t data)
+{
+ while (true)
+ {
+ sar_thread_t *ctx = (sar_thread_t *) data;
+ dbg_assert (ctx);
+ cyg_thread_delay (SAR_THREAD_DELAY_RTC);
+ sar_expiration_mfs (ctx->sar);
+ if (ctx->sar->pbs_missing_for_pbproc)
+ {
+ /* Refill the PB pool if missing block were registered. */
+ arch_dsr_lock ();
+ sar_pb_pool_refill (ctx->sar, 0);
+ arch_dsr_unlock ();
+ }
+ }
+}
+
+void
+sar_thread_init (sar_t *sar)
+{
+ sar_thread_t *ctx = &sar_thread_global;
+ ctx->sar = sar;
+#ifndef SAR_UNIT_TEST
+ /* Create the Thread for the SAR. */
+ cyg_thread_create (MAC_SAR_THREAD_PRIORITY,
+ &sar_thread_process,
+ (cyg_addrword_t) ctx,
+ "MAC_SAR",
+ ctx->thread_stack,
+ MAC_SAR_THREAD_STACK_SIZE,
+ &ctx->thread_handle, &ctx->thread);
+ cyg_thread_resume (ctx->thread_handle);
+#endif
+}
+
+void
+sar_thread_uninit (void)
+{
+ sar_thread_t *ctx = &sar_thread_global;
+#ifndef SAR_UNIT_TEST
+ cyg_thread_suspend (ctx->thread_handle);
+ cyg_thread_delete (ctx->thread_handle);
+#endif
+}
diff --git a/cesar/mac/sar/stub/src/sar.c b/cesar/mac/sar/stub/src/sar.c
index 4c82ac89dd..49112f34ec 100644
--- a/cesar/mac/sar/stub/src/sar.c
+++ b/cesar/mac/sar/stub/src/sar.c
@@ -76,9 +76,6 @@ sar_beacon_send (sar_t *sar, pb_beacon_t *beacon, mfs_tx_t *beacon_mfs,
void *bto_bpsto) __attribute__((weak));
void
-sar_launch (sar_t *sar) __attribute__((weak));
-
-void
sar_sta_remove (sar_t *ctx, u8 tei) __attribute__((weak));
@@ -169,9 +166,6 @@ sar_beacon_send (sar_t *sar, pb_beacon_t *beacon, mfs_tx_t *beacon_mfs,
void *bto_bpsto) {}
void
-sar_launch (sar_t *sar) {}
-
-void
sar_sta_remove (sar_t *ctx, u8 tei) {}