mos/dev/include/mica2-light-temp.h

Go to the documentation of this file.
00001 //  This file is part of MOS, the MANTIS Operating System
00002 //  See http://mantis.cs.colorado.edu/
00003 //
00004 //  Copyright (c) 2002 - 2007 University of Colorado, Boulder
00005 //
00006 //   All rights reserved.
00007 //
00008 //   Redistribution and use in source and binary forms, with or without
00009 //   modification, are permitted provided that the following conditions are
00010 //   met:
00011 //
00012 //       * Redistributions of source code must retain the above copyright
00013 //         notice, this list of conditions and the following disclaimer.
00014 //       * Redistributions in binary form must reproduce the above
00015 //         copyright notice, this list of conditions and the following
00016 //         disclaimer in the documentation and/or other materials provided
00017 //         with the distribution. 
00018 //       * Neither the name of the MANTIS Project nor the names of its
00019 //         contributors may be used to endorse or promote products derived
00020 //         from this software without specific prior written permission.
00021 //
00022 //   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023 //   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024 //   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00025 //   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00026 //   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027 //   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028 //   BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029 //   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030 //   CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 //   LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032 //   ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033 //   POSSIBILITY OF SUCH DAMAGE.
00034 
00035 
00046 //#define MICA2_PROTO 1
00047 #include "plat_dep.h"
00048 
00049 #if defined (PLATFORM_MICA2) || defined (PLATFORM_MICAZ) || defined(PLATFORM_AVRDEV) || defined(PLATFORM_MICA2DOT)
00050 
00051 
00052 #ifdef MICA2_PROTO
00053 #define LIGHT_PORT_DIRE DDRC
00054 #define TEMP_PORT_DIRE DDRC
00055 #define LIGHT_PORT PORTC
00056 #define TEMP_PORT PORTC
00057 #define LIGHT_PIN_MASK (1 << 1)
00058 #define TEMP_PIN_MASK (1 << 2)
00059 #define LIGHT_ADC_CHANNEL AVR_ADC_CH_6
00060 #define TEMP_ADC_CHANNEL AVR_ADC_CH_5
00061 
00062 
00064 static int8_t temp_vals [] ARCH_PROGMEM = {
00065    -82, -66, -56, -49, -44, -39, -35, -31, -28, -25,
00066    -22, -20, -18, -15, -13, -11, -10,  -8,  -6,  -4,
00067    -3,   -1,   0,   0,   2,   3,   4,   5,   7,   8,
00068    9,   10,  11,  12,  13,  14,  15,  16,  17,  18,
00069    19,   20,  21,  22,  23,  23,  24,  25,  26,  27,
00070    28,   28,  29,  30,  31,  31,  32,  33,  34,  34,
00071    35,   36,  37,  37,  38,  39,  39,  40,  41,  41,
00072    42,   43,  43,  44,  45,  45,  46,  47,  47,  48,
00073    48,   49,  50,  50,  51,  52,  52,  53,  53,  54,
00074    55,   55,  56,  56,  57,  58,  58,  59,  59,  60,
00075    61,   61,  62,  62,  63,  64,  64,  65,  65,  66,
00076    66,   67,  68,  68,  69,  69,  70,  71,  71,  72,
00077    72,   73,  74,  74,  75,  75,  76,  76,  77,  78, 
00078    78,   79,  79,  80,  81,  81,  82,  82,  83,  84,
00079    84,   85,  86,  86,  87,  87,  88,  89,  89,  90,
00080    91,   91,  92,  93,  93,  94,  95,  95,  96,  97,
00081    97,   98,  99,  99, 100, 101, 101, 102, 103, 104,
00082    104, 105, 106, 106, 107, 108, 109, 110, 110, 111,
00083    112, 113, 114, 114, 115, 116, 117, 118, 119, 119, 
00084    120, 121, 122, 123, 124, 125, 126, 127, 127, 127,
00085    127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
00086    127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
00087    127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
00088    127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
00089    127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
00090    127, 127, 127, 127, 127};
00091 
00092 /* truncate the table so it will fit in an uint8_t, this is the full data */
00093 /*
00094   128, 129, 130, 
00095   131, 132, 133, 134, 135, 137, 138, 139, 140, 141, 143, 
00096   144, 145, 147, 148, 149, 151, 152, 154, 155, 157, 159, 
00097   161, 162, 164, 166, 168, 170, 172, 174, 177, 179, 182, 
00098   184, 187, 190, 193, 196, 200, 204, 208, 212, 217, 222, 
00099   228, 235, 242, 251, 261, 273, 288, 309, 340, 398};
00100 */
00101 
00102 
00103 #else
00104 #define LIGHT_PORT_DIRE DDRE
00105 #define TEMP_PORT_DIRE DDRE
00106 #define LIGHT_PORT PORTE
00107 #define TEMP_PORT PORTE
00108 #define LIGHT_PIN_MASK 0x20
00109 #define TEMP_PIN_MASK 0x40
00110 #define LIGHT_ADC_CHANNEL AVR_ADC_CH_1
00111 #define TEMP_ADC_CHANNEL AVR_ADC_CH_1
00112 
00113 
00114 
00115 /*temperature conversion table*/
00116 /* TODO: put this in the right place in memory */
00117 static int8_t temp_vals [] ARCH_PROGMEM = {
00118    -82, -66, -56, -49, -44, -39, -35, -31, -28, -25,
00119    -22, -20, -18, -15, -13, -11, -10,  -8,  -6,  -4,
00120    -3,   -1,   0,   0,   2,   3,   4,   5,   7,   8,
00121    9,   10,  11,  12,  13,  14,  15,  16,  17,  18,
00122    19,   20,  21,  22,  23,  23,  24,  25,  26,  27,
00123    28,   28,  29,  30,  31,  31,  32,  33,  34,  34,
00124    35,   36,  37,  37,  38,  39,  39,  40,  41,  41,
00125    42,   43,  43,  44,  45,  45,  46,  47,  47,  48,
00126    48,   49,  50,  50,  51,  52,  52,  53,  53,  54,
00127    55,   55,  56,  56,  57,  58,  58,  59,  59,  60,
00128    61,   61,  62,  62,  63,  64,  64,  65,  65,  66,
00129    66,   67,  68,  68,  69,  69,  70,  71,  71,  72,
00130    72,   73,  74,  74,  75,  75,  76,  76,  77,  78, 
00131    78,   79,  79,  80,  81,  81,  82,  82,  83,  84,
00132    84,   85,  86,  86,  87,  87,  88,  89,  89,  90,
00133    91,   91,  92,  93,  93,  94,  95,  95,  96,  97,
00134    97,   98,  99,  99, 100, 101, 101, 102, 103, 104,
00135    104, 105, 106, 106, 107, 108, 109, 110, 110, 111,
00136    112, 113, 114, 114, 115, 116, 117, 118, 119, 119, 
00137    120, 121, 122, 123, 124, 125, 126, 127, 127, 127,
00138    127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
00139    127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
00140    127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
00141    127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
00142    127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
00143    127, 127, 127, 127, 127};
00144 
00145 /* truncate the table so it will fit in an uint8_t, this is the full data */
00146 /*
00147   128, 129, 130, 
00148   131, 132, 133, 134, 135, 137, 138, 139, 140, 141, 143, 
00149   144, 145, 147, 148, 149, 151, 152, 154, 155, 157, 159, 
00150   161, 162, 164, 166, 168, 170, 172, 174, 177, 179, 182, 
00151   184, 187, 190, 193, 196, 200, 204, 208, 212, 217, 222, 
00152   228, 235, 242, 251, 261, 273, 288, 309, 340, 398};
00153 */
00154 
00155 
00156 #endif
00157 
00158 #define select_temp()                                           \
00159    LIGHT_PORT_DIRE &= ~LIGHT_PIN_MASK;                          \
00160    LIGHT_PORT &= ~LIGHT_PIN_MASK;                               \
00161    TEMP_PORT_DIRE |= TEMP_PIN_MASK;                             \
00162    TEMP_PORT &= ~TEMP_PIN_MASK;                                 \
00163    TEMP_PORT |= TEMP_PIN_MASK;
00164 
00165 #define select_light()                                                  \
00166    TEMP_PORT_DIRE &= ~TEMP_PIN_MASK;                                    \
00167    TEMP_PORT &= ~TEMP_PIN_MASK;         \
00168    LIGHT_PORT_DIRE |= LIGHT_PIN_MASK;                                   \
00169    LIGHT_PORT &= ~LIGHT_PIN_MASK; \
00170    LIGHT_PORT |= LIGHT_PIN_MASK; 
00171 
00172 #define select_off()                                                 \
00173    LIGHT_PORT &= ~LIGHT_PIN_MASK; \
00174    LIGHT_PORT_DIRE &= ~LIGHT_PIN_MASK;                               \
00175    TEMP_PORT &= ~TEMP_PIN_MASK; \
00176    TEMP_PORT_DIRE &= ~TEMP_PIN_MASK;                                 \
00177 
00178 #elif defined (PLATFORM_MICA2DOT)
00179 
00180 #define LIGHT_PORT_DIRE DDRC
00181 #define LIGHT_PORT PORTC
00182 #define LIGHT_PIN_MASK (1 << 0)
00183 #define LIGHT_ADC_CHANNEL AVR_ADC_CH_7
00184 
00185 #define TEMP_PORT_DIRE DDRC
00186 #define TEMP_PORT PORTC
00187 #define TEMP_HI (1 << 7)
00188 #define TEMP_LO (1 << 6)
00189 
00190 #define select_temp() {                                         \
00191       TEMP_PORT_DIRE |= (TEMP_HI | TEMP_LO);                    \
00192       /* turn on thermistor (int2) */                           \
00193       TEMP_PORT |= (TEMP_HI);                                   \
00194       TEMP_PORT &= ~(TEMP_LO);                                  \
00195       LIGHT_PORT_DIRE &= ~LIGHT_PIN_MASK;                       \
00196       /* turn off photoresistor (int1) */                       \
00197       LIGHT_PORT &= ~LIGHT_PIN_MASK;                            \
00198    }
00199 
00200 
00201 #define select_light() {                                                \
00202       LIGHT_PORT_DIRE &= ~LIGHT_PIN_MASK;                               \
00203       LIGHT_PORT |= LIGHT_PIN_MASK; /* turn on photo-resistor (int1)*/  \
00204       LIGHT_PORT_DIRE |= LIGHT_PIN_MASK;                                \
00205       TEMP_PORT &= ~(TEMP_HI);                                          \
00206       TEMP_PORT |= (TEMP_LO);                                           \
00207       TEMP_PORT_DIRE &= ~(TEMP_HI | TEMP_LO);                           \
00208    }
00209 
00210 
00211 #define select_off() {                                                  \
00212       LIGHT_PORT_DIRE |= LIGHT_PIN_MASK;                                \
00213       LIGHT_PORT &= ~LIGHT_PIN_MASK;  /*turn off photoresistor (int1)*/ \
00214       TEMP_PORT &= ~(TEMP_HI);                                          \
00215       TEMP_PORT |= (TEMP_LO);                                           \
00216       TEMP_PORT_DIRE &= ~(TEMP_HI | TEMP_LO);                           \
00217    }
00218 
00219 #endif
00220 
00221 
00222 /*functions*/
00223 
00224 void mica2_light_temp_init(void);

Generated on Mon Nov 23 06:25:59 2009 for MANTIS by  doxygen 1.4.6