From 9a5bac6282f125310f23a9c51280fb291d8f692c Mon Sep 17 00:00:00 2001 From: adamdunkels Date: Tue, 22 May 2007 20:59:11 +0000 Subject: [PATCH] Added energy estimation --- cpu/msp430/cc2420_uart0.c | 55 +++++++++++++++++++++------------------ cpu/msp430/clock.c | 5 +++- cpu/msp430/dev/uart1.c | 5 +++- cpu/msp430/slip_uart1.c | 9 ++++--- 4 files changed, 43 insertions(+), 31 deletions(-) diff --git a/cpu/msp430/cc2420_uart0.c b/cpu/msp430/cc2420_uart0.c index 0498d85e0..6e963c8f8 100644 --- a/cpu/msp430/cc2420_uart0.c +++ b/cpu/msp430/cc2420_uart0.c @@ -1,32 +1,32 @@ /* * Copyright (c) 2006, Swedish Institute of Computer Science - * All rights reserved. + * 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. + * 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 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. * - * @(#)$Id: cc2420_uart0.c,v 1.2 2006/08/17 15:41:13 bg- Exp $ + * @(#)$Id: cc2420_uart0.c,v 1.3 2007/05/22 20:59:11 adamdunkels Exp $ */ #include @@ -41,13 +41,16 @@ interrupt(PORT1_VECTOR) __fifop_interrupt(void) { - if(__cc2420_intr()) + ENERGEST_ON(ENERGEST_TYPE_IRQ); + if(__cc2420_intr()) { LPM4_EXIT; + } + ENERGEST_OFF(ENERGEST_TYPE_IRQ); } void __cc2420_arch_init(void) -{ +{ spi_init(); P4DIR |= BV(CSN) | BV(VREG_EN) | BV(RESET_N); diff --git a/cpu/msp430/clock.c b/cpu/msp430/clock.c index 64af12754..53d6bf3f8 100644 --- a/cpu/msp430/clock.c +++ b/cpu/msp430/clock.c @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * @(#)$Id: clock.c,v 1.6 2007/04/02 16:32:20 joxe Exp $ + * @(#)$Id: clock.c,v 1.7 2007/05/22 20:59:27 adamdunkels Exp $ */ @@ -37,6 +37,7 @@ #include "contiki-conf.h" +#include "lib/energest.h" #include "sys/clock.h" #include "sys/etimer.h" @@ -50,6 +51,7 @@ static volatile clock_time_t count = 0; static unsigned short last_tar = 0; /*---------------------------------------------------------------------------*/ interrupt(TIMERA1_VECTOR) timera1 (void) { + ENERGEST_ON(ENERGEST_TYPE_IRQ); if(TAIV == 2) { TACCR1 += INTERVAL; last_tar = TAR; @@ -61,6 +63,7 @@ interrupt(TIMERA1_VECTOR) timera1 (void) { LPM4_EXIT; } } + ENERGEST_OFF(ENERGEST_TYPE_IRQ); } /*---------------------------------------------------------------------------*/ clock_time_t diff --git a/cpu/msp430/dev/uart1.c b/cpu/msp430/dev/uart1.c index 1094e421f..7c0d6f987 100644 --- a/cpu/msp430/dev/uart1.c +++ b/cpu/msp430/dev/uart1.c @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)$Id: uart1.c,v 1.1 2007/03/15 21:37:19 adamdunkels Exp $ + * @(#)$Id: uart1.c,v 1.2 2007/05/22 21:01:51 adamdunkels Exp $ */ /* @@ -36,6 +36,7 @@ #include #include +#include "lib/energest.h" #include "dev/uart1.h" /*---------------------------------------------------------------------------*/ @@ -110,6 +111,7 @@ uart1_init(unsigned long ubr) interrupt(UART1RX_VECTOR) uart1_interrupt(void) { + ENERGEST_ON(ENERGEST_TYPE_IRQ); /* Check status register for receive errors. */ if(URCTL1 & RXERR) { volatile unsigned dummy; @@ -119,5 +121,6 @@ uart1_interrupt(void) LPM4_EXIT; }*/ } + ENERGEST_OFF(ENERGEST_TYPE_IRQ); } /*---------------------------------------------------------------------------*/ diff --git a/cpu/msp430/slip_uart1.c b/cpu/msp430/slip_uart1.c index 8b9ba4b77..30db74362 100644 --- a/cpu/msp430/slip_uart1.c +++ b/cpu/msp430/slip_uart1.c @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)$Id: slip_uart1.c,v 1.6 2007/03/29 23:43:59 adamdunkels Exp $ + * @(#)$Id: slip_uart1.c,v 1.7 2007/05/22 21:00:27 adamdunkels Exp $ */ /* @@ -136,12 +136,15 @@ slip_arch_init(unsigned long ubr) interrupt(UART1RX_VECTOR) __uart1_intr() { + ENERGEST_ON(ENERGEST_TYPE_IRQ); /* Check status register for receive errors. */ - if (URCTL1 & RXERR) { + if(URCTL1 & RXERR) { volatile unsigned dummy; dummy = RXBUF1; /* Clear error flags by forcing a dummy read. */ } else { - if(slip_input_byte(RXBUF1)) + if(slip_input_byte(RXBUF1)) { LPM4_EXIT; + } } + ENERGEST_OFF(ENERGEST_TYPE_IRQ); }