summaryrefslogtreecommitdiff
path: root/cesar/mac/sar/src
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/src
parent051e91123f40c3100f890d295d96361985ee52de (diff)
cesar/mac/sar: move thread behavior to thread files, refs #2813
Diffstat (limited to 'cesar/mac/sar/src')
-rw-r--r--cesar/mac/sar/src/sar.c45
-rw-r--r--cesar/mac/sar/src/thread.c73
2 files changed, 76 insertions, 42 deletions
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
+}