LPC43: Fix a naming collision with i2c_read

This commit is contained in:
Gregory Nutt 2016-01-28 07:47:32 -06:00
parent 4d2e423cf6
commit 9f2ae5bb86

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* arch/arm/src/lpc43xx/lpc43_i2c.c * arch/arm/src/lpc43xx/lpc43_i2c.c
* *
* Copyright (C) 2012, 2014-2015 Gregory Nutt. All rights reserved. * Copyright (C) 2012, 2014-2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Ported from from the LPC17 version: * Ported from from the LPC17 version:
@ -82,7 +82,7 @@
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
#define I2C_TIMEOUT (20*1000/CONFIG_USEC_PER_TICK) /* 20 mS */ #define I2C_TIMEOUT (20*1000/CONFIG_USEC_PER_TICK) /* 20 mS */
#ifdef CONFIG_LPC43_I2C0_SUPERFAST #ifdef CONFIG_LPC43_I2C0_SUPERFAST
# define I2C0_DEFAULT_FREQUENCY 1000000 # define I2C0_DEFAULT_FREQUENCY 1000000
@ -127,36 +127,36 @@ static struct lpc43_i2cdev_s g_i2c1dev;
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
static int i2c_start(struct lpc43_i2cdev_s *priv); static int lpc43_i2c_start(struct lpc43_i2cdev_s *priv);
static void i2c_stop(struct lpc43_i2cdev_s *priv); static void lpc43_i2c_stop(struct lpc43_i2cdev_s *priv);
static int i2c_interrupt(int irq, FAR void *context); static int lpc43_i2c_interrupt(int irq, FAR void *context);
static void i2c_timeout(int argc, uint32_t arg, ...); static void lpc43_i2c_timeout(int argc, uint32_t arg, ...);
/**************************************************************************** /****************************************************************************
* I2C device operations * I2C device operations
****************************************************************************/ ****************************************************************************/
static uint32_t i2c_setfrequency(FAR struct i2c_dev_s *dev, static uint32_t lpc43_i2c_setfrequency(FAR struct i2c_dev_s *dev,
uint32_t frequency); uint32_t frequency);
static int i2c_setaddress(FAR struct i2c_dev_s *dev, int addr, static int lpc43_i2c_setaddress(FAR struct i2c_dev_s *dev, int addr,
int nbits); int nbits);
static int i2c_write(FAR struct i2c_dev_s *dev, const uint8_t *buffer, static int lpc43_i2c_write(FAR struct i2c_dev_s *dev,
int buflen); const uint8_t *buffer, int buflen);
static int i2c_read(FAR struct i2c_dev_s *dev, uint8_t *buffer, static int lpc43_i2c_read(FAR struct i2c_dev_s *dev, uint8_t *buffer,
int buflen); int buflen);
#ifdef CONFIG_I2C_TRANSFER #ifdef CONFIG_I2C_TRANSFER
static int i2c_transfer(FAR struct i2c_dev_s *dev, static int lpc43_i2c_transfer(FAR struct i2c_dev_s *dev,
FAR struct i2c_msg_s *msgs, int count); FAR struct i2c_msg_s *msgs, int count);
#endif #endif
struct i2c_ops_s lpc43_i2c_ops = struct i2c_ops_s lpc43_i2c_ops =
{ {
.setfrequency = i2c_setfrequency, .setfrequency = lpc43_i2c_setfrequency,
.setaddress = i2c_setaddress, .setaddress = lpc43_i2c_setaddress,
.write = i2c_write, .write = lpc43_i2c_write,
.read = i2c_read, .read = lpc43_i2c_read,
#ifdef CONFIG_I2C_TRANSFER #ifdef CONFIG_I2C_TRANSFER
.transfer = i2c_transfer .transfer = lpc43_i2c_transfer
#endif #endif
}; };
@ -167,7 +167,9 @@ struct i2c_ops_s lpc43_i2c_ops =
* Set the frequence for the next transfer * Set the frequence for the next transfer
* *
****************************************************************************/ ****************************************************************************/
static uint32_t i2c_setfrequency(FAR struct i2c_dev_s *dev, uint32_t frequency)
static uint32_t lpc43_i2c_setfrequency(FAR struct i2c_dev_s *dev,
uint32_t frequency)
{ {
struct lpc43_i2cdev_s *priv = (struct lpc43_i2cdev_s *) dev; struct lpc43_i2cdev_s *priv = (struct lpc43_i2cdev_s *) dev;
@ -175,15 +177,19 @@ static uint32_t i2c_setfrequency(FAR struct i2c_dev_s *dev, uint32_t frequency)
{ {
/* asymetric per 400Khz I2C spec */ /* asymetric per 400Khz I2C spec */
putreg32(priv->baseFreq / (83 + 47) * 47 / frequency, priv->base + LPC43_I2C_SCLH_OFFSET); putreg32(priv->baseFreq / (83 + 47) * 47 / frequency, priv->base +
putreg32(priv->baseFreq / (83 + 47) * 83 / frequency, priv->base + LPC43_I2C_SCLL_OFFSET); LPC43_I2C_SCLH_OFFSET);
putreg32(priv->baseFreq / (83 + 47) * 83 / frequency, priv->base +
LPC43_I2C_SCLL_OFFSET);
} }
else else
{ {
/* 50/50 mark space ratio */ /* 50/50 mark space ratio */
putreg32(priv->baseFreq / 100 * 50 / frequency, priv->base + LPC43_I2C_SCLH_OFFSET); putreg32(priv->baseFreq / 100 * 50 / frequency, priv->base +
putreg32(priv->baseFreq / 100 * 50 / frequency, priv->base + LPC43_I2C_SCLL_OFFSET); LPC43_I2C_SCLH_OFFSET);
putreg32(priv->baseFreq / 100 * 50 / frequency, priv->base +
LPC43_I2C_SCLL_OFFSET);
} }
/* FIXME: This function should return the actual selected frequency */ /* FIXME: This function should return the actual selected frequency */
@ -199,7 +205,8 @@ static uint32_t i2c_setfrequency(FAR struct i2c_dev_s *dev, uint32_t frequency)
* *
****************************************************************************/ ****************************************************************************/
static int i2c_setaddress(FAR struct i2c_dev_s *dev, int addr, int nbits) static int lpc43_i2c_setaddress(FAR struct i2c_dev_s *dev, int addr,
int nbits)
{ {
struct lpc43_i2cdev_s *priv = (struct lpc43_i2cdev_s *)dev; struct lpc43_i2cdev_s *priv = (struct lpc43_i2cdev_s *)dev;
@ -220,8 +227,8 @@ static int i2c_setaddress(FAR struct i2c_dev_s *dev, int addr, int nbits)
* *
****************************************************************************/ ****************************************************************************/
static int i2c_write(FAR struct i2c_dev_s *dev, const uint8_t *buffer, static int lpc43_i2c_write(FAR struct i2c_dev_s *dev, const uint8_t *buffer,
int buflen) int buflen)
{ {
struct lpc43_i2cdev_s *priv = (struct lpc43_i2cdev_s *)dev; struct lpc43_i2cdev_s *priv = (struct lpc43_i2cdev_s *)dev;
int ret = 0; int ret = 0;
@ -239,7 +246,7 @@ static int i2c_write(FAR struct i2c_dev_s *dev, const uint8_t *buffer,
if (buflen > 0) if (buflen > 0)
{ {
ret = i2c_start(priv); ret = lpc43_i2c_start(priv);
} }
return (ret == 0 ? 0 : -ETIMEDOUT); return (ret == 0 ? 0 : -ETIMEDOUT);
@ -254,7 +261,8 @@ static int i2c_write(FAR struct i2c_dev_s *dev, const uint8_t *buffer,
* *
****************************************************************************/ ****************************************************************************/
static int i2c_read(FAR struct i2c_dev_s *dev, uint8_t *buffer, int buflen) static int lpc43_i2c_read(FAR struct i2c_dev_s *dev, uint8_t *buffer,
int buflen)
{ {
struct lpc43_i2cdev_s *priv = (struct lpc43_i2cdev_s *)dev; struct lpc43_i2cdev_s *priv = (struct lpc43_i2cdev_s *)dev;
int ret = 0; int ret = 0;
@ -272,30 +280,31 @@ static int i2c_read(FAR struct i2c_dev_s *dev, uint8_t *buffer, int buflen)
if (buflen > 0) if (buflen > 0)
{ {
ret = i2c_start(priv); ret = lpc43_i2c_start(priv);
} }
return (ret == 0 ? 0 : -ETIMEDOUT); return (ret == 0 ? 0 : -ETIMEDOUT);
} }
/**************************************************************************** /****************************************************************************
* Name: i2c_start * Name: lpc43_i2c_start
* *
* Description: * Description:
* Perform a I2C transfer start * Perform a I2C transfer start
* *
****************************************************************************/ ****************************************************************************/
static int i2c_start(struct lpc43_i2cdev_s *priv) static int lpc43_i2c_start(struct lpc43_i2cdev_s *priv)
{ {
int ret = -1; int ret = -1;
sem_wait(&priv->mutex); sem_wait(&priv->mutex);
putreg32(I2C_CONCLR_STAC | I2C_CONCLR_SIC, priv->base + LPC43_I2C_CONCLR_OFFSET); putreg32(I2C_CONCLR_STAC | I2C_CONCLR_SIC,
priv->base + LPC43_I2C_CONCLR_OFFSET);
putreg32(I2C_CONSET_STA, priv->base + LPC43_I2C_CONSET_OFFSET); putreg32(I2C_CONSET_STA, priv->base + LPC43_I2C_CONSET_OFFSET);
wd_start(priv->timeout, I2C_TIMEOUT, i2c_timeout, 1, (uint32_t)priv); wd_start(priv->timeout, I2C_TIMEOUT, lpc43_i2c_timeout, 1, (uint32_t)priv);
sem_wait(&priv->wait); sem_wait(&priv->wait);
wd_cancel(priv->timeout); wd_cancel(priv->timeout);
@ -308,32 +317,33 @@ static int i2c_start(struct lpc43_i2cdev_s *priv)
} }
/**************************************************************************** /****************************************************************************
* Name: i2c_stop * Name: lpc43_i2c_stop
* *
* Description: * Description:
* Perform a I2C transfer stop * Perform a I2C transfer stop
* *
****************************************************************************/ ****************************************************************************/
static void i2c_stop(struct lpc43_i2cdev_s *priv) static void lpc43_i2c_stop(struct lpc43_i2cdev_s *priv)
{ {
if (priv->state != 0x38) if (priv->state != 0x38)
{ {
putreg32(I2C_CONSET_STO | I2C_CONSET_AA, priv->base + LPC43_I2C_CONSET_OFFSET); putreg32(I2C_CONSET_STO | I2C_CONSET_AA,
priv->base + LPC43_I2C_CONSET_OFFSET);
} }
sem_post(&priv->wait); sem_post(&priv->wait);
} }
/**************************************************************************** /****************************************************************************
* Name: i2c_timeout * Name: lpc43_i2c_timeout
* *
* Description: * Description:
* Watchdog timer for timeout of I2C operation * Watchdog timer for timeout of I2C operation
* *
****************************************************************************/ ****************************************************************************/
static void i2c_timeout(int argc, uint32_t arg, ...) static void lpc43_i2c_timeout(int argc, uint32_t arg, ...)
{ {
struct lpc43_i2cdev_s *priv = (struct lpc43_i2cdev_s *)arg; struct lpc43_i2cdev_s *priv = (struct lpc43_i2cdev_s *)arg;
@ -344,14 +354,15 @@ static void i2c_timeout(int argc, uint32_t arg, ...)
} }
/**************************************************************************** /****************************************************************************
* Name: i2c_transfer * Name: lpc43_i2c_transfer
* *
* Description: * Description:
* Perform a sequence of I2C transfers * Perform a sequence of I2C transfers
* *
****************************************************************************/ ****************************************************************************/
static int i2c_transfer(FAR struct i2c_dev_s *dev, FAR struct i2c_msg_s *msgs, int count) static int lpc43_i2c_transfer(FAR struct i2c_dev_s *dev,
FAR struct i2c_msg_s *msgs, int count)
{ {
struct lpc43_i2cdev_s *priv = (struct lpc43_i2cdev_s *)dev; struct lpc43_i2cdev_s *priv = (struct lpc43_i2cdev_s *)dev;
int ret; int ret;
@ -363,7 +374,7 @@ static int i2c_transfer(FAR struct i2c_dev_s *dev, FAR struct i2c_msg_s *msgs, i
priv->msgs = msgs; priv->msgs = msgs;
priv->nmsg = count; priv->nmsg = count;
ret = i2c_start(priv); ret = lpc43_i2c_start(priv);
return ret; return ret;
} }
@ -379,19 +390,19 @@ void startStopNextMessage(struct lpc43_i2cdev_s *priv)
} }
else else
{ {
i2c_stop(priv); lpc43_i2c_stop(priv);
} }
} }
/**************************************************************************** /****************************************************************************
* Name: i2c_interrupt * Name: lpc43_i2c_interrupt
* *
* Description: * Description:
* The I2C Interrupt Handler * The I2C Interrupt Handler
* *
****************************************************************************/ ****************************************************************************/
static int i2c_interrupt(int irq, FAR void *context) static int lpc43_i2c_interrupt(int irq, FAR void *context)
{ {
struct lpc43_i2cdev_s *priv; struct lpc43_i2cdev_s *priv;
struct i2c_msg_s *msg; struct i2c_msg_s *msg;
@ -488,7 +499,7 @@ static int i2c_interrupt(int irq, FAR void *context)
break; break;
default: default:
i2c_stop(priv); lpc43_i2c_stop(priv);
break; break;
} }
@ -551,7 +562,8 @@ struct i2c_dev_s *up_i2cinitialize(int port)
regval |= CCU_CLK_CFG_RUN; regval |= CCU_CLK_CFG_RUN;
putreg32(regval, LPC43_CCU1_APB1_I2C0_CFG); putreg32(regval, LPC43_CCU1_APB1_I2C0_CFG);
i2c_setfrequency((struct i2c_dev_s *)priv, I2C0_DEFAULT_FREQUENCY); lpc43_i2c_setfrequency((struct i2c_dev_s *)priv,
I2C0_DEFAULT_FREQUENCY);
/* No pin configuration needed */ /* No pin configuration needed */
} }
@ -578,7 +590,7 @@ struct i2c_dev_s *up_i2cinitialize(int port)
lpc43_pin_config(PINCONF_I2C1_SCL); lpc43_pin_config(PINCONF_I2C1_SCL);
lpc43_pin_config(PINCONF_I2C1_SDA); lpc43_pin_config(PINCONF_I2C1_SDA);
i2c_setfrequency(priv, I2C1_DEFAULT_FREQUENCY); lpc43_i2c_setfrequency(priv, I2C1_DEFAULT_FREQUENCY);
} }
else else
#endif #endif
@ -600,7 +612,7 @@ struct i2c_dev_s *up_i2cinitialize(int port)
/* Attach Interrupt Handler */ /* Attach Interrupt Handler */
irq_attach(priv->irqid, i2c_interrupt); irq_attach(priv->irqid, lpc43_i2c_interrupt);
/* Enable Interrupt Handler */ /* Enable Interrupt Handler */
@ -630,13 +642,13 @@ int up_i2cuninitialize(FAR struct i2c_dev_s * dev)
return OK; return OK;
} }
/************************************************************************************ /****************************************************************************
* Name: up_i2creset * Name: up_i2creset
* *
* Description: * Description:
* Reset an I2C bus * Reset an I2C bus
* *
************************************************************************************/ ****************************************************************************/
#ifdef CONFIG_I2C_RESET #ifdef CONFIG_I2C_RESET
int up_i2creset(FAR struct i2c_dev_s * dev) int up_i2creset(FAR struct i2c_dev_s * dev)