2017-05-05 20:50:34 +02:00
|
|
|
/****************************************************************************
|
2021-03-08 22:39:04 +01:00
|
|
|
* wireless/ieee802154/ieee802154_primitive.c
|
2017-05-05 20:50:34 +02:00
|
|
|
*
|
2024-09-11 09:04:25 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2021-02-19 09:38:00 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2017-05-05 20:50:34 +02:00
|
|
|
*
|
2021-02-19 09:38:00 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2017-05-05 20:50:34 +02:00
|
|
|
*
|
2021-02-19 09:38:00 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2017-05-05 20:50:34 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
2021-05-18 08:59:14 +02:00
|
|
|
#include <assert.h>
|
2021-05-14 04:45:57 +02:00
|
|
|
#include <debug.h>
|
2017-05-05 20:50:34 +02:00
|
|
|
|
|
|
|
#include <nuttx/kmalloc.h>
|
|
|
|
#include <nuttx/wireless/ieee802154/ieee802154_mac.h>
|
|
|
|
|
|
|
|
#include "mac802154.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-04-09 14:46:24 +02:00
|
|
|
/* NOTE: The CONFIG_IEEE802154_PRIMITIVE_IRQRESERVE options is marked as
|
|
|
|
* marked '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-07-16 20:53:01 +02:00
|
|
|
*/
|
|
|
|
|
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
|
2020-04-09 14:46:24 +02:00
|
|
|
* general use. The number of messages in this list is a system
|
|
|
|
* configuration item.
|
2017-05-05 20:50:34 +02:00
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
|
2018-03-31 18:37:34 +02:00
|
|
|
/* Pool of pre-allocated primitive structures */
|
2017-11-01 21:15:21 +01:00
|
|
|
|
2020-04-09 14:46:24 +02:00
|
|
|
static struct ieee802154_priv_primitive_s
|
|
|
|
g_primpool[CONFIG_IEEE802154_PRIMITIVE_PREALLOC];
|
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
|
|
|
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
|
2020-04-09 14:46:24 +02:00
|
|
|
/* Initialize g_primfree, the list of primitive structures that are
|
|
|
|
* available for general use.
|
2017-05-05 20:50:34 +02:00
|
|
|
*/
|
|
|
|
|
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:
|
2020-04-09 14:46:24 +02:00
|
|
|
* A reference to the allocated primitive structure.
|
|
|
|
* All user fields in this structure have been zeroed.
|
|
|
|
* On a failure to allocate, NULL is returned.
|
2017-05-05 20:50:34 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
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
|
2020-02-23 09:50:23 +01:00
|
|
|
* will have to allocate one from the kernel memory pool.
|
2017-05-05 20:50:34 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
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
|
|
|
|
2018-02-06 16:13:16 +01:00
|
|
|
if (prim == NULL)
|
2017-05-05 20:50:34 +02:00
|
|
|
{
|
2018-02-06 16:13:16 +01:00
|
|
|
/* No.. memory not available */
|
2017-05-05 20:50:34 +02:00
|
|
|
|
2018-02-06 16:13:16 +01:00
|
|
|
wlerr("ERROR: Failed to allocate primitive.\n");
|
|
|
|
return NULL;
|
2017-05-05 20:50:34 +02:00
|
|
|
}
|
2018-02-06 16:13:16 +01:00
|
|
|
|
2020-04-09 14:46:24 +02:00
|
|
|
/* Remember that this primitive structure
|
|
|
|
* was dynamically allocated
|
|
|
|
*/
|
2018-02-06 16:13:16 +01:00
|
|
|
|
|
|
|
pool = POOL_PRIMITIVE_DYNAMIC;
|
2017-05-05 20:50:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We have successfully allocated memory from some source.
|
2018-04-01 20:25:30 +02:00
|
|
|
* Zero and tag the allocated 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:
|
2020-04-09 14:46:24 +02:00
|
|
|
* The ieee802154_primitive_free function will return a primitive structure
|
|
|
|
* to the free pool of messages if it was a pre-allocated primitive
|
2017-11-01 21:15:21 +01:00
|
|
|
* 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);
|
2020-04-07 16:31:47 +02:00
|
|
|
kmm_free(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
|
|
|
}
|