luat_malloc_rtt.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "luat_base.h"
  2. #include "luat_malloc.h"
  3. #include "rtthread.h"
  4. #include "bget.h"
  5. #define ALI8 __attribute__ ((aligned (8)))
  6. #ifdef BSP_USING_WM_LIBRARIES
  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. ALI8 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. ALI8 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
  30. bpool(w600_mcu_heap, W600_MUC_HEAP_SIZE);
  31. #endif
  32. void *ptr = W600_HEAP_ADDR;
  33. #else
  34. char *ptr = (char*)luavm_buff;
  35. #endif
  36. bpool(ptr, LUAT_HEAP_SIZE);
  37. return 0;
  38. }
  39. INIT_COMPONENT_EXPORT(rtt_mem_init);
  40. void luat_meminfo_sys(size_t* total, size_t* used, size_t* max_used) {
  41. rt_memory_info(total, used, max_used);
  42. }