OSDN Git Service

b98f5944eab787e914bb321319aa379205eb303d
[nxt-jsp/etrobo-atk.git] / nxtOSEK / samples / tttest / template.c
1 \r
2 #include "kernel.h"\r
3 #include "kernel_id.h"\r
4 #include "ecrobot_interface.h"\r
5 \r
6 /*--------------------------------------------------------------------------*/\r
7 /* OSEK declarations                                                        */\r
8 /*--------------------------------------------------------------------------*/\r
9 DeclareEvent(BarrierEvent);\r
10 DeclareCounter(SysTimerCnt);\r
11 DeclareResource(mx);\r
12 DeclareTask(LowTask);\r
13 DeclareTask(HighTask);\r
14 \r
15 /*--------------------------------------------------------------------------*/\r
16 /* Definitions                                                              */\r
17 /*--------------------------------------------------------------------------*/\r
18 int digits;\r
19 \r
20 /*--------------------------------------------------------------------------*/\r
21 /* Function to be invoked from a category 2 interrupt                       */\r
22 /*--------------------------------------------------------------------------*/\r
23 void user_1ms_isr_type2()\r
24 {\r
25 \r
26       SignalCounter( SysTimerCnt );\r
27 \r
28 }\r
29 \r
30 /*--------------------------------------------------------------------------*/\r
31 /* Task information:                                                        */\r
32 /* -----------------                                                        */\r
33 /* Name    : LowTask                                                        */\r
34 /* Priority: 2                                                              */\r
35 /* Typ     : EXTENDED TASK                                                  */\r
36 /* Schedule: preemptive                                                     */\r
37 /*--------------------------------------------------------------------------*/\r
38 int lowtaskcount;\r
39 int hightaskcount;\r
40 TASK(LowTask)\r
41 {\r
42     int hcount, lcount;\r
43 \r
44     while(1)\r
45         {\r
46           for (hcount = 0; hcount < 10; hcount++) {\r
47                   digits--;\r
48                   GetResource(mx);\r
49 \r
50                   ecrobot_debug1(digits, lowtaskcount, hightaskcount);\r
51               /* The following loop is to wait for the ISR triggered by ecrobot_debug\r
52                * (or the specific I/O statement inside ecrobot_debug) to complete\r
53                * This is a good example to show how explicit/implicit shared resource\r
54                * is needed to be protected against concurrent accesses from multiple Tasks\r
55                    */\r
56                   for (lcount = 0; lcount < 3200; lcount++) ;\r
57 \r
58                   ReleaseResource(mx);\r
59           }\r
60           lowtaskcount++;\r
61 \r
62     }\r
63 \r
64     TerminateTask();\r
65 }\r
66 \r
67 /*--------------------------------------------------------------------------*/\r
68 /* Task information:                                                        */\r
69 /* -----------------                                                        */\r
70 /* Name    : HighTask                                                       */\r
71 /* Priority: 3                                                              */\r
72 /* Typ     : EXTENDED TASK                                                  */\r
73 /* Schedule: preemptive                                                     */\r
74 /*--------------------------------------------------------------------------*/\r
75 TASK(HighTask)\r
76 {\r
77         int hcount, lcount;\r
78 \r
79         while(1) {\r
80                 for (hcount = 0; hcount < 10; hcount++) {\r
81                         GetResource(mx);\r
82 \r
83                         ecrobot_debug2(digits, hcount, 0);\r
84                 /* The following loop is to wait for the ISR triggered by ecrobot_debug\r
85                  * (or the specific I/O statement inside ecrobot_debug) to complete\r
86                  * This is a good example to show how explicit/implicit shared resource\r
87                  * is needed to be protected against concurrent accesses from multiple Tasks\r
88                      */\r
89                         for (lcount = 0; lcount < 3200; lcount++) ;\r
90 \r
91                         ReleaseResource(mx);\r
92                 }\r
93                 WaitEvent(BarrierEvent);\r
94         ClearEvent(BarrierEvent);\r
95         digits = 0;\r
96         hightaskcount++;\r
97     }\r
98 \r
99     TerminateTask();\r
100 }\r