risc-v/litex: Add system reset and access to core control registers.
This commit is contained in:
parent
937312242e
commit
50f0fd4df2
@ -45,6 +45,7 @@ config ARCH_CHIP_LITEX
|
||||
select ARCH_RV_ISA_A
|
||||
select ARCH_DCACHE
|
||||
select ARCH_HAVE_TICKLESS
|
||||
select ARCH_HAVE_RESET
|
||||
---help---
|
||||
Enjoy Digital LITEX VEXRISCV softcore processor (RV32IMA).
|
||||
|
||||
|
@ -30,6 +30,7 @@ endif
|
||||
|
||||
# Specify our C code within this directory to be included
|
||||
CHIP_CSRCS = litex_allocateheap.c litex_clockconfig.c
|
||||
CHIP_CSRCS += litex_ctrl.c litex_systemreset.c
|
||||
CHIP_CSRCS += litex_irq.c litex_irq_dispatch.c
|
||||
CHIP_CSRCS += litex_lowputc.c litex_serial.c
|
||||
CHIP_CSRCS += litex_start.c
|
||||
|
@ -60,6 +60,10 @@
|
||||
#define LITEX_SDPHY_BASE 0xf0005000
|
||||
#endif
|
||||
|
||||
/* Litex core control block */
|
||||
|
||||
#define LITEX_CTRL_BASE 0xf0000800
|
||||
|
||||
/* GPIO peripheral definitions.
|
||||
* - LITEX_GPIO_BASE is the first 32-bit address which contains a block
|
||||
* of GPIO registers (peripheral). Each block can contain up to 32 pins.
|
||||
|
108
arch/risc-v/src/litex/litex_ctrl.c
Normal file
108
arch/risc-v/src/litex/litex_ctrl.c
Normal file
@ -0,0 +1,108 @@
|
||||
/****************************************************************************
|
||||
* arch/risc-v/src/litex/litex_ctrl.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "hardware/litex_memorymap.h"
|
||||
#include "riscv_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define LITEX_CTRL_RST_OFFSET 0x00
|
||||
#define LITEX_CTRL_SCRATCH_OFFSET 0x04
|
||||
#define LITEX_CTRL_BUS_ERROR_OFFSET 0x08
|
||||
|
||||
#define LITEX_CTRL_RST_RESET_BIT 0x00
|
||||
|
||||
#define CTRL_REG(X) (LITEX_CTRL_BASE + X)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: litex_ctrl_reset
|
||||
*
|
||||
* Description:
|
||||
* Request a core reset.
|
||||
*
|
||||
* Returned Value:
|
||||
* None: This function should not return.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void litex_ctrl_reset(void)
|
||||
{
|
||||
putreg32(0x1 << LITEX_CTRL_RST_RESET_BIT, CTRL_REG(LITEX_CTRL_RST_OFFSET));
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: litex_ctrl_write_scratch
|
||||
*
|
||||
* Description:
|
||||
* Write a value to the litex control block scratch register.
|
||||
*
|
||||
* Input Parameters:
|
||||
* value - The value to store in the register.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void litex_ctrl_write_scratch(uint32_t value)
|
||||
{
|
||||
putreg32(value, CTRL_REG(LITEX_CTRL_SCRATCH_OFFSET));
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: litex_ctrl_read_scratch
|
||||
*
|
||||
* Description:
|
||||
* Read a stored value from the litex control block scratch register.
|
||||
*
|
||||
* Returned Value:
|
||||
* The value stored in the scratch register.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uint32_t litex_ctrl_read_scratch(void)
|
||||
{
|
||||
return getreg32(CTRL_REG(LITEX_CTRL_SCRATCH_OFFSET));
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: litex_ctrl_read_bus_error
|
||||
*
|
||||
* Description:
|
||||
* Read any bus error reported in the control block.
|
||||
*
|
||||
* Returned Value:
|
||||
* The bus error number stored.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uint32_t litex_ctrl_read_bus_error(void)
|
||||
{
|
||||
return getreg32(CTRL_REG(LITEX_CTRL_BUS_ERROR_OFFSET));
|
||||
}
|
105
arch/risc-v/src/litex/litex_ctrl.h
Normal file
105
arch/risc-v/src/litex/litex_ctrl.h
Normal file
@ -0,0 +1,105 @@
|
||||
/****************************************************************************
|
||||
* arch/risc-v/src/litex/litex_ctrl.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ARCH_RISCV_SRC_LITEX_LITEX_CTRL_H
|
||||
#define __ARCH_RISCV_SRC_LITEX_LITEX_CTRL_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include "chip.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: litex_ctrl_reset
|
||||
*
|
||||
* Description:
|
||||
* Request a core reset.
|
||||
*
|
||||
* Returned Value:
|
||||
* None: This function should not return.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void litex_ctrl_reset(void) noreturn_function;
|
||||
|
||||
/****************************************************************************
|
||||
* Name: litex_ctrl_write_scratch
|
||||
*
|
||||
* Description:
|
||||
* Write a value to the litex control block scratch register.
|
||||
*
|
||||
* Input Parameters:
|
||||
* value - The value to store in the register.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void litex_ctrl_write_scratch(uint32_t value);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: litex_ctrl_read_scratch
|
||||
*
|
||||
* Description:
|
||||
* Read a stored value from the litex control block scratch register.
|
||||
*
|
||||
* Returned Value:
|
||||
* The value stored in the scratch register.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uint32_t litex_ctrl_read_scratch(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: litex_ctrl_read_bus_error
|
||||
*
|
||||
* Description:
|
||||
* Read any bus error reported in the control block.
|
||||
*
|
||||
* Returned Value:
|
||||
* The bus error number stored.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uint32_t litex_ctrl_read_bus_error(void);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __ARCH_RISCV_SRC_LITEX_LITEX_CTRL_H */
|
52
arch/risc-v/src/litex/litex_systemreset.c
Normal file
52
arch/risc-v/src/litex/litex_systemreset.c
Normal file
@ -0,0 +1,52 @@
|
||||
/****************************************************************************
|
||||
* arch/risc-v/src/litex/litex_systemreset.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include "litex_ctrl.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_systemreset
|
||||
*
|
||||
* Description:
|
||||
* Does a warm reset of the core through litex ctrl register block.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void up_systemreset(void)
|
||||
{
|
||||
/* Should not return */
|
||||
|
||||
litex_ctrl_reset();
|
||||
|
||||
for (; ; )
|
||||
{
|
||||
up_mdelay(250);
|
||||
}
|
||||
}
|
@ -32,6 +32,7 @@ CONFIG_ARCH_USE_MMU=y
|
||||
CONFIG_ARCH_USE_MPU=y
|
||||
CONFIG_ARCH_USE_S_MODE=y
|
||||
CONFIG_BINFMT_ELF_EXECUTABLE=y
|
||||
CONFIG_BOARDCTL_RESET=y
|
||||
CONFIG_BOARDCTL_ROMDISK=y
|
||||
CONFIG_BOARD_LATE_INITIALIZE=y
|
||||
CONFIG_BOARD_LOOPSPERMSEC=10000
|
||||
|
@ -32,6 +32,7 @@ CONFIG_ARCH_USE_MMU=y
|
||||
CONFIG_ARCH_USE_MPU=y
|
||||
CONFIG_ARCH_USE_S_MODE=y
|
||||
CONFIG_BINFMT_ELF_EXECUTABLE=y
|
||||
CONFIG_BOARDCTL_RESET=y
|
||||
CONFIG_BOARDCTL_ROMDISK=y
|
||||
CONFIG_BOARD_LATE_INITIALIZE=y
|
||||
CONFIG_BOARD_LOOPSPERMSEC=10000
|
||||
|
@ -28,6 +28,7 @@ CONFIG_ARCH_CHIP_LITEX=y
|
||||
CONFIG_ARCH_INTERRUPTSTACK=8192
|
||||
CONFIG_ARCH_RISCV=y
|
||||
CONFIG_ARCH_STACKDUMP=y
|
||||
CONFIG_BOARDCTL_RESET=y
|
||||
CONFIG_BOARD_LOOPSPERMSEC=10000
|
||||
CONFIG_BUILTIN=y
|
||||
CONFIG_DEBUG_FULLOPT=y
|
||||
|
@ -28,6 +28,7 @@ CONFIG_ARCH_CHIP_LITEX=y
|
||||
CONFIG_ARCH_INTERRUPTSTACK=8192
|
||||
CONFIG_ARCH_RISCV=y
|
||||
CONFIG_ARCH_STACKDUMP=y
|
||||
CONFIG_BOARDCTL_RESET=y
|
||||
CONFIG_BOARD_LOOPSPERMSEC=10000
|
||||
CONFIG_BUILTIN=y
|
||||
CONFIG_DEBUG_FULLOPT=y
|
||||
|
@ -42,4 +42,8 @@ ifeq ($(CONFIG_LITEX_APPLICATION_RAMDISK),y)
|
||||
CSRCS += litex_ramdisk.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_BOARDCTL_RESET),y)
|
||||
CSRCS += litex_reset.c
|
||||
endif
|
||||
|
||||
include $(TOPDIR)/boards/Board.mk
|
||||
|
78
boards/risc-v/litex/arty_a7/src/litex_reset.c
Normal file
78
boards/risc-v/litex/arty_a7/src/litex_reset.c
Normal file
@ -0,0 +1,78 @@
|
||||
/****************************************************************************
|
||||
* boards/risc-v/litex/arty_a7/src/litex_reset.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <nuttx/board.h>
|
||||
#include <nuttx/arch.h>
|
||||
|
||||
#ifdef CONFIG_BOARDCTL_RESET
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_reset
|
||||
*
|
||||
* Description:
|
||||
* Reset board. Support for this function is required by board-level
|
||||
* logic if CONFIG_BOARDCTL_RESET is selected.
|
||||
*
|
||||
* Input Parameters:
|
||||
* status - Status information provided with the reset event. This
|
||||
* meaning of this status information is board-specific. If not
|
||||
* used by a board, the value zero may be provided in calls to
|
||||
* board_reset().
|
||||
*
|
||||
* Returned Value:
|
||||
* If this function returns, then it was not possible to power-off the
|
||||
* board due to some constraints. The return value in this case is a
|
||||
* board-specific reason for the failure to shutdown.
|
||||
*
|
||||
* Additionally: This function is called from assert if
|
||||
* CONFIG_BOARD_RESET_ON_ASSERT >= 1. In this case status is set to
|
||||
* CONFIG_BOARD_ASSERT_RESET_VALUE
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_reset(int status)
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
case CONFIG_BOARD_ASSERT_RESET_VALUE:
|
||||
default:
|
||||
up_systemreset();
|
||||
}
|
||||
|
||||
/* up_systemreset can't actually return. However, let's try to catch the
|
||||
* case that this changes in the future, or the logic is extended to a case
|
||||
* which can fail.
|
||||
*/
|
||||
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BOARDCTL_RESET */
|
Loading…
x
Reference in New Issue
Block a user