mirror of
https://github.com/raspberrypi/pico-sdk.git
synced 2025-12-10 07:14:36 +01:00
start IAR specific development branch - need not compile with GCC or Clang
This commit is contained in:
parent
9f68faf5ab
commit
e63c22a9e5
3 changed files with 55 additions and 14 deletions
|
|
@ -3,7 +3,7 @@ if (NOT TARGET pico_malloc)
|
|||
pico_add_library(pico_malloc)
|
||||
|
||||
target_sources(pico_malloc INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}/pico_malloc.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/pico_malloc_iar.c
|
||||
)
|
||||
|
||||
target_include_directories(pico_malloc_headers INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,19 @@
|
|||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifdef __ICCARM__
|
||||
/* To support IAR's runtime library, which features multiple link-time
|
||||
* selectable heap implementations, this file is designed to be
|
||||
* multiply included with PREFIX set to the appropriate function name
|
||||
* prefix (if any) */
|
||||
#ifndef PREFIX
|
||||
#error pico_malloc.c is #included on IAR
|
||||
#endif
|
||||
#else
|
||||
#define PREFIX
|
||||
#endif
|
||||
|
||||
#ifndef PICO_MALLOC_INCLUDED_ONCE
|
||||
#include <stdlib.h>
|
||||
#include "pico.h"
|
||||
#include "pico/malloc.h"
|
||||
|
|
@ -13,11 +26,6 @@
|
|||
auto_init_mutex(malloc_mutex);
|
||||
#endif
|
||||
|
||||
extern void *REAL_FUNC(malloc)(size_t size);
|
||||
extern void *REAL_FUNC(calloc)(size_t count, size_t size);
|
||||
extern void *REAL_FUNC(realloc)(void *mem, size_t size);
|
||||
extern void REAL_FUNC(free)(void *mem);
|
||||
|
||||
extern char __StackLimit; /* Set by linker. */
|
||||
|
||||
static inline void check_alloc(__unused void *mem, __unused uint size) {
|
||||
|
|
@ -27,12 +35,19 @@ static inline void check_alloc(__unused void *mem, __unused uint size) {
|
|||
}
|
||||
#endif
|
||||
}
|
||||
#define PICO_MALLOC_INCLUDED_ONCE
|
||||
#endif
|
||||
|
||||
void *WRAPPER_FUNC(malloc)(size_t size) {
|
||||
extern void *REAL_FUNC_EXP(__CONCAT(PREFIX,malloc))(size_t size);
|
||||
extern void *REAL_FUNC_EXP(__CONCAT(PREFIX,calloc))(size_t count, size_t size);
|
||||
extern void *REAL_FUNC_EXP(__CONCAT(PREFIX,realloc))(void *mem, size_t size);
|
||||
extern void REAL_FUNC_EXP(__CONCAT(PREFIX,free))(void *mem);
|
||||
|
||||
void *WRAPPER_FUNC_EXP(__CONCAT(PREFIX,malloc))(size_t size) {
|
||||
#if PICO_USE_MALLOC_MUTEX
|
||||
mutex_enter_blocking(&malloc_mutex);
|
||||
#endif
|
||||
void *rc = REAL_FUNC(malloc)(size);
|
||||
void *rc = REAL_FUNC_EXP(__CONCAT(PREFIX,malloc))(size);
|
||||
#if PICO_USE_MALLOC_MUTEX
|
||||
mutex_exit(&malloc_mutex);
|
||||
#endif
|
||||
|
|
@ -45,11 +60,11 @@ void *WRAPPER_FUNC(malloc)(size_t size) {
|
|||
return rc;
|
||||
}
|
||||
|
||||
void *WRAPPER_FUNC(calloc)(size_t count, size_t size) {
|
||||
void *WRAPPER_FUNC_EXP(__CONCAT(PREFIX,calloc))(size_t count, size_t size) {
|
||||
#if PICO_USE_MALLOC_MUTEX
|
||||
mutex_enter_blocking(&malloc_mutex);
|
||||
#endif
|
||||
void *rc = REAL_FUNC(calloc)(count, size);
|
||||
void *rc = REAL_FUNC_EXP(__CONCAT(PREFIX,calloc))(count, size);
|
||||
#if PICO_USE_MALLOC_MUTEX
|
||||
mutex_exit(&malloc_mutex);
|
||||
#endif
|
||||
|
|
@ -62,11 +77,11 @@ void *WRAPPER_FUNC(calloc)(size_t count, size_t size) {
|
|||
return rc;
|
||||
}
|
||||
|
||||
void *WRAPPER_FUNC(realloc)(void *mem, size_t size) {
|
||||
void *WRAPPER_FUNC_EXP(__CONCAT(PREFIX,realloc))(void *mem, size_t size) {
|
||||
#if PICO_USE_MALLOC_MUTEX
|
||||
mutex_enter_blocking(&malloc_mutex);
|
||||
#endif
|
||||
void *rc = REAL_FUNC(realloc)(mem, size);
|
||||
void *rc = REAL_FUNC_EXP(__CONCAT(PREFIX,realloc))(mem, size);
|
||||
#if PICO_USE_MALLOC_MUTEX
|
||||
mutex_exit(&malloc_mutex);
|
||||
#endif
|
||||
|
|
@ -79,11 +94,11 @@ void *WRAPPER_FUNC(realloc)(void *mem, size_t size) {
|
|||
return rc;
|
||||
}
|
||||
|
||||
void WRAPPER_FUNC(free)(void *mem) {
|
||||
void WRAPPER_FUNC_EXP(__CONCAT(PREFIX,free))(void *mem) {
|
||||
#if PICO_USE_MALLOC_MUTEX
|
||||
mutex_enter_blocking(&malloc_mutex);
|
||||
#endif
|
||||
REAL_FUNC(free)(mem);
|
||||
REAL_FUNC_EXP(__CONCAT(PREFIX,free))(mem);
|
||||
#if PICO_USE_MALLOC_MUTEX
|
||||
mutex_exit(&malloc_mutex);
|
||||
#endif
|
||||
|
|
|
|||
26
src/rp2_common/pico_malloc/pico_malloc_iar.c
Normal file
26
src/rp2_common/pico_malloc/pico_malloc_iar.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#if defined __ICCARM__
|
||||
|
||||
/* Used when you select "No-free heap" in Project > Options... > General options > Library options 2 */
|
||||
#define PREFIX __no_free_
|
||||
#include "pico_malloc.c"
|
||||
#undef PREFIX
|
||||
/* Used when you select "Basic heap" in Project > Options... > General options > Library options 2 */
|
||||
#define PREFIX __basic_
|
||||
#include "pico_malloc.c"
|
||||
#undef PREFIX
|
||||
/* Used when you select "Advanced heap" in Project > Options... > General options > Library options 2 */
|
||||
#define PREFIX __iar_dl
|
||||
#include "pico_malloc.c"
|
||||
#undef PREFIX
|
||||
|
||||
#else
|
||||
|
||||
#error Unsupported toolchain
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Reference in a new issue