summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-01-23 18:37:45 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-01-23 18:37:45 +0000
commitef82d9a26df8c1abfb0ab0cf36d194c597a5dda7 (patch)
treeea48b73e1893927467230bd559eeeae840e5c6b9
parent14bc61cb16e67bd247cef620e42500cc2c19bcd5 (diff)
downloadpx4-nuttx-ef82d9a26df8c1abfb0ab0cf36d194c597a5dda7.tar.gz
px4-nuttx-ef82d9a26df8c1abfb0ab0cf36d194c597a5dda7.tar.bz2
px4-nuttx-ef82d9a26df8c1abfb0ab0cf36d194c597a5dda7.zip
Fixes for clean compile of battery drivers
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4325 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r--nuttx/drivers/power/battery.c18
-rw-r--r--nuttx/drivers/power/max1704x.c43
-rw-r--r--nuttx/include/nuttx/power/battery.h17
3 files changed, 54 insertions, 24 deletions
diff --git a/nuttx/drivers/power/battery.c b/nuttx/drivers/power/battery.c
index ce9397408..70337b5cb 100644
--- a/nuttx/drivers/power/battery.c
+++ b/nuttx/drivers/power/battery.c
@@ -40,10 +40,12 @@
#include <nuttx/config.h>
-#include <sempaphore.h>
+#include <stdbool.h>
+#include <semaphore.h>
#include <errno.h>
#include <debug.h>
+#include <nuttx/fs.h>
#include <nuttx/power/battery.h>
/* This driver requires:
@@ -69,7 +71,7 @@
static int bat_open(FAR struct file *filep);
static int bat_close(FAR struct file *filep);
-static ssize_t bat_read(FAR struct file *, FAR char *, size_t);
+static ssize_t bat_read(FAR struct file *, FAR char *, size_t nbytes);
static ssize_t bat_write(FAR struct file *filep, FAR const char *buffer, size_t buflen);
static int bat_ioctl(FAR struct file *filep,int cmd,unsigned long arg);
@@ -77,7 +79,7 @@ static int bat_ioctl(FAR struct file *filep,int cmd,unsigned long arg);
* Private Data
****************************************************************************/
-static const struct file_operations_s g_batteryops =
+static const struct file_operations g_batteryops =
{
bat_open,
bat_close,
@@ -167,7 +169,7 @@ static int bat_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
{
case BATIOC_STATE:
{
- FAR int *ptr = (FAR int *)((uintptr_t)arg));
+ FAR int *ptr = (FAR int *)((uintptr_t)arg);
if (ptr)
{
ret = dev->ops->state(dev, ptr);
@@ -176,16 +178,18 @@ static int bat_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
break;
case BATIOC_ONLINE:
- FAR bool *ptr = (FAR bool *)((uintptr_t)arg));
+ {
+ FAR bool *ptr = (FAR bool *)((uintptr_t)arg);
if (ptr)
{
ret = dev->ops->online(dev, ptr);
}
+ }
break;
case BATIOC_VOLTAGE:
{
- FAR b16_t *ptr = (FAR b16_t *)((uintptr_t)arg));
+ FAR b16_t *ptr = (FAR b16_t *)((uintptr_t)arg);
if (ptr)
{
ret = dev->ops->voltage(dev, ptr);
@@ -195,7 +199,7 @@ static int bat_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
case BATIOC_CAPACITY:
{
- FAR b16_t *ptr = (FAR b16_t *)((uintptr_t)arg));
+ FAR b16_t *ptr = (FAR b16_t *)((uintptr_t)arg);
if (ptr)
{
ret = dev->ops->capacity(dev, ptr);
diff --git a/nuttx/drivers/power/max1704x.c b/nuttx/drivers/power/max1704x.c
index 58f48aaa3..b74590737 100644
--- a/nuttx/drivers/power/max1704x.c
+++ b/nuttx/drivers/power/max1704x.c
@@ -46,9 +46,15 @@
#include <nuttx/config.h>
+#include <sys/types.h>
+
+#include <stdint.h>
+#include <stdbool.h>
#include <errno.h>
#include <debug.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/i2c.h>
#include <nuttx/power/battery.h>
/* This driver requires:
@@ -63,6 +69,16 @@
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
+/* Configuration ************************************************************/
+/* CONFIG_I2C_MAX17040 or CONFIG_I2C_MAX17041 - The driver must know which
+ * chip is on the board in order to scale the voltage correctly.
+ */
+
+#if !defined(CONFIG_I2C_MAX17040) && !defined(CONFIG_I2C_MAX17041)
+# warning "Assuming CONFIG_I2C_MAX17040"
+# define CONFIG_I2C_MAX17040 1
+#endif
+
/* MAX1704x Register Definitions ********************************************/
/* "All host interaction with the MAX17040/MAX17041 is handled by writing to
* and reading from register locations. The MAX17040/MAX17041 have six 16-bit
@@ -85,6 +101,12 @@
#define MAX14701_VCELL_CONV 163 /* 0.0025 v * 65536 */
#define MAX14071_VCELL(v) ((b16_t)(v) * MAX14701_VCELL_CONV)
+#ifdef CONFIG_I2C_MAX17040
+# define MAX1407X_VCELL(v) MAX14070_VCELL(v)
+#else
+# define MAX1407X_VCELL(v) MAX14071_VCELL(v)
+#endif
+
/* "SOC Register. The SOC register is a read-only register that displays the
* state of charge of the cell as calculated by the ModelGauge algorithm. The
* result is displayed as a percentage of the cell’s full capacity...
@@ -98,7 +120,7 @@
/* SoC conversion macros */
-#define MAX1407X_SOC(s) ((b16_t)MAX1407X_SOCB8(s) << 8)
+#define MAX1407X_SOC(s) ((b16_t)(s) << 8)
#define MAX17040_SOC_FULL itob16(95) /* We say full if Soc >= 95% */
/* "MODE Register.The MODE register allows the host processor to send special
@@ -169,7 +191,7 @@ struct max1704x_dev_s
****************************************************************************/
/* I2C support */
-static int max1704x_getreg16(FAR struct max1704x_dev_s *priv, uint8_t regaddr)
+static int max1704x_getreg16(FAR struct max1704x_dev_s *priv, uint8_t regaddr,
FAR uint16_t *regval);
static int max1704x_putreg16(FAR struct max1704x_dev_s *priv, uint8_t regaddr,
uint16_t regval);
@@ -217,7 +239,7 @@ static const struct battery_operations_s g_max1704xops =
*
****************************************************************************/
-static int max1704x_getreg16(FAR struct max1704x_dev_s *priv, uint8_t regaddr)
+static int max1704x_getreg16(FAR struct max1704x_dev_s *priv, uint8_t regaddr,
FAR uint16_t *regval)
{
uint8_t buffer[2];
@@ -262,7 +284,6 @@ static int max1704x_putreg16(FAR struct max1704x_dev_s *priv, uint8_t regaddr,
uint16_t regval)
{
uint8_t buffer[3];
- b8_t regb8;
batdbg("addr: %02x regval: %08x\n", regaddr, regval);
@@ -295,7 +316,7 @@ static inline int max1704x_getvcell(FAR struct max1704x_dev_s *priv,
ret = max1704x_getreg16(priv, MAX1407X_VCELL_ADDR, &regval);
if (ret == OK)
{
- *vcell = MAX14070_VCELL(regval);
+ *vcell = MAX1407X_VCELL(regval);
}
return ret;
}
@@ -386,7 +407,7 @@ static inline int max1704x_reset(FAR struct max1704x_dev_s *priv)
static int max1704x_state(struct battery_dev_s *dev, int *status)
{
FAR struct max1704x_dev_s *priv = (FAR struct max1704x_dev_s *)dev;
- b16_t soc;
+ b16_t soc = 0;
int ret;
/* Only a few of the possible battery states are supported by this driver:
@@ -427,11 +448,11 @@ static int max1704x_state(struct battery_dev_s *dev, int *status)
*
****************************************************************************/
-static int max1704x_online(struct battery_dev_s *dev, bool *status);
+static int max1704x_online(struct battery_dev_s *dev, bool *status)
{
/* There is no concept of online/offline in this driver */
- *status = true
+ *status = true;
return OK;
}
@@ -443,7 +464,7 @@ static int max1704x_online(struct battery_dev_s *dev, bool *status);
*
****************************************************************************/
-static int max1704x_voltage(struct battery_dev_s *dev, b16_t *value);
+static int max1704x_voltage(struct battery_dev_s *dev, b16_t *value)
{
FAR struct max1704x_dev_s *priv = (FAR struct max1704x_dev_s *)dev;
return max1704x_getvcell(priv, value);
@@ -457,7 +478,7 @@ static int max1704x_voltage(struct battery_dev_s *dev, b16_t *value);
*
****************************************************************************/
-static int max1704x_capacity(struct battery_dev_s *dev, b16_t *value);
+static int max1704x_capacity(struct battery_dev_s *dev, b16_t *value)
{
FAR struct max1704x_dev_s *priv = (FAR struct max1704x_dev_s *)dev;
return max1704x_getsoc(priv, value);
@@ -479,6 +500,8 @@ static int max1704x_capacity(struct battery_dev_s *dev, b16_t *value);
* CONFIG_BATTERY - Upper half battery driver support
* CONFIG_I2C - I2C support
* CONFIG_I2C_MAX1704X - And the driver must be explictly selected.
+ * CONFIG_I2C_MAX17040 or CONFIG_I2C_MAX17041 - The driver must know which
+ * chip is on the board in order to scale the voltage correctly.
*
* Input Parameters:
* i2c - An instance of the I2C interface to use to communicate with the MAX1704x
diff --git a/nuttx/include/nuttx/power/battery.h b/nuttx/include/nuttx/power/battery.h
index b1a06fd62..b98d6379e 100644
--- a/nuttx/include/nuttx/power/battery.h
+++ b/nuttx/include/nuttx/power/battery.h
@@ -44,6 +44,7 @@
#include <nuttx/config.h>
#include <nuttx/ioctl.h>
+#include <stdbool.h>
#include <semaphore.h>
#include <fixedmath.h>
@@ -85,9 +86,9 @@
*/
#define BATIOC_STATE _BATIOC(0x0001)
-#define BATIOC_ONLINE _BATIOC(0x0001)
-#define BATIOC_VOLTAGE _BATIOC(0x0001)
-#define BATIOC_CAPACITY _BATIOC(0x0001)
+#define BATIOC_ONLINE _BATIOC(0x0002)
+#define BATIOC_VOLTAGE _BATIOC(0x0003)
+#define BATIOC_CAPACITY _BATIOC(0x0004)
/****************************************************************************
* Public Types
@@ -110,19 +111,19 @@ struct battery_operations_s
{
/* Return the current battery state (see enum battery_status_e) */
- int state(struct battery_dev_s *dev, int *status);
+ int (*state)(struct battery_dev_s *dev, int *status);
/* Return true if the batter is online */
- int online(struct battery_dev_s *dev, bool *status);
+ int (*online)(struct battery_dev_s *dev, bool *status);
/* Current battery voltage */
- int voltage(struct battery_dev_s *dev, b16_t *value);
+ int (*voltage)(struct battery_dev_s *dev, b16_t *value);
/* Battery capacity */
- int capacity(struct battery_dev_s *dev, b16_t *value);
+ int (*capacity)(struct battery_dev_s *dev, b16_t *value);
};
/* This structure defines the battery driver state structure */
@@ -185,6 +186,8 @@ EXTERN int battery_register(FAR const char *devpath,
* CONFIG_BATTERY - Upper half battery driver support
* CONFIG_I2C - I2C support
* CONFIG_I2C_MAX1704X - And the driver must be explictly selected.
+ * CONFIG_I2C_MAX17040 or CONFIG_I2C_MAX17041 - The driver must know which
+ * chip is on the board in order to scale the voltage correctly.
*
* Input Parameters:
* i2c - An instance of the I2C interface to use to communicate with the MAX1704x