2017-05-05 20:50:34 +02:00
|
|
|
/****************************************************************************
|
2017-11-01 21:15:21 +01:00
|
|
|
* wireless/ieee802154/ieee802154_primitive.c
|
2017-05-05 20:50:34 +02:00
|
|
|
*
|
|
|
|
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <nuttx/kmalloc.h>
|
|
|
|
#include <nuttx/wireless/ieee802154/ieee802154_mac.h>
|
|
|
|
|
|
|
|
#include "mac802154.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
/* NOTE: The CONFIG_IEEE802154_PRIMITIVE_IRQRESERVE options is marked as marked
|
2017-07-16 20:53:01 +02:00
|
|
|
* 'experimental' and with the default 0 zero because there are no interrupt
|
|
|
|
* level allocations performed by the current IEEE 802.15.4 MAC code.
|
|
|
|
*/
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
#if !defined(CONFIG_IEEE802154_PRIMITIVE_PREALLOC) || \
|
|
|
|
CONFIG_IEEE802154_PRIMITIVE_PREALLOC < 0
|
|
|
|
# undef CONFIG_IEEE802154_PRIMITIVE_PREALLOC
|
|
|
|
# define CONFIG_IEEE802154_PRIMITIVE_PREALLOC 20
|
2017-05-05 20:50:34 +02:00
|
|
|
#endif
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
#if !defined(CONFIG_IEEE802154_PRIMITIVE_IRQRESERVE) || \
|
|
|
|
CONFIG_IEEE802154_PRIMITIVE_IRQRESERVE < 0
|
|
|
|
# undef CONFIG_IEEE802154_PRIMITIVE_IRQRESERVE
|
|
|
|
# define CONFIG_IEEE802154_PRIMITIVE_IRQRESERVE 0
|
2017-05-05 20:50:34 +02:00
|
|
|
#endif
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
#if CONFIG_IEEE802154_PRIMITIVE_IRQRESERVE > CONFIG_IEEE802154_PRIMITIVE_PREALLOC
|
|
|
|
# undef CONFIG_IEEE802154_PRIMITIVE_IRQRESERVE
|
|
|
|
# define CONFIG_IEEE802154_PRIMITIVE_IRQRESERVE CONFIG_IEEE802154_PRIMITIVE_PREALLOC
|
2017-05-05 20:50:34 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Memory Pools */
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
#define POOL_PRIMITIVE_GENERAL 0
|
|
|
|
#define POOL_PRIMITIVE_IRQ 1
|
|
|
|
#define POOL_PRIMITIVE_DYNAMIC 2
|
2017-05-05 20:50:34 +02:00
|
|
|
|
2017-05-05 23:12:26 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
/* Private data type that extends the ieee802154_primitive_s struct */
|
2017-05-05 23:12:26 +02:00
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
struct ieee802154_priv_primitive_s
|
2017-05-05 23:12:26 +02:00
|
|
|
{
|
|
|
|
/* Must be first member so we can cast to/from */
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
struct ieee802154_primitive_s pub;
|
|
|
|
FAR struct ieee802154_priv_primitive_s *flink;
|
2017-05-05 23:12:26 +02:00
|
|
|
uint8_t pool;
|
|
|
|
};
|
|
|
|
|
2017-05-05 20:50:34 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
#if CONFIG_IEEE802154_PRIMITIVE_PREALLOC > 0
|
|
|
|
#if CONFIG_IEEE802154_PRIMITIVE_PREALLOC > CONFIG_IEEE802154_PRIMITIVE_IRQRESERVE
|
|
|
|
/* The g_primfree is a list of primitive structures that are available for
|
2017-05-05 20:50:34 +02:00
|
|
|
* general use. The number of messages in this list is a system configuration
|
|
|
|
* item.
|
|
|
|
*/
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
static struct ieee802154_priv_primitive_s *g_primfree;
|
2017-05-05 20:50:34 +02:00
|
|
|
#endif
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
#if CONFIG_IEEE802154_PRIMITIVE_IRQRESERVE > 0
|
|
|
|
/* The g_primfree_irq is a list of primitive structures that are reserved for
|
2017-05-05 20:50:34 +02:00
|
|
|
* use by only by interrupt handlers.
|
|
|
|
*/
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
static struct ieee802154_priv_primitive_s *g_primfree_irq;
|
2017-05-05 20:50:34 +02:00
|
|
|
#endif
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
/* Pool of pre-allocated primitive stuctures */
|
|
|
|
|
|
|
|
static struct ieee802154_priv_primitive_s g_primpool[CONFIG_IEEE802154_PRIMITIVE_PREALLOC];
|
|
|
|
#endif /* CONFIG_IEEE802154_PRIMITIVE_PREALLOC > 0 */
|
2017-05-05 20:50:34 +02:00
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
static bool g_poolinit = false;
|
2017-05-05 20:50:34 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-11-01 21:15:21 +01:00
|
|
|
* Name: ieee802154_primitivepool_initialize
|
2017-05-05 20:50:34 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2017-11-01 21:15:21 +01:00
|
|
|
* This function initializes the primitive allocator. This function must
|
2017-05-05 20:50:34 +02:00
|
|
|
* be called early in the initialization sequence before any radios
|
|
|
|
* begin operation.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2017-05-05 20:50:34 +02:00
|
|
|
* None
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2017-05-05 20:50:34 +02:00
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
void ieee802154_primitivepool_initialize(void)
|
2017-05-05 20:50:34 +02:00
|
|
|
{
|
2017-11-01 21:15:21 +01:00
|
|
|
/* Only allow the pool to be initialized once */
|
|
|
|
|
|
|
|
if (g_poolinit)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2017-05-05 20:50:34 +02:00
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
g_poolinit = true;
|
|
|
|
|
|
|
|
#if CONFIG_IEEE802154_PRIMITIVE_PREALLOC > 0
|
|
|
|
FAR struct ieee802154_priv_primitive_s *pool = g_primpool;
|
|
|
|
int remaining = CONFIG_IEEE802154_PRIMITIVE_PREALLOC;
|
|
|
|
|
|
|
|
#if CONFIG_IEEE802154_PRIMITIVE_PREALLOC > CONFIG_IEEE802154_PRIMITIVE_IRQRESERVE
|
|
|
|
/* Initialize g_primfree, thelist of primitive structures that are available
|
2017-05-05 20:50:34 +02:00
|
|
|
* for general use.
|
|
|
|
*/
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
g_primfree = NULL;
|
|
|
|
while (remaining > CONFIG_IEEE802154_PRIMITIVE_IRQRESERVE)
|
2017-05-05 20:50:34 +02:00
|
|
|
{
|
2017-11-01 21:15:21 +01:00
|
|
|
FAR struct ieee802154_priv_primitive_s *prim = pool;
|
2017-05-05 20:50:34 +02:00
|
|
|
|
|
|
|
/* Add the next meta data structure from the pool to the list of
|
|
|
|
* general structures.
|
|
|
|
*/
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
prim->flink = g_primfree;
|
|
|
|
g_primfree = prim;
|
2017-05-05 20:50:34 +02:00
|
|
|
|
|
|
|
/* Set up for the next structure from the pool */
|
|
|
|
|
|
|
|
pool++;
|
|
|
|
remaining--;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
#if CONFIG_IEEE802154_PRIMITIVE_IRQRESERVE > 0
|
|
|
|
/* Initialize g_primfree_irq is a list of primitive structures reserved for
|
2017-05-05 20:50:34 +02:00
|
|
|
* use by only by interrupt handlers.
|
|
|
|
*/
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
g_primfree_irq = NULL;
|
2017-05-05 20:50:34 +02:00
|
|
|
while (remaining > 0)
|
|
|
|
{
|
2017-11-01 21:15:21 +01:00
|
|
|
FAR struct ieee802154_priv_primitive_s *prim = pool;
|
2017-05-05 20:50:34 +02:00
|
|
|
|
|
|
|
/* Add the next meta data structure from the pool to the list of
|
|
|
|
* general structures.
|
|
|
|
*/
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
prim->flink = g_primfree_irq;
|
|
|
|
g_primfree_irq = prim;
|
2017-05-05 20:50:34 +02:00
|
|
|
|
|
|
|
/* Set up for the next structure from the pool */
|
|
|
|
|
|
|
|
pool++;
|
|
|
|
remaining--;
|
|
|
|
}
|
|
|
|
#endif
|
2017-11-01 21:15:21 +01:00
|
|
|
#endif /* CONFIG_IEEE802154_PRIMITIVE_PREALLOC > 0 */
|
2017-05-05 20:50:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-11-01 21:15:21 +01:00
|
|
|
* Name: ieee802154_primitive_allocate
|
2017-05-05 20:50:34 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2017-11-01 21:15:21 +01:00
|
|
|
* The ieee802154_primitive_allocate function will get a free primitive
|
2017-05-05 20:50:34 +02:00
|
|
|
* structure for use by the IEEE 802.15.4 MAC.
|
|
|
|
*
|
|
|
|
* Interrupt handling logic will first attempt to allocate from the
|
2017-11-01 21:15:21 +01:00
|
|
|
* g_primfree list. If that list is empty, it will attempt to allocate
|
|
|
|
* from its reserve, g_primfree_irq. If that list is empty, then the
|
2017-05-05 20:50:34 +02:00
|
|
|
* allocation fails (NULL is returned).
|
|
|
|
*
|
2017-11-01 21:15:21 +01:00
|
|
|
* Non-interrupt handler logic will attempt to allocate from g_primfree
|
|
|
|
* list. If that the list is empty, then the primitive structure will be
|
2017-05-05 20:50:34 +02:00
|
|
|
* allocated from the dynamic memory pool.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2017-05-05 20:50:34 +02:00
|
|
|
* None
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2017-11-01 21:15:21 +01:00
|
|
|
* A reference to the allocated primitive structure. All user fields in this
|
2017-05-05 20:50:34 +02:00
|
|
|
* structure have been zeroed. On a failure to allocate, NULL is
|
|
|
|
* returned.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
FAR struct ieee802154_primitive_s *ieee802154_primitive_allocate(void)
|
2017-05-05 20:50:34 +02:00
|
|
|
{
|
2017-11-01 21:15:21 +01:00
|
|
|
#if CONFIG_IEEE802154_PRIMITIVE_PREALLOC > 0
|
|
|
|
FAR struct ieee802154_priv_primitive_s *prim;
|
2017-05-05 20:50:34 +02:00
|
|
|
irqstate_t flags;
|
|
|
|
uint8_t pool;
|
|
|
|
|
|
|
|
/* If we were called from an interrupt handler, then try to get the meta-
|
|
|
|
* data structure from generally available list of messages. If this fails,
|
|
|
|
* then try the list of messages reserved for interrupt handlers
|
|
|
|
*/
|
|
|
|
|
|
|
|
flags = enter_critical_section(); /* Always necessary in SMP mode */
|
|
|
|
if (up_interrupt_context())
|
|
|
|
{
|
2017-11-01 21:15:21 +01:00
|
|
|
#if CONFIG_IEEE802154_PRIMITIVE_PREALLOC > CONFIG_IEEE802154_PRIMITIVE_IRQRESERVE
|
2017-05-05 20:50:34 +02:00
|
|
|
/* Try the general free list */
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
if (g_primfree != NULL)
|
2017-05-05 20:50:34 +02:00
|
|
|
{
|
2017-11-01 21:15:21 +01:00
|
|
|
prim = g_primfree;
|
|
|
|
g_primfree = prim->flink;
|
2017-05-05 20:50:34 +02:00
|
|
|
|
|
|
|
leave_critical_section(flags);
|
2017-11-01 21:15:21 +01:00
|
|
|
pool = POOL_PRIMITIVE_GENERAL;
|
2017-05-05 20:50:34 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
2017-11-01 21:15:21 +01:00
|
|
|
#if CONFIG_IEEE802154_PRIMITIVE_IRQRESERVE > 0
|
2017-05-05 20:50:34 +02:00
|
|
|
/* Try the list list reserved for interrupt handlers */
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
if (g_primfree_irq != NULL)
|
2017-05-05 20:50:34 +02:00
|
|
|
{
|
2017-11-01 21:15:21 +01:00
|
|
|
prim = g_primfree_irq;
|
|
|
|
g_primfree_irq = prim->flink;
|
2017-05-05 20:50:34 +02:00
|
|
|
|
|
|
|
leave_critical_section(flags);
|
2017-11-01 21:15:21 +01:00
|
|
|
pool = POOL_PRIMITIVE_IRQ;
|
2017-05-05 20:50:34 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
leave_critical_section(flags);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We were not called from an interrupt handler. */
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
2017-11-01 21:15:21 +01:00
|
|
|
#if CONFIG_IEEE802154_PRIMITIVE_PREALLOC > CONFIG_IEEE802154_PRIMITIVE_IRQRESERVE
|
2017-05-05 20:50:34 +02:00
|
|
|
/* Try the general free list */
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
if (g_primfree != NULL)
|
2017-05-05 20:50:34 +02:00
|
|
|
{
|
2017-11-01 21:15:21 +01:00
|
|
|
prim = g_primfree;
|
|
|
|
g_primfree = prim->flink;
|
2017-05-05 20:50:34 +02:00
|
|
|
|
|
|
|
leave_critical_section(flags);
|
2017-11-01 21:15:21 +01:00
|
|
|
pool = POOL_PRIMITIVE_GENERAL;
|
2017-05-05 20:50:34 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2017-11-01 21:15:21 +01:00
|
|
|
/* If we cannot a primitive structure from the free list, then we
|
2017-05-05 20:50:34 +02:00
|
|
|
* will have to allocate one from the kernal memory pool.
|
|
|
|
*/
|
|
|
|
|
|
|
|
leave_critical_section(flags);
|
2017-11-01 21:15:21 +01:00
|
|
|
prim = (FAR struct ieee802154_priv_primitive_s *)
|
|
|
|
kmm_malloc((sizeof (struct ieee802154_priv_primitive_s)));
|
2017-05-05 20:50:34 +02:00
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
/* Check if we allocated the primitive structure */
|
2017-05-05 20:50:34 +02:00
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
if (prim != NULL)
|
2017-05-05 20:50:34 +02:00
|
|
|
{
|
2017-11-01 21:15:21 +01:00
|
|
|
/* Yes... remember that this primitive structure was dynamically allocated */
|
2017-05-05 20:50:34 +02:00
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
pool = POOL_PRIMITIVE_DYNAMIC;
|
2017-05-05 20:50:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We have successfully allocated memory from some source.
|
2017-11-01 21:15:21 +01:00
|
|
|
* Zero and tag the alloated primitive structure.
|
2017-05-05 20:50:34 +02:00
|
|
|
*/
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
prim->pool = pool;
|
|
|
|
memset(&prim->pub, 0, sizeof(struct ieee802154_primitive_s));
|
2017-05-05 23:12:26 +02:00
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
wlinfo("Primitive allocated: %p\n", prim);
|
|
|
|
return &prim->pub;
|
2017-05-05 20:50:34 +02:00
|
|
|
#else
|
|
|
|
return NULL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-11-01 21:15:21 +01:00
|
|
|
* Name: ieee802154_primitive_free
|
2017-05-05 20:50:34 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2017-11-01 21:15:21 +01:00
|
|
|
* The ieee802154_primitive_free function will return a primitive structure to
|
|
|
|
* the free pool of messages if it was a pre-allocated primitive
|
|
|
|
* structure. If the primitive structure was allocated dynamically it will
|
2017-05-05 20:50:34 +02:00
|
|
|
* be deallocated.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2017-11-01 21:15:21 +01:00
|
|
|
* prim - primitive structure to free
|
2017-05-05 20:50:34 +02:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2017-05-05 20:50:34 +02:00
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
void ieee802154_primitive_free(FAR struct ieee802154_primitive_s *prim)
|
2017-05-05 20:50:34 +02:00
|
|
|
{
|
2017-11-01 21:15:21 +01:00
|
|
|
if (--prim->nclients > 0)
|
2017-05-05 23:12:26 +02:00
|
|
|
{
|
2017-11-01 21:15:21 +01:00
|
|
|
wlinfo("Remaining Clients: %d\n", prim->nclients);
|
|
|
|
return;
|
2017-05-05 23:12:26 +02:00
|
|
|
}
|
2017-05-05 20:50:34 +02:00
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
#if CONFIG_IEEE802154_PRIMITIVE_PREALLOC > 0
|
|
|
|
irqstate_t flags;
|
|
|
|
FAR struct ieee802154_priv_primitive_s *priv =
|
|
|
|
(FAR struct ieee802154_priv_primitive_s *)prim;
|
|
|
|
|
|
|
|
#if CONFIG_IEEE802154_PRIMITIVE_PREALLOC > CONFIG_IEEE802154_PRIMITIVE_IRQRESERVE
|
|
|
|
/* If this is a generally available pre-allocated primitive structure,
|
2017-05-05 20:50:34 +02:00
|
|
|
* then just put it back in the free list.
|
|
|
|
*/
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
if (priv->pool == POOL_PRIMITIVE_GENERAL)
|
2017-05-05 20:50:34 +02:00
|
|
|
{
|
|
|
|
/* Make sure we avoid concurrent access to the free
|
|
|
|
* list from interrupt handlers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
2017-11-01 21:15:21 +01:00
|
|
|
priv->flink = g_primfree;
|
|
|
|
g_primfree = priv;
|
2017-05-05 20:50:34 +02:00
|
|
|
leave_critical_section(flags);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
#if CONFIG_IEEE802154_PRIMITIVE_IRQRESERVE > 0
|
|
|
|
/* If this is a primitive structure pre-allocated for interrupts,
|
2017-05-05 20:50:34 +02:00
|
|
|
* then put it back in the correct free list.
|
|
|
|
*/
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
if (priv->pool == POOL_PRIMITIVE_IRQ)
|
2017-05-05 20:50:34 +02:00
|
|
|
{
|
|
|
|
/* Make sure we avoid concurrent access to the free
|
|
|
|
* list from interrupt handlers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
2017-11-01 21:15:21 +01:00
|
|
|
priv->flink = g_primfree_irq;
|
|
|
|
g_primfree_irq = priv;
|
2017-05-05 20:50:34 +02:00
|
|
|
leave_critical_section(flags);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
|
|
|
|
{
|
|
|
|
/* Otherwise, deallocate it. */
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
DEBUGASSERT(priv->pool == POOL_PRIMITIVE_DYNAMIC);
|
2017-05-05 23:12:26 +02:00
|
|
|
sched_kfree(priv);
|
2017-05-05 20:50:34 +02:00
|
|
|
}
|
|
|
|
#endif
|
2017-11-01 21:15:21 +01:00
|
|
|
|
|
|
|
wlinfo("Primitive freed: %p\n", prim);
|
2017-05-05 20:50:34 +02:00
|
|
|
}
|