summaryrefslogtreecommitdiffstats
path: root/mnsl/mns_eh.c
diff options
context:
space:
mode:
authorChristian Gromm <christian.gromm@microchip.com>2016-12-08 13:51:04 +0100
committerChristian Gromm <christian.gromm@microchip.com>2016-12-08 13:51:04 +0100
commit8c5f2324d7aa61669324aec1a0ad091fe1379489 (patch)
tree29cbdcdbe3657e1400d596ec3d560a2573d80817 /mnsl/mns_eh.c
parente89ba11bd9111f02a940f227cf979f1947e975ac (diff)
src: unicens: import sources
This patch adds the source tree of the NetworkManager v3.0.4. Additionally, it provides the needed configuration scripts. Change-Id: I23778b51423b51a4f87741957e0fb208bceb79b3 Signed-off-by: Christian Gromm <christian.gromm@microchip.com>
Diffstat (limited to 'mnsl/mns_eh.c')
-rw-r--r--mnsl/mns_eh.c155
1 files changed, 155 insertions, 0 deletions
diff --git a/mnsl/mns_eh.c b/mnsl/mns_eh.c
new file mode 100644
index 0000000..36e0168
--- /dev/null
+++ b/mnsl/mns_eh.c
@@ -0,0 +1,155 @@
+/*
+ * MOST NetServices "Light" V3.2.7.0.1796 MultiInstance Patch
+ *
+ * Copyright (C) 2015 Microchip Technology Germany II GmbH & Co. KG
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * You may also obtain this software under a propriety license from Microchip.
+ * Please contact Microchip for further information.
+ *
+ */
+
+/*!
+ * \file
+ * \brief Implementation of the event handler.
+ *
+ * \cond MNS_INTERNAL_DOC
+ * \addtogroup G_EH
+ * @{
+ */
+
+/*------------------------------------------------------------------------------------------------*/
+/* Includes */
+/*------------------------------------------------------------------------------------------------*/
+#include "mns_eh.h"
+#include "mns_misc.h"
+
+/*------------------------------------------------------------------------------------------------*/
+/* Internal prototypes */
+/*------------------------------------------------------------------------------------------------*/
+static bool Eh_EncodeEvent(uint32_t event_code, Mns_Error_t *public_error_code_ptr);
+
+/*------------------------------------------------------------------------------------------------*/
+/* Implementation of class CEventHandler */
+/*------------------------------------------------------------------------------------------------*/
+/*! \brief Constructor of the event handler class.
+ * \param self Instance pointer
+ * \param mns_inst_id MOST NetServices instance ID
+ */
+void Eh_Ctor(CEventHandler *self, uint8_t mns_inst_id)
+{
+ MISC_MEM_SET(self, 0, sizeof(*self));
+ /* Save MOST NetServices instance ID */
+ self->mns_inst_id = mns_inst_id;
+ /* Initialize subject for internal events */
+ Sub_Ctor(&self->internal_event_subject, self->mns_inst_id);
+ /* Initialize subject for public error reporting */
+ Ssub_Ctor(&self->public_error_subject, self->mns_inst_id);
+}
+
+/*! \brief Adds an observer which reports public errors
+ * \param self Instance pointer
+ * \param obs_ptr Reference to an observer
+ */
+void Eh_AddObsrvPublicError(CEventHandler *self, CSingleObserver *obs_ptr)
+{
+ (void)Ssub_AddObserver(&self->public_error_subject, obs_ptr);
+}
+
+/*! \brief Removes an observer registered by Eh_AddObsrvPublicError().
+ * \param self Instance pointer
+ */
+void Eh_DelObsrvPublicError(CEventHandler *self)
+{
+ Ssub_RemoveObserver(&self->public_error_subject);
+}
+
+/*! \brief Reports an event to the event handler.
+ * \param self Instance pointer
+ * \param event_code Event code to report
+ */
+void Eh_ReportEvent(CEventHandler *self, uint32_t event_code)
+{
+ Mns_Error_t public_error_code;
+ /* Check if event code exists */
+ if((event_code & EH_M_ALL_EVENTS) != 0U)
+ {
+ /* Encode internal event code */
+ bool result = Eh_EncodeEvent(event_code, &public_error_code);
+ /* Notify all registered observers */
+ Msub_Notify(&self->internal_event_subject, &event_code, event_code);
+ /* Report error to application? */
+ if(result != false)
+ {
+ Ssub_Notify(&self->public_error_subject, &public_error_code, false);
+ }
+ }
+}
+
+/*! \brief Encodes an internal event code. Some internal event codes are mapped to public
+ * error codes.
+ * \param event_code Internal event code to report
+ * \param public_error_code_ptr Returned public error code
+ * \return true if error must be reported to the application, otherwise false
+ */
+static bool Eh_EncodeEvent(uint32_t event_code, Mns_Error_t *public_error_code_ptr)
+{
+ bool ret_val = true;
+
+ /* Translate internal event code into public error code */
+ switch(event_code)
+ {
+ case EH_E_BIST_FAILED:
+ *public_error_code_ptr = MNS_GEN_ERR_INIC;
+ break;
+ case EH_E_UNSYNC_COMPLETE:
+ case EH_E_UNSYNC_FAILED:
+ *public_error_code_ptr = MNS_GEN_ERR_COMMUNICATION;
+ break;
+ default:
+ ret_val = false; /* Do not report this event to application. */
+ break;
+ }
+
+ return ret_val;
+}
+
+/*! \brief Registers an observer on the given event code.
+ * \param self Instance pointer
+ * \param obs_ptr Reference to the masked-observer object
+ */
+void Eh_AddObsrvInternalEvent(CEventHandler *self, CMaskedObserver *obs_ptr)
+{
+ (void)Sub_AddObserver(&self->internal_event_subject, &obs_ptr->parent);
+}
+
+/*! \brief Unregisters the given observer from the given event code.
+ * \param self Instance pointer
+ * \param obs_ptr Reference to the masked-observer object
+ */
+void Eh_DelObsrvInternalEvent(CEventHandler *self, CMaskedObserver *obs_ptr)
+{
+ (void)Sub_RemoveObserver(&self->internal_event_subject, &obs_ptr->parent);
+}
+
+/*!
+ * @}
+ * \endcond
+ */
+
+/*------------------------------------------------------------------------------------------------*/
+/* End of file */
+/*------------------------------------------------------------------------------------------------*/
+