From 68a56e94de556ae868220559843bc5c679aec2da Mon Sep 17 00:00:00 2001 From: Hongpeng HUO Date: Fri, 19 Aug 2022 13:52:02 +0800 Subject: [PATCH] Enable GPIO all features Signed-off-by: Hongpeng HUO --- application/BUILD.gn | 1 + application/Kconfig.liteos_m.defconfig.board | 12 +++ application/gpio/BUILD.gn | 43 +++++++++ application/gpio/app_gpio_in.c | 94 ++++++++++++++++++++ application/gpio/app_gpio_irq.c | 66 ++++++++++++++ application/gpio/app_gpio_out.c | 82 +++++++++++++++++ hpm6750evk/liteos_m/ld/liteos_flash_xip.ld | 7 +- 7 files changed, 299 insertions(+), 6 deletions(-) create mode 100644 application/gpio/BUILD.gn create mode 100644 application/gpio/app_gpio_in.c create mode 100644 application/gpio/app_gpio_irq.c create mode 100644 application/gpio/app_gpio_out.c diff --git a/application/BUILD.gn b/application/BUILD.gn index 014159d..e4277e3 100644 --- a/application/BUILD.gn +++ b/application/BUILD.gn @@ -17,6 +17,7 @@ module_name = get_path_info(rebase_path("."), "name") module_group(module_name) { modules = [ "watchdog", + "gpio", ] } diff --git a/application/Kconfig.liteos_m.defconfig.board b/application/Kconfig.liteos_m.defconfig.board index 28b872f..4359028 100644 --- a/application/Kconfig.liteos_m.defconfig.board +++ b/application/Kconfig.liteos_m.defconfig.board @@ -17,6 +17,18 @@ menu "Applications for HPMicro" config WDT_DRIVER_TEST bool "watchdog driver test" default n + +config GPIO_DRIVER_IN_TEST + bool "gpio driver input test" + default n + +config GPIO_DRIVER_OUT_TEST + bool "gpio driver output test" + default n + +config GPIO_DRIVER_IRQ_TEST + bool "gpio driver interrupt test" + default n endmenu endif #BOARD_COMPANY_HPMCIRO diff --git a/application/gpio/BUILD.gn b/application/gpio/BUILD.gn new file mode 100644 index 0000000..f76bd76 --- /dev/null +++ b/application/gpio/BUILD.gn @@ -0,0 +1,43 @@ +# Copyright (c) 2022 HPMicro. +# Licensed 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. + +import("//kernel/liteos_m/liteos.gni") +import("//drivers/hdf_core/adapter/khdf/liteos_m/hdf.gni") + +module_name = get_path_info(rebase_path("."), "name") +module_switch = true + +hdf_driver(module_name) { + include_dirs = [ + "//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog_lite" + ] + + sources = [] + if (defined(LOSCFG_GPIO_DRIVER_IN_TEST)) { + sources += [ + "app_gpio_in.c", + ] + } + + if (defined(LOSCFG_GPIO_DRIVER_OUT_TEST)) { + sources += [ + "app_gpio_out.c", + ] + } + + if (defined(LOSCFG_GPIO_DRIVER_IRQ_TEST)) { + sources += [ + "app_gpio_irq.c", + ] + } +} diff --git a/application/gpio/app_gpio_in.c b/application/gpio/app_gpio_in.c new file mode 100644 index 0000000..3e4a2b3 --- /dev/null +++ b/application/gpio/app_gpio_in.c @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2022 HPMicro. + * Licensed 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. + */ +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOG_TAG "HPM_GPIO_OUT" + +#define GPIOA(pin) (pin) +#define GPIOB(pin) (pin + 32) +#define GPIOC(pin) (pin + 32 * 2) +#define GPIOD(pin) (pin + 32 * 3) +#define GPIOE(pin) (pin + 32 * 4) +#define GPIOF(pin) (pin + 32 * 5) +#define GPIOY(pin) (pin + 32 * 14) +#define GPIOZ(pin) (pin + 32 * 15) + +static void GpioDriverInTestTask(uint32_t arg) +{ + HILOG_INFO(HILOG_MODULE_APP, "GpioDriverInTestTask"); + + HPM_BIOC->PAD[IOC_PAD_PZ02].FUNC_CTL = IOC_PZ02_FUNC_CTL_SOC_PZ_02; + HPM_BIOC->PAD[IOC_PAD_PZ02].PAD_CTL = IOC_PAD_PAD_CTL_PE_SET(1) | IOC_PAD_PAD_CTL_PS_SET(1) | IOC_PAD_PAD_CTL_SMT_SET(1); + HPM_BIOC->PAD[IOC_PAD_PZ03].FUNC_CTL = IOC_PZ03_FUNC_CTL_SOC_PZ_03; + HPM_BIOC->PAD[IOC_PAD_PZ03].PAD_CTL = IOC_PAD_PAD_CTL_PE_SET(1) | IOC_PAD_PAD_CTL_PS_SET(1) | IOC_PAD_PAD_CTL_SMT_SET(1); + + HPM_IOC->PAD[IOC_PAD_PZ02].FUNC_CTL = 0; + HPM_IOC->PAD[IOC_PAD_PZ02].PAD_CTL = IOC_PAD_PAD_CTL_PE_SET(1) | IOC_PAD_PAD_CTL_PS_SET(1) | IOC_PAD_PAD_CTL_SMT_SET(1); + + HPM_IOC->PAD[IOC_PAD_PZ03].FUNC_CTL = 0; + HPM_IOC->PAD[IOC_PAD_PZ03].PAD_CTL = IOC_PAD_PAD_CTL_PE_SET(1) | IOC_PAD_PAD_CTL_PS_SET(1) | IOC_PAD_PAD_CTL_SMT_SET(1); + + GpioSetDir(GPIOZ(2), GPIO_DIR_IN); + GpioSetDir(GPIOZ(3), GPIO_DIR_IN); + + uint32_t pz02_flag = GPIO_VAL_HIGH; + uint32_t pz03_flag = GPIO_VAL_HIGH; + + while (1) { + uint16_t val; + GpioRead(GPIOZ(2), &val); + if (val == GPIO_VAL_LOW && pz02_flag == GPIO_VAL_HIGH) { + pz02_flag = GPIO_VAL_LOW; + HILOG_INFO(HILOG_MODULE_APP, "GPIOZ(2) DOWN"); + } else if (val == GPIO_VAL_HIGH && pz02_flag == GPIO_VAL_LOW) { + pz02_flag = GPIO_VAL_HIGH; + HILOG_INFO(HILOG_MODULE_APP, "GPIOZ(2) UP"); + } + + GpioRead(GPIOZ(3), &val); + if (val == GPIO_VAL_LOW && pz03_flag == GPIO_VAL_HIGH) { + pz03_flag = GPIO_VAL_LOW; + HILOG_INFO(HILOG_MODULE_APP, "GPIOZ(3) DOWN"); + } else if (val == GPIO_VAL_HIGH && pz03_flag == GPIO_VAL_LOW) { + pz03_flag = GPIO_VAL_HIGH; + HILOG_INFO(HILOG_MODULE_APP, "GPIOZ(3) UP"); + } + + LOS_TaskDelay(50); + } +} + +static void GpioDriverTest(void) +{ + TSK_INIT_PARAM_S taskInitParam = {0}; + + taskInitParam.pcName = "gpio_in_test"; + taskInitParam.pfnTaskEntry = GpioDriverInTestTask; + taskInitParam.stackAddr = 0; + taskInitParam.uwStackSize = 4096; + taskInitParam.usTaskPrio = 20; + taskInitParam.uwArg = 0x66; + uint32_t taskID; + LOS_TaskCreate(&taskID, &taskInitParam); +} + +APP_FEATURE_INIT(GpioDriverTest); diff --git a/application/gpio/app_gpio_irq.c b/application/gpio/app_gpio_irq.c new file mode 100644 index 0000000..dbc6889 --- /dev/null +++ b/application/gpio/app_gpio_irq.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2022 HPMicro. + * Licensed 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. + */ +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOG_TAG "HPM_GPIO_OUT" + +#define GPIOA(pin) (pin) +#define GPIOB(pin) (pin + 32) +#define GPIOC(pin) (pin + 32 * 2) +#define GPIOD(pin) (pin + 32 * 3) +#define GPIOE(pin) (pin + 32 * 4) +#define GPIOF(pin) (pin + 32 * 5) +#define GPIOY(pin) (pin + 32 * 14) +#define GPIOZ(pin) (pin + 32 * 15) + + +static int32_t GpioIrq(uint16_t gpio, void *data) +{ + HILOG_INFO(HILOG_MODULE_APP, "gpio: %u", gpio); +} + +static void GpioDriverInTestTask(void) +{ + HILOG_INFO(HILOG_MODULE_APP, "GpioDriverIrqTest"); + + HPM_BIOC->PAD[IOC_PAD_PZ02].FUNC_CTL = IOC_PZ02_FUNC_CTL_SOC_PZ_02; + HPM_BIOC->PAD[IOC_PAD_PZ02].PAD_CTL = IOC_PAD_PAD_CTL_PE_SET(1) | IOC_PAD_PAD_CTL_PS_SET(1) | IOC_PAD_PAD_CTL_SMT_SET(1); + HPM_BIOC->PAD[IOC_PAD_PZ03].FUNC_CTL = IOC_PZ03_FUNC_CTL_SOC_PZ_03; + HPM_BIOC->PAD[IOC_PAD_PZ03].PAD_CTL = IOC_PAD_PAD_CTL_PE_SET(1) | IOC_PAD_PAD_CTL_PS_SET(1) | IOC_PAD_PAD_CTL_SMT_SET(1); + + HPM_IOC->PAD[IOC_PAD_PZ02].FUNC_CTL = 0; + HPM_IOC->PAD[IOC_PAD_PZ02].PAD_CTL = IOC_PAD_PAD_CTL_PE_SET(1) | IOC_PAD_PAD_CTL_PS_SET(1) | IOC_PAD_PAD_CTL_SMT_SET(1); + + HPM_IOC->PAD[IOC_PAD_PZ03].FUNC_CTL = 0; + HPM_IOC->PAD[IOC_PAD_PZ03].PAD_CTL = IOC_PAD_PAD_CTL_PE_SET(1) | IOC_PAD_PAD_CTL_PS_SET(1) | IOC_PAD_PAD_CTL_SMT_SET(1); + + GpioSetDir(GPIOZ(2), GPIO_DIR_IN); + GpioSetDir(GPIOZ(3), GPIO_DIR_IN); + + GpioSetIrq(GPIOZ(2), GPIO_IRQ_TRIGGER_RISING, GpioIrq, NULL); + GpioSetIrq(GPIOZ(3), GPIO_IRQ_TRIGGER_FALLING, GpioIrq, NULL); + + GpioEnableIrq(GPIOZ(2)); + GpioEnableIrq(GPIOZ(3)); +} + +APP_FEATURE_INIT(GpioDriverInTestTask); diff --git a/application/gpio/app_gpio_out.c b/application/gpio/app_gpio_out.c new file mode 100644 index 0000000..834fc77 --- /dev/null +++ b/application/gpio/app_gpio_out.c @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2022 HPMicro. + * Licensed 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. + */ +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOG_TAG "HPM_GPIO_OUT" + +#define GPIOA(pin) (pin) +#define GPIOB(pin) (pin + 32) +#define GPIOC(pin) (pin + 32 * 2) +#define GPIOD(pin) (pin + 32 * 3) +#define GPIOE(pin) (pin + 32 * 4) +#define GPIOF(pin) (pin + 32 * 5) +#define GPIOY(pin) (pin + 32 * 14) +#define GPIOZ(pin) (pin + 32 * 15) + +static void GpioDriverOutTestTask(uint32_t arg) +{ + HILOG_INFO(HILOG_MODULE_APP, "GpioDriverOutTestTask"); + + HPM_IOC->PAD[IOC_PAD_PB11].FUNC_CTL = 0; + HPM_IOC->PAD[IOC_PAD_PB11].PAD_CTL = IOC_PAD_PAD_CTL_PE_SET(1) | IOC_PAD_PAD_CTL_PS_SET(1); + + HPM_IOC->PAD[IOC_PAD_PB12].FUNC_CTL = 0; + HPM_IOC->PAD[IOC_PAD_PB12].PAD_CTL = IOC_PAD_PAD_CTL_PE_SET(1) | IOC_PAD_PAD_CTL_PS_SET(1); + + HPM_IOC->PAD[IOC_PAD_PB13].FUNC_CTL = 0; + HPM_IOC->PAD[IOC_PAD_PB13].PAD_CTL = IOC_PAD_PAD_CTL_PE_SET(1) | IOC_PAD_PAD_CTL_PS_SET(1); + + GpioSetDir(GPIOB(11), GPIO_DIR_OUT); + GpioSetDir(GPIOB(12), GPIO_DIR_OUT); + GpioSetDir(GPIOB(13), GPIO_DIR_OUT); + + while (1) { + GpioWrite(GPIOB(11), GPIO_VAL_LOW); + LOS_TaskDelay(500); + GpioWrite(GPIOB(11), GPIO_VAL_HIGH); + LOS_TaskDelay(500); + GpioWrite(GPIOB(12), GPIO_VAL_LOW); + LOS_TaskDelay(500); + GpioWrite(GPIOB(12), GPIO_VAL_HIGH); + LOS_TaskDelay(500); + GpioWrite(GPIOB(13), GPIO_VAL_LOW); + LOS_TaskDelay(500); + GpioWrite(GPIOB(13), GPIO_VAL_HIGH); + LOS_TaskDelay(500); + } +} + +static void GpioDriverTest(void) +{ + TSK_INIT_PARAM_S taskInitParam = {0}; + + taskInitParam.pcName = "gpio_out_test"; + taskInitParam.pfnTaskEntry = GpioDriverOutTestTask; + taskInitParam.stackAddr = 0; + taskInitParam.uwStackSize = 4096; + taskInitParam.usTaskPrio = 20; + taskInitParam.uwArg = 0x66; + uint32_t taskID; + LOS_TaskCreate(&taskID, &taskInitParam); +} + +APP_FEATURE_INIT(GpioDriverTest); diff --git a/hpm6750evk/liteos_m/ld/liteos_flash_xip.ld b/hpm6750evk/liteos_m/ld/liteos_flash_xip.ld index 4caea9e..60b14f2 100644 --- a/hpm6750evk/liteos_m/ld/liteos_flash_xip.ld +++ b/hpm6750evk/liteos_m/ld/liteos_flash_xip.ld @@ -6,7 +6,7 @@ ENTRY(_start) STACK_SIZE = DEFINED(_stack_size) ? _stack_size : 0x4000; -HEAP_SIZE = DEFINED(_heap_size) ? _heap_size : 0x10000; +HEAP_SIZE = DEFINED(_heap_size) ? _heap_size : 0x40000; MEMORY { @@ -50,11 +50,6 @@ SECTIONS *(.rodata*) *(.srodata) *(.srodata*) - - - - - *(.hash) *(.dyn*) *(.gnu*)