b0b833d175b313d6c19c69e8d920ac26a7f4b837
[apps/agl-service-unicens.git] / ucs2-lib / src / ucs_lldpool.c
1 /*------------------------------------------------------------------------------------------------*/
2 /* UNICENS V2.1.0-3491                                                                            */
3 /* Copyright (c) 2017 Microchip Technology Germany II GmbH & Co. KG.                              */
4 /*                                                                                                */
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.                                                            */
9 /*                                                                                                */
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.                                                   */
14 /*                                                                                                */
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/>.                          */
17 /*                                                                                                */
18 /* You may also obtain this software under a propriety license from Microchip.                    */
19 /* Please contact Microchip for further information.                                              */
20 /*------------------------------------------------------------------------------------------------*/
21
22 /*!
23  * \file
24  * \brief Implementation of LLD Message Pool
25  *
26  * \cond UCS_INTERNAL_DOC
27  * \addtogroup  G_PMF
28  * @{
29  */
30
31 /*------------------------------------------------------------------------------------------------*/
32 /* Includes                                                                                       */
33 /*------------------------------------------------------------------------------------------------*/
34 #include "ucs_lldpool.h"
35 #include "ucs_misc.h"
36 #include "ucs_trace.h"
37
38 /*------------------------------------------------------------------------------------------------*/
39 /* Implementation                                                                                 */
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
45  */
46 void Lldp_Ctor(CLldPool *self, void *owner_ptr, void* ucs_user_ptr)
47 {
48     uint8_t cnt;
49     MISC_MEM_SET(self, 0, sizeof(*self));
50
51     Dl_Ctor(&self->list, ucs_user_ptr);
52
53     for (cnt = 0U; cnt < LLDP_NUM_HANDLES; cnt++)         /* setup LLD Tx handles */
54     {
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);
59     }
60 }
61
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 
65  */
66 void Lldp_ReturnTxToPool(CLldPool *self, Lld_IntTxMsg_t *msg_ptr)
67 {
68     Dl_InsertTail(&self->list, &msg_ptr->node);
69 }
70
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 
74  *          available.
75  */
76 Lld_IntTxMsg_t* Lldp_GetTxFromPool(CLldPool *self)
77 {
78     CDlNode *node_ptr = NULL;
79     Lld_IntTxMsg_t *handle_ptr = NULL;
80
81     node_ptr = Dl_PopHead(&self->list);
82
83     if (node_ptr != NULL)
84     {
85         handle_ptr = (Lld_IntTxMsg_t*)Dln_GetData(node_ptr);
86     }
87
88     return handle_ptr;
89 }
90
91 /*!
92  * @}
93  * \endcond
94  */
95
96 /*------------------------------------------------------------------------------------------------*/
97 /* End of file                                                                                    */
98 /*------------------------------------------------------------------------------------------------*/
99