00001 /* 00002 Aseba - an event-based framework for distributed robot control 00003 Copyright (C) 2006 - 2009: 00004 Philippe Rétornaz <philippe.retornaz at epfl dot ch> 00005 and other contributors, see authors.txt for details 00006 Mobots group, Laboratory of Robotics Systems, EPFL, Lausanne 00007 00008 This program is free software: you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation, either version 3 of the License, or 00011 any other version as decided by the two original authors 00012 Stephane Magnenat and Valentin Longchamp. 00013 00014 This program is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU General Public License for more details. 00018 00019 You should have received a copy of the GNU General Public License 00020 along with this program. If not, see <http://www.gnu.org/licenses/>. 00021 */ 00022 00023 00024 00025 #ifndef _SKEL_H_ 00026 #define _SKEL_H_ 00027 00028 // Molole includes 00029 #include <can/can.h> 00030 #include <dma/dma.h> 00031 #include <gpio/gpio.h> 00032 #include <types/types.h> 00033 00034 00035 // Aseba include 00036 #include <vm/natives.h> 00037 #include <vm/vm.h> 00038 00039 #include <common/types.h> 00040 00041 #include <skel-user.h> 00042 00043 00044 00045 00046 extern struct _vmVariables vmVariables; 00047 00048 extern unsigned int events_flags; 00049 00050 extern AsebaVMState vmState; 00051 00052 00053 /*** In your code, put "SET_EVENT(EVENT_NUMBER)" when you want to trigger an 00054 event. This macro is interrupt-safe, you can call it anywhere you want. 00055 ***/ 00056 #define SET_EVENT(event) atomic_or(&events_flags, 1 << event) 00057 #define CLEAR_EVENT(event) atomic_and(&events_flags, ~(1 << event)) 00058 #define IS_EVENT(event) (events_flags & (1 << event)) 00059 00060 00061 00062 00063 00064 // Call this when everything is initialised and you are ready to give full control to the VM 00065 void __attribute((noreturn)) run_aseba_main_loop(void); 00066 00067 // Call this to init aseba. Beware, this will: 00068 // 1. init the CAN module 00069 // 2. clear vmVariables. 00070 // 3. Load any bytecode in flash if present 00071 void init_aseba_and_can(void); 00072 00073 // This function must update the variable to match the microcontroller state 00074 // It is called _BEFORE_ running the VM, so it's a {Microcontroller state} -> {Aseba Variable} 00075 // synchronisation 00076 // Implement it yourself 00077 void update_aseba_variables_read(void); 00078 00079 // This function must update the microcontrolleur state to match the variables 00080 // It is called _AFTER_ running the VM, so it's a {Aseba Variables} -> {Microcontroller state} 00081 // synchronisation 00082 //Implement it yourself 00083 void update_aseba_variables_write(void); 00084 00085 // This function load the settings structure from flash. Call it _AFTER_ init_aseba_and_can() 00086 // return 0 if the settings were loaded 00087 // return non-zero if the settings were NOT found (settings is non-initilised) 00088 int load_settings_from_flash(void); 00089 00090 00091 extern struct private_settings settings; 00092 00093 00094 #endif