Skip to content

Commit 73c85fd

Browse files
committed
drivers:platform:freeRTOS:Added mem functions
Add freeRTOS memory functions for no-OS implementation. Signed-off-by: Lars Andre Landås <[email protected]>
1 parent bf1043a commit 73c85fd

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*******************************************************************************
2+
* @file freeRTOS/freertos_alloc.c
3+
* @brief Implementation of freertos allocation functions.
4+
* @author Lars Andre Landås ([email protected])
5+
********************************************************************************
6+
* Copyright 2025(c) Analog Devices, Inc.
7+
*
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions are met:
10+
*
11+
* 1. Redistributions of source code must retain the above copyright notice,
12+
* this list of conditions and the following disclaimer.
13+
*
14+
* 2. Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* 3. Neither the name of Analog Devices, Inc. nor the names of its
19+
* contributors may be used to endorse or promote products derived from this
20+
* software without specific prior written permission.
21+
*
22+
* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR
23+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24+
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
25+
* EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
26+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
28+
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31+
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
*******************************************************************************/
33+
34+
#include "FreeRTOS.h"
35+
#include "task.h"
36+
#include "no_os_alloc.h"
37+
#include "portable.h"
38+
#include <string.h>
39+
40+
/**
41+
* @brief Allocate memory and return a pointer to it.
42+
* @param size - Size of the memory block, in bytes.
43+
* @return Pointer to the allocated memory, or NULL if the request fails.
44+
*/
45+
void *no_os_malloc(size_t size)
46+
{
47+
return pvPortMalloc(size);
48+
}
49+
50+
/**
51+
* @brief Allocate memory and return a pointer to it, set memory to 0.
52+
* @param nitems - Number of elements to be allocated.
53+
* @param size - Size of elements.
54+
* @return Pointer to the allocated memory, or NULL if the request fails.
55+
*/
56+
void *no_os_calloc(size_t nitems, size_t size)
57+
{
58+
void *p_ret;
59+
p_ret = pvPortMalloc(nitems * size);
60+
if (p_ret != NULL) {
61+
memset(p_ret, 0, nitems * size);
62+
}
63+
return p_ret;
64+
}
65+
66+
/**
67+
* @brief Deallocate memory previously allocated by a call to no_os_calloc
68+
* or no_os_malloc.
69+
* @param ptr - Pointer to a memory block previously allocated by a call
70+
* to no_os_calloc or no_os_malloc.
71+
* @return None.
72+
*/
73+
void no_os_free(void *ptr)
74+
{
75+
vPortFree(ptr);
76+
}

0 commit comments

Comments
 (0)