summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2015-01-06 11:50:56 -0600
committerGregory Nutt <gnutt@nuttx.org>2015-01-06 11:50:56 -0600
commit3c5fae81f4923f684adaafc5b72d18ad09baba45 (patch)
treeb77d83cc8300acd5856ff8effdf3a303d4655d76
parent0e1697302a5692d2fa81af5c76d3277b3a19a656 (diff)
downloadnuttx-3c5fae81f4923f684adaafc5b72d18ad09baba45.tar.gz
nuttx-3c5fae81f4923f684adaafc5b72d18ad09baba45.tar.bz2
nuttx-3c5fae81f4923f684adaafc5b72d18ad09baba45.zip
DK-TM4C129X: Add support for on-board TMP100 temperature sensor
-rw-r--r--nuttx/configs/dk-tm4c129x/README.txt32
-rw-r--r--nuttx/configs/dk-tm4c129x/include/board.h30
-rw-r--r--nuttx/configs/dk-tm4c129x/src/Makefile4
-rw-r--r--nuttx/configs/dk-tm4c129x/src/dk-tm4c129x.h1
-rw-r--r--nuttx/configs/dk-tm4c129x/src/tm4c_tmp100.c103
-rw-r--r--nuttx/configs/stm3210e-eval/README.txt6
-rw-r--r--nuttx/configs/stm3210e-eval/include/board.h13
-rw-r--r--nuttx/drivers/sensors/Kconfig4
-rw-r--r--nuttx/drivers/sensors/lm75.c2
9 files changed, 179 insertions, 16 deletions
diff --git a/nuttx/configs/dk-tm4c129x/README.txt b/nuttx/configs/dk-tm4c129x/README.txt
index 49f356340..720a522bf 100644
--- a/nuttx/configs/dk-tm4c129x/README.txt
+++ b/nuttx/configs/dk-tm4c129x/README.txt
@@ -36,6 +36,7 @@ Contents
- Buttons and LEDs
- Serial Console
- Networking Support
+ - Temperature Sensor
- DK-TM4129X Configuration Options
- Configurations
@@ -648,6 +649,37 @@ f Application Configuration -> Network Utilities
CONFIG_NSH_NETINIT_RETRYMSEC=2000 : Configure the network monitor as you like
CONFIG_NSH_NETINIT_SIGNO=18
+Temperature Sensor
+==================
+
+ Support for the on-board TMP-100 temperature sensor is available. This
+ uses the driver for the compatible LM-75 part. To set up the temperature
+ sensor, add the following to the NuttX configuration file:
+
+ System Type -> Tiva/Stellaris Peripheral Selection
+ CONFIG_TIVA_I2C6=y
+
+ Drivers -> I2C Support
+ CONFIG_I2C=y
+
+ Drivers -> Sensors
+ CONFIG_I2C_LM75=y
+
+ Then you can implement logic like the following to use the temperature sensor:
+
+ #include <nuttx/sensors/lm75.h>
+ #include <arch/board/board.h>
+
+ ret = tiva_tmp100_initialize("/dev/temp"); /* Register the temperature sensor */
+ fd = open("/dev/temp", O_RDONLY); /* Open the temperature sensor device */
+ ret = ioctl(fd, SNIOC_FAHRENHEIT, 0); /* Select Fahrenheit */
+ bytesread = read(fd, buffer, 8*sizeof(b16_t)); /* Read temperature samples */
+
+ More complex temperature sensor operations are also available. See the IOCTL
+ commands enumerated in include/nuttx/sensors/lm75.h. Also read the descriptions
+ of the tiva_tmp100_initialize() and tiva_tmp100_attach() interfaces in the
+ arch/board/board.h file (sames as configs/dk-tm4c129x/include/board.h).
+
DK-TM4129X Configuration Options
================================
diff --git a/nuttx/configs/dk-tm4c129x/include/board.h b/nuttx/configs/dk-tm4c129x/include/board.h
index 7df3b08eb..aacdda3b2 100644
--- a/nuttx/configs/dk-tm4c129x/include/board.h
+++ b/nuttx/configs/dk-tm4c129x/include/board.h
@@ -108,14 +108,14 @@
* --- ------------ -----------------
*/
-/* LED index values for use with tm4c_setled() */
+/* LED index values for use with tiva_setled() */
#define BOARD_LED_R 0
#define BOARD_LED_G 1
#define BOARD_LED_B 2
#define BOARD_NLEDS 3
-/* LED bits for use with tm4c_setleds() */
+/* LED bits for use with tiva_setleds() */
#define BOARD_LED_R_BIT (1 << BOARD_LED_R)
#define BOARD_LED_G_BIT (1 << BOARD_LED_G)
@@ -244,7 +244,7 @@
void tiva_boardinitialize(void);
/************************************************************************************
- * Name: tm4c_ledinit, tm4c_setled, and tm4c_setleds
+ * Name: tiva_ledinit, tiva_setled, and tiva_setleds
*
* Description:
* If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board LED. If
@@ -254,9 +254,27 @@ void tiva_boardinitialize(void);
************************************************************************************/
#ifndef CONFIG_ARCH_LEDS
-void tm4c_ledinit(void);
-void tm4c_setled(int led, bool ledon);
-void tm4c_setleds(uint8_t ledset);
+void tiva_ledinit(void);
+void tiva_setled(int led, bool ledon);
+void tiva_setleds(uint8_t ledset);
+#endif
+
+/************************************************************************************
+ * Name: tiva_tmp100_initialize
+ *
+ * Description:
+ * Initialize and register the TMP-100 Temperature Sensor driver.
+ *
+ * Input parameters:
+ * devpath - The full path to the driver to register. E.g., "/dev/temp0"
+ *
+ * Returned Value:
+ * Zero (OK) on success; a negated errno value on failure.
+ *
+ ************************************************************************************/
+
+#if defined(CONFIG_I2C) && defined(CONFIG_I2C_LM75) && defined(CONFIG_STM32_I2C1)
+int tiva_tmp100_initialize(FAR const char *devpath);
#endif
#endif /* __ASSEMBLY__ */
diff --git a/nuttx/configs/dk-tm4c129x/src/Makefile b/nuttx/configs/dk-tm4c129x/src/Makefile
index 99739fa76..3f624142b 100644
--- a/nuttx/configs/dk-tm4c129x/src/Makefile
+++ b/nuttx/configs/dk-tm4c129x/src/Makefile
@@ -59,6 +59,10 @@ ifeq ($(CONFIG_NSH_ARCHINIT),y)
CSRCS += tm4c_nsh.c
endif
+ifeq ($(CONFIG_I2C_LM75),y)
+CSRCS += tm4c_tmp100.c
+endif
+
COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
diff --git a/nuttx/configs/dk-tm4c129x/src/dk-tm4c129x.h b/nuttx/configs/dk-tm4c129x/src/dk-tm4c129x.h
index 6935752e3..b51e70418 100644
--- a/nuttx/configs/dk-tm4c129x/src/dk-tm4c129x.h
+++ b/nuttx/configs/dk-tm4c129x/src/dk-tm4c129x.h
@@ -122,6 +122,7 @@
* I2C address is 0x4A
*/
+#define TMP100_I2CBUS 6
#define TMP100_I2CADDR 0x4a
/* Speaker outputs *****************************************************************/
diff --git a/nuttx/configs/dk-tm4c129x/src/tm4c_tmp100.c b/nuttx/configs/dk-tm4c129x/src/tm4c_tmp100.c
new file mode 100644
index 000000000..1b179610c
--- /dev/null
+++ b/nuttx/configs/dk-tm4c129x/src/tm4c_tmp100.c
@@ -0,0 +1,103 @@
+/****************************************************************************
+ * configs/dk-tm4c129x/src/tiva_tmp100.c
+ *
+ * Copyright (C) 2015 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 <nuttx/i2c.h>
+#include <nuttx/sensors/lm75.h>
+
+#include "tiva_i2c.h"
+#include "dk-tm4c129x.h"
+
+#if defined(CONFIG_I2C) && defined(CONFIG_I2C_LM75) && \
+ defined(CONFIG_TIVA_I2C6)
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: tiva_tmp100_initialize
+ *
+ * Description:
+ * Initialize and register the LM-75 Temperature Sensor driver.
+ *
+ * Input parameters:
+ * devpath - The full path to the driver to register. E.g., "/dev/temp0"
+ *
+ * Returned Value:
+ * Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int tiva_tmp100_initialize(FAR const char *devpath)
+{
+ FAR struct i2c_dev_s *i2c;
+ int ret;
+
+ /* Get an instance of the I2C6 interface */
+
+ i2c = up_i2cinitialize(TMP100_I2CBUS);
+ if (!i2c)
+ {
+ return -ENODEV;
+ }
+
+ /* Then register the temperature sensor */
+
+ ret = lm75_register(devpath, i2c, TMP100_I2CADDR);
+ if (ret < 0)
+ {
+ (void)up_i2cuninitialize(i2c);
+ }
+
+ return ret;
+}
+
+#endif /* CONFIG_I2C && CONFIG_I2C_LM75 && CONFIG_TIVA_I2C6 */
diff --git a/nuttx/configs/stm3210e-eval/README.txt b/nuttx/configs/stm3210e-eval/README.txt
index e3130552d..a6743c803 100644
--- a/nuttx/configs/stm3210e-eval/README.txt
+++ b/nuttx/configs/stm3210e-eval/README.txt
@@ -360,12 +360,12 @@ Then you can implement logic like the following to use the temperature sensor:
#include <nuttx/sensors/lm75.h>
#include <arch/board/board.h>
- ret = stm32_lm75initialize("/dev/temp"); /* Register the temperature sensor */
- fd = open("/dev/temp", O_RDONLY); /* Open the temperature sensor device */
+ ret = stm32_lm75initialize("/dev/temp"); /* Register the temperature sensor */
+ fd = open("/dev/temp", O_RDONLY); /* Open the temperature sensor device */
ret = ioctl(fd, SNIOC_FAHRENHEIT, 0); /* Select Fahrenheit */
bytesread = read(fd, buffer, 8*sizeof(b16_t)); /* Read temperature samples */
-More complex temperature sensor operations are also available. See the IOCTAL
+More complex temperature sensor operations are also available. See the IOCTL
commands enumerated in include/nuttx/sensors/lm75.h. Also read the descriptions
of the stm32_lm75initialize() and stm32_lm75attach() interfaces in the
arch/board/board.h file (sames as configs/stm3210e-eval/include/board.h).
diff --git a/nuttx/configs/stm3210e-eval/include/board.h b/nuttx/configs/stm3210e-eval/include/board.h
index 25cbcd402..dd79f1400 100644
--- a/nuttx/configs/stm3210e-eval/include/board.h
+++ b/nuttx/configs/stm3210e-eval/include/board.h
@@ -222,7 +222,8 @@
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
-extern "C" {
+extern "C"
+{
#else
#define EXTERN extern
#endif
@@ -235,12 +236,12 @@ extern "C" {
*
* Description:
* All STM32 architectures must provide the following entry point. This entry point
- * is called early in the intitialization -- after all memory has been configured
+ * is called early in the initialization -- after all memory has been configured
* and mapped but before any devices have been initialized.
*
************************************************************************************/
-EXTERN void stm32_boardinitialize(void);
+void stm32_boardinitialize(void);
/************************************************************************************
* Name: stm3210e_lcdclear
@@ -254,7 +255,7 @@ EXTERN void stm32_boardinitialize(void);
************************************************************************************/
#ifdef CONFIG_STM32_FSMC
-EXTERN void stm3210e_lcdclear(uint16_t color);
+void stm3210e_lcdclear(uint16_t color);
#endif
/************************************************************************************
@@ -272,7 +273,7 @@ EXTERN void stm3210e_lcdclear(uint16_t color);
************************************************************************************/
#if defined(CONFIG_I2C) && defined(CONFIG_I2C_LM75) && defined(CONFIG_STM32_I2C1)
-EXTERN int stm32_lm75initialize(FAR const char *devpath);
+int stm32_lm75initialize(FAR const char *devpath);
#endif
/************************************************************************************
@@ -290,7 +291,7 @@ EXTERN int stm32_lm75initialize(FAR const char *devpath);
************************************************************************************/
#if defined(CONFIG_I2C) && defined(CONFIG_I2C_LM75) && defined(CONFIG_STM32_I2C1)
-EXTERN xcpt_t stm32_lm75attach(xcpt_t irqhandler);
+xcpt_t stm32_lm75attach(xcpt_t irqhandler);
#endif
#undef EXTERN
diff --git a/nuttx/drivers/sensors/Kconfig b/nuttx/drivers/sensors/Kconfig
index 89b588dfd..cedb9ac5c 100644
--- a/nuttx/drivers/sensors/Kconfig
+++ b/nuttx/drivers/sensors/Kconfig
@@ -60,6 +60,10 @@ config LM75
default n
select I2C
select I2C_LM75
+ ---help---
+ Enable driver support for the STMicro LM-75 temperature sensor.
+ This should also work with compatible temperature sensors such as
+ the TI TMP100/101.
config QENCODER
bool "Qencoder"
diff --git a/nuttx/drivers/sensors/lm75.c b/nuttx/drivers/sensors/lm75.c
index 234d80dd8..5277fada4 100644
--- a/nuttx/drivers/sensors/lm75.c
+++ b/nuttx/drivers/sensors/lm75.c
@@ -331,7 +331,7 @@ static ssize_t lm75_read(FAR struct file *filep, FAR char *buffer, size_t buflen
for (i = 0; i < nsamples; i++)
{
- b16_t temp;
+ b16_t temp = 0;
/* Read the next b16_t temperature value */