Teensy 4.1 core updated for C++20
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

51 rinda
986B

  1. // External memory allocation functions. Attempt to use external memory,
  2. // but automatically fall back to internal RAM if external RAM can't be used.
  3. #include <stdlib.h>
  4. #include "smalloc.h"
  5. #include "wiring.h"
  6. #if defined(ARDUINO_TEENSY41)
  7. // Teensy 4.1 external RAM address range is 0x70000000 to 0x7FFFFFFF
  8. #define HAS_EXTRAM
  9. #define IS_EXTMEM(addr) (((uint32_t)ptr >> 28) == 7)
  10. #endif
  11. void *extmem_malloc(size_t size)
  12. {
  13. #ifdef HAS_EXTRAM
  14. void *ptr = sm_malloc_pool(&extmem_smalloc_pool, size);
  15. if (ptr) return ptr;
  16. #endif
  17. return malloc(size);
  18. }
  19. void extmem_free(void *ptr)
  20. {
  21. #ifdef HAS_EXTRAM
  22. if (IS_EXTMEM(ptr)) {
  23. sm_free_pool(&extmem_smalloc_pool, ptr);
  24. return;
  25. }
  26. #endif
  27. free(ptr);
  28. }
  29. void *extmem_calloc(size_t nmemb, size_t size)
  30. {
  31. return extmem_malloc(nmemb * size);
  32. }
  33. void *extmem_realloc(void *ptr, size_t size)
  34. {
  35. #ifdef HAS_EXTRAM
  36. if (IS_EXTMEM(ptr)) {
  37. return sm_realloc_pool(&extmem_smalloc_pool, ptr, size);
  38. }
  39. #endif
  40. return realloc(ptr, size);
  41. }