OSDN Git Service

Update samples to nxtOSEK_v212.zip (I did not check their licenses.)
[nxt-jsp/etrobo-atk.git] / nxtOSEK / samples_c++ / cpp / New / sample.cpp
diff --git a/nxtOSEK/samples_c++/cpp/New/sample.cpp b/nxtOSEK/samples_c++/cpp/New/sample.cpp
new file mode 100644 (file)
index 0000000..029d323
--- /dev/null
@@ -0,0 +1,78 @@
+/* sample.cpp for TOPPERS/ATK(OSEK) */ \r
+\r
+// ECRobot++ API\r
+#include "Lcd.h"\r
+#include "Clock.h"\r
+using namespace ecrobot;\r
+\r
+extern "C"\r
+{\r
+#include <string.h>\r
+\r
+#include "kernel.h"\r
+#include "kernel_id.h"\r
+#include "ecrobot_interface.h"\r
+\r
+Lcd lcd;\r
+\r
+// test classes\r
+class Hoge\r
+{\r
+private:\r
+       U8 buf[256]; // certain size of memory to be heaped\r
+public:\r
+       Hoge() { lcd.putf("sn", "new Hoge"); }\r
+\r
+       virtual ~Hoge(){ lcd.putf("ns", "delete Hoge"); }\r
+\r
+       void func(void) { lcd.putf("s", "func "); }\r
+};\r
+\r
+class Hoge1: public Hoge\r
+{\r
+public:\r
+       Hoge1() { lcd.putf("sn", "new Hoge1"); }\r
+       \r
+       ~Hoge1() { lcd.putf("ns", "delete Hoge1");}\r
+};\r
+\r
+// nxtOSEK hook to be invoked from an ISR in category 2\r
+void user_1ms_isr_type2(void)\r
+{\r
+       SleeperMonitor(); // needed for I2C device and Clock classes\r
+}\r
+\r
+TASK(TaskMain)\r
+{\r
+       Clock clock;\r
+\r
+       U32 cnt = 0;\r
+       while(1)\r
+       {\r
+               lcd.clear();\r
+               lcd.putf("dn", cnt,0);\r
+               if ((cnt++ << 31) == 0)\r
+               {\r
+                       // single new/delete\r
+                       Hoge1* hoge1 = new Hoge1;\r
+\r
+                       hoge1->func();\r
+\r
+                       delete hoge1;\r
+               }\r
+               else\r
+               {\r
+                       // array new/delete\r
+                       Hoge* hoges = new Hoge[3];\r
+\r
+                       hoges[0].func();\r
+                       hoges[1].func();\r
+                       hoges[2].func();\r
+\r
+                       delete [] hoges;\r
+               }\r
+               lcd.disp();\r
+               clock.wait(2000);\r
+       }\r
+}\r
+}\r