Added SHT11 driver for TMote.
[sos-2x.git] / modules / include / VM / DvmConstants.h
blobda0137b4b479422013c6fe7b1f6087e45b7ae980
1 #ifndef _DVM_CONSTANTS_H_
2 #define _DVM_CONSTANTS_H_
4 #include <mod_pid.h>
5 #include <message_types.h>
6 #include "codesend.h"
8 #define ASVM_LIB_MIN_PID 200
9 #define LIB_ID_BIT 0x80
10 #define BASIC_LIB_OP_MASK 0x7F
11 #define EXT_LIB_OP_MASK 0x1F
12 #define EXT_LIB_OP_SHIFT 5
14 enum {
15 DVM_OPDEPTH = 8,
16 DVM_BUF_LEN = 64, //Ram - This has to be 64 for outlier detection//32,//20
17 DVM_CAPSULE_SIZE = 28,
18 DVM_CAPSULE_NUM = 8,
19 DVM_CPU_SLICE = 50,
20 DVM_NUM_SHARED_VARS = 8,
21 DVM_NUM_LOCAL_VARS = 5,//4
22 DVM_NUM_BUFS = 4,
23 DVM_LOCK_COUNT = DVM_NUM_SHARED_VARS + DVM_NUM_BUFS,
24 DVM_MAX_SCRIPT_LENGTH = 255,
27 enum {
28 DVM_ALL = 0,
29 DVM_STACK = 1,
30 DVM_SCRIPT = 2,
31 DVM_LOCALVARS = 3,
34 typedef enum {
35 DVM_TYPE_NONE = 0,
36 DVM_TYPE_BUFFER = 1,
37 DVM_TYPE_INTEGER = 3,
38 DVM_TYPE_UINT32_LSB= 4,
39 DVM_TYPE_UINT32_MSB= 5,
40 DVM_TYPE_FLOAT_DEC = 6,
41 DVM_TYPE_FLOAT = 7,
42 DVM_TYPE_MSBPHOTO = 48,
43 DVM_TYPE_MSBTEMP = 49,
44 DVM_TYPE_MSBMIC = 50,
45 DVM_TYPE_MSBMAGX = 51,
46 DVM_TYPE_MSBMAGY = 52,
47 DVM_TYPE_MSBACCELX = 53,
48 DVM_TYPE_MSBACCELY = 54,
49 DVM_TYPE_THUM = 55,
50 DVM_TYPE_TTEMP = 56,
51 DVM_TYPE_TPAR = 57,
52 DVM_TYPE_TTSR = 58,
53 DVM_TYPE_END = 59
54 } DvmDataType;
56 typedef enum {
57 DVM_STATE_HALT,
58 DVM_STATE_WAITING,
59 DVM_STATE_READY,
60 DVM_STATE_RUN,
61 DVM_STATE_BLOCKED,
62 } DvmContextState;
64 typedef enum {
65 DVM_ERROR_TRIGGERED,
66 DVM_ERROR_INVALID_RUNNABLE,
67 DVM_ERROR_STACK_UNDERFLOW,
68 DVM_ERROR_BUFFER_OVERFLOW,
69 DVM_ERROR_BUFFER_UNDERFLOW,
70 DVM_ERROR_STACK_OVERFLOW,
71 DVM_ERROR_INDEX_OUT_OF_BOUNDS,
72 DVM_ERROR_INSTRUCTION_RUNOFF,
73 DVM_ERROR_LOCK_INVALID,
74 DVM_ERROR_LOCK_STEAL,
75 DVM_ERROR_UNLOCK_INVALID,
76 DVM_ERROR_QUEUE_ENQUEUE,
77 DVM_ERROR_QUEUE_DEQUEUE,
78 DVM_ERROR_QUEUE_REMOVE,
79 DVM_ERROR_QUEUE_INVALID,
80 DVM_ERROR_RSTACK_OVERFLOW,
81 DVM_ERROR_RSTACK_UNDERFLOW,
82 DVM_ERROR_INVALID_ACCESS,
83 DVM_ERROR_TYPE_CHECK,
84 DVM_ERROR_INVALID_TYPE,
85 DVM_ERROR_INVALID_LOCK,
86 DVM_ERROR_INVALID_INSTRUCTION,
87 DVM_ERROR_INVALID_SENSOR,
88 DVM_ERROR_INVALID_HANDLER,
89 DVM_ERROR_ARITHMETIC,
90 DVM_ERROR_SENSOR_FAIL,
91 } DvmErrorCode;
93 /*enum {
94 AM_DVMUARTMSG = (MOD_MSG_START + 40),
95 AM_DVMBCASTMSG = (MOD_MSG_START + 41),
96 AM_DVMROUTEMSG = (MOD_MSG_START + 42),
97 AM_DVMVERSIONMSG = (MOD_MSG_START + 43),
98 AM_DVMVERSIONREQUESTMSG= (MOD_MSG_START + 44),
99 AM_DVMERRORMSG = (MOD_MSG_START + 45),
100 AM_DVMCAPSULEMSG = (MOD_MSG_START + 46),
101 AM_DVMPACKETMSG = (MOD_MSG_START + 47),
102 AM_DVMCAPSULECHUNKMSG = (MOD_MSG_START + 48),
103 AM_DVMCAPSULESTATUSMSG = (MOD_MSG_START + 49),
107 #define DVM_ERROR_MSG (MOD_MSG_START + 45)
109 #define TRUE 1
110 #define FALSE 0
112 //Functions provided by DVM Engine
113 #define SUBMIT 0
114 #define ERROR 1
115 #define REBOOT 2
117 //Functions provided by Concurrency Manager
118 #define ANALYZEVARS 0
119 #define ANALYZECALLS 1
120 #define CLEARANALYSIS 2
121 #define INITIALIZECONTEXT 3
122 #define YIELDCONTEXT 4
123 #define HALTCONTEXT 5
124 #define RESUMECONTEXT 6
125 #define ISHELDBY 7
126 #define RESET 8
128 //Functions provided by Handler Store
129 #define INITIALIZEHANDLER 0
130 #define GETCODELENGTH 1
131 #define GETOPCODE 2
132 #define GETLIBMASK 3
133 #define GETSTATEBLOCK 4
134 #define STARTSCRIPTTIMER 5
136 //Functions provided by MStacks
137 #define RESETSTACKS 0
138 #define PUSHVALUE 1
139 #define PUSHBUFFER 2
140 #define PUSHOPERAND 3
141 #define POPOPERAND 4
142 #define SETSTACK 5
144 //Functions provided by Resource manager
145 #define ALLOCATEMEM 0
146 #define FREEMEM 1
148 //Functions provided by Buffer
149 #define BUFFER_EXECUTE 0
151 //Functions provided by Mathlib
152 #define MATHLIB_EXECUTE 0
154 //Functions provided by Basiclib
155 #define BYTELENGTH 0
156 #define LOCKNUM 1
157 #define REBOOTED 2
158 #define SETLOCALVAR 3
159 #define EXECUTE 4
161 //Functions provided by Queue
162 #define Q_INIT 0
163 #define Q_EMPTY 1
164 #define Q_ENQUEUE 2
165 #define Q_DEQUEUE 3
166 #define Q_REMOVE 4
168 //provided by scriptable modules
169 #define EXECUTE_SYNCALL 0
171 //May be provided by Typecheck module
172 #define CHECKTYPES 0
173 #define CHECKMATCH 1
174 #define CHECKVALUE 2
175 #define CHECKINTEGER 3
176 #define ISINTEGER 4
177 #define ISVALUE 5
178 #define ISTYPE 6
180 //Module IDs in DVM
182 #define M_CONTEXT_SYNCH (ASVM_MOD_MIN_PID + 0)
183 #define DVM_ENGINE_M (ASVM_MOD_MIN_PID + 1)
184 #define M_STACKS (ASVM_MOD_MIN_PID + 2)
185 #define M_HANDLER_STORE (ASVM_MOD_MIN_PID + 3)
186 #define M_BUFFER (ASVM_MOD_MIN_PID + 4)
187 #define M_MATHLIB (ASVM_MOD_MIN_PID + 5)
188 #define M_RESOURCE_MANAGER (ASVM_MOD_MIN_PID + 6)
189 #define M_BASIC_LIB (ASVM_MOD_MIN_PID + 7)
190 #define M_QUEUE (ASVM_MOD_MIN_PID + 8)
194 //Extension Libraries
195 #define M_EXT_LIB (ASVM_LIB_MIN_PID + 0)
196 #define M_MATH_LIB (ASVM_LIB_MIN_PID + 1)
197 #define M_RAGO_LIB (ASVM_LIB_MIN_PID + 2)
200 #define MSG_RUN_TASK (MOD_MSG_START + 0)
201 #define MSG_HALT (MOD_MSG_START + 1)
202 #define MSG_RESUME (MOD_MSG_START + 2)
203 #define MSG_VERSION_TIMER_TASK (MOD_MSG_START + 3)
204 #define MSG_CAPSULE_TIMER_TASK (MOD_MSG_START + 4)
205 #define MSG_CHECK_NEED_TASK (MOD_MSG_START + 5)
206 #define MSG_ADD_LIBRARY (MOD_MSG_START + 6)
207 #define MSG_REMOVE_LIBRARY (MOD_MSG_START + 7)
209 #define POST_EXECUTE (MOD_MSG_START + 10)
211 #define SUBSCRIBE_TIMER 128
212 #define ERROR_TIMER 129
213 #define VERSION_TIMER 130
214 #define CAPSULE_TIMER 131
215 #define CLOCK_TIMER 132
218 * MVirus uses the Trickle algorithm for code propagation and maintenance.
219 * A full description and evaluation of the algorithm can be found in
221 * Philip Levis, Neil Patel, David Culler, and Scott Shenker.
222 * "Trickle: A Self-Regulating Algorithm for Code Propagation and Maintenance
223 * in Wireless Sensor Networks." In Proceedings of the First USENIX/ACM
224 * Symposium on Networked Systems Design and Implementation (NSDI 2004).
226 * A copy of the paper can be downloaded from Phil Levis' web site:
227 * http://www.cs.berkeley.edu/~pal/
229 * A brief description of the algorithm can be found in the comments
230 * at the head of MVirus.c.
234 typedef enum {
235 /* These first two constants define the granularity at which t values
236 are calculated (in ms). Version vectors and capsules have separate
237 timers, as version timers decay (lengthen) while capsules timers
238 are constant, as they are not a continuous process.*/
239 MVIRUS_VERSION_TIMER = 100, // The units of time (ms)
240 MVIRUS_CAPSULE_TIMER = 100, // The units of time (ms)
242 /* These constants define how many times a capsule is transmitted,
243 the timer interval for Trickle suppression, and the redundancy constant
244 k. Due to inherent loss, having a repeat > 1 is preferrable, although
245 it should be small. It's better to broadcast the data twice rather
246 than require another metadata announcement to trigger another
247 transmission. It's not clear whether REDUNDANCY should be > or = to
248 REPEAT. In either case, both constants should be small (e.g, 2-4). */
250 MVIRUS_CAPSULE_REPEAT = 2, // How many times to repeat a capsule
251 MVIRUS_CAPSULE_TAU = 10, // Capsules have a fixed tau
252 MVIRUS_CAPSULE_REDUNDANCY = 2, // Capsule redundancy (suppression pt.)
254 /* These constants define the minimum and maximum tau values for
255 version vector exchange, as well as the version vector redundancy
256 constant k. Note that the tau values are in terms of multiples
257 of the TIMER value above (e.g., a MIN of 10 and a TIMER of 100
258 means a MIN of 1000 ms, or one second). */
259 MVIRUS_VERSION_TAU_MIN = 10, // Version scaling tau minimum
260 MVIRUS_VERSION_TAU_MAX = 600, // Version scaling tau maximum
261 MVIRUS_VERSION_REDUNDANCY = 1, // Version redundancy (suppression pt.)
263 /* These constants are all for sending data larger than a single
264 packet; they define the size of a program chunk, bitmasks, etc.*/
265 MVIRUS_CAPSULE_HEADER_SIZE = 4,
266 MVIRUS_CHUNK_SIZE = DVM_CAPSULE_SIZE + MVIRUS_CAPSULE_HEADER_SIZE,
267 MVIRUS_BITMASK_ENTRIES = ((DVM_CAPSULE_SIZE + MVIRUS_CHUNK_SIZE - 1) / MVIRUS_CHUNK_SIZE),
268 MVIRUS_BITMASK_SIZE = (MVIRUS_BITMASK_ENTRIES + 7) / 8,
269 } MVirusConstants;
279 #endif