http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a1481cb2/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/low_power_pwm/low_power_pwm.h ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/low_power_pwm/low_power_pwm.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/low_power_pwm/low_power_pwm.h deleted file mode 100644 index f8175bb..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/low_power_pwm/low_power_pwm.h +++ /dev/null @@ -1,176 +0,0 @@ -/* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved. - * - * The information contained herein is property of Nordic Semiconductor ASA. - * Terms and conditions of usage are described in detail in NORDIC - * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. - * - * Licensees are granted free, non-transferable use of the information. NO - * WARRANTY of ANY KIND is provided. This heading must NOT be removed from - * the file. - * - */ - - /** @file - * - * @defgroup low_power_pwm Low-power PWM - * @{ - * @ingroup app_common - * - * @brief Module for generating a low-power pulse-width modulated output signal. - * - * This module provides a low-power PWM implementation using app_timers and GPIO. - * - * Each low-power PWM instance utilizes one app_timer. This means it runs on RTC - * and does not require HFCLK to be running. There can be any number of output - * channels per instance. - */ - -#ifndef LOW_POWER_PWM_H__ -#define LOW_POWER_PWM_H__ - -#include <stdbool.h> -#include <stdint.h> -#include "app_timer.h" -#include "nrf_drv_common.h" -#include "sdk_errors.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Event types. - */ -typedef enum -{ - LOW_POWER_PWM_EVENT_PERIOD = 0, - LOW_POWER_PWM_EVENT_DUTY_CYCLE -}low_power_pwm_evt_type_t; - -/**@brief Application time-out handler type. */ -typedef void (*low_power_pwm_timeout_user)(void * p_context, low_power_pwm_evt_type_t evt_type); - -/** - * @brief Structure holding the initialization parameters. - */ -typedef struct -{ - bool active_high; /**< Activate negative polarity. */ - uint8_t period; /**< Width of the low_power_pwm period. */ - uint32_t bit_mask; /**< Pins to be initialized. */ - app_timer_id_t const * p_timer_id; /**< Pointer to the timer ID of low_power_pwm. */ -} low_power_pwm_config_t; - - -/** - * @name Default settings - * @{ - * - * @brief Default parameters for the @ref low_power_pwm_config_t structure. - * - */ -#define LOW_POWER_PWM_CONFIG_ACTIVE_HIGH false -#define LOW_POWER_PWM_CONFIG_PERIOD UINT8_MAX -#define LOW_POWER_PWM_CONFIG_BIT_MASK(mask) (mask) -/** @} */ - -/** - * @brief Low-power PWM default configuration. - */ -#define LOW_POWER_PWM_DEFAULT_CONFIG(mask) \ -{ \ - .active_high = LOW_POWER_PWM_CONFIG_ACTIVE_HIGH , \ - .period = LOW_POWER_PWM_CONFIG_PERIOD , \ - .bit_mask = LOW_POWER_PWM_CONFIG_BIT_MASK(mask) \ -} -/** - * @cond (NODOX) - * @defgroup low_power_pwm_internal Auxiliary internal types declarations - * @brief Module for internal usage inside the library only. - * @details These definitions are available to the user, but they should not - * be accessed directly. Use @ref low_power_pwm_duty_set instead. - * @{ - * - */ - - /** - * @brief Structure holding parameters of a given low-power PWM instance. - */ - struct low_power_pwm_s - { - bool active_high; /**< Activate negative polarity. */ - bool led_is_on; /**< Indicates the current state of the LED. */ - uint8_t period; /**< Width of the low_power_pwm period. */ - uint8_t duty_cycle; /**< Width of high pulse. */ - nrf_drv_state_t pwm_state; /**< Indicates the current state of the PWM instance. */ - uint32_t bit_mask; /**< Pins to be initialized. */ - uint32_t bit_mask_toggle; /**< Pins to be toggled. */ - uint32_t timeout_ticks; /**< Value to start the next app_timer. */ - low_power_pwm_evt_type_t evt_type; /**< Slope that triggered time-out. */ - app_timer_timeout_handler_t handler; /**< User handler to be called in the time-out handler. */ - app_timer_id_t const * p_timer_id; /**< Pointer to the timer ID of low_power_pwm. */ - }; - -/** @} - * @endcond - */ - -/** - * @brief Internal structure holding parameters of a low-power PWM instance. - */ -typedef struct low_power_pwm_s low_power_pwm_t; - - -/** - * @brief Function for initializing a low-power PWM instance. - * - * @param[in] p_pwm_instance Pointer to the instance to be started. - * @param[in] p_pwm_config Pointer to the configuration structure. - * @param[in] handler User function to be called in case of time-out. - * - * @return Values returned by @ref app_timer_create. - */ -ret_code_t low_power_pwm_init(low_power_pwm_t * p_pwm_instance, low_power_pwm_config_t const * p_pwm_config, app_timer_timeout_handler_t handler); - - -/** - * @brief Function for starting a low-power PWM instance. - * - * @param[in] p_pwm_instance Pointer to the instance to be started. - * @param[in] leds_pin_bit_mask Bit mask of pins to be started. - * - * @return Values returned by @ref app_timer_start. - */ -ret_code_t low_power_pwm_start(low_power_pwm_t * p_pwm_instance, - uint32_t leds_pin_bit_mask); - -/** - * @brief Function for stopping a low-power PWM instance. - * - * @param[in] p_pwm_instance Pointer to the instance to be stopped. - * - * @return Values returned by @ref app_timer_stop. - */ -ret_code_t low_power_pwm_stop(low_power_pwm_t * p_pwm_instance); - - -/** - * @brief Function for setting a new high pulse width for a given instance. - * - * This function can be called from the timer handler. - * - * @param[in] p_pwm_instance Pointer to the instance to be changed. - * @param[in] duty_cycle New high pulse width. 0 means that the LED is always off. 255 means that it is always on. - * - * @retval NRF_SUCCESS If the function completed successfully. - * @retval NRF_ERROR_INVALID_PARAM If the function returned an error because of invalid parameters. - */ -ret_code_t low_power_pwm_duty_set(low_power_pwm_t * p_pwm_instance, uint8_t duty_cycle); - -#ifdef __cplusplus -} -#endif - -#endif // LOW_POWER_PWM_H__ - -/** @} */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a1481cb2/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/mailbox/app_mailbox.c ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/mailbox/app_mailbox.c b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/mailbox/app_mailbox.c deleted file mode 100644 index b4f3b43..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/mailbox/app_mailbox.c +++ /dev/null @@ -1,152 +0,0 @@ -/* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved. - * - * The information contained herein is property of Nordic Semiconductor ASA. - * Terms and conditions of usage are described in detail in NORDIC - * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. - * - * Licensees are granted free, non-transferable use of the information. NO - * WARRANTY of ANY KIND is provided. This heading must NOT be removed from - * the file. - * - */ -#include <stddef.h> -#include <string.h> -#include "app_mailbox.h" -#include "nrf_error.h" -#include "app_util_platform.h" -#include "app_util.h" -#include "nrf_assert.h" - -ret_code_t app_mailbox_create(const app_mailbox_t * queue_def) -{ - queue_def->p_cb->r_idx = 0; - queue_def->p_cb->w_idx = 0; - queue_def->p_cb->len = 0; - queue_def->p_cb->mode = APP_MAILBOX_MODE_NO_OVERFLOW; - - return NRF_SUCCESS; -} - -static __INLINE void dequeue(app_mailbox_cb_t * p_cb, uint8_t queue_sz) -{ - uint8_t r_idx = p_cb->r_idx + 1; - p_cb->len--; - - //Handle index wrapping. - p_cb->r_idx = (r_idx == queue_sz) ? 0 : r_idx; -} - -static __INLINE void enqueue(app_mailbox_cb_t * p_cb, uint8_t queue_sz) -{ - uint8_t w_idx = p_cb->w_idx + 1; - p_cb->len++; - - //Handle index wrapping. - p_cb->w_idx = (w_idx == queue_sz) ? 0 : w_idx; -} - -ret_code_t app_mailbox_put(const app_mailbox_t * p_mailbox, void * p_item) -{ - ASSERT(p_mailbox); - return app_mailbox_sized_put(p_mailbox, p_item, p_mailbox->item_sz); -} - -ret_code_t app_mailbox_sized_put(const app_mailbox_t * p_mailbox, void * p_item, uint16_t size) -{ - ASSERT((uint32_t)p_item>0); - ASSERT(p_mailbox); - uint32_t err_code = NRF_ERROR_INTERNAL; - uint32_t * p_dst = p_mailbox->p_pool; - bool do_put = true; - uint8_t queue_sz = p_mailbox->queue_sz; - uint16_t item_sz = p_mailbox->item_sz; - app_mailbox_cb_t * p_cb = p_mailbox->p_cb; - - CRITICAL_REGION_ENTER(); - - if (p_cb->len == queue_sz) - { - if (p_cb->mode == APP_MAILBOX_MODE_NO_OVERFLOW) - { - do_put = false; - } - else - { - // Remove the oldest element. - dequeue(p_cb, queue_sz); - } - err_code = NRF_ERROR_NO_MEM; - } - else - { - err_code = NRF_SUCCESS; - } - - if (do_put) - { - p_dst = (uint32_t *)((uint32_t)p_dst + (p_cb->w_idx * (item_sz + sizeof(uint32_t)))); - enqueue(p_cb, queue_sz); - - //Put data in mailbox. - *p_dst = (uint32_t)size; - p_dst++; - memcpy(p_dst, p_item, size); - } - - CRITICAL_REGION_EXIT(); - - return err_code; -} - -ret_code_t app_mailbox_get(const app_mailbox_t * p_mailbox, void * p_item) -{ - uint16_t size; - return app_mailbox_sized_get(p_mailbox, p_item, &size); -} - -ret_code_t app_mailbox_sized_get(const app_mailbox_t * p_mailbox, void * p_item, uint16_t * p_size) -{ - ASSERT(p_mailbox); - ASSERT((uint32_t)p_item>0); - uint32_t * p_src = p_mailbox->p_pool; - ret_code_t err_code = NRF_SUCCESS; - uint16_t item_sz = p_mailbox->item_sz; - uint8_t queue_sz = p_mailbox->queue_sz; - app_mailbox_cb_t * p_cb = p_mailbox->p_cb; - - CRITICAL_REGION_ENTER(); - - if (p_cb->len == 0) - { - err_code = NRF_ERROR_NO_MEM; - } - else - { - p_src = (void *)((uint32_t)p_src + (p_cb->r_idx * (item_sz + sizeof(uint32_t)))); - dequeue(p_cb, queue_sz); - } - - if (err_code == NRF_SUCCESS) - { - uint16_t size = (uint16_t)*p_src; - *p_size = size; - p_src++; - memcpy(p_item, p_src, size); - } - - CRITICAL_REGION_EXIT(); - - return err_code; -} - -uint32_t app_mailbox_length_get (const app_mailbox_t * p_mailbox) -{ - ASSERT(p_mailbox); - return p_mailbox->p_cb->len; -} - -void app_mailbox_mode_set(const app_mailbox_t * p_mailbox, app_mailbox_overflow_mode_t mode) -{ - ASSERT(p_mailbox); - p_mailbox->p_cb->mode = mode; -} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a1481cb2/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/mailbox/app_mailbox.h ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/mailbox/app_mailbox.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/mailbox/app_mailbox.h deleted file mode 100644 index e663af4..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/mailbox/app_mailbox.h +++ /dev/null @@ -1,151 +0,0 @@ -/* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved. - * - * The information contained herein is property of Nordic Semiconductor ASA. - * Terms and conditions of usage are described in detail in NORDIC - * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. - * - * Licensees are granted free, non-transferable use of the information. NO - * WARRANTY of ANY KIND is provided. This heading must NOT be removed from - * the file. - * - */ - -/** @file - * - * @defgroup app_mailbox Mailbox library - * @{ - * @ingroup app_common - * - * @brief Mailbox for safely queuing items. - * - */ - -#ifndef _APP_MAILBOX_H -#define _APP_MAILBOX_H - -#include <stdint.h> -#include "sdk_errors.h" -#include "app_util.h" -#include "nordic_common.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Supported overflow modes. - */ -typedef enum -{ - APP_MAILBOX_MODE_NO_OVERFLOW, //!< If the mailbox is full, @ref app_mailbox_put does not add a new element. - APP_MAILBOX_MODE_OVERFLOW //!< If the mailbox is full, the oldest element is lost and a new one is added. -} app_mailbox_overflow_mode_t; - -#include "app_mailbox_local.h" - -/** - * @brief Mailbox definition structure. - */ -typedef struct -{ - void * p_pool; /**< Memory array for mail. */ - app_mailbox_cb_t * p_cb; /**< Mailbox handle. */ - uint16_t item_sz; /**< Size of a single item. */ - uint8_t queue_sz; /**< Capacity of the queue. */ -} app_mailbox_t; - -/** - * @brief Macro to statically allocate memory for a given mailbox queue. - */ -#define APP_MAILBOX_DEF(name, QUEUE_SZ, ITEM_SZ) \ -static uint32_t STRING_CONCATENATE(mailbox_items_,name)[(1+CEIL_DIV((ITEM_SZ),4))*(QUEUE_SZ)];\ -static app_mailbox_cb_t STRING_CONCATENATE(mailbox_cb_,name); \ -const app_mailbox_t name = \ - { \ - .p_pool = STRING_CONCATENATE(mailbox_items_,name), \ - .p_cb = STRING_CONCATENATE(&mailbox_cb_,name), \ - .queue_sz = (uint8_t)(QUEUE_SZ), \ - .item_sz = (uint16_t)(ITEM_SZ), \ - } - -/** - * @brief Function for creating a mailbox queue. - * - * This function creates and initializes a mailbox queue. - * - * @param[in] p_mailbox Pointer to the mailbox. - * - * @retval NRF_SUCCESS If the queue was successfully created. - */ -ret_code_t app_mailbox_create(const app_mailbox_t * p_mailbox); - -/** - * @brief Function for putting an item in the mailbox queue. - * - * @param[in] p_mailbox Pointer to the mailbox. - * @param[in] p_item Pointer to the item to be queued. - * - * @retval NRF_SUCCESS If the item was enqueued. - * @retval NRF_ERROR_NO_MEM If the queue is full. - */ -ret_code_t app_mailbox_put (const app_mailbox_t * p_mailbox, void * p_item); - -/** - * @brief Function for putting an item with a specified size in the mailbox queue. - * - * @param[in] p_mailbox Pointer to the mailbox. - * @param[in] p_item Pointer to the item to be queued. - * @param[in] size Size of the item. - * - * @retval NRF_SUCCESS If the item was enqueued. - * @retval NRF_ERROR_NO_MEM If the queue is full. - */ -ret_code_t app_mailbox_sized_put (const app_mailbox_t * p_mailbox, void * p_item, uint16_t size); - -/** - * @brief Function for getting an item from the mailbox queue. - * - * @param[in] p_mailbox Pointer to the mailbox. - * @param[out] p_item Pointer to the output location for the dequeued item. - * - * @retval NRF_SUCCESS If the item was retrieved successfully. - * @retval NRF_ERROR_NO_MEM If the queue is empty. - */ -ret_code_t app_mailbox_get (const app_mailbox_t * p_mailbox, void * p_item); - -/** - * @brief Function for getting an item and its size from the mailbox queue. - * - * @param[in] p_mailbox Pointer to the mailbox. - * @param[out] p_item Pointer to the output location for the dequeued item. - * @param[out] p_size Pointer to the item size. - * - * @retval NRF_SUCCESS If the item was retrieved successfully. - * @retval NRF_ERROR_NO_MEM If the queue is empty. - */ -ret_code_t app_mailbox_sized_get (const app_mailbox_t * p_mailbox, void * p_item, uint16_t * p_size); - -/** - * @brief Function for getting the current length of the mailbox queue. - * - * @param[in] p_mailbox Pointer to the mailbox. - * - * @return Current number of elements in the queue. - * - */ -uint32_t app_mailbox_length_get (const app_mailbox_t * p_mailbox); - -/** - * @brief Function for changing the mode of overflow handling. - * - * @param[in] p_mailbox Pointer to the mailbox. - * @param mode New mode to set. - */ -void app_mailbox_mode_set(const app_mailbox_t * p_mailbox, app_mailbox_overflow_mode_t mode); - -#ifdef __cplusplus -} -#endif - -#endif //_APP_MAILBOX_H -/** @} */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a1481cb2/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/mailbox/app_mailbox_local.h ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/mailbox/app_mailbox_local.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/mailbox/app_mailbox_local.h deleted file mode 100644 index f59f70b..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/mailbox/app_mailbox_local.h +++ /dev/null @@ -1,41 +0,0 @@ -/* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved. - * - * The information contained herein is property of Nordic Semiconductor ASA. - * Terms and conditions of usage are described in detail in NORDIC - * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. - * - * Licensees are granted free, non-transferable use of the information. NO - * WARRANTY of ANY KIND is provided. This heading must NOT be removed from - * the file. - * - */ - -/** - * @cond (NODOX) - * @defgroup app_mailbox_internal Auxiliary internal types declarations - * @{ - * @ingroup app_mailbox - * @internal - * - * @brief Module for internal usage inside the library only - * - * Some definitions must be included in the header file because - * of the way the library is set up. In this way, the are accessible to the user. - * However, any functions and variables defined here may change at any time - * without a warning, so you should not access them directly. - */ - /** - * @brief Mailbox handle used for managing a mailbox queue. - */ - typedef struct - { - uint8_t r_idx; /**< Read index for the mailbox queue. */ - uint8_t w_idx; /**< Write index for the mailbox queue. */ - uint8_t len; /**< Number of elements currently in the mailbox queue. */ - app_mailbox_overflow_mode_t mode; /**< Mode of overflow handling. */ - } app_mailbox_cb_t; - - -/** @} - * @endcond - */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a1481cb2/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/mem_manager/mem_manager.c ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/mem_manager/mem_manager.c b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/mem_manager/mem_manager.c deleted file mode 100644 index 161c78a..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/mem_manager/mem_manager.c +++ /dev/null @@ -1,925 +0,0 @@ -/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved. - * - * The information contained herein is property of Nordic Semiconductor ASA. - * Terms and conditions of usage are described in detail in NORDIC - * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. - * - * Licensees are granted free, non-transferable use of the information. NO - * WARRANTY of ANY KIND is provided. This heading must NOT be removed from - * the file. - * - */ -#include "sdk_config.h" -#include "sdk_common.h" -#include "mem_manager.h" -#include "app_trace.h" -#include "nrf_assert.h" - -/** - * @defgroup mem_manager_log Module's Log Macros - * - * @details Macros used for creating module logs which can be useful in understanding handling - * of events or actions on API requests. These are intended for debugging purposes and - * can be enabled by defining the MEM_MANAGER_ENABLE_LOGS. - * - * @note If ENABLE_DEBUG_LOG_SUPPORT is disabled, having MEM_MANAGER_ENABLE_LOGS has no effect. - * @{ - */ -#if (MEM_MANAGER_ENABLE_LOGS == 1) - -#define MM_LOG app_trace_log /**< Used for logging details. */ -#define MM_ERR app_trace_log /**< Used for logging errors in the module. */ -#define MM_TRC app_trace_log /**< Used for getting trace of execution in the module. */ -#define MM_DUMP app_trace_dump /**< Used for dumping octet information. */ - -#else //MEM_MANAGER_ENABLE_LOGS - -#define MM_DUMP(...) /**< Disables dumping of octet streams. */ -#define MM_LOG(...) /**< Disables detailed logs. */ -#define MM_ERR(...) /**< Disables error logs. */ -#define MM_TRC(...) /**< Disables traces. */ - -#endif //MEM_MANAGER_ENABLE_LOGS -/** @} */ - -#ifdef MEM_MANAGER_ENABLE_DIAGNOSTICS -#if (MEM_MANAGER_DIAGNOSTICS_LOGS_ONLY == 1) -#define MMD_LOG app_trace_log /**< Used for logging diagnostic details. */ -#else -#define MMD_LOG MM_LOG /**< Diagnostoc logs same as other module logs, and depend on definition of MEM_MANAGER_ENABLE_LOGS */ -#endif //MEM_MANAGER_DIAGNOSTICS_LOGS_ONLY -#endif //MEM_MANAGER_ENABLE_DIAGNOSTICS - -/** - * @defgroup memory_manager_mutex_lock_unlock Module's Mutex Lock/Unlock Macros. - * - * @details Macros used to lock and unlock modules. Currently the SDK does not use mutexes but - * framework is provided in case need arises to use an alternative architecture. - * @{ - */ -#define MM_MUTEX_LOCK() SDK_MUTEX_LOCK(m_mm_mutex) /**< Lock module using mutex. */ -#define MM_MUTEX_UNLOCK() SDK_MUTEX_UNLOCK(m_mm_mutex) /**< Unlock module using mutex. */ -/** @} */ - -#undef NULL_PARAM_CHECK -#undef NULL_PARAM_CHECK_VOID -#undef VERIFY_MODULE_INITIALIZED -#undef VERIFY_MODULE_INITIALIZED_VOID -#undef VERIFY_REQUESTED_SIZE -#undef VERIFY_REQUESTED_SIZE_VOID - -#if (MEM_MANAGER_DISABLE_API_PARAM_CHECK == 0) - -/** - * @brief Macro for verifying NULL parameters. - * Returning with an appropriate error code on failure. - * - * @param[in] PARAM Parameter checked for NULL. - * - * @retval (NRF_ERROR_NULL | MEMORY_MANAGER_ERR_BASE) when @ref PARAM is NULL. - */ -#define NULL_PARAM_CHECK(PARAM) \ - if ((PARAM) == NULL) \ - { \ - return (NRF_ERROR_NULL | MEMORY_MANAGER_ERR_BASE); \ - } - -/** - * @brief Macro for verifying NULL parameters are not passed to API and returning on failure. - * - * @param[in] PARAM Parameter checked for NULL. - */ -#define NULL_PARAM_CHECK_VOID(PARAM) \ - if ((PARAM) == NULL) \ - { \ - return; \ - } - - -/** - * @brief Macro for verifying module's initialization status. - * Returning with an appropriate error code on failure. - * - * @retval (NRF_ERROR_INVALID_STATE | MEMORY_MANAGER_ERR_BASE) module is uninitialized. - */ -#define VERIFY_MODULE_INITIALIZED() \ - do \ - { \ - if (!m_module_initialized) \ - { \ - return (NRF_ERROR_INVALID_STATE | MEMORY_MANAGER_ERR_BASE); \ - } \ - } while (0) - -/** - * @brief Macro for verifying module's initialization status and returning on failure. - */ -#define VERIFY_MODULE_INITIALIZED_VOID() \ - do \ - { \ - if (!m_module_initialized) \ - { \ - return; \ - } \ - } while (0) - - -/** - * @brief Macro for verifying requested size of memory does not exceed maximum block - * size supported by the module. Returning with appropriate error code on failure. - * - * @param[in] SIZE Requested size to be allocated. - * - * @retval (NRF_ERROR_INVALID_PARAM | MEMORY_MANAGER_ERR_BASE) if requested size is greater - * than the largest block size managed by the module. - */ -#define VERIFY_REQUESTED_SIZE(SIZE) \ - do \ - { \ - if (((SIZE) == 0) ||((SIZE) > MAX_MEM_SIZE)) \ - { \ - return (NRF_ERROR_INVALID_PARAM | MEMORY_MANAGER_ERR_BASE); \ - } \ - } while (0) - - -/** - * @brief Macro for verifying requested size of memory does not exceed maximum block - * size supported by the module. Returnson failure. - * - * @param[in] SIZE Requested size to be allocated. - */ -#define VERIFY_REQUESTED_SIZE_VOID(SIZE) \ - do \ - { \ - if (((SIZE) == 0) ||((SIZE) > MAX_MEM_SIZE)) \ - { \ - return; \ - } \ - } while (0) - - -/**@} */ -#else //MEM_MANAGER_DISABLE_API_PARAM_CHECK - -#define NULL_PARAM_CHECK(PARAM) -#define VERIFY_MODULE_INITIALIZED() -#define VERIFY_REQUESTED_SIZE(SIZE) - -#endif //MEM_MANAGER_DISABLE_API_PARAM_CHECK - - -/**@brief Setting defualts in case XXSmall block not used by application. */ -#ifndef MEMORY_MANAGER_XXSMALL_BLOCK_COUNT - #define MEMORY_MANAGER_XXSMALL_BLOCK_COUNT 0 - #define MEMORY_MANAGER_XXSMALL_BLOCK_SIZE 0 - #define XXSMALL_BLOCK_START 0 - #define XXSMALL_BLOCK_END 0 - #define XXSMALL_MEMORY_START 0 -#endif // MEMORY_MANAGER_XXSMALL_BLOCK_SIZE - - -/**@brief Setting defualts in case XSmall block not used by application. */ -#ifndef MEMORY_MANAGER_XSMALL_BLOCK_COUNT - #define MEMORY_MANAGER_XSMALL_BLOCK_COUNT 0 - #define MEMORY_MANAGER_XSMALL_BLOCK_SIZE 0 - #define XSMALL_BLOCK_START 0 - #define XSMALL_BLOCK_END 0 - #define XSMALL_MEMORY_START 0 -#endif // MEMORY_MANAGER_XSMALL_BLOCK_SIZE - - -/**@brief Setting defualts in case Small block not used by application. */ -#ifndef MEMORY_MANAGER_SMALL_BLOCK_COUNT - #define MEMORY_MANAGER_SMALL_BLOCK_COUNT 0 - #define MEMORY_MANAGER_SMALL_BLOCK_SIZE 0 - #define SMALL_BLOCK_START 0 - #define SMALL_BLOCK_END 0 - #define SMALL_MEMORY_START 0 -#endif // MEMORY_MANAGER_SMALL_BLOCK_COUNT - - -/**@brief Setting defualts in case Medium block not used by application. */ -#ifndef MEMORY_MANAGER_MEDIUM_BLOCK_COUNT - #define MEMORY_MANAGER_MEDIUM_BLOCK_COUNT 0 - #define MEMORY_MANAGER_MEDIUM_BLOCK_SIZE 0 - #define MEDIUM_BLOCK_START 0 - #define MEDIUM_BLOCK_END 0 - #define MEDIUM_MEMORY_START 0 -#endif // MEMORY_MANAGER_MEDIUM_BLOCK_COUNT - - -/**@brief Setting defualts in case Large block not used by application. */ -#ifndef MEMORY_MANAGER_LARGE_BLOCK_COUNT - #define MEMORY_MANAGER_LARGE_BLOCK_COUNT 0 - #define MEMORY_MANAGER_LARGE_BLOCK_SIZE 0 - #define LARGE_BLOCK_START 0 - #define LARGE_BLOCK_END 0 - #define LARGE_MEMORY_START 0 -#endif // MEMORY_MANAGER_LARGE_BLOCK_COUNT - - -/**@brief Setting defualts in case XLarge block not used by application. */ -#ifndef MEMORY_MANAGER_XLARGE_BLOCK_COUNT - #define MEMORY_MANAGER_XLARGE_BLOCK_COUNT 0 - #define MEMORY_MANAGER_XLARGE_BLOCK_SIZE 0 - #define XLARGE_BLOCK_START 0 - #define XLARGE_BLOCK_END 0 - #define XLARGE_MEMORY_START 0 -#endif // MEMORY_MANAGER_XLARGE_BLOCK_COUNT - - -/**@brief Setting defualts in case XXLarge block not used by application. */ -#ifndef MEMORY_MANAGER_XXLARGE_BLOCK_COUNT - #define MEMORY_MANAGER_XXLARGE_BLOCK_COUNT 0 - #define MEMORY_MANAGER_XXLARGE_BLOCK_SIZE 0 - #define XXLARGE_BLOCK_START 0 - #define XXLARGE_BLOCK_END 0 - #define XXLARGE_MEMORY_START 0 -#endif // MEMORY_MANAGER_XXLARGE_BLOCK_COUNT - - -/**@brief Based on which blocks are defined, MAX_MEM_SIZE is determined. - * - * @note Also, in case none of these are defined, a compile time error is indicated. - */ -#if (MEMORY_MANAGER_XXLARGE_BLOCK_COUNT != 0) - #define MAX_MEM_SIZE MEMORY_MANAGER_XXLARGE_BLOCK_SIZE -#elif (MEMORY_MANAGER_XLARGE_BLOCK_COUNT != 0) - #define MAX_MEM_SIZE MEMORY_MANAGER_XLARGE_BLOCK_SIZE -#elif (MEMORY_MANAGER_LARGE_BLOCK_COUNT != 0) - #define MAX_MEM_SIZE MEMORY_MANAGER_LARGE_BLOCK_SIZE -#elif (MEMORY_MANAGER_MEDIUM_BLOCK_COUNT != 0) - #define MAX_MEM_SIZE MEMORY_MANAGER_MEDIUM_BLOCK_SIZE -#elif (MEMORY_MANAGER_SMALL_BLOCK_COUNT != 0) - #define MAX_MEM_SIZE MEMORY_MANAGER_SMALL_BLOCK_SIZE -#elif (MEMORY_MANAGER_XSMALL_BLOCK_COUNT != 0) - #define MAX_MEM_SIZE MEMORY_MANAGER_XSMALL_BLOCK_SIZE -#elif (MEMORY_MANAGER_XXSMALL_BLOCK_COUNT != 0) - #define MAX_MEM_SIZE MEMORY_MANAGER_XXSMALL_BLOCK_SIZE -#else - #err "One of MEMORY_MANAGER_SMALL_BLOCK_COUNT, MEMORY_MANAGER_MEDIUM_BLOCK_COUNT or \ - or MEMORY_MANAGER_LARGE_BLOCK_COUNT should be defined." -#endif - -/**@brief XXSmall block start index in case XXSmall Block is defined. */ -#ifndef XXSMALL_BLOCK_START -#define XXSMALL_BLOCK_START 0 -#endif // XXSMALL_BLOCK_START - - -/**@brief XSmall block start index in case XSmall Block is defined. */ -#ifndef XSMALL_BLOCK_START -#define XSMALL_BLOCK_START (XXSMALL_BLOCK_START + MEMORY_MANAGER_XXSMALL_BLOCK_COUNT) -#endif // XSMALL_BLOCK_START - - -/**@brief Small block start index in case Small Block is defined. */ -#ifndef SMALL_BLOCK_START -#define SMALL_BLOCK_START (XSMALL_BLOCK_START + MEMORY_MANAGER_XSMALL_BLOCK_COUNT) -#endif // SMALL_BLOCK_START - - -/**@brief Medium block start index in case Medium Block is defined. */ -#ifndef MEDIUM_BLOCK_START -#define MEDIUM_BLOCK_START (SMALL_BLOCK_START + MEMORY_MANAGER_SMALL_BLOCK_COUNT) -#endif // MEDIUM_BLOCK_START - - -/**@brief Large block start index in case Large Block is defined. */ -#ifndef LARGE_BLOCK_START -#define LARGE_BLOCK_START (MEDIUM_BLOCK_START + MEMORY_MANAGER_MEDIUM_BLOCK_COUNT) -#endif // LARGE_BLOCK_START - - -/**@brief XLarge block start index in case XLarge Block is defined. */ -#ifndef XLARGE_BLOCK_START -#define XLARGE_BLOCK_START (LARGE_BLOCK_START + MEMORY_MANAGER_LARGE_BLOCK_COUNT) -#endif // XLARGE_BLOCK_START - -/**@brief XXLarge block start index in case XXLarge Block is defined. */ -#ifndef XXLARGE_BLOCK_START -#define XXLARGE_BLOCK_START (XLARGE_BLOCK_START + MEMORY_MANAGER_XLARGE_BLOCK_COUNT) -#endif //XXLARGE_BLOCK_START - - -/**@brief XXSmall block end index in case XXSmall Block is defined. */ -#ifndef XXSMALL_BLOCK_END -#define XXSMALL_BLOCK_END (XXSMALL_BLOCK_START + MEMORY_MANAGER_XXSMALL_BLOCK_COUNT) -#endif // XXSMALL_BLOCK_END - -/**@brief XSmall block end index in case XSmall Block is defined. */ -#ifndef XSMALL_BLOCK_END -#define XSMALL_BLOCK_END (XSMALL_BLOCK_START + MEMORY_MANAGER_XSMALL_BLOCK_COUNT) -#endif // XSMALL_BLOCK_END - - -/**@brief Small block end index in case Small Block is defined. */ -#ifndef SMALL_BLOCK_END -#define SMALL_BLOCK_END (SMALL_BLOCK_START + MEMORY_MANAGER_SMALL_BLOCK_COUNT) -#endif // SMALL_BLOCK_END - - -/**@brief Medium block end index in case Medium Block is defined. */ -#ifndef MEDIUM_BLOCK_END -#define MEDIUM_BLOCK_END (MEDIUM_BLOCK_START + MEMORY_MANAGER_MEDIUM_BLOCK_COUNT) -#endif // MEDIUM_BLOCK_END - - -/**@brief Large block end index in case Large Block is defined. */ -#ifndef LARGE_BLOCK_END -#define LARGE_BLOCK_END (LARGE_BLOCK_START + MEMORY_MANAGER_LARGE_BLOCK_COUNT) -#endif // LARGE_BLOCK_END - - -/**@brief XLarge block end index in case XLarge Block is defined. */ -#ifndef XLARGE_BLOCK_END -#define XLARGE_BLOCK_END (XLARGE_BLOCK_START + MEMORY_MANAGER_XLARGE_BLOCK_COUNT) -#endif // XLARGE_BLOCK_END - - -/**@brief XXLarge block end index in case XXLarge Block is defined. */ -#ifndef XXLARGE_BLOCK_END -#define XXLARGE_BLOCK_END (XXLARGE_BLOCK_START + MEMORY_MANAGER_XXLARGE_BLOCK_COUNT) -#endif //XXLARGE_BLOCK_END - - -#define XXSMALL_MEMORY_SIZE (MEMORY_MANAGER_XXSMALL_BLOCK_COUNT * MEMORY_MANAGER_XXSMALL_BLOCK_SIZE) -#define XSMALL_MEMORY_SIZE (MEMORY_MANAGER_XSMALL_BLOCK_COUNT * MEMORY_MANAGER_XSMALL_BLOCK_SIZE) -#define SMALL_MEMORY_SIZE (MEMORY_MANAGER_SMALL_BLOCK_COUNT * MEMORY_MANAGER_SMALL_BLOCK_SIZE) -#define MEDIUM_MEMORY_SIZE (MEMORY_MANAGER_MEDIUM_BLOCK_COUNT * MEMORY_MANAGER_MEDIUM_BLOCK_SIZE) -#define LARGE_MEMORY_SIZE (MEMORY_MANAGER_LARGE_BLOCK_COUNT * MEMORY_MANAGER_LARGE_BLOCK_SIZE) -#define XLARGE_MEMORY_SIZE (MEMORY_MANAGER_XLARGE_BLOCK_COUNT * MEMORY_MANAGER_XLARGE_BLOCK_SIZE) -#define XXLARGE_MEMORY_SIZE (MEMORY_MANAGER_XXLARGE_BLOCK_COUNT * MEMORY_MANAGER_XXLARGE_BLOCK_SIZE) - - -/**@brief XXSmall memory start index in case XXSmall Block is defined. */ -#ifndef XXSMALL_MEMORY_START -#define XXSMALL_MEMORY_START 0 -#endif // XXSMALL_MEMORY_START - - -/**@brief XSmall memory start index in case XSmall Block is defined. */ -#ifndef XSMALL_MEMORY_START -#define XSMALL_MEMORY_START (XXSMALL_MEMORY_START + XXSMALL_MEMORY_SIZE) -#endif // XSMALL_MEMORY_START - - -/**@brief Small memory start index in case Small Block is defined. */ -#ifndef SMALL_MEMORY_START -#define SMALL_MEMORY_START (XSMALL_MEMORY_START + XSMALL_MEMORY_SIZE) -#endif // SMALL_MEMORY_START - - -/**@brief Medium memory start index in case Medium Block is defined. */ -#ifndef MEDIUM_MEMORY_START -#define MEDIUM_MEMORY_START (SMALL_MEMORY_START + SMALL_MEMORY_SIZE) -#endif // MEDIUM_MEMORY_START - - -/**@brief Large memory start index in case Large Block is defined. */ -#ifndef LARGE_MEMORY_START -#define LARGE_MEMORY_START (MEDIUM_MEMORY_START + MEDIUM_MEMORY_SIZE) -#endif // LARGE_MEMORY_START - - -/**@brief XLarge memory start index in case XLarge Block is defined. */ -#ifndef XLARGE_MEMORY_START -#define XLARGE_MEMORY_START (LARGE_MEMORY_START + LARGE_MEMORY_SIZE) -#endif // XLARGE_MEMORY_START - - -/**@brief XXLarge memory start index in case XXLarge Block is defined. */ -#ifndef XXLARGE_MEMORY_START -#define XXLARGE_MEMORY_START (XLARGE_MEMORY_START + XLARGE_MEMORY_SIZE) -#endif // XLARGE_MEMORY_START - - -/**@brief Total count of block managed by the module. */ -#define TOTAL_BLOCK_COUNT (MEMORY_MANAGER_XXSMALL_BLOCK_COUNT + \ - MEMORY_MANAGER_XSMALL_BLOCK_COUNT + \ - MEMORY_MANAGER_SMALL_BLOCK_COUNT + \ - MEMORY_MANAGER_MEDIUM_BLOCK_COUNT + \ - MEMORY_MANAGER_LARGE_BLOCK_COUNT + \ - MEMORY_MANAGER_XLARGE_BLOCK_COUNT + \ - MEMORY_MANAGER_XLARGE_BLOCK_COUNT) - - -/**@brief Total memory managed by the module. */ -#define TOTAL_MEMORY_SIZE (XXSMALL_MEMORY_SIZE + \ - XSMALL_MEMORY_SIZE + \ - SMALL_MEMORY_SIZE + \ - MEDIUM_MEMORY_SIZE + \ - LARGE_MEMORY_SIZE + \ - XLARGE_MEMORY_SIZE + \ - XXLARGE_MEMORY_SIZE) - - -#define BLOCK_CAT_COUNT 7 /**< Block category count is 7 (xxsmall, xsmall, small, medium, large, xlarge, xxlarge). Having one of the block count to zero has no impact on this count. */ -#define BLOCK_CAT_XXS 0 /**< Extra Extra Small category identifier. */ -#define BLOCK_CAT_XS 1 /**< Extra Small category identifier. */ -#define BLOCK_CAT_SMALL 2 /**< Small category identifier. */ -#define BLOCK_CAT_MEDIUM 3 /**< Medium category identifier. */ -#define BLOCK_CAT_LARGE 4 /**< Large category identifier. */ -#define BLOCK_CAT_XL 5 /**< Extra Large category identifier. */ -#define BLOCK_CAT_XXL 6 /**< Extra Extra Large category identifier. */ - -#define BITMAP_SIZE 32 /**< Bitmap size for each word used to contain block information. */ -#define BLOCK_BITMAP_ARRAY_SIZE CEIL_DIV(TOTAL_BLOCK_COUNT, BITMAP_SIZE) /**< Determines number of blocks needed for book keeping availability status of all blocks. */ - - -/**@brief Lookup table for maximum memory size per block category. */ -static const uint32_t m_block_size[BLOCK_CAT_COUNT] = -{ - MEMORY_MANAGER_XXSMALL_BLOCK_SIZE, - MEMORY_MANAGER_XSMALL_BLOCK_SIZE, - MEMORY_MANAGER_SMALL_BLOCK_SIZE, - MEMORY_MANAGER_MEDIUM_BLOCK_SIZE, - MEMORY_MANAGER_LARGE_BLOCK_SIZE, - MEMORY_MANAGER_XLARGE_BLOCK_SIZE, - MEMORY_MANAGER_XXLARGE_BLOCK_SIZE -}; - -/**@brief Lookup table for block start index for each block caetgory. */ -static const uint32_t m_block_start[BLOCK_CAT_COUNT] = -{ - XXSMALL_BLOCK_START, - XSMALL_BLOCK_START, - SMALL_BLOCK_START, - MEDIUM_BLOCK_START, - LARGE_BLOCK_START, - XLARGE_BLOCK_START, - XXLARGE_BLOCK_START -}; - -/**@brief Lookup table for last block index for each block category. */ -static const uint32_t m_block_end[BLOCK_CAT_COUNT] = -{ - XXSMALL_BLOCK_END, - XSMALL_BLOCK_END, - SMALL_BLOCK_END, - MEDIUM_BLOCK_END, - LARGE_BLOCK_END, - XLARGE_BLOCK_END, - XXLARGE_BLOCK_END -}; - -/**@brief Lookup table for memory start range for each block category. */ -static const uint32_t m_block_mem_start[BLOCK_CAT_COUNT] = -{ - XXSMALL_MEMORY_START, - XSMALL_MEMORY_START, - SMALL_MEMORY_START, - MEDIUM_MEMORY_START, - LARGE_MEMORY_START, - XLARGE_MEMORY_START, - XXLARGE_MEMORY_START -}; - -static uint8_t m_memory[TOTAL_MEMORY_SIZE]; /**< Memory managed by the module. */ -static uint32_t m_mem_pool[BLOCK_BITMAP_ARRAY_SIZE]; /**< Bitmap used for book-keeping availability of all blocks managed by the module. */ - -#ifdef MEM_MANAGER_ENABLE_DIAGNOSTICS - -/**@brief Lookup table for descriptive strings for each block category. */ -static const char * m_block_desc_str[BLOCK_CAT_COUNT] = -{ - "XXSmall", - "XSmall", - "Small", - "Medium", - "Large", - "XLarge", - "XXLarge" -}; - -/**@brief Table for book keeping smallest size allocated in each block range. */ -static uint32_t m_min_size[BLOCK_CAT_COUNT] = -{ - MEMORY_MANAGER_XXSMALL_BLOCK_SIZE, - MEMORY_MANAGER_XSMALL_BLOCK_SIZE, - MEMORY_MANAGER_SMALL_BLOCK_SIZE, - MEMORY_MANAGER_MEDIUM_BLOCK_SIZE, - MEMORY_MANAGER_LARGE_BLOCK_SIZE, - MEMORY_MANAGER_XLARGE_BLOCK_SIZE, - MEMORY_MANAGER_XXLARGE_BLOCK_SIZE -}; - -/**@brief Table for book keeping largest size allocated in each block range. */ -static uint32_t m_max_size[BLOCK_CAT_COUNT]; - -/**@brief Global pointing to minimum size holder for block type being allocated. */ -static uint32_t * p_min_size; - -/**@brief Global pointing to maximum size holder for block type being allocated. */ -static uint32_t * p_max_size; - -/**@brief Lookup table for count of block available in each block category. */ -static uint32_t m_block_count[BLOCK_CAT_COUNT] = -{ - MEMORY_MANAGER_XXSMALL_BLOCK_COUNT, - MEMORY_MANAGER_XSMALL_BLOCK_COUNT, - MEMORY_MANAGER_SMALL_BLOCK_COUNT, - MEMORY_MANAGER_MEDIUM_BLOCK_COUNT, - MEMORY_MANAGER_LARGE_BLOCK_COUNT, - MEMORY_MANAGER_XLARGE_BLOCK_COUNT, - MEMORY_MANAGER_XXLARGE_BLOCK_COUNT -}; - -#endif // MEM_MANAGER_ENABLE_DIAGNOSTICS - -SDK_MUTEX_DEFINE(m_mm_mutex) /**< Mutex variable. Currently unused, this declaration does not occupy any space in RAM. */ -#if (MEM_MANAGER_DISABLE_API_PARAM_CHECK == 0) -static bool m_module_initialized = false; /**< State indicating if module is initialized or not. */ -#endif // MEM_MANAGER_DISABLE_API_PARAM_CHECK - - -/**@brief Function to get X and Y coordinates. - * - * @details Function to get X and Y co-ordinates for the block identified by index. - * Here, X determines relevant word for the block. Y determines the actual bit in the word. - * - * @param[in] index Identifies the block. - * @param[out] p_x Points to the word that contains the bit representing the block. - * @param[out] p_y Contains the bitnumber in the the word 'X' relevant to the block. - */ -static __INLINE void get_block_coordinates(uint32_t block_index, uint32_t * p_x, uint32_t * p_y) -{ - // Determine position of the block in the bitmap. - // X determines relevant word for the block. Y determines the actual bit in the word. - const uint32_t x = block_index/BITMAP_SIZE; - const uint32_t y = (block_index - x*BITMAP_SIZE); - - (*p_x) = x; - (*p_y) = y; -} - - -/**@brief Initializes the block by setting it to be free. */ -static void block_init (uint32_t block_index) -{ - uint32_t x; - uint32_t y; - - // Determine position of the block in the bitmap. - // X determines relevant word for the block. Y determines the actual bit in the word. - get_block_coordinates(block_index, &x, &y); - - // Set bit related to the block to indicate that the block is free. - SET_BIT(m_mem_pool[x], y); -} - - -/**@brief Function to get the category of the block of size 'size' or block number 'block_index'.*/ -static __INLINE uint32_t get_block_cat(uint32_t size, uint32_t block_index) -{ - for (uint32_t block_cat = 0; block_cat < BLOCK_CAT_COUNT; block_cat++) - { - if (((size != 0) && (size <= m_block_size[block_cat]) && - (m_block_end[block_cat] != m_block_start[block_cat])) || - (block_index < m_block_end[block_cat])) - { - return block_cat; - } - } - - return 0; -} - - -/**@brief Function to get the size of the block number 'block_index'. */ -static __INLINE uint32_t get_block_size(uint32_t block_index) -{ - const uint32_t block_cat = get_block_cat(0, block_index); - - #ifdef MEM_MANAGER_ENABLE_DIAGNOSTICS - p_min_size = &m_min_size[block_cat]; - p_max_size = &m_max_size[block_cat]; - #endif // MEM_MANAGER_ENABLE_DIAGNOSTICS - - return m_block_size[block_cat]; -} - - -/**@brief Function to free the block identified by block number 'block_index'. */ -static bool is_block_free(uint32_t block_index) -{ - uint32_t x; - uint32_t y; - - // Determine position of the block in the bitmap. - // X determines relevant word for the block. Y determines the actual bit in the word. - get_block_coordinates(block_index, &x, &y); - - return IS_SET(m_mem_pool[x], y); -} - - -/**@brief Function to allocate the block identified by block number 'block_index'. */ -static void block_allocate(uint32_t block_index) -{ - uint32_t x; - uint32_t y; - - // Determine position of the block in the bitmap. - // X determines relevant word for the block. Y determines the actual bit in the word. - get_block_coordinates(block_index, &x, &y); - - CLR_BIT(m_mem_pool[x], y); -} - - -uint32_t nrf_mem_init(void) -{ - MM_LOG("[MM]: >> nrf_mem_init.\r\n"); - - SDK_MUTEX_INIT(m_mm_mutex); - - MM_MUTEX_LOCK(); - - uint32_t block_index = 0; - - for(block_index = 0; block_index < TOTAL_BLOCK_COUNT; block_index++) - { - block_init(block_index); - } - -#if (MEM_MANAGER_DISABLE_API_PARAM_CHECK == 0) - m_module_initialized = true; -#endif // MEM_MANAGER_DISABLE_API_PARAM_CHECK - -#ifdef MEM_MANAGER_ENABLE_DIAGNOSTICS - nrf_mem_diagnose(); -#endif // MEM_MANAGER_ENABLE_DIAGNOSTICS - - MM_MUTEX_UNLOCK(); - - MM_LOG("[MM]: << nrf_mem_init.\r\n"); - - return NRF_SUCCESS; -} - - -uint32_t nrf_mem_reserve(uint8_t ** pp_buffer, uint32_t * p_size) -{ - VERIFY_MODULE_INITIALIZED(); - NULL_PARAM_CHECK(pp_buffer); - NULL_PARAM_CHECK(p_size); - - const uint32_t requested_size = (*p_size); - - VERIFY_REQUESTED_SIZE(requested_size); - - MM_LOG("[MM]: >> nrf_mem_reserve, size 0x%04lX.\r\n", requested_size); - - MM_MUTEX_LOCK(); - - const uint32_t block_cat = get_block_cat(requested_size, TOTAL_BLOCK_COUNT); - uint32_t block_index = m_block_start[block_cat]; - uint32_t memory_index = m_block_mem_start[block_cat]; - uint32_t err_code = (NRF_ERROR_NO_MEM | MEMORY_MANAGER_ERR_BASE); - - MM_LOG("[MM]: Start index for the pool = 0x%08lX, total block count 0x%08X\r\n", - block_index, - TOTAL_BLOCK_COUNT); - - for (; block_index < TOTAL_BLOCK_COUNT; block_index++) - { - uint32_t block_size = get_block_size(block_index); - - if (is_block_free(block_index) == true) - { - MM_LOG("[MM]: Reserving block 0x%08lX\r\n", block_index); - - // Search succeeded, found free block. - err_code = NRF_SUCCESS; - - // Allocate block. - block_allocate(block_index); - - (*pp_buffer) = &m_memory[memory_index]; - (*p_size) = block_size; - - #ifdef MEM_MANAGER_ENABLE_DIAGNOSTICS - (*p_min_size) = MIN((*p_min_size), requested_size); - (*p_max_size) = MAX((*p_max_size), requested_size); - #endif // MEM_MANAGER_ENABLE_DIAGNOSTICS - - break; - } - memory_index += block_size; - } - if (err_code != NRF_SUCCESS) - { - MM_LOG ("[MM]: Memory reservation result %d, memory %p, size %d!", - err_code, - (*pp_buffer), - (*p_size)); - - #ifdef MEM_MANAGER_ENABLE_DIAGNOSTICS - nrf_mem_diagnose(); - #endif // MEM_MANAGER_ENABLE_DIAGNOSTICS - } - - MM_MUTEX_UNLOCK(); - - MM_LOG("[MM]: << nrf_mem_reserve %p, result 0x%08lX.\r\n", (*pp_buffer), err_code); - - return err_code; -} - - -void * nrf_malloc(uint32_t size) -{ - uint8_t * buffer = NULL; - uint32_t allocated_size = size; - - uint32_t retval = nrf_mem_reserve(&buffer, &allocated_size); - - if (retval != NRF_SUCCESS) - { - buffer = NULL; - } - - return buffer; -} - - -void * nrf_calloc(uint32_t count, uint32_t size) -{ - uint8_t * buffer = NULL; - uint32_t allocated_size = (size * count); - - MM_LOG ("[nrf_calloc]: Requested size %d, count %d\r\n", allocated_size, count); - - uint32_t retval = nrf_mem_reserve(&buffer,&allocated_size); - if (retval == NRF_SUCCESS) - { - MM_LOG ("[nrf_calloc]: buffer %p, total size %d\r\n", buffer, allocated_size); - memset(buffer,0, allocated_size); - } - else - { - MM_LOG("[nrf_calloc]: Failed to allocate memory %d\r\n", allocated_size); - buffer = NULL; - } - - return buffer; -} - - -void nrf_free(void * p_mem) -{ - VERIFY_MODULE_INITIALIZED_VOID(); - NULL_PARAM_CHECK_VOID(p_mem); - - MM_LOG("[MM]: >> nrf_free %p.\r\n", p_mem); - - MM_MUTEX_LOCK(); - - uint32_t index; - uint32_t memory_index = 0; - - for (index = 0; index < TOTAL_BLOCK_COUNT; index++) - { - if (&m_memory[memory_index] == p_mem) - { - // Found a free block of memory, assign. - MM_LOG("[MM]: << Freeing block %d.\r\n", index); - block_init(index); - break; - } - memory_index += get_block_size(index); - } - - MM_MUTEX_UNLOCK(); - - MM_LOG("[MM]: << nrf_free.\r\n"); - return; -} - - -void * nrf_realloc(void * p_mem, uint32_t size) -{ - return p_mem; -} - - -#ifdef MEM_MANAGER_ENABLE_DIAGNOSTICS - -/**@brief Function to format and print information with respect to each block. - * - * @details Internal function that formats and prints information related to the block category - * identified by 'block_cat'. This function also appends the number of bytes in use to - * p_mem_in_use based on current count of block in the category. - * - * @param[in] block_cat Identifies the category of block. - * @param[out] p_mem_in_use Updates the memory in use based on count in use. - */ -void print_block_info(uint32_t block_cat, uint32_t * p_mem_in_use) -{ - #define PRINT_COLUMN_WIDTH 13 - #define PRINT_BUFFER_SIZE 80 - #define ASCII_VALUE_FOR_SPACE 32 - - char print_buffer[PRINT_BUFFER_SIZE]; - const uint32_t total_count = (m_block_start[block_cat] + m_block_count[block_cat]); - uint32_t in_use = 0; - uint32_t num_of_blocks = 0; - uint32_t index = m_block_start[block_cat]; - uint32_t column_number; - - // No statistic provided in case block category is not included. - if (m_block_count[block_cat] != 0) - { - memset(print_buffer, ASCII_VALUE_FOR_SPACE, PRINT_BUFFER_SIZE); - - for (; index < total_count; index++) - { - if (is_block_free(index) == false) - { - num_of_blocks++; - in_use += m_block_size[block_cat]; - } - } - - column_number = 0; - snprintf(&print_buffer[column_number * PRINT_COLUMN_WIDTH], - PRINT_COLUMN_WIDTH, - "| %s", - m_block_desc_str[block_cat]); - - column_number++; - snprintf(&print_buffer[column_number * PRINT_COLUMN_WIDTH], - PRINT_COLUMN_WIDTH, - "| %d", - m_block_size[block_cat]); - - column_number++; - snprintf(&print_buffer[column_number * PRINT_COLUMN_WIDTH], - PRINT_COLUMN_WIDTH, - "| %d", - m_block_count[block_cat]); - - column_number++; - snprintf(&print_buffer[column_number * PRINT_COLUMN_WIDTH], - PRINT_COLUMN_WIDTH, - "| %d", - num_of_blocks); - - column_number++; - snprintf(&print_buffer[column_number * PRINT_COLUMN_WIDTH], - PRINT_COLUMN_WIDTH, - "| %d", - m_min_size[block_cat]); - - column_number++; - snprintf(&print_buffer[column_number * PRINT_COLUMN_WIDTH], - PRINT_COLUMN_WIDTH, - "| %d", - m_max_size[block_cat]); - - column_number++; - const uint32_t column_end = (column_number * PRINT_COLUMN_WIDTH); - - for (int j = 0; j < column_end; j ++) - { - if (print_buffer[j] == 0) - { - print_buffer[j] = 0x20; - } - } - snprintf(&print_buffer[column_end], 2, "|"); - - MMD_LOG("%s\r\n", print_buffer); - - (*p_mem_in_use) += in_use; - } -} - - -void nrf_mem_diagnose(void) -{ - uint32_t in_use = 0; - - MMD_LOG ("\r\n"); - MMD_LOG ("+------------+------------+------------+------------+------------+------------+\r\n"); - MMD_LOG ("| Block | Size | Total | In Use | Min Alloc | Max Alloc |\r\n"); - MMD_LOG ("+------------+------------+------------+------------+------------+------------+\r\n"); - - print_block_info(BLOCK_CAT_XXS, &in_use); - print_block_info(BLOCK_CAT_XS, &in_use); - print_block_info(BLOCK_CAT_SMALL, &in_use); - print_block_info(BLOCK_CAT_MEDIUM, &in_use); - print_block_info(BLOCK_CAT_LARGE, &in_use); - print_block_info(BLOCK_CAT_XL, &in_use); - print_block_info(BLOCK_CAT_XXL, &in_use); - - MMD_LOG ("+------------+------------+------------+------------+------------+------------+\r\n"); - MMD_LOG ("| Total | %d | %d | %d\r\n", - TOTAL_MEMORY_SIZE, TOTAL_BLOCK_COUNT,in_use); - MMD_LOG ("+------------+------------+------------+------------+------------+------------+\r\n"); -} - -#endif // MEM_MANAGER_ENABLE_DIAGNOSTICS -/** @} */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a1481cb2/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/mem_manager/mem_manager.h ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/mem_manager/mem_manager.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/mem_manager/mem_manager.h deleted file mode 100644 index 5d009ce..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/mem_manager/mem_manager.h +++ /dev/null @@ -1,147 +0,0 @@ -/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved. - * - * The information contained herein is property of Nordic Semiconductor ASA. - * Terms and conditions of usage are described in detail in NORDIC - * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. - * - * Licensees are granted free, non-transferable use of the information. NO - * WARRANTY of ANY KIND is provided. This heading must NOT be removed from - * the file. - * - */ - -/** @file - * - * @defgroup mem_manager Memory Manager - * @{ - * @ingroup app_common - * @brief Memory Manager for the \nRFXX SDK - * - * @details This module allows for dynamic use of memory. Currently, - * this module can be used only to allocate and free memory in the RAM. - * - * The Memory Manager manages static memory blocks of fixed sizes. These blocks can be requested for - * usage, and freed when the application no longer needs them. A maximum of seven block categories - * can be managed by the module. These block categories are identified by xxsmall, xmall, small, - * medium, large, xlarge, and xxlarge. They are ordered in increasing block sizes. - * The size and the count of each of the block categories can be configured based on the application - * requirements in the configuration file @c sdk_config.h. - * To use fewer than seven buffer pools, do not define the count for the unwanted block - * or explicitly set it to zero. At least one block category must be configured - * for this module to function as expected. - */ - -#ifndef MEM_MANAGER_H__ -#define MEM_MANAGER_H__ - -#include "sdk_common.h" - - -#ifdef __cplusplus -extern "C" { -#endif - -/**@brief Initializes Memory Manager. - * - * @details API to initialize the Memory Manager. Always call this API before using any of the other - * APIs of the module. This API should be called only once. - * - * @retval NRF_SUCCESS If initialization was successful. - * Otherwise, an error code that indicates the reason for the failure is returned. - * - * @warning If this API fails, the application shall not proceed with using other APIs of this - * module. - */ -uint32_t nrf_mem_init(void); - - -/**@brief Reserves a block of memory for the application. - * - * @details API to request a contiguous memory block of the given length. If - * the memory allocation succeeds, pp_buffer points to the memory block. If - * the memory allocation fails, pp_buffer points to NULL and the return value of - * the API indicates the reason for the failure. The memory block reserved using this API can - * be freed using the @ref nrf_free function. - * - * @param[out] pp_buffer Pointer to the allocated memory block if memory allocation - * succeeds; otherwise points to NULL. - * @param[inout] p_size Requested memory size. This parameter returns the actual size - * allocated. If the procedure was successful, the actual size - * returned is always greater than or equal to requested size, - * never less. - * - * @retval NRF_SUCCESS If memory was successfully allocated. - * Otherwise, an error code indicating the reason for failure. - * @retval NRF_ERROR_INVALID_PARAM If the requested memory size is zero or greater than the - * largest memory block that the module is configured to - * support. - * @retval NRF_ERROR_NO_MEM If there is no memory available of the requested size. - */ -uint32_t nrf_mem_reserve(uint8_t ** pp_buffer, uint32_t * p_size); - - -/**@brief 'malloc' styled memory allocation function. - * - * @details API to allocate memory, same as nrf_mem_reserve but uses malloc signature. - * - * @param[in] size Requested memory size. - * - * @retval Valid memory location if the procedure was successful, else, NULL. - */ -void * nrf_malloc(uint32_t size); - - -/**@brief 'calloc' styled memory allocation function. - * - * @details API to allocate zero-initialized memory of size count*size. - * - * @param[in] nmemb Number of elements of 'size' bytes. - * @param[in] size Size of each element allocated. - * - * @retval Valid, zero-initialized memory location if the procedure was successful, else, NULL. - */ -void * nrf_calloc(uint32_t nmemb, uint32_t size); - - -/**@brief Free allocated memory - standard 'free' styles API. - * - * @details API to resubmit memory allocated, same in functionality nrf_free. - * - * @param[out] p_buffer Pointer to the memory block that is being freed. - */ -void nrf_free(void * p_buffer); - - -/**@brief Memory reallocation (trim) function. - * - * @details API to reallocate memory or to trim it. Trim is mentioned here to avoid use of API to - * request memory size larger than original memory allocated. - * - * @param[in] p_buffer Pointer to the memory block that needs to be trimmed. - * @param[in] size Size of memory at the beginning of the buffer to be left untrimmed. - * - * @retval Pointer to memory location with trimmed size, else, NULL. - */ -void * nrf_realloc(void *p_buffer, uint32_t size); - -#ifdef MEM_MANAGER_ENABLE_DIAGNOSTICS - -/**@brief Function to print statstics related to memory blocks managed by memory manager. - * - * @details This API prints information with respects to each block function, including size, total - * block count, number of blocks in use at the time of printing, smallest memory size - * allocated in the block and the largest one. This API is intended to help developers - * tune the block sizes to make optimal use of memory for the application. - * This functionality is never needed in final application and therefore, is disabled by - * default. - */ -void nrf_mem_diagnose(void); - -#endif // MEM_MANAGER_ENABLE_DIAGNOSTICS - -#ifdef __cplusplus -} -#endif - -#endif // MEM_MANAGER_H__ -/** @} */
