OSDN Git Service

Replace samples.
[nxt-jsp/etrobo-atk.git] / nxtOSEK / samples_c / petest / 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 DeclareCounter( SysTimerCnt );\r
10 DeclareResource(lcd);\r
11 DeclareTask(LowTask);\r
12 DeclareTask(HighTask);\r
13 \r
14 /*--------------------------------------------------------------------------*/\r
15 /* Definitions                                                              */\r
16 /*--------------------------------------------------------------------------*/\r
17 int digits;\r
18 \r
19 /*--------------------------------------------------------------------------*/\r
20 /* Function to be invoked from a category 2 interrupt                       */\r
21 /*--------------------------------------------------------------------------*/\r
22 void user_1ms_isr_type2(void)\r
23 {\r
24         StatusType ercd;\r
25         \r
26         /*\r
27          *  Increment OSEK Alarm System Timer Count\r
28      */\r
29         ercd = SignalCounter( SysTimerCnt );\r
30         if( ercd != E_OK ){\r
31                 ShutdownOS( ercd );\r
32         }\r
33 }\r
34 \r
35 /*--------------------------------------------------------------------------*/\r
36 /* Task information:                                                        */\r
37 /* -----------------                                                        */\r
38 /* Name    : LowTask                                                        */\r
39 /* Priority: 2                                                              */\r
40 /* Typ     : EXTENDED TASK                                                  */\r
41 /* Schedule: preemptive                                                     */\r
42 /*--------------------------------------------------------------------------*/\r
43 TASK(LowTask)\r
44 {\r
45     int hcount, lcount;\r
46 \r
47         for (hcount = 0; hcount < 10; hcount++) {\r
48                 digits--;\r
49                 GetResource(lcd);\r
50 \r
51                 ecrobot_debug1(digits, hcount, 0);\r
52             /* The following loop is to wait for the ISR triggered by ecrobot_debug\r
53              * (or the specific I/O statement inside ecrobot_debug) to complete\r
54              * This is a good example to show how explicit/implicit shared resource\r
55              * is needed to be protected against concurrent accesses from multiple Tasks\r
56                  */\r
57                 for (lcount = 0; lcount < 3200; lcount++) ;\r
58 \r
59                 ReleaseResource(lcd);\r
60         }\r
61 \r
62         ChainTask(LowTask);\r
63 \r
64 }\r
65 \r
66 /*--------------------------------------------------------------------------*/\r
67 /* Task information:                                                        */\r
68 /* -----------------                                                        */\r
69 /* Name    : HighTask                                                       */\r
70 /* Priority: 3                                                              */\r
71 /* Typ     : EXTENDED TASK                                                  */\r
72 /* Schedule: preemptive                                                     */\r
73 /*--------------------------------------------------------------------------*/\r
74 TASK(HighTask)\r
75 {\r
76         int hcount, lcount;\r
77 \r
78         for (hcount = 0; hcount < 10; hcount++) {\r
79                 GetResource(lcd);\r
80 \r
81                 ecrobot_debug2(digits, hcount, 0);\r
82             /* The following loop is to wait for the ISR triggered by ecrobot_debug\r
83              * (or the specific I/O statement inside ecrobot_debug) to complete\r
84              * This is a good example to show how explicit/implicit shared resource\r
85              * is needed to be protected against concurrent accesses from multiple Tasks\r
86                  */\r
87         for (lcount = 0; lcount < 3200; lcount++) ;\r
88 \r
89                 ReleaseResource(lcd);\r
90         }\r
91         digits=0;\r
92         \r
93         TerminateTask();\r
94 }\r
95 \r