Added SHT11 driver for TMote.
[sos-2x.git] / modules / include / VM / Dvm.h
blobeaf0e5cc7c5da569f3385b024869a0e4f100ac57
1 /* tab:4
4 * "Copyright (c) 2000-2004 The Regents of the University of California.
5 * All rights reserved.
7 * Permission to use, copy, modify, and distribute this software and
8 * its documentation for any purpose, without fee, and without written
9 * agreement is hereby granted, provided that the above copyright
10 * notice, the following two paragraphs and the author appear in all
11 * copies of this software.
13 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY
14 * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
15 * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
16 * DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN
17 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
22 * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
23 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
26 /* tab:4
27 * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
28 * downloading, copying, installing or using the software you agree to
29 * this license. If you do not agree to this license, do not download,
30 * install, copy or use the software.
32 * Intel Open Source License
34 * Copyright (c) 2004 Intel Corporation
35 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions are
38 * met:
40 * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
45 * Neither the name of the Intel Corporation nor the names of its
46 * contributors may be used to endorse or promote products derived from
47 * this software without specific prior written permission.
49 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
50 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
51 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
52 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
53 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
54 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
55 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
56 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
57 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
58 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
59 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 /* Authors: Rahul Balani
64 * History: April 2005 Ported to sos
65 * November 2005 Modifications for new design
68 /**
69 * @author Rahul Balani
73 #ifndef _DVM_H_
74 #define _DVM_H_
76 #include <stddef.h>
77 #include <sos_list.h>
78 #include <string.h>
79 #include <codemem.h>
80 #include "DvmConstants.h"
82 typedef uint8_t DvmOpcode;
83 typedef uint16_t DvmCapsuleLength;
84 typedef uint32_t DvmCapsuleVersion;
86 typedef struct {
87 list_t queue;
88 } __attribute__((packed)) DvmQueue;
90 typedef struct {
91 int16_t var;
92 } __attribute__((packed)) DvmValueVariable;
94 typedef struct {
95 uint8_t size;
96 uint8_t entries[DVM_BUF_LEN];
97 } __attribute__((packed)) DvmDataBuffer;
99 typedef struct {
100 DvmDataBuffer* var;
101 } DvmBufferVariable;
103 typedef struct {
104 uint8_t type;
105 union {
106 DvmValueVariable value;
107 DvmBufferVariable buffer;
109 } __attribute__((packed)) DvmStackVariable;
112 typedef struct {
113 DvmOpcode data[DVM_CAPSULE_SIZE];
114 } DvmEventType;
117 typedef struct {
118 uint8_t sp;
119 DvmStackVariable stack[DVM_OPDEPTH];
120 } __attribute__((packed)) DvmOperandStack;
122 /* A DvmCapsule is the unit of propagation. */
124 typedef struct {
125 //DvmCapsuleOption options;
126 DvmCapsuleLength dataSize;
127 int8_t data[DVM_CAPSULE_SIZE];
128 } __attribute__((packed)) DvmCapsule;
131 typedef struct {
132 uint8_t moduleID; // Event information
133 uint8_t type;
134 DvmCapsuleLength dataSize; // Size of script in bytes
135 uint8_t libraryMask; // Indicates required libraries
136 uint16_t pc; // Current pc value
137 uint8_t state; // Context state
138 DvmCapsuleID which; // Context ID
139 uint8_t heldSet[(DVM_LOCK_COUNT + 7) / 8]; // Held locks
140 uint8_t releaseSet[(DVM_LOCK_COUNT + 7) / 8]; // Pending lock releases
141 uint8_t acquireSet[(DVM_LOCK_COUNT + 7) / 8]; // Locks to acquire
142 list_link_t link; // Link entry for wait queues
143 DvmQueue* queue; // Current wait queue
144 uint16_t num_executed;
145 uint8_t *init_data; // Initial data attached with an event message
146 uint8_t init_size;
147 } __attribute__((packed)) DvmContext;
149 typedef struct {
150 DvmContext context;
151 DvmOperandStack stack;
152 DvmStackVariable vars[DVM_NUM_LOCAL_VARS];
153 codemem_t cm; // the handle to codemem
154 } DvmState;
156 typedef struct {
157 DvmContext* holder;
158 } __attribute__((packed)) DvmLock;
160 typedef struct DvmErrorMsg {
161 uint8_t context;
162 uint8_t reason;
163 uint8_t capsule;
164 uint8_t instruction;
165 uint16_t me;
166 } __attribute__((packed)) DvmErrorMsg;
168 typedef struct DvmTrickleTimer {
169 uint16_t elapsed; // Current time (in ticks)
170 uint16_t threshold; // Time to consider transmitting (in ticks) (t)
171 uint16_t interval; // Size of current interval (in ticks) (tau)
172 uint16_t numHeard; // Number of messages heard (c)
173 } __attribute__((packed)) DvmTrickleTimer;
175 typedef struct {
176 sos_pid_t destModID; // lddata requirement: destination module ID
177 uint8_t capsuleID; // lddata requirement: data ID
178 sos_pid_t moduleID;
179 uint8_t eventType;
180 DvmCapsuleLength length;
181 uint8_t libraryMask;
182 uint8_t data[DVM_MAX_SCRIPT_LENGTH];
183 } __attribute__((packed)) DvmScript;
185 typedef struct {
186 DvmCapsuleVersion version;
187 uint8_t capsuleNum;
188 uint8_t piece;
189 uint8_t chunk[MVIRUS_CHUNK_SIZE];
190 } __attribute__((packed)) DvmCapsuleChunkMsg;
192 typedef struct {
193 DvmCapsuleVersion versions[DVM_CAPSULE_NUM];
194 } __attribute__((packed)) DvmVersionMsg;
196 typedef struct {
197 DvmCapsuleVersion version;
198 uint8_t capsuleNum;
199 uint8_t bitmask[MVIRUS_BITMASK_SIZE];
200 } __attribute__((packed)) DvmCapsuleStatusMsg;
202 #endif