87 lines
2.0 KiB
C
87 lines
2.0 KiB
C
/* 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.
|
|
*
|
|
* The Reflow Oven Control Firmware 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/>.
|
|
*/
|
|
|
|
#include <reflow-controller/stack-check.h>
|
|
#include <stdint.h>
|
|
#include <stm-periph/rng.h>
|
|
|
|
extern char __ld_top_of_stack;
|
|
extern char __ld_end_stack;
|
|
|
|
int32_t stack_check_get_usage()
|
|
{
|
|
uint32_t stack_top;
|
|
uint32_t stack_ptr;
|
|
|
|
stack_ptr = read_stack_pointer();
|
|
stack_top = (uint32_t)&__ld_top_of_stack;
|
|
|
|
return stack_top - stack_ptr;
|
|
}
|
|
|
|
int32_t stack_check_get_free()
|
|
{
|
|
uint32_t upper_heap_boundary;
|
|
uint32_t stack_ptr;
|
|
|
|
stack_ptr = read_stack_pointer();
|
|
upper_heap_boundary = (uint32_t)&__ld_end_stack;
|
|
|
|
return stack_ptr - upper_heap_boundary;
|
|
}
|
|
|
|
extern uint32_t __ld_start_stack_corruption_detect_area;
|
|
extern uint32_t __ld_end_stack_corruption_detect_area;
|
|
|
|
int stack_check_init_corruption_detect_area(void)
|
|
{
|
|
volatile uint32_t *ptr = &__ld_start_stack_corruption_detect_area;
|
|
volatile uint32_t *end_ptr = &__ld_end_stack_corruption_detect_area;
|
|
enum random_number_error rng_stat;
|
|
uint32_t rng_number;
|
|
int ret = 0;
|
|
|
|
end_ptr--;
|
|
|
|
random_number_gen_init(false);
|
|
|
|
while (ptr < end_ptr) {
|
|
rng_stat = random_number_gen_get_number(&rng_number, true);
|
|
|
|
if (rng_stat != RNG_ERROR_OK) {
|
|
ret = -1;
|
|
goto exit_deinit_rng;
|
|
}
|
|
|
|
*ptr = rng_number;
|
|
ptr++;
|
|
}
|
|
|
|
exit_deinit_rng:
|
|
random_number_gen_deinit();
|
|
|
|
return ret;
|
|
}
|
|
|
|
int stack_check_corruption_detect_area(void)
|
|
{
|
|
|
|
}
|