@@ -34,18 +34,15 @@ LOG_MODULE_DECLARE(ocre_cs_component, OCRE_LOG_LEVEL);
3434#include "cs_sm.h"
3535#include "cs_sm_impl.h"
3636
37- // External RAM support for WAMR heap on boards that have it
37+ #include "ocre_psram.h"
38+
39+ // WAMR heap buffer - uses PSRAM when available
3840#if defined(CONFIG_MEMC )
39- #if defined(CONFIG_BOARD_ARDUINO_PORTENTA_H7 )
40- __attribute__((section ("SDRAM1" ), aligned (32 )))
41- #elif defined(CONFIG_BOARD_B_U585I_IOT02A )
42- __attribute__((section (".stm32_psram" ), aligned (32 )))
43- #elif defined(CONFIG_BOARD_MIMXRT1064_EVK )
44- __attribute__((section ("SDRAM" ), aligned (32 )))
45- #endif // defined (<board>)
46- #endif // defined(CONFIG_MEMC)
41+ PSRAM_SECTION_ATTR
42+ #endif
4743static char wamr_heap_buf [CONFIG_OCRE_WAMR_HEAP_BUFFER_SIZE ] = {0 };
4844
45+
4946// Thread pool for container execution
5047#define CONTAINER_THREAD_POOL_SIZE 4
5148static core_thread_t container_threads [CONTAINER_THREAD_POOL_SIZE ];
@@ -178,6 +175,7 @@ static int load_binary_to_buffer_fs(ocre_runtime_arguments_t *container_argument
178175 size_t file_size = 0 ;
179176 void * file_handle = NULL ;
180177 char filepath [FILE_PATH_MAX ];
178+
181179
182180 ret = core_construct_filepath (filepath , sizeof (filepath ), container_data -> sha256 );
183181 if (ret < 0 ) {
@@ -191,9 +189,9 @@ static int load_binary_to_buffer_fs(ocre_runtime_arguments_t *container_argument
191189 }
192190
193191 container_arguments -> size = file_size ;
194- container_arguments -> buffer = malloc (file_size );
192+ container_arguments -> buffer = storage_heap_alloc (file_size );
195193 if (!container_arguments -> buffer ) {
196- LOG_ERR ("Failed to allocate memory for container binary." );
194+ LOG_ERR ("Failed to allocate memory for container binary from PSRAM ." );
197195 return - ENOMEM ;
198196 }
199197
@@ -202,22 +200,22 @@ static int load_binary_to_buffer_fs(ocre_runtime_arguments_t *container_argument
202200 ret = core_fileopen (filepath , & file_handle );
203201 if (ret < 0 ) {
204202 LOG_ERR ("Failed to open file %s: %d" , filepath , ret );
205- free (container_arguments -> buffer );
203+ storage_heap_free (container_arguments -> buffer );
206204 return ret ;
207205 }
208206
209207 ret = core_fileread (file_handle , container_arguments -> buffer , file_size );
210208 if (ret < 0 ) {
211209 LOG_ERR ("Failed to read file %s: %d" , filepath , ret );
212210 core_fileclose (file_handle );
213- free (container_arguments -> buffer );
211+ storage_heap_free (container_arguments -> buffer );
214212 return ret ;
215213 }
216214
217215 ret = core_fileclose (file_handle );
218216 if (ret < 0 ) {
219217 LOG_ERR ("Failed to close file %s: %d" , filepath , ret );
220- free (container_arguments -> buffer );
218+ storage_heap_free (container_arguments -> buffer );
221219 return ret ;
222220 }
223221 return 0 ;
@@ -268,6 +266,7 @@ ocre_container_runtime_status_t CS_runtime_init(ocre_cs_ctx *ctx, ocre_container
268266#ifdef CONFIG_OCRE_CONTAINER_MESSAGING
269267 ocre_messaging_init ();
270268#endif
269+ storage_heap_init ();
271270 return RUNTIME_STATUS_INITIALIZED ;
272271}
273272
@@ -322,7 +321,7 @@ ocre_container_status_t CS_create_container(ocre_container_t *container) {
322321 curr_container_arguments -> error_buf , sizeof (curr_container_arguments -> error_buf ));
323322 if (!curr_container_arguments -> module ) {
324323 LOG_ERR ("Failed to load WASM module: %s" , curr_container_arguments -> error_buf );
325- free (curr_container_arguments -> buffer );
324+ storage_heap_free (curr_container_arguments -> buffer );
326325 return CONTAINER_STATUS_ERROR ;
327326 }
328327
@@ -381,7 +380,7 @@ ocre_container_status_t CS_run_container(ocre_container_t *container) {
381380 LOG_ERR ("Failed to instantiate WASM module: %s, for containerID= %d" , curr_container_arguments -> error_buf ,
382381 curr_container_ID );
383382 wasm_runtime_unload (curr_container_arguments -> module );
384- free (curr_container_arguments -> buffer );
383+ storage_heap_free (curr_container_arguments -> buffer );
385384 return CONTAINER_STATUS_ERROR ;
386385 }
387386#if defined(CONFIG_OCRE_TIMER ) || defined(CONFIG_OCRE_GPIO ) || defined(CONFIG_OCRE_SENSORS ) || \
@@ -514,7 +513,7 @@ ocre_container_status_t CS_destroy_container(ocre_container_t *container, ocre_c
514513 }
515514
516515 if (container -> ocre_runtime_arguments .buffer ) {
517- free (container -> ocre_runtime_arguments .buffer );
516+ storage_heap_free (container -> ocre_runtime_arguments .buffer );
518517 container -> ocre_runtime_arguments .buffer = NULL ;
519518 }
520519
0 commit comments