Contiki 2.5
timetable.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, Swedish Institute of Computer Science.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  *
31  * $Id: timetable.h,v 1.2 2008/02/28 22:11:30 oliverschmidt Exp $
32  */
33 
34 /**
35  * \file
36  * A brief description of what this file is.
37  * \author
38  * Adam Dunkels <adam@sics.se>
39  */
40 
41 #ifndef __TIMETABLE_H__
42 #define __TIMETABLE_H__
43 
44 #include "sys/cc.h"
45 #include "sys/rtimer.h"
46 
47 
48 struct timetable_timestamp {
49  const char *id;
50  rtimer_clock_t time;
51 #if TIMETABLE_WITH_TYPE
52  uint8_t type;
53 #endif /* TIMETABLE_WITH_TYPE */
54 };
55 struct timetable {
56  struct timetable_timestamp *timestamps;
57  const int size;
58  unsigned int * const ptr;
59 };
60 
61 #define TIMETABLE_NONSTATIC(name) \
62 struct timetable_timestamp CC_CONCAT(name,_timestamps)[CC_CONCAT(name,_size)]; \
63 unsigned int CC_CONCAT(name,_ptr); \
64 struct timetable name = { \
65  CC_CONCAT(name,_timestamps), \
66  CC_CONCAT(name,_size), \
67  &CC_CONCAT(name,_ptr)}
68 
69 #define TIMETABLE_STATIC(name) \
70 static struct timetable_timestamp CC_CONCAT(name,_timestamps)[CC_CONCAT(name,_size)]; \
71 static unsigned int CC_CONCAT(name,_ptr); \
72 static struct timetable name = { \
73  CC_CONCAT(name,_timestamps), \
74  CC_CONCAT(name,_size), \
75  &CC_CONCAT(name,_ptr)}
76 
77 #define TIMETABLE_DECLARE(name) \
78 extern unsigned int CC_CONCAT(name,_ptr); \
79 extern struct timetable_timestamp CC_CONCAT(name, _timestamps)[CC_CONCAT(name,_size)]; \
80 extern struct timetable name
81 
82 #define TIMETABLE(name) TIMETABLE_STATIC(name)
83 
84 #define TIMETABLE_TIMESTAMP(name, str) \
85 do { \
86  CC_CONCAT(name,_timestamps)[CC_CONCAT(name,_ptr)].id = str; \
87  CC_CONCAT(name,_timestamps)[CC_CONCAT(name,_ptr)].time = RTIMER_NOW(); \
88  CC_CONCAT(name,_ptr) = (CC_CONCAT(name,_ptr) + 1) % \
89  CC_CONCAT(name,_size); \
90 } while(0)
91 
92 #if TIMETABLE_WITH_TYPE
93 #define TIMETABLE_TIMESTAMP_TYPE(name, str, t) \
94 do { \
95  CC_CONCAT(name,_timestamps)[CC_CONCAT(name,_ptr)].id = str; \
96  CC_CONCAT(name,_timestamps)[CC_CONCAT(name,_ptr)].type = t; \
97  CC_CONCAT(name,_timestamps)[CC_CONCAT(name,_ptr)].time = RTIMER_NOW(); \
98  CC_CONCAT(name,_ptr) = (CC_CONCAT(name,_ptr) + 1) % \
99  CC_CONCAT(name,_size); \
100 } while(0)
101 #else /* TIMETABLE_WITH_TYPE */
102 #define TIMETABLE_TIMESTAMP_TYPE(name, str, t) TIMETABLE_TIMESTAMP(name, str)
103 #endif /* TIMETABLE_WITH_TYPE */
104 
105 
106 #define TIMETABLE_RESUME(name,num) \
107  TIMETABLE_TIMESTAMP(CC_CONCAT(name,_timestamps[num].id))
108 
109 #define TIMETABLE_COND_TIMESTAMP(cond,name,id) \
110  do { if(cond) { \
111  TIMETABLE_TIMESTAMP(id); \
112  } while(0)
113 
114 #define TIMETABLE_COND_RESUME(cond,name,num) \
115  TIMETABLE_COND_TIMESTAMP(cond,name, \
116  CC_CONCAT(name,_timestamps[num].id))
117 
118 #define TIMETABLE_ENTRY(name, num) CC_CONCAT(name,_timestamps)[num]
119 #define TIMETABLE_PTR(name) CC_CONCAT(name,_ptr)
120 
121 /**
122  * The time for taking a timestamp.
123  */
124 extern rtimer_clock_t timetable_timestamp_time;
125 
126 
127 struct timetable_timestamp *timetable_entry(struct timetable *t,
128  int num);
129 int timetable_ptr(struct timetable *t);
130 
131 void timetable_clear(struct timetable *t);
132 rtimer_clock_t timetable_timediff(struct timetable *t,
133  const char *id1, const char *id2);
134 void timetable_init(void);
135 
136 void timetable_print(struct timetable *t);
137 
138 #include "sys/timetable-aggregate.h"
139 
140 #endif /* __TIMETABLE_H__ */