vm.h
Go to the documentation of this file.
00001 /*
00002         Aseba - an event-based framework for distributed robot control
00003         Copyright (C) 2007--2012:
00004                 Stephane Magnenat <stephane at magnenat dot net>
00005                 (http://stephane.magnenat.net)
00006                 and other contributors, see authors.txt for details
00007         
00008         This program is free software: you can redistribute it and/or modify
00009         it under the terms of the GNU Lesser General Public License as published
00010         by the Free Software Foundation, version 3 of the License.
00011         
00012         This program is distributed in the hope that it will be useful,
00013         but WITHOUT ANY WARRANTY; without even the implied warranty of
00014         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015         GNU Lesser General Public License for more details.
00016         
00017         You should have received a copy of the GNU Lesser General Public License
00018         along with this program. If not, see <http://www.gnu.org/licenses/>.
00019 */
00020 
00021 #ifndef __ASEBA_VM_H
00022 #define __ASEBA_VM_H
00023 
00024 #ifdef __cplusplus
00025 extern "C" {
00026 #endif
00027 
00028 #include "../common/types.h"
00029 
00053 
00054 enum
00055 {
00056         ASEBA_MAX_BREAKPOINTS = 16              
00057 };
00058 
00069 typedef struct
00070 {
00071         // node id
00072         uint16 nodeId;
00073         
00074         // bytecode
00075         uint16 bytecodeSize; 
00076         uint16 * bytecode; 
00078         // variables
00079         uint16 variablesSize; 
00080         sint16 * variables; 
00082         // execution stack
00083         uint16 stackSize; 
00084         sint16 * stack; 
00086         // execution
00087         uint16 flags;
00088         uint16 pc;
00089         sint16 sp;
00090         
00091         // breakpoint
00092         uint16 breakpoints[ASEBA_MAX_BREAKPOINTS];
00093         uint16 breakpointsCount;
00094 } AsebaVMState;
00095 
00096 // Macros to work with masks
00097 
00099 #define AsebaMaskSet(v, m) ((v) |= (m))
00100 
00101 #define AsebaMaskClear(v, m) ((v) &= (~(m)))
00102 
00103 #define AsebaMaskIsSet(v, m) (((v) & (m)) != 0)
00104 
00105 #define AsebaMaskIsClear(v, m) (((v) & (m)) == 0)
00106 
00107 
00108 // Functions provided by aseba-core
00109 
00110 
00116 void AsebaVMInit(AsebaVMState *vm);
00117 
00119 uint16 AsebaVMGetEventAddress(AsebaVMState *vm, uint16 event);
00120 
00124 uint16 AsebaVMSetupEvent(AsebaVMState *vm, uint16 event);
00125 
00130 uint16 AsebaVMRun(AsebaVMState *vm, uint16 stepsLimit);
00131 
00134 void AsebaVMDebugMessage(AsebaVMState *vm, uint16 id, uint16 *data, uint16 dataLength);
00135 
00137 void AsebaVMEmitNodeSpecificError(AsebaVMState *vm, const char* message);
00138 
00140 uint16 AsebaVMShouldDropPacket(AsebaVMState *vm, uint16 source, const uint8* data);
00141 
00142 // Functions implemented outside by the glue/transport layer
00143 
00146 void AsebaSendMessage(AsebaVMState *vm, uint16 id, const void *data, uint16 size);
00147 
00148 #ifdef __BIG_ENDIAN__
00149 
00151 void AsebaSendMessageWords(AsebaVMState *vm, uint16 type, const uint16* data, uint16 count);
00152 #else
00153         #define AsebaSendMessageWords(vm,type,data,size) AsebaSendMessage(vm,type,data,(size)*2)
00154 #endif
00155 
00157 void AsebaSendVariables(AsebaVMState *vm, uint16 start, uint16 length);
00158 
00160 void AsebaSendDescription(AsebaVMState *vm);
00161 
00163 void AsebaNativeFunction(AsebaVMState *vm, uint16 id);
00164 
00166 void AsebaWriteBytecode(AsebaVMState *vm);
00167 
00169 void AsebaResetIntoBootloader(AsebaVMState *vm);
00170 
00172 void AsebaPutVmToSleep(AsebaVMState *vm);
00173 
00175 void __attribute__((weak)) AsebaVMRunCB(AsebaVMState *vm);
00176 
00179 void __attribute__((weak)) AsebaVMErrorCB(AsebaVMState *vm, const char* message);
00180 
00181 // Function optionally implemented
00182 
00183 #ifdef ASEBA_ASSERT
00184 
00186 typedef enum
00187 {
00188         ASEBA_ASSERT_UNKNOWN = 0,
00189         ASEBA_ASSERT_UNKNOWN_UNARY_OPERATOR,
00190         ASEBA_ASSERT_UNKNOWN_BINARY_OPERATOR,
00191         ASEBA_ASSERT_UNKNOWN_BYTECODE,
00192         ASEBA_ASSERT_STACK_OVERFLOW,
00193         ASEBA_ASSERT_STACK_UNDERFLOW,
00194         ASEBA_ASSERT_OUT_OF_VARIABLES_BOUNDS,
00195         ASEBA_ASSERT_OUT_OF_BYTECODE_BOUNDS,
00196         ASEBA_ASSERT_STEP_OUT_OF_RUN,
00197         ASEBA_ASSERT_BREAKPOINT_OUT_OF_BYTECODE_BOUNDS,
00198         ASEBA_ASSERT_EMIT_BUFFER_TOO_LONG,
00199 } AsebaAssertReason;
00200 
00202 void AsebaAssert(AsebaVMState *vm, AsebaAssertReason reason);
00203 
00204 #endif /* ASEBA_ASSERT */
00205 
00208 #ifdef __cplusplus
00209 } /* closing brace for extern "C" */
00210 #endif
00211 
00212 #endif


aseba
Author(s): Stéphane Magnenat
autogenerated on Sun Oct 5 2014 23:46:39