#ifndef _GD32_BKP_H__
#define _GD32_BKP_H__
#include <stdio.h>

#if defined (GD32F30X_HD) || defined (GD32F30X_XD) || defined (GD32F30X_CL)
#include "gd32f30x.h"
#include <stdbool.h>
#elif defined GD32E10x
#include "gd32e10x.h"
#include <stdbool.h>
#define bkp_write_data bkp_data_write
#define bkp_read_data bkp_data_read
#endif
#include "config.h"
#include "os/os_types.h"

#define POWER_FIRSTFLAG_REG BKP_DATA_0
#define POWER_FIRSTFLAG_VALUE 0x5AA5

#define BACK_TRACE_MAIGC_REG BKP_DATA_1
#define BACK_TRACE_MAIGC_VALUE 0x55AA

#define BACK_TRACE_INFO_REG BKP_DATA_2

#define BACK_TRACE_CALLTRACE_START_REG BKP_DATA_3

#define BACK_TRACE_LINE_REG ((bkp_data_register_enum)(BACK_TRACE_CALLTRACE_START_REG + 16))

void gd32_bkp_init(void);
bool gd32_bkp_first_startup(void);
bool gd32_bkp_btrace_valid(void);
void gd32_bkp_save_backtrace(uint32_t *backtrace, uint32_t stack_over, uint32_t stack_dep, uint16_t line);
void gd32_bkp_get_backtrace(uint32_t *backtrace, uint32_t *stack_over, uint32_t *stack_dep, uint16_t *line);
uint32_t  gd32_get_reset_source(void);


#endif /* _GD32_BKP_H__ */

