HAL_AVR: moved memcheck into HAL_AVR
This commit is contained in:
parent
efc7f88e4b
commit
36e06a1709
@ -1,4 +1,7 @@
|
||||
/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
||||
/*
|
||||
keep track of available memory on AVR
|
||||
*/
|
||||
|
||||
/*
|
||||
* note that we use a 32 bit sentinel to reduce the chance
|
||||
@ -7,7 +10,8 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <AP_HAL_Boards.h>
|
||||
|
||||
#if (CONFIG_HAL_BOARD == HAL_BOARD_APM1 || CONFIG_HAL_BOARD == HAL_BOARD_APM2)
|
||||
|
||||
static const uint32_t *stack_low;
|
||||
extern unsigned __brkval;
|
||||
@ -28,7 +32,7 @@ static __attribute__((noinline)) const uint32_t *current_stackptr(void)
|
||||
* deep stack usage. It should be caught by the sentinel, but this
|
||||
* is an added protection
|
||||
*/
|
||||
void memcheck_update_stackptr(void)
|
||||
static void memcheck_update_stackptr(void)
|
||||
{
|
||||
if (current_stackptr() < stack_low) {
|
||||
uintptr_t s = (uintptr_t)(current_stackptr() - STACK_OFFSET);
|
||||
@ -41,7 +45,6 @@ void memcheck_update_stackptr(void)
|
||||
*/
|
||||
void memcheck_init(void)
|
||||
{
|
||||
#if CONFIG_HAL_BOARD == HAL_BOARD_APM1 || CONFIG_HAL_BOARD == HAL_BOARD_APM2
|
||||
uint32_t *p;
|
||||
free(malloc(1)); // ensure heap is initialised
|
||||
stack_low = current_stackptr();
|
||||
@ -49,7 +52,6 @@ void memcheck_init(void)
|
||||
for (p=(uint32_t *)(stack_low-1); p>(uint32_t *)__brkval; p--) {
|
||||
*p = SENTINEL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
@ -58,13 +60,11 @@ void memcheck_init(void)
|
||||
*/
|
||||
unsigned memcheck_available_memory(void)
|
||||
{
|
||||
#if CONFIG_HAL_BOARD == HAL_BOARD_APM1 || CONFIG_HAL_BOARD == HAL_BOARD_APM2
|
||||
memcheck_update_stackptr();
|
||||
while (*stack_low != SENTINEL && stack_low > (const uint32_t *)__brkval) {
|
||||
stack_low--;
|
||||
}
|
||||
return (uintptr_t)(stack_low) - __brkval;
|
||||
#else
|
||||
return 0x1000;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // CONFIG_HAL_BOARD
|
@ -2,5 +2,3 @@
|
||||
|
||||
unsigned memcheck_available_memory(void);
|
||||
void memcheck_init(void);
|
||||
void memcheck_update_stackptr(void);
|
||||
|
Loading…
Reference in New Issue
Block a user