add xidatong-riscv64 bsp for nuttx

This commit is contained in:
wgzAIIT
2022-06-17 17:55:30 +08:00
parent 4ee205876a
commit 66d30ed255
30 changed files with 3374 additions and 1 deletions
@@ -17,6 +17,7 @@ cp -rf $current/nuttx $nuttx
cp -rf $current/apps $nuttx
cp -rf $nuttx/aiit_board/aiit-arm32-board $nuttx/nuttx/boards/arm/stm32
cp -rf $nuttx/aiit_board/aiit-riscv64-board $nuttx/nuttx/boards/risc-v/k210
cp -rf $nuttx/aiit_board/xidatong-riscv64 $nuttx/nuttx/boards/risc-v/k210
cp -rf $nuttx/aiit_board/xidatong $nuttx/nuttx/boards/arm/imxrt
cd ../nuttx
@@ -1769,7 +1769,6 @@ void arm_serialinit(void)
uart_register("/dev/ttyS8", &g_uart8port);
#endif
}
}
/****************************************************************************
* Name: up_putc
@@ -0,0 +1,67 @@
############################################################################
# arch/risc-v/src/k210/Make.defs
#
# 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.
#
############################################################################
# Specify our HEAD assembly file. This will be linked as
# the first object file, so it will appear at address 0
HEAD_ASRC = k210_head.S
# Specify our general Assembly files
CMN_ASRCS += riscv_vectors.S riscv_testset.S riscv_exception_common.S
# Specify C code within the common directory to be included
CMN_CSRCS += riscv_initialize.c riscv_swint.c
CMN_CSRCS += riscv_createstack.c riscv_exit.c riscv_fault.c
CMN_CSRCS += riscv_assert.c riscv_blocktask.c riscv_copystate.c riscv_initialstate.c
CMN_CSRCS += riscv_interruptcontext.c riscv_modifyreg32.c riscv_puts.c
CMN_CSRCS += riscv_releasepending.c riscv_reprioritizertr.c
CMN_CSRCS += riscv_releasestack.c riscv_stackframe.c riscv_schedulesigaction.c
CMN_CSRCS += riscv_sigdeliver.c riscv_unblocktask.c riscv_usestack.c
CMN_CSRCS += riscv_mdelay.c riscv_udelay.c riscv_copyfullstate.c riscv_idle.c
CMN_CSRCS += riscv_tcbinfo.c riscv_cpuidlestack.c
ifeq ($(CONFIG_SMP), y)
CMN_CSRCS += riscv_cpuindex.c riscv_cpupause.c riscv_cpustart.c
endif
ifeq ($(CONFIG_SCHED_BACKTRACE),y)
CMN_CSRCS += riscv_backtrace.c
endif
ifeq ($(CONFIG_STACK_COLORATION),y)
CMN_CSRCS += riscv_checkstack.c
endif
ifeq ($(CONFIG_ARCH_HAVE_VFORK),y)
CMN_CSRCS += riscv_vfork.c
endif
# Specify our C code within this directory to be included
CHIP_CSRCS = k210_allocateheap.c k210_clockconfig.c
CHIP_CSRCS += k210_irq.c k210_irq_dispatch.c
CHIP_CSRCS += k210_lowputc.c k210_serial.c k210_fpioa.c
CHIP_CSRCS += k210_start.c k210_timerisr.c k210_gpiohs.c
ifeq ($(CONFIG_BUILD_PROTECTED),y)
CMN_CSRCS += riscv_task_start.c riscv_pthread_start.c
CMN_CSRCS += riscv_signal_dispatch.c
CMN_UASRCS += riscv_signal_handler.S
CHIP_CSRCS += k210_userspace.c
endif
@@ -0,0 +1,92 @@
/****************************************************************************
* arch/risc-v/src/k210/k210_fpioa.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 <debug.h>
#include "riscv_internal.h"
#include "k210_memorymap.h"
#include "k210_fpioa.h"
/****************************************************************************
* Public Functions
****************************************************************************/
int k210_fpioa_get_io_by_function(uint8_t function)
{
int index = 0;
uint32_t RegValue = 0x0000;
uint32_t *fpioa = (uint32_t *)K210_FPIOA_BASE;
for (index = 0; index < K210_IO_NUMBER; index++)
{
RegValue = getreg32(&fpioa[index]);
if ((RegValue & 0xFF) == function)
return index;
}
return -1;
}
int fpioa_set_io_pull(int number, fpioa_pull_t pull)
{
/* Check parameters */
if (number < 0 || number >= K210_IO_NUMBER || pull >= FPIOA_PULL_MAX)
return -1;
/* read register */
uint32_t *fpioa = (uint32_t *)K210_FPIOA_BASE;
fpioa_io_config_t cfg = *(fpioa_io_config_t *)(&fpioa[number]);
uint32_t ioflags = 0x0000;
switch (pull)
{
case FPIOA_PULL_NONE:
cfg.pu = 0;
cfg.pd = 0;
break;
case FPIOA_PULL_DOWN:
cfg.pu = 0;
cfg.pd = 1;
break;
case FPIOA_PULL_UP:
cfg.pu = 1;
cfg.pd = 0;
break;
default:
break;
}
/* write register */
ioflags = *(uint32_t*)(&cfg);
putreg32(ioflags, &fpioa[number]);
return 0;
}
void k210_fpioa_config(uint32_t io, uint32_t ioflags)
{
uint32_t *fpioa = (uint32_t *)K210_FPIOA_BASE;
DEBUGASSERT(io < K210_IO_NUMBER);
putreg32(ioflags, &fpioa[io]);
}
@@ -0,0 +1,123 @@
/****************************************************************************
* arch/risc-v/src/k210/k210_fpioa.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_K210_K210_FPIOA_H
#define __ARCH_RISCV_SRC_K210_K210_FPIOA_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdint.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define K210_IO_NUMBER 48
#define K210_GPIOHS_MAX_PINNO 32
#define K210_IO_FUNC_UARTHS_RX 18 /* UART High speed Receiver */
#define K210_IO_FUNC_UARTHS_TX 19 /* UART High speed Transmitter */
#define K210_IO_FUNC_GPIOHS0 24 /* GPIO High speed 0 */
#define K210_IO_FUNC_GPIOHS1 25 /* GPIO High speed 1 */
#define K210_IO_FUNC_GPIOHS2 26 /* GPIO High speed 2 */
#define K210_IO_FUNC_GPIOHS3 27 /* GPIO High speed 3 */
#define K210_IO_FUNC_GPIOHS4 28 /* GPIO High speed 4 */
#define K210_IO_FUNC_GPIOHS5 29 /* GPIO High speed 5 */
#define K210_IO_FUNC_GPIOHS6 30 /* GPIO High speed 6 */
#define K210_IO_FUNC_GPIOHS7 31 /* GPIO High speed 7 */
#define K210_IO_FUNC_GPIOHS8 32 /* GPIO High speed 8 */
#define K210_IO_FUNC_GPIOHS9 33 /* GPIO High speed 9 */
#define K210_IO_FUNC_GPIOHS10 34 /* GPIO High speed 10 */
#define K210_IO_FUNC_GPIOHS11 35 /* GPIO High speed 11 */
#define K210_IO_FUNC_GPIOHS12 36 /* GPIO High speed 12 */
#define K210_IO_FUNC_GPIOHS13 37 /* GPIO High speed 13 */
#define K210_IO_FUNC_GPIOHS14 38 /* GPIO High speed 14 */
#define K210_IO_FUNC_GPIOHS15 39 /* GPIO High speed 15 */
#define K210_IO_FUNC_GPIOHS16 40 /* GPIO High speed 16 */
#define K210_IO_FUNC_GPIOHS17 41 /* GPIO High speed 17 */
#define K210_IO_FUNC_GPIOHS18 42 /* GPIO High speed 18 */
#define K210_IO_FUNC_GPIOHS19 43 /* GPIO High speed 19 */
#define K210_IO_FUNC_GPIOHS20 44 /* GPIO High speed 20 */
#define K210_IO_FUNC_GPIOHS21 45 /* GPIO High speed 21 */
#define K210_IO_FUNC_GPIOHS22 46 /* GPIO High speed 22 */
#define K210_IO_FUNC_GPIOHS23 47 /* GPIO High speed 23 */
#define K210_IO_FUNC_GPIOHS24 48 /* GPIO High speed 24 */
#define K210_IO_FUNC_GPIOHS25 49 /* GPIO High speed 25 */
#define K210_IO_FUNC_GPIOHS26 50 /* GPIO High speed 26 */
#define K210_IO_FUNC_GPIOHS27 51 /* GPIO High speed 27 */
#define K210_IO_FUNC_GPIOHS28 52 /* GPIO High speed 28 */
#define K210_IO_FUNC_GPIOHS29 53 /* GPIO High speed 29 */
#define K210_IO_FUNC_GPIOHS30 54 /* GPIO High speed 30 */
#define K210_IO_FUNC_GPIOHS31 55 /* GPIO High speed 31 */
#define K210_IO_DS(x) (x << 8) /* Driving Selector */
#define K210_IO_OUTPUT_ENABLE (1 << 12)
#define K210_IO_OUTPUT_INVERT (1 << 13)
#define K210_IO_INPUT_ENABLE (1 << 20)
#define K210_IO_INPUT_INVERT (1 << 21)
#define K210_IO_PULL_DOWN (1 << 16)
#define K210_IO_PULL_UP (3 << 16)
#define K210_IO_PULL_UP_STRONG (7 << 16)
#define K210_IO_SL (1 << 19)
#define K210_IO_ST (1 << 23)
#define K210_IOFLAG_GPIOHS (K210_IO_DS(0xf) | K210_IO_OUTPUT_ENABLE | \
K210_IO_INPUT_ENABLE | K210_IO_ST)
typedef struct _fpioa_io_config
{
uint32_t ch_sel : 8; /* Channel select from 256 input. */
uint32_t ds : 4; /* Driving selector. */
uint32_t oe_en : 1; /* Static output enable, will AND with OE_INV. */
uint32_t oe_inv : 1; /* Invert output enable. */
uint32_t do_sel : 1; /* Data output select: 0 for DO, 1 for OE. */
uint32_t do_inv : 1; /* Invert the result of data output select (DO_SEL). */
uint32_t pu : 1; /* Pull up enable. 0 for nothing, 1 for pull up. */
uint32_t pd : 1; /* Pull down enable. 0 for nothing, 1 for pull down. */
uint32_t resv0 : 1; /* Reserved bits. */
uint32_t sl : 1; /* Slew rate control enable. */
uint32_t ie_en : 1; /* Static input enable, will AND with IE_INV. */
uint32_t ie_inv : 1; /* Invert input enable. */
uint32_t di_inv : 1; /* Invert Data input. */
uint32_t st : 1; /* Schmitt trigger. */
uint32_t resv1 : 7; /* Reserved bits. */
uint32_t pad_di : 1; /* Read current IO's data input. */
} __attribute__((packed, aligned(4))) fpioa_io_config_t;
typedef enum _fpioa_pull
{
FPIOA_PULL_NONE, /* No Pull */
FPIOA_PULL_DOWN, /* Pull Down */
FPIOA_PULL_UP, /* Pull Up */
FPIOA_PULL_MAX /* Count of pull settings */
} fpioa_pull_t;
/****************************************************************************
* Public Functions Prototypes
****************************************************************************/
int k210_fpioa_get_io_by_function(uint8_t function);
int fpioa_set_io_pull(int number, fpioa_pull_t pull);
void k210_fpioa_config(uint32_t io, uint32_t ioflags);
#endif /* __ARCH_RISCV_SRC_K210_K210_FPIOA_H */
@@ -0,0 +1,111 @@
/****************************************************************************
* arch/risc-v/src/k210/k210_gpiohs.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 <debug.h>
#include "riscv_internal.h"
#include "k210_memorymap.h"
#include "k210_gpiohs.h"
#include "k210_fpioa.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define GPIOHS_INPUT_VAL_OFFSET 0x00
#define GPIOHS_INPUT_EN_OFFSET 0x04
#define GPIOHS_OUTPUT_EN_OFFSET 0x08
#define GPIOHS_OUTPUT_VAL_OFFSET 0x0c
#define GPIOHS_PULLUP_EN_OFFSET 0x10
#define GPIOHS_DRIVE_OFFSET 0x14
#define GPIOHS_INPUT (K210_GPIOHS_BASE + GPIOHS_INPUT_VAL_OFFSET)
#define GPIOHS_INPUT_EN (K210_GPIOHS_BASE + GPIOHS_INPUT_EN_OFFSET)
#define GPIOHS_OUTPUT (K210_GPIOHS_BASE + GPIOHS_OUTPUT_VAL_OFFSET)
#define GPIOHS_OUTPUT_EN (K210_GPIOHS_BASE + GPIOHS_OUTPUT_EN_OFFSET)
/****************************************************************************
* Public Functions
****************************************************************************/
void k210_gpiohs_set_direction(uint32_t io, gpio_drive_mode_t mode)
{
DEBUGASSERT(io < K210_GPIOHS_MAX_PINNO);
int io_number = k210_fpioa_get_io_by_function(K210_IO_FUNC_GPIOHS0 + io);
DEBUGASSERT(io_number >= 0);
fpioa_pull_t pull = FPIOA_PULL_NONE;
uint32_t dir = 0;
switch (mode)
{
case GPIO_DM_INPUT:
pull = FPIOA_PULL_NONE;
dir = 0;
break;
case GPIO_DM_INPUT_PULL_DOWN:
pull = FPIOA_PULL_DOWN;
dir = 0;
break;
case GPIO_DM_INPUT_PULL_UP:
pull = FPIOA_PULL_UP;
dir = 0;
break;
case GPIO_DM_OUTPUT:
pull = FPIOA_PULL_DOWN;
dir = 1;
break;
default:
DEBUGASSERT(!"GPIO drive mode is not supported.");
break;
}
fpioa_set_io_pull(io_number, pull);
uint32_t outbit = dir << io;
uint32_t inbit = (!dir) << io;
modifyreg32(GPIOHS_OUTPUT_EN, inbit, outbit);
modifyreg32(GPIOHS_INPUT_EN, outbit, inbit);
}
void k210_gpiohs_set_value(uint32_t io, bool val)
{
uint32_t setbit = val << io;
uint32_t clrbit = (!val) << io;
modifyreg32(GPIOHS_OUTPUT, clrbit, setbit);
}
bool k210_gpiohs_get_value(uint32_t io)
{
uint32_t reg = getreg32(GPIOHS_INPUT);
if (reg & (1 << io))
{
return true;
}
else
{
return false;
}
}
@@ -0,0 +1,87 @@
/****************************************************************************
* arch/risc-v/src/k210/k210_gpiohs.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_K210_K210_GPIOHS_H
#define __ARCH_RISCV_SRC_K210_K210_GPIOHS_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdint.h>
#include <stdbool.h>
typedef enum _gpio_drive_mode
{
GPIO_DM_INPUT,
GPIO_DM_INPUT_PULL_DOWN,
GPIO_DM_INPUT_PULL_UP,
GPIO_DM_OUTPUT,
} gpio_drive_mode_t;
/****************************************************************************
* Public Functions Prototypes
****************************************************************************/
/****************************************************************************
* Name: k210_gpiohs_set_direction
*
* Description:
* Set gpiohs direction
*
* Input Parameters:
* io - IO number
* dir - true for output, false for input
*
****************************************************************************/
void k210_gpiohs_set_direction(uint32_t io, gpio_drive_mode_t mode);
/****************************************************************************
* Name: k210_gpiohs_set_value
*
* Description:
* Set gpiohs direction
*
* Input Parameters:
* io - IO number
* dir - true for high level, false for low level
*
****************************************************************************/
void k210_gpiohs_set_value(uint32_t io, bool val);
/****************************************************************************
* Name: k210_gpiohs_get_value
*
* Description:
* Get gpiohs level
*
* Input Parameters:
* io - IO number
*
* Returned Value:
* true for high level, false for low level
*
****************************************************************************/
bool k210_gpiohs_get_value(uint32_t io);
#endif /* __ARCH_RISCV_SRC_K210_K210_GPIOHS_H */
@@ -694,6 +694,14 @@ config ARCH_BOARD_AIIT_RISCV64
This is the board configuration for the port of NuttX to the
aiit-riscv64 board. This board features the RISC-V K210
config ARCH_BOARD_XIDATONG_RISCV64
bool "xidatong riscv64 board"
depends on ARCH_CHIP_K210
select ARCH_HAVE_LEDS if !K210_WITH_QEMU
---help---
This is the board configuration for the port of NuttX to the
xidatong-riscv64 board. This board features the RISC-V K210
config ARCH_BOARD_SMARTL_C906
bool "smartl evaluation board for C906"
depends on ARCH_CHIP_C906
@@ -2488,6 +2496,7 @@ config ARCH_BOARD
default "lx_cpu" if ARCH_BOARD_LX_CPU
default "maix-bit" if ARCH_BOARD_MAIX_BIT
default "aiit-riscv64-board" if ARCH_BOARD_AIIT_RISCV64
default "xidatong-riscv64" if ARCH_BOARD_XIDATONG_RISCV64
default "smartl-c906" if ARCH_BOARD_SMARTL_C906
default "icicle" if ARCH_BOARD_ICICLE_MPFS
default "m100pfsevp" if ARCH_BOARD_M100PFSEVP_MPFS
@@ -3320,6 +3329,9 @@ endif
if ARCH_BOARD_AIIT_RISCV64
source "boards/risc-v/k210/aiit-riscv64-board/Kconfig"
endif
if ARCH_BOARD_XIDATONG_RISCV64
source "boards/risc-v/k210/xidatong-riscv64/Kconfig"
endif
if ARCH_BOARD_SMARTL_C906
source "boards/risc-v/c906/smartl-c906/Kconfig"
endif