From dba4fcde90567248c78984fee0db4ac25d8eb86c Mon Sep 17 00:00:00 2001 From: Pankaj Goenka Date: Fri, 4 Dec 2015 01:09:27 +0530 Subject: [PATCH 1/4] Adding CMSIS HAL for GPIO Driver Modified the SH-Xpresso-LPC54102 project to include HAL files Signed-off-by: Pankaj Goenka --- .../keil-mdk-build/SH-Xpresso-LPC54102.uvoptx | 21 ++ .../SH-Xpresso-LPC54102.uvprojx | 42 ++- .../sources/app/hostif_i2c.c | 12 +- .../SH-Xpresso-LPC54102/sources/app/main.c | 4 +- .../sources/boardsupport/hw_setup.c | 76 +---- .../boardsupport/hw_setup_xpresso_lpc54102.h | 6 + external/CMSIS/Include/Driver_Common.h | 72 +++++ external/CMSIS/Include/Driver_GPIO.h | 103 +++++++ external/CMSIS/NXP/LPC5410x/Driver_GPIO.c | 286 ++++++++++++++++++ 9 files changed, 544 insertions(+), 78 deletions(-) create mode 100644 external/CMSIS/Include/Driver_Common.h create mode 100644 external/CMSIS/Include/Driver_GPIO.h create mode 100644 external/CMSIS/NXP/LPC5410x/Driver_GPIO.c diff --git a/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvoptx b/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvoptx index 625f4ec..d2c5a5f 100644 --- a/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvoptx +++ b/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvoptx @@ -1365,6 +1365,27 @@ + + Device + 0 + 0 + 0 + 0 + + 13 + 39 + 1 + 0 + 0 + 0 + 0 + ..\..\..\..\external\CMSIS\NXP\LPC5410x\Driver_GPIO.c + Driver_GPIO.c + 0 + 0 + + + ::CMSIS 0 diff --git a/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvprojx b/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvprojx index c44dd66..006e42d 100644 --- a/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvprojx +++ b/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvprojx @@ -790,6 +790,16 @@ + + Device + + + Driver_GPIO.c + 1 + ..\..\..\..\external\CMSIS\NXP\LPC5410x\Driver_GPIO.c + + + ::CMSIS @@ -1579,6 +1589,16 @@ + + Device + + + Driver_GPIO.c + 1 + ..\..\..\..\external\CMSIS\NXP\LPC5410x\Driver_GPIO.c + + + ::CMSIS @@ -2368,6 +2388,16 @@ + + Device + + + Driver_GPIO.c + 1 + ..\..\..\..\external\CMSIS\NXP\LPC5410x\Driver_GPIO.c + + + ::CMSIS @@ -2740,7 +2770,7 @@ SYSTEM_CLOCK_FREQ=96000000, __FPU_PRESENT=1, CHIP_LPC5410X, CORE_M4, DEBUG_BUILD, XPRESSO_LPC54102_BOARD, UART_DMA_ENABLE, ANDROID_DEMO, ASF_PROFILING, ON_DEMAND_PROFILING - ..\sources\app;..\sources\config;..\sources\boardsupport;..\..\..\..\include;..\..\..\common\app;..\..\..\common\asf;..\..\..\common\alg;..\..\..\..\external\rtos\rtx\inc;..\..\..\..\external\rtos\rtx\cm;..\..\..\..\external\MCU\NXP-5410x\CSLib\inc;..\..\..\common\modules\bus-drivers;..\..\..\common\modules\sensor-drivers;..\..\..\..\external\Drivers\Sensor\Bosch-Sensortec;..\..\..\common\hostinterface + ..\sources\app;..\sources\config;..\sources\boardsupport;..\..\..\..\include;..\..\..\common\app;..\..\..\common\asf;..\..\..\common\alg;..\..\..\..\external\rtos\rtx\inc;..\..\..\..\external\rtos\rtx\cm;..\..\..\..\external\MCU\NXP-5410x\CSLib\inc;..\..\..\common\modules\bus-drivers;..\..\..\common\modules\sensor-drivers;..\..\..\..\external\Drivers\Sensor\Bosch-Sensortec;..\..\..\common\hostinterface;..\..\..\..\external\CMSIS\Include @@ -3157,6 +3187,16 @@ + + Device + + + Driver_GPIO.c + 1 + ..\..\..\..\external\CMSIS\NXP\LPC5410x\Driver_GPIO.c + + + ::CMSIS diff --git a/embedded/projects/SH-Xpresso-LPC54102/sources/app/hostif_i2c.c b/embedded/projects/SH-Xpresso-LPC54102/sources/app/hostif_i2c.c index a8e2fdd..21ee3e4 100644 --- a/embedded/projects/SH-Xpresso-LPC54102/sources/app/hostif_i2c.c +++ b/embedded/projects/SH-Xpresso-LPC54102/sources/app/hostif_i2c.c @@ -24,6 +24,7 @@ #include "i2cs_driver.h" #include "hostif_i2c.h" #include +#include "Driver_GPIO.h" /*-------------------------------------------------------------------------------------------------*\ | E X T E R N A L V A R I A B L E S & F U N C T I O N S @@ -63,6 +64,11 @@ typedef struct _HostGCResponse uint8_t szLSB; //data size LSB } HostGCResponse_t; +/*-------------------------------------------------------------------------------------------------*\ + | E X T E R N A L V A R I A B L E S & F U N C T I O N S +\*-------------------------------------------------------------------------------------------------*/ +extern ARM_DRIVER_GPIO Driver_GPIO; + typedef struct __HOSTIF_Ctrl_t { uint16_t rxCount; /* Bytes so far received */ uint16_t txCountSet; @@ -362,10 +368,10 @@ void Hostif_I2C_Init(void) i2c_slave_mode(&slave_i2c_handle,1); /* init host interrupt pin */ - Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN); + Driver_GPIO.SetDirection (ENCODE_PORT_PIN(HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN), ARM_GPIO_DIR_OUTPUT); /* de-assert interrupt line to high to indicate Host/AP that - * there is no data to receive */ - Chip_GPIO_SetPinState(LPC_GPIO_PORT, HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN, 0); + * there is no data to receive */ + Driver_GPIO.WritePin (ENCODE_PORT_PIN(HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN), false); /* Enable the interrupt for the I2C */ NVIC_SetPriority(I2C_HOSTIF_IRQn, HOSTIF_IRQ_PRIORITY); diff --git a/embedded/projects/SH-Xpresso-LPC54102/sources/app/main.c b/embedded/projects/SH-Xpresso-LPC54102/sources/app/main.c index 134144f..9cc4ec9 100644 --- a/embedded/projects/SH-Xpresso-LPC54102/sources/app/main.c +++ b/embedded/projects/SH-Xpresso-LPC54102/sources/app/main.c @@ -20,6 +20,7 @@ \*-------------------------------------------------------------------------------------------------*/ #include "common.h" #include "hw_setup.h" +#include "Driver_GPIO.h" /*-------------------------------------------------------------------------------------------------*\ | E X T E R N A L V A R I A B L E S & F U N C T I O N S @@ -29,6 +30,7 @@ extern uint32_t gStackSize; extern const char C_gStackPattern[8]; #endif +extern ARM_DRIVER_GPIO Driver_GPIO; void SPISlaveSetup( void ); @@ -102,7 +104,7 @@ int main( void ) SystemCoreClockUpdate(); /* Configure the GPIO ports (non module specific) */ - SystemGPIOConfig(); + Driver_GPIO.Initialize(); /* Set startup state of LEDs */ LED_Init(); /* Initialize Debug LEDs */ diff --git a/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup.c b/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup.c index d8ec16d..2e99fc5 100644 --- a/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup.c +++ b/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup.c @@ -21,10 +21,12 @@ #include "common.h" #include "timer_5410x.h" #include "i2c_driver.h" +#include "Driver_GPIO.h" /*-------------------------------------------------------------------------------------------------*\ | E X T E R N A L V A R I A B L E S & F U N C T I O N S \*-------------------------------------------------------------------------------------------------*/ +extern ARM_DRIVER_GPIO Driver_GPIO; /*-------------------------------------------------------------------------------------------------*\ | P U B L I C V A R I A B L E S D E F I N I T I O N S @@ -40,47 +42,10 @@ const GpioInfo_t DiagLEDs[NUM_LEDS] = {PINS_LEDS}; | P R I V A T E T Y P E D E F I N I T I O N S \*-------------------------------------------------------------------------------------------------*/ -/*-------------------------------------------------------------------------------------------------*\ - | S T A T I C V A R I A B L E S D E F I N I T I O N S -\*-------------------------------------------------------------------------------------------------*/ -/* Pin muxing table, only items that need changing from their default pin - state are in this table. Not every pin is mapped. */ -//TODO Pin init should be moved to respective modules handling the pin function -STATIC const PINMUX_GRP_T pinmuxing[] = { - - /* I2C1 standard/fast (bridge) */ - {0, 27, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGITAL_EN | IOCON_STDI2C_EN)}, /* BRIDGE_SCL (SCL) */ - {0, 28, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGITAL_EN | IOCON_STDI2C_EN)}, /* BRIDGE_SDA (SDA) */ - - /* Sensor related */ - {0, 4, (IOCON_FUNC0 | IOCON_MODE_PULLDOWN | IOCON_DIGITAL_EN)}, /* GYR_INT1 (GPIO input) */ - {0, 18, (IOCON_FUNC0 | IOCON_MODE_INACT | IOCON_DIGITAL_EN)}, /* CT32B0_MAT0-ACCL_INT1 */ - {0, 22, (IOCON_FUNC0 | IOCON_MODE_PULLDOWN | IOCON_DIGITAL_EN)}, /* MAG_DRDY_INT (GPIO input) */ - -}; - /*-------------------------------------------------------------------------------------------------*\ | F O R W A R D F U N C T I O N D E C L A R A T I O N S \*-------------------------------------------------------------------------------------------------*/ -/*-------------------------------------------------------------------------------------------------*\ - | P R I V A T E F U N C T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/**************************************************************************************************** - * @fn GPIO_AINConfig - * Configures all IOs as AIN to reduce the power consumption. - * - * @param none - * - * @return none - * - ***************************************************************************************************/ -static void GPIO_AINConfig(void) -{ -} - - /*-------------------------------------------------------------------------------------------------*\ | P U B L I C F U N C T I O N S \*-------------------------------------------------------------------------------------------------*/ @@ -143,47 +108,12 @@ void LED_Init( void ) Chip_IOCON_PinMuxSet(LPC_IOCON, DiagLEDs[index].PinDef.port, DiagLEDs[index].PinDef.pin, DiagLEDs[index].PinDef.modefunc); - Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, DiagLEDs[index].PinDef.port, DiagLEDs[index].PinDef.pin); + Driver_GPIO.SetDirection (ENCODE_PORT_PIN(DiagLEDs[index].PinDef.port,DiagLEDs[index].PinDef.pin), ARM_GPIO_DIR_OUTPUT); LED_Off(index); } } - -/**************************************************************************************************** - * @fn SystemGPIOConfig - * Configures the various GPIO ports on the chip according to the usage by various - * peripherals. - * - * @param none - * - * @return none - * - ***************************************************************************************************/ -void SystemGPIOConfig( void ) -{ - /* Set all GPIOs to analog input mode to begin with */ - GPIO_AINConfig(); - - /* Enable the peripheral clock in the PMC */ - Chip_GPIO_Init(LPC_GPIO_PORT); - - /* Setup the Sensor Hub interrupt pin as output */ - //Chip_IOCON_Config(LPC_IOCON, SH_INT_PIN); - //Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, SH_INT_GPIO_GRP, SH_INT_GPIO_PIN); - //SensorHubIntLow(); //Deassert on startup - - /* TODO: Catch ALL for uninitialized pins... should be moved to respective modules */ - Chip_IOCON_SetPinMuxing(LPC_IOCON, pinmuxing, sizeof(pinmuxing) / sizeof(PINMUX_GRP_T)); - - /* Setup DMA Common here since its not specific to any peripheral */ - Chip_DMA_Init(LPC_DMA); - //Chip_SYSCON_PeriphReset(RESET_DMA); - Chip_DMA_Enable(LPC_DMA); - Chip_DMA_SetSRAMBase(LPC_DMA, DMA_ADDR(Chip_DMA_Table)); -} - - /**************************************************************************************************** * @fn SystemInterruptConfig * Configures the nested vectored interrupt controller. diff --git a/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup_xpresso_lpc54102.h b/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup_xpresso_lpc54102.h index f183077..97ed952 100644 --- a/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup_xpresso_lpc54102.h +++ b/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup_xpresso_lpc54102.h @@ -65,6 +65,12 @@ /* ########################################################################## */ /* Diagnostic GPIOs */ #define LPC_GPIO_PORT LPC_GPIO +#define NC (uint32_t)0xFFFFFFFF +typedef uint32_t PinName; + +#define ENCODE_PORT_PIN(port,pin) (PinName)(((uint32_t)port << 16) + (uint16_t)pin) +#define DECODE_PORT(X) (((uint32_t)(X) >> 16) & 0xF) +#define DECODE_PIN(X) ((uint32_t)(X) & 0xFFFF) /* Diagnostic LEDs on this board */ enum _Leds { //Sequence must correspond to PINS_LED definition diff --git a/external/CMSIS/Include/Driver_Common.h b/external/CMSIS/Include/Driver_Common.h new file mode 100644 index 0000000..396a11c --- /dev/null +++ b/external/CMSIS/Include/Driver_Common.h @@ -0,0 +1,72 @@ +/* ----------------------------------------------------------------------------- + * Copyright (c) 2013-2014 ARM Ltd. + * + * This software is provided 'as-is', without any express or implied warranty. + * In no event will the authors be held liable for any damages arising from + * the use of this software. Permission is granted to anyone to use this + * software for any purpose, including commercial applications, and to alter + * it and redistribute it freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software in + * a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any source distribution. + * + * + * $Date: 2. Jan 2014 + * $Revision: V2.00 + * + * Project: Common Driver definitions + * -------------------------------------------------------------------------- */ + +/* History: + * Version 2.00 + * Changed prefix ARM_DRV -> ARM_DRIVER + * Added General return codes definitions + * Version 1.10 + * Namespace prefix ARM_ added + * Version 1.00 + * Initial release + */ + +#ifndef __DRIVER_COMMON_H +#define __DRIVER_COMMON_H + +#include +#include +#include + +#define ARM_DRIVER_VERSION_MAJOR_MINOR(major,minor) (((major) << 8) | (minor)) + +/** +\brief Driver Version +*/ +typedef struct _ARM_DRIVER_VERSION { + uint16_t api; ///< API version + uint16_t drv; ///< Driver version +} ARM_DRIVER_VERSION; + +/* General return codes */ +#define ARM_DRIVER_OK 0 ///< Operation succeeded +#define ARM_DRIVER_ERROR -1 ///< Unspecified error +#define ARM_DRIVER_ERROR_BUSY -2 ///< Driver is busy +#define ARM_DRIVER_ERROR_TIMEOUT -3 ///< Timeout occurred +#define ARM_DRIVER_ERROR_UNSUPPORTED -4 ///< Operation not supported +#define ARM_DRIVER_ERROR_PARAMETER -5 ///< Parameter error +#define ARM_DRIVER_ERROR_SPECIFIC -6 ///< Start of driver specific errors + +/** +\brief General power states +*/ +typedef enum _ARM_POWER_STATE { + ARM_POWER_OFF, ///< Power off: no operation possible + ARM_POWER_LOW, ///< Low Power mode: retain state, detect and signal wake-up events + ARM_POWER_FULL ///< Power on: full operation at maximum performance +} ARM_POWER_STATE; + +#endif /* __DRIVER_COMMON_H */ diff --git a/external/CMSIS/Include/Driver_GPIO.h b/external/CMSIS/Include/Driver_GPIO.h new file mode 100644 index 0000000..2917b6e --- /dev/null +++ b/external/CMSIS/Include/Driver_GPIO.h @@ -0,0 +1,103 @@ +/* ----------------------------------------------------------------------------- + * Copyright (c) 2015 Pinecone Ltd. + * + * This software is provided 'as-is', without any express or implied warranty. + * In no event will the authors be held liable for any damages arising from + * the use of this software. Permission is granted to anyone to use this + * software for any purpose, including commercial applications, and to alter + * it and redistribute it freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software in + * a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any source distribution. + * + * + * $Date: 8. June 2015 + * $Revision: V1.00 + * + * Project: GPIO Driver definitions + * -------------------------------------------------------------------------- */ + +/* History: + * Version 1.00 + * Initial release + */ + +#ifndef __DRIVER_GPIO_H +#define __DRIVER_GPIO_H + +#include "Driver_Common.h" + +#define OSP_GPIO_API_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(1,00) + +#define ARM_GPIO_DIR_INPUT 0 +#define ARM_GPIO_DIR_OUTPUT 1 + +#define ARM_GPIO_TRIGGER_NONE 0 +#define ARM_GPIO_TRIGGER_HIGH 1 +#define ARM_GPIO_TRIGGER_LOW 2 +#define ARM_GPIO_TRIGGER_RISING 3 +#define ARM_GPIO_TRIGGER_FALLING 4 +#define ARM_GPIO_TRIGGER_EDGE 5 + +typedef void (*ARM_GPIO_Handler_t) (uint32_t pin, void *data); + +typedef struct _ARM_DRIVER_GPIO { + ARM_DRIVER_VERSION (*GetVersion) (void); + int32_t (*Initialize) (void); + int32_t (*Uninitialize) (void); + int32_t (*PowerControl) (ARM_POWER_STATE state); + int32_t (*SetDirection) (uint32_t pin, uint32_t dir); + int32_t (*SetTrigger) (uint32_t pin, uint32_t trigger); + int32_t (*WritePin) (uint32_t pin, uint32_t value); + int32_t (*ReadPin) (uint32_t pin); + int32_t (*SetHandler) (uint32_t pin, ARM_GPIO_Handler_t handler, void *data); +} const ARM_DRIVER_GPIO; + +#define ARM_BUILD_DRIVER_GPIO(pre1, pre2, priv) \ + static ARM_DRIVER_VERSION pre1##_GetVersion (void) { \ + return pre2##_GetVersion (priv); \ + } \ + static int32_t pre1##_Initialize (void) { \ + return pre2##_Initialize (priv); \ + } \ + static int32_t pre1##_Uninitialize (void) { \ + return pre2##_Uninitialize (priv); \ + } \ + static int32_t pre1##_PowerControl (ARM_POWER_STATE state) { \ + return pre2##_PowerControl (state, priv); \ + } \ + static int32_t pre1##_SetDirection (uint32_t pin, uint32_t dir) { \ + return pre2##_SetDirection (pin, dir, priv); \ + } \ + static int32_t pre1##_SetTrigger (uint32_t pin, uint32_t trigger) { \ + return pre2##_SetTrigger (pin, trigger, priv); \ + } \ + static int32_t pre1##_WritePin (uint32_t pin, uint32_t value) { \ + return pre2##_WritePin (pin, value, priv); \ + } \ + static int32_t pre1##_ReadPin (uint32_t pin) { \ + return pre2##_ReadPin (pin, priv); \ + } \ + static int32_t pre1##_SetHandler (uint32_t pin, ARM_GPIO_Handler_t handler, void *data) { \ + return pre2##_SetHandler (pin, handler, data, priv); \ + } \ + ARM_DRIVER_GPIO Driver_##pre1 = { \ + pre1##_GetVersion, \ + pre1##_Initialize, \ + pre1##_Uninitialize, \ + pre1##_PowerControl, \ + pre1##_SetDirection, \ + pre1##_SetTrigger, \ + pre1##_WritePin, \ + pre1##_ReadPin, \ + pre1##_SetHandler, \ + }; + +#endif /* __DRIVER_GPIO_H */ diff --git a/external/CMSIS/NXP/LPC5410x/Driver_GPIO.c b/external/CMSIS/NXP/LPC5410x/Driver_GPIO.c new file mode 100644 index 0000000..503ac1e --- /dev/null +++ b/external/CMSIS/NXP/LPC5410x/Driver_GPIO.c @@ -0,0 +1,286 @@ +/* Open Sensor Platform Project + * https://github.com/sensorplatforms/open-sensor-platform + * + * Copyright (C) 2015 Audience Inc. + * + * 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 "common.h" +#include "Driver_GPIO.h" +#include "chip.h" + +#define OSP_GPIO_DRV_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(1,00) + +/*-------------------------------------------------------------------------------------------------*\ + | S T A T I C V A R I A B L E S D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/* Pin muxing table, only items that need changing from their default pin + state are in this table. Not every pin is mapped. */ +STATIC const PINMUX_GRP_T pinmuxing[] = { + + /* I2C1 standard/fast (bridge) */ + {0, 27, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGITAL_EN | IOCON_STDI2C_EN)}, /* BRIDGE_SCL (SCL) */ + {0, 28, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGITAL_EN | IOCON_STDI2C_EN)}, /* BRIDGE_SDA (SDA) */ + + /* Sensor related */ + {0, 4, (IOCON_FUNC0 | IOCON_MODE_PULLDOWN | IOCON_DIGITAL_EN)}, /* GYR_INT1 (GPIO input) */ + {0, 18, (IOCON_FUNC0 | IOCON_MODE_INACT | IOCON_DIGITAL_EN)}, /* CT32B0_MAT0-ACCL_INT1 */ + {0, 22, (IOCON_FUNC0 | IOCON_MODE_PULLDOWN | IOCON_DIGITAL_EN)}, /* MAG_DRDY_INT (GPIO input) */ + +}; + +/* Private structure for GPIO */ +typedef struct _GPIO_T { + LPC_GPIO_T *base; /* GPIO Base address */ + uint16_t port; /* Port number */ + uint16_t pin; /* Pin number */ + uint8_t id; /* Pin Interrupt Select Value */ +} GPIO_T; + +/* Private argument */ +static GPIO_T gpio_ID = { LPC_GPIO, 0, 0, 0 }; + +/*-------------------------------------------------------------------------------------------------*\ + | P R I V A T E F U N C T I O N S +\*-------------------------------------------------------------------------------------------------*/ + +/* Driver Version */ +static const ARM_DRIVER_VERSION DriverVersion = { + OSP_GPIO_API_VERSION, + OSP_GPIO_DRV_VERSION +}; + +/**************************************************************************************************** + * @fn GPIOx_GetVersion + * Get driver version. + * + * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers + * + * @return ARM_DRIVER_VERSION + * + ***************************************************************************************************/ +static ARM_DRIVER_VERSION GPIOx_GetVersion (GPIO_T *gpio_priv) +{ + return DriverVersion; +} + +/**************************************************************************************************** + * @fn GPIOx_AINConfig + * Configures all IOs as AIN to reduce the power consumption. + * + * @param none + * + * @return none + * + ***************************************************************************************************/ +static void GPIOx_AINConfig(void) +{ + return; +} + +/**************************************************************************************************** + * @fn GPIOx_Initialize + * Initializes the GPIO Module and Hardware + * + * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t GPIOx_Initialize(GPIO_T *gpio_priv) +{ + /* Set all GPIOs to analog input mode to begin with */ + GPIOx_AINConfig(); + + /* Enable the peripheral clock in the PMC */ + Chip_GPIO_Init(gpio_priv->base); + + /* TODO: Catch ALL for uninitialized pins... should be moved to respective modules */ + Chip_IOCON_SetPinMuxing(LPC_IOCON, pinmuxing, sizeof(pinmuxing) / sizeof(PINMUX_GRP_T)); + + /* Setup DMA Common here since its not specific to any peripheral */ + Chip_DMA_Init(LPC_DMA); + Chip_DMA_Enable(LPC_DMA); + Chip_DMA_SetSRAMBase(LPC_DMA, DMA_ADDR(Chip_DMA_Table)); + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn GPIOx_Uninitialize + * Unitialize the GPIO Module + * + * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t GPIOx_Uninitialize (GPIO_T *gpio_priv) +{ + + /* Uninitialize GPIO */ + Chip_GPIO_DeInit(gpio_priv->base); + + Chip_PININT_DeInit(LPC_PININT); + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn GPIOx_PowerControl + * Control the GPIO's power state + * + * @param state Target GPIO Power state + * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t GPIOx_PowerControl(ARM_POWER_STATE state, GPIO_T *gpio_priv) +{ + switch (state) + { + case ARM_POWER_OFF: + Chip_PININT_ClearIntStatus(LPC_PININT, gpio_priv->pin); + break; + + case ARM_POWER_FULL: + Chip_INMUX_PinIntSel(gpio_priv->id, gpio_priv->port, gpio_priv->pin); + break; + + default: + return ARM_DRIVER_ERROR_UNSUPPORTED; + } + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn GPIOx_SetDirection + * Set the direction of GPIO pin + * + * @param pin Port pin number + * @param dir Direction (GPIO_DIR_INPUT or GPIO_DIR_OUTPUT) + * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t GPIOx_SetDirection (uint32_t pin, uint32_t dir, GPIO_T *gpio_priv) +{ + uint32_t port_num = 0, pin_num = 0; + + ASF_assert(pin != (PinName)NC); + ASF_assert ((dir == ARM_GPIO_DIR_INPUT) || (dir == ARM_GPIO_DIR_OUTPUT)); + port_num = DECODE_PORT(pin); + pin_num = DECODE_PIN(pin); + + dir ? (gpio_priv->base->DIR[port_num] |= (1UL << pin_num)) : \ + (gpio_priv->base->DIR[port_num] &= ~(1UL << pin_num)); + + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn GPIOx_SetTrigger + * Set the trigger mode for GPIO + * + * @param pin Pin Interrupt Channel + * @param trigger Trigger mode + * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t GPIOx_SetTrigger (uint32_t pin, uint32_t trigger, GPIO_T *gpio_priv) +{ + if (trigger & (1 << ARM_GPIO_TRIGGER_EDGE)) + { + Chip_PININT_SetPinModeEdge(LPC_PININT, pin); /* edge sensitive */ + } + else + { + Chip_PININT_SetPinModeLevel(LPC_PININT, pin); /* Level sensitive */ + } + if ((trigger & (1 << ARM_GPIO_TRIGGER_HIGH)) || (trigger & (1 << ARM_GPIO_TRIGGER_RISING))) + { + Chip_PININT_EnableIntHigh(LPC_PININT, pin); /* Rising Edge/High Level */ + } + else + { + Chip_PININT_EnableIntLow(LPC_PININT, pin); /* Falling Edge/Low Level */ + } + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn GPIOx_WritePin + * Set the GPIO Pin state + * + * @param pin Port pin number + * @param val Value to be written (0 or 1) + * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t GPIOx_WritePin (uint32_t pin, uint32_t val, GPIO_T *gpio_priv) +{ + uint32_t port_num = 0, pin_num = 0; + + ASF_assert(pin != (PinName)NC); + port_num = DECODE_PORT(pin); + pin_num = DECODE_PIN(pin); + + gpio_priv->base->B[port_num][pin_num] = val; + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn GPIOx_ReadPin + * Get the GPIO Pin value + * + * @param pin Port pin number + * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers + * + * @return pin value + * + ***************************************************************************************************/ +static int32_t GPIOx_ReadPin (uint32_t pin, GPIO_T *gpio_priv) +{ + uint32_t port_num = 0, pin_num = 0; + + ASF_assert(pin != (PinName)NC); + port_num = DECODE_PORT(pin); + pin_num = DECODE_PIN(pin); + return ((gpio_priv->base->PIN[port_num] & (1UL << pin_num)) ? (1) : (0)); +} + +/**************************************************************************************************** + * @fn GPIOx_SetHandler + * Handler function + * + * @param pin Port pin number + * @param handler Pointer to handler function + * @param data Data to pass to the handler + * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t GPIOx_SetHandler (uint32_t pin, ARM_GPIO_Handler_t handler, void *data, GPIO_T *gpio_priv) +{ + return ARM_DRIVER_OK; //Do nothing +} + +/* Driver Definition */ +ARM_BUILD_DRIVER_GPIO(GPIO, GPIOx, &gpio_ID); From a57e4a7309491bc681a4a63a2ad2c9b9dc82270b Mon Sep 17 00:00:00 2001 From: Pankaj Goenka Date: Sat, 12 Dec 2015 01:06:33 +0530 Subject: [PATCH 2/4] Moved DMA initialization outside GPIO Init function Moved pinmux initialization to respective module function Moved GPIO macros and types under correct heading in the code Closed all review comments from pull request #6 Signed-off-by: Pankaj Goenka --- .../CMSIS/Device}/NXP/LPC5410x/Driver_GPIO.c | 553 +++++++++--------- .../keil-mdk-build/SH-Xpresso-LPC54102.uvoptx | 3 +- .../SH-Xpresso-LPC54102.uvprojx | 10 +- .../sources/app/hostif_i2c.c | 6 +- .../SH-Xpresso-LPC54102/sources/app/main.c | 4 +- .../sources/boardsupport/hw_setup.c | 41 ++ .../boardsupport/hw_setup_xpresso_lpc54102.h | 27 +- .../{ => Driver}/Include/Driver_Common.h | 144 ++--- .../CMSIS/{ => Driver}/Include/Driver_GPIO.h | 206 +++---- 9 files changed, 515 insertions(+), 479 deletions(-) rename {external/CMSIS => embedded/Drivers/CMSIS/Device}/NXP/LPC5410x/Driver_GPIO.c (64%) rename external/CMSIS/{ => Driver}/Include/Driver_Common.h (97%) rename external/CMSIS/{ => Driver}/Include/Driver_GPIO.h (97%) diff --git a/external/CMSIS/NXP/LPC5410x/Driver_GPIO.c b/embedded/Drivers/CMSIS/Device/NXP/LPC5410x/Driver_GPIO.c similarity index 64% rename from external/CMSIS/NXP/LPC5410x/Driver_GPIO.c rename to embedded/Drivers/CMSIS/Device/NXP/LPC5410x/Driver_GPIO.c index 503ac1e..c293b65 100644 --- a/external/CMSIS/NXP/LPC5410x/Driver_GPIO.c +++ b/embedded/Drivers/CMSIS/Device/NXP/LPC5410x/Driver_GPIO.c @@ -1,286 +1,273 @@ -/* Open Sensor Platform Project - * https://github.com/sensorplatforms/open-sensor-platform - * - * Copyright (C) 2015 Audience Inc. - * - * 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. - */ - +/* Open Sensor Platform Project + * https://github.com/sensorplatforms/open-sensor-platform + * + * Copyright (C) 2015 Audience Inc. + * + * 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. + */ +/*-------------------------------------------------------------------------------------------------*\ + | I N C L U D E F I L E S +\*-------------------------------------------------------------------------------------------------*/ #include "common.h" -#include "Driver_GPIO.h" -#include "chip.h" - -#define OSP_GPIO_DRV_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(1,00) - -/*-------------------------------------------------------------------------------------------------*\ - | S T A T I C V A R I A B L E S D E F I N I T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/* Pin muxing table, only items that need changing from their default pin - state are in this table. Not every pin is mapped. */ -STATIC const PINMUX_GRP_T pinmuxing[] = { - - /* I2C1 standard/fast (bridge) */ - {0, 27, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGITAL_EN | IOCON_STDI2C_EN)}, /* BRIDGE_SCL (SCL) */ - {0, 28, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGITAL_EN | IOCON_STDI2C_EN)}, /* BRIDGE_SDA (SDA) */ - - /* Sensor related */ - {0, 4, (IOCON_FUNC0 | IOCON_MODE_PULLDOWN | IOCON_DIGITAL_EN)}, /* GYR_INT1 (GPIO input) */ - {0, 18, (IOCON_FUNC0 | IOCON_MODE_INACT | IOCON_DIGITAL_EN)}, /* CT32B0_MAT0-ACCL_INT1 */ - {0, 22, (IOCON_FUNC0 | IOCON_MODE_PULLDOWN | IOCON_DIGITAL_EN)}, /* MAG_DRDY_INT (GPIO input) */ - -}; - -/* Private structure for GPIO */ -typedef struct _GPIO_T { - LPC_GPIO_T *base; /* GPIO Base address */ - uint16_t port; /* Port number */ - uint16_t pin; /* Pin number */ - uint8_t id; /* Pin Interrupt Select Value */ -} GPIO_T; - -/* Private argument */ -static GPIO_T gpio_ID = { LPC_GPIO, 0, 0, 0 }; - -/*-------------------------------------------------------------------------------------------------*\ - | P R I V A T E F U N C T I O N S -\*-------------------------------------------------------------------------------------------------*/ - -/* Driver Version */ -static const ARM_DRIVER_VERSION DriverVersion = { - OSP_GPIO_API_VERSION, - OSP_GPIO_DRV_VERSION -}; - -/**************************************************************************************************** - * @fn GPIOx_GetVersion - * Get driver version. - * - * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers - * - * @return ARM_DRIVER_VERSION - * - ***************************************************************************************************/ -static ARM_DRIVER_VERSION GPIOx_GetVersion (GPIO_T *gpio_priv) -{ - return DriverVersion; -} - -/**************************************************************************************************** - * @fn GPIOx_AINConfig - * Configures all IOs as AIN to reduce the power consumption. - * - * @param none - * - * @return none - * - ***************************************************************************************************/ -static void GPIOx_AINConfig(void) -{ - return; -} - -/**************************************************************************************************** - * @fn GPIOx_Initialize - * Initializes the GPIO Module and Hardware - * - * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers - * - * @return Return code: On success return ARM_DRIVER_OK - * - ***************************************************************************************************/ -static int32_t GPIOx_Initialize(GPIO_T *gpio_priv) -{ - /* Set all GPIOs to analog input mode to begin with */ - GPIOx_AINConfig(); - - /* Enable the peripheral clock in the PMC */ - Chip_GPIO_Init(gpio_priv->base); - - /* TODO: Catch ALL for uninitialized pins... should be moved to respective modules */ - Chip_IOCON_SetPinMuxing(LPC_IOCON, pinmuxing, sizeof(pinmuxing) / sizeof(PINMUX_GRP_T)); - - /* Setup DMA Common here since its not specific to any peripheral */ - Chip_DMA_Init(LPC_DMA); - Chip_DMA_Enable(LPC_DMA); - Chip_DMA_SetSRAMBase(LPC_DMA, DMA_ADDR(Chip_DMA_Table)); +#include "Driver_GPIO.h" +#include "chip.h" + +/*-------------------------------------------------------------------------------------------------*\ + | P R I V A T E C O N S T A N T S & M A C R O S +\*-------------------------------------------------------------------------------------------------*/ +#define OSP_GPIO_DRV_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR( 1,00 ) + +/*-------------------------------------------------------------------------------------------------*\ + | T Y P E D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ +/* Private structure for GPIO */ +typedef struct _GPIO_T +{ + LPC_GPIO_T *base; /* GPIO Base address */ + uint16_t port; /* Port number */ + uint16_t pin; /* Pin number */ + uint8_t id; /* Pin Interrupt Select Value */ +} GPIO_T; + +/*-------------------------------------------------------------------------------------------------*\ + | S T A T I C V A R I A B L E S D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ +/* Private argument */ +static GPIO_T gpio_ID = { LPC_GPIO, 0, 0, 0 }; + +/* Driver Version */ +static const ARM_DRIVER_VERSION DriverVersion = { + OSP_GPIO_API_VERSION, + OSP_GPIO_DRV_VERSION +}; + +/*-------------------------------------------------------------------------------------------------*\ + | P R I V A T E F U N C T I O N S +\*-------------------------------------------------------------------------------------------------*/ +/**************************************************************************************************** + * @fn OSP_GPIO_GetVersion + * Get driver version. + * + * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers + * + * @return ARM_DRIVER_VERSION + * + ***************************************************************************************************/ +static ARM_DRIVER_VERSION OSP_GPIO_GetVersion( GPIO_T *gpio_priv ) +{ + return DriverVersion; +} + +/**************************************************************************************************** + * @fn OSP_GPIO_AINConfig + * Configures all IOs as AIN to reduce the power consumption. + * + * @param none + * + * @return none + * + ***************************************************************************************************/ +static void OSP_GPIO_AINConfig( void ) +{ + return; +} + +/**************************************************************************************************** + * @fn OSP_GPIO_Initialize + * Initializes the GPIO Module and Hardware + * + * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t OSP_GPIO_Initialize( GPIO_T *gpio_priv ) +{ + /* Set all GPIOs to analog input mode to begin with */ + OSP_GPIO_AINConfig(); + + /* Enable the peripheral clock in the PMC */ + Chip_GPIO_Init( gpio_priv->base ); return ARM_DRIVER_OK; -} - -/**************************************************************************************************** - * @fn GPIOx_Uninitialize - * Unitialize the GPIO Module - * - * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers - * - * @return Return code: On success return ARM_DRIVER_OK - * - ***************************************************************************************************/ -static int32_t GPIOx_Uninitialize (GPIO_T *gpio_priv) -{ - - /* Uninitialize GPIO */ - Chip_GPIO_DeInit(gpio_priv->base); - - Chip_PININT_DeInit(LPC_PININT); +} + +/**************************************************************************************************** + * @fn OSP_GPIO_Uninitialize + * Unitialize the GPIO Module + * + * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t OSP_GPIO_Uninitialize( GPIO_T *gpio_priv ) +{ + /* Uninitialize GPIO */ + Chip_GPIO_DeInit( gpio_priv->base ); + + Chip_PININT_DeInit( LPC_PININT ); return ARM_DRIVER_OK; -} - -/**************************************************************************************************** - * @fn GPIOx_PowerControl - * Control the GPIO's power state - * - * @param state Target GPIO Power state - * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers - * - * @return Return code: On success return ARM_DRIVER_OK - * - ***************************************************************************************************/ -static int32_t GPIOx_PowerControl(ARM_POWER_STATE state, GPIO_T *gpio_priv) -{ - switch (state) - { - case ARM_POWER_OFF: - Chip_PININT_ClearIntStatus(LPC_PININT, gpio_priv->pin); - break; - - case ARM_POWER_FULL: - Chip_INMUX_PinIntSel(gpio_priv->id, gpio_priv->port, gpio_priv->pin); - break; - - default: - return ARM_DRIVER_ERROR_UNSUPPORTED; - } - return ARM_DRIVER_OK; -} - -/**************************************************************************************************** - * @fn GPIOx_SetDirection - * Set the direction of GPIO pin - * - * @param pin Port pin number - * @param dir Direction (GPIO_DIR_INPUT or GPIO_DIR_OUTPUT) - * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers - * - * @return Return code: On success return ARM_DRIVER_OK - * - ***************************************************************************************************/ -static int32_t GPIOx_SetDirection (uint32_t pin, uint32_t dir, GPIO_T *gpio_priv) -{ - uint32_t port_num = 0, pin_num = 0; - - ASF_assert(pin != (PinName)NC); - ASF_assert ((dir == ARM_GPIO_DIR_INPUT) || (dir == ARM_GPIO_DIR_OUTPUT)); - port_num = DECODE_PORT(pin); - pin_num = DECODE_PIN(pin); - - dir ? (gpio_priv->base->DIR[port_num] |= (1UL << pin_num)) : \ - (gpio_priv->base->DIR[port_num] &= ~(1UL << pin_num)); - - return ARM_DRIVER_OK; -} - -/**************************************************************************************************** - * @fn GPIOx_SetTrigger - * Set the trigger mode for GPIO - * - * @param pin Pin Interrupt Channel - * @param trigger Trigger mode - * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers - * - * @return Return code: On success return ARM_DRIVER_OK - * - ***************************************************************************************************/ -static int32_t GPIOx_SetTrigger (uint32_t pin, uint32_t trigger, GPIO_T *gpio_priv) -{ - if (trigger & (1 << ARM_GPIO_TRIGGER_EDGE)) - { - Chip_PININT_SetPinModeEdge(LPC_PININT, pin); /* edge sensitive */ - } - else - { - Chip_PININT_SetPinModeLevel(LPC_PININT, pin); /* Level sensitive */ - } - if ((trigger & (1 << ARM_GPIO_TRIGGER_HIGH)) || (trigger & (1 << ARM_GPIO_TRIGGER_RISING))) - { - Chip_PININT_EnableIntHigh(LPC_PININT, pin); /* Rising Edge/High Level */ - } - else - { - Chip_PININT_EnableIntLow(LPC_PININT, pin); /* Falling Edge/Low Level */ - } - return ARM_DRIVER_OK; -} - -/**************************************************************************************************** - * @fn GPIOx_WritePin - * Set the GPIO Pin state - * - * @param pin Port pin number - * @param val Value to be written (0 or 1) - * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers - * - * @return Return code: On success return ARM_DRIVER_OK - * - ***************************************************************************************************/ -static int32_t GPIOx_WritePin (uint32_t pin, uint32_t val, GPIO_T *gpio_priv) -{ - uint32_t port_num = 0, pin_num = 0; - - ASF_assert(pin != (PinName)NC); - port_num = DECODE_PORT(pin); - pin_num = DECODE_PIN(pin); - - gpio_priv->base->B[port_num][pin_num] = val; - return ARM_DRIVER_OK; -} - -/**************************************************************************************************** - * @fn GPIOx_ReadPin - * Get the GPIO Pin value - * - * @param pin Port pin number - * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers - * - * @return pin value - * - ***************************************************************************************************/ -static int32_t GPIOx_ReadPin (uint32_t pin, GPIO_T *gpio_priv) -{ - uint32_t port_num = 0, pin_num = 0; - - ASF_assert(pin != (PinName)NC); - port_num = DECODE_PORT(pin); - pin_num = DECODE_PIN(pin); - return ((gpio_priv->base->PIN[port_num] & (1UL << pin_num)) ? (1) : (0)); -} - -/**************************************************************************************************** - * @fn GPIOx_SetHandler - * Handler function - * - * @param pin Port pin number - * @param handler Pointer to handler function - * @param data Data to pass to the handler - * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers - * - * @return Return code: On success return ARM_DRIVER_OK - * - ***************************************************************************************************/ -static int32_t GPIOx_SetHandler (uint32_t pin, ARM_GPIO_Handler_t handler, void *data, GPIO_T *gpio_priv) -{ - return ARM_DRIVER_OK; //Do nothing -} - -/* Driver Definition */ -ARM_BUILD_DRIVER_GPIO(GPIO, GPIOx, &gpio_ID); +} + +/**************************************************************************************************** + * @fn OSP_GPIO_PowerControl + * Control the GPIO's power state + * + * @param state Target GPIO Power state + * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t OSP_GPIO_PowerControl( ARM_POWER_STATE state, GPIO_T *gpio_priv ) +{ + switch ( state ) + { + case ARM_POWER_OFF: + Chip_PININT_ClearIntStatus( LPC_PININT, gpio_priv->pin ); + break; + + case ARM_POWER_FULL: + Chip_INMUX_PinIntSel( gpio_priv->id, gpio_priv->port, gpio_priv->pin ); + break; + + default: + return ARM_DRIVER_ERROR_UNSUPPORTED; + } + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn OSP_GPIO_SetDirection + * Set the direction of GPIO pin + * + * @param pin Port pin number + * @param dir Direction (GPIO_DIR_INPUT or GPIO_DIR_OUTPUT) + * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t OSP_GPIO_SetDirection( uint32_t pin, uint32_t dir, GPIO_T *gpio_priv ) +{ + uint32_t port_num = 0, pin_num = 0; + + ASF_assert( pin != (PinName)NC ); + ASF_assert( (dir == ARM_GPIO_DIR_INPUT) || (dir == ARM_GPIO_DIR_OUTPUT) ); + port_num = DECODE_PORT( pin ); + pin_num = DECODE_PIN( pin ); + + dir ? ( gpio_priv->base->DIR[port_num] |= ( 1UL << pin_num) ) : \ + ( gpio_priv->base->DIR[port_num] &= ~( 1UL << pin_num) ); + + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn OSP_GPIO_SetTrigger + * Set the trigger mode for GPIO + * + * @param pin Pin Interrupt Channel + * @param trigger Trigger mode + * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t OSP_GPIO_SetTrigger( uint32_t pin, uint32_t trigger, GPIO_T *gpio_priv ) +{ + if ( trigger & (1 << ARM_GPIO_TRIGGER_EDGE) ) + { + Chip_PININT_SetPinModeEdge( LPC_PININT, pin ); /* edge sensitive */ + } + else + { + Chip_PININT_SetPinModeLevel( LPC_PININT, pin ); /* Level sensitive */ + } + if ( (trigger & (1 << ARM_GPIO_TRIGGER_HIGH)) || (trigger & (1 << ARM_GPIO_TRIGGER_RISING)) ) + { + Chip_PININT_EnableIntHigh( LPC_PININT, pin ); /* Rising Edge/High Level */ + } + else + { + Chip_PININT_EnableIntLow( LPC_PININT, pin ); /* Falling Edge/Low Level */ + } + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn OSP_GPIO_WritePin + * Set the GPIO Pin state + * + * @param pin Port pin number + * @param val Value to be written (0 or 1) + * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t OSP_GPIO_WritePin( uint32_t pin, uint32_t val, GPIO_T *gpio_priv ) +{ + uint32_t port_num = 0, pin_num = 0; + + ASF_assert( pin != (PinName)NC ); + port_num = DECODE_PORT( pin ); + pin_num = DECODE_PIN( pin ); + + gpio_priv->base->B[port_num][pin_num] = val; + return ARM_DRIVER_OK; +} + +/**************************************************************************************************** + * @fn OSP_GPIO_ReadPin + * Get the GPIO Pin value + * + * @param pin Port pin number + * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers + * + * @return pin value + * + ***************************************************************************************************/ +static int32_t OSP_GPIO_ReadPin( uint32_t pin, GPIO_T *gpio_priv ) +{ + uint32_t port_num = 0, pin_num = 0; + + ASF_assert( pin != (PinName)NC ); + port_num = DECODE_PORT( pin ); + pin_num = DECODE_PIN( pin ); + return ( (gpio_priv->base->PIN[port_num] & (1UL << pin_num)) ? (1) : (0) ); +} + +/**************************************************************************************************** + * @fn OSP_GPIO_SetHandler + * Handler function + * + * @param pin Port pin number + * @param handler Pointer to handler function + * @param data Data to pass to the handler + * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers + * + * @return Return code: On success return ARM_DRIVER_OK + * + ***************************************************************************************************/ +static int32_t OSP_GPIO_SetHandler( uint32_t pin, ARM_GPIO_Handler_t handler, void *data, GPIO_T *gpio_priv ) +{ + return ARM_DRIVER_OK; //Do nothing +} + +/* Driver Definition */ +ARM_BUILD_DRIVER_GPIO( GPIO, OSP_GPIO, &gpio_ID ); + +/*-------------------------------------------------------------------------------------------------*\ + | E N D O F F I L E +\*-------------------------------------------------------------------------------------------------*/ diff --git a/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvoptx b/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvoptx index d2c5a5f..058a55c 100644 --- a/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvoptx +++ b/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvoptx @@ -1376,10 +1376,9 @@ 39 1 0 - 0 0 0 - ..\..\..\..\external\CMSIS\NXP\LPC5410x\Driver_GPIO.c + ..\..\..\..\embedded\Drivers\CMSIS\Device\NXP\LPC5410x\Driver_GPIO.c Driver_GPIO.c 0 0 diff --git a/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvprojx b/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvprojx index 006e42d..bc9627e 100644 --- a/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvprojx +++ b/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvprojx @@ -796,7 +796,7 @@ Driver_GPIO.c 1 - ..\..\..\..\external\CMSIS\NXP\LPC5410x\Driver_GPIO.c + ..\..\..\..\embedded\Drivers\CMSIS\Device\NXP\LPC5410x\Driver_GPIO.c @@ -1595,7 +1595,7 @@ Driver_GPIO.c 1 - ..\..\..\..\external\CMSIS\NXP\LPC5410x\Driver_GPIO.c + ..\..\..\..\embedded\Drivers\CMSIS\Device\NXP\LPC5410x\Driver_GPIO.c @@ -2394,7 +2394,7 @@ Driver_GPIO.c 1 - ..\..\..\..\external\CMSIS\NXP\LPC5410x\Driver_GPIO.c + ..\..\..\..\embedded\Drivers\CMSIS\Device\NXP\LPC5410x\Driver_GPIO.c @@ -2770,7 +2770,7 @@ SYSTEM_CLOCK_FREQ=96000000, __FPU_PRESENT=1, CHIP_LPC5410X, CORE_M4, DEBUG_BUILD, XPRESSO_LPC54102_BOARD, UART_DMA_ENABLE, ANDROID_DEMO, ASF_PROFILING, ON_DEMAND_PROFILING - ..\sources\app;..\sources\config;..\sources\boardsupport;..\..\..\..\include;..\..\..\common\app;..\..\..\common\asf;..\..\..\common\alg;..\..\..\..\external\rtos\rtx\inc;..\..\..\..\external\rtos\rtx\cm;..\..\..\..\external\MCU\NXP-5410x\CSLib\inc;..\..\..\common\modules\bus-drivers;..\..\..\common\modules\sensor-drivers;..\..\..\..\external\Drivers\Sensor\Bosch-Sensortec;..\..\..\common\hostinterface;..\..\..\..\external\CMSIS\Include + ..\sources\app;..\sources\config;..\sources\boardsupport;..\..\..\..\include;..\..\..\common\app;..\..\..\common\asf;..\..\..\common\alg;..\..\..\..\external\rtos\rtx\inc;..\..\..\..\external\rtos\rtx\cm;..\..\..\..\external\MCU\NXP-5410x\CSLib\inc;..\..\..\common\modules\bus-drivers;..\..\..\common\modules\sensor-drivers;..\..\..\..\external\Drivers\Sensor\Bosch-Sensortec;..\..\..\common\hostinterface;..\..\..\..\external\CMSIS\Driver\Include @@ -3193,7 +3193,7 @@ Driver_GPIO.c 1 - ..\..\..\..\external\CMSIS\NXP\LPC5410x\Driver_GPIO.c + ..\..\..\..\embedded\Drivers\CMSIS\Device\NXP\LPC5410x\Driver_GPIO.c diff --git a/embedded/projects/SH-Xpresso-LPC54102/sources/app/hostif_i2c.c b/embedded/projects/SH-Xpresso-LPC54102/sources/app/hostif_i2c.c index 21ee3e4..c56cc98 100644 --- a/embedded/projects/SH-Xpresso-LPC54102/sources/app/hostif_i2c.c +++ b/embedded/projects/SH-Xpresso-LPC54102/sources/app/hostif_i2c.c @@ -29,6 +29,7 @@ /*-------------------------------------------------------------------------------------------------*\ | E X T E R N A L V A R I A B L E S & F U N C T I O N S \*-------------------------------------------------------------------------------------------------*/ +extern ARM_DRIVER_GPIO Driver_GPIO; /*-------------------------------------------------------------------------------------------------*\ | P R I V A T E C O N S T A N T S & M A C R O S @@ -64,11 +65,6 @@ typedef struct _HostGCResponse uint8_t szLSB; //data size LSB } HostGCResponse_t; -/*-------------------------------------------------------------------------------------------------*\ - | E X T E R N A L V A R I A B L E S & F U N C T I O N S -\*-------------------------------------------------------------------------------------------------*/ -extern ARM_DRIVER_GPIO Driver_GPIO; - typedef struct __HOSTIF_Ctrl_t { uint16_t rxCount; /* Bytes so far received */ uint16_t txCountSet; diff --git a/embedded/projects/SH-Xpresso-LPC54102/sources/app/main.c b/embedded/projects/SH-Xpresso-LPC54102/sources/app/main.c index 9cc4ec9..134144f 100644 --- a/embedded/projects/SH-Xpresso-LPC54102/sources/app/main.c +++ b/embedded/projects/SH-Xpresso-LPC54102/sources/app/main.c @@ -20,7 +20,6 @@ \*-------------------------------------------------------------------------------------------------*/ #include "common.h" #include "hw_setup.h" -#include "Driver_GPIO.h" /*-------------------------------------------------------------------------------------------------*\ | E X T E R N A L V A R I A B L E S & F U N C T I O N S @@ -30,7 +29,6 @@ extern uint32_t gStackSize; extern const char C_gStackPattern[8]; #endif -extern ARM_DRIVER_GPIO Driver_GPIO; void SPISlaveSetup( void ); @@ -104,7 +102,7 @@ int main( void ) SystemCoreClockUpdate(); /* Configure the GPIO ports (non module specific) */ - Driver_GPIO.Initialize(); + SystemGPIOConfig(); /* Set startup state of LEDs */ LED_Init(); /* Initialize Debug LEDs */ diff --git a/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup.c b/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup.c index 2e99fc5..ae6d25c 100644 --- a/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup.c +++ b/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup.c @@ -42,10 +42,18 @@ const GpioInfo_t DiagLEDs[NUM_LEDS] = {PINS_LEDS}; | P R I V A T E T Y P E D E F I N I T I O N S \*-------------------------------------------------------------------------------------------------*/ +/*-------------------------------------------------------------------------------------------------*\ + | S T A T I C V A R I A B L E S D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ + /*-------------------------------------------------------------------------------------------------*\ | F O R W A R D F U N C T I O N D E C L A R A T I O N S \*-------------------------------------------------------------------------------------------------*/ +/*-------------------------------------------------------------------------------------------------*\ + | P R I V A T E F U N C T I O N S +\*-------------------------------------------------------------------------------------------------*/ + /*-------------------------------------------------------------------------------------------------*\ | P U B L I C F U N C T I O N S \*-------------------------------------------------------------------------------------------------*/ @@ -113,6 +121,33 @@ void LED_Init( void ) LED_Off(index); } } +/**************************************************************************************************** + * @fn SystemGPIOConfig + * Configures the various GPIO ports on the chip according to the usage by various + * peripherals. + * + * @param none + * + * @return none + * + ***************************************************************************************************/ +void SystemGPIOConfig( void ) +{ + /* Initialize GPIO */ + Driver_GPIO.Initialize(); + + /* Setup the Sensor Hub interrupt pin as output */ + //Chip_IOCON_Config(LPC_IOCON, SH_INT_PIN); + //Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, SH_INT_GPIO_GRP, SH_INT_GPIO_PIN); + //SensorHubIntLow(); //Deassert on startup + + /* Setup DMA Common here since its not specific to any peripheral */ + Chip_DMA_Init(LPC_DMA); + //Chip_SYSCON_PeriphReset(RESET_DMA); + Chip_DMA_Enable(LPC_DMA); + Chip_DMA_SetSRAMBase(LPC_DMA, DMA_ADDR(Chip_DMA_Table)); +} + /**************************************************************************************************** * @fn SystemInterruptConfig @@ -274,6 +309,8 @@ void Board_SensorIfInit( InputSensor_t ifID ) switch (ifID) { case ACCEL_INPUT_SENSOR: + /* Initialize the pinmux pin */ + Chip_IOCON_PinMuxSet(LPC_IOCON, PIN_ACCEL); /* ACCEL INT1 irq setup */ NVIC_DisableIRQ(ACCEL_PINT_IRQn); NVIC_SetPriority(ACCEL_PINT_IRQn, ACCEL_INT_IRQ_PRIORITY); @@ -293,6 +330,8 @@ void Board_SensorIfInit( InputSensor_t ifID ) break; case MAG_INPUT_SENSOR: + /* Initialize the pinmux pin */ + Chip_IOCON_PinMuxSet(LPC_IOCON, PIN_MAG); NVIC_DisableIRQ(MAG_PINT_IRQn); NVIC_SetPriority(MAG_PINT_IRQn, MAG_INT_IRQ_PRIORITY); @@ -311,6 +350,8 @@ void Board_SensorIfInit( InputSensor_t ifID ) break; case GYRO_INPUT_SENSOR: + /* Initialize the pinmux pin */ + Chip_IOCON_PinMuxSet(LPC_IOCON, PIN_GYRO); NVIC_DisableIRQ(GYRO_PINT_IRQn); NVIC_SetPriority(GYRO_PINT_IRQn, GYRO_INT_IRQ_PRIORITY); diff --git a/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup_xpresso_lpc54102.h b/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup_xpresso_lpc54102.h index 97ed952..8daf4a8 100644 --- a/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup_xpresso_lpc54102.h +++ b/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup_xpresso_lpc54102.h @@ -34,6 +34,18 @@ \*-------------------------------------------------------------------------------------------------*/ #define SENSORHUB_INT_ACTIVE_HIGH +/* Pin handling macros for GPIO */ +#define NC (uint32_t)0xFFFFFFFF //Indicates pin is not assigned +#define ENCODE_PORT_PIN(port,pin) (PinName)(((uint32_t)port << 16) + (uint16_t)pin) +#define DECODE_PORT(X) (((uint32_t)(X) >> 16) & 0xF) +#define DECODE_PIN(X) ((uint32_t)(X) & 0xFFFF) + +/*-------------------------------------------------------------------------------------------------*\ + | T Y P E D E F I N I T I O N S +\*-------------------------------------------------------------------------------------------------*/ +/* Type to address GPIO pins */ +typedef uint32_t PinName; + /* ########################################################################## */ /* # T I M I N G S # */ /* ########################################################################## */ @@ -65,12 +77,6 @@ /* ########################################################################## */ /* Diagnostic GPIOs */ #define LPC_GPIO_PORT LPC_GPIO -#define NC (uint32_t)0xFFFFFFFF -typedef uint32_t PinName; - -#define ENCODE_PORT_PIN(port,pin) (PinName)(((uint32_t)port << 16) + (uint16_t)pin) -#define DECODE_PORT(X) (((uint32_t)(X) >> 16) & 0xF) -#define DECODE_PIN(X) ((uint32_t)(X) & 0xFFFF) /* Diagnostic LEDs on this board */ enum _Leds { //Sequence must correspond to PINS_LED definition @@ -170,6 +176,9 @@ extern const GpioInfo_t DiagLEDs[NUM_LEDS]; #define ACCEL_INT2_PORT 0 #define ACCEL_INT2_PIN 7 +/* CT32B0_MAT0-ACCL_INT1 */ +#define PIN_ACCEL 0, 18, (IOCON_FUNC0 | IOCON_MODE_INACT | IOCON_DIGITAL_EN) + /* IMPORTANT! - Sensor interrupts are shared by multiple sensor devices on the * LPCXpresso Sensor Shield board. Particularly when Accel on BMI055 is used, * INT1 is connected to P0_18 via R16 (220ohm) and fights with the INT1 of BMC150 @@ -192,6 +201,9 @@ extern const GpioInfo_t DiagLEDs[NUM_LEDS]; #define MAG_INT3_PORT 0 #define MAG_INT3_PIN 10 +/* MAG_DRDY_INT (GPIO input) */ +#define PIN_MAG 0, 22, (IOCON_FUNC0 | IOCON_MODE_PULLDOWN | IOCON_DIGITAL_EN) + /* ########################################################################## */ /* # G Y R O S C O P E I N T E R F A C E # */ /* ########################################################################## */ @@ -204,6 +216,9 @@ extern const GpioInfo_t DiagLEDs[NUM_LEDS]; #define GYRO_WAKE SYSCON_STARTER_PINT1 #define GYRO_IRQHandler PIN_INT1_IRQHandler +/* GYR_INT1 (GPIO input) */ +#define PIN_GYRO 0, 4, (IOCON_FUNC0 | IOCON_MODE_PULLDOWN | IOCON_DIGITAL_EN) + /* ########################################################################## */ /* # B A R O M E T E R I N T E R F A C E # */ /* ########################################################################## */ diff --git a/external/CMSIS/Include/Driver_Common.h b/external/CMSIS/Driver/Include/Driver_Common.h similarity index 97% rename from external/CMSIS/Include/Driver_Common.h rename to external/CMSIS/Driver/Include/Driver_Common.h index 396a11c..b11a115 100644 --- a/external/CMSIS/Include/Driver_Common.h +++ b/external/CMSIS/Driver/Include/Driver_Common.h @@ -1,72 +1,72 @@ -/* ----------------------------------------------------------------------------- - * Copyright (c) 2013-2014 ARM Ltd. - * - * This software is provided 'as-is', without any express or implied warranty. - * In no event will the authors be held liable for any damages arising from - * the use of this software. Permission is granted to anyone to use this - * software for any purpose, including commercial applications, and to alter - * it and redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software in - * a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source distribution. - * - * - * $Date: 2. Jan 2014 - * $Revision: V2.00 - * - * Project: Common Driver definitions - * -------------------------------------------------------------------------- */ - -/* History: - * Version 2.00 - * Changed prefix ARM_DRV -> ARM_DRIVER - * Added General return codes definitions - * Version 1.10 - * Namespace prefix ARM_ added - * Version 1.00 - * Initial release - */ - -#ifndef __DRIVER_COMMON_H -#define __DRIVER_COMMON_H - -#include -#include -#include - -#define ARM_DRIVER_VERSION_MAJOR_MINOR(major,minor) (((major) << 8) | (minor)) - -/** -\brief Driver Version -*/ -typedef struct _ARM_DRIVER_VERSION { - uint16_t api; ///< API version - uint16_t drv; ///< Driver version -} ARM_DRIVER_VERSION; - -/* General return codes */ -#define ARM_DRIVER_OK 0 ///< Operation succeeded -#define ARM_DRIVER_ERROR -1 ///< Unspecified error -#define ARM_DRIVER_ERROR_BUSY -2 ///< Driver is busy -#define ARM_DRIVER_ERROR_TIMEOUT -3 ///< Timeout occurred -#define ARM_DRIVER_ERROR_UNSUPPORTED -4 ///< Operation not supported -#define ARM_DRIVER_ERROR_PARAMETER -5 ///< Parameter error -#define ARM_DRIVER_ERROR_SPECIFIC -6 ///< Start of driver specific errors - -/** -\brief General power states -*/ -typedef enum _ARM_POWER_STATE { - ARM_POWER_OFF, ///< Power off: no operation possible - ARM_POWER_LOW, ///< Low Power mode: retain state, detect and signal wake-up events - ARM_POWER_FULL ///< Power on: full operation at maximum performance -} ARM_POWER_STATE; - -#endif /* __DRIVER_COMMON_H */ +/* ----------------------------------------------------------------------------- + * Copyright (c) 2013-2014 ARM Ltd. + * + * This software is provided 'as-is', without any express or implied warranty. + * In no event will the authors be held liable for any damages arising from + * the use of this software. Permission is granted to anyone to use this + * software for any purpose, including commercial applications, and to alter + * it and redistribute it freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software in + * a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any source distribution. + * + * + * $Date: 2. Jan 2014 + * $Revision: V2.00 + * + * Project: Common Driver definitions + * -------------------------------------------------------------------------- */ + +/* History: + * Version 2.00 + * Changed prefix ARM_DRV -> ARM_DRIVER + * Added General return codes definitions + * Version 1.10 + * Namespace prefix ARM_ added + * Version 1.00 + * Initial release + */ + +#ifndef __DRIVER_COMMON_H +#define __DRIVER_COMMON_H + +#include +#include +#include + +#define ARM_DRIVER_VERSION_MAJOR_MINOR(major,minor) (((major) << 8) | (minor)) + +/** +\brief Driver Version +*/ +typedef struct _ARM_DRIVER_VERSION { + uint16_t api; ///< API version + uint16_t drv; ///< Driver version +} ARM_DRIVER_VERSION; + +/* General return codes */ +#define ARM_DRIVER_OK 0 ///< Operation succeeded +#define ARM_DRIVER_ERROR -1 ///< Unspecified error +#define ARM_DRIVER_ERROR_BUSY -2 ///< Driver is busy +#define ARM_DRIVER_ERROR_TIMEOUT -3 ///< Timeout occurred +#define ARM_DRIVER_ERROR_UNSUPPORTED -4 ///< Operation not supported +#define ARM_DRIVER_ERROR_PARAMETER -5 ///< Parameter error +#define ARM_DRIVER_ERROR_SPECIFIC -6 ///< Start of driver specific errors + +/** +\brief General power states +*/ +typedef enum _ARM_POWER_STATE { + ARM_POWER_OFF, ///< Power off: no operation possible + ARM_POWER_LOW, ///< Low Power mode: retain state, detect and signal wake-up events + ARM_POWER_FULL ///< Power on: full operation at maximum performance +} ARM_POWER_STATE; + +#endif /* __DRIVER_COMMON_H */ diff --git a/external/CMSIS/Include/Driver_GPIO.h b/external/CMSIS/Driver/Include/Driver_GPIO.h similarity index 97% rename from external/CMSIS/Include/Driver_GPIO.h rename to external/CMSIS/Driver/Include/Driver_GPIO.h index 2917b6e..16fcc93 100644 --- a/external/CMSIS/Include/Driver_GPIO.h +++ b/external/CMSIS/Driver/Include/Driver_GPIO.h @@ -1,103 +1,103 @@ -/* ----------------------------------------------------------------------------- - * Copyright (c) 2015 Pinecone Ltd. - * - * This software is provided 'as-is', without any express or implied warranty. - * In no event will the authors be held liable for any damages arising from - * the use of this software. Permission is granted to anyone to use this - * software for any purpose, including commercial applications, and to alter - * it and redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software in - * a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source distribution. - * - * - * $Date: 8. June 2015 - * $Revision: V1.00 - * - * Project: GPIO Driver definitions - * -------------------------------------------------------------------------- */ - -/* History: - * Version 1.00 - * Initial release - */ - -#ifndef __DRIVER_GPIO_H -#define __DRIVER_GPIO_H - -#include "Driver_Common.h" - -#define OSP_GPIO_API_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(1,00) - -#define ARM_GPIO_DIR_INPUT 0 -#define ARM_GPIO_DIR_OUTPUT 1 - -#define ARM_GPIO_TRIGGER_NONE 0 -#define ARM_GPIO_TRIGGER_HIGH 1 -#define ARM_GPIO_TRIGGER_LOW 2 -#define ARM_GPIO_TRIGGER_RISING 3 -#define ARM_GPIO_TRIGGER_FALLING 4 -#define ARM_GPIO_TRIGGER_EDGE 5 - -typedef void (*ARM_GPIO_Handler_t) (uint32_t pin, void *data); - -typedef struct _ARM_DRIVER_GPIO { - ARM_DRIVER_VERSION (*GetVersion) (void); - int32_t (*Initialize) (void); - int32_t (*Uninitialize) (void); - int32_t (*PowerControl) (ARM_POWER_STATE state); - int32_t (*SetDirection) (uint32_t pin, uint32_t dir); - int32_t (*SetTrigger) (uint32_t pin, uint32_t trigger); - int32_t (*WritePin) (uint32_t pin, uint32_t value); - int32_t (*ReadPin) (uint32_t pin); - int32_t (*SetHandler) (uint32_t pin, ARM_GPIO_Handler_t handler, void *data); -} const ARM_DRIVER_GPIO; - -#define ARM_BUILD_DRIVER_GPIO(pre1, pre2, priv) \ - static ARM_DRIVER_VERSION pre1##_GetVersion (void) { \ - return pre2##_GetVersion (priv); \ - } \ - static int32_t pre1##_Initialize (void) { \ - return pre2##_Initialize (priv); \ - } \ - static int32_t pre1##_Uninitialize (void) { \ - return pre2##_Uninitialize (priv); \ - } \ - static int32_t pre1##_PowerControl (ARM_POWER_STATE state) { \ - return pre2##_PowerControl (state, priv); \ - } \ - static int32_t pre1##_SetDirection (uint32_t pin, uint32_t dir) { \ - return pre2##_SetDirection (pin, dir, priv); \ - } \ - static int32_t pre1##_SetTrigger (uint32_t pin, uint32_t trigger) { \ - return pre2##_SetTrigger (pin, trigger, priv); \ - } \ - static int32_t pre1##_WritePin (uint32_t pin, uint32_t value) { \ - return pre2##_WritePin (pin, value, priv); \ - } \ - static int32_t pre1##_ReadPin (uint32_t pin) { \ - return pre2##_ReadPin (pin, priv); \ - } \ - static int32_t pre1##_SetHandler (uint32_t pin, ARM_GPIO_Handler_t handler, void *data) { \ - return pre2##_SetHandler (pin, handler, data, priv); \ - } \ - ARM_DRIVER_GPIO Driver_##pre1 = { \ - pre1##_GetVersion, \ - pre1##_Initialize, \ - pre1##_Uninitialize, \ - pre1##_PowerControl, \ - pre1##_SetDirection, \ - pre1##_SetTrigger, \ - pre1##_WritePin, \ - pre1##_ReadPin, \ - pre1##_SetHandler, \ - }; - -#endif /* __DRIVER_GPIO_H */ +/* ----------------------------------------------------------------------------- + * Copyright (c) 2015 Pinecone Ltd. + * + * This software is provided 'as-is', without any express or implied warranty. + * In no event will the authors be held liable for any damages arising from + * the use of this software. Permission is granted to anyone to use this + * software for any purpose, including commercial applications, and to alter + * it and redistribute it freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software in + * a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any source distribution. + * + * + * $Date: 8. June 2015 + * $Revision: V1.00 + * + * Project: GPIO Driver definitions + * -------------------------------------------------------------------------- */ + +/* History: + * Version 1.00 + * Initial release + */ + +#ifndef __DRIVER_GPIO_H +#define __DRIVER_GPIO_H + +#include "Driver_Common.h" + +#define OSP_GPIO_API_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(1,00) + +#define ARM_GPIO_DIR_INPUT 0 +#define ARM_GPIO_DIR_OUTPUT 1 + +#define ARM_GPIO_TRIGGER_NONE 0 +#define ARM_GPIO_TRIGGER_HIGH 1 +#define ARM_GPIO_TRIGGER_LOW 2 +#define ARM_GPIO_TRIGGER_RISING 3 +#define ARM_GPIO_TRIGGER_FALLING 4 +#define ARM_GPIO_TRIGGER_EDGE 5 + +typedef void (*ARM_GPIO_Handler_t) (uint32_t pin, void *data); + +typedef struct _ARM_DRIVER_GPIO { + ARM_DRIVER_VERSION (*GetVersion) (void); + int32_t (*Initialize) (void); + int32_t (*Uninitialize) (void); + int32_t (*PowerControl) (ARM_POWER_STATE state); + int32_t (*SetDirection) (uint32_t pin, uint32_t dir); + int32_t (*SetTrigger) (uint32_t pin, uint32_t trigger); + int32_t (*WritePin) (uint32_t pin, uint32_t value); + int32_t (*ReadPin) (uint32_t pin); + int32_t (*SetHandler) (uint32_t pin, ARM_GPIO_Handler_t handler, void *data); +} const ARM_DRIVER_GPIO; + +#define ARM_BUILD_DRIVER_GPIO(pre1, pre2, priv) \ + static ARM_DRIVER_VERSION pre1##_GetVersion (void) { \ + return pre2##_GetVersion (priv); \ + } \ + static int32_t pre1##_Initialize (void) { \ + return pre2##_Initialize (priv); \ + } \ + static int32_t pre1##_Uninitialize (void) { \ + return pre2##_Uninitialize (priv); \ + } \ + static int32_t pre1##_PowerControl (ARM_POWER_STATE state) { \ + return pre2##_PowerControl (state, priv); \ + } \ + static int32_t pre1##_SetDirection (uint32_t pin, uint32_t dir) { \ + return pre2##_SetDirection (pin, dir, priv); \ + } \ + static int32_t pre1##_SetTrigger (uint32_t pin, uint32_t trigger) { \ + return pre2##_SetTrigger (pin, trigger, priv); \ + } \ + static int32_t pre1##_WritePin (uint32_t pin, uint32_t value) { \ + return pre2##_WritePin (pin, value, priv); \ + } \ + static int32_t pre1##_ReadPin (uint32_t pin) { \ + return pre2##_ReadPin (pin, priv); \ + } \ + static int32_t pre1##_SetHandler (uint32_t pin, ARM_GPIO_Handler_t handler, void *data) { \ + return pre2##_SetHandler (pin, handler, data, priv); \ + } \ + ARM_DRIVER_GPIO Driver_##pre1 = { \ + pre1##_GetVersion, \ + pre1##_Initialize, \ + pre1##_Uninitialize, \ + pre1##_PowerControl, \ + pre1##_SetDirection, \ + pre1##_SetTrigger, \ + pre1##_WritePin, \ + pre1##_ReadPin, \ + pre1##_SetHandler, \ + }; + +#endif /* __DRIVER_GPIO_H */ From 327563c95608d873fc73173e8af5a7bb4d5dd2f1 Mon Sep 17 00:00:00 2001 From: Pankaj Goenka Date: Thu, 17 Dec 2015 15:22:34 +0530 Subject: [PATCH 3/4] Closed following comments: Moved Driver_GPIO.c to embedded/Drivers/LPC5410x-CM4/CMSIS Removed private structure GPIO_T Removed GPIO_AINConfig() Added Chip_PININT_Init() to GPIO Init Removed calls to Chip_PININT_ClearIntStatus & Chip_INMUX_PinIntSel from OSP_GPIO_PowerControl Added comment describing how port and pin number are encoded Using Chip_GPIO_WriteDirBit, Chip_GPIO_ReadDirBit functions rather than directly modifying registers Made the description and usage of 'pin' argument in OSP_GPIO_SetTrigger in line with the other GPIO HAL APIs Asserting that the value of 'val' received in OSP_GPIO_WritePin is <=1 Returning ARM_DRIVER_ERROR_UNSUPPORTED from OSP_GPIO_SetHandler Signed-off-by: Pankaj Goenka --- .../CMSIS}/Driver_GPIO.c | 136 +++++++++--------- .../keil-mdk-build/SH-Xpresso-LPC54102.uvoptx | 2 +- .../SH-Xpresso-LPC54102.uvprojx | 8 +- .../sources/boardsupport/hw_setup.c | 3 - .../boardsupport/hw_setup_xpresso_lpc54102.h | 1 + 5 files changed, 72 insertions(+), 78 deletions(-) rename embedded/Drivers/{CMSIS/Device/NXP/LPC5410x => LPC5410x-CM4/CMSIS}/Driver_GPIO.c (64%) diff --git a/embedded/Drivers/CMSIS/Device/NXP/LPC5410x/Driver_GPIO.c b/embedded/Drivers/LPC5410x-CM4/CMSIS/Driver_GPIO.c similarity index 64% rename from embedded/Drivers/CMSIS/Device/NXP/LPC5410x/Driver_GPIO.c rename to embedded/Drivers/LPC5410x-CM4/CMSIS/Driver_GPIO.c index c293b65..c5cf70c 100644 --- a/embedded/Drivers/CMSIS/Device/NXP/LPC5410x/Driver_GPIO.c +++ b/embedded/Drivers/LPC5410x-CM4/CMSIS/Driver_GPIO.c @@ -30,21 +30,10 @@ /*-------------------------------------------------------------------------------------------------*\ | T Y P E D E F I N I T I O N S \*-------------------------------------------------------------------------------------------------*/ -/* Private structure for GPIO */ -typedef struct _GPIO_T -{ - LPC_GPIO_T *base; /* GPIO Base address */ - uint16_t port; /* Port number */ - uint16_t pin; /* Pin number */ - uint8_t id; /* Pin Interrupt Select Value */ -} GPIO_T; /*-------------------------------------------------------------------------------------------------*\ | S T A T I C V A R I A B L E S D E F I N I T I O N S \*-------------------------------------------------------------------------------------------------*/ -/* Private argument */ -static GPIO_T gpio_ID = { LPC_GPIO, 0, 0, 0 }; - /* Driver Version */ static const ARM_DRIVER_VERSION DriverVersion = { OSP_GPIO_API_VERSION, @@ -58,46 +47,33 @@ static const ARM_DRIVER_VERSION DriverVersion = { * @fn OSP_GPIO_GetVersion * Get driver version. * - * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers + * @param gpio_priv Private argument (Unused) * * @return ARM_DRIVER_VERSION * ***************************************************************************************************/ -static ARM_DRIVER_VERSION OSP_GPIO_GetVersion( GPIO_T *gpio_priv ) +static ARM_DRIVER_VERSION OSP_GPIO_GetVersion( void *gpio_priv ) { return DriverVersion; } -/**************************************************************************************************** - * @fn OSP_GPIO_AINConfig - * Configures all IOs as AIN to reduce the power consumption. - * - * @param none - * - * @return none - * - ***************************************************************************************************/ -static void OSP_GPIO_AINConfig( void ) -{ - return; -} - /**************************************************************************************************** * @fn OSP_GPIO_Initialize * Initializes the GPIO Module and Hardware * - * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers + * @param gpio_priv Private argument (Unused) * * @return Return code: On success return ARM_DRIVER_OK * ***************************************************************************************************/ -static int32_t OSP_GPIO_Initialize( GPIO_T *gpio_priv ) +static int32_t OSP_GPIO_Initialize( void *gpio_priv ) { - /* Set all GPIOs to analog input mode to begin with */ - OSP_GPIO_AINConfig(); - /* Enable the peripheral clock in the PMC */ - Chip_GPIO_Init( gpio_priv->base ); + Chip_GPIO_Init( LPC_GPIO ); + + /* Enable Pin interrupt sources */ + Chip_PININT_Init( NULL ); /* Note: input arg is ignored! */ + return ARM_DRIVER_OK; } @@ -105,17 +81,17 @@ static int32_t OSP_GPIO_Initialize( GPIO_T *gpio_priv ) * @fn OSP_GPIO_Uninitialize * Unitialize the GPIO Module * - * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers + * @param gpio_priv Private argument (Unused) * * @return Return code: On success return ARM_DRIVER_OK * ***************************************************************************************************/ -static int32_t OSP_GPIO_Uninitialize( GPIO_T *gpio_priv ) +static int32_t OSP_GPIO_Uninitialize( void *gpio_priv ) { /* Uninitialize GPIO */ - Chip_GPIO_DeInit( gpio_priv->base ); + Chip_GPIO_DeInit( LPC_GPIO ); - Chip_PININT_DeInit( LPC_PININT ); + Chip_PININT_DeInit( NULL ); /* Note: input arg is ignored! */ return ARM_DRIVER_OK; } @@ -124,21 +100,21 @@ static int32_t OSP_GPIO_Uninitialize( GPIO_T *gpio_priv ) * Control the GPIO's power state * * @param state Target GPIO Power state - * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers + * @param gpio_priv Private argument (Unused) * * @return Return code: On success return ARM_DRIVER_OK * ***************************************************************************************************/ -static int32_t OSP_GPIO_PowerControl( ARM_POWER_STATE state, GPIO_T *gpio_priv ) +static int32_t OSP_GPIO_PowerControl( ARM_POWER_STATE state, void *gpio_priv ) { switch ( state ) { case ARM_POWER_OFF: - Chip_PININT_ClearIntStatus( LPC_PININT, gpio_priv->pin ); + Chip_GPIO_DeInit( LPC_GPIO ); break; case ARM_POWER_FULL: - Chip_INMUX_PinIntSel( gpio_priv->id, gpio_priv->port, gpio_priv->pin ); + Chip_GPIO_Init( LPC_GPIO ); break; default: @@ -151,14 +127,14 @@ static int32_t OSP_GPIO_PowerControl( ARM_POWER_STATE state, GPIO_T *gpio_priv ) * @fn OSP_GPIO_SetDirection * Set the direction of GPIO pin * - * @param pin Port pin number - * @param dir Direction (GPIO_DIR_INPUT or GPIO_DIR_OUTPUT) - * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers + * @param pin Port pin number (Port and pin numbers encoded using ENCODE_PORT_PIN) + * @param dir Direction (GPIO_DIR_INPUT or GPIO_DIR_OUTPUT) + * @param gpio_priv Private argument (Unused) * * @return Return code: On success return ARM_DRIVER_OK * ***************************************************************************************************/ -static int32_t OSP_GPIO_SetDirection( uint32_t pin, uint32_t dir, GPIO_T *gpio_priv ) +static int32_t OSP_GPIO_SetDirection( uint32_t pin, uint32_t dir, void *gpio_priv ) { uint32_t port_num = 0, pin_num = 0; @@ -167,8 +143,8 @@ static int32_t OSP_GPIO_SetDirection( uint32_t pin, uint32_t dir, GPIO_T *gpio_p port_num = DECODE_PORT( pin ); pin_num = DECODE_PIN( pin ); - dir ? ( gpio_priv->base->DIR[port_num] |= ( 1UL << pin_num) ) : \ - ( gpio_priv->base->DIR[port_num] &= ~( 1UL << pin_num) ); + ( dir == ARM_GPIO_DIR_OUTPUT ) ? Chip_GPIO_SetPinDIROutput( LPC_GPIO, port_num, pin_num ) : \ + Chip_GPIO_SetPinDIRInput( LPC_GPIO, port_num, pin_num ); return ARM_DRIVER_OK; } @@ -177,30 +153,48 @@ static int32_t OSP_GPIO_SetDirection( uint32_t pin, uint32_t dir, GPIO_T *gpio_p * @fn OSP_GPIO_SetTrigger * Set the trigger mode for GPIO * - * @param pin Pin Interrupt Channel + * @param pin Port pin number (Port and pin numbers encoded using ENCODE_PORT_PIN) * @param trigger Trigger mode - * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers + * @param gpio_priv Private argument (Unused) * * @return Return code: On success return ARM_DRIVER_OK * ***************************************************************************************************/ -static int32_t OSP_GPIO_SetTrigger( uint32_t pin, uint32_t trigger, GPIO_T *gpio_priv ) +static int32_t OSP_GPIO_SetTrigger( uint32_t pin, uint32_t trigger, void *gpio_priv ) { + uint32_t pinInterruptChannel = 0; + + switch (DECODE_PIN(pin)) + { + case ACCEL_INT_PIN: + pinInterruptChannel = ACCEL_PINT_CH; + break; + case MAG_INT_PIN: + pinInterruptChannel = MAG_PINT_CH; + break; + case GYRO_INT_PIN: + pinInterruptChannel = GYRO_PINT_CH; + break; + default: + return ARM_DRIVER_ERROR_UNSUPPORTED; + } + if ( trigger & (1 << ARM_GPIO_TRIGGER_EDGE) ) { - Chip_PININT_SetPinModeEdge( LPC_PININT, pin ); /* edge sensitive */ + Chip_PININT_SetPinModeEdge( LPC_PININT, pinInterruptChannel ); /* edge sensitive */ } else { - Chip_PININT_SetPinModeLevel( LPC_PININT, pin ); /* Level sensitive */ + Chip_PININT_SetPinModeLevel( LPC_PININT, pinInterruptChannel ); /* Level sensitive */ } + if ( (trigger & (1 << ARM_GPIO_TRIGGER_HIGH)) || (trigger & (1 << ARM_GPIO_TRIGGER_RISING)) ) { - Chip_PININT_EnableIntHigh( LPC_PININT, pin ); /* Rising Edge/High Level */ + Chip_PININT_EnableIntHigh( LPC_PININT, pinInterruptChannel ); /* Rising Edge/High Level */ } else { - Chip_PININT_EnableIntLow( LPC_PININT, pin ); /* Falling Edge/Low Level */ + Chip_PININT_EnableIntLow( LPC_PININT, pinInterruptChannel ); /* Falling Edge/Low Level */ } return ARM_DRIVER_OK; } @@ -209,22 +203,23 @@ static int32_t OSP_GPIO_SetTrigger( uint32_t pin, uint32_t trigger, GPIO_T *gpio * @fn OSP_GPIO_WritePin * Set the GPIO Pin state * - * @param pin Port pin number - * @param val Value to be written (0 or 1) - * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers + * @param pin Port pin number (Port and pin numbers encoded using ENCODE_PORT_PIN) + * @param val Value to be written (0 or 1) + * @param gpio_priv Private argument (Unused) * * @return Return code: On success return ARM_DRIVER_OK * ***************************************************************************************************/ -static int32_t OSP_GPIO_WritePin( uint32_t pin, uint32_t val, GPIO_T *gpio_priv ) +static int32_t OSP_GPIO_WritePin( uint32_t pin, uint32_t val, void *gpio_priv ) { uint32_t port_num = 0, pin_num = 0; ASF_assert( pin != (PinName)NC ); + ASF_assert( val <= 1 ); port_num = DECODE_PORT( pin ); pin_num = DECODE_PIN( pin ); - gpio_priv->base->B[port_num][pin_num] = val; + Chip_GPIO_WritePortBit( LPC_GPIO, port_num, pin_num, (bool) val ); return ARM_DRIVER_OK; } @@ -232,41 +227,42 @@ static int32_t OSP_GPIO_WritePin( uint32_t pin, uint32_t val, GPIO_T *gpio_priv * @fn OSP_GPIO_ReadPin * Get the GPIO Pin value * - * @param pin Port pin number - * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers + * @param pin Port pin number (Port and pin numbers encoded using ENCODE_PORT_PIN) + * @param gpio_priv Private argument (Unused) * * @return pin value * ***************************************************************************************************/ -static int32_t OSP_GPIO_ReadPin( uint32_t pin, GPIO_T *gpio_priv ) +static int32_t OSP_GPIO_ReadPin( uint32_t pin, void *gpio_priv ) { uint32_t port_num = 0, pin_num = 0; ASF_assert( pin != (PinName)NC ); port_num = DECODE_PORT( pin ); pin_num = DECODE_PIN( pin ); - return ( (gpio_priv->base->PIN[port_num] & (1UL << pin_num)) ? (1) : (0) ); + + return ( Chip_GPIO_ReadPortBit( LPC_GPIO, port_num, pin_num ) ); } /**************************************************************************************************** * @fn OSP_GPIO_SetHandler * Handler function * - * @param pin Port pin number - * @param handler Pointer to handler function - * @param data Data to pass to the handler - * @param gpio_priv Private object containing GPIO Base address, Interrupt pin select value (id) and Port-Pin numbers + * @param pin Port pin number (Port and pin numbers encoded using ENCODE_PORT_PIN) + * @param handler Pointer to handler function + * @param data Data to pass to the handler + * @param gpio_priv Private argument (Unused) * * @return Return code: On success return ARM_DRIVER_OK * ***************************************************************************************************/ -static int32_t OSP_GPIO_SetHandler( uint32_t pin, ARM_GPIO_Handler_t handler, void *data, GPIO_T *gpio_priv ) +static int32_t OSP_GPIO_SetHandler( uint32_t pin, ARM_GPIO_Handler_t handler, void *data, void *gpio_priv ) { - return ARM_DRIVER_OK; //Do nothing + return ARM_DRIVER_ERROR_UNSUPPORTED; //Not Supported } /* Driver Definition */ -ARM_BUILD_DRIVER_GPIO( GPIO, OSP_GPIO, &gpio_ID ); +ARM_BUILD_DRIVER_GPIO( GPIO, OSP_GPIO, NULL ); /*-------------------------------------------------------------------------------------------------*\ | E N D O F F I L E diff --git a/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvoptx b/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvoptx index 058a55c..222b0e4 100644 --- a/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvoptx +++ b/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvoptx @@ -1378,7 +1378,7 @@ 0 0 0 - ..\..\..\..\embedded\Drivers\CMSIS\Device\NXP\LPC5410x\Driver_GPIO.c + ..\..\..\..\embedded\Drivers\LPC5410x-CM4\CMSIS\Driver_GPIO.c Driver_GPIO.c 0 0 diff --git a/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvprojx b/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvprojx index bc9627e..fa5cfe7 100644 --- a/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvprojx +++ b/embedded/projects/SH-Xpresso-LPC54102/keil-mdk-build/SH-Xpresso-LPC54102.uvprojx @@ -796,7 +796,7 @@ Driver_GPIO.c 1 - ..\..\..\..\embedded\Drivers\CMSIS\Device\NXP\LPC5410x\Driver_GPIO.c + ..\..\..\..\embedded\Drivers\LPC5410x-CM4\CMSIS\Driver_GPIO.c @@ -1595,7 +1595,7 @@ Driver_GPIO.c 1 - ..\..\..\..\embedded\Drivers\CMSIS\Device\NXP\LPC5410x\Driver_GPIO.c + ..\..\..\..\embedded\Drivers\LPC5410x-CM4\CMSIS\Driver_GPIO.c @@ -2394,7 +2394,7 @@ Driver_GPIO.c 1 - ..\..\..\..\embedded\Drivers\CMSIS\Device\NXP\LPC5410x\Driver_GPIO.c + ..\..\..\..\embedded\Drivers\LPC5410x-CM4\CMSIS\Driver_GPIO.c @@ -3193,7 +3193,7 @@ Driver_GPIO.c 1 - ..\..\..\..\embedded\Drivers\CMSIS\Device\NXP\LPC5410x\Driver_GPIO.c + ..\..\..\..\embedded\Drivers\LPC5410x-CM4\CMSIS\Driver_GPIO.c diff --git a/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup.c b/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup.c index ae6d25c..b269fa6 100644 --- a/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup.c +++ b/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup.c @@ -157,9 +157,6 @@ void SystemGPIOConfig( void ) void SystemInterruptConfig( void ) { NVIC_SetPriorityGrouping( SYSTEM_INTERRUPT_PRIORITY_GRP ); - - /* Enable Pin interrupt sources */ - Chip_PININT_Init(NULL); /* Note: input arg is ignored! */ } diff --git a/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup_xpresso_lpc54102.h b/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup_xpresso_lpc54102.h index 8daf4a8..9068b2c 100644 --- a/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup_xpresso_lpc54102.h +++ b/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup_xpresso_lpc54102.h @@ -36,6 +36,7 @@ /* Pin handling macros for GPIO */ #define NC (uint32_t)0xFFFFFFFF //Indicates pin is not assigned +/* Port and pin number are encoded into a 32-bit word with port number as upper nibble and pin number as lower nibble */ #define ENCODE_PORT_PIN(port,pin) (PinName)(((uint32_t)port << 16) + (uint16_t)pin) #define DECODE_PORT(X) (((uint32_t)(X) >> 16) & 0xF) #define DECODE_PIN(X) ((uint32_t)(X) & 0xFFFF) From 1be97747c71f4832f1449677a78c09307b8447e4 Mon Sep 17 00:00:00 2001 From: Pankaj Goenka Date: Mon, 21 Dec 2015 19:58:58 +0530 Subject: [PATCH 4/4] Incorporated internal review comments * Made SetTrigger's pin parameters inline with parameters of other APIs * Closed coding guidelines related comments * Added calls to Driver_GPIO.SetTrigger Signed-off-by: Pankaj Goenka --- .../Drivers/LPC5410x-CM4/CMSIS/Driver_GPIO.c | 60 +++++++++---------- .../sources/boardsupport/hw_setup.c | 36 +++++------ .../boardsupport/hw_setup_xpresso_lpc54102.h | 20 ++++++- 3 files changed, 65 insertions(+), 51 deletions(-) diff --git a/embedded/Drivers/LPC5410x-CM4/CMSIS/Driver_GPIO.c b/embedded/Drivers/LPC5410x-CM4/CMSIS/Driver_GPIO.c index c5cf70c..8b281fb 100644 --- a/embedded/Drivers/LPC5410x-CM4/CMSIS/Driver_GPIO.c +++ b/embedded/Drivers/LPC5410x-CM4/CMSIS/Driver_GPIO.c @@ -35,7 +35,8 @@ | S T A T I C V A R I A B L E S D E F I N I T I O N S \*-------------------------------------------------------------------------------------------------*/ /* Driver Version */ -static const ARM_DRIVER_VERSION DriverVersion = { +static const ARM_DRIVER_VERSION DriverVersion = +{ OSP_GPIO_API_VERSION, OSP_GPIO_DRV_VERSION }; @@ -72,8 +73,7 @@ static int32_t OSP_GPIO_Initialize( void *gpio_priv ) Chip_GPIO_Init( LPC_GPIO ); /* Enable Pin interrupt sources */ - Chip_PININT_Init( NULL ); /* Note: input arg is ignored! */ - + Chip_PININT_Init( NULL ); return ARM_DRIVER_OK; } @@ -91,7 +91,7 @@ static int32_t OSP_GPIO_Uninitialize( void *gpio_priv ) /* Uninitialize GPIO */ Chip_GPIO_DeInit( LPC_GPIO ); - Chip_PININT_DeInit( NULL ); /* Note: input arg is ignored! */ + Chip_PININT_DeInit( NULL ); return ARM_DRIVER_OK; } @@ -109,16 +109,16 @@ static int32_t OSP_GPIO_PowerControl( ARM_POWER_STATE state, void *gpio_priv ) { switch ( state ) { - case ARM_POWER_OFF: - Chip_GPIO_DeInit( LPC_GPIO ); - break; + case ARM_POWER_OFF: + Chip_GPIO_DeInit( LPC_GPIO ); + break; - case ARM_POWER_FULL: - Chip_GPIO_Init( LPC_GPIO ); - break; + case ARM_POWER_FULL: + Chip_GPIO_Init( LPC_GPIO ); + break; - default: - return ARM_DRIVER_ERROR_UNSUPPORTED; + default: + return ARM_DRIVER_ERROR_UNSUPPORTED; } return ARM_DRIVER_OK; } @@ -127,7 +127,7 @@ static int32_t OSP_GPIO_PowerControl( ARM_POWER_STATE state, void *gpio_priv ) * @fn OSP_GPIO_SetDirection * Set the direction of GPIO pin * - * @param pin Port pin number (Port and pin numbers encoded using ENCODE_PORT_PIN) + * @param pin Port pin number (Upper 16-bit is port number and lower 16-bit is pin number) * @param dir Direction (GPIO_DIR_INPUT or GPIO_DIR_OUTPUT) * @param gpio_priv Private argument (Unused) * @@ -145,7 +145,6 @@ static int32_t OSP_GPIO_SetDirection( uint32_t pin, uint32_t dir, void *gpio_pri ( dir == ARM_GPIO_DIR_OUTPUT ) ? Chip_GPIO_SetPinDIROutput( LPC_GPIO, port_num, pin_num ) : \ Chip_GPIO_SetPinDIRInput( LPC_GPIO, port_num, pin_num ); - return ARM_DRIVER_OK; } @@ -153,7 +152,7 @@ static int32_t OSP_GPIO_SetDirection( uint32_t pin, uint32_t dir, void *gpio_pri * @fn OSP_GPIO_SetTrigger * Set the trigger mode for GPIO * - * @param pin Port pin number (Port and pin numbers encoded using ENCODE_PORT_PIN) + * @param pin Port pin number (Upper 16-bit is port number and lower 16-bit is pin number) * @param trigger Trigger mode * @param gpio_priv Private argument (Unused) * @@ -162,23 +161,22 @@ static int32_t OSP_GPIO_SetDirection( uint32_t pin, uint32_t dir, void *gpio_pri ***************************************************************************************************/ static int32_t OSP_GPIO_SetTrigger( uint32_t pin, uint32_t trigger, void *gpio_priv ) { - uint32_t pinInterruptChannel = 0; + uint8_t index = 0; + uint8_t pinInterruptChannel = 0; - switch (DECODE_PIN(pin)) + ASF_assert( pin != (PinName)NC ); + + for ( ; index < MAX_PIN_INTERRUPT_CHANNEL; index++ ) { - case ACCEL_INT_PIN: - pinInterruptChannel = ACCEL_PINT_CH; - break; - case MAG_INT_PIN: - pinInterruptChannel = MAG_PINT_CH; - break; - case GYRO_INT_PIN: - pinInterruptChannel = GYRO_PINT_CH; + if ( GPIO_PinMap[index].pin == pin ) + { + pinInterruptChannel = GPIO_PinMap[index].pinInterruptChannel; break; - default: - return ARM_DRIVER_ERROR_UNSUPPORTED; + } } + ASF_assert( index < MAX_PIN_INTERRUPT_CHANNEL ); + if ( trigger & (1 << ARM_GPIO_TRIGGER_EDGE) ) { Chip_PININT_SetPinModeEdge( LPC_PININT, pinInterruptChannel ); /* edge sensitive */ @@ -203,7 +201,7 @@ static int32_t OSP_GPIO_SetTrigger( uint32_t pin, uint32_t trigger, void *gpio_p * @fn OSP_GPIO_WritePin * Set the GPIO Pin state * - * @param pin Port pin number (Port and pin numbers encoded using ENCODE_PORT_PIN) + * @param pin Port pin number (Upper 16-bit is port number and lower 16-bit is pin number) * @param val Value to be written (0 or 1) * @param gpio_priv Private argument (Unused) * @@ -227,7 +225,7 @@ static int32_t OSP_GPIO_WritePin( uint32_t pin, uint32_t val, void *gpio_priv ) * @fn OSP_GPIO_ReadPin * Get the GPIO Pin value * - * @param pin Port pin number (Port and pin numbers encoded using ENCODE_PORT_PIN) + * @param pin Port pin number (Upper 16-bit is port number and lower 16-bit is pin number) * @param gpio_priv Private argument (Unused) * * @return pin value @@ -240,7 +238,7 @@ static int32_t OSP_GPIO_ReadPin( uint32_t pin, void *gpio_priv ) ASF_assert( pin != (PinName)NC ); port_num = DECODE_PORT( pin ); pin_num = DECODE_PIN( pin ); - + return ( Chip_GPIO_ReadPortBit( LPC_GPIO, port_num, pin_num ) ); } @@ -248,7 +246,7 @@ static int32_t OSP_GPIO_ReadPin( uint32_t pin, void *gpio_priv ) * @fn OSP_GPIO_SetHandler * Handler function * - * @param pin Port pin number (Port and pin numbers encoded using ENCODE_PORT_PIN) + * @param pin Port pin number (Upper 16-bit is port number and lower 16-bit is pin number) * @param handler Pointer to handler function * @param data Data to pass to the handler * @param gpio_priv Private argument (Unused) diff --git a/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup.c b/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup.c index b269fa6..398bc88 100644 --- a/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup.c +++ b/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup.c @@ -34,6 +34,15 @@ extern ARM_DRIVER_GPIO Driver_GPIO; const uint32_t ExtClockIn = 0; const GpioInfo_t DiagLEDs[NUM_LEDS] = {PINS_LEDS}; +/* Mapping of Port and Pin to Pin Interrupt Channel */ +const GPIO_PinMap_t GPIO_PinMap[MAX_PIN_INTERRUPT_CHANNEL] = +{ + { ENCODE_PORT_PIN( ACCEL_INT_PORT, ACCEL_INT_PIN ), ACCEL_PINT_CH }, /* Channel 0 */ + { ENCODE_PORT_PIN( GYRO_INT_PORT, GYRO_INT_PIN ), GYRO_PINT_CH }, /* Channel 1 */ + { ENCODE_PORT_PIN( MAG_INT_PORT, MAG_INT_PIN ), MAG_PINT_CH }, /* Channel 2 */ + { ENCODE_PORT_PIN( PROXI_INT_PORT, PROXI_INT_PIN ), PROXI_PINT_CH } /* Channel 3 */ +}; + /*-------------------------------------------------------------------------------------------------*\ | P R I V A T E C O N S T A N T S & M A C R O S \*-------------------------------------------------------------------------------------------------*/ @@ -315,15 +324,10 @@ void Board_SensorIfInit( InputSensor_t ifID ) Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, ACCEL_INT_PORT, ACCEL_INT_PIN, false); Chip_INMUX_PinIntSel(ACCEL_PINT_SEL, ACCEL_INT_PORT, ACCEL_INT_PIN); - Chip_PININT_SetPinModeEdge(LPC_PININT, ACCEL_PINT_CH); /* edge sensitive */ - Chip_PININT_EnableIntHigh(LPC_PININT, ACCEL_PINT_CH); /* Rising edge interrupt */ - - //pinDef.pin = ENCODE_PORT_PIN(ACCEL_INT2_PORT, ACCEL_INT2_PIN); - //gpio_dir(&pinDef, PIN_INPUT); + /* High Edge Trigger */ + Driver_GPIO.SetTrigger( ENCODE_PORT_PIN( ACCEL_INT_PORT, ACCEL_INT_PIN ), + ( ( 1 << ARM_GPIO_TRIGGER_EDGE ) | ( 1 << ARM_GPIO_TRIGGER_HIGH ) ) ); - //Chip_SYSCON_EnableWakeup(ACCEL_WAKE); /* enable to wake from sleep */ - - //gpio_irq_disable(&gpioIrq); break; case MAG_INPUT_SENSOR: @@ -336,14 +340,10 @@ void Board_SensorIfInit( InputSensor_t ifID ) Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, MAG_INT_PORT, MAG_INT_PIN, false); Chip_INMUX_PinIntSel(MAG_PINT_SEL, MAG_INT_PORT, MAG_INT_PIN); - Chip_PININT_SetPinModeEdge(LPC_PININT, MAG_PINT_CH); /* edge sensitive */ - Chip_PININT_EnableIntHigh(LPC_PININT, MAG_PINT_CH); /* Rising edge interrupt */ - - //Chip_SYSCON_EnableWakeup(MAG_WAKE); /* enable to wake from sleep */ - //Chip_SYSCON_EnableWakeup(SYSCON_STARTER_WWDT); /* enable to wake from sleep */ + /* High Edge Trigger */ + Driver_GPIO.SetTrigger( ENCODE_PORT_PIN( MAG_INT_PORT, MAG_INT_PIN ), + ( ( 1 << ARM_GPIO_TRIGGER_EDGE ) | ( 1 << ARM_GPIO_TRIGGER_HIGH ) ) ); - //pinDef.pin = ENCODE_PORT_PIN(MAG_INT3_PORT, MAG_INT3_PIN); - //gpio_dir(&pinDef,PIN_INPUT); break; case GYRO_INPUT_SENSOR: @@ -356,10 +356,10 @@ void Board_SensorIfInit( InputSensor_t ifID ) Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, GYRO_INT_PORT, GYRO_INT_PIN, false); Chip_INMUX_PinIntSel(GYRO_PINT_SEL, GYRO_INT_PORT, GYRO_INT_PIN); - Chip_PININT_SetPinModeEdge(LPC_PININT, GYRO_PINT_CH); /* edge sensitive */ - Chip_PININT_EnableIntHigh(LPC_PININT, GYRO_PINT_CH); /* Rising edge interrupt */ + /* High Edge Trigger */ + Driver_GPIO.SetTrigger( ENCODE_PORT_PIN( GYRO_INT_PORT, GYRO_INT_PIN ), + ( ( 1 << ARM_GPIO_TRIGGER_EDGE ) | ( 1 << ARM_GPIO_TRIGGER_HIGH ) ) ); - //Chip_SYSCON_EnableWakeup(GYRO_WAKE); break; case PRESSURE_INPUT_SENSOR: diff --git a/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup_xpresso_lpc54102.h b/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup_xpresso_lpc54102.h index 9068b2c..5bbaa61 100644 --- a/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup_xpresso_lpc54102.h +++ b/embedded/projects/SH-Xpresso-LPC54102/sources/boardsupport/hw_setup_xpresso_lpc54102.h @@ -36,7 +36,7 @@ /* Pin handling macros for GPIO */ #define NC (uint32_t)0xFFFFFFFF //Indicates pin is not assigned -/* Port and pin number are encoded into a 32-bit word with port number as upper nibble and pin number as lower nibble */ +/* Port and pin number are encoded into a 32-bit word with port number as upper 16 bits and pin number as lower 16 bits */ #define ENCODE_PORT_PIN(port,pin) (PinName)(((uint32_t)port << 16) + (uint16_t)pin) #define DECODE_PORT(X) (((uint32_t)(X) >> 16) & 0xF) #define DECODE_PIN(X) ((uint32_t)(X) & 0xFFFF) @@ -44,9 +44,25 @@ /*-------------------------------------------------------------------------------------------------*\ | T Y P E D E F I N I T I O N S \*-------------------------------------------------------------------------------------------------*/ + +/* ########################################################################## */ +/* # G P I O # */ +/* ########################################################################## */ +/* Number of pin interrupt channels */ +#define MAX_PIN_INTERRUPT_CHANNEL 8 + /* Type to address GPIO pins */ typedef uint32_t PinName; +/* Structure to hold pin/port to interrupt channel mapping */ +typedef struct _GPIO_PinMap +{ + uint32_t pin; + uint8_t pinInterruptChannel; +} GPIO_PinMap_t; + +extern const GPIO_PinMap_t GPIO_PinMap[MAX_PIN_INTERRUPT_CHANNEL]; + /* ########################################################################## */ /* # T I M I N G S # */ /* ########################################################################## */ @@ -234,7 +250,7 @@ extern const GpioInfo_t DiagLEDs[NUM_LEDS]; #define PROXI_INT_PORT 0X0 #define PROXI_INT_PIN 9 #define PROXI_PINT_SEL PININTSELECT3 -#define PROXI_PINT_CH PINTINTCH3 +#define PROXI_PINT_CH PININTCH3 #define PROXI_PINT_IRQn PIN_INT3_IRQn #define PROXI_WAKE SYSCON_STARTER_PINT3 #define PROXI_IRQHandler PIN_INT3_IRQHandler