OSDN Git Service

Update ecrobot to nxtOSEK_v212.zip
[nxt-jsp/etrobo-atk.git] / nxtOSEK / ecrobot / c++ / device / Clock.h
1 //\r
2 // Clock.h\r
3 //\r
4 // Copyright 2009 by Takashi Chikamasa, Jon C. Martin and Robert W. Kramer\r
5 //\r
6 \r
7 #ifndef CLOCK_H_\r
8 #define CLOCK_H_\r
9 \r
10 extern "C"\r
11 {\r
12         #include "ecrobot_interface.h"\r
13         #include "rtoscalls.h"\r
14 };\r
15 \r
16 namespace ecrobot\r
17 {\r
18 /**\r
19  * NXT system clock related class\r
20  *\r
21  * [ How to use with TOPPERS/ATK1(OSEK) ]<BR>\r
22  * I2C (derived/compositted) class and Clock class internally use RTOS features.\r
23  * Thus, user needs to implement a C function and RTOS provided events.<BR><BR>\r
24  * + Invoke SleeperMonitor function in user_1msec_isr_type2 hook.<BR>\r
25  * &nbsp;&nbsp;void user_1ms_isr_type2(void)<BR>\r
26  * &nbsp;&nbsp;{<BR>\r
27  * &nbsp;&nbsp;&nbsp;&nbsp;SleeperMonitor(); // needed for I2C devices and Clock class<BR>\r
28  * &nbsp;&nbsp;}<BR>\r
29  * <BR>\r
30  * + Define EventSleepI2C and EventSleep Events in user oil file.<BR>\r
31  * &nbsp;&nbsp;EVENT EventSleepI2C<BR>\r
32  * &nbsp;&nbsp;{<BR>\r
33  * &nbsp;&nbsp;&nbsp;&nbsp;MASK = AUTO;<BR>\r
34  * &nbsp;&nbsp;};<BR><BR>\r
35  * &nbsp;&nbsp;EVENT EventSleep<BR>\r
36  * &nbsp;&nbsp;{<BR>\r
37  * &nbsp;&nbsp;&nbsp;&nbsp;MASK = AUTO;<BR>\r
38  * &nbsp;&nbsp;};<BR><BR>\r
39  * &nbsp;&nbsp;TASK TaskMain<BR>\r
40  * &nbsp;&nbsp;{<BR>\r
41  * &nbsp;&nbsp;&nbsp;&nbsp;AUTOSTART = TRUE<BR>\r
42  * &nbsp;&nbsp;&nbsp;&nbsp;{<BR>\r
43  * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;APPMODE = appmode1;<BR>\r
44  * &nbsp;&nbsp;&nbsp;&nbsp;};<BR>\r
45  * &nbsp;&nbsp;&nbsp;&nbsp;PRIORITY = 1;<BR>\r
46  * &nbsp;&nbsp;&nbsp;&nbsp;ACTIVATION = 1;<BR>\r
47  * &nbsp;&nbsp;&nbsp;&nbsp;SCHEDULE = FULL;<BR>\r
48  * &nbsp;&nbsp;&nbsp;&nbsp;STACKSIZE = 512;<BR>\r
49  * &nbsp;&nbsp;&nbsp;&nbsp;EVENT = EventSleepI2C; <- Here it is<BR>\r
50  * &nbsp;&nbsp;&nbsp;&nbsp;EVENT = EventSleep; <- Here it is<BR>\r
51  * &nbsp;&nbsp;};<BR>\r
52  * <BR>\r
53  * [ How to use with TOPPERS/JSP(ITRON) ]<BR>\r
54  * In case of using this class with TOPPERS/JSP(ITRON), RTOS specific definitions for the class are not needed.\r
55  */\r
56 class Clock\r
57 {\r
58 public:\r
59         /**\r
60          * Constructor.\r
61          * System clock is set to 0 when the class object is constructed.\r
62          * @param -\r
63          * @return -\r
64          */\r
65         Clock(void);\r
66         \r
67         /**\r
68          * Reset the system clock to 0.\r
69          * @param -\r
70          * @return -\r
71          */\r
72         void reset(void);\r
73 \r
74         /**\r
75          * Get the current system clock in msec.\r
76          * @param -\r
77          * @return Current system clock in msec\r
78          */\r
79         U32 now(void) const;\r
80 \r
81         /**\r
82          * Wait in a loop for duration in msec.\r
83          * @param duration Wait duration in msec\r
84          * @return -\r
85          */\r
86         void wait(U32 duration);\r
87 \r
88         /**\r
89          * Sleep the running Task for duration in msec.\r
90          * @param duration Sleep duration in msec\r
91          * @return -\r
92          */\r
93         void sleep(U32 duration);\r
94 \r
95 private:\r
96         U32 mStartClock;\r
97 };\r
98 }\r
99 \r
100 #endif\r