diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index c2ad02c0c..9d8545fb2 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -2386,4 +2386,9 @@ CAN IDs. * arch/arm/src/lpc17xx/lpc17_can.c: Add support for extended (29-bit) CAN IDs. * arch/arm/src/stm32/stm32_can.c: Add support for extended (29-bit) CAN IDs. + * include/nuttx/power/pm.h: Move include/nuttx/pm.h into a sub-directory named + power. + * drivers/power: Rename the drivers/pm directory to power + * drivers/power/max1704x.c: Add a skeleton file that will eventually become + the MAX17040x battery driver. diff --git a/nuttx/Documentation/NuttxPortingGuide.html b/nuttx/Documentation/NuttxPortingGuide.html index 7ef4e522a..62f5d1d11 100644 --- a/nuttx/Documentation/NuttxPortingGuide.html +++ b/nuttx/Documentation/NuttxPortingGuide.html @@ -3331,18 +3331,18 @@ extern void up_ledoff(int led); SLEEP (some MCUs may even require going through reset).

- These various states are represented with type enum pm_state_e in include/nuttx/pm.h. + These various states are represented with type enum pm_state_e in include/nuttx/power/pm.h.

6.4.2 Interfaces

- All PM interfaces are declared in the file include/nuttx/pm.h. + All PM interfaces are declared in the file include/nuttx/power/pm.h.

6.4.2.1 pm_initialize()

Function Prototype:

Description: @@ -3359,7 +3359,7 @@ None

6.4.2.2 pm_register()

Function Prototype:

Description: @@ -3379,7 +3379,7 @@ Zero (OK) on success; otherwise a negater errno value

6.4.2.3 pm_activity()

Function Prototype:

Description: @@ -3406,7 +3406,7 @@ void pm_activity(int priority);

6.4.2.4 pm_checkstate()

Function Prototype:

Description: @@ -3433,7 +3433,7 @@ enum pm_state_e pm_checkstate(void);

6.4.2.5 pm_changestate()

Function Prototype:

Description: @@ -3461,7 +3461,7 @@ enum pm_state_e pm_checkstate(void);

6.4.3 Callbacks

The struct pm_callback_s includes the pointers to the driver callback functions. - This structure is defined include/nuttx/pm.h. + This structure is defined include/nuttx/power/pm.h. These callback functions can be used to provide power management information to the driver.

@@ -3496,7 +3496,7 @@ int (*prepare)(FAR struct pm_callback_s *cb, enum pm_state_e pmstate);

6.4.3.1 notify()

Function Prototype:

Description: diff --git a/nuttx/arch/arm/src/stm32/stm32_idle.c b/nuttx/arch/arm/src/stm32/stm32_idle.c index ec78861c8..b5fd9fcb3 100644 --- a/nuttx/arch/arm/src/stm32/stm32_idle.c +++ b/nuttx/arch/arm/src/stm32/stm32_idle.c @@ -41,7 +41,7 @@ #include #include -#include +#include #include diff --git a/nuttx/arch/sim/src/up_head.c b/nuttx/arch/sim/src/up_head.c index 431d417de..7326e73dc 100644 --- a/nuttx/arch/sim/src/up_head.c +++ b/nuttx/arch/sim/src/up_head.c @@ -1,8 +1,8 @@ /**************************************************************************** * up_head.c * - * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Copyright (C) 2007-2009, 2011-2112 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -47,7 +47,7 @@ #include #include -#include +#include /**************************************************************************** * Private Data diff --git a/nuttx/arch/sim/src/up_idle.c b/nuttx/arch/sim/src/up_idle.c index d7397ba22..c66b3b770 100644 --- a/nuttx/arch/sim/src/up_idle.c +++ b/nuttx/arch/sim/src/up_idle.c @@ -1,8 +1,8 @@ /**************************************************************************** * up_idle.c * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -42,7 +42,7 @@ #include #include -#include +#include #include "up_internal.h" diff --git a/nuttx/drivers/Makefile b/nuttx/drivers/Makefile index 4254acac0..9d804871e 100644 --- a/nuttx/drivers/Makefile +++ b/nuttx/drivers/Makefile @@ -1,7 +1,7 @@ ############################################################################ # drivers/Makefile # -# Copyright (C) 2007-2011 Gregory Nutt. All rights reserved. +# Copyright (C) 2007-2012 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -56,7 +56,7 @@ include mmcsd/Make.defs include mtd/Make.defs include net/Make.defs include pipes/Make.defs -include pm/Make.defs +include power/Make.defs include sensors/Make.defs include serial/Make.defs include usbdev/Make.defs diff --git a/nuttx/drivers/pm/Make.defs b/nuttx/drivers/power/Make.defs similarity index 86% rename from nuttx/drivers/pm/Make.defs rename to nuttx/drivers/power/Make.defs index 6204973f5..91102c1e9 100644 --- a/nuttx/drivers/pm/Make.defs +++ b/nuttx/drivers/power/Make.defs @@ -1,8 +1,8 @@ ############################################################################ -# drivers/pm/Make.defs +# drivers/power/Make.defs # -# Copyright (C) 2011 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -41,10 +41,18 @@ ifeq ($(CONFIG_PM),y) CSRCS += pm_activity.c pm_changestate.c pm_checkstate.c pm_initialize.c pm_register.c pm_update.c -# Include power management in the build +# Add I2C devices -DEPPATH += --dep-path pm -VPATH += :pm -CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/drivers/pm} +ifeq ($(CONFIG_I2C),y) +ifeq ($(CONFIG_I2C_MAX1704X),y) +CSRCS += max1704x.c +endif +endif + +# Include power management in the build + +DEPPATH += --dep-path power +VPATH += :power +CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/drivers/power} endif diff --git a/nuttx/drivers/power/max1704x.c b/nuttx/drivers/power/max1704x.c new file mode 100644 index 000000000..bba53478a --- /dev/null +++ b/nuttx/drivers/power/max1704x.c @@ -0,0 +1,208 @@ +/**************************************************************************** + * drivers/power/max1704x.c + * Character driver for the STMicroMAX1704x Temperature Sensor + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#if defined(CONFIG_I2C) && defined(CONFIG_I2C_MAX1704X) + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private + ****************************************************************************/ + +struct max1704x_dev_s +{ + FAR struct i2c_dev_s *i2c; /* I2C interface */ + uint8_t addr; /* I2C address */ +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ +/* I2C Helpers */ + +/* Character driver methods */ + +static int max1704x_open(FAR struct file *filep); +static int max1704x_close(FAR struct file *filep); +static ssize_t max1704x_read(FAR struct file *, FAR char *, size_t); +static ssize_t max1704x_write(FAR struct file *filep, FAR const char *buffer, size_t buflen); +static int max1704x_ioctl(FAR struct file *filep,int cmd,unsigned long arg); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct file_operations g_max1704xfopg = +{ + max1704x_open, + max1704x_close, + max1704x_read, + max1704x_write, + 0, + max1704x_ioctl +#ifndef CONFIG_DISABLE_POLL + , 0 +#endif +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ +/**************************************************************************** + * Name: max1704x_open + * + * Description: + * This function is called whenever theMAX1704x device is opened. + * + ****************************************************************************/ + +static int max1704x_open(FAR struct file *filep) +{ + return OK; +} + +/**************************************************************************** + * Name: max1704x_close + * + * Description: + * This routine is called when theMAX1704x device is closed. + * + ****************************************************************************/ + +static int max1704x_close(FAR struct file *filep) +{ + return OK; +} + +/**************************************************************************** + * Name: max1704x_read + ****************************************************************************/ + +static ssize_t max1704x_read(FAR struct file *filep, FAR char *buffer, size_t buflen) +{ + retrun 0; +} + +/**************************************************************************** + * Name: max1704x_write + ****************************************************************************/ + +static ssize_t max1704x_write(FAR struct file *filep, FAR const char *buffer, + size_t buflen) +{ + return -EACCESS; +} + +/**************************************************************************** + * Name: max1704x_ioctl + ****************************************************************************/ + +static int max1704x_ioctl(FAR struct file *filep, int cmd, unsigned long arg) +{ + FAR struct inode *inode = filep->f_inode; + FAR struct max1704x_dev_s *priv = inode->i_private; + int ret = OK; + + switch (cmd) + { + default: + i2cdbg("Unrecognized cmd: %d\n", cmd); + ret = -ENOTTY; + break; + } + + return ret; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: max1704x_register + * + * Description: + * Register theMAX1704x character device as 'devpath' + * + * Input Parameters: + * devpath - The full path to the driver to register. E.g., "/dev/temp0" + * i2c - An instance of the I2C interface to use to communicate with the MAX1704x + * addr - The I2C address of the MAX1704x. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int max1704x_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, uint8_t addr) +{ + FAR struct max1704x_dev_s *priv; + int ret; + + /* Initialize theMAX1704x device structure */ + + priv = (FAR struct max1704x_dev_s *)kzalloc(sizeof(struct max1704x_dev_s)); + if (!priv) + { + i2cdbg("Failed to allocate instance\n"); + return -ENOMEM; + } + + priv->i2c = i2c; + priv->addr = addr; + + /* Register the character driver */ + + ret = register_driver(devpath, &g_max1704xfopg, 0555, priv); + if (ret < 0) + { + i2cdbg("Failed to register driver: %d\n", ret); + free(priv); + } + return ret; +} +#endif /* CONFIG_I2C && CONFIG_I2C_MAX1704X */ diff --git a/nuttx/drivers/pm/pm_activity.c b/nuttx/drivers/power/pm_activity.c similarity index 97% rename from nuttx/drivers/pm/pm_activity.c rename to nuttx/drivers/power/pm_activity.c index dd908b949..8cef46684 100644 --- a/nuttx/drivers/pm/pm_activity.c +++ b/nuttx/drivers/power/pm_activity.c @@ -1,7 +1,7 @@ /**************************************************************************** - * drivers/pm/pm_activity.c + * drivers/power/pm_activity.c * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -39,7 +39,7 @@ #include -#include +#include #include #include diff --git a/nuttx/drivers/pm/pm_changestate.c b/nuttx/drivers/power/pm_changestate.c similarity index 97% rename from nuttx/drivers/pm/pm_changestate.c rename to nuttx/drivers/power/pm_changestate.c index 50fa0640f..27d17ce88 100644 --- a/nuttx/drivers/pm/pm_changestate.c +++ b/nuttx/drivers/power/pm_changestate.c @@ -1,8 +1,8 @@ /**************************************************************************** - * drivers/pm/pm_changestate.c + * drivers/power/pm_changestate.c * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -39,7 +39,7 @@ #include -#include +#include #include #include "pm_internal.h" diff --git a/nuttx/drivers/pm/pm_checkstate.c b/nuttx/drivers/power/pm_checkstate.c similarity index 97% rename from nuttx/drivers/pm/pm_checkstate.c rename to nuttx/drivers/power/pm_checkstate.c index 9ecff862e..9b0e1045e 100644 --- a/nuttx/drivers/pm/pm_checkstate.c +++ b/nuttx/drivers/power/pm_checkstate.c @@ -1,8 +1,8 @@ /**************************************************************************** - * drivers/pm/pm_checkstate.c + * drivers/power/pm_checkstate.c * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -39,7 +39,7 @@ #include -#include +#include #include #include diff --git a/nuttx/drivers/pm/pm_initialize.c b/nuttx/drivers/power/pm_initialize.c similarity index 95% rename from nuttx/drivers/pm/pm_initialize.c rename to nuttx/drivers/power/pm_initialize.c index 70cd8d7e6..9401fba9e 100644 --- a/nuttx/drivers/pm/pm_initialize.c +++ b/nuttx/drivers/power/pm_initialize.c @@ -1,8 +1,8 @@ /**************************************************************************** - * drivers/pm/pm_initialize.c + * drivers/power/pm_initialize.c * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -41,7 +41,7 @@ #include -#include +#include #include "pm_internal.h" diff --git a/nuttx/drivers/pm/pm_internal.h b/nuttx/drivers/power/pm_internal.h similarity index 95% rename from nuttx/drivers/pm/pm_internal.h rename to nuttx/drivers/power/pm_internal.h index b3e610ba0..0ae4722da 100644 --- a/nuttx/drivers/pm/pm_internal.h +++ b/nuttx/drivers/power/pm_internal.h @@ -1,8 +1,8 @@ /**************************************************************************** - * drivers/pm/pm_internal.h + * drivers/power/pm_internal.h * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __DRIVERS_PM_PM_INTERNAL_H -#define __DRIVERS_PM_PM_INTERNAL_H +#ifndef __DRIVERS_POWER_PM_INTERNAL_H +#define __DRIVERS_POWER_PM_INTERNAL_H /**************************************************************************** * Included Files @@ -45,7 +45,7 @@ #include #include -#include +#include #include #ifdef CONFIG_PM @@ -207,4 +207,4 @@ EXTERN void pm_update(int16_t accum); #endif #endif /* CONFIG_PM */ -#endif /* #define __DRIVERS_PM_PM_INTERNAL_H */ +#endif /* #define __DRIVERS_POWER_PM_INTERNAL_H */ diff --git a/nuttx/drivers/pm/pm_register.c b/nuttx/drivers/power/pm_register.c similarity index 95% rename from nuttx/drivers/pm/pm_register.c rename to nuttx/drivers/power/pm_register.c index 41d4bb836..19f94cb02 100644 --- a/nuttx/drivers/pm/pm_register.c +++ b/nuttx/drivers/power/pm_register.c @@ -1,8 +1,8 @@ /**************************************************************************** - * drivers/pm/pm_register.c + * drivers/power/pm_register.c * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -42,7 +42,7 @@ #include #include -#include +#include #include "pm_internal.h" diff --git a/nuttx/drivers/pm/pm_update.c b/nuttx/drivers/power/pm_update.c similarity index 98% rename from nuttx/drivers/pm/pm_update.c rename to nuttx/drivers/power/pm_update.c index 336bee5ef..ae5e1f840 100644 --- a/nuttx/drivers/pm/pm_update.c +++ b/nuttx/drivers/power/pm_update.c @@ -1,8 +1,8 @@ /**************************************************************************** - * drivers/pm/pm_update.c + * drivers/power/pm_update.c * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -41,7 +41,7 @@ #include -#include +#include #include #include "pm_internal.h" diff --git a/nuttx/include/nuttx/pm.h b/nuttx/include/nuttx/power/pm.h similarity index 99% rename from nuttx/include/nuttx/pm.h rename to nuttx/include/nuttx/power/pm.h index 308960fdb..7c9433c22 100644 --- a/nuttx/include/nuttx/pm.h +++ b/nuttx/include/nuttx/power/pm.h @@ -1,5 +1,5 @@ /**************************************************************************** - * include/nuttx/pm.h + * include/nuttx/power/pm.h * NuttX Power Management Interfaces * * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. @@ -61,8 +61,8 @@ * +-------+------+--------+ */ -#ifndef __INCLUDE_NUTTX_PM_H -#define __INCLUDE_NUTTX_PM_H +#ifndef __INCLUDE_NUTTX_POWER_PM_H +#define __INCLUDE_NUTTX_POWER_PM_H /**************************************************************************** * Included Files @@ -481,4 +481,4 @@ EXTERN int pm_changestate(enum pm_state_e newstate); # define pm_changestate(state) #endif /* CONFIG_PM */ -#endif /* __INCLUDE_NUTTX_PM_H */ +#endif /* __INCLUDE_NUTTX_POWER_PM_H */