Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions embedded/common/modules/sensor-drivers/BMG160.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@
#include "bmg160.h"
#include "sensorhub.h"
#include "common.h"
#include "board.h"
#include "gyro_common.h"
#include "osp-sensors.h"
#include "sensacq_i2c.h"
#include "gpio_api.h"
#include "gpio_irq_api.h"

static struct bmg160_t *p_bmg160 = NULL;
static struct bmg160_t bmg160;
Expand Down Expand Up @@ -137,12 +138,15 @@ static void gyro_activate(bool enable)

void Gyro_HardwareSetup(osp_bool_t enable)
{
gpio_t hostifIrq;
gpio_irq_t gpioIrq;
NVIC_DisableIRQ(GYRO_PINT_IRQn);
NVIC_SetPriority(GYRO_PINT_IRQn, SENSOR_IRQ_PRIORITY);
Chip_GPIO_SetPinDIRInput(LPC_GPIO, GYRO_INT_PORT, GYRO_INT_PIN);
Chip_INMUX_PinIntSel(GYRO_PINT_SEL,GYRO_INT_PORT, GYRO_INT_PIN);
Chip_PININT_SetPinModeEdge(LPC_PININT, GYRO_PINT_CH);
Chip_PININT_EnableIntHigh(LPC_PININT, GYRO_PINT_CH);
hostifIrq.pin = ENCODE_PORT_PIN(GYRO_INT_PORT, GYRO_INT_PIN);
gpio_dir(&hostifIrq,PIN_INPUT);
gpioIrq.irq_index = GYRO_PINT_CH;
gpioIrq.event = IRQ_EDGE_RISE;
gpio_irq_init(&gpioIrq, ENCODE_PORT_PIN(GYRO_INT_PORT, GYRO_INT_PIN), NULL, GYRO_PINT_SEL);
Chip_SYSCON_EnableWakeup(GYRO_WAKE);
}

Expand Down Expand Up @@ -228,18 +232,20 @@ void Gyro_ReadData(MsgGyroData *gyroData)

void GYRO_IRQHandler(void)
{
gpio_irq_t gpioIrq;
uint32_t currTime = GetCurrentTime();
gpioIrq.irq_index = GYRO_PINT_CH;
#if 0
PhysicalSensor_t* pSens = g_phySensors[PHYS_GYRO_ID];
uint32_t currTime = g_Timer.GetCurrent();
pSens->ts_nextSample = currTime + ((pSens->period + (pSens->ts_nextSample - pSens->ts_lastSample)) >> 1) ;
pSens->ts_lastSample = currTime;

pSens->irq_pending++;
Chip_PININT_ClearIntStatus(LPC_PININT, GYRO_PINT_CH);
gpio_irq_disable(&gpioIrq);
ResMgr_IRQDone();
#else
Chip_PININT_ClearIntStatus(LPC_PININT, GYRO_PINT_CH);
gpio_irq_disable(&gpioIrq);
SendDataReadyIndication(GYRO_INPUT_SENSOR, currTime);
#endif
}
Expand Down
28 changes: 16 additions & 12 deletions embedded/common/modules/sensor-drivers/bma2x2.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@
#include "sensorhub.h"
#include "common.h"
#include "acc_common.h"
#include "board.h"
#include "osp-sensors.h"
#include "sensacq_i2c.h"
#include "gpio_api.h"
#include "gpio_irq_api.h"

/* user defined code to be added here ... */
static bma2x2_t *p_bma2x2;
Expand Down Expand Up @@ -122,23 +123,24 @@ static void accel_activate(bool enable)
}
void Accel_HardwareSetup(osp_bool_t enable)
{
gpio_t hostifIrq;
gpio_irq_t gpioIrq;
/* ACCEL INT1 irq setup */
NVIC_DisableIRQ(ACCEL_PINT_IRQn);
NVIC_SetPriority(ACCEL_PINT_IRQn, SENSOR_IRQ_PRIORITY);
Chip_GPIO_SetPinDIRInput(LPC_GPIO, ACCEL_INT_PORT, ACCEL_INT_PIN);
hostifIrq.pin = ENCODE_PORT_PIN(ACCEL_INT_PORT, ACCEL_INT_PIN);
gpio_dir(&hostifIrq,PIN_INPUT);

Chip_INMUX_PinIntSel(ACCEL_PINT_SEL, ACCEL_INT_PORT, ACCEL_INT_PIN);
gpioIrq.irq_index = ACCEL_PINT_CH;
gpioIrq.event = IRQ_EDGE_RISE;
gpio_irq_init(&gpioIrq, ENCODE_PORT_PIN(ACCEL_INT_PORT, ACCEL_INT_PIN), NULL, ACCEL_PINT_SEL);


Chip_PININT_SetPinModeEdge(LPC_PININT, ACCEL_PINT_CH); /* edge sensitive and rising edge interrupt */
Chip_PININT_EnableIntHigh(LPC_PININT, ACCEL_PINT_CH);

//Chip_GPIO_SetPinDIRInput(LPC_GPIO, ACCEL_INT2_PORT, ACCEL_INT2_PIN);
hostifIrq.pin = ENCODE_PORT_PIN(ACCEL_INT2_PORT, ACCEL_INT2_PIN);
gpio_dir(&hostifIrq,PIN_INPUT);

Chip_SYSCON_EnableWakeup(ACCEL_WAKE); /* enable to wake from sleep */

//Chip_PININT_ClearIntStatus(LPC_PININT, ACCEL_PINT_CH);

//gpio_irq_disable(&gpioIrq);

}
void Accel_Initialize(AccelInitOption option)
Expand Down Expand Up @@ -221,7 +223,9 @@ void Accel_ReadData(MsgAccelData *accelData )

void ACCEL_IRQHandler(void)
{
gpio_irq_t gpioIrq;
uint32_t currTime = GetCurrentTime();
gpioIrq.irq_index = ACCEL_PINT_CH;
#if 0
uint32_t currTime = g_Timer.GetCurrent();
PhysicalSensor_t* pSens = g_phySensors[PHYS_ACCEL_ID];
Expand All @@ -230,10 +234,10 @@ void ACCEL_IRQHandler(void)

pSens->irq_pending++;

Chip_PININT_ClearIntStatus(LPC_PININT, ACCEL_PINT_CH);
gpio_irq_disable(&gpioIrq);
ResMgr_IRQDone();
#else
Chip_PININT_ClearIntStatus(LPC_PININT, ACCEL_PINT_CH);
gpio_irq_disable(&gpioIrq);
SendDataReadyIndication(ACCEL_INPUT_SENSOR, currTime);
#endif
}
Expand Down
24 changes: 16 additions & 8 deletions embedded/common/modules/sensor-drivers/bmm050.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@
#include "mag_common.h"
#include "osp-sensors.h"
#include "sensacq_i2c.h"
#include "board.h"
#include "gpio_api.h"
#include "gpio_irq_api.h"

static struct bmm050 *p_bmm050;
static struct bmm050 bmm050;
Expand Down Expand Up @@ -126,18 +127,23 @@ static void mag_activate(bool enable)

void Mag_HardwareSetup(osp_bool_t enable)
{
gpio_t hostifIrq;
gpio_irq_t gpioIrq;
NVIC_SetPriority(MAG_PINT_IRQn, SENSOR_IRQ_PRIORITY);
NVIC_DisableIRQ(MAG_PINT_IRQn);

/* MAG INT2 irq setup */
Chip_GPIO_SetPinDIRInput(LPC_GPIO, MAG_INT_PORT, MAG_INT_PIN);
Chip_INMUX_PinIntSel(MAG_PINT_SEL, MAG_INT_PORT, MAG_INT_PIN); /* Configure INMUX block */
Chip_PININT_SetPinModeEdge(LPC_PININT, MAG_PINT_CH);/* edge sensitive and rising edge interrupt */
Chip_PININT_EnableIntHigh(LPC_PININT, MAG_PINT_CH);
hostifIrq.pin = ENCODE_PORT_PIN(MAG_INT_PORT, MAG_INT_PIN);
gpio_dir(&hostifIrq,PIN_INPUT);
gpioIrq.irq_index = MAG_PINT_CH;
gpioIrq.event = IRQ_EDGE_RISE;
gpio_irq_init(&gpioIrq, ENCODE_PORT_PIN(MAG_INT_PORT, MAG_INT_PIN), NULL, MAG_PINT_SEL);

Chip_SYSCON_EnableWakeup(MAG_WAKE); /* enable to wake from sleep */
Chip_SYSCON_EnableWakeup(SYSCON_STARTER_WWDT); /* enable to wake from sleep */

Chip_GPIO_SetPinDIRInput(LPC_GPIO, MAG_INT3_PORT, MAG_INT3_PIN);
hostifIrq.pin = ENCODE_PORT_PIN(MAG_INT3_PORT, MAG_INT3_PIN);
gpio_dir(&hostifIrq,PIN_INPUT);

}

Expand Down Expand Up @@ -222,18 +228,20 @@ void Mag_ReadData(MsgMagData *magData)
}
void MAG_IRQHandler(void)
{
gpio_irq_t gpioIrq;
uint32_t currTime = GetCurrentTime();
gpioIrq.irq_index = MAG_PINT_CH;
#if 0
uint32_t currTime = g_Timer.GetCurrent();
PhysicalSensor_t* pSens = g_phySensors[PHYS_MAG_ID];
pSens->ts_nextSample = currTime + ((pSens->period + (pSens->ts_nextSample - pSens->ts_lastSample)) >> 1) ;
pSens->ts_lastSample = currTime;

pSens->irq_pending++;
Chip_PININT_ClearIntStatus(LPC_PININT, MAG_PINT_CH);
gpio_irq_disable(&gpioIrq);
ResMgr_IRQDone();
#else
Chip_PININT_ClearIntStatus(LPC_PININT, MAG_PINT_CH);
gpio_irq_disable(&gpioIrq);
SendDataReadyIndication(MAG_INPUT_SENSOR, currTime);
#endif
}
Expand Down
47 changes: 47 additions & 0 deletions embedded/projects/osp-lpc54102/Keil/osp-lpc54102.uvoptx
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,53 @@
</File>
</Group>

<Group>
<GroupName>TARGET_LPC54102</GroupName>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>0</RteFlg>
<File>
<GroupNumber>10</GroupNumber>
<FileNumber>36</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<Focus>0</Focus>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\targets\TARGET_LPC54102\gpio_api.c</PathWithFileName>
<FilenameWithoutPath>gpio_api.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>10</GroupNumber>
<FileNumber>37</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<Focus>0</Focus>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\targets\TARGET_LPC54102\gpio_irq_api.c</PathWithFileName>
<FilenameWithoutPath>gpio_irq_api.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>10</GroupNumber>
<FileNumber>38</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<Focus>0</Focus>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\targets\TARGET_LPC54102\pinmap.c</PathWithFileName>
<FilenameWithoutPath>pinmap.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
</Group>

<Group>
<GroupName>::CMSIS</GroupName>
<tvExp>0</tvExp>
Expand Down
22 changes: 21 additions & 1 deletion embedded/projects/osp-lpc54102/Keil/osp-lpc54102.uvprojx
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@
<MiscControls></MiscControls>
<Define>INTERNAL_FLASH,BOARD_NXP_LPCXPRESS0_54102,PWRROMD_PRESENT,__FPU_PRESENT=1,CORE_M4,ANDROID_DEMO,DEBUG_BUILD,DEBUG_OUTPUT,ASF_PROFILING,ON_DEMAND_PROFILING</Define>
<Undefine></Undefine>
<IncludePath>..\..\..\..\include;..\..\..\common\app;..\..\..\common\asf;..\..\..\common\alg;..\sources\app;..\sources\config;..\sources\boardsupport;..\..\..\common\modules\sensor-drivers;..\..\..\common\modules\bus-drivers;..\..\..\..\external\rtos\rtx\inc;..\..\..\..\external\rtos\rtx\cm;..\sources\lpcopen\software\lpc_core\lpc_board\boards_5410x\lpcxpresso_54102;..\sources\lpcopen\software\lpc_core\lpc_chip\chip_5410x;..\sources\lpcopen\software\lpc_core\lpc_chip\chip_common;..\sources\lpcopen\software\lpc_core\lpc_chip\chip_5410x\config;..\sources\lpcopen\software\lpc_core\lpc_board\board_common;..\sources\HostInterface;c:\keil_v5\arm\rv31\inc</IncludePath>
<IncludePath>..\..\..\..\include;..\..\..\common\app;..\..\..\common\asf;..\..\..\common\alg;..\sources\app;..\sources\config;..\sources\boardsupport;..\..\..\common\modules\sensor-drivers;..\..\..\common\modules\bus-drivers;..\..\..\..\external\rtos\rtx\inc;..\..\..\..\external\rtos\rtx\cm;..\sources\lpcopen\software\lpc_core\lpc_board\boards_5410x\lpcxpresso_54102;..\sources\lpcopen\software\lpc_core\lpc_chip\chip_5410x;..\sources\lpcopen\software\lpc_core\lpc_chip\chip_common;..\sources\lpcopen\software\lpc_core\lpc_chip\chip_5410x\config;..\sources\lpcopen\software\lpc_core\lpc_board\board_common;..\sources\HostInterface;..\..\..\..\include\hal;..\..\..\..\targets\TARGET_LPC54102</IncludePath>
</VariousControls>
</Cads>
<Aads>
Expand Down Expand Up @@ -1025,6 +1025,26 @@
</File>
</Files>
</Group>
<Group>
<GroupName>TARGET_LPC54102</GroupName>
<Files>
<File>
<FileName>gpio_api.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\targets\TARGET_LPC54102\gpio_api.c</FilePath>
</File>
<File>
<FileName>gpio_irq_api.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\targets\TARGET_LPC54102\gpio_irq_api.c</FilePath>
</File>
<File>
<FileName>pinmap.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\targets\TARGET_LPC54102\pinmap.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>::CMSIS</GroupName>
<GroupOption>
Expand Down
9 changes: 6 additions & 3 deletions embedded/projects/osp-lpc54102/sources/app/hostif.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@
#define _HOSTIF_H_

#include "spi-sensor-hub-priv.h"
#include "gpio_api.h"

#ifdef __cplusplus
extern "C" {
#endif

extern gpio_t hostifIrq;

/** @defgroup SH_HOSTIF : Sensor hub host interface
* @ingroup SENSOR_HUB
* @{
Expand Down Expand Up @@ -65,7 +68,7 @@ void Hostif_StartTx(uint8_t *pBuf, uint16_t size, int magic);
*/
static INLINE void Hostif_AssertIRQ(void)
{
Chip_GPIO_SetPinState(LPC_GPIO, HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN, 0);
gpio_write(&hostifIrq,0);
}

/**
Expand All @@ -74,7 +77,7 @@ static INLINE void Hostif_AssertIRQ(void)
*/
static INLINE void Hostif_DeassertIRQ(void)
{
Chip_GPIO_SetPinState(LPC_GPIO, HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN, 1);
gpio_write(&hostifIrq,1);
}

/**
Expand All @@ -83,7 +86,7 @@ static INLINE void Hostif_DeassertIRQ(void)
*/
static INLINE bool Hostif_IRQActive(void)
{
return (Chip_GPIO_GetPinState(LPC_GPIO, HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN) == false);
return (gpio_read(&hostifIrq) == false);
}

/**
Expand Down
15 changes: 9 additions & 6 deletions embedded/projects/osp-lpc54102/sources/app/hostif_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
* copyright, permission, and disclaimer notice must appear in all copies of
* this code.
*/
#include "board.h"
#include <string.h>
#include <stdint.h>
#include "sensorhub.h"
#include "hostif.h"
#include "osp-types.h"
#include "common.h"
#include "pinmap.h"
/*****************************************************************************
* Private types/enumerations/variables
****************************************************************************/
Expand All @@ -56,6 +56,9 @@ typedef struct __HOSTIF_Ctrl_t {
uint16_t txLength_next;
} Hostif_Ctrl_t;

/* Host Interface Pin. Making it global since it is used in multiple places */
gpio_t hostifIrq = {ENCODE_PORT_PIN(HOSTIF_IRQ_PORT,HOSTIF_IRQ_PIN)};

static Hostif_Ctrl_t g_hostif;

#define I2C_MEM_SZ 64 /* Size of memory for I2C Slave ROM driver */
Expand Down Expand Up @@ -275,8 +278,8 @@ void Hostif_Init(void)
memset(&g_hostif, 0, sizeof(Hostif_Ctrl_t));

/* Setup I2C pin mux */
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 27, (IOCON_FUNC1 | IOCON_DIGITAL_EN)); /* i2c2 */
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 28, (IOCON_FUNC1 | IOCON_DIGITAL_EN)); /* I2C2 */
pin_function( ENCODE_PORT_PIN((uint8_t)Port_0, (uint8_t)Pin_27), (PINMAP_FUNC1 | PINMAP_DIGITAL_EN));
pin_function( ENCODE_PORT_PIN((uint8_t)Port_0, (uint8_t)Pin_28), (PINMAP_FUNC1 | PINMAP_DIGITAL_EN));

Chip_Clock_EnablePeriphClock(I2C_HOSTIF_CLK);
Chip_SYSCON_PeriphReset(I2C_HOSTIF_RST);
Expand Down Expand Up @@ -320,12 +323,12 @@ void Hostif_Init(void)
ROM_I2CS_Transfer(hI2C, &i2cXfer);

/* init host interrupt pin */
Chip_GPIO_SetPinDIROutput(LPC_GPIO, HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN);
gpio_dir(&hostifIrq,PIN_OUTPUT);

/* de-assert interrupt line to high to indicate Host/AP that
* there is no data to receive
*/
Chip_GPIO_SetPinState(LPC_GPIO, HOSTIF_IRQ_PORT, HOSTIF_IRQ_PIN, 1);
gpio_write(&hostifIrq,1);

/* Enable the interrupt for the I2C */
NVIC_SetPriority(I2C_HOSTIF_IRQn, HOSTIF_IRQ_PRIORITY);
Expand Down
Loading