summaryrefslogtreecommitdiff
path: root/cesar/mac/sar/src/thread.c
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/mac/sar/src/thread.c')
-rw-r--r--cesar/mac/sar/src/thread.c73
1 files changed, 73 insertions, 0 deletions
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
+}