luat_malloc_rtt.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "luat_base.h"
  2. #include "luat_malloc.h"
  3. #include "rtthread.h"
  4. #include "bget.h"
  5. #ifdef BSP_USING_WM_LIBRARIES
  6. #include "wm_ram_config.h"
  7. #define LUAT_HEAP_SIZE 64*1024
  8. #define W600_HEAP_ADDR 0x20028000
  9. #ifdef RT_USING_WIFI
  10. #else
  11. #define W600_MUC_HEAP_SIZE (64*1024)
  12. ALIGN(RT_ALIGN_SIZE) static char w600_mcu_heap[W600_MUC_HEAP_SIZE]; // MCU模式下, rtt起码剩余140kb内存, 用64kb不过分吧
  13. #endif
  14. #else
  15. #ifndef LUAT_HEAP_SIZE
  16. #ifdef SOC_FAMILY_STM32
  17. #define LUAT_HEAP_SIZE (64*1024)
  18. #else
  19. #define LUAT_HEAP_SIZE 128*1024
  20. #endif
  21. #endif
  22. ALIGN(RT_ALIGN_SIZE) static char luavm_buff[LUAT_HEAP_SIZE] = {0};
  23. #endif
  24. static int rtt_mem_init() {
  25. #ifdef BSP_USING_WM_LIBRARIES
  26. #ifdef RT_USING_WIFI
  27. // nothing
  28. #else
  29. // MUC heap , 占用一部分rtt heap
  30. bpool((void*)w600_mcu_heap, W600_MUC_HEAP_SIZE);
  31. // 把wifi的内存全部吃掉
  32. bpool((void*)WIFI_MEM_START_ADDR, (64 - 16)*1024);
  33. #endif
  34. void *ptr = W600_HEAP_ADDR;
  35. #else
  36. char *ptr = (char*)luavm_buff;
  37. #endif
  38. bpool(ptr, LUAT_HEAP_SIZE);
  39. return 0;
  40. }
  41. INIT_COMPONENT_EXPORT(rtt_mem_init);
  42. void luat_meminfo_sys(size_t* total, size_t* used, size_t* max_used) {
  43. rt_memory_info(total, used, max_used);
  44. }