• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

xpal_power.h

Go to the documentation of this file.
00001 /* Power Control and Management Functions */
00002 /* Copyright (C) 2009,2010 Thomas Klosa
00003  *
00004  *   This program is free software; you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation; either version 2 of the License, or
00007  *   (at your option) version 3.
00008  *
00009  *   This program is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License along
00015  *   with this program; if not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00025 #ifndef POWER_H
00026 #define POWER_H
00027 
00028 #include <avr/io.h>
00029 #include "cb_list.h"
00030 
00031 
00032 #define HL_PWR_ON       1     //!< Parameter to switch things on
00033 #define HL_PWR_OFF      0     //!< Parameter to switch things off
00034 #define HL_PWR_FAIL -1    //!< Return value to indicate error conditions
00035 
00036 /*  @brief Power Information variable */
00037 typedef int8_t  hl_pwr_state_t;
00038 
00039 #define HL_PWR_USB_ACTIVE       0x01    //!< Power from USB is available
00040 #define HL_PWR_3V3_ACTIVE       0x02    //!< 3.3V is active
00041 #define HL_PWR_5V_ACTIVE        0x04    //!< 5V regulator is active
00042 #define HL_PWR_LCD_ACTIVE       0x08    //!< LCD High Voltage is active
00043 
00051 #define HL_PWR_ST_RUNNING       0x00
00052 
00067 #define HL_PWR_ST_IDLE          0x10
00068 
00089 #define HL_PWR_ST_33SLEEP       0x20
00090 
00111 #define HL_PWR_ST_SLEEP 0x40
00112 
00134 #define HL_PWR_ST_OFF   0x80
00135 
00136 /*
00137         The following bits are used with hl_pwr_CtrlAutoSave
00138         When set, the pwr Management can enter the related power state
00139 */
00140 #define HL_PWR_ALLOW_NOSAVE     0x0000  
00141 #define HL_PWR_ALLOW_IDLE               0x0010  
00142 #define HL_PWR_ALLOW_33SLEEP    0x0020  
00143 #define HL_PWR_ALLOW_SLEEP              0x0040  
00144 #define HL_PWR_ALLOW_OFF                0x0080  
00147 typedef int8_t  pwr_info_t;   // 
00148 
00149 #define HL_PWR_OFF_TIME         600             //!< inactivity seconds until power off
00150 
00151 /*
00152         Definition of WakeUp sources
00153 */
00154 #define HL_PWR_WAKE_BY_KEY              0x01    //!< Key in COL0..2
00155 #define HL_PWR_WAKE_BY_PWR_KEY  0x02    //!< Key in COL3
00156 #define HL_PWR_WAKE_BY_SYS_TMR  0x04    //!< Timer2 COMPA
00157 #define HL_PWR_WAKE_BY_1S_TMR   0x08    //!< Timer2 OV
00158 #define HL_PWR_WAKE_BY_EX232    0x10    //!< USART 3
00159 #define HL_PWR_WAKE_BY_MOD232   0x20    //!< USART 2
00160 #define HL_PWR_WAKE_BY_ADC              0x40    //!< ADC
00161 #define HL_PWR_WAKE_NO_SOURCE   0x00    //!< Unknown Source or system was not in sleep (_NOSAVE)
00162 
00163 
00170 extern volatile uint8_t WakeUpSource;
00171 
00177 extern volatile uint16_t PowerOffTimer;
00178 
00179 extern volatile hl_pwr_state_t hl_pwr_state;    
00180 
00181 extern volatile hl_pwr_state_t hl_pwr_info;             
00182 
00183 
00184 /*
00185         Functions for external use
00186 */
00187 
00194 void hl_pwr_InitBoard(void);
00195 
00203 void hl_pwr_InitPwrMan(void);
00204 
00218  uint8_t hl_pwr_EnterSleep(void);
00219 
00220 
00238 inline void hl_pwr_SetWakeSource(uint8_t ws){
00239 
00240         WakeUpSource |= ws;
00241 }
00242 
00245 inline uint8_t hl_pwr_GetWakeSource(void){
00246         return WakeUpSource;
00247 }
00248 
00256 inline void hl_pwr_AppBusy(void){
00257         PowerOffTimer = HL_PWR_OFF_TIME;
00258 }
00259 
00260 
00267 inline void hl_pwr_OffNow(void){
00268         PowerOffTimer = 0;
00269 }
00270 
00271 
00278 inline uint16_t hl_pwr_GetOffTime(void){
00279         return PowerOffTimer;
00280 }
00281 
00282 
00283 uint16_t hl_pwr_fast(void*); 
00284 uint16_t hl_pwr_slow(void*);  
00285 
00292 void hl_pwr_3V3reg(hl_pwr_state_t state);
00293 
00301 void hl_pwr_5Vreg(hl_pwr_state_t state);
00302 
00309 void hl_pwr_LCDreg(hl_pwr_state_t state);
00310 
00315 inline hl_pwr_state_t hl_pwr_GetState(void){ 
00316         return hl_pwr_state;
00317 };
00318 
00335 extern void hl_RegisterPwrCb(cb_function_t fkt2call, void *PwrStAllowed);
00336 
00337 
00338 #endif

Generated by  doxygen 1.7.1