1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: 17: 18: 19:
20:
21: #include <basic.h>
22: #include <tk/tkernel.h>
23: #include <tm/tmonitor.h>
24: #include <libstr.h>
25:
26:
27: IMPORT ER ConsoleIO( INT ac, UB *av[] );
28: IMPORT ER ClockDrv( INT ac, UB *av[] );
29: IMPORT ER SysDiskDrv( INT ac, UB *av[] );
30: IMPORT ER ScreenDrv( INT ac, UB *av[] );
31: IMPORT ER KbPdDrv( INT ac, UB *av[] );
32: IMPORT ER LowKbPdDrv( INT ac, UB *av[] );
33:
34: #ifdef DEBUG_SAMPLE
35: 36: 37:
38: 39: 40:
41: LOCAL void test_tsk( INT stacd, void *exinf )
42: {
43: INT i;
44:
45: tm_printf("3 - Sample task started (tid=%d).\n", tk_get_tid());
46:
47: for (i = 0; i < 3; i++) {
48: tk_dly_tsk(1000);
49: tm_printf("%d - Delay 1000 msec.\n", 4 + i);
50: }
51:
52: tm_printf("7 - Wakeup main task.\n");
53:
54:
55: tk_wup_tsk(stacd);
56:
57: tm_printf("9 - Sample task finished.\n");
58:
59:
60: tk_exd_tsk();
61: }
62: 63: 64:
65: LOCAL void debug_sample(void)
66: {
67: ER er;
68: ID ttskid;
69: T_CTSK ctsk;
70: T_RTSK rtsk;
71:
72: tm_printf("1 - Debug sample started.\n");
73:
74:
75: MEMSET(&ctsk, 0, sizeof(ctsk));
76:
77: ctsk.tskatr = TA_HLNG | TA_RNG0;
78: ctsk.task = test_tsk;
79: ctsk.itskpri = 140;
80: ctsk.stksz = 2 * 1024;
81:
82: ttskid = tk_cre_tsk(&ctsk);
83: if ( ttskid < E_OK ) {
84: tm_printf("ERROR: tk_cre_tsk [%#x].\n", ttskid);
85: goto err_ret;
86: }
87:
88:
89: er = tk_sta_tsk(ttskid, tk_get_tid());
90: if ( er < E_OK ) {
91: tk_del_tsk(ttskid);
92: tm_printf("ERROR: tk_sta_tsk [%#x].\n", er);
93: goto err_ret;
94: }
95:
96: tm_printf("2 - Start sample task (tid=%d) and wait.\n", ttskid);
97:
98:
99: tk_slp_tsk(TMO_FEVR);
100:
101: tm_printf("8 - Wakeup from sample task.\n");
102:
103:
104: while(1) {
105: er = tk_ref_tsk(ttskid, &rtsk);
106: if ( er == E_NOEXS ) break;
107: tk_slp_tsk(50);
108: }
109: tm_printf("10 - Debug sample finished.\n");
110:
111: err_ret:
112: return;
113: }
114: #endif
115:
116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127:
128: EXPORT INT usermain( void )
129: {
130: ER ercd;
131:
132:
133: #ifdef DRV_CONSOLE
134: ercd = ConsoleIO(0, NULL);
135: tm_putstring(ercd >= E_OK ? "ConsoleIO - OK\n" : "ConsoleIO - ERR\n");
136: #endif
137: #ifdef DRV_CLOCK
138: ercd = ClockDrv(0, NULL);
139: tm_putstring(ercd >= E_OK ? "ClockDrv - OK\n" : "ClockDrv - ERR\n");
140: #endif
141: #ifdef DRV_SYSDISK
142: ercd = SysDiskDrv(0, NULL);
143: tm_putstring(ercd >= E_OK ? "SysDiskDrv - OK\n" : "SysDiskDrv - ERR\n");
144: #endif
145: #ifdef DRV_SCREEN
146: ercd = ScreenDrv(0, NULL);
147: tm_putstring(ercd >= E_OK ? "ScreenDrv - OK\n" : "ScreenDrv - ERR\n");
148: #endif
149: #ifdef DRV_KBPD
150: ercd = KbPdDrv(0, NULL);
151: tm_putstring(ercd >= E_OK ? "KbPdDrv - OK\n" : "KbPdDrv - ERR\n");
152: #endif
153: #ifdef DRV_LOWKBPD
154: ercd = LowKbPdDrv(0, NULL);
155: tm_putstring(ercd >= E_OK ? "LowKbPdDrv - OK\n" : "LowKbPdDrv - ERR\n");
156: #endif
157:
158: #ifdef DEBUG_SAMPLE
159:
160: debug_sample();
161: #endif
162:
163:
164: tm_putstring((UB*)"Push any key to shutdown the T-Kernel.\n");
165: tm_getchar(-1);
166:
167:
168: #ifdef DRV_LOWKBPD
169: LowKbPdDrv(-1, NULL);
170: #endif
171: #ifdef DRV_KBPD
172: KbPdDrv(-1, NULL);
173: #endif
174: #ifdef DRV_SCREEN
175: ScreenDrv(-1, NULL);
176: #endif
177: #ifdef DRV_SYSDISK
178: SysDiskDrv(-1, NULL);
179: #endif
180: #ifdef DRV_CLOCK
181: ClockDrv(-1, NULL);
182: #endif
183: #ifdef DRV_CONSOLE
184: ConsoleIO(-1, NULL);
185: #endif
186:
187: return 0;
188: }