From 71aa580af9322cacff19b9f5ce27cf437a7a3cb4 Mon Sep 17 00:00:00 2001 From: "lichao.ren" Date: Fri, 5 May 2023 17:14:58 +0800 Subject: [PATCH] [Add] Add GPIO hardware library --- .../include/board_eth_phy_conf.h | 75 +++++ .../drivers-x2600/include/x2600_hal_conf.h | 118 +++++++ drivers/drivers-x2600/include/x2600_ll_gpio.h | 277 ++++++++++------ .../drivers-x2600/include/x2600_sysclk_conf.h | 68 ++++ drivers/drivers-x2600/src/x2600_ll_gpio.c | 311 ++++++++++++++---- .../Examples/gpio/.vscode/cmake-kits.json | 18 + .../Examples/gpio/.vscode/launch.json | 63 ++++ .../Examples/gpio/.vscode/settings.json | 9 + .../Examples/gpio/.vscode/tasks.json | 12 + .../x2660-halley/Examples/gpio/CMakeLists.txt | 108 ++++++ projects/x2660-halley/Examples/gpio/Makefile | 173 ++++++++++ .../gpio/include/board_eth_phy_conf.h | 75 +++++ .../Examples/gpio/include/x2600_hal_conf.h | 118 +++++++ .../Examples/gpio/include/x2600_sysclk_conf.h | 68 ++++ projects/x2660-halley/Examples/gpio/main.c | 35 ++ .../Examples/gpio/riscv32-gcc.cmake | 18 + 16 files changed, 1387 insertions(+), 159 deletions(-) create mode 100644 drivers/drivers-x2600/include/board_eth_phy_conf.h create mode 100644 drivers/drivers-x2600/include/x2600_hal_conf.h create mode 100644 drivers/drivers-x2600/include/x2600_sysclk_conf.h create mode 100644 projects/x2660-halley/Examples/gpio/.vscode/cmake-kits.json create mode 100644 projects/x2660-halley/Examples/gpio/.vscode/launch.json create mode 100644 projects/x2660-halley/Examples/gpio/.vscode/settings.json create mode 100644 projects/x2660-halley/Examples/gpio/.vscode/tasks.json create mode 100644 projects/x2660-halley/Examples/gpio/CMakeLists.txt create mode 100644 projects/x2660-halley/Examples/gpio/Makefile create mode 100644 projects/x2660-halley/Examples/gpio/include/board_eth_phy_conf.h create mode 100644 projects/x2660-halley/Examples/gpio/include/x2600_hal_conf.h create mode 100644 projects/x2660-halley/Examples/gpio/include/x2600_sysclk_conf.h create mode 100644 projects/x2660-halley/Examples/gpio/main.c create mode 100644 projects/x2660-halley/Examples/gpio/riscv32-gcc.cmake diff --git a/drivers/drivers-x2600/include/board_eth_phy_conf.h b/drivers/drivers-x2600/include/board_eth_phy_conf.h new file mode 100644 index 00000000..c907ead4 --- /dev/null +++ b/drivers/drivers-x2600/include/board_eth_phy_conf.h @@ -0,0 +1,75 @@ +#ifndef __ETH_PHY_CONF_H +#define __ETH_PHY_CONF_H + +/* ################## Ethernet peripheral configuration ##################### */ + +/* Section 1 : Ethernet peripheral configuration */ + +/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */ +#define MAC_ADDR0 0x00U +#define MAC_ADDR1 0x11U +#define MAC_ADDR2 0x22U +#define MAC_ADDR3 0x33U +#define MAC_ADDR4 0x44U +#define MAC_ADDR5 0x55U + +/* Definition of the Ethernet driver buffers size and count */ +#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */ +#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */ +#define ETH_RXBUFNB ((uint32_t)4U) /* 4 Rx buffers of size ETH_RX_BUF_SIZE */ +#define ETH_TXBUFNB ((uint32_t)4U) /* 4 Tx buffers of size ETH_TX_BUF_SIZE */ + +/* Section 2: PHY configuration section */ + +/* DP83848 PHY Address*/ +#define DP83848_PHY_ADDRESS 0x01U +/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/ +#define PHY_RESET_DELAY ((uint32_t)0x000000FFU) +/* PHY Configuration delay */ +#define PHY_CONFIG_DELAY ((uint32_t)0x00000FFFU) + +#define PHY_READ_TO ((uint32_t)0x0000FFFFU) +#define PHY_WRITE_TO ((uint32_t)0x0000FFFFU) + +/* Section 3: Common PHY Registers */ + +#define PHY_BCR ((uint16_t)0x00U) /*!< Transceiver Basic Control Register */ +#define PHY_BSR ((uint16_t)0x01U) /*!< Transceiver Basic Status Register */ + +#define PHY_RESET ((uint16_t)0x8000U) /*!< PHY Reset */ +#define PHY_LOOPBACK ((uint16_t)0x4000U) /*!< Select loop-back mode */ +#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100U) /*!< Set the full-duplex mode at 100 Mb/s */ +#define PHY_HALFDUPLEX_100M ((uint16_t)0x2600U) /*!< Set the half-duplex mode at 100 Mb/s */ +#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100U) /*!< Set the full-duplex mode at 10 Mb/s */ +#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000U) /*!< Set the half-duplex mode at 10 Mb/s */ +#define PHY_AUTONEGOTIATION ((uint16_t)0x1000U) /*!< Enable auto-negotiation function */ +#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200U) /*!< Restart auto-negotiation function */ +#define PHY_POWERDOWN ((uint16_t)0x0800U) /*!< Select the power down mode */ +#define PHY_ISOLATE ((uint16_t)0x0400U) /*!< Isolate PHY from MII */ + +#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020U) /*!< Auto-Negotiation process completed */ +#define PHY_LINKED_STATUS ((uint16_t)0x0004U) /*!< Valid link established */ +#define PHY_JABBER_DETECTION ((uint16_t)0x0002U) /*!< Jabber condition detected */ + +/* Section 4: Extended PHY Registers */ + +#define PHY_SR ((uint16_t)0x10U) /*!< PHY status register Offset */ +#define PHY_MICR ((uint16_t)0x11U) /*!< MII Interrupt Control Register */ +#define PHY_MISR ((uint16_t)0x12U) /*!< MII Interrupt Status and Misc. Control Register */ + +#define PHY_LINK_STATUS ((uint16_t)0x0001U) /*!< PHY Link mask */ +#define PHY_SPEED_STATUS ((uint16_t)0x0002U) /*!< PHY Speed mask */ +#define PHY_DUPLEX_STATUS ((uint16_t)0x0004U) /*!< PHY Duplex mask */ + +#define PHY_MICR_INT_EN ((uint16_t)0x0002U) /*!< PHY Enable interrupts */ +#define PHY_MICR_INT_OE ((uint16_t)0x0001U) /*!< PHY Enable output interrupt events */ + +#define PHY_MISR_LINK_INT_EN ((uint16_t)0x0020U) /*!< Enable Interrupt on change of link status */ +#define PHY_LINK_INTERRUPT ((uint16_t)0x2600U) /*!< PHY link status interrupt mask */ + +/* ################## Ethernet peripheral configuration ##################### */ + + + +#endif // __ETH_PHY_CONF_H + diff --git a/drivers/drivers-x2600/include/x2600_hal_conf.h b/drivers/drivers-x2600/include/x2600_hal_conf.h new file mode 100644 index 00000000..83b6afab --- /dev/null +++ b/drivers/drivers-x2600/include/x2600_hal_conf.h @@ -0,0 +1,118 @@ +#ifndef __X2000_HAL_CONF_H__ +#define __X2000_HAL_CONF_H__ +/* TODO: 本文件应该通过工具生成,在配置工程中选择不同的组件时,在此处包含不同的头文件 + 暂时包含全部头文件. +*/ + + +/* 1. Includes ---------------------------------------------------- */ + + +/* Hal Module selections. */ +#if 0 +#define HAL_MSC_ENABLED +#define HAL_I2C_ENABLED +#define HAL_UART_ENABLED +#define HAL_ADC_ENABLED +#define HAL_SPI_ENABLED +#define HAL_WDT_ENABLED +#define HAL_TCU_ENABLED +#define HAL_RTC_ENABLED +#define HAL_EFUSE_ENABLED +#define HAL_PWM_ENABLED +#define HAL_GMAC_ENABLED +#define HAL_USB_ENABLED +#endif + +/* 系统时钟配配置,通过工具生成,随开发板或者平台变化.*/ +#include +#include + +#include "x2600_hal_tick.h" +#include "x2600_ll_ost_core.h" +#include "x2600_ll_ost_global.h" +//#include "x2600_ll_cpm.h" +#include "x2600_ll_gpio.h" + +//#include "x2600_hal_pdma.h" + +//#include "x2600_hal_sfcnor.h" + +#ifdef HAL_MSC_ENABLED + +#endif + +#ifdef HAL_I2C_ENABLED +#include "x2600_hal_i2c.h" +#endif + +#ifdef HAL_UART_ENABLED +#include "x2600_hal_uart.h" +#endif + +#ifdef HAL_ADC_ENABLED +#include "x2600_hal_adc.h" +#endif + +#ifdef HAL_SPI_ENABLED +#include "x2600_hal_spi.h" +#endif + +#ifdef HAL_WDT_ENABLED +#include "x2600_hal_wdt.h" +#endif + +#ifdef HAL_TCU_ENABLED +#include "x2600_hal_tcu.h" +#endif + +#ifdef HAL_RTC_ENABLED +#include "x2600_hal_rtc.h" +#endif + +#ifdef HAL_EFUSE_ENABLED +#include "x2600_ll_efuse.h" +#include "x2600_hal_efuse.h" +#endif + +#ifdef HAL_PWM_ENABLED +#include "x2600_hal_pwm.h" +#endif + +#ifdef HAL_GMAC_ENABLED +#include "x2600_hal_gmac.h" +#endif + +#ifdef HAL_USB_ENABLED +#include "x2600_hal_pcd.h" +#include "x2600_hal_pcd_ex.h" +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* 2. Exported Types ---------------------------------------------- */ + +/* 3. Exported Constants ------------------------------------------ */ + +/* 4. Exported Macros --------------------------------------------- */ + +/* 5. Exported Funcs ---------------------------------------------- */ + +/* 6. Exported Variables ------------------------------------------ */ + +/* 7. Private Types ----------------------------------------------- */ + +/* 8. Private Constants ------------------------------------------- */ + +/* 9. Private Macros ---------------------------------------------- */ + +/* 10. Private Funcs ---------------------------------------------- */ + +/* 11. Private Variables ------------------------------------------ */ + +#ifdef __cplusplus +} +#endif +#endif /* __X2000_HAL_H__ */ diff --git a/drivers/drivers-x2600/include/x2600_ll_gpio.h b/drivers/drivers-x2600/include/x2600_ll_gpio.h index aca3704d..93359348 100755 --- a/drivers/drivers-x2600/include/x2600_ll_gpio.h +++ b/drivers/drivers-x2600/include/x2600_ll_gpio.h @@ -1,20 +1,23 @@ /** * @file x2600_ll_gpio.h * @author MPU系统软件部团队 - * @brief [!!!!删除此内容,添加文件简介!!!!] + * @brief GPIO驱动头文件 * - * @copyright 版权所有 (北京君正集成电路股份有限公司) {2022} - * @copyright Copyright© 2022 Ingenic Semiconductor Co.,Ltd + * @copyright 版权所有 (北京君正集成电路股份有限公司) {2023} + * @copyright Copyright© 2023 Ingenic Semiconductor Co.,Ltd * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. */ - + #ifndef __X2600_LL_GPIO_H__ #define __X2600_LL_GPIO_H__ +/* 1. 头文件 (Includes)----------------------------------------------- */ +#include + #ifdef __cplusplus extern "C" { #endif @@ -28,138 +31,222 @@ * @addtogroup g_X2600_GPIO_LL_Driver GPIO LL 驱动 * @{ */ - -/* 1. 头文件 (Includes)----------------------------------------------- */ -//删除此行,添加内容 -//删除此行,添加内容 +/** + * @brief GPIO LL Configuration Structure + */ + +typedef struct { + uint32_t Pin; + uint32_t Mode; + uint32_t Pull; + uint32_t Function; +} LL_GPIO_InitTypeDef; + +enum gpio_port { + GPIO_PORT_A = 0, + GPIO_PORT_B, + GPIO_PORT_C, + GPIO_PORT_D, + GPIO_PORT_E, + + /* this must be last */ + GPIO_NR_PORTS, +}; + /* 2. 导出的类型 (Exported Types)--------------------------------------- */ /** * @defgroup GPIO_exported_types GPIO 导出的类型 (Exported Types) * @{ */ - + // 删除此行, 添加内容 // 删除此行, 添加内容 /** * @} - */ + */ /* 3. 导出常量定义 Exported Constants ----------------------------------- */ /** * @defgroup GPIO_exported_constants GPIO 导出的常量 Exported Constants * @{ */ - -// 删除此行, 添加内容 -// 删除此行, 添加内容 +#define GPIO_MODE_FUNCTION0 0 +#define GPIO_MODE_FUNCTION1 1 +#define GPIO_MODE_FUNCTION2 2 +#define GPIO_MODE_FUNCTION3 3 +#define GPIO_MODE_OUTPUT0 4 +#define GPIO_MODE_OUTPUT1 5 +#define GPIO_MODE_INPUT 6 +#define GPIO_MODE_IRQ_LEVEL_LOW 8 //低电平触发中断 +#define GPIO_MODE_IRQ_LEVEL_HIGH 9 //高电平触发中断 +#define GPIO_MODE_IRQ_EDGE_FALLING 10 //下降沿触发中断 +#define GPIO_MODE_IRQ_EDGE_RISING 11 //上升沿触发中断 +#define GPIO_MODE_IRQ_EDGE_BOTH 27 //双边沿触发中断 -/** - * @} - */ -/* 4. 导出宏定义 Exported Macros --------------------------------------- */ -/** - * @defgroup GPIO_exported_macros GPIO 导出宏 Exported Macros - * @{ - */ - -// 删除此行, 添加内容 -// 删除此行, 添加内容 +#define GPIO_IRQ_PA(n) (0 * 32 + (n) + IRQ_GPIO_START) +#define GPIO_IRQ_PB(n) (1 * 32 + (n) + IRQ_GPIO_START) +#define GPIO_IRQ_PC(n) (2 * 32 + (n) + IRQ_GPIO_START) +#define GPIO_IRQ_PD(n) (3 * 32 + (n) + IRQ_GPIO_START) +#define GPIO_IRQ_PE(n) (4 * 32 + (n) + IRQ_GPIO_START) /** - * @} - */ -/* 5. 导出函数申明 Exported Funcs --------------------------------------- */ -/** - * @defgroup GPIO_exported_funcs GPIO 导出函数申明 Exported Funcs - * @{ + * @brief 设置GPIO管脚中断触发类型 + * @param GPIOx 指向GPIO_TypeDef结构的GPIOx指针 + * @param port GPIO端口号 + * @param Pin 要配置的管脚 + * @param Mode 中断触发类型 + * @retval None */ - -// 删除此行, 添加内容 -// 删除此行, 添加内容 +static inline void LL_GPIO_setIrqMode(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Mode) +{ + uint32_t EDG = !!(Mode & (1 << 4)); + uint32_t INT = !!(Mode & (1 << 3)); + uint32_t PAT1 = !!(Mode & (1 << 1)); + uint32_t PAT0 = !!(Mode & (1 << 0)); -/** - * @} - */ -/* 6. 导出变量申明 (Exported Variables) --------------------------------- */ -/** - * @defgroup GPIO_exported_var GPIO 导出变量申明 (Exported Variables) - * @{ - */ - -// 删除此行, 添加内容 -// 删除此行, 添加内容 + /* No Shadows registers for EDG, set registers directly */ + if (EDG == 1) { + WRITE_REG(GPIOx->PxEDGS, 1 << Pin); + } else { + WRITE_REG(GPIOx->PxEDGC, 1 << Pin); + } + + if (INT == 1) { + WRITE_REG(GPIOx->PxINTSS1, 1 << Pin); + } else { + WRITE_REG(GPIOx->PxINTCS1, 1 << Pin); + } + + if (PAT1 == 1) { + WRITE_REG(GPIOx->PxPAT1SS1, 1 << Pin); + } else { + WRITE_REG(GPIOx->PxPAT1CS1, 1 << Pin); + } + + if (PAT0 == 1) { + WRITE_REG(GPIOx->PxPAT0SS1, 1 << Pin); + } else { + WRITE_REG(GPIOx->PxPAT0CS1, 1 << Pin); + } + + // 默认一开始屏蔽中断 + WRITE_REG(GPIOx->PxMSKSS1, 1 << Pin); + + WRITE_REG(GPIOx->PxGLD1, 1); +} /** - * @} - */ -/* 7. 私有类型定义 (Private Types) -------------------------------------- */ -/** - * @defgroup GPIO_private_types GPIO 私有类型定义 (Private Types) - * @{ + * @brief 设置GPIO管脚功能 + * + * @param GPIOx 指向GPIO_TypeDef结构的GPIOx指针 + * @param Pin 管脚 + * @param Mode 管脚功能模式 + * @retval None */ - -// 删除此行, 添加内容 -// 删除此行, 添加内容 +static inline void LL_GPIO_setPinMode(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Mode) +{ + uint32_t INT = !!(Mode & (1 << 3)); + uint32_t MSK = !!(Mode & (1 << 2)); + uint32_t PAT1 = !!(Mode & (1 << 1)); + uint32_t PAT0 = !!(Mode & (1 << 0)); + + if (INT == 1) { + WRITE_REG(GPIOx->PxINTS, 1 << Pin); + } else { + WRITE_REG(GPIOx->PxINTC, 1 << Pin); + } + + if (MSK == 1) { + WRITE_REG(GPIOx->PxMSKS, 1 << Pin); + } else { + WRITE_REG(GPIOx->PxMSKC, 1 << Pin); + } + + if (PAT1 == 1) { + WRITE_REG(GPIOx->PxPAT1S, 1 << Pin); + } else { + WRITE_REG(GPIOx->PxPAT1C, 1 << Pin); + } + + if (PAT0 == 1) { + WRITE_REG(GPIOx->PxPAT0S, 1 << Pin); + } else { + WRITE_REG(GPIOx->PxPAT0C, 1 << Pin); + } +} /** - * @} - */ -/* 8. 私有常量定义Private Constants ------------------------------------- */ -/** - * @defgroup GPIO_private_constants GPIO 私有常量定义Private Constants - * @{ + * @brief 获取GPIO管脚功能模式 + * @param GPIOx 指向GPIO_TypeDef结构的GPIOx指针 + * @param Pin 管脚 + * @retval GPIO管脚功能模式 */ - -// 删除此行, 添加内容 -// 删除此行, 添加内容 +static inline uint32_t LL_GPIO_getPinMode(GPIO_TypeDef *GPIOx, uint32_t Pin) +{ + uint32_t INT = READ_REG(GPIOx->PxINT) & (1 << Pin); + uint32_t MSK = READ_REG(GPIOx->PxMSK) & (1 << Pin); + uint32_t PAT1 = READ_REG(GPIOx->PxPAT1) & (1 << Pin); + uint32_t PAT0 = READ_REG(GPIOx->PxPAT0) & (1 << Pin); + + return (INT << 3) | (MSK << 2) | (PAT1 << 1) | (PAT0 << 0); +} + +static inline void LL_GPIO_setPinPull(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Pull) +{ + +} /** - * @} - */ -/* 9. 私有宏定义 (Private Macros) -------------------------------------- */ -/** - * @defgroup GPIO_private_macros GPIO 私有宏定义 (Private Macros) - * @{ + * @brief 获取管脚PULL状态 + * @param GPIOx 指向GPIO_TypeDef结构的GPIOx指针 + * @param Pin 管脚 + * @retval 管脚PULL状态 */ - -// 删除此行, 添加内容 -// 删除此行, 添加内容 +static inline uint32_t LL_GPIO_getPinPull(GPIO_TypeDef *GPIOx, uint32_t Pin) +{ + return READ_REG(GPIOx->PxPU) & (1 << Pin); +} /** - * @} - */ -/* 10. 私有函数申明 (Private Funcs) ------------------------------------- */ -/** - * @defgroup GPIO_private_funcs GPIO 私有函数申明 (Private Funcs) - * @{ + * @brief 设置管脚为输出高电平 + * @param GPIOx 指向GPIO_TypeDef结构的GPIOx指针 + * @param Pin 管脚 + * @retval None */ - -// 删除此行, 添加内容 -// 删除此行, 添加内容 +static inline void LL_GPIO_setOutputPin(GPIO_TypeDef *GPIOx, uint32_t Pin) +{ + WRITE_REG(GPIOx->PxPAT0S, (1 << Pin)); +} /** - * @} - */ -/* 11. 私有变量申明 Private Variables ----------------------------------- */ -/** - * @defgroup GPIO_private_var GPIO 私有变量申明 (Private Variables) - * @{ + * @brief 设置管脚为输出低电平 + * @param GPIOx 指向GPIO_TypeDef结构的GPIOx指针 + * @param Pin 管脚 + * @retval None */ - -// 删除此行, 添加内容 -// 删除此行, 添加内容 +static inline void LL_GPIO_clearOutputPin(GPIO_TypeDef *GPIOx, uint32_t Pin) +{ + WRITE_REG(GPIOx->PxPAT0C, (1 << Pin)); +} /** - * @} - */ + * @brief 获取管脚电平状态 + * @param GPIOx 指向GPIO_TypeDef结构的GPIOx指针 + * @param Pin 管脚 + * @retval 管脚电平状态 + */ +static inline uint32_t LL_GPIO_getPinLevel(GPIO_TypeDef *GPIOx, uint32_t Pin) +{ + return !!(READ_REG(GPIOx->PxPINL) & (1 << Pin)); +} /** * @} - */ + */ +/* 5. 导出函数申明 Exported Funcs --------------------------------------- */ -/** - * @} - */ +void gpio_request_irq(int irq, uint32_t irq_type, irq_handler_t handler, void *data); +void gpio_unrequest_irq(int irq); #ifdef __cplusplus } #endif diff --git a/drivers/drivers-x2600/include/x2600_sysclk_conf.h b/drivers/drivers-x2600/include/x2600_sysclk_conf.h new file mode 100644 index 00000000..2126aba0 --- /dev/null +++ b/drivers/drivers-x2600/include/x2600_sysclk_conf.h @@ -0,0 +1,68 @@ +/** + * @file x2600_sysclk_conf.h + * @author MPU系统软件部团队 + * @brief + * + * @copyright 版权所有 (北京君正集成电路股份有限公司) {2022} + * @copyright Copyright© 2022 Ingenic Semiconductor Co.,Ltd + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + */ + +#ifndef __X2000_SYSCLK_CONF_H__ +#define __X2000_SYSCLK_CONF_H__ + +#ifdef __cplusplus +extern "C" { +#endif +/* 1. Includes ---------------------------------------------------- */ + +/* 2. Exported Types ---------------------------------------------- */ + + +/* 3. Exported Constants ------------------------------------------ */ + +/* 4. Exported Macros --------------------------------------------- */ +#define SYSCLK_EXTAL (24000000) +#define SYSCLK_APLL (1200000000) +#define SYSCLK_MPLL (1200000000) + +#define SystemCoreClock SYSCLK_APLL + +#define CGU_CONFIG_MSC_APLL_24M { \ + .PLLMux = MSC1CDR_SCLK_A, \ + .Div = 24, \ + .Config = 0 } + +#define CGU_CONFIG_MSC_APLL_48M { \ + .PLLMux = MSC1CDR_SCLK_A, \ + .Div = 11, \ + .Config = 0 } + + +#define CGU_CONFIG_SSI_MPLL_500K { \ + .PLLMux = SSICDR_MPLL, \ + .Div = 15, \ + .Config = 0 } + +/* 5. Exported Funcs ---------------------------------------------- */ + +/* 6. Exported Variables ------------------------------------------ */ + +/* 7. Private Types ----------------------------------------------- */ + +/* 8. Private Constants ------------------------------------------- */ + +/* 9. Private Macros ---------------------------------------------- */ + +/* 10. Private Funcs ---------------------------------------------- */ + +/* 11. Private Variables ------------------------------------------ */ + +#ifdef __cplusplus +} +#endif +#endif /* __X2000_HAL_ADC_H__ */ diff --git a/drivers/drivers-x2600/src/x2600_ll_gpio.c b/drivers/drivers-x2600/src/x2600_ll_gpio.c index ff248873..86157c6c 100755 --- a/drivers/drivers-x2600/src/x2600_ll_gpio.c +++ b/drivers/drivers-x2600/src/x2600_ll_gpio.c @@ -1,7 +1,7 @@ /** * @file x2600_ll_gpio.c * @author MPU系统软件部团队 - * @brief [!!!!删除此内容,添加文件简介!!!!] + * @brief GPIO LL模块驱动程序 * * @copyright 版权所有 (北京君正集成电路股份有限公司) {2022} * @copyright Copyright© 2022 Ingenic Semiconductor Co.,Ltd @@ -10,105 +10,288 @@ * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. - @verbatim - ============================================================================== - ##### 使用说明 ##### - ============================================================================== - [!!!!删除此内容,添加针对模块的使用方法说明,例如: 配置,启动/停止,状态,重点提醒等等.!!!!] - @endverbatim - */ - + */ + /* 1.头文件 (Includes)------------------------------------------------ */ +#include -/** @addtogroup g_X2600_GPIO_LL_Driver - * @{ +/** + * @brief GPIO LL Configuration Structure */ - +static const uint32_t gpio_irqbase[] = { + [GPIO_PORT_A] = IRQ_GPIO_START + 0 * 32, + [GPIO_PORT_B] = IRQ_GPIO_START + 1 * 32, + [GPIO_PORT_C] = IRQ_GPIO_START + 2 * 32, + [GPIO_PORT_D] = IRQ_GPIO_START + 3 * 32, + [GPIO_PORT_E] = IRQ_GPIO_START + 4 * 32, +}; + /* 2.私有常量定义Private Constants -------------------------------------- */ /** - * @addtogroup GPIO_private_constants + * @addtogroup GPIO_private_constants * @{ */ - -// 删除此行, 添加内容 -// 删除此行, 添加内容 - /** - * @} - */ -/* 3. 私有类型定义 (Private Types) -------------------------------------- */ -/** - * @addtogroup GPIO_private_types - * @{ + * @brief */ - -// 删除此行, 添加内容 -// 删除此行, 添加内容 +static void hang(void) +{ + (*(volatile unsigned int *)0) = 0; + while (1); +} /** - * @} - */ -/* 4. 私有宏定义 (Private Macros) -------------------------------------- */ + * @brief 设置GPIO中断屏蔽 + * @param gpio 中断号-IRQ_GPIO_START + * @retval None + */ +static void ll_gpio_mask_irq(int gpio) +{ + enum gpio_port port = gpio / 32; + unsigned int pin = gpio % 32; + + if (port == GPIO_PORT_A) { + WRITE_REG(PA_Instance->PxMMSKS, 1 << pin); + } else if (port == GPIO_PORT_B) { + WRITE_REG(PB_Instance->PxMMSKS, 1 << pin); + } else if (port == GPIO_PORT_C) { + WRITE_REG(PC_Instance->PxMMSKS, 1 << pin); + } else if (port == GPIO_PORT_D) { + WRITE_REG(PD_Instance->PxMMSKS, 1 << pin); + } else { + WRITE_REG(PE_Instance->PxMMSKS, 1 << pin); + } + +} + /** - * @addtogroup GPIO_private_macros - * @{ + * @brief 清除GPIO中断标志位 + * @param gpio 中断号-IRQ_GPIO_START + * @retval None */ - -// 删除此行, 添加内容 -// 删除此行, 添加内容 +static void ll_gpio_clear_irqflag(int gpio) +{ + enum gpio_port port = gpio / 32; + unsigned int pin = gpio % 32; + + + if (port == GPIO_PORT_A) { + WRITE_REG(PA_Instance->PxFLGC, 1 << pin); + } else if (port == GPIO_PORT_B) { + WRITE_REG(PB_Instance->PxFLGC, 1 << pin); + } else if (port == GPIO_PORT_C) { + WRITE_REG(PC_Instance->PxFLGC, 1 << pin); + } else if (port == GPIO_PORT_D) { + WRITE_REG(PD_Instance->PxFLGC, 1 << pin); + } else { + WRITE_REG(PE_Instance->PxFLGC, 1 << pin); + } +} /** - * @} - */ -/* 5. 私有变量申明 Private Variables ------------------------------------ */ + * @brief 关闭GPIO中断屏蔽 + * @param gpio 中断号-IRQ_GPIO_START + * @retval None + */ +static void ll_gpio_unmask_irq(int gpio) +{ + enum gpio_port port = gpio / 32; + unsigned int pin = gpio % 32; + + if (port == GPIO_PORT_A) { + WRITE_REG(PA_Instance->PxMMSKC, 1 << pin); + } else if (port == GPIO_PORT_B) { + WRITE_REG(PB_Instance->PxMMSKC, 1 << pin); + } else if (port == GPIO_PORT_C) { + WRITE_REG(PC_Instance->PxMMSKC, 1 << pin); + } else if (port == GPIO_PORT_D) { + WRITE_REG(PD_Instance->PxMMSKC, 1 << pin); + } else { + WRITE_REG(PE_Instance->PxMMSKC, 1 << pin); + } +} + /** - * @addtogroup GPIO_private_var - * @{ + * @brief 清除GPIO中断标志位,关闭GPIO中断屏蔽 + * @param gpio 中断号-IRQ_GPIO_START + * @retval None */ - -// 删除此行, 添加内容 -// 删除此行, 添加内容 +static void enable_irq_gpio(int irq) +{ + int gpio = irq - IRQ_GPIO_START; + + ll_gpio_clear_irqflag(gpio); + ll_gpio_unmask_irq(gpio); +} /** - * @} - */ -/* 6. 私有函数申明 (Private Funcs) -------------------------------------- */ + * @brief 屏蔽GPIO中断 + * @param gpio 中断号-IRQ_GPIO_START + * @retval None + */ +__attribute__((unused)) static void disable_irq_gpio(int irq) +{ + int gpio = irq - IRQ_GPIO_START; + + ll_gpio_mask_irq(gpio); +} + /** - * @addtogroup GPIO_private_funcs - * @{ + * @brief 获取来中断的GPIO标志位 + * @param port GPIO端口号 + * @retval 返回获取到的GPIO中断标志位 */ - -// 删除此行, 添加内容 -// 删除此行, 添加内容 +static uint32_t ll_gpio_port_get_irqflag(enum gpio_port port) +{ + if (port == GPIO_PORT_A) { + return READ_REG(PA_Instance->PxFLG) & ~READ_REG(PA_Instance->PxMMSK); + } else if (port == GPIO_PORT_B) { + return READ_REG(PB_Instance->PxFLG) & ~READ_REG(PB_Instance->PxMMSK); + } else if (port == GPIO_PORT_C) { + return READ_REG(PC_Instance->PxFLG) & ~READ_REG(PC_Instance->PxMMSK); + } else if (port == GPIO_PORT_D) { + return READ_REG(PD_Instance->PxFLG) & ~READ_REG(PD_Instance->PxMMSK); + } else { + return READ_REG(PE_Instance->PxFLG) & ~READ_REG(PE_Instance->PxMMSK); + } +} /** - * @} - */ -/* 7. 私有函数实现 (Private Funcs) -------------------------------------- */ + * @brief GPIO中断处理函数 + * @param irq 中断号 + * @param data 中断处理函数参数的指针 + * @retval None + */ +static void gpio_irq_handler(int irq, void *data) +{ + enum gpio_port port = (enum gpio_port) data; + uint32_t flag = ll_gpio_port_get_irqflag(port); + int pin = __ffs(flag); + + if (!flag) { + hang(); + } + + if (port == GPIO_PORT_A) { + WRITE_REG(PA_Instance->PxFLGC, (1 << pin)); + } else if (port == GPIO_PORT_B) { + WRITE_REG(PB_Instance->PxFLGC, (1 << pin)); + } else if (port == GPIO_PORT_C) { + WRITE_REG(PC_Instance->PxFLGC, (1 << pin)); + } else if (port == GPIO_PORT_D) { + WRITE_REG(PD_Instance->PxFLGC, (1 << pin)); + } else { + WRITE_REG(PE_Instance->PxFLGC, (1 << pin)); + } + + // ll_gpio_mask_irq(port * 32 + pin); + handle_irq(gpio_irqbase[port] + pin); + // ll_gpio_unmask_irq(port * 32 + pin); +} + /** - * @defgroup GPIO_private_funcs_impl GPIO 私有函数实现 - * @{ + * @brief GPIO申请中断处理函数 + * @param irq 中断号 + * @param irq_type 设置GPIO中断触发条件类型 + * @param handler 中断处理函数 + * @param data 中断处理函数参数的指针 + * @retval None */ - -// 删除此行, 添加内容 -// 删除此行, 添加内容 +void gpio_request_irq(int irq, uint32_t irq_type, irq_handler_t handler, void *data) +{ + int gpio = irq - IRQ_GPIO_START; + enum gpio_port port = gpio / 32; + uint32_t pin = gpio % 32; + + switch (port) { + case GPIO_PORT_A: + ll_request_irq(IRQ_INTC0_GPIO0, gpio_irq_handler, (void *)GPIO_PORT_A); + LL_GPIO_setIrqMode(PA_Instance, pin, irq_type); + ll_request_irq(irq, handler, data); + enable_irq_gpio(irq); + break; + case GPIO_PORT_B: + ll_request_irq(IRQ_INTC0_GPIO1, gpio_irq_handler, (void *)GPIO_PORT_B); + LL_GPIO_setIrqMode(PB_Instance, pin, irq_type); + ll_request_irq(irq, handler, data); + enable_irq_gpio(irq); + break; + case GPIO_PORT_C: + ll_request_irq(IRQ_INTC0_GPIO2, gpio_irq_handler, (void *)GPIO_PORT_C); + LL_GPIO_setIrqMode(PC_Instance, pin, irq_type); + ll_request_irq(irq, handler, data); + enable_irq_gpio(irq); + break; + case GPIO_PORT_D: + ll_request_irq(IRQ_INTC0_GPIO3, gpio_irq_handler, (void *)GPIO_PORT_D); + LL_GPIO_setIrqMode(PD_Instance, pin, irq_type); + ll_request_irq(irq, handler, data); + enable_irq_gpio(irq); + break; + case GPIO_PORT_E: + ll_request_irq(IRQ_INTC0_GPIO2, gpio_irq_handler, (void *)GPIO_PORT_E); + LL_GPIO_setIrqMode(PE_Instance, pin, irq_type); + ll_request_irq(irq, handler, data); + enable_irq_gpio(irq); + break; + default: + return; + } +} + +void gpio_unrequest_irq(int irq) +{ + int gpio = irq - IRQ_GPIO_START; + enum gpio_port port = gpio / 32; + + switch (port) { + case GPIO_PORT_A: + disable_irq_gpio(irq); + ll_disable_irq(irq); + ll_release_irq(irq); + ll_disable_irq(IRQ_INTC0_GPIO0); + ll_release_irq(IRQ_INTC0_GPIO0); + break; + case GPIO_PORT_B: + disable_irq_gpio(irq); + ll_disable_irq(irq); + ll_release_irq(irq); + ll_disable_irq(IRQ_INTC0_GPIO1); + ll_release_irq(IRQ_INTC0_GPIO1); + break; + case GPIO_PORT_C: + disable_irq_gpio(irq); + ll_disable_irq(irq); + ll_release_irq(irq); + ll_disable_irq(IRQ_INTC0_GPIO2); + ll_release_irq(IRQ_INTC0_GPIO2); + break; + case GPIO_PORT_D: + disable_irq_gpio(irq); + ll_disable_irq(irq); + ll_release_irq(irq); + ll_disable_irq(IRQ_INTC0_GPIO3); + ll_release_irq(IRQ_INTC0_GPIO3); + break; + default: + return; + } +} /** * @} - */ + */ /* 8. 导出函数实现------------------------------------------------------- */ /** * @defgroup GPIO_exported_funcs_impl GPIO 导出函数实现 * @{ */ - -// 删除此行, 添加内容 -// 删除此行, 添加内容 + /** * @} - */ + */ /** * @} - */ + */ diff --git a/projects/x2660-halley/Examples/gpio/.vscode/cmake-kits.json b/projects/x2660-halley/Examples/gpio/.vscode/cmake-kits.json new file mode 100644 index 00000000..7c98a0d9 --- /dev/null +++ b/projects/x2660-halley/Examples/gpio/.vscode/cmake-kits.json @@ -0,0 +1,18 @@ +[ + { + "name": "GCC for ingenic cross compile on Windows", + + "toolchainFile": "mips-gcc-sde-elf.cmake", + "preferredGenerator": { + "name":"MinGW Makefiles" + } + }, + { + "name": "GCC for ingenic cross compile on Linux", + "toolchainFile": "mips-gcc-sde-elf.cmake", + "preferredGenerator": { + "name":"Unix Makefiles" + } + } +] + \ No newline at end of file diff --git a/projects/x2660-halley/Examples/gpio/.vscode/launch.json b/projects/x2660-halley/Examples/gpio/.vscode/launch.json new file mode 100644 index 00000000..8ddcfe12 --- /dev/null +++ b/projects/x2660-halley/Examples/gpio/.vscode/launch.json @@ -0,0 +1,63 @@ +{ + "version": "0.2.0", + "configurations": [ + // GDB Debugging: + { + "program": "${command:cmake.launchTargetPath}", + "name": "Launch (gdb)", + "request": "launch", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "console": "integratedTerminal", + "internalConsoleOptions": "openOnSessionStart", + "type": "cppdbg", + "MIMode": "gdb", + "miDebuggerPath": "mips-sde-elf-gdb", + "miDebuggerArgs": "", + "miDebuggerServerAddress": "localhost:3333", + "targetArchitecture": "mips", + "preLaunchTask": "adb forward", + "customLaunchSetupCommands": [ + { + "description": "gdb 启用整齐打印", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "text":"cd ${workspaceFolder}", + "ignoreFailures": false + }, + { + "text":"file build/${command:cmake.buildType}/${command:cmake.launchTargetFilename}", + "ignoreFailures": false + }, + { + "text": "target remote localhost:3333", + "ignoreFailures": false + }, + { + "text": "monitor reset halt", + "ignoreFailures": false + }, + { + "text": "monitor x1600_init", + "ignoreFailures": false + }, + { + "text": "load", + "ignoreFailures": false + }, + { + "text": "monitor mips32 invalidate all", + "ignoreFailures": false + } + ], + "logging": { + "engineLogging": false, + "programOutput": true + } + } + ] + } + \ No newline at end of file diff --git a/projects/x2660-halley/Examples/gpio/.vscode/settings.json b/projects/x2660-halley/Examples/gpio/.vscode/settings.json new file mode 100644 index 00000000..0537c076 --- /dev/null +++ b/projects/x2660-halley/Examples/gpio/.vscode/settings.json @@ -0,0 +1,9 @@ +{ + "cmake.buildDirectory": "${workspaceFolder}/build/${buildType}", + "files.associations": { + "*.build": "makefile", + "*.mk": "makefile", + "Makefile*": "makefile", + "x16xx_hal.h": "c" + } +} \ No newline at end of file diff --git a/projects/x2660-halley/Examples/gpio/.vscode/tasks.json b/projects/x2660-halley/Examples/gpio/.vscode/tasks.json new file mode 100644 index 00000000..53b4731e --- /dev/null +++ b/projects/x2660-halley/Examples/gpio/.vscode/tasks.json @@ -0,0 +1,12 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "adb forward", + "type": "shell", + "command": "adb forward tcp:3333 tcp:3333", + }, + ] +} \ No newline at end of file diff --git a/projects/x2660-halley/Examples/gpio/CMakeLists.txt b/projects/x2660-halley/Examples/gpio/CMakeLists.txt new file mode 100644 index 00000000..18658658 --- /dev/null +++ b/projects/x2660-halley/Examples/gpio/CMakeLists.txt @@ -0,0 +1,108 @@ +cmake_minimum_required(VERSION 3.8) +# +# Core project settings +# +Project(gpio) # Modified +enable_language(C CXX ASM) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +# Setup compiler settings +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_C_EXTENSIONS ON) +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS ON) +set(PROJ_PATH ${CMAKE_CURRENT_SOURCE_DIR}) +set(SDK_PATH ${PROJ_PATH}/../../../../) +message("Build type: " ${CMAKE_BUILD_TYPE}) + +# Set linker script +set(linker_script_SRC ${SDK_PATH}/cpu/core-riscv/ld.lds) # Modified +set(EXECUTABLE ${CMAKE_PROJECT_NAME}) +set(CPU_PARAMETERS "-march=rv32imc -mabi=ilp32 -Wno-abi") + +set(CMAKE_ASM_FLAGS "${CPU_PARAMETERS} -D_ASSEMBLER_ -D__ASSEMBLY__") + +set(CMAKE_C_FLAGS "${CPU_PARAMETERS} -fno-pic -fno-builtin -fomit-frame-pointer -Wall -nostdlib -Wall -fdata-sections -ffunction-sections") + +# Compiler options + +if(CMAKE_BUILD_TYPE STREQUAL Debug) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g -ggdb -DDEBUG") +else() + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2") +endif() + +set(CMAKE_CXX_FLAGS ${CMAKE_C_FLAGS}) + +set(CMAKE_LD_FLAGS "${CPU_PARAMETERS}") + + +set(sources_SRCS # Modified + ${SDK_PATH}/cpu/core-riscv/spinlock.c + ${SDK_PATH}/cpu/core-riscv/start.S + ${SDK_PATH}/cpu/core-riscv/genex.S + ${SDK_PATH}/cpu/core-riscv/traps.c + ${SDK_PATH}/cpu/soc-x2600/src/interrupt.c + ${SDK_PATH}/cpu/soc-x2600/src/serial.c + ${SDK_PATH}/cpu/soc-x2600/src/startup.c + ${SDK_PATH}/drivers/drivers-x2600/src/x2600_hal_def.c + ${SDK_PATH}/drivers/drivers-x2600/src/x2600_ll_gpio.c + ${SDK_PATH}/lib/libc/minimal/ctype.c + ${SDK_PATH}/lib/libc/minimal/div64.c + ${SDK_PATH}/lib/libc/minimal/string.c + ${SDK_PATH}/lib/libc/minimal/vsprintf.c + main.c + +) + +if(CMAKE_EXPORT_COMPILE_COMMANDS) + set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}) + set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}) +endif() + +# +# Include directories +# +#set(include_path_DIRS +# Modified + +include_directories( + ${PROJ_PATH}/include + ${SDK_PATH}/lib/libc/minimal/include + ${SDK_PATH}/drivers/drivers-x2600/include + ${SDK_PATH}/cpu/core-riscv/include + ${SDK_PATH}/cpu/soc-x2600/include + +) + +# +# -L libdirs. +# +link_directories( +#path/to/lib +) + +# Executable files +add_executable(${EXECUTABLE} ${sources_SRCS}) + +# Linker options +target_link_libraries(${EXECUTABLE} PRIVATE + -T${linker_script_SRC} + ${CMAKE_LD_FLAGS} + -Wl,-Map=${CMAKE_PROJECT_NAME}.map,--cref + -Wl,--gc-sections + -Wl,--start-group + -Wl,--end-group + -Wl,--print-memory-usage +) + +# Execute post-build to print size +add_custom_command(TARGET ${EXECUTABLE} POST_BUILD + COMMAND ${CMAKE_SIZE} $ +) + +# Convert output to hex and binary +add_custom_command(TARGET ${EXECUTABLE} POST_BUILD + COMMAND ${CMAKE_OBJCOPY} -O binary $ ${EXECUTABLE}.bin + ) diff --git a/projects/x2660-halley/Examples/gpio/Makefile b/projects/x2660-halley/Examples/gpio/Makefile new file mode 100644 index 00000000..bffb53a2 --- /dev/null +++ b/projects/x2660-halley/Examples/gpio/Makefile @@ -0,0 +1,173 @@ +###################################### +# target +###################################### +TARGET = gpio + +SDK_PATH = ../../../../ + + +###################################### +# building variables +###################################### +# debug build? +DEBUG = 1 +# optimization +OPT = -Og -fno-pic -fno-builtin -fomit-frame-pointer -Wall -nostdlib -Werror-implicit-function-declaration + + +####################################### +# paths +####################################### +# Build path +BUILD_DIR = build + +###################################### +# source +###################################### +# C sources +C_SOURCES = \ +$(SDK_PATH)/cpu/core-riscv/traps.c \ +$(SDK_PATH)/cpu/core-riscv/spinlock.c \ +$(SDK_PATH)/cpu/soc-x2600/src/startup.c \ +$(SDK_PATH)/cpu/soc-x2600/src/serial.c \ +$(SDK_PATH)/cpu/soc-x2600/src/interrupt.c \ +$(SDK_PATH)/drivers/drivers-x2600/src/x2600_hal_def.c \ +$(SDK_PATH)/drivers/drivers-x2600/src/x2600_ll_gpio.c \ +$(SDK_PATH)/lib/libc/minimal/vsprintf.c \ +$(SDK_PATH)/lib/libc/minimal/string.c \ +$(SDK_PATH)/lib/libc/minimal/ctype.c \ +$(SDK_PATH)/lib/libc/minimal/div64.c \ +main.c + +# ASM sources +ASM_SOURCES = \ +$(SDK_PATH)/cpu/core-riscv/start.S \ +$(SDK_PATH)/cpu/core-riscv/genex.S + + +####################################### +# binaries +####################################### +PREFIX = riscv32-ingenicv0-elf- +# The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx) +# either it can be added to the PATH environment variable. +ifdef GCC_PATH +CC = $(GCC_PATH)/$(PREFIX)gcc +AS = $(GCC_PATH)/$(PREFIX)as +LD = $(GCC_PATH)/$(PREFIX)ld +CP = $(GCC_PATH)/$(PREFIX)objcopy +SZ = $(GCC_PATH)/$(PREFIX)size +else +CC = $(PREFIX)gcc +AS = $(PREFIX)as +LD = $(PREFIX)ld +CP = $(PREFIX)objcopy +SZ = $(PREFIX)size +endif +BIN = $(CP) -O binary -S + +####################################### +# CFLAGS +####################################### +# cpu +CPU = -march=rv32imc -mabi=ilp32 -Wno-abi + +# fpu +FPU = + +# float-abi +FLOAT-ABI = + +# mcu +#MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI) +MCU = $(CPU) $(FPU) $(FLOAT-ABI) + +# macros for gcc +# AS defines +AS_DEFS = -D_ASSEMBLER_ -D__ASSEMBLY__ + +# C defines +C_DEFS = + + +# AS includes +AS_INCLUDES = \ +-I$(SDK_PATH)/cpu/core-riscv/include \ +-I$(SDK_PATH)/lib/libc/minimal/include \ + +# C includes +C_INCLUDES = \ +-Iinclude \ +-I$(SDK_PATH)/cpu/core-riscv/include \ +-I$(SDK_PATH)/cpu/soc-x2600/include \ +-I$(SDK_PATH)/lib/libc/minimal/include \ +-I$(SDK_PATH)/drivers/drivers-x2600/include + + +# compile gcc flags +ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections + +CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections + +ifeq ($(DEBUG), 1) +CFLAGS += -g -gdwarf-2 -O0 +endif + + +# Generate dependency information +CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" + + +####################################### +# LDFLAGS +####################################### +# link script +LDSCRIPT = $(SDK_PATH)/cpu/core-riscv/ld.lds + +# libraries +#LIBS = -lc -lm -lnosys +LIBDIR = +LDFLAGS = $(MCU) -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections -nostdlib + +# default action: build all +all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).bin + + +####################################### +# build the application +####################################### +# list of objects +OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o))) +vpath %.c $(sort $(dir $(C_SOURCES))) +# list of ASM program objects +OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.S=.o))) +vpath %.S $(sort $(dir $(ASM_SOURCES))) + +$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR) + $(CC) -c $(CFLAGS) $< -o $@ + +$(BUILD_DIR)/%.o: %.S Makefile | $(BUILD_DIR) + $(CC) -c $(ASFLAGS) -o $@ $< + +$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile + $(CC) $(OBJECTS) $(LDFLAGS) -o $@ + $(SZ) $@ + +$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR) + $(BIN) $< $@ + +$(BUILD_DIR): + mkdir $@ + +####################################### +# clean up +####################################### +clean: + -rm -fR $(BUILD_DIR) + +####################################### +# dependencies +####################################### +-include $(wildcard $(BUILD_DIR)/*.d) + +# *** EOF *** diff --git a/projects/x2660-halley/Examples/gpio/include/board_eth_phy_conf.h b/projects/x2660-halley/Examples/gpio/include/board_eth_phy_conf.h new file mode 100644 index 00000000..c907ead4 --- /dev/null +++ b/projects/x2660-halley/Examples/gpio/include/board_eth_phy_conf.h @@ -0,0 +1,75 @@ +#ifndef __ETH_PHY_CONF_H +#define __ETH_PHY_CONF_H + +/* ################## Ethernet peripheral configuration ##################### */ + +/* Section 1 : Ethernet peripheral configuration */ + +/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */ +#define MAC_ADDR0 0x00U +#define MAC_ADDR1 0x11U +#define MAC_ADDR2 0x22U +#define MAC_ADDR3 0x33U +#define MAC_ADDR4 0x44U +#define MAC_ADDR5 0x55U + +/* Definition of the Ethernet driver buffers size and count */ +#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */ +#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */ +#define ETH_RXBUFNB ((uint32_t)4U) /* 4 Rx buffers of size ETH_RX_BUF_SIZE */ +#define ETH_TXBUFNB ((uint32_t)4U) /* 4 Tx buffers of size ETH_TX_BUF_SIZE */ + +/* Section 2: PHY configuration section */ + +/* DP83848 PHY Address*/ +#define DP83848_PHY_ADDRESS 0x01U +/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/ +#define PHY_RESET_DELAY ((uint32_t)0x000000FFU) +/* PHY Configuration delay */ +#define PHY_CONFIG_DELAY ((uint32_t)0x00000FFFU) + +#define PHY_READ_TO ((uint32_t)0x0000FFFFU) +#define PHY_WRITE_TO ((uint32_t)0x0000FFFFU) + +/* Section 3: Common PHY Registers */ + +#define PHY_BCR ((uint16_t)0x00U) /*!< Transceiver Basic Control Register */ +#define PHY_BSR ((uint16_t)0x01U) /*!< Transceiver Basic Status Register */ + +#define PHY_RESET ((uint16_t)0x8000U) /*!< PHY Reset */ +#define PHY_LOOPBACK ((uint16_t)0x4000U) /*!< Select loop-back mode */ +#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100U) /*!< Set the full-duplex mode at 100 Mb/s */ +#define PHY_HALFDUPLEX_100M ((uint16_t)0x2600U) /*!< Set the half-duplex mode at 100 Mb/s */ +#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100U) /*!< Set the full-duplex mode at 10 Mb/s */ +#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000U) /*!< Set the half-duplex mode at 10 Mb/s */ +#define PHY_AUTONEGOTIATION ((uint16_t)0x1000U) /*!< Enable auto-negotiation function */ +#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200U) /*!< Restart auto-negotiation function */ +#define PHY_POWERDOWN ((uint16_t)0x0800U) /*!< Select the power down mode */ +#define PHY_ISOLATE ((uint16_t)0x0400U) /*!< Isolate PHY from MII */ + +#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020U) /*!< Auto-Negotiation process completed */ +#define PHY_LINKED_STATUS ((uint16_t)0x0004U) /*!< Valid link established */ +#define PHY_JABBER_DETECTION ((uint16_t)0x0002U) /*!< Jabber condition detected */ + +/* Section 4: Extended PHY Registers */ + +#define PHY_SR ((uint16_t)0x10U) /*!< PHY status register Offset */ +#define PHY_MICR ((uint16_t)0x11U) /*!< MII Interrupt Control Register */ +#define PHY_MISR ((uint16_t)0x12U) /*!< MII Interrupt Status and Misc. Control Register */ + +#define PHY_LINK_STATUS ((uint16_t)0x0001U) /*!< PHY Link mask */ +#define PHY_SPEED_STATUS ((uint16_t)0x0002U) /*!< PHY Speed mask */ +#define PHY_DUPLEX_STATUS ((uint16_t)0x0004U) /*!< PHY Duplex mask */ + +#define PHY_MICR_INT_EN ((uint16_t)0x0002U) /*!< PHY Enable interrupts */ +#define PHY_MICR_INT_OE ((uint16_t)0x0001U) /*!< PHY Enable output interrupt events */ + +#define PHY_MISR_LINK_INT_EN ((uint16_t)0x0020U) /*!< Enable Interrupt on change of link status */ +#define PHY_LINK_INTERRUPT ((uint16_t)0x2600U) /*!< PHY link status interrupt mask */ + +/* ################## Ethernet peripheral configuration ##################### */ + + + +#endif // __ETH_PHY_CONF_H + diff --git a/projects/x2660-halley/Examples/gpio/include/x2600_hal_conf.h b/projects/x2660-halley/Examples/gpio/include/x2600_hal_conf.h new file mode 100644 index 00000000..aa920107 --- /dev/null +++ b/projects/x2660-halley/Examples/gpio/include/x2600_hal_conf.h @@ -0,0 +1,118 @@ +#ifndef __X2000_HAL_CONF_H__ +#define __X2000_HAL_CONF_H__ +/* TODO: 本文件应该通过工具生成,在配置工程中选择不同的组件时,在此处包含不同的头文件 + 暂时包含全部头文件. +*/ + + +/* 1. Includes ---------------------------------------------------- */ + + +/* Hal Module selections. */ +#if 0 +#define HAL_MSC_ENABLED +#define HAL_I2C_ENABLED +#define HAL_UART_ENABLED +#define HAL_ADC_ENABLED +#define HAL_SPI_ENABLED +#define HAL_WDT_ENABLED +#define HAL_TCU_ENABLED +#define HAL_RTC_ENABLED +#define HAL_EFUSE_ENABLED +#define HAL_PWM_ENABLED +#define HAL_GMAC_ENABLED +#define HAL_USB_ENABLED +#endif + +/* 系统时钟配配置,通过工具生成,随开发板或者平台变化.*/ +#include +#include + +#include "x2600_hal_tick.h" +#include "x2600_ll_ost_core.h" +#include "x2600_ll_ost_global.h" +#include "x2600_ll_cpm.h" +#include "x2600_ll_gpio.h" + +#include "x2600_hal_pdma.h" + +//#include "x2600_hal_sfcnor.h" + +#ifdef HAL_MSC_ENABLED + +#endif + +#ifdef HAL_I2C_ENABLED +#include "x2600_hal_i2c.h" +#endif + +#ifdef HAL_UART_ENABLED +#include "x2600_hal_uart.h" +#endif + +#ifdef HAL_ADC_ENABLED +#include "x2600_hal_adc.h" +#endif + +#ifdef HAL_SPI_ENABLED +#include "x2600_hal_spi.h" +#endif + +#ifdef HAL_WDT_ENABLED +#include "x2600_hal_wdt.h" +#endif + +#ifdef HAL_TCU_ENABLED +#include "x2600_hal_tcu.h" +#endif + +#ifdef HAL_RTC_ENABLED +#include "x2600_hal_rtc.h" +#endif + +#ifdef HAL_EFUSE_ENABLED +#include "x2600_ll_efuse.h" +#include "x2600_hal_efuse.h" +#endif + +#ifdef HAL_PWM_ENABLED +#include "x2600_hal_pwm.h" +#endif + +#ifdef HAL_GMAC_ENABLED +#include "x2600_hal_gmac.h" +#endif + +#ifdef HAL_USB_ENABLED +#include "x2600_hal_pcd.h" +#include "x2600_hal_pcd_ex.h" +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* 2. Exported Types ---------------------------------------------- */ + +/* 3. Exported Constants ------------------------------------------ */ + +/* 4. Exported Macros --------------------------------------------- */ + +/* 5. Exported Funcs ---------------------------------------------- */ + +/* 6. Exported Variables ------------------------------------------ */ + +/* 7. Private Types ----------------------------------------------- */ + +/* 8. Private Constants ------------------------------------------- */ + +/* 9. Private Macros ---------------------------------------------- */ + +/* 10. Private Funcs ---------------------------------------------- */ + +/* 11. Private Variables ------------------------------------------ */ + +#ifdef __cplusplus +} +#endif +#endif /* __X2000_HAL_H__ */ diff --git a/projects/x2660-halley/Examples/gpio/include/x2600_sysclk_conf.h b/projects/x2660-halley/Examples/gpio/include/x2600_sysclk_conf.h new file mode 100644 index 00000000..2126aba0 --- /dev/null +++ b/projects/x2660-halley/Examples/gpio/include/x2600_sysclk_conf.h @@ -0,0 +1,68 @@ +/** + * @file x2600_sysclk_conf.h + * @author MPU系统软件部团队 + * @brief + * + * @copyright 版权所有 (北京君正集成电路股份有限公司) {2022} + * @copyright Copyright© 2022 Ingenic Semiconductor Co.,Ltd + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + */ + +#ifndef __X2000_SYSCLK_CONF_H__ +#define __X2000_SYSCLK_CONF_H__ + +#ifdef __cplusplus +extern "C" { +#endif +/* 1. Includes ---------------------------------------------------- */ + +/* 2. Exported Types ---------------------------------------------- */ + + +/* 3. Exported Constants ------------------------------------------ */ + +/* 4. Exported Macros --------------------------------------------- */ +#define SYSCLK_EXTAL (24000000) +#define SYSCLK_APLL (1200000000) +#define SYSCLK_MPLL (1200000000) + +#define SystemCoreClock SYSCLK_APLL + +#define CGU_CONFIG_MSC_APLL_24M { \ + .PLLMux = MSC1CDR_SCLK_A, \ + .Div = 24, \ + .Config = 0 } + +#define CGU_CONFIG_MSC_APLL_48M { \ + .PLLMux = MSC1CDR_SCLK_A, \ + .Div = 11, \ + .Config = 0 } + + +#define CGU_CONFIG_SSI_MPLL_500K { \ + .PLLMux = SSICDR_MPLL, \ + .Div = 15, \ + .Config = 0 } + +/* 5. Exported Funcs ---------------------------------------------- */ + +/* 6. Exported Variables ------------------------------------------ */ + +/* 7. Private Types ----------------------------------------------- */ + +/* 8. Private Constants ------------------------------------------- */ + +/* 9. Private Macros ---------------------------------------------- */ + +/* 10. Private Funcs ---------------------------------------------- */ + +/* 11. Private Variables ------------------------------------------ */ + +#ifdef __cplusplus +} +#endif +#endif /* __X2000_HAL_ADC_H__ */ diff --git a/projects/x2660-halley/Examples/gpio/main.c b/projects/x2660-halley/Examples/gpio/main.c new file mode 100644 index 00000000..b49c4131 --- /dev/null +++ b/projects/x2660-halley/Examples/gpio/main.c @@ -0,0 +1,35 @@ +#include + +void delay(uint32_t d) +{ + while (d--) { + asm volatile("nop\n\t"); + } +} + +void gpio_handler(int irq, void *data) +{ + prom_printk("gpio interrupt happend!\n"); +} + +int main(void) +{ + prom_printk("hello world %s, %d\n", __func__, __LINE__); + + LL_GPIO_getPinLevel(PB_Instance, 25); + + LL_GPIO_setPinMode(PB_Instance, 25, GPIO_MODE_OUTPUT1); + + prom_printk("GPIO level: %d\n", LL_GPIO_getPinLevel(PB_Instance, 25)); + + gpio_request_irq(GPIO_IRQ_PD(14), GPIO_MODE_IRQ_LEVEL_LOW, gpio_handler, NULL); //申请gpio中断,设置PD14管脚为高电平触发中断模式 + + while (1) { + LL_GPIO_setOutputPin(PB_Instance, 25); + delay(10000); + LL_GPIO_clearOutputPin(PB_Instance, 25); + delay(10000); + } + + return 0; +} diff --git a/projects/x2660-halley/Examples/gpio/riscv32-gcc.cmake b/projects/x2660-halley/Examples/gpio/riscv32-gcc.cmake new file mode 100644 index 00000000..d09813df --- /dev/null +++ b/projects/x2660-halley/Examples/gpio/riscv32-gcc.cmake @@ -0,0 +1,18 @@ +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_SYSTEM_PROCESSOR riscv32) + +# Some default GCC settings +set(TOOLCHAIN_PREFIX "riscv32-ingenicv0-elf-") + +set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc) +set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER}) +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++) + +set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}objcopy) +set(CMAKE_SIZE ${TOOLCHAIN_PREFIX}size) + +set(CMAKE_EXECUTABLE_SUFFIX_ASM ".elf") +set(CMAKE_EXECUTABLE_SUFFIX_C ".elf") +set(CMAKE_EXECUTABLE_SUFFIX_CXX ".elf") + +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) -- Gitee