1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17:
18: #include <tk/tkernel.h>
19: #include <tm/tmonitor.h>
20: #include <sys/inittask.h>
21:
22: #include "kernel.h"
23:
24: #if !USE_IMALLOC
25: INT init_task_stack[INITTASK_STKSZ/sizeof(INT)];
26: #endif
27:
28: typedef INT (*MAIN_FP)(INT, UB **);
29:
30: 31: 32:
33:
34: LOCAL void init_task_main(void);
35:
36: EXPORT const T_CTSK knl_init_ctsk = {
37: (void *)INITTASK_EXINF,
38: INITTASK_TSKATR,
39: (FP)&init_task_main,
40: INITTASK_ITSKPRI,
41: INITTASK_STKSZ,
42: #if USE_OBJECT_NAME
43: INITTASK_DSNAME,
44: #endif
45: INITTASK_STACK,
46: };
47:
48:
49: 50: 51: 52: 53:
54: LOCAL ER start_system( void )
55: {
56: ER ercd;
57:
58: #if USE_DEVICE
59:
60: ercd = knl_initialize_devmgr();
61: if ( ercd < E_OK ) return ercd;
62: #endif
63:
64:
65: ercd = knl_start_device();
66:
67: return ercd;
68: }
69:
70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80:
81: LOCAL void shutdown_system( INT fin )
82: {
83: #if USE_SHUTDOWN
84:
85: knl_finish_device();
86:
87:
88: if ( fin >= 0 ) {
89: SYSTEM_MESSAGE("\n<< SYSTEM SHUTDOWN >>\n");
90: }
91:
92: if ( fin < 0 ) {
93:
94: knl_restart_hw(fin);
95: }
96:
97: knl_tkernel_exit();
98: #else
99: DISABLE_INTERRUPT;
100: for(;;) {
101: ;
102: }
103: #endif
104: }
105:
106:
107: 108: 109:
110: LOCAL void init_task_main(void)
111: {
112: INT fin = 1;
113: ER ercd;
114:
115: ercd = start_system();
116: if(ercd >= E_OK) {
117:
118: #if (USE_SYSTEM_MESSAGE && USE_TMONITOR)
119: tm_printf((UB*)"\n\nmicroT-Kernel Version %x.%02x\n\n", VER_MAJOR, VER_MINOR);
120: #endif
121:
122: #if USE_USERINIT
123:
124: fin = (*(MAIN_FP)RI_USERINIT)(0, NULL);
125: #endif
126: if ( fin > 0 ) {
127: fin = usermain();
128: }
129: #if USE_USERINIT
130:
131: (*(MAIN_FP)RI_USERINIT)(-1, NULL);
132: #endif
133:
134: } else {
135: SYSTEM_MESSAGE("!ERROR! Init Task start\n");
136: }
137:
138: shutdown_system(fin);
139: }
140: