diff --git a/arch/risc-v/src/k210/Make.defs b/arch/risc-v/src/k210/Make.defs index c8ad47e5fe..718a785f7b 100644 --- a/arch/risc-v/src/k210/Make.defs +++ b/arch/risc-v/src/k210/Make.defs @@ -47,6 +47,7 @@ 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 k210_schedulesigaction.c CMN_CSRCS += riscv_sigdeliver.c riscv_unblocktask.c riscv_usestack.c +CMN_CSRCS += riscv_mdelay.c ifeq ($(CONFIG_STACK_COLORATION),y) CMN_CSRCS += riscv_checkstack.c diff --git a/arch/risc-v/src/k210/k210_fpioa.h b/arch/risc-v/src/k210/k210_fpioa.h index 5b13884a26..b3c7349634 100644 --- a/arch/risc-v/src/k210/k210_fpioa.h +++ b/arch/risc-v/src/k210/k210_fpioa.h @@ -80,8 +80,8 @@ #define K210_IO_SL (1 << 19) #define K210_IO_ST (1 << 23) -#define K210_FLAG_GPIOHS (K210_IO_DS(0xf) | K210_IO_OUTPUT_ENABLE | \ - K210_IO_INPUT_ENABLE | K210_IO_ST) +#define K210_IOFLAG_GPIOHS (K210_IO_DS(0xf) | K210_IO_OUTPUT_ENABLE | \ + K210_IO_INPUT_ENABLE | K210_IO_ST) /**************************************************************************** * Public Functions Prototypes diff --git a/boards/Kconfig b/boards/Kconfig index 860f3ecbea..917903f0b4 100644 --- a/boards/Kconfig +++ b/boards/Kconfig @@ -549,6 +549,7 @@ config ARCH_BOARD_LX_CPU config ARCH_BOARD_MAIX_BIT bool "Sipeed Maix Bit board" depends on ARCH_CHIP_K210 + select ARCH_HAVE_LEDS ---help--- This is the board configuration for the port of NuttX to the Sipeed Maix Bit board. This board features the RISC-V K210 diff --git a/boards/risc-v/k210/maix-bit/include/board.h b/boards/risc-v/k210/maix-bit/include/board.h index b0127c3c72..c3862bc51b 100644 --- a/boards/risc-v/k210/maix-bit/include/board.h +++ b/boards/risc-v/k210/maix-bit/include/board.h @@ -48,6 +48,28 @@ #include "k210.h" +#include "k210_fpioa.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define BOARD_LED_PAD 14 /* Connected to red led */ + +/* Map pad 14 to gpiohs io 0 */ + +#define BOARD_LED_IO_FUNC K210_IO_FUNC_GPIOHS0 +#define BOARD_LED_IO 0 + +#define LED_STARTED 0 /* N/C */ +#define LED_HEAPALLOCATE 1 /* N/C */ +#define LED_IRQSENABLED 2 /* N/C */ +#define LED_STACKCREATED 3 /* N/C */ +#define LED_INIRQ 4 /* N/C */ +#define LED_SIGNAL 5 /* N/C */ +#define LED_ASSERTION 6 /* N/C */ +#define LED_PANIC 7 /* blink */ + /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/boards/risc-v/k210/maix-bit/src/Makefile b/boards/risc-v/k210/maix-bit/src/Makefile index dc91ae4a96..cbb092ecb3 100644 --- a/boards/risc-v/k210/maix-bit/src/Makefile +++ b/boards/risc-v/k210/maix-bit/src/Makefile @@ -41,4 +41,8 @@ ifeq ($(CONFIG_LIB_BOARDCTL),y) CSRCS += k210_appinit.c endif +ifeq ($(CONFIG_ARCH_LEDS),y) +CSRCS += k210_leds.c +endif + include $(TOPDIR)/boards/Board.mk diff --git a/boards/risc-v/k210/maix-bit/src/k210_boot.c b/boards/risc-v/k210/maix-bit/src/k210_boot.c index fe08418860..8c6f42c980 100644 --- a/boards/risc-v/k210/maix-bit/src/k210_boot.c +++ b/boards/risc-v/k210/maix-bit/src/k210_boot.c @@ -41,6 +41,7 @@ #include +#include #include /**************************************************************************** @@ -68,4 +69,5 @@ void k210_boardinitialize(void) { + board_autoled_initialize(); } diff --git a/boards/risc-v/k210/maix-bit/src/k210_leds.c b/boards/risc-v/k210/maix-bit/src/k210_leds.c new file mode 100644 index 0000000000..15442cb510 --- /dev/null +++ b/boards/risc-v/k210/maix-bit/src/k210_leds.c @@ -0,0 +1,59 @@ +/**************************************************************************** + * boards/risc-v/k210/maix-bit/src/k210_leds.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 + +#include + +#include + +#include "k210_fpioa.h" +#include "k210_gpiohs.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +void board_autoled_initialize(void) +{ + k210_fpioa_config(BOARD_LED_PAD, BOARD_LED_IO_FUNC | K210_IOFLAG_GPIOHS); + k210_gpiohs_set_direction(BOARD_LED_IO, true); + k210_gpiohs_set_value(BOARD_LED_IO, true); /* LED off */ +} + +void board_autoled_on(int led) +{ + if (led == LED_PANIC) + { + k210_gpiohs_set_value(BOARD_LED_IO, false); + } +} + +void board_autoled_off(int led) +{ + if (led == LED_PANIC) + { + k210_gpiohs_set_value(BOARD_LED_IO, true); + } +}