Add stack checking functions
This commit is contained in:
parent
b5d4bf5528
commit
68fc473372
@ -18,8 +18,24 @@
|
|||||||
* If not, see <http://www.gnu.org/licenses/>.
|
* If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef __STACK_CHECK_H__
|
#ifndef __STACK_CHECK_H__
|
||||||
#define __STACK_CHECK_H__
|
#define __STACK_CHECK_H__
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define STACK_CHECK_MIN_HEAP_GAP 16UL
|
||||||
|
|
||||||
|
int32_t stack_check_get_usage();
|
||||||
|
|
||||||
|
int32_t stack_check_get_free();
|
||||||
|
|
||||||
|
static inline uint32_t read_stack_pointer()
|
||||||
|
{
|
||||||
|
uint32_t stack_pointer;
|
||||||
|
|
||||||
|
__asm__ __volatile__ ("mov %0, sp\n\t" : "=r"(stack_pointer) : : );
|
||||||
|
|
||||||
|
return stack_pointer;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* __STACK_CHECK_H__ */
|
#endif /* __STACK_CHECK_H__ */
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include <stm-periph/unique-id.h>
|
#include <stm-periph/unique-id.h>
|
||||||
#include <reflow-controller/calibration.h>
|
#include <reflow-controller/calibration.h>
|
||||||
#include <reflow-controller/temp-converter.h>
|
#include <reflow-controller/temp-converter.h>
|
||||||
|
#include <reflow-controller/stack-check.h>
|
||||||
|
|
||||||
#ifndef GIT_VER
|
#ifndef GIT_VER
|
||||||
#define GIT_VER "VERSION NOT SET"
|
#define GIT_VER "VERSION NOT SET"
|
||||||
@ -201,6 +202,24 @@ static shellmatta_retCode_t shell_cmd_cal(const shellmatta_handle_t handle,
|
|||||||
calibration_sequence_shell_cmd(handle);
|
calibration_sequence_shell_cmd(handle);
|
||||||
return SHELLMATTA_OK;
|
return SHELLMATTA_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static shellmatta_retCode_t shell_get_sp(const shellmatta_handle_t handle,
|
||||||
|
const char *arguments,
|
||||||
|
uint32_t length)
|
||||||
|
{
|
||||||
|
(void)arguments;
|
||||||
|
(void)length;
|
||||||
|
|
||||||
|
shellmatta_printf(handle,
|
||||||
|
"Stack pointer: %p\r\n"
|
||||||
|
"Stack usage: 0x%x bytes\r\n"
|
||||||
|
"Lim to heap: 0x%x bytes\r\n",
|
||||||
|
read_stack_pointer(),
|
||||||
|
stack_check_get_usage(),
|
||||||
|
stack_check_get_free());
|
||||||
|
return SHELLMATTA_OK;
|
||||||
|
}
|
||||||
|
|
||||||
//typedef struct shellmatta_cmd
|
//typedef struct shellmatta_cmd
|
||||||
//{
|
//{
|
||||||
// char *cmd; /**< command name */
|
// char *cmd; /**< command name */
|
||||||
@ -211,7 +230,7 @@ static shellmatta_retCode_t shell_cmd_cal(const shellmatta_handle_t handle,
|
|||||||
// struct shellmatta_cmd *next; /**< pointer to next command or NULL */
|
// struct shellmatta_cmd *next; /**< pointer to next command or NULL */
|
||||||
//} shellmatta_cmd_t;
|
//} shellmatta_cmd_t;
|
||||||
|
|
||||||
static shellmatta_cmd_t cmd[7] = {
|
static shellmatta_cmd_t cmd[8] = {
|
||||||
{
|
{
|
||||||
.cmd = "version",
|
.cmd = "version",
|
||||||
.cmdAlias = "ver",
|
.cmdAlias = "ver",
|
||||||
@ -266,6 +285,14 @@ static shellmatta_cmd_t cmd[7] = {
|
|||||||
.helpText = "Calibrate resistance measurement",
|
.helpText = "Calibrate resistance measurement",
|
||||||
.usageText = "",
|
.usageText = "",
|
||||||
.cmdFct = shell_cmd_cal,
|
.cmdFct = shell_cmd_cal,
|
||||||
|
.next = &cmd[7],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.cmd = "get-stack-pointer",
|
||||||
|
.cmdAlias = "sp",
|
||||||
|
.helpText = "Get the stack pointer",
|
||||||
|
.usageText = "",
|
||||||
|
.cmdFct = shell_get_sp,
|
||||||
.next = NULL,
|
.next = NULL,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -19,3 +19,29 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <reflow-controller/stack-check.h>
|
#include <reflow-controller/stack-check.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
extern char _estack;
|
||||||
|
extern char heap_top;
|
||||||
|
|
||||||
|
int32_t stack_check_get_usage()
|
||||||
|
{
|
||||||
|
uint32_t stack_top;
|
||||||
|
uint32_t stack_ptr;
|
||||||
|
|
||||||
|
stack_ptr = read_stack_pointer();
|
||||||
|
stack_top = (uint32_t)&_estack;
|
||||||
|
|
||||||
|
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)&heap_top;
|
||||||
|
|
||||||
|
return stack_ptr - upper_heap_boundary;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user