Skip to content

Commit

Permalink
add Adafruit Feather M0 (SAMD21G18A), refactor selective content
Browse files Browse the repository at this point in the history
  • Loading branch information
dniklaus committed Jul 22, 2017
1 parent 5c4be2d commit 79c5f31
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions RamUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,24 @@

#include <Arduino.h>
#include <RamUtils.h>

#if defined (__arm__) && defined (__SAM3X8E__) // Arduino Due
#include <malloc.h>
#include <stdlib.h>
#include <stdio.h>
extern char* _sbrk(int i);
#endif

#if defined (ARDUINO_ARCH_SAMD) && defined (__SAMD21G18A__) // Adafruit Feather M0
extern "C" char *sbrk(int i);
#endif

#if defined (__AVR__) // AVR
extern "C" int __bss_end;
extern "C" int *__brkval;
#endif

/*!
/**
* Returns the free ram memory space.
* @return Free Memory space in Bytes
*/
Expand All @@ -22,14 +33,13 @@ int RamUtils::getFreeRam()
int free_memory = 0;
#if defined (__arm__) && defined (__SAM3X8E__) // Arduino Due
struct mallinfo mi=mallinfo();
extern char* _sbrk(int i);
char* heapend = _sbrk(0);
register char * stack_ptr asm("sp");
free_memory = stack_ptr - heapend + mi.fordblks;
return free_memory;
#else // AVR
extern int __bss_end;
extern int *__brkval;
#elif defined (ARDUINO_ARCH_SAMD) && defined (__SAMD21G18A__) // Adafruit Feather M0
char stack_dummy = 0;
free_memory = &stack_dummy - sbrk(0);
#elif defined (__AVR__) // AVR
if ((int) __brkval == 0)
{
free_memory = ((int) &free_memory) - ((int) &__bss_end);
Expand All @@ -38,6 +48,6 @@ int RamUtils::getFreeRam()
{
free_memory = ((int) &free_memory) - ((int) __brkval);
}
return free_memory;
#endif
return free_memory;
}

0 comments on commit 79c5f31

Please sign in to comment.