00001 /*! \file WaspPWR.h 00002 \brief Library for managing Waspmote Power & Energy Modes 00003 00004 Copyright (C) 2009 Libelium Comunicaciones Distribuidas S.L. 00005 http://www.libelium.com 00006 00007 This program is free software: you can redistribute it and/or modify 00008 it under the terms of the GNU Lesser General Public License as published by 00009 the Free Software Foundation, either version 2.1 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. 00019 00020 Version: 0.6 00021 00022 Design: David Gascón 00023 00024 Implementation: Alberto Bielsa, David Cuartielles 00025 00026 */ 00027 00028 /*! \def WaspPWR_h 00029 \brief The library flag 00030 00031 */ 00032 #ifndef WaspPWR_h 00033 #define WaspPWR_h 00034 00035 00036 /****************************************************************************** 00037 * Includes 00038 ******************************************************************************/ 00039 00040 #include <inttypes.h> 00041 00042 00043 /****************************************************************************** 00044 * Definitions & Declarations 00045 ******************************************************************************/ 00046 00047 /*! \def WTD_ON 00048 \brief Watchdog possible states. ON in this case 00049 */ 00050 #define WTD_ON 1 00051 00052 /*! \def WTD_OFF 00053 \brief Watchdog possible states. OFF in this case 00054 */ 00055 #define WTD_OFF 2 00056 00057 00058 /*! \def WTD_16MS 00059 \brief Watchdog possible timers. 16 miliseconds in this case 00060 */ 00061 #define WTD_16MS 0 00062 00063 /*! \def WTD_32MS 00064 \brief Watchdog possible timers. 32 miliseconds in this case 00065 */ 00066 #define WTD_32MS 1 00067 00068 /*! \def WTD_64MS 00069 \brief Watchdog possible timers. 64 miliseconds in this case 00070 */ 00071 #define WTD_64MS 2 00072 00073 /*! \def WTD_128MS 00074 \brief Watchdog possible timers. 128 miliseconds in this case 00075 */ 00076 #define WTD_128MS 3 00077 00078 /*! \def WTD_250MS 00079 \brief Watchdog possible timers. 250 miliseconds in this case 00080 */ 00081 #define WTD_250MS 4 00082 00083 /*! \def WTD_500MS 00084 \brief Watchdog possible timers. 500 miliseconds in this case 00085 */ 00086 #define WTD_500MS 5 00087 00088 /*! \def WTD_1S 00089 \brief Watchdog possible timers. 1 second in this case 00090 */ 00091 #define WTD_1S 6 00092 00093 /*! \def WTD_2S 00094 \brief Watchdog possible timers. 2 seconds in this case 00095 */ 00096 #define WTD_2S 7 00097 00098 /*! \def WTD_4S 00099 \brief Watchdog possible timers. 4 seconds in this case 00100 */ 00101 #define WTD_4S 8 00102 00103 /*! \def WTD_8S 00104 \brief Watchdog possible timers. 8 seconds in this case 00105 */ 00106 #define WTD_8S 9 00107 00108 00109 00110 /*! \def BAT_MIN 00111 \brief Battery level. Minimum value pre-defined 00112 */ 00113 #define BAT_MIN 512 // 3.3V / 2 00114 00115 /*! \def BAT_MAX 00116 \brief Battery level. Maximum value pre-defined 00117 */ 00118 #define BAT_MAX 651 // 4.2V / 2 00119 00120 /*! \def ALL_OFF 00121 \brief Sleep Options. All the modules and switches OFF 00122 */ 00123 #define ALL_OFF SENS_OFF | UART0_OFF | UART1_OFF | BAT_OFF | RTC_OFF 00124 00125 /*! \def SENS_OFF 00126 \brief Sleep Options. Set sensor switches OFF 00127 */ 00128 #define SENS_OFF 1 00129 00130 /*! \def UART0_OFF 00131 \brief Sleep Options. UART0 closed and switch related with XBee is set OFF 00132 */ 00133 #define UART0_OFF 2 00134 00135 /*! \def UART1_OFF 00136 \brief Sleep Options. UART1 closed 00137 */ 00138 #define UART1_OFF 4 00139 00140 /*! \def BAT_OFF 00141 \brief Sleep Options. Battery level switch is set OFF 00142 */ 00143 #define BAT_OFF 8 00144 00145 /*! \def RTC_OFF 00146 \brief Sleep Options. RTC switch is set OFF 00147 */ 00148 #define RTC_OFF 16 00149 00150 /*! \def HIB_ADDR 00151 \brief EEPROM Address for hibernating 00152 */ 00153 #define HIB_ADDR 0 00154 00155 /*! \def HIB_VALUE 00156 \brief EEPROM Value for hibernating 00157 */ 00158 #define HIB_VALUE 10 00159 00160 extern volatile uint16_t intFlag; 00161 00162 /****************************************************************************** 00163 * Class 00164 ******************************************************************************/ 00165 00166 //! WaspPWR Class 00167 /*! 00168 WaspPWR Class defines all the variables and functions used for managing Waspmote Energy and Power Modes 00169 */ 00170 class WaspPWR 00171 { 00172 private: 00173 00174 //! It sets a certain internal peripheral on 00175 /*! 00176 \param uint8_t peripheral : the peripheral to set on 00177 \return void 00178 \sa resetIPF(uint8_t peripheral), getIPF() 00179 */ 00180 void setIPF(uint8_t peripheral); 00181 00182 //! It sets a certain internal peripheral off 00183 /*! 00184 \param uint8_t peripheral : the peripheral to set off 00185 \return void 00186 \sa setIPF(uint8_t peripheral), getIPF() 00187 */ 00188 void resetIPF(uint8_t peripheral); 00189 00190 //! It gets the whole IPR 00191 /*! 00192 \param void 00193 \return the IPRA flag 00194 \sa setIPF(uint8_t peripheral), resetIPF(uint8_t peripheral) 00195 */ 00196 uint8_t getIPF(); 00197 00198 public: 00199 // VARIABLES 00200 uint8_t IPRA; //20090224 -- moved to wiring.c 00201 uint8_t IPRB; 00202 00203 // CONSTRUCTOR 00204 //! class constructor 00205 /*! 00206 It does nothing 00207 \param void 00208 \return void 00209 */ 00210 WaspPWR(); 00211 00212 //! It sets ON/OFF 3V3 or 5V switches 00213 /*! 00214 \param uint8_t type : SENS_3V3 or SENS_5V 00215 \param uint8_t mode : SENS_ON or SENS_OFF 00216 \return void 00217 */ 00218 void setSensorPower(uint8_t type, uint8_t mode); 00219 00220 //! It enables or disables watchdog interruption 00221 /*! 00222 \param uint8_t mode : WTD_ON or WTD_OFF 00223 \param uint8_t timer : WTD_16MS, WTD_32MS, WTD_64MS, WTD_128MS, WTD_250MS, WTD_500MS, WTD_1S, WTD_2S, WTD_4S or WTD_8S 00224 \return void 00225 */ 00226 void setWatchdog(uint8_t mode, uint8_t timer); 00227 00228 //! It switches off the specified Waspmote switches 00229 /*! 00230 \param uint8_t option : ALL_OFF, SENS_OFF, UART0_OFF, UART1_OFF, BAT_OFF or RTC_OFF 00231 \return void 00232 \sa switchesON(uint8_t option) 00233 */ 00234 void switchesOFF(uint8_t option); 00235 00236 //! It switches on the specified Waspmote switches 00237 /*! 00238 \param uint8_t option : ALL_OFF, SENS_OFF, UART0_OFF, UART1_OFF, BAT_OFF or RTC_OFF 00239 \return void 00240 \sa switchesOFF(uint8_t option) 00241 */ 00242 void switchesON(uint8_t option); 00243 00244 //! It clears all the captured interrupts to allow new interrupts on that modules 00245 /*! 00246 \return void 00247 */ 00248 void clearInts(); 00249 00250 //! It sets the microcontroller to the lowest consumption sleep mode 00251 /*! 00252 \param uint8_t option : ALL_OFF, SENS_OFF, UART0_OFF, UART1_OFF, BAT_OFF or RTC_OFF 00253 \return void 00254 \sa sleep(uint8_t timer, uint8_t option), deepSleep(const char* time2wake, uint8_t offset, uint8_t mode, uint8_t option), hibernate(const char* time2wake, uint8_t offset, uint8_t mode) 00255 */ 00256 void sleep(uint8_t option); 00257 00258 //! It sets the microcontroller to the lowest consumption sleep mode enabling the watchdog 00259 /*! 00260 \param uint8_t timer : WTD_16MS, WTD_32MS, WTD_64MS, WTD_128MS, WTD_250MS, WTD_500MS, WTD_1S, WTD_2S, WTD_4S or WTD_8S 00261 \param uint8_t option : ALL_OFF, SENS_OFF, UART0_OFF, UART1_OFF, BAT_OFF or RTC_OFF 00262 \return void 00263 \sa sleep(uint8_t option), deepSleep(const char* time2wake, uint8_t offset, uint8_t mode, uint8_t option), hibernate(const char* time2wake, uint8_t offset, uint8_t mode) 00264 */ 00265 void sleep(uint8_t timer, uint8_t option); 00266 00267 //! It sets the microcontroller to the lowest consumption sleep mode enabling RTC interruption 00268 /*! 00269 \param const char* time2wake : string that indicates the time to wake up. It looks like "dd:hh:mm:ss" 00270 \param uint8_t offset : RTC_OFFSET or RTC_ABSOLUTE 00271 \param uint8_t mode : RTC_ALM1_MODE1, RTC_ALM1_MODE2, RTC_ALM1_MODE3, RTC_ALM1_MODE4 or RTC_ALM1_MODE5 00272 \param uint8_t option : ALL_OFF, SENS_OFF, UART0_OFF, UART1_OFF, BAT_OFF or RTC_OFF 00273 \return void 00274 \sa sleep(uint8_t option), sleep(uint8_t timer, uint8_t option), hibernate(const char* time2wake, uint8_t offset, uint8_t mode) 00275 */ 00276 void deepSleep(const char* time2wake, uint8_t offset, uint8_t mode, uint8_t option); 00277 00278 //! It switches off the general switch enabling RTC interruption 00279 /*! 00280 \param const char* time2wake : string that indicates the time to wake up. It looks like "dd:hh:mm:ss" 00281 \param uint8_t offset : RTC_OFFSET or RTC_ABSOLUTE 00282 \param uint8_t mode : RTC_ALM1_MODE1, RTC_ALM1_MODE2, RTC_ALM1_MODE3, RTC_ALM1_MODE4 or RTC_ALM1_MODE5 00283 \return void 00284 \sa sleep(uint8_t option), sleep(uint8_t timer, uint8_t option), deepSleep(const char* time2wake, uint8_t offset, uint8_t mode, uint8_t option) 00285 */ 00286 void hibernate(const char* time2wake, uint8_t offset, uint8_t mode); 00287 00288 //! It gets the remaining battery % 00289 /*! 00290 \return the remaining battery % 00291 */ 00292 uint8_t getBatteryLevel(); 00293 00294 //! It closes I2C bus 00295 /*! 00296 \return void 00297 */ 00298 void closeI2C(); 00299 00300 //! It inits the value of the digipot used in the battery detector 00301 /*! 00302 \param float threshold : threshold to init the battery detector (from 3V to 3.4V) 00303 \return void 00304 */ 00305 void setLowBatteryThreshold(float threshold); 00306 00307 //! It checks if Hibernate has generated the reset 00308 /*! 00309 \return void 00310 */ 00311 void ifHibernate(); 00312 }; 00313 00314 extern WaspPWR PWR; 00315 00316 #endif 00317
1.5.6