9
0
Fork 0

Create directory structures to support power-related devices

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4321 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo 2012-01-22 16:42:49 +00:00
parent 6e7a3dbbd2
commit de94649dd8
16 changed files with 280 additions and 59 deletions

View File

@ -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.

View File

@ -3331,18 +3331,18 @@ extern void up_ledoff(int led);
<code>SLEEP</code> (some MCUs may even require going through reset).
</dl>
<p>
These various states are represented with type <code>enum pm_state_e</code> in <code>include/nuttx/pm.h</code>.
These various states are represented with type <code>enum pm_state_e</code> in <code>include/nuttx/power/pm.h</code>.
</p>
<h3><a name="pminterfaces">6.4.2 Interfaces</a></h3>
<p>
All PM interfaces are declared in the file <code>include/nuttx/pm.h</code>.
All PM interfaces are declared in the file <code>include/nuttx/power/pm.h</code>.
</p>
<h4><a name="pminitialize">6.4.2.1 pm_initialize()</a></h4>
<p><b>Function Prototype:</b></p>
<ul><pre>
#include &lt;nuttx/pm.h&gt;
#include &lt;nuttx/power/pm.h&gt;
void pm_initialize(void);
</pre></ul>
<p><b>Description:</b>
@ -3359,7 +3359,7 @@ None
<h4><a name="pmregister">6.4.2.2 pm_register()</a></h4>
<p><b>Function Prototype:</b></p>
<ul><pre>
#include &lt;nuttx/pm.h&gt;
#include &lt;nuttx/power/pm.h&gt;
int pm_register(FAR struct pm_callback_s *callbacks);
</pre></ul>
<p><b>Description:</b>
@ -3379,7 +3379,7 @@ Zero (<code>OK</code>) on success; otherwise a negater <code>errno</code> value
<h4><a name="pmactivity">6.4.2.3 pm_activity()</a></h4>
<p><b>Function Prototype:</b></p>
<ul><pre>
#include &lt;nuttx/pm.h&gt;
#include &lt;nuttx/power/pm.h&gt;
void pm_activity(int priority);
</pre></ul>
<p><b>Description:</b>
@ -3406,7 +3406,7 @@ void pm_activity(int priority);
<h4><a name="pmcheckstate">6.4.2.4 pm_checkstate()</a></h4>
<p><b>Function Prototype:</b></p>
<ul><pre>
#include &lt;nuttx/pm.h&gt;
#include &lt;nuttx/power/pm.h&gt;
enum pm_state_e pm_checkstate(void);
</pre></ul>
<p><b>Description:</b>
@ -3433,7 +3433,7 @@ enum pm_state_e pm_checkstate(void);
<h4><a name="pmchangestate">6.4.2.5 pm_changestate()</a></h4>
<p><b>Function Prototype:</b></p>
<ul><pre>
#include &lt;nuttx/pm.h&gt;
#include &lt;nuttx/power/pm.h&gt;
int pm_changestate(enum pm_state_e newstate);
</pre></ul>
<p><b>Description:</b>
@ -3461,7 +3461,7 @@ enum pm_state_e pm_checkstate(void);
<h3><a name="pmcallbacks">6.4.3 Callbacks</a></h3>
<p>
The <code>struct pm_callback_s</code> includes the pointers to the driver callback functions.
This structure is defined <code>include/nuttx/pm.h</code>.
This structure is defined <code>include/nuttx/power/pm.h</code>.
These callback functions can be used to provide power management information to the driver.
</p>
@ -3496,7 +3496,7 @@ int (*prepare)(FAR struct pm_callback_s *cb, enum pm_state_e pmstate);
<h4><a name="pmnotify">6.4.3.1 notify()</a></h4>
<p><b>Function Prototype:</b></p>
<ul><pre>
#include &lt;nuttx/pm.h&gt;
#include &lt;nuttx/power/pm.h&gt;
void (*notify)(FAR struct pm_callback_s *cb, enum pm_state_e pmstate);
</pre></ul>
<p><b>Description:</b>

View File

@ -41,7 +41,7 @@
#include <nuttx/config.h>
#include <nuttx/arch.h>
#include <nuttx/pm.h>
#include <nuttx/power/pm.h>
#include <arch/irq.h>

View File

@ -1,8 +1,8 @@
/****************************************************************************
* up_head.c
*
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
* Copyright (C) 2007-2009, 2011-2112 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -47,7 +47,7 @@
#include <nuttx/init.h>
#include <nuttx/arch.h>
#include <nuttx/pm.h>
#include <nuttx/power/pm.h>
/****************************************************************************
* Private Data

View File

@ -1,8 +1,8 @@
/****************************************************************************
* up_idle.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -42,7 +42,7 @@
#include <time.h>
#include <nuttx/arch.h>
#include <nuttx/pm.h>
#include <nuttx/power/pm.h>
#include "up_internal.h"

View File

@ -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 <gnutt@nuttx.org>
#
# 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

View File

@ -1,8 +1,8 @@
############################################################################
# drivers/pm/Make.defs
# drivers/power/Make.defs
#
# Copyright (C) 2011 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# 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

View File

@ -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 <gnutt@nuttx.org>
*
* 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 <nuttx/config.h>
#include <errno.h>
#include <debug.h>
#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 */

View File

@ -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 <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@ -39,7 +39,7 @@
#include <nuttx/config.h>
#include <nuttx/pm.h>
#include <nuttx/power/pm.h>
#include <nuttx/clock.h>
#include <arch/irq.h>

View File

@ -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 <spudmonkey@racsa.co.cr>
* Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -39,7 +39,7 @@
#include <nuttx/config.h>
#include <nuttx/pm.h>
#include <nuttx/power/pm.h>
#include <arch/irq.h>
#include "pm_internal.h"

View File

@ -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 <spudmonkey@racsa.co.cr>
* Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -39,7 +39,7 @@
#include <nuttx/config.h>
#include <nuttx/pm.h>
#include <nuttx/power/pm.h>
#include <nuttx/clock.h>
#include <arch/irq.h>

View File

@ -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 <spudmonkey@racsa.co.cr>
* Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -41,7 +41,7 @@
#include <semaphore.h>
#include <nuttx/pm.h>
#include <nuttx/power/pm.h>
#include "pm_internal.h"

View File

@ -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 <spudmonkey@racsa.co.cr>
* Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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 <semaphore.h>
#include <queue.h>
#include <nuttx/pm.h>
#include <nuttx/power/pm.h>
#include <nuttx/wqueue.h>
#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 */

View File

@ -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 <spudmonkey@racsa.co.cr>
* Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -42,7 +42,7 @@
#include <queue.h>
#include <assert.h>
#include <nuttx/pm.h>
#include <nuttx/power/pm.h>
#include "pm_internal.h"

View File

@ -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 <spudmonkey@racsa.co.cr>
* Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -41,7 +41,7 @@
#include <assert.h>
#include <nuttx/pm.h>
#include <nuttx/power/pm.h>
#include <nuttx/wqueue.h>
#include "pm_internal.h"

View File

@ -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 */