summaryrefslogtreecommitdiff
path: root/cesar/cp/station/src/station_event_handler.c
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/cp/station/src/station_event_handler.c')
-rw-r--r--cesar/cp/station/src/station_event_handler.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/cesar/cp/station/src/station_event_handler.c b/cesar/cp/station/src/station_event_handler.c
new file mode 100644
index 0000000000..a534a7d7c3
--- /dev/null
+++ b/cesar/cp/station/src/station_event_handler.c
@@ -0,0 +1,76 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}}
+ * \file cp/station/src/station_event_handler.c
+ * \brief a simple event handler
+ * \ingroup cp/station
+ *
+ */
+
+#include "common/std.h"
+
+#include "cp/beacon/beacons.h"
+#include "cp/beacon/inc/beacons_ctx.h"
+#include "cp/beacon/forward.h"
+
+#include "cp/station/inc/station_event_handler.h"
+
+
+static event_t events[EVENT_QUEUE_SIZE];
+static u32 head, tail;
+static cyg_mutex_t mutex_event;
+
+void
+cp_station_initialize_handler()
+{
+ tail = 0;
+ head = 1;
+ cyg_mutex_init(&mutex_event);
+}
+
+
+ev_err_code_t
+cp_station_add_event(const SEM_EVENT_TYPE event_type, const VS_VOIDPTR mme_address)
+{
+ msg_ctx_t *msg_ctx = (msg_ctx_t *)mme_address;
+ ev_err_code_t return_value = EV_QUEUE_FULL;
+
+ #if DEBUG
+ //if(mme_address) dbg_assert ( !msg_check_wrong_mme_const_values (mme_address));
+ if(mme_address) dbg_assert ( !msg_check_wrong_mme_const_values (msg_ctx->buffer));
+ #endif
+cyg_mutex_lock(&mutex_event);
+ if( ((head+1)%EVENT_QUEUE_SIZE) != tail)
+ {
+ events[head].event_type = event_type;
+ //events[head].mme_address = (VS_VOIDPTR) mme_address;
+ events[head].mme_address = (VS_VOIDPTR) msg_ctx;
+ head++;
+ head %= EVENT_QUEUE_SIZE;
+ return_value = EV_OK;
+ }
+cyg_mutex_unlock(&mutex_event);
+ // generate the event
+ cyg_flag_setbits (&station_flag, STATION_FLAG_FSM);
+ return return_value;
+}
+
+
+ev_err_code_t
+cp_station_get_event(event_t *event)
+{
+ if( ((tail+1)%EVENT_QUEUE_SIZE) != head)
+ {
+ tail++;
+ tail %= EVENT_QUEUE_SIZE;
+ event->event_type = events[tail].event_type;
+ event->mme_address = events[tail].mme_address;
+ return EV_OK;
+ }
+ return EV_QUEUE_EMPTY;
+}
+