From b03c4a2ef5784e3122571930d8b46c5a6ebeba56 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 6 Jan 2015 13:23:02 -0600 Subject: DK-TM4C129X: Add logic to initialize the TMP-100 temperature sensor driver at startup --- nuttx/configs/dk-tm4c129x/README.txt | 43 +++++++++++++++++++++++++++- nuttx/configs/dk-tm4c129x/include/board.h | 2 +- nuttx/configs/dk-tm4c129x/src/Makefile | 2 ++ nuttx/configs/dk-tm4c129x/src/tm4c_bringup.c | 21 +++++++++++++- 4 files changed, 65 insertions(+), 3 deletions(-) diff --git a/nuttx/configs/dk-tm4c129x/README.txt b/nuttx/configs/dk-tm4c129x/README.txt index 720a522bf..017bf0e6f 100644 --- a/nuttx/configs/dk-tm4c129x/README.txt +++ b/nuttx/configs/dk-tm4c129x/README.txt @@ -652,6 +652,8 @@ f Application Configuration -> Network Utilities Temperature Sensor ================== + TMP-1000 Temperature Sensor Driver + ---------------------------------- 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: @@ -663,8 +665,12 @@ Temperature Sensor CONFIG_I2C=y Drivers -> Sensors + CONFIG_LM75=y CONFIG_I2C_LM75=y + Applications -> NSH Library + CONFIG_NSH_ARCHINIT=y + Then you can implement logic like the following to use the temperature sensor: #include @@ -673,13 +679,35 @@ Temperature Sensor 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 */ + bytesread = read(fd, buffer, 8*sizeof(b16_t)); /* Read (8) 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). + NSH Command Line Application + ---------------------------- + There is a tiny NSH command line application at examples/system/lm75 that + will read the current temperature from an LM75 compatible temperature sensor + and print the temperature on stdout in either units of degrees Fahrenheit or + Centigrade. This tiny command line application is enabled with the following + configuratin options: + + Library + CONFIG_LIBM=y + CONFIG_LIBC_FLOATINGPOINT=y + + Applications -> NSH Library + CONFIG_NSH_ARCHINIT=y + + Applications -> System Add-Ons + CONFIG_SYSTEM_LM75=y + CONFIG_SYSTEM_LM75_DEVNAME="/dev/temp" + CONFIG_SYSTEM_LM75_FAHRENHEIT=y (or CENTIGRADE) + CONFIG_SYSTEM_LM75_STACKSIZE=1024 + CONFIG_SYSTEM_LM75_PRIORITY=100 + DK-TM4129X Configuration Options ================================ @@ -868,3 +896,16 @@ Where is one of the following: network back up when the link becomes available again (for example, if the cable is reconnected. The paragraph "Network Monitor" above for additional information. + + 5. I2C6 and support for the on-board TMP-100 temperature sensor are + enabled. Also enabled is the NSH 'temp' command that will show the + current temperature on the command line like: + + nsh> temp + 80.60 degrees Fahrenheit + + [80.6 F in January. I love living in Costa Rica1] + + The default units is degrees Fahrenheit, but that is easily + reconfigured. See the discussin above in the paragraph entitled + "Temperature Sensor". diff --git a/nuttx/configs/dk-tm4c129x/include/board.h b/nuttx/configs/dk-tm4c129x/include/board.h index aacdda3b2..5efb3cc9a 100644 --- a/nuttx/configs/dk-tm4c129x/include/board.h +++ b/nuttx/configs/dk-tm4c129x/include/board.h @@ -273,7 +273,7 @@ void tiva_setleds(uint8_t ledset); * ************************************************************************************/ -#if defined(CONFIG_I2C) && defined(CONFIG_I2C_LM75) && defined(CONFIG_STM32_I2C1) +#if defined(CONFIG_I2C) && defined(CONFIG_I2C_LM75) && defined(CONFIG_TIVA_I2C6) int tiva_tmp100_initialize(FAR const char *devpath); #endif diff --git a/nuttx/configs/dk-tm4c129x/src/Makefile b/nuttx/configs/dk-tm4c129x/src/Makefile index 3f624142b..7b6eaf480 100644 --- a/nuttx/configs/dk-tm4c129x/src/Makefile +++ b/nuttx/configs/dk-tm4c129x/src/Makefile @@ -60,8 +60,10 @@ CSRCS += tm4c_nsh.c endif ifeq ($(CONFIG_I2C_LM75),y) +ifeq ($(CONFIG_TIVA_I2C6),y) CSRCS += tm4c_tmp100.c endif +endif COBJS = $(CSRCS:.c=$(OBJEXT)) diff --git a/nuttx/configs/dk-tm4c129x/src/tm4c_bringup.c b/nuttx/configs/dk-tm4c129x/src/tm4c_bringup.c index 07f3345ea..b2b2d457e 100644 --- a/nuttx/configs/dk-tm4c129x/src/tm4c_bringup.c +++ b/nuttx/configs/dk-tm4c129x/src/tm4c_bringup.c @@ -39,7 +39,9 @@ #include -#include +#include + +#include #include "dk-tm4c129x.h" @@ -47,6 +49,11 @@ * Pre-Processor Definitions ****************************************************************************/ +#ifdef CONFIG_SYSTEM_LM75_DEVNAME +# define TMP100_DEVNAME CONFIG_SYSTEM_LM75_DEVNAME +#else +# define TMP100_DEVNAME "/dev/temp" +#endif /**************************************************************************** * Public Functions @@ -62,5 +69,17 @@ int tm4c_bringup(void) { +#if defined(CONFIG_I2C) && defined(CONFIG_I2C_LM75) && defined(CONFIG_TIVA_I2C6) + int ret; + + /* Initialize and register the TMP-100 Temperature Sensor driver. */ + + ret = tiva_tmp100_initialize(TMP100_DEVNAME); + if (ret < 0) + { + dbg("ERROR: Failed to initialize TMP100 driver: %d\n", ret); + } +#endif + return OK; } -- cgit v1.2.3