Skip to content

Commit 2391f48

Browse files
SidLeungeriknyquist
authored andcommitted
Moving balloc static memory buffer to DCCM memory
balloc() is used by interrupt context code for memory allocation. The memory space is statically allocated at initialization. In order not to take up SRAM memory, this buffer is moved to the DCCM memory space.
1 parent 34d0e50 commit 2391f48

File tree

7 files changed

+36
-7
lines changed

7 files changed

+36
-7
lines changed

cores/arduino/dccm/dccm_alloc.c

+9
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ void* dccm_malloc(uint16_t size)
3737
return addr;
3838
}
3939

40+
void *dccm_memalign(uint16_t size)
41+
{
42+
if ((dccm_index +3) > DCCM_SIZE)
43+
return 0;
44+
45+
dccm_index = (dccm_index + 3) & ~((uint16_t)0x3); /* 4 byte addr alignment */
46+
return dccm_malloc(size);
47+
}
48+
4049
#ifdef __cplusplus
4150
}
4251
#endif

cores/arduino/dccm/dccm_alloc.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
3131

3232
void* dccm_malloc(uint16_t size);
3333

34+
void *dccm_memalign(uint16_t size);
35+
3436
#ifdef __cplusplus
3537
}
3638
#endif
3739

3840

39-
#endif
41+
#endif

system/libarc32_arduino101/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ CFGFLAGS+=-DCONFIG_BLUETOOTH_MAX_CONN=2
3939
CFGFLAGS+=-DCONFIG_BT_GATT_BLE_MAX_SERVICES=10
4040
CFGFLAGS+=-DCONFIG_BLUETOOTH_GATT_CLIENT
4141
CFGFLAGS+=-DCONFIG_BLUETOOTH_CENTRAL -DCONFIG_BLUETOOTH_PERIPHERAL
42-
INCLUDES=-I. -Icommon -Idrivers -Ibootcode -Iframework/include -Iframework/include/services/ble -Iframework/src/services/ble_service
42+
INCLUDES=-I. -Icommon -Idrivers -Ibootcode -Iframework/include -Iframework/include/services/ble -Iframework/src/services/ble_service -I../../cores/arduino/dccm
4343
#-Iframework/src/services/ble -Iframework/include/services/ble
4444
INCLUDES+= -Idrivers/rpc -Iframework/src
4545
EXTRA_CFLAGS=-D__CPU_ARC__ -DCLOCK_SPEED=32 -std=c99 -fno-reorder-functions -fno-asynchronous-unwind-tables -fno-omit-frame-pointer -fno-defer-pop -Wno-unused-but-set-variable -Wno-main -ffreestanding -fno-stack-protector -mno-sdata -ffunction-sections -fdata-sections

system/libarc32_arduino101/bootcode/c_init.c

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2121

2222
#include "interrupt.h"
2323
#include "arcv2_timer0.h"
24+
#include "os/os.h"
2425

2526
/* Application main() function prototype */
2627
extern int main (void);
@@ -60,6 +61,8 @@ static void _exec_ctors (void)
6061
interrupt_unit_device_init();
6162
/* Start the system's virtual 64-bit Real Time Counter */
6263
timer0_driver_init();
64+
/* Initialize the memory buffer for balloc() calls. */
65+
os_abstraction_init_malloc();
6366
/* Jump to application main() */
6467
main ();
6568
/* Never reached */

system/libarc32_arduino101/framework/include/os/os.h

+9
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,15 @@ extern void queue_get_message (T_QUEUE queue, T_QUEUE_MESSAGE* message, int time
132132
*/
133133
extern void queue_send_message(T_QUEUE queue, T_QUEUE_MESSAGE message, OS_ERR_TYPE* err );
134134

135+
/**
136+
* \brief Initialize the resources used by the framework's memory allocation services
137+
*
138+
* IMPORTANT : This function must be called during the initialization
139+
* of the OS abstraction layer.
140+
* This function shall only be called once after reset.
141+
*/
142+
extern void os_abstraction_init_malloc(void);
143+
135144
/**
136145
* \brief Reserves a block of memory
137146
*

system/libarc32_arduino101/framework/src/os/balloc.c

+11-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "os/os.h"
1111
#include "infra/log.h"
12+
#include "dccm_alloc.h"
1213

1314
#ifdef CONFIG_MEMORY_POOLS_BALLOC_TRACK_OWNER
1415
#include "misc/printk.h"
@@ -59,7 +60,6 @@ typedef struct {
5960

6061
#include "memory_pool_list.def"
6162

62-
6363
/** Pool descriptor definition */
6464
T_POOL_DESC mpool[] =
6565
{
@@ -100,21 +100,19 @@ T_POOL_DESC mpool[] =
100100

101101
/** Allocate the memory blocks and tracking variables for each pool */
102102
#define DECLARE_MEMORY_POOL(index, size, count) \
103-
uint8_t mblock_ ## index[count][size]; \
104103
uint32_t mblock_alloc_track_ ## index[count / BITS_PER_U32 + 1] = { 0 };
105104

106105
#include "memory_pool_list.def"
107106

108107

109-
110108
/** Pool descriptor definition */
111109
T_POOL_DESC mpool [] =
112110
{
113111
#define DECLARE_MEMORY_POOL(index, size, count) \
114112
{ \
115113
/* T_POOL_DESC.track */ mblock_alloc_track_ ## index, \
116-
/* T_POOL_DESC.start */ (uint32_t)mblock_ ## index, \
117-
/* T_POOL_DESC.end */ (uint32_t)mblock_ ## index + count * size, \
114+
/* T_POOL_DESC.start */ 0, \
115+
/* T_POOL_DESC.end */ 0, \
118116
/* T_POOL_DESC.count */ count, \
119117
/* T_POOL_DESC.size */ size \
120118
},
@@ -333,6 +331,14 @@ static void print_pool(int method, void *ctx)
333331
*/
334332
void os_abstraction_init_malloc(void)
335333
{
334+
int indx;
335+
uint32_t bufSize;
336+
337+
for (indx=0; indx < NB_MEMORY_POOLS; indx++) {
338+
bufSize = mpool[indx].count * mpool[indx].size;
339+
mpool[indx].start = (uint32_t)dccm_memalign((uint16_t)bufSize);
340+
mpool[indx].end = mpool[indx].start + bufSize;
341+
}
336342
}
337343

338344
/**
-1.89 KB
Binary file not shown.

0 commit comments

Comments
 (0)