From a8928c881ed935a1e2a45bb02bd0b2a7fe8d45d4 Mon Sep 17 00:00:00 2001 From: michael Date: Mon, 14 Sep 2020 11:10:44 +0800 Subject: [PATCH 1/6] MIPS:fix the RT_EXCEPTION_MAX value from know that cp0_cause's ExcCode have 5 bit filed and the max exception is 32. --- libcpu/mips/common/exception.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libcpu/mips/common/exception.c b/libcpu/mips/common/exception.c index 94be475878..3da8ecead6 100644 --- a/libcpu/mips/common/exception.c +++ b/libcpu/mips/common/exception.c @@ -74,7 +74,7 @@ void rt_hw_interrupt_enable(rt_base_t level) /** * exception handle table */ -#define RT_EXCEPTION_MAX 31 +#define RT_EXCEPTION_MAX 32 exception_func_t sys_exception_handlers[RT_EXCEPTION_MAX]; /** From b86d608d631d5d50f51e202d8e28107b2dd69f9a Mon Sep 17 00:00:00 2001 From: michael Date: Tue, 15 Sep 2020 11:20:15 +0800 Subject: [PATCH 2/6] bsp:ls2k: add reboot and shutdown support --- bsp/ls2kdev/drivers/board.c | 5 +++++ bsp/ls2kdev/drivers/board.h | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/bsp/ls2kdev/drivers/board.c b/bsp/ls2kdev/drivers/board.c index 6a66777121..f970e60574 100644 --- a/bsp/ls2kdev/drivers/board.c +++ b/bsp/ls2kdev/drivers/board.c @@ -22,6 +22,9 @@ */ void rt_hw_cpu_reset(void) { + WDT_EN = 0x01; + WDT_TIMER = 0x01; + WDT_SET = 0x01; rt_kprintf("reboot system...\n"); while (1); } @@ -32,6 +35,8 @@ void rt_hw_cpu_reset(void) */ void rt_hw_cpu_shutdown(void) { + PM1_STS &= 0xffffffff; + PM1_CNT = 0x3c00; rt_kprintf("shutdown...\n"); while (1); diff --git a/bsp/ls2kdev/drivers/board.h b/bsp/ls2kdev/drivers/board.h index ca57ebf3f2..3c9347931c 100644 --- a/bsp/ls2kdev/drivers/board.h +++ b/bsp/ls2kdev/drivers/board.h @@ -12,6 +12,8 @@ #define BOARD_H__ #include +#include +#include "ls2k1000.h" extern unsigned char __bss_end; @@ -19,6 +21,28 @@ extern unsigned char __bss_end; #define RT_HW_HEAP_BEGIN (void*)&__bss_end #define RT_HW_HEAP_END (void*)(RT_HW_HEAP_BEGIN + 64 * 1024 * 1024) +/* + * General PM Configuration Register + */ +#define PMCON_BASE (APB_BASE | (0x7 << 12)) + +/* + * Power Management1 Configuration Registers + */ +#define PM1_BASE (PMCON_BASE + 0x0C) +#define PM1_STS HWREG32(PM1_BASE) +#define PM1_EN HWREG32(PM1_BASE + 0x04) +#define PM1_CNT HWREG32(PM1_BASE + 0x08) + +/* + * Watch Dog Configuration Registers + */ +#define WDT_BASE (PMCON_BASE + 0x30) +#define WDT_EN HWREG32(WDT_BASE) +#define WDT_SET HWREG32(WDT_BASE + 0x04) +#define WDT_TIMER HWREG32(WDT_BASE + 0x08) + + void rt_hw_board_init(void); #endif From dd3677180179c310686b368a67cb801fe807b5e8 Mon Sep 17 00:00:00 2001 From: michael Date: Tue, 15 Sep 2020 11:25:37 +0800 Subject: [PATCH 3/6] bsp:ls2k:add reboot and power command --- bsp/ls2kdev/applications/pmcon.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 bsp/ls2kdev/applications/pmcon.c diff --git a/bsp/ls2kdev/applications/pmcon.c b/bsp/ls2kdev/applications/pmcon.c new file mode 100644 index 0000000000..82bca9c947 --- /dev/null +++ b/bsp/ls2kdev/applications/pmcon.c @@ -0,0 +1,15 @@ +#include + +static void reboot() +{ + rt_hw_cpu_reset(); +} +MSH_CMD_EXPORT(reboot, reboot sample); + + +static void poweroff() +{ + rt_hw_cpu_shutdown(); +} +MSH_CMD_EXPORT(poweroff, shutdown power sample); + From 93bcc2e0d289bc455dd9ac9ca58818ff9ec1c690 Mon Sep 17 00:00:00 2001 From: michael Date: Tue, 15 Sep 2020 11:34:29 +0800 Subject: [PATCH 4/6] unify code format --- bsp/ls2kdev/drivers/board.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/bsp/ls2kdev/drivers/board.h b/bsp/ls2kdev/drivers/board.h index 3c9347931c..da7d5ea2f2 100644 --- a/bsp/ls2kdev/drivers/board.h +++ b/bsp/ls2kdev/drivers/board.h @@ -24,23 +24,23 @@ extern unsigned char __bss_end; /* * General PM Configuration Register */ -#define PMCON_BASE (APB_BASE | (0x7 << 12)) +#define PMCON_BASE (APB_BASE | (0x7 << 12)) /* * Power Management1 Configuration Registers */ -#define PM1_BASE (PMCON_BASE + 0x0C) -#define PM1_STS HWREG32(PM1_BASE) -#define PM1_EN HWREG32(PM1_BASE + 0x04) -#define PM1_CNT HWREG32(PM1_BASE + 0x08) +#define PM1_BASE (PMCON_BASE + 0x0C) +#define PM1_STS HWREG32(PM1_BASE) +#define PM1_EN HWREG32(PM1_BASE + 0x04) +#define PM1_CNT HWREG32(PM1_BASE + 0x08) /* * Watch Dog Configuration Registers */ -#define WDT_BASE (PMCON_BASE + 0x30) -#define WDT_EN HWREG32(WDT_BASE) -#define WDT_SET HWREG32(WDT_BASE + 0x04) -#define WDT_TIMER HWREG32(WDT_BASE + 0x08) +#define WDT_BASE (PMCON_BASE + 0x30) +#define WDT_EN HWREG32(WDT_BASE) +#define WDT_SET HWREG32(WDT_BASE + 0x04) +#define WDT_TIMER HWREG32(WDT_BASE + 0x08) void rt_hw_board_init(void); From 623bf0abc923210c1b990210a421660122b6c296 Mon Sep 17 00:00:00 2001 From: michael Date: Thu, 17 Sep 2020 10:27:04 +0800 Subject: [PATCH 5/6] bsp:ls2k:unify code format --- bsp/ls2kdev/applications/pmcon.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/bsp/ls2kdev/applications/pmcon.c b/bsp/ls2kdev/applications/pmcon.c index 82bca9c947..92b06cc8f2 100644 --- a/bsp/ls2kdev/applications/pmcon.c +++ b/bsp/ls2kdev/applications/pmcon.c @@ -1,15 +1,26 @@ +/* + * Copyright (c) 2006-2020, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2020-09-17 maoxiaochuan first version + */ + + #include static void reboot() { - rt_hw_cpu_reset(); + rt_hw_cpu_reset(); } -MSH_CMD_EXPORT(reboot, reboot sample); +MSH_CMD_EXPORT(reboot, reboot system); static void poweroff() { - rt_hw_cpu_shutdown(); + rt_hw_cpu_shutdown(); } -MSH_CMD_EXPORT(poweroff, shutdown power sample); +MSH_CMD_EXPORT(poweroff, shutdown system); From ab78ea1de1ce3841a36e4b2b08ce938c1a6fc4f8 Mon Sep 17 00:00:00 2001 From: michael Date: Thu, 17 Sep 2020 20:22:51 +0800 Subject: [PATCH 6/6] bsp:ls2k:improved implement of shutdown and reboot command --- bsp/ls2kdev/applications/pmcon.c | 26 -------------------------- bsp/ls2kdev/drivers/board.c | 5 +++++ bsp/ls2kdev/drivers/board.h | 24 ------------------------ bsp/ls2kdev/drivers/ls2k1000.h | 23 +++++++++++++++++++++++ 4 files changed, 28 insertions(+), 50 deletions(-) delete mode 100644 bsp/ls2kdev/applications/pmcon.c diff --git a/bsp/ls2kdev/applications/pmcon.c b/bsp/ls2kdev/applications/pmcon.c deleted file mode 100644 index 92b06cc8f2..0000000000 --- a/bsp/ls2kdev/applications/pmcon.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2006-2020, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2020-09-17 maoxiaochuan first version - */ - - -#include - -static void reboot() -{ - rt_hw_cpu_reset(); -} -MSH_CMD_EXPORT(reboot, reboot system); - - -static void poweroff() -{ - rt_hw_cpu_shutdown(); -} -MSH_CMD_EXPORT(poweroff, shutdown system); - diff --git a/bsp/ls2kdev/drivers/board.c b/bsp/ls2kdev/drivers/board.c index f970e60574..30fb59091a 100644 --- a/bsp/ls2kdev/drivers/board.c +++ b/bsp/ls2kdev/drivers/board.c @@ -16,6 +16,8 @@ #include "exception.h" #include "drv_uart.h" #include "board.h" +#include "ls2k1000.h" + /** * this function will reset CPU * @@ -28,6 +30,8 @@ void rt_hw_cpu_reset(void) rt_kprintf("reboot system...\n"); while (1); } +MSH_CMD_EXPORT_ALIAS(rt_hw_cpu_reset, reboot, reset cpu); + /** * this function will shutdown CPU @@ -41,6 +45,7 @@ void rt_hw_cpu_shutdown(void) while (1); } +MSH_CMD_EXPORT_ALIAS(rt_hw_cpu_shutdown, poweroff, shutdown cpu); /** diff --git a/bsp/ls2kdev/drivers/board.h b/bsp/ls2kdev/drivers/board.h index da7d5ea2f2..ca57ebf3f2 100644 --- a/bsp/ls2kdev/drivers/board.h +++ b/bsp/ls2kdev/drivers/board.h @@ -12,8 +12,6 @@ #define BOARD_H__ #include -#include -#include "ls2k1000.h" extern unsigned char __bss_end; @@ -21,28 +19,6 @@ extern unsigned char __bss_end; #define RT_HW_HEAP_BEGIN (void*)&__bss_end #define RT_HW_HEAP_END (void*)(RT_HW_HEAP_BEGIN + 64 * 1024 * 1024) -/* - * General PM Configuration Register - */ -#define PMCON_BASE (APB_BASE | (0x7 << 12)) - -/* - * Power Management1 Configuration Registers - */ -#define PM1_BASE (PMCON_BASE + 0x0C) -#define PM1_STS HWREG32(PM1_BASE) -#define PM1_EN HWREG32(PM1_BASE + 0x04) -#define PM1_CNT HWREG32(PM1_BASE + 0x08) - -/* - * Watch Dog Configuration Registers - */ -#define WDT_BASE (PMCON_BASE + 0x30) -#define WDT_EN HWREG32(WDT_BASE) -#define WDT_SET HWREG32(WDT_BASE + 0x04) -#define WDT_TIMER HWREG32(WDT_BASE + 0x08) - - void rt_hw_board_init(void); #endif diff --git a/bsp/ls2kdev/drivers/ls2k1000.h b/bsp/ls2kdev/drivers/ls2k1000.h index 38e83875fb..668d484d9c 100644 --- a/bsp/ls2kdev/drivers/ls2k1000.h +++ b/bsp/ls2kdev/drivers/ls2k1000.h @@ -3,6 +3,7 @@ #include #include "interrupt.h" +#include #define APB_BASE CKSEG1ADDR(0xbfe00000) @@ -24,6 +25,28 @@ #define GEN_CONFIG0_REG (0xFFFFFFFFBfe10420) + +/* + * General PM Configuration Register + */ +#define PMCON_BASE (APB_BASE | (0x7 << 12)) + +/* + * Power Management1 Configuration Registers + */ +#define PM1_BASE (PMCON_BASE + 0x0C) +#define PM1_STS HWREG32(PM1_BASE) +#define PM1_EN HWREG32(PM1_BASE + 0x04) +#define PM1_CNT HWREG32(PM1_BASE + 0x08) + +/* + * Watch Dog Configuration Registers + */ +#define WDT_BASE (PMCON_BASE + 0x30) +#define WDT_EN HWREG32(WDT_BASE) +#define WDT_SET HWREG32(WDT_BASE + 0x04) +#define WDT_TIMER HWREG32(WDT_BASE + 0x08) + void rt_hw_timer_handler(void); void rt_hw_uart_init(void);