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 Implementation of LLD Message Pool
26 * \cond UCS_INTERNAL_DOC
31 /*------------------------------------------------------------------------------------------------*/
33 /*------------------------------------------------------------------------------------------------*/
34 #include "ucs_lldpool.h"
36 #include "ucs_trace.h"
38 /*------------------------------------------------------------------------------------------------*/
40 /*------------------------------------------------------------------------------------------------*/
41 /*! \brief Returns an unused LLD Tx message object back to the pool
42 * \param self The instance
43 * \param owner_ptr Assigns messages to the respective FIFO
44 * \param ucs_user_ptr User reference that needs to be passed in every callback function
46 void Lldp_Ctor(CLldPool *self, void *owner_ptr, void* ucs_user_ptr)
49 MISC_MEM_SET(self, 0, sizeof(*self));
51 Dl_Ctor(&self->list, ucs_user_ptr);
53 for (cnt = 0U; cnt < LLDP_NUM_HANDLES; cnt++) /* setup LLD Tx handles */
55 TR_ASSERT(ucs_user_ptr, "[FIFO]", (self->messages[cnt].msg_ptr == NULL) );
56 Dln_Ctor(&self->messages[cnt].node, &self->messages[cnt]);
57 self->messages[cnt].owner_ptr = owner_ptr;
58 Dl_InsertTail(&self->list, &self->messages[cnt].node);
62 /*! \brief Returns an unused LLD Tx message object back to the pool
63 * \param self The instance
64 * \param msg_ptr The unused LLD Tx message object
66 void Lldp_ReturnTxToPool(CLldPool *self, Lld_IntTxMsg_t *msg_ptr)
68 Dl_InsertTail(&self->list, &msg_ptr->node);
71 /*! \brief Allocates an unused LLD Tx message object from the pool
72 * \param self The instance
73 * \return An internal LLD Tx message object or \c NULL if no message object is
76 Lld_IntTxMsg_t* Lldp_GetTxFromPool(CLldPool *self)
78 CDlNode *node_ptr = NULL;
79 Lld_IntTxMsg_t *handle_ptr = NULL;
81 node_ptr = Dl_PopHead(&self->list);
85 handle_ptr = (Lld_IntTxMsg_t*)Dln_GetData(node_ptr);
96 /*------------------------------------------------------------------------------------------------*/
98 /*------------------------------------------------------------------------------------------------*/