Contiki 2.6
|
00001 /* 00002 * Copyright (c) 2006, Swedish Institute of Computer Science. 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 3. Neither the name of the Institute nor the names of its contributors 00014 * may be used to endorse or promote products derived from this software 00015 * without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 00018 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 00021 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00023 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00024 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00025 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00026 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00027 * SUCH DAMAGE. 00028 * 00029 * This file is part of the Contiki operating system. 00030 * 00031 * Author : Adam Dunkels 00032 */ 00033 00034 #include "contiki.h" 00035 #include "duty-cycle-scroller.h" 00036 #include "lcd.h" 00037 #include "sys/energest.h" 00038 00039 PROCESS(duty_cycle_scroller_process, "Duty cycle scroller"); 00040 00041 static clock_time_t interval; 00042 00043 /*---------------------------------------------------------------------------*/ 00044 PROCESS_THREAD(duty_cycle_scroller_process, ev, data) 00045 { 00046 static struct etimer interval_timer; 00047 int height; 00048 static uint32_t last_cpu, last_lpm, last_transmit, last_listen; 00049 uint32_t cpu, lpm, transmit, listen; 00050 uint32_t all_cpu, all_lpm, all_transmit, all_listen; 00051 uint32_t radio, time; 00052 PROCESS_BEGIN(); 00053 00054 while(1) { 00055 etimer_set(&interval_timer, interval); 00056 PROCESS_WAIT_UNTIL(etimer_expired(&interval_timer)); 00057 lcd_scroll_x(); 00058 00059 all_cpu = energest_type_time(ENERGEST_TYPE_CPU); 00060 all_lpm = energest_type_time(ENERGEST_TYPE_LPM); 00061 all_transmit = energest_type_time(ENERGEST_TYPE_TRANSMIT); 00062 all_listen = energest_type_time(ENERGEST_TYPE_LISTEN); 00063 00064 cpu = all_cpu - last_cpu; 00065 lpm = all_lpm - last_lpm; 00066 transmit = all_transmit - last_transmit; 00067 listen = all_listen - last_listen; 00068 00069 last_cpu = all_cpu; 00070 last_lpm = all_lpm; 00071 last_transmit = all_transmit; 00072 last_listen = all_listen; 00073 00074 radio = transmit + listen; 00075 time = cpu + lpm; 00076 00077 height = 1 + (5 + ((1000 * radio) / time)) / 10; 00078 if(height >= LCD_MAX_SCROLL_AREA) { 00079 height = LCD_MAX_SCROLL_AREA; 00080 } 00081 lcd_draw_vertical_line(height); 00082 } 00083 00084 PROCESS_END(); 00085 } 00086 /*---------------------------------------------------------------------------*/ 00087 void 00088 duty_cycle_scroller_start(clock_time_t i) 00089 { 00090 interval = i; 00091 process_start(&duty_cycle_scroller_process, NULL); 00092 } 00093 /*---------------------------------------------------------------------------*/ 00094 void 00095 duty_cycle_scroller_stop(void) 00096 { 00097 process_exit(&duty_cycle_scroller_process); 00098 } 00099 /*---------------------------------------------------------------------------*/