Contiki 2.6
|
00001 /* 00002 * Copyright (c) 2010, 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 */ 00032 00033 /** 00034 * \file 00035 * Common functionality for phase optimization in duty cycling radio protocols 00036 * \author 00037 * Adam Dunkels <adam@sics.se> 00038 */ 00039 00040 #ifndef PHASE_H 00041 #define PHASE_H 00042 00043 #include "net/rime/rimeaddr.h" 00044 #include "sys/timer.h" 00045 #include "sys/rtimer.h" 00046 #include "lib/list.h" 00047 #include "lib/memb.h" 00048 #include "net/netstack.h" 00049 00050 #if PHASE_CONF_DRIFT_CORRECT 00051 #define PHASE_DRIFT_CORRECT PHASE_CONF_DRIFT_CORRECT 00052 #else 00053 #define PHASE_DRIFT_CORRECT 0 00054 #endif 00055 00056 struct phase { 00057 struct phase *next; 00058 rimeaddr_t neighbor; 00059 rtimer_clock_t time; 00060 #if PHASE_DRIFT_CORRECT 00061 rtimer_clock_t drift; 00062 #endif 00063 uint8_t noacks; 00064 struct timer noacks_timer; 00065 }; 00066 00067 struct phase_list { 00068 list_t *list; 00069 struct memb *memb; 00070 }; 00071 00072 typedef enum { 00073 PHASE_UNKNOWN, 00074 PHASE_SEND_NOW, 00075 PHASE_DEFERRED, 00076 } phase_status_t; 00077 00078 00079 #define PHASE_LIST(name, num) LIST(phase_list_list); \ 00080 MEMB(phase_list_memb, struct phase, num); \ 00081 struct phase_list name = { &phase_list_list, &phase_list_memb } 00082 00083 void phase_init(struct phase_list *list); 00084 phase_status_t phase_wait(struct phase_list *list, const rimeaddr_t *neighbor, 00085 rtimer_clock_t cycle_time, rtimer_clock_t wait_before, 00086 mac_callback_t mac_callback, void *mac_callback_ptr, 00087 struct rdc_buf_list *buf_list); 00088 void phase_update(const struct phase_list *list, const rimeaddr_t *neighbor, 00089 rtimer_clock_t time, int mac_status); 00090 00091 void phase_remove(const struct phase_list *list, const rimeaddr_t *neighbor); 00092 00093 #endif /* PHASE_H */