@@ -395,51 +395,89 @@ void IRAM_ATTR vPortFree(void *ptr, const char* file, int line)
395395
396396 The NON-OS SDK 3.0.x has breaking changes to pvPortMalloc. They added one more
397397 argument for selecting a heap. To avoid breaking the build, I renamed their
398- broken version pvEsprMalloc. To be used, the LIBS need to be edited.
398+ breaking version to sdk3_pvPortMalloc. To complete the fix, the LIBS need to
399+ be edited.
399400
400- They also added pvPortZallocIram and pvPortCallocIram, which are not a
401- problem.
401+ Also in the release are low-level functions pvPortZallocIram and
402+ pvPortCallocIram, which are not documented in the Espressif NONOS SDK manual.
403+ No issues in providing replacements. For the non-Arduino ESP8266 applications,
404+ pvPortZallocIram and pvPortCallocIram would have been selected through the
405+ macros like os_malloc defined in `mem.h`.
406+
407+ OOM - Implementation strategy - Native v3.0 SDK
408+ * For functions `pvPortMalloc(,,,true);` and `pvPortMallocIram(,,,);` on a
409+ failed IRAM alloc, try DRAM.
410+ * For function `pvPortMalloc(,,,false);` use DRAM only - on fail, do not
411+ try IRAM.
402412
403413 WPA2 Enterprise connect crashing is fixed at v3.0.2 and up.
404414
405415 Not used for unreleased version NONOSDK3V0.
406416*/
417+ #ifdef UMM_HEAP_IRAM
407418void * IRAM_ATTR sdk3_pvPortMalloc (size_t size, const char * file, int line, bool iram)
408419{
409420 if (iram) {
410421 HeapSelectIram ephemeral;
411- return heap_pvPortMalloc (size, file, line);
412- } else {
422+ void * ret = heap_pvPortMalloc (size, file, line);
423+ if (ret) return ret;
424+ }
425+ {
413426 HeapSelectDram ephemeral;
414427 return heap_pvPortMalloc (size, file, line);
415428 }
416429}
417430
418431void * IRAM_ATTR pvPortCallocIram (size_t count, size_t size, const char * file, int line)
419432{
420- HeapSelectIram ephemeral;
421- return heap_pvPortCalloc (count, size, file, line);
433+ {
434+ HeapSelectIram ephemeral;
435+ void * ret = heap_pvPortCalloc (count, size, file, line);
436+ if (ret) return ret;
437+ }
438+ {
439+ HeapSelectDram ephemeral;
440+ return heap_pvPortCalloc (count, size, file, line);
441+ }
422442}
423443
424444void * IRAM_ATTR pvPortZallocIram (size_t size, const char * file, int line)
425445{
426- HeapSelectIram ephemeral;
427- return heap_pvPortZalloc (size, file, line);
446+ {
447+ HeapSelectIram ephemeral;
448+ void * ret = heap_pvPortZalloc (size, file, line);
449+ if (ret) return ret;
450+ }
451+ {
452+ HeapSelectDram ephemeral;
453+ return heap_pvPortZalloc (size, file, line);
454+ }
428455}
456+ #define CONFIG_IRAM_MEMORY 1
429457
430- /*
431- uint32_t IRAM_ATTR user_iram_memory_is_enabled(void)
432- {
433- return CONFIG_ENABLE_IRAM_MEMORY;
434- }
458+ #else
459+ // For sdk3_pvPortMalloc, the bool argument is ignored and intentionally omitted.
460+ extern " C" void * sdk3_pvPortMalloc (size_t size, const char * file, int line) __attribute__ ((alloc_size(1 ), malloc, nothrow, alias(" pvPortMalloc" )));
461+ extern " C" void * pvPortCallocIram (size_t count, size_t size, const char * file, int line) __attribute__((alloc_size(1 , 2 ), malloc, nothrow, alias(" pvPortCalloc" )));
462+ extern " C" void * pvPortZallocIram (size_t size, const char * file, int line) __attribute__((alloc_size(1 ), malloc, nothrow, alias(" pvPortZalloc" )));
463+ #define CONFIG_IRAM_MEMORY 0
464+ #endif // #ifdef UMM_HEAP_IRAM
435465
466+ /*
436467 We do not need the function user_iram_memory_is_enabled().
437468 1. It was used by mem_manager.o which was replaced with this custom heap
438- implementation. IRAM memory selection is handled differently.
469+ implementation. IRAM memory selection is handled differently for
470+ Arduino ESP8266.
439471 2. In libmain.a, Cache_Read_Enable_New uses it for cache size. However, When
440472 using IRAM for memory or running with 48K IRAM for code, we use a
441473 replacement Cache_Read_Enable to correct the cache size ignoring
442474 Cache_Read_Enable_New's selected value.
475+ 3. Create a linker conflicts in the event the sketch author tries to control
476+ IRAM heap through this method.
443477*/
444- #endif
478+ uint32 IRAM_ATTR user_iram_memory_is_enabled (void )
479+ {
480+ return CONFIG_IRAM_MEMORY;
481+ }
482+ #endif // #if (NONOSDK >= (0x30000))
445483};
0 commit comments