diff --git a/core/dev/leds.c b/core/dev/leds.c index b18eccb89..6394826f1 100644 --- a/core/dev/leds.c +++ b/core/dev/leds.c @@ -28,11 +28,12 @@ * * This file is part of the Contiki operating system. * - * @(#)$Id: leds.c,v 1.3 2006/10/09 14:38:23 nifi Exp $ + * @(#)$Id: leds.c,v 1.4 2007/03/19 00:33:25 adamdunkels Exp $ */ #include "dev/leds.h" #include "sys/clock.h" +#include "lib/energest.h" static unsigned char leds, invert; /*---------------------------------------------------------------------------*/ @@ -68,6 +69,16 @@ leds_get(void) { void leds_on(unsigned char l) { + if((l & LEDS_GREEN) && !(leds & LEDS_GREEN)) { + ENERGEST_ON(ENERGEST_TYPE_LED_GREEN); + } + if((l & LEDS_YELLOW) && !(leds & LEDS_YELLOW)) { + ENERGEST_ON(ENERGEST_TYPE_LED_YELLOW); + } + if((l & LEDS_RED) && !(leds & LEDS_RED)) { + ENERGEST_ON(ENERGEST_TYPE_LED_RED); + } + leds |= l; show_leds(); } @@ -75,6 +86,16 @@ leds_on(unsigned char l) void leds_off(unsigned char l) { + + if((l & LEDS_GREEN) && (leds & LEDS_GREEN)) { + ENERGEST_OFF(ENERGEST_TYPE_LED_GREEN); + } + if((l & LEDS_YELLOW) && (leds & LEDS_YELLOW)) { + ENERGEST_OFF(ENERGEST_TYPE_LED_YELLOW); + } + if((l & LEDS_RED) && (leds & LEDS_RED)) { + ENERGEST_OFF(ENERGEST_TYPE_LED_RED); + } leds &= ~l; show_leds(); } diff --git a/core/lib/energest.c b/core/lib/energest.c new file mode 100644 index 000000000..321ab9113 --- /dev/null +++ b/core/lib/energest.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2007, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + * $Id: energest.c,v 1.1 2007/03/19 00:30:13 adamdunkels Exp $ + */ + +/** + * \file + * A brief description of what this file is. + * \author + * Adam Dunkels + */ + +#include "lib/energest.h" + +#if ENERGEST_CONF_ON + +energest_t energest_total_time[ENERGEST_TYPE_MAX]; +energest_t energest_current_time[ENERGEST_TYPE_MAX]; + +/*---------------------------------------------------------------------------*/ +void +energest_init(void) +{ + int i; + for(i = 0; i < ENERGEST_TYPE_MAX; ++i) { + energest_total_time[i] = 0; + } +} +/*---------------------------------------------------------------------------*/ +energest_t +energest_type_time(int type) +{ + return energest_total_time[type]; +} +/*---------------------------------------------------------------------------*/ +#else /* ENERGEST_CONF_ON */ +void energest_init(void) {} +energest_t energest_type_time(int type) { return 0; } +#endif /* ENERGEST_CONF_ON */ diff --git a/core/lib/energest.h b/core/lib/energest.h new file mode 100644 index 000000000..bdace4dd9 --- /dev/null +++ b/core/lib/energest.h @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2007, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + * $Id: energest.h,v 1.1 2007/03/19 00:30:18 adamdunkels Exp $ + */ + +/** + * \file + * A brief description of what this file is. + * \author + * Adam Dunkels + */ + +#ifndef __ENERGEST_H__ +#define __ENERGEST_H__ + +typedef unsigned long energest_t; + +enum { + ENERGEST_TYPE_NONE, + + ENERGEST_TYPE_CPU, + ENERGEST_TYPE_LPM1, + ENERGEST_TYPE_LPM2, + ENERGEST_TYPE_LPM3, + ENERGEST_TYPE_LPM4, + ENERGEST_TYPE_LED_GREEN, + ENERGEST_TYPE_LED_YELLOW, + ENERGEST_TYPE_LED_RED, + ENERGEST_TYPE_TRANSMIT, + ENERGEST_TYPE_RECEIVE, + + ENERGEST_TYPE_SENSORS, + + ENERGEST_TYPE_MAX +} energest_type; + +void energest_init(void); +energest_t energest_type_time(int type); + +#if ENERGEST_CONF_ON +extern energest_t energest_total_time[ENERGEST_TYPE_MAX]; +extern energest_t energest_current_time[ENERGEST_TYPE_MAX]; + +#define ENERGEST_ON(type) do { \ + energest_current_time[type] = energest_arch_now(); \ + } while(0) +#define ENERGEST_OFF(type) do { \ + energest_total_time[type] += energest_arch_now() - \ + energest_current_time[type]; \ + } while(0) +#else /* ENERGEST_CONF_ON */ +#define ENERGEST_ON(type) do { } while(0) +#define ENERGEST_OFF(type) do { } while(0) +#endif /* ENERGEST_CONF_ON */ + +energest_t energest_arch_current_estimate(void); +energest_t energest_arch_now(void); + +#endif /* __ENERGEST_H__ */ diff --git a/platform/esb/dev/esb-sensors.c b/platform/esb/dev/esb-sensors.c index 8d99524b0..0075b6a41 100644 --- a/platform/esb/dev/esb-sensors.c +++ b/platform/esb/dev/esb-sensors.c @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: esb-sensors.c,v 1.1 2006/06/18 07:49:33 adamdunkels Exp $ + * $Id: esb-sensors.c,v 1.2 2007/03/19 00:34:43 adamdunkels Exp $ */ /** @@ -44,6 +44,7 @@ #include "contiki-esb.h" HWCONF_PIN(SENSORSWITCH, 5, 5); + /*---------------------------------------------------------------------------*/ void esb_sensors_init(void) @@ -56,11 +57,13 @@ void esb_sensors_on(void) { SENSORSWITCH_CLEAR(); + ENERGEST_ON(ENERGEST_TYPE_SENSORS); } /*---------------------------------------------------------------------------*/ void esb_sensors_off(void) { SENSORSWITCH_SET(); + ENERGEST_OFF(ENERGEST_TYPE_SENSORS); } /*---------------------------------------------------------------------------*/ diff --git a/platform/esb/dev/tr1001-gcr.c b/platform/esb/dev/tr1001-gcr.c index d1daaca41..2e279f02e 100644 --- a/platform/esb/dev/tr1001-gcr.c +++ b/platform/esb/dev/tr1001-gcr.c @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * @(#)$Id: tr1001-gcr.c,v 1.6 2007/03/15 21:57:35 adamdunkels Exp $ + * @(#)$Id: tr1001-gcr.c,v 1.7 2007/03/19 00:35:23 adamdunkels Exp $ */ /** * \addtogroup esb @@ -224,6 +224,8 @@ radio_off(void) onoroff = OFF; rxoff(); rxclear(); + + ENERGEST_OFF(ENERGEST_TYPE_RECEIVE); } /*---------------------------------------------------------------------------*/ /* @@ -233,6 +235,8 @@ radio_off(void) void radio_on(void) { + ENERGEST_ON(ENERGEST_TYPE_RECEIVE); + onoroff = ON; rxon(); rxclear(); @@ -618,6 +622,8 @@ tr1001_send(u8_t *packet, u16_t len) LOG("tr1001_send: sending %d bytes\n", len); + ENERGEST_ON(ENERGEST_TYPE_TRANSMIT); + /* Prepare the transmission. */ prepare_transmission(NUM_SYNCHBYTES); @@ -664,6 +670,8 @@ tr1001_send(u8_t *packet, u16_t len) rxclear(); } + ENERGEST_OFF(ENERGEST_TYPE_TRANSMIT); + return UIP_FW_OK; } /*---------------------------------------------------------------------------*/