From 732fc749ed8de98d5f47aae3c4c803bafc527c28 Mon Sep 17 00:00:00 2001 From: Raul Munoz Date: Mon, 29 May 2017 16:16:06 -0300 Subject: examples: gpio_bank2_imx: gpio example using just GPIO2 This example control a led and a button just using GPIOs from the bank 2 (GPIO2). Signed-off-by: Raul Munoz Signed-off-by: Stefan Agner --- .../gpio_bank2_imx/armgcc/CMakeLists.txt | 132 +++++++++++++ .../gpio_bank2_imx/armgcc/build_all.bat | 7 + .../gpio_bank2_imx/armgcc/build_all.sh | 7 + .../gpio_bank2_imx/armgcc/clean.bat | 9 + .../driver_examples/gpio_bank2_imx/armgcc/clean.sh | 7 + .../gpio_bank2_imx/armgcc/debug/build_debug.bat | 3 + .../gpio_bank2_imx/armgcc/debug/build_debug.sh | 3 + .../armgcc/release/build_release.bat | 3 + .../gpio_bank2_imx/armgcc/release/build_release.sh | 3 + .../driver_examples/gpio_bank2_imx/gpio_ctrl.c | 214 +++++++++++++++++++++ .../driver_examples/gpio_bank2_imx/gpio_ctrl.h | 76 ++++++++ .../driver_examples/gpio_bank2_imx/hardware_init.c | 54 ++++++ .../driver_examples/gpio_bank2_imx/main.c | 94 +++++++++ 13 files changed, 612 insertions(+) create mode 100644 examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/CMakeLists.txt create mode 100644 examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/build_all.bat create mode 100755 examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/build_all.sh create mode 100644 examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/clean.bat create mode 100755 examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/clean.sh create mode 100644 examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/debug/build_debug.bat create mode 100755 examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/debug/build_debug.sh create mode 100644 examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/release/build_release.bat create mode 100755 examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/release/build_release.sh create mode 100644 examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/gpio_ctrl.c create mode 100644 examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/gpio_ctrl.h create mode 100644 examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/hardware_init.c create mode 100644 examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/main.c diff --git a/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/CMakeLists.txt b/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/CMakeLists.txt new file mode 100644 index 0000000..a308638 --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/CMakeLists.txt @@ -0,0 +1,132 @@ +INCLUDE(CMakeForceCompiler) + +SET(ProjectName gpio_imx) +PROJECT(${ProjectName}) + +# CROSS COMPILER SETTING +SET(CMAKE_SYSTEM_NAME Generic) +CMAKE_MINIMUM_REQUIRED (VERSION 2.6) + +# THE VERSION NUMBER +SET (Tutorial_VERSION_MAJOR 1) +SET (Tutorial_VERSION_MINOR 0) + +# ENABLE ASM +ENABLE_LANGUAGE(ASM) + +SET(CMAKE_STATIC_LIBRARY_PREFIX) +SET(CMAKE_STATIC_LIBRARY_SUFFIX) + +SET(CMAKE_EXECUTABLE_LIBRARY_PREFIX) +SET(CMAKE_EXECUTABLE_LIBRARY_SUFFIX) + +SET(CMAKE_SKIP_INSTALL_RULES TRUE) + +# CURRENT DIRECTORY +SET(ProjDirPath ${CMAKE_CURRENT_SOURCE_DIR}) +SET(BspRootDirPath ${CMAKE_CURRENT_SOURCE_DIR}/../../../../..) + +# RELEASE/DEBUG LINK FILE +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -T MCIMX7D_M4_ocram.ld -static -L ${BspRootDirPath}/platform/devices/MCIMX7D/linker/gcc/") + +# DEFAULT ASM FLAGS +SET(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mthumb -Wall -fno-common -ffunction-sections -fdata-sections -ffreestanding -fno-builtin -mapcs -std=gnu99") + +# DEFAULT C FLAGS +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mthumb -MMD -MP -Wall -fno-common -ffunction-sections -fdata-sections -ffreestanding -fno-builtin -mapcs -std=gnu99") + +# DEFAULT LD FLAGS +SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 --specs=nano.specs -Wall -fno-common -ffunction-sections -fdata-sections -ffreestanding -fno-builtin -mthumb -mapcs -Xlinker --gc-sections -Xlinker -static -Xlinker -z -z max-page-size=4096 -Xlinker muldefs") + +# DEBUG ASM FLAGS +SET(CMAKE_ASM_FLAGS_DEBUG "${CMAKE_ASM_FLAGS_DEBUG} -g") + +# DEBUG C FLAGS +SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -O0") + +# DEBUG LD FLAGS +SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -g") + +# RELEASE C FLAGS +SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Os") + +# ASM MACRO +SET(CMAKE_ASM_FLAGS_DEBUG "${CMAKE_ASM_FLAGS_DEBUG} -D__DEBUG") + +# C MACRO +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCPU_MCIMX7D_M4") +SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D__DEBUG") +SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -D__NDEBUG") + +# INCLUDE_DIRECTORIES +INCLUDE_DIRECTORIES(${ProjDirPath}/..) +INCLUDE_DIRECTORIES(${ProjDirPath}/../../..) +INCLUDE_DIRECTORIES(${BspRootDirPath}/platform/CMSIS/Include) +INCLUDE_DIRECTORIES(${BspRootDirPath}/platform/devices) +INCLUDE_DIRECTORIES(${BspRootDirPath}/platform/devices/MCIMX7D/include) +INCLUDE_DIRECTORIES(${BspRootDirPath}/platform/devices/MCIMX7D/startup) +INCLUDE_DIRECTORIES(${BspRootDirPath}/platform/drivers/inc) +INCLUDE_DIRECTORIES(${BspRootDirPath}/platform/utilities/inc) + + +# ADD_EXECUTABLE +ADD_EXECUTABLE(${ProjectName} + "${BspRootDirPath}/platform/devices/MCIMX7D/startup/gcc/startup_MCIMX7D_M4.S" + "${BspRootDirPath}/platform/utilities/src/debug_console_imx.c" + "${BspRootDirPath}/platform/utilities/inc/debug_console_imx.h" + "${BspRootDirPath}/platform/utilities/src/print_scan.c" + "${BspRootDirPath}/platform/utilities/src/print_scan.h" + "${BspRootDirPath}/platform/drivers/inc/ccm_analog_imx7d.h" + "${BspRootDirPath}/platform/drivers/inc/ccm_imx7d.h" + "${BspRootDirPath}/platform/drivers/inc/lmem.h" + "${BspRootDirPath}/platform/drivers/src/rdc_semaphore.c" + "${BspRootDirPath}/platform/drivers/inc/rdc_semaphore.h" + "${BspRootDirPath}/platform/drivers/inc/rdc.h" + "${BspRootDirPath}/platform/drivers/inc/rdc_defs_imx7d.h" + "${BspRootDirPath}/platform/drivers/inc/wdog_imx.h" + "${BspRootDirPath}/platform/drivers/src/ccm_analog_imx7d.c" + "${BspRootDirPath}/platform/drivers/src/ccm_imx7d.c" + "${BspRootDirPath}/platform/drivers/src/lmem.c" + "${BspRootDirPath}/platform/drivers/src/rdc.c" + "${BspRootDirPath}/platform/drivers/src/wdog_imx.c" + "${BspRootDirPath}/platform/devices/MCIMX7D/startup/system_MCIMX7D_M4.c" + "${BspRootDirPath}/platform/devices/MCIMX7D/startup/system_MCIMX7D_M4.h" + "${BspRootDirPath}/platform/drivers/src/gpio_imx.c" + "${BspRootDirPath}/platform/drivers/inc/gpio_imx.h" + "${ProjDirPath}/../../../pin_mux.c" + "${ProjDirPath}/../../../pin_mux.h" + "${ProjDirPath}/../../../board.c" + "${ProjDirPath}/../../../board.h" + "${ProjDirPath}/../../../clock_freq.c" + "${ProjDirPath}/../../../clock_freq.h" + "${ProjDirPath}/../hardware_init.c" + "${ProjDirPath}/../../../gpio_pins.c" + "${ProjDirPath}/../../../gpio_pins.h" + "${ProjDirPath}/../gpio_ctrl.c" + "${ProjDirPath}/../gpio_ctrl.h" + "${ProjDirPath}/../main.c" + "${BspRootDirPath}/platform/drivers/src/uart_imx.c" + "${BspRootDirPath}/platform/drivers/inc/uart_imx.h" +) +SET_TARGET_PROPERTIES(${ProjectName} PROPERTIES OUTPUT_NAME "${ProjectName}.elf") + +TARGET_LINK_LIBRARIES(${ProjectName} -Wl,--start-group) +# LIBRARIES +IF(CMAKE_BUILD_TYPE MATCHES Debug) +ELSEIF(CMAKE_BUILD_TYPE MATCHES Release) +ENDIF() + +# SYSTEM LIBRARIES +TARGET_LINK_LIBRARIES(${ProjectName} m) +TARGET_LINK_LIBRARIES(${ProjectName} c) +TARGET_LINK_LIBRARIES(${ProjectName} gcc) +TARGET_LINK_LIBRARIES(${ProjectName} nosys) +TARGET_LINK_LIBRARIES(${ProjectName} -Wl,--end-group) + +# MAP FILE +SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Xlinker -Map=${ProjectName}.map") + +# BIN AND HEX +ADD_CUSTOM_COMMAND(TARGET ${ProjectName} POST_BUILD COMMAND ${CMAKE_OBJCOPY} -Oihex ${EXECUTABLE_OUTPUT_PATH}/${ProjectName}.elf ${EXECUTABLE_OUTPUT_PATH}/${ProjectName}.hex) +# bin does not support sparse memory area, which our default linker file uses... +#ADD_CUSTOM_COMMAND(TARGET ${ProjectName} POST_BUILD COMMAND ${CMAKE_OBJCOPY} -Obinary ${EXECUTABLE_OUTPUT_PATH}/${ProjectName}.elf ${EXECUTABLE_OUTPUT_PATH}/${ProjectName}.bin) diff --git a/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/build_all.bat b/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/build_all.bat new file mode 100644 index 0000000..426a29f --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/build_all.bat @@ -0,0 +1,7 @@ +cd release +call build_release.bat +cd .. +cd debug +call build_debug.bat +cd .. +pause diff --git a/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/build_all.sh b/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/build_all.sh new file mode 100755 index 0000000..99e6267 --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/build_all.sh @@ -0,0 +1,7 @@ +#!/bin/sh +cd debug/ +./build_debug.sh +cd .. +cd release/ +./build_release.sh +cd .. diff --git a/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/clean.bat b/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/clean.bat new file mode 100644 index 0000000..fc53949 --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/clean.bat @@ -0,0 +1,9 @@ +cd debug +rd /s /Q CMakeFiles/ +del /s /Q /F Makefile cmake_install.cmake CMakeCache.txt *.elf *.bin *.map *.hex +cd .. +cd release +rd /s /Q CMakeFiles/ +del /s /Q /F Makefile cmake_install.cmake CMakeCache.txt *.elf *.bin *.map *.hex +cd .. +pause diff --git a/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/clean.sh b/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/clean.sh new file mode 100755 index 0000000..4b188ab --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/clean.sh @@ -0,0 +1,7 @@ +#!/bin/sh +cd debug +rm -rf Makefile cmake_install.cmake CMakeCache.txt CMakeFiles *.elf *.bin *.map *.hex .cproject .project +cd .. +cd release +rm -rf Makefile cmake_install.cmake CMakeCache.txt CMakeFiles *.elf *.bin *.map *.hex +cd .. diff --git a/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/debug/build_debug.bat b/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/debug/build_debug.bat new file mode 100644 index 0000000..434e91e --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/debug/build_debug.bat @@ -0,0 +1,3 @@ +cmake -DCMAKE_TOOLCHAIN_FILE="../../../../../tools/cmake_toolchain_files/armgcc.cmake" -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug .. +mingw32-make -j4 +pause diff --git a/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/debug/build_debug.sh b/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/debug/build_debug.sh new file mode 100755 index 0000000..3c169d2 --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/debug/build_debug.sh @@ -0,0 +1,3 @@ +#!/bin/sh +cmake -DCMAKE_TOOLCHAIN_FILE="../../../../../tools/cmake_toolchain_files/armgcc.cmake" -G "Eclipse CDT4 - Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug .. +make -j4 diff --git a/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/release/build_release.bat b/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/release/build_release.bat new file mode 100644 index 0000000..17f773a --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/release/build_release.bat @@ -0,0 +1,3 @@ +cmake -DCMAKE_TOOLCHAIN_FILE="../../../../../tools/cmake_toolchain_files/armgcc.cmake" -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release .. +mingw32-make -j4 +pause diff --git a/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/release/build_release.sh b/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/release/build_release.sh new file mode 100755 index 0000000..1ad7338 --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/armgcc/release/build_release.sh @@ -0,0 +1,3 @@ +#!/bin/sh +cmake -DCMAKE_TOOLCHAIN_FILE="../../../../../tools/cmake_toolchain_files/armgcc.cmake" -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release .. +make -j4 diff --git a/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/gpio_ctrl.c b/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/gpio_ctrl.c new file mode 100644 index 0000000..f3d1eed --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/gpio_ctrl.c @@ -0,0 +1,214 @@ +/* + * Copyright (c) 2015, Freescale Semiconductor, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * o Redistributions of source code must retain the above copyright notice, this list + * of conditions and the following disclaimer. + * + * o Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * o Neither the name of Freescale Semiconductor, Inc. nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/**************************************************************************** +* +* Comments: +* This file contains the functions which write and read the SPI memories +* using the ECSPI driver in interrupt mode. +* +****************************************************************************/ + +#include +#include "gpio_pins.h" +#include "board.h" +#include "gpio_ctrl.h" +#include "gpio_imx.h" +#include "rdc_semaphore.h" +#include "debug_console_imx.h" + +#define GPIO_DEBOUNCE_DELAY (100000) + + +void GPIO_Ctrl_InitSwitch1Pin() +{ +#ifdef BOARD_GPIO_SWITCH1_CONFIG + /* Acquire RDC semaphore before access GPIO to avoid conflict, it's + * necessary when GPIO RDC is configured as Semaphore Required */ + RDC_SEMAPHORE_Lock(BOARD_GPIO_SWITCH1_RDC_PDAP); + GPIO_Init(BOARD_GPIO_SWITCH1_CONFIG->base, &Switch1); + RDC_SEMAPHORE_Unlock(BOARD_GPIO_SWITCH1_RDC_PDAP); +#endif +} + +void GPIO_Ctrl_InitLed1Pin() +{ +#ifdef BOARD_GPIO_LED1_CONFIG + /* Acquire RDC semaphore before access GPIO to avoid conflict, it's + * necessary when GPIO RDC is configured as Semaphore Required */ + RDC_SEMAPHORE_Lock(BOARD_GPIO_LED1_RDC_PDAP); + GPIO_Init(BOARD_GPIO_LED1_CONFIG->base, &Led1); + RDC_SEMAPHORE_Unlock(BOARD_GPIO_LED1_RDC_PDAP); +#endif +} + +void GPIO_Ctrl_InitSwitch2Pin() +{ +#ifdef BOARD_GPIO_SWITCH2_CONFIG + /* Acquire RDC semaphore before access GPIO to avoid conflict, it's + * necessary when GPIO RDC is configured as Semaphore Required */ + RDC_SEMAPHORE_Lock(BOARD_GPIO_SWITCH2_RDC_PDAP); + GPIO_Init(BOARD_GPIO_SWITCH2_CONFIG->base, &Switch2); + RDC_SEMAPHORE_Unlock(BOARD_GPIO_SWITCH2_RDC_PDAP); +#endif +} + +void GPIO_Ctrl_InitLed2Pin() +{ +#ifdef BOARD_GPIO_LED2_CONFIG + /* Acquire RDC semaphore before access GPIO to avoid conflict, it's + * necessary when GPIO RDC is configured as Semaphore Required */ + RDC_SEMAPHORE_Lock(BOARD_GPIO_LED2_RDC_PDAP); + GPIO_Init(BOARD_GPIO_LED2_CONFIG->base, &Led2); + RDC_SEMAPHORE_Unlock(BOARD_GPIO_LED2_RDC_PDAP); +#endif +} + +void GPIO_Ctrl_Init() +{ + GPIO_Ctrl_InitSwitch1Pin(); + GPIO_Ctrl_InitLed1Pin(); + GPIO_Ctrl_InitSwitch2Pin(); + GPIO_Ctrl_InitLed2Pin(); +} + +void GPIO_Ctrl_ToggleLed(gpio_config_t *boardGpioConfig, uint32_t boardGpioRdc) +{ + static bool onLed0 = 0; + onLed0 = GPIO_ReadPinOutput(boardGpioConfig->base, boardGpioConfig->pin); + if(onLed0 == 0) + { + RDC_SEMAPHORE_Lock(boardGpioRdc); + GPIO_WritePinOutput(boardGpioConfig->base, + boardGpioConfig->pin, gpioPinSet); + RDC_SEMAPHORE_Unlock(boardGpioRdc); + } + else + { + RDC_SEMAPHORE_Lock(boardGpioRdc); + GPIO_WritePinOutput(boardGpioConfig->base, + boardGpioConfig->pin, gpioPinClear); + RDC_SEMAPHORE_Unlock(boardGpioRdc); + } +} + +void GPIO_Ctrl_ClearLed(gpio_config_t *boardGpioConfig, uint32_t boardGpioRdc) +{ + RDC_SEMAPHORE_Lock(boardGpioRdc); + GPIO_WritePinOutput(boardGpioConfig->base, + boardGpioConfig->pin, gpioPinClear); + RDC_SEMAPHORE_Unlock(boardGpioRdc); +} + +void GPIO_Ctrl_SetLed(gpio_config_t *boardGpioConfig, uint32_t boardGpioRdc) +{ + + RDC_SEMAPHORE_Lock(boardGpioRdc); + GPIO_WritePinOutput(boardGpioConfig->base, + boardGpioConfig->pin, gpioPinSet); + RDC_SEMAPHORE_Unlock(boardGpioRdc); +} + +void GPIO_Ctrl_WriteLed(gpio_config_t *boardGpioConfig, uint32_t boardGpioRdc, uint32_t value) +{ + RDC_SEMAPHORE_Lock(boardGpioRdc); + GPIO_WritePinOutput(boardGpioConfig->base, + boardGpioConfig->pin, value); + RDC_SEMAPHORE_Unlock(boardGpioRdc); +} + + +uint32_t GPIO_Ctrl_GetKey(gpio_config_t *boardGpioConfig) +{ + return GPIO_ReadPinInput(boardGpioConfig->base, boardGpioConfig->pin); +} + +void GPIO_WaitKeyPressed(gpio_config_t *boardGpioConfig, uint32_t boardGpioRdc) +{ + uint32_t i, j, debounce; + /* Wait for Key Released. */ + do + { + debounce = 0; + while (0 == GPIO_ReadPinInput(boardGpioConfig->base, boardGpioConfig->pin)); + + for (i = 0; i < 3; i++) + { + /* Delay to wait key value stable. The cycle number should be changed + * according to M4 Core clock frequncy. + */ + for (j = 0 ; j < GPIO_DEBOUNCE_DELAY; j++) + { + __NOP(); + } + + if (1 == GPIO_ReadPinInput(boardGpioConfig->base, boardGpioConfig->pin)) + { + debounce++; + } + } + + if (debounce > 2) + { + break; + } + } + while (1); +} +#ifdef BOARD_GPIO_KEY_CONFIG +void BOARD_GPIO_KEY_HANDLER() +{ + + + /* When user input captured, we disable GPIO interrupt */ + NVIC_DisableIRQ(BOARD_GPIO_KEY_IRQ_NUM); + + RDC_SEMAPHORE_Lock(BOARD_GPIO_KEY_RDC_PDAP); + + /* Disable GPIO pin interrupt */ + GPIO_SetPinIntMode(BOARD_GPIO_KEY_CONFIG->base, BOARD_GPIO_KEY_CONFIG->pin, false); + /* Clear the interrupt state */ + GPIO_ClearStatusFlag(BOARD_GPIO_KEY_CONFIG->base, BOARD_GPIO_KEY_CONFIG->pin); + + RDC_SEMAPHORE_Unlock(BOARD_GPIO_KEY_RDC_PDAP); + +#ifdef xSemaphoreGiveFromISR + BaseType_t xHigherPriorityTaskWoken = pdFALSE; + /* Unlock the task to process the event. */ + xSemaphoreGiveFromISR(xSemaphore, &xHigherPriorityTaskWoken); + + /* Perform a context switch to wake the higher priority task. */ + portYIELD_FROM_ISR(xHigherPriorityTaskWoken); +#endif +} +#endif + +/******************************************************************************* + * EOF + ******************************************************************************/ diff --git a/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/gpio_ctrl.h b/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/gpio_ctrl.h new file mode 100644 index 0000000..4b20ce1 --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/gpio_ctrl.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2015, Freescale Semiconductor, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * o Redistributions of source code must retain the above copyright notice, this list + * of conditions and the following disclaimer. + * + * o Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * o Neither the name of Freescale Semiconductor, Inc. nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __GPIO_CTRL_H__ +#define __GPIO_CTRL_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/*! + * @brief Initialize GPIO controller. + */ +void GPIO_Ctrl_Init(void); + +/*! + * @brief Toggle LED on/off status + */ +void GPIO_Ctrl_ToggleLed(gpio_config_t *boardGpioConfig, uint32_t boardGpioRdc); +/*! + * @brief Clear LED on/off status + */ +void GPIO_Ctrl_ClearLed(gpio_config_t *boardGpioConfig, uint32_t boardGpioRdc); +/*! + * @brief Set LED on/off status + */ +void GPIO_Ctrl_SetLed(gpio_config_t *boardGpioConfig, uint32_t boardGpioRdc); +/*! + * @brief write LED on/off status + */ +void GPIO_Ctrl_WriteLed(gpio_config_t *boardGpioConfig, uint32_t boardGpioRdc, uint32_t value); +/*! + * @brief Get Key on/off status + */ +uint32_t GPIO_Ctrl_GetKey(gpio_config_t *boardGpioConfig); + +/*! + * @brief Get Key on/off status + */ +void GPIO_WaitKeyPressed(gpio_config_t *boardGpioConfig, uint32_t boardGpioRdc); + +#ifdef __cplusplus +} +#endif + +#endif /* __GPIO_CTRL_H__ */ +/******************************************************************************* + * EOF + ******************************************************************************/ diff --git a/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/hardware_init.c b/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/hardware_init.c new file mode 100644 index 0000000..c0be651 --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/hardware_init.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2015, Freescale Semiconductor, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * o Redistributions of source code must retain the above copyright notice, this list + * of conditions and the following disclaimer. + * + * o Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * o Neither the name of Freescale Semiconductor, Inc. nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "gpio_pins.h" +#include "board.h" + +void hardware_init(void) +{ + /* Board specific RDC settings */ + BOARD_RdcInit(); + /* Board specific clock settings */ + BOARD_ClockInit(); + /* initialize debug uart */ + dbg_uart_init(); + + /* In this demo, we need to share board GPIO, we can set sreq argument to true + * when the peer core could also access GPIO with RDC_SEMAPHORE, or the peer + * core doesn't access the GPIO at all */ + RDC_SetPdapAccess(RDC, rdcPdapGpio2, 0xFF, false/*true*/, false); + + /* Enable gpio clock gate */ + // CCM_ControlGate(CCM, BOARD_GPIO_KEY_CCM_CCGR, ccmClockNeededRunWait); +} + +/******************************************************************************* + * EOF + ******************************************************************************/ diff --git a/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/main.c b/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/main.c new file mode 100644 index 0000000..c130c31 --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/gpio_bank2_imx/main.c @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2015, Freescale Semiconductor, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * o Redistributions of source code must retain the above copyright notice, this list + * of conditions and the following disclaimer. + * + * o Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * o Neither the name of Freescale Semiconductor, Inc. nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "board.h" +#include "gpio_pins.h" +#include "gpio_imx.h" +#include "gpio_ctrl.h" +#include "debug_console_imx.h" + + +/* button relevent variables */ +static uint8_t keyPressCount; +static uint8_t keyPressCountOld; + + +/****************************************************************************** +* +* Function Name: main +* Comments: Hello World Example with GPIO. +* This example include: +* Configure BUTTON1 as GPIO functionality +* and check the button's state(pressed or released). According to the Button +* status, copy it to the LED +* +******************************************************************************/ +int main(void) +{ + /* hardware initialiize, include RDC, IOMUX, Uart debug initialize */ + hardware_init(); + PRINTF("\n\r\n\r\n\r"); + PRINTF("=======================================================\n\r"); + PRINTF("================= GPIO Bank 2 Example =================\n\r"); + PRINTF("===== Change the Led Status according to the Key ======\n\r"); + PRINTF("=======================================================\n\r"); + + /* GPIO module initialize, configure "LED" as output and button as interrupt mode. */ + GPIO_Ctrl_Init(); + + keyPressCount = 0; + keyPressCountOld = 0; + + /* Initialize enviroments and led status */ + keyPressCount = GPIO_Ctrl_GetKey(BOARD_GPIO_SWITCH1_CONFIG); + keyPressCountOld = keyPressCount; + GPIO_Ctrl_WriteLed(BOARD_GPIO_LED1_CONFIG, BOARD_GPIO_LED1_RDC_PDAP, keyPressCount); + + PRINTF("================== Hello World GPIO ===================\n\r"); + + while(true) + { + /* wait for user change button leve */ + keyPressCount = GPIO_Ctrl_GetKey(BOARD_GPIO_SWITCH1_CONFIG); + /* If button change, than print and update LED */ + if(keyPressCount != keyPressCountOld) + { + keyPressCountOld = keyPressCount; + GPIO_Ctrl_WriteLed(BOARD_GPIO_LED1_CONFIG, BOARD_GPIO_LED1_RDC_PDAP, keyPressCount); + PRINTF("================== keyPressCount = %d ==================\n\r", keyPressCount); + } + } +} + + +/******************************************************************************* + * EOF + ******************************************************************************/ -- cgit v1.2.3