1 /*------------------------------------------------------------------------------------------------*/
2 /* UNICENS V2.1.0-3491 */
3 /* Copyright (c) 2017 Microchip Technology Germany II GmbH & Co. KG. */
5 /* This program is free software: you can redistribute it and/or modify */
6 /* it under the terms of the GNU General Public License as published by */
7 /* the Free Software Foundation, either version 2 of the License, or */
8 /* (at your option) any later version. */
10 /* This program is distributed in the hope that it will be useful, */
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
13 /* GNU General Public License for more details. */
15 /* You should have received a copy of the GNU General Public License */
16 /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 /* You may also obtain this software under a propriety license from Microchip. */
19 /* Please contact Microchip for further information. */
20 /*------------------------------------------------------------------------------------------------*/
24 * \brief Internal header file of class CPmFifos
26 * \cond UCS_INTERNAL_DOC
27 * \addtogroup G_PMFIFOS
34 /*------------------------------------------------------------------------------------------------*/
36 /*------------------------------------------------------------------------------------------------*/
37 #include "ucs_rules.h"
39 #include "ucs_pmfifo.h"
40 #include "ucs_pmchannel.h"
47 /*------------------------------------------------------------------------------------------------*/
49 /*------------------------------------------------------------------------------------------------*/
50 #define FIFOS_SYNC_TIMEOUT 50U /*!< \brief Synchronization timeout in milliseconds */
51 #define FIFOS_SYNC_RETRIES 40U /*!< \brief Maximum number of synchronization retries after timeout */
52 #define FIFOS_UNSYNC_TIMEOUT 200U /*!< \brief Un-synchronization timeout in milliseconds */
53 #define FIFOS_UNSYNC_RETRIES 0U /*!< \brief Un-synchronization retries */
55 /*------------------------------------------------------------------------------------------------*/
57 /*------------------------------------------------------------------------------------------------*/
58 /*! \brief The synchronization status of all FIFOs */
59 typedef enum Fifos_SyncState_
61 FIFOS_S_UNSYNCED, /*!< \brief Not all FIFOs are synchronized */
62 FIFOS_S_SYNCING, /*!< \brief FIFOs synchronization has started */
63 FIFOS_S_SYNCED, /*!< \brief All FIFOs are synchronized */
64 FIFOS_S_UNSYNCING /*!< \brief FIFOs un-synchronization has started */
68 /*! \brief PMS Events */
69 typedef enum Fifos_Event_
71 FIFOS_EV_SYNC_LOST = 0, /*!< \brief Synchronization of at least one FIFO is lost */
72 FIFOS_EV_SYNC_ESTABLISHED = 1, /*!< \brief Synchronization of all FIFOs is established */
73 FIFOS_EV_SYNC_FAILED = 2, /*!< \brief The initial synchronization of FIFOs failed */
74 FIFOS_EV_UNSYNC_COMPLETE = 3, /*!< \brief Un-synchronization of all FIFOs has succeeded */
75 FIFOS_EV_UNSYNC_FAILED = 4 /*!< \brief Un-synchronization of all FIFOs has failed */
79 /*! \brief The class CPmFifos*/
80 typedef struct CPmFifos_
82 CBase *base_ptr; /*!< \brief Reference to base object */
83 uint8_t ucs_inst_id; /*!< \brief UNICENS instance ID */
84 CPmChannel *channel_ptr; /*!< \brief UNICENS instance ID */
86 CPmFifo *fifos[PMP_MAX_NUM_FIFOS]; /*!< \brief Reference to assigned FIFOs */
88 CObserver obs_icm; /*!< \brief Observes ICM synchronization state */
89 CObserver obs_rcm; /*!< \brief Observes ICM synchronization state */
90 CObserver obs_mcm; /*!< \brief Observes MCM synchronization state */
91 Fifos_SyncState_t state; /*!< \brief The Overall synchronization state */
92 uint8_t sync_cnt; /*!< \brief The current count of synchronization command */
94 uint8_t cmd_retries; /*!< \brief The number of sync/un-sync retries */
95 uint16_t cmd_timeout; /*!< \brief The the timeout to retry sync/un-sync */
96 bool unsync_initial; /*!< \brief Specifies if un-sync complete shall un-initialize the channel */
98 CSubject event_subject; /*!< \brief Subject to report synchronization result */
99 CTimer init_timer; /*!< \brief Timer elapses on synchronization timeout */
103 /*------------------------------------------------------------------------------------------------*/
104 /* Function prototypes */
105 /*------------------------------------------------------------------------------------------------*/
106 extern void Fifos_Ctor(CPmFifos *self, CBase *base_ptr, CPmChannel *channel_ptr, CPmFifo *icm_fifo_ptr, CPmFifo *mcm_fifo_ptr, CPmFifo *rcm_fifo_ptr);
107 extern void Fifos_AddEventObserver(CPmFifos *self, CObserver *obs_ptr);
108 extern void Fifos_RemoveEventObserver(CPmFifos *self, CObserver *obs_ptr);
109 extern void Fifos_Synchronize(CPmFifos *self, bool reset_cnt, bool force_sync);
110 extern void Fifos_Unsynchronize(CPmFifos *self, bool reset_cnt, bool initial);
111 extern void Fifos_ForceTermination(CPmFifos *self);
112 extern void Fifos_ConfigureSyncParams(CPmFifos *self, uint8_t retries, uint16_t timeout);
118 #endif /* UCS_PMFIFOS_H */
125 /*------------------------------------------------------------------------------------------------*/
127 /*------------------------------------------------------------------------------------------------*/