forked from xuos/xiuos
Merge pull request 'merge code' (#74) from xidatong-riscv64 into e22lora
This commit is contained in:
commit
d28caa835a
|
@ -56,7 +56,7 @@ endif
|
|||
CHIP_CSRCS = k210_allocateheap.c k210_clockconfig.c
|
||||
CHIP_CSRCS += k210_irq.c k210_irq_dispatch.c k210_systemreset.c
|
||||
CHIP_CSRCS += k210_lowputc.c k210_serial.c k210_fpioa.c
|
||||
CHIP_CSRCS += k210_start.c k210_timerisr.c k210_gpiohs.c
|
||||
CHIP_CSRCS += k210_start.c k210_timerisr.c k210_gpiohs.c k210_gpio.c
|
||||
|
||||
ifeq ($(CONFIG_BUILD_PROTECTED),y)
|
||||
CMN_CSRCS += riscv_task_start.c riscv_pthread_start.c
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
/****************************************************************************
|
||||
* arch/risc-v/src/k210/hardware/k210_memorymap.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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file k210_memorymap.h
|
||||
* @brief nuttx source code
|
||||
* https://github.com/apache/incubator-nuttx.git
|
||||
* @version 10.3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2022-06-30
|
||||
*/
|
||||
|
||||
#ifndef __ARCH_RISCV_SRC_K210_HARDWARE_K210_MEMORYMAP_H
|
||||
#define __ARCH_RISCV_SRC_K210_HARDWARE_K210_MEMORYMAP_H
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Register Base Address ****************************************************/
|
||||
|
||||
#define K210_CLINT_BASE 0x02000000
|
||||
#define K210_PLIC_BASE 0x0c000000
|
||||
|
||||
#ifdef CONFIG_K210_WITH_QEMU
|
||||
#define K210_UART0_BASE 0x10010000
|
||||
#else
|
||||
#define K210_UART0_BASE 0x38000000
|
||||
#endif
|
||||
#define K210_GPIOHS_BASE 0x38001000
|
||||
#define K210_GPIO_BASE 0x50200000
|
||||
#define K210_FPIOA_BASE 0x502B0000
|
||||
|
||||
#define K210_SYSCTL_BASE 0x50440000
|
||||
|
||||
#endif /* __ARCH_RISCV_SRC_K210_HARDWARE_K210_MEMORYMAP_H */
|
|
@ -45,52 +45,52 @@
|
|||
****************************************************************************/
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
/* 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;
|
||||
/* 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;
|
||||
}
|
||||
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;
|
||||
/* write register */
|
||||
ioflags = *(uint32_t*)(&cfg);
|
||||
putreg32(ioflags, &fpioa[number]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void k210_fpioa_config(uint32_t io, uint32_t ioflags)
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
|
||||
#define K210_IO_NUMBER 48
|
||||
#define K210_GPIOHS_MAX_PINNO 32
|
||||
#define K210_GPIO_MAX_PINNO 8
|
||||
|
||||
#define K210_IO_FUNC_UARTHS_RX 18 /* UART High speed Receiver */
|
||||
#define K210_IO_FUNC_UARTHS_TX 19 /* UART High speed Transmitter */
|
||||
|
@ -77,6 +78,14 @@
|
|||
#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_FUNC_GPIO0 56 /* GPIO pin 0 */
|
||||
#define K210_IO_FUNC_GPIO1 57 /* GPIO pin 1 */
|
||||
#define K210_IO_FUNC_GPIO2 58 /* GPIO pin 2 */
|
||||
#define K210_IO_FUNC_GPIO3 59 /* GPIO pin 3 */
|
||||
#define K210_IO_FUNC_GPIO4 60 /* GPIO pin 4 */
|
||||
#define K210_IO_FUNC_GPIO5 61 /* GPIO pin 5 */
|
||||
#define K210_IO_FUNC_GPIO6 62 /* GPIO pin 6 */
|
||||
#define K210_IO_FUNC_GPIO7 63 /* GPIO pin 7 */
|
||||
|
||||
#define K210_IO_DS(x) (x << 8) /* Driving Selector */
|
||||
|
||||
|
|
|
@ -0,0 +1,121 @@
|
|||
/****************************************************************************
|
||||
* arch/risc-v/src/k210/k210_gpio.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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file k210_gpio.c
|
||||
* @brief nuttx source code
|
||||
* https://github.com/apache/incubator-nuttx.git
|
||||
* @version 10.3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2022-06-30
|
||||
*/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include "riscv_internal.h"
|
||||
#include "k210_memorymap.h"
|
||||
#include "k210_gpio.h"
|
||||
#include "k210_fpioa.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define GPIO_INPUT_VAL_OFFSET 0x00
|
||||
#define GPIO_INPUT_EN_OFFSET 0x04
|
||||
#define GPIO_OUTPUT_EN_OFFSET 0x08
|
||||
#define GPIO_OUTPUT_VAL_OFFSET 0x0c
|
||||
#define GPIO_PULLUP_EN_OFFSET 0x10
|
||||
#define GPIO_DRIVE_OFFSET 0x14
|
||||
|
||||
#define GPIO_INPUT (K210_GPIO_BASE + GPIO_INPUT_VAL_OFFSET)
|
||||
#define GPIO_INPUT_EN (K210_GPIO_BASE + GPIO_INPUT_EN_OFFSET)
|
||||
#define GPIO_OUTPUT (K210_GPIO_BASE + GPIO_OUTPUT_VAL_OFFSET)
|
||||
#define GPIO_OUTPUT_EN (K210_GPIO_BASE + GPIO_OUTPUT_EN_OFFSET)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
void k210_gpio_set_direction(uint32_t io, gpio_drive_mode_t mode)
|
||||
{
|
||||
DEBUGASSERT(io < K210_GPIO_MAX_PINNO);
|
||||
int io_number = fpioa_get_io_by_function(K210_IO_FUNC_GPIO0 + 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(GPIO_OUTPUT_EN, inbit, outbit);
|
||||
modifyreg32(GPIO_INPUT_EN, outbit, inbit);
|
||||
}
|
||||
|
||||
void k210_gpio_set_value(uint32_t io, bool val)
|
||||
{
|
||||
uint32_t setbit = val << io;
|
||||
uint32_t clrbit = (!val) << io;
|
||||
modifyreg32(GPIO_OUTPUT, clrbit, setbit);
|
||||
}
|
||||
|
||||
bool k210_gpio_get_value(uint32_t io)
|
||||
{
|
||||
uint32_t reg = getreg32(GPIO_INPUT);
|
||||
|
||||
if (reg & (1 << io))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
/****************************************************************************
|
||||
* arch/risc-v/src/k210/k210_gpio.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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file k210_gpio.h
|
||||
* @brief nuttx source code
|
||||
* https://github.com/apache/incubator-nuttx.git
|
||||
* @version 10.3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2022-06-30
|
||||
*/
|
||||
|
||||
#ifndef __ARCH_RISCV_SRC_K210_K210_GPIO_H
|
||||
#define __ARCH_RISCV_SRC_K210_K210_GPIO_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "k210_gpio_common.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: k210_gpio_set_direction
|
||||
*
|
||||
* Description:
|
||||
* Set gpiohs direction
|
||||
*
|
||||
* Input Parameters:
|
||||
* io - IO number
|
||||
* dir - true for output, false for input
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void k210_gpio_set_direction(uint32_t io, gpio_drive_mode_t mode);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: k210_gpio_set_value
|
||||
*
|
||||
* Description:
|
||||
* Set gpiohs direction
|
||||
*
|
||||
* Input Parameters:
|
||||
* io - IO number
|
||||
* dir - true for high level, false for low level
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void k210_gpio_set_value(uint32_t io, bool val);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: k210_gpio_get_value
|
||||
*
|
||||
* Description:
|
||||
* Get gpiohs level
|
||||
*
|
||||
* Input Parameters:
|
||||
* io - IO number
|
||||
*
|
||||
* Returned Value:
|
||||
* true for high level, false for low level
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
bool k210_gpio_get_value(uint32_t io);
|
||||
|
||||
#endif /* __ARCH_RISCV_SRC_K210_K210_GPIO_H */
|
|
@ -0,0 +1,66 @@
|
|||
/****************************************************************************
|
||||
* arch/risc-v/src/k210/k210_gpio_common
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file k210_gpio_common.h
|
||||
* @brief nuttx source code
|
||||
* https://github.com/apache/incubator-nuttx.git
|
||||
* @version 10.3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2022-06-30
|
||||
*/
|
||||
|
||||
#ifndef __ARCH_RISCV_SRC_K210_GPIO_COMMON_H
|
||||
#define __ARCH_RISCV_SRC_K210_GPIO_COMMON_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
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;
|
||||
|
||||
typedef enum _gpio_pin_edge
|
||||
{
|
||||
GPIO_PE_NONE,
|
||||
GPIO_PE_FALLING,
|
||||
GPIO_PE_RISING,
|
||||
GPIO_PE_BOTH,
|
||||
GPIO_PE_LOW,
|
||||
GPIO_PE_HIGH = 8,
|
||||
} gpio_pin_edge_t;
|
||||
|
||||
typedef enum _gpio_pin_value
|
||||
{
|
||||
GPIO_PV_LOW,
|
||||
GPIO_PV_HIGH
|
||||
} gpio_pin_value_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ARCH_RISCV_SRC_K210_GPIO_COMMON_H */
|
||||
|
|
@ -68,28 +68,28 @@ void k210_gpiohs_set_direction(uint32_t io, gpio_drive_mode_t mode)
|
|||
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;
|
||||
}
|
||||
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;
|
||||
|
|
|
@ -36,14 +36,7 @@
|
|||
|
||||
#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;
|
||||
#include "k210_gpio_common.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions Prototypes
|
||||
|
|
|
@ -35,8 +35,8 @@
|
|||
|
||||
typedef struct _k210_soft_reset
|
||||
{
|
||||
uint32_t soft_reset : 1;
|
||||
uint32_t reserved : 31;
|
||||
uint32_t soft_reset : 1;
|
||||
uint32_t reserved : 31;
|
||||
} __attribute__((packed, aligned(4))) k210_soft_reset_t;
|
||||
|
||||
volatile k210_soft_reset_t *const reset = (volatile k210_soft_reset_t *)(K210_SYSCTL_BASE + 0x30);
|
||||
|
|
Loading…
Reference in New Issue