blob: 13a427ec845cda1daa524c6d12b6276816e969e2 [file] [log] [blame]
brians343bc112013-02-10 01:53:46 +00001#ifndef _AOS_CORE_H_
2#define _AOS_CORE_H_
3
4#ifdef __VXWORKS__
5#include "WPILib/Task.h"
6#endif
7
8#ifdef __cplusplus
9extern "C" {
10#endif
11
12#ifndef __VXWORKS__
13#include "aos/atom_code/ipc_lib/resource.h"
14#include "aos/atom_code/ipc_lib/shared_mem.h"
15#include "aos/atom_code/ipc_lib/queue.h"
16#ifdef __cplusplus
17}
18#include "aos/atom_code/init.h"
19extern "C" {
20#endif
21
22// A macro that runs a control loop using AOS_RUN on linux, and lets the user
23// register the control loop on the cRIO.
24#define AOS_RUN_LOOP AOS_RUN
25
26// A macro that will create an instance of the given class using
27// its default constructor and call Run() on it on the cRIO or the atom.
28// It will generate a main on the atom and a function that the build system links
29// in a call to on the cRIO.
30// NOTE: No ; after this macro, and it should be used at the file scope (NO NAMESPACES!).
31#define AOS_RUN(classname) int main() { \
32 aos::Init(); \
33 classname looper; /* on the stack to avoid eigen alignment issue */ \
34 looper.Run(); \
35 aos::Cleanup(); \
36}
37// Same as AOS_RUN, except uses aos::init_nrt instead of aos::init.
38#define AOS_RUN_NRT(classname) int main() { \
39 aos::InitNRT(); \
40 classname looper; /* on the stack to avoid eigen alignment issue */ \
41 looper.Run(); \
42 aos::Cleanup(); \
43}
44// Same as AOS_RUN, except passes args to the constructor.
45#define AOS_RUN_ARGS(classname, args...) int () { \
46 aos::Init(); \
47 classname looper(args); /* on the stack to avoid eigen alignment issue */ \
48 looper.Run(); \
49 aos::Cleanup(); \
50}
51
52#else // ifndef __VXWORKS__
53
54// The cRIO doesn't need to run the Run method. The cRIO main should register
55// all loops to get run.
56#define AOS_RUN_LOOP(classname) /* nop */
57
58#define AOS_RUN(classname) extern "C" void AOS_INITNAME() { \
59 classname *looper = new classname(); /* dynamically allocated because most (all?) Run functions store references */ \
60 looper->Run(); \
61}
62// Same as AOS_RUN, except it runs in a new Task (named name and at priority).
63// Calls both the constructor and Run in the new Task.
64#define AOS_RUN_FORK(classname, name, priority) \
65static void aos_init_(void *) { \
66 classname *looper = new classname(); /* dynamically allocated because most (all?) Run functions store references */ \
67 looper->Run(); \
68} \
69extern "C" void AOS_INITNAME() { \
70 (new Task(name, reinterpret_cast<FUNCPTR>(aos_init_), priority))->Start(); \
71}
72
73#endif // ifndef __VXWORKS__
74
75#ifdef __cplusplus
76}
77#endif
78
79#include "aos/common/logging/logging.h"
80
81#endif