keybrd library is an open source library for creating custom-keyboard firmware.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

getFreeSRAM.h 907B

123456789101112131415161718192021222324252627282930313233343536
  1. // getFreeSRAM.h copied from
  2. // http://andybrown.me.uk/2011/01/01/debugging-avr-dynamic-memory-allocation/
  3. /*
  4. * memdebug.h
  5. *
  6. * Created on: 15 Dec 2010
  7. * Author: Andy Brown
  8. *
  9. * Use without attribution is permitted provided that this
  10. * header remains intact and that these terms and conditions
  11. * are followed:
  12. *
  13. * http://andybrown.me.uk/ws/terms-and-conditions
  14. */
  15. #include <inttypes.h>
  16. extern unsigned int __bss_end;
  17. extern unsigned int __heap_start;
  18. extern void *__brkval;
  19. //measure and return amount of free SRAM
  20. uint16_t getFreeSRAM()
  21. {
  22. uint8_t newVariable;
  23. // if heap is empty, use bss as start memory address
  24. if ((uint16_t)__brkval == 0)
  25. {
  26. return (((uint16_t)&newVariable) - ((uint16_t)&__bss_end));
  27. }
  28. // else use heap end as the start of the memory address
  29. else
  30. {
  31. return (((uint16_t)&newVariable) - ((uint16_t)__brkval));
  32. }
  33. };