Contiki 2.6

board-mbxxx.c

00001 /*#include PLATFORM_HEADER
00002 #include BOARD_HEADER
00003 #include "hal/micro/micro-common.h"
00004 #include "hal/micro/cortexm3/micro-common.h"*/
00005 
00006 #include "dev/button-sensor.h"
00007 #include "dev/temperature-sensor.h"
00008 #include "dev/acc-sensor.h"
00009 
00010 static uint8_t sensors_status;
00011 
00012 #define BUTTON_STATUS_ACTIVE    (1 << 0)
00013 #define TEMP_STATUS_ACTIVE              (1 << 1)
00014 #define ACC_STATUS_ACTIVE               (1 << 2)
00015 
00016 /* Remember state of sensors (if active or not), in order to
00017  * resume their original state after calling powerUpSensors().
00018  * Useful when entering in sleep mode, since all system
00019  * peripherals have to be reinitialized.  */
00020 
00021 void sensorsPowerDown(){
00022 
00023         sensors_status = 0;
00024 
00025         if(button_sensor.status(SENSORS_READY)){
00026                 sensors_status |= BUTTON_STATUS_ACTIVE;
00027         }
00028         if(temperature_sensor.status(SENSORS_READY)){
00029                 sensors_status |= TEMP_STATUS_ACTIVE;
00030         }
00031         if(acc_sensor.status(SENSORS_READY)){
00032                 sensors_status |= ACC_STATUS_ACTIVE;
00033                 // Power down accelerometer to save power
00034                 SENSORS_DEACTIVATE(acc_sensor);
00035         }
00036 }
00037 
00038 /**/
00039 void sensorsPowerUp(){
00040 
00041         button_sensor.configure(SENSORS_HW_INIT, 0);
00042         temperature_sensor.configure(SENSORS_HW_INIT, 0);
00043         acc_sensor.configure(SENSORS_HW_INIT, 0);
00044 
00045         if(sensors_status & BUTTON_STATUS_ACTIVE){
00046                 SENSORS_ACTIVATE(button_sensor);
00047         }
00048         if(sensors_status & TEMP_STATUS_ACTIVE){
00049                 SENSORS_ACTIVATE(temperature_sensor);
00050         }
00051         if(sensors_status & ACC_STATUS_ACTIVE){
00052                 SENSORS_ACTIVATE(acc_sensor);
00053         }
00054 }