251 lines
6.6 KiB
C
251 lines
6.6 KiB
C
#include "iot_bitops.h"
|
||
#include "dtest_printf.h"
|
||
#include "cpu.h"
|
||
#include "ahb.h"
|
||
|
||
#if HW_PLATFORM > HW_PLATFORM_SIMU
|
||
#include "dbg_io.h"
|
||
#endif
|
||
|
||
#include "chip_reg_base.h"
|
||
#include "ahb_rf_s.h"
|
||
|
||
#include "uart.h"
|
||
#include "strformat.h"
|
||
#include "uart_e.h"
|
||
|
||
#include "mailbox.h"
|
||
#include "mailbox_hw.h"
|
||
#include "iot_irq.h"
|
||
|
||
#include "dev_spinlock.h"
|
||
#include "watchdog.h"
|
||
extern struct uart_ctrl uart_e_ctrl;
|
||
#define my_g_uart_ctrl uart_e_ctrl
|
||
#define TEST_NUMS 32
|
||
#define BUF_LEN 500
|
||
|
||
typedef enum
|
||
{
|
||
TEST_MODE_CPURST = 0,
|
||
TEST_MODE_FULLRST,
|
||
}TEST_MODE;
|
||
|
||
static char g_buf[BUF_LEN];
|
||
uint32_t g_spinlock, g_cpu;
|
||
static volatile ahb_lite_reg_t *ahb_base =
|
||
(volatile ahb_lite_reg_t *)AHB_REG_LITE_BASEADDR;
|
||
|
||
extern struct uart_ctrl uart_e_ctrl;
|
||
#define my_g_uart_ctrl uart_e_ctrl
|
||
extern iot_wdg_info g_wdg_info[3];
|
||
extern iot_wdg_info g_wdg_timeout;
|
||
extern int g_feed_dog[3];
|
||
|
||
void register_print_by_addr(uint32_t addr, int num);
|
||
void core_working_loop(UART_PORT port, int pin_num, char *buf, int buf_len);
|
||
void core_wdg_test_loop(UART_PORT port, int pin_num, char *buf, int buf_len, TEST_MODE mode);
|
||
void delay_sometime(uint32_t t)
|
||
{
|
||
uint32_t loop, i;
|
||
for(i = 0; i < t; i++) {
|
||
loop = 0;
|
||
while(loop++ < 1000000) __asm volatile ("nop\n");
|
||
}
|
||
}
|
||
|
||
|
||
/*
|
||
!!!!!!!!!!!
|
||
特别注意,需要屏蔽startup_init.c的 pre_init函数部分代码
|
||
|
||
if (cpu == 0) {
|
||
//wdg_deinit(1);
|
||
//wdg_deinit(2);
|
||
}
|
||
|
||
*/
|
||
void wdg_test(UART_PORT port, int pin_num)
|
||
{
|
||
|
||
g_cpu = cpu_get_mhartid();
|
||
|
||
/*int init*/
|
||
iot_interrupt_init(g_cpu);
|
||
|
||
//core_working_loop(UART_PORT port, int pin_num, char *buf, int buf_len);
|
||
//core_wdg_test_loop(UART_PORT port, int pin_num, char *buf, int buf_len, TEST_MODE mode);
|
||
|
||
if (0 == g_cpu) {
|
||
core_wdg_test_loop( port, pin_num, g_buf, sizeof(g_buf), TEST_MODE_CPURST);
|
||
//core_working_loop( port, pin_num, g_buf, sizeof(g_buf));
|
||
} else if (1 == g_cpu) {
|
||
core_wdg_test_loop( port, pin_num, g_buf, sizeof(g_buf), TEST_MODE_CPURST);
|
||
//core_working_loop( port, pin_num, g_buf, sizeof(g_buf));
|
||
} else {
|
||
core_wdg_test_loop( port, pin_num, g_buf, sizeof(g_buf), TEST_MODE_CPURST);
|
||
//core_working_loop( port, pin_num, g_buf, sizeof(g_buf));
|
||
}
|
||
|
||
|
||
while(1) {
|
||
|
||
}
|
||
}
|
||
|
||
|
||
void core_print_regs(UART_PORT port, char *buf, int len, uint32_t cur_cpu) {
|
||
|
||
uint32_t pc;
|
||
uint32_t rst_flag;
|
||
int str_len;
|
||
uint32_t *reg = (uint32_t *)WDG0_REG_BASEADDR ;
|
||
|
||
switch(cur_cpu) {
|
||
case 0:
|
||
pc = ahb_base->cpu0_start_pc.w;
|
||
reg = (uint32_t *)WDG0_REG_BASEADDR ;
|
||
break;
|
||
case 1:
|
||
pc = ahb_base->cpu1_start_pc.w;
|
||
reg = (uint32_t *)WDG1_REG_BASEADDR ;
|
||
break;
|
||
case 2:
|
||
pc = ahb_base->cpu2_start_pc.w;
|
||
reg = (uint32_t *)WDG2_REG_BASEADDR ;
|
||
break;
|
||
|
||
}
|
||
|
||
rst_flag = *( (uint32_t *)(0x40000000 + 0x008C) );
|
||
|
||
str_len = iot_snprintf(buf, len, "cpu:%d,ctl0:%08x,ctl1:%08x,cnt:%08x,\
|
||
cmp:%08x,cnts:%08x,cmps:%08x,width:%08x,pc=%08x,rst_flag=%08x\r\n",
|
||
cur_cpu, *(reg + 1),*(reg + 2), *(reg + 4), *(reg + 5), *(reg+6), *(reg+7),
|
||
*(reg+8), pc , rst_flag);
|
||
|
||
my_g_uart_ctrl.puts(port, (uint8_t*)buf, str_len);
|
||
}
|
||
|
||
|
||
/*
|
||
port:输出日志的串口编号
|
||
pin_num:对应串口的txd引脚编号
|
||
buf:输出日志时用的缓存地址
|
||
buf_len:缓存大小
|
||
mode :测试cpurst还是fullrst
|
||
*/
|
||
void core_wdg_test_loop(UART_PORT port, int pin_num, char *buf, int buf_len,
|
||
TEST_MODE mode) {
|
||
uint32_t cnt = 0;
|
||
uint32_t cur_cpu = cpu_get_mhartid();
|
||
|
||
// UART0 init
|
||
my_g_uart_ctrl.init(port);
|
||
my_g_uart_ctrl.config(port, 115200, UART_DATA_8_BITS, UART_STOP_BITS_1,
|
||
UART_PARITY_DISABLE);
|
||
iot_uart_set_pin(port, 0xff, pin_num);
|
||
|
||
//my_g_uart_ctrl.puts(port, (uint8_t*)"00000\r\n", 7);
|
||
|
||
int str_len ;
|
||
|
||
// print start
|
||
str_len = iot_snprintf(buf, buf_len, "CPU %d : Start 0000!!!\r\n", cur_cpu);
|
||
my_g_uart_ctrl.puts(port, (uint8_t*)buf, str_len);
|
||
|
||
delay_sometime(1);
|
||
|
||
//wdg init
|
||
//core_print_regs(port, buf, buf_len, cur_cpu);
|
||
|
||
//str_len = iot_snprintf(buf, buf_len, "CPU %d : Start 111!!!\r\n", cur_cpu);
|
||
//my_g_uart_ctrl.puts(port, (uint8_t*)buf, str_len);
|
||
|
||
wdg_deinit(cur_cpu);
|
||
wdg_init(cur_cpu);
|
||
|
||
if (TEST_MODE_CPURST == mode) {
|
||
wdg_set_cmp(cur_cpu, 32768);//SET_WDG_INTC_CMP);
|
||
wdg_set_timeout_cmp(cur_cpu, 1500);//SET_WDG_TIMEOUT_CMP);
|
||
wdg_set_cpurst_cmp(cur_cpu, 29);//SET_WDG_CPURST_CMP );
|
||
wdg_set_fullrst_cmp(cur_cpu, 1000);//SET_WDG_FULLRST_CMP);
|
||
} else if (TEST_MODE_FULLRST == mode) {
|
||
wdg_set_cmp(cur_cpu, 32768);//SET_WDG_INTC_CMP);
|
||
wdg_set_timeout_cmp(cur_cpu, 15);//SET_WDG_TIMEOUT_CMP);
|
||
wdg_set_cpurst_cmp(cur_cpu, 10);//SET_WDG_CPURST_CMP );
|
||
wdg_set_fullrst_cmp(cur_cpu, 5);//SET_WDG_FULLRST_CMP);
|
||
} else {
|
||
|
||
}
|
||
int times = 0;
|
||
(void)times;
|
||
while(1) {
|
||
//delay_sometime(1);
|
||
//core_print_regs(port, buf, buf_len, cur_cpu);
|
||
#if 0
|
||
if (cur_cpu == 1 || cur_cpu == 2) {
|
||
delay_sometime(1);
|
||
str_len = iot_snprintf(buf, buf_len,
|
||
"core=%d , %d\r\n", cur_cpu, times ++);
|
||
|
||
my_g_uart_ctrl.puts(port, (uint8_t*)buf, str_len);
|
||
|
||
}
|
||
#endif
|
||
if (g_feed_dog[cur_cpu] == 1 && cnt < 5) {
|
||
|
||
str_len = iot_snprintf(buf, buf_len,
|
||
"cnt %d, feed dog cpu%d\r\n", cnt, cur_cpu);
|
||
|
||
my_g_uart_ctrl.puts(port, (uint8_t*)buf, str_len);
|
||
|
||
wdg_feed_dog(cur_cpu);
|
||
|
||
iot_interrupt_unmask(g_wdg_info[cur_cpu].handle);
|
||
g_feed_dog[cur_cpu] = 0;
|
||
cnt++;
|
||
}
|
||
}
|
||
}
|
||
|
||
void core_working_loop(UART_PORT port, int pin_num, char *buf, int buf_len) {
|
||
|
||
uint32_t cur_cpu = cpu_get_mhartid();
|
||
|
||
// UART init
|
||
my_g_uart_ctrl.init(port);
|
||
my_g_uart_ctrl.config(port, 115200, UART_DATA_8_BITS, UART_STOP_BITS_1,
|
||
UART_PARITY_DISABLE);
|
||
|
||
iot_uart_set_pin(port, 0xff, pin_num);
|
||
|
||
int str_len ;
|
||
int inc = 0;
|
||
|
||
while(1) {
|
||
str_len = iot_snprintf(buf, buf_len, "CPU %d : %d\r\n", cur_cpu, inc);
|
||
my_g_uart_ctrl.puts(port, (uint8_t*)buf, str_len);
|
||
inc ++;
|
||
if(inc > 10000)
|
||
inc = 0;
|
||
delay_sometime(1);
|
||
}
|
||
}
|
||
|
||
|
||
void register_print_by_addr(uint32_t addr, int num)
|
||
{
|
||
volatile uint32_t *p_addr = (volatile uint32_t *)addr;
|
||
|
||
iot_printf("base=%08x:", addr);
|
||
for(int i = 0; i < num; i++) {
|
||
iot_printf("[%02x]=%04x_%04x,",
|
||
(uint32_t)p_addr & 0xff, (*p_addr) >> 16, (*p_addr) & 0xffff );
|
||
p_addr ++;
|
||
}
|
||
iot_printf("\r\n");
|
||
}
|
||
|
||
|