reflow-oven-control-sw/stm-firmware/include/reflow-controller/stack-check.h

58 lines
1.4 KiB
C
Raw Normal View History

/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __STACK_CHECK_H__
#define __STACK_CHECK_H__
2020-02-21 23:01:04 +01:00
#include <stdint.h>
#define STACK_CHECK_MIN_HEAP_GAP 16UL
int32_t stack_check_get_usage();
int32_t stack_check_get_free();
2020-04-23 00:09:44 +02:00
static inline int stack_check_collision()
{
int ret = 0;
int32_t free_space = stack_check_get_free();
if ((unsigned int)free_space < STACK_CHECK_MIN_HEAP_GAP) {
ret = -1;
}
return ret;
}
2020-02-21 23:01:04 +01:00
static inline uint32_t read_stack_pointer()
{
uint32_t stack_pointer;
__asm__ __volatile__ ("mov %0, sp\n\t" : "=r"(stack_pointer) : : );
return stack_pointer;
}
int stack_check_init_corruption_detect_area(void);
int stack_check_corruption_detect_area(void);
#endif /* __STACK_CHECK_H__ */