/* * Re-starting processing * mode = -1 Reset and re-start (cold boot) * mode = -2 Re-start (warm boot) * mode = -3 Reboot (normal boot) * mode = 0xFFhhmmss Re-start at hh:mm:ss * 0 <= hh < 24, 0 <= mm,ss < 60 */ EXPORT ER restart_device( W mode ) { if ( mode == -1 ) { /* Reset and re-start (cold boot) */ #if USE_KERNEL_MESSAGE tm_putstring((UB*)"\n<< SYSTEM RESTART >>\n"); #endif tm_exit(-1); /* no return */ return E_OBJ; } if ( mode == -3 ) { /* Reboot (normal boot) */ static UB bdcmd[4 + L_DEVNM] = "bd "; #if USE_KERNEL_MESSAGE tm_putstring((UB*)"\n<< SYSTEM REBOOT >>\n"); #endif strncat((char*)bdcmd, (char*)SCInfo.bootdev, L_DEVNM); tm_command(bdcmd); /* Normally no return */ return E_OBJ; /* When the BD command is an error */ } if ( mode == -2 ) { return E_NOSPT; /* Unsupported */ } if ( (mode & 0xff000000) == 0xff000000 ) { /* Re-start at specified time */ return E_NOSPT; /* Unsupported */ } return E_PAR; }
/* * End and delete its own task */ SYSCALL void _tk_exd_tsk( void ) { /* Check context error */ #if CHK_CTX2 if ( in_indp() ) { #if USE_KERNEL_MESSAGE tm_putstring((UB*)"tk_exd_tsk was called in the task independent\n"); #endif tm_monitor(); /* To monitor */ } #endif #if CHK_CTX1 if ( in_ddsp() ) { #if USE_KERNEL_MESSAGE tm_putstring((UB*)"tk_exd_tsk was called in the dispatch disabled\n"); #endif } #endif DISABLE_INTERRUPT; _ter_tsk(ctxtsk); _del_tsk(ctxtsk); force_dispatch(); /* No return */ }
/* * Re-starting processing * mode = -1 Reset and re-start (cold boot) * mode = -2 Re-start (warm boot) * mode = -3 Reboot (normal boot) * mode = 0xFFhhmmss Re-start at hh:mm:ss * 0 <= hh < 24, 0 <= mm,ss < 60 */ EXPORT ER knl_restart_device( W mode ) { if ( mode == -1 ) { /* Reset and re-start (cold boot) */ #if USE_KERNEL_MESSAGE tm_putstring((UB*)"\n<< SYSTEM RESTART >>\n"); #endif tm_exit(-1); /* no return */ return E_OBJ; } if ( mode == -3 ) { /* Reboot (normal boot) */ #if USE_KERNEL_MESSAGE tm_putstring((UB*)"\n<< SYSTEM REBOOT >>\n"); #endif return E_NOSPT; } if ( mode == -2 ) { return E_NOSPT; /* Unsupported */ } if ( (mode & 0xff000000U) == 0xff000000U ) { /* Re-start at specified time */ return E_NOSPT; /* Unsupported */ } return E_PAR; }
/* * Call module initialization */ LOCAL void knl_init_module( ER (*initfunc)( void ), UB *name ) { ER ercd; ercd = (*initfunc)(); if ( ercd < E_OK ) { #if USE_KERNEL_MESSAGE tm_putstring(name); tm_putstring((UB*)" : module initialize error\n"); #endif tm_monitor(); } }
/* * Start initial task */ LOCAL void knl_init_task_startup( T_CTSK *ctsk ) { ER ercd; #if TA_GP extern int _gp; ercd = tk_cre_tsk_impl(ctsk, 0,0,0,0,&_gp); #else ercd = tk_cre_tsk_impl(ctsk); #endif if ( ercd < E_OK ) { goto err_exit; } ercd = tk_sta_tsk_impl((ID)ercd, 0); if ( ercd < E_OK ) { goto err_exit; } return; err_exit: #if USE_KERNEL_MESSAGE tm_putstring((UB*)"init_task can not started\n"); #endif tm_monitor(); }
EXPORT INT usermain( void ) { tm_putstring((UB*)"Push any key to shutdown the micro T-Kernel.\n"); tm_getchar(-1); return 0; }
/* * Stop system */ EXPORT void shutdown_system( INT fin ) { /* Stop subsystem */ finish_subsystems(); /* Platform dependent finalize sequence */ finish_device(); /* Stop library (libtk) */ _FinishLibtk(); /* Shutdown message output */ #if USE_KERNEL_MESSAGE if ( fin >= 0 ) { tm_putstring((UB*)"\n<< SYSTEM SHUTDOWN >>\n"); } #endif /* Stop T-Kernel/SM */ SystemManager(-1, NULL); /* Stop memory manager */ finish_memmgr(); /* Stop segment manager */ finish_segmgr(); if ( fin < 0 ) { /* Re-start sequence (platform dependent) */ restart_device(fin); } /* Stop system */ t_kernel_exit(); }
/* * Switch to power-saving mode */ EXPORT void knl_low_pow( void ) { static int flag = 0; if(flag == 0) { tm_putstring((UB*)"in knl_low_pow().So no tasks in ready state.\r\n"); flag = 1; } }
/* |------------------+-------------------------------------------------------------| */ StatusType ChainTask ( TaskType xTaskID ) { StatusType ercd; #ifdef DORMANT_STACK_SIZE /* To avoid destroying stack used in 'knl_make_dormant', allocate the dummy area on the stack. */ volatile VB _dummy[DORMANT_STACK_SIZE]; #endif /* Check context error */ #if CHK_CTX2 if ( in_indp() ) { #if USE_KERNEL_MESSAGE tm_putstring((UB*)"ChainTask was called in the task independent\n"); #endif tm_monitor(); /* To monitor */ } #endif #if CHK_CTX1 if ( in_ddsp() ) { #if USE_KERNEL_MESSAGE tm_putstring((UB*)"ChainTask was called in the dispatch disabled\n"); #endif } #endif DISABLE_INTERRUPT; ercd = tk_sta_tsk(xTaskID,xTaskID); if(ercd < E_OK) { ENABLE_INTERRUPT; return ercd; } knl_ter_tsk(knl_ctxtsk); knl_make_dormant(knl_ctxtsk); OsekStartHighReadyTask(); /* No return */ #ifdef DORMANT_STACK_SIZE /* for WARNING */ _dummy[0] = 0; #endif }
/* * Start system */ EXPORT void start_system( void ) { ER ercd; /* Initialize segment manager */ DispProgress(0x30); ercd = start_segmgr(); if ( ercd < E_OK ) { goto err_ret; } /* Start memory manager */ DispProgress(0x31); ercd = start_memmgr(); if ( ercd < E_OK ) { goto err_ret; } /* Initialize system manager */ DispProgress(0x32); ercd = SystemManager(0, NULL); if ( ercd < E_OK ) { goto err_ret; } /* Initialize library (libtk) V/K/Smalloc is available after this. */ DispProgress(0x33); _InitLibtk(); /* Lower the initial task priority to initialize sequence for the subsystem task at first. */ tk_chg_pri(TSK_SELF, InitTaskPri); /* Start system dependent sequence */ DispProgress(0x34); ercd = start_device(); if ( ercd < E_OK ) { goto err_ret; } /* Start subsystem */ DispProgress(0x35); ercd = start_subsystems(); if ( ercd < E_OK ) { goto err_ret; } return; err_ret: #if USE_KERNEL_MESSAGE tm_putstring((UB*)"!ERROR! start_system\n"); #endif tm_monitor(); /* Stop */ }
void CanIf_RxIndication( uint8 Hrh, Can_IdType CanId, uint8 CanDlc, const uint8 *CanSduPtr ) { tm_printf("Hrh = %d,CanId = %d:\r\n",(int)Hrh,(int)CanId); while(CanDlc > 0) { tm_putchar(*CanSduPtr++); CanDlc--; } tm_putstring("\r\n"); }
/* * End its own task */ SYSCALL void _tk_ext_tsk( void ) { #ifdef DORMANT_STACK_SIZE /* To avoid destroying stack used in 'make_dormant', allocate the dummy area on the stack. */ volatile VB _dummy[DORMANT_STACK_SIZE]; MEMSET((void *)_dummy, 0xCC, DORMANT_STACK_SIZE); #endif /* Check context error */ #if CHK_CTX2 if ( in_indp() ) { #if USE_KERNEL_MESSAGE tm_putstring((UB*)"tk_ext_tsk was called in the task independent\n"); #endif tm_monitor(); /* To monitor */ } #endif #if CHK_CTX1 if ( in_ddsp() ) { #if USE_KERNEL_MESSAGE tm_putstring((UB*)"tk_ext_tsk was called in the dispatch disabled\n"); #endif } #endif DISABLE_INTERRUPT; _ter_tsk(ctxtsk); make_dormant(ctxtsk); force_dispatch(); /* No return */ #ifdef DORMANT_STACK_SIZE /* for WARNING */ _dummy[0] = 0; #endif }
boolean IncommingFreqReq(PduIdType PduId, const uint8 *IPduData) { tm_putstring((UB*)"IncommingFreqReq() is running.\r\n"); return FALSE; }
/* * Initialize sequence before T-Kernel starts */ EXPORT ER init_system( void ) { ER ercd; /* Platform dependent initialize sequence */ DispProgress(0x10); ercd = init_device(); if ( ercd < E_OK ) { goto err_ret; } /* Initialize subsystem */ DispProgress(0x11); ercd = init_subsystems(); if ( ercd < E_OK ) { goto err_ret; } /* Initialize segment manager */ DispProgress(0x12); ercd = init_segmgr(); if ( ercd < E_OK ) { goto err_ret; } #ifdef _BTRON_ ercd = init_bk_early(); if (ercd < E_OK) { vd_printf("error init_bk_early\n"); goto err_ret; } #endif /* Initialize memory manager */ DispProgress(0x13); ercd = init_memmgr(); if ( ercd < E_OK ) { goto err_ret; } #ifdef _BTRON_ /* Initialize slab allocator */ DispProgress(0x14); ercd = init_slab_allocator(); if ( ercd < E_OK ) { vd_printf("init_slab_allocator\n"); goto err_ret; } /* Initialize bk */ DispProgress(0x15); ercd = init_bk(); if ( ercd < E_OK ) { vd_printf("init_bk\n"); goto err_ret; } #else /* Initialize Imalloc */ DispProgress(0x14); ercd = init_Imalloc(); if ( ercd < E_OK ) { goto err_ret; } #endif return(ercd); err_ret: #if USE_KERNEL_MESSAGE tm_putstring((UB*)"!ERROR! init_kernel\n"); #endif //tm_monitor(); /* Stop */ return(ercd); }
/* * Entry routine for the user application. * At this point, Initialize and start the user application. * * Entry routine is called from the initial task for Kernel, * so system call for stopping the task should not be issued * from the contexts of entry routine. * We recommend that: * (1)'usermain()' only generates the user initial task. * (2)initialize and start the user application by the user * initial task. */ EXPORT INT usermain( void ) { ER err = E_OK; /* Start the device drivers */ #ifdef DRV_CONSOLE //err = ConsoleIO(0, NULL); tm_putstring(err >= E_OK ? "ConsoleIO - OK\n" : "ConsoleIO - ERR\n"); vd_printf(err >= E_OK ? "ConsoleIO - OK\n" : "ConsoleIO - ERR\n"); #endif #ifdef DRV_CLOCK err = ClockDrv(0, NULL); tm_putstring(err >= E_OK ? "ClockDrv - OK\n" : "ClockDrv - ERR\n"); vd_printf(err >= E_OK ? "ClockDrv - OK\n" : "ClockDrv - ERR\n"); #endif #ifdef DRV_SYSDISK err = SysDiskDrv(0, NULL); tm_putstring(err >= E_OK ? "SysDiskDrv - OK\n" : "SysDiskDrv - ERR\n"); vd_printf(err >= E_OK ? "SysDiskDrv - OK\n" : "SysDiskDrv - ERR\n"); #endif #ifdef DRV_SCREEN //err = ScreenDrv(0, NULL); tm_putstring(err >= E_OK ? "ScreenDrv - OK\n" : "ScreenDrv - ERR\n"); vd_printf(err >= E_OK ? "ScreenDrv - OK\n" : "ScreenDrv - ERR\n"); #endif #ifdef DRV_KBPD //err = KbPdDrv(0, NULL); tm_putstring(err >= E_OK ? "KbPdDrv - OK\n" : "KbPdDrv - ERR\n"); vd_printf(err >= E_OK ? "KbPdDrv - OK\n" : "KbPdDrv - ERR\n"); #endif #ifdef DRV_LOWKBPD //err = LowKbPdDrv(0, NULL); tm_putstring(err >= E_OK ? "LowKbPdDrv - OK\n" : "LowKbPdDrv - ERR\n"); vd_printf(err >= E_OK ? "LowKbPdDrv - OK\n" : "LowKbPdDrv - ERR\n"); #endif #ifdef DRV_NET err = NetDrv(0, NULL); tm_putstring(err >= E_OK ? "NetDrv - OK\n" : "NetDrv - ERR\n"); vd_printf(err >= E_OK ? "NetDrv - OK\n" : "NetDrv - ERR\n"); #endif err = initKeyboard(); if (err)vd_printf("err:initKeyborad\n"); initVga(); /* Start the T2EX extension modules */ #ifdef USE_T2EX_DT err = dt_main(0, NULL); tm_putstring(err >= E_OK ? "dt_main(0) - OK\n":"dt_main(0) - ERR\n"); vd_printf(err >= E_OK ? "dt_main(0) - OK\n":"dt_main(0) - ERR\n"); #endif #ifdef USE_T2EX_PM err = pm_main(0, NULL); tm_putstring(err >= E_OK ? "pm_main(0) - OK\n":"pm_main(0) - ERR\n"); vd_printf(err >= E_OK ? "pm_main(0) - OK\n":"pm_main(0) - ERR\n"); #endif #ifdef USE_T2EX_FS err = fs_main(0, NULL); tm_putstring(err >= E_OK ? "fs_main(0) - OK\n":"fs_main(0) - ERR\n"); vd_printf(err >= E_OK ? "fs_main(0) - OK\n":"fs_main(0) - ERR\n"); #endif #ifdef USE_T2EX_NET err = so_main(0, NULL); tm_putstring(err >= E_OK ? "so_main(0) - OK\n":"so_main(0) - ERR\n"); vd_printf(err >= E_OK ? "so_main(0) - OK\n":"so_main(0) - ERR\n"); #endif /* Initialize stdio */ libc_stdio_init(); /* Start the T2EX application */ tm_putstring("*** T2EX Application program start !!\n"); appl_main(); /* Shutdowm the T2EX extension modules */ #ifdef USE_T2EX_DT err = dt_main(-1, NULL); tm_putstring(err >= E_OK ? "dt_main(-1) - OK\n":"dt_main(-1) - ERR\n"); #endif #ifdef USE_T2EX_PM err = pm_main(-1, NULL); tm_putstring(err >= E_OK ? "pm_main(-1) - OK\n":"pm_main(-1) - ERR\n"); #endif #ifdef USE_T2EX_FS err = fs_main(-1, NULL); tm_putstring(err >= E_OK ? "fs_main(-1) - OK\n":"fs_main(-1) - ERR\n"); #endif #ifdef USE_T2EX_NET err = so_main(-1, NULL); tm_putstring(err >= E_OK ? "so_main(-1) - OK\n":"so_main(-1) - ERR\n"); #endif /* Stop the device drivers */ #ifdef DRV_NET NetDrv(-1, NULL); #endif #ifdef DRV_LOWKBPD LowKbPdDrv(-1, NULL); #endif #ifdef DRV_KBPD KbPdDrv(-1, NULL); #endif #ifdef DRV_SCREEN ScreenDrv(-1, NULL); #endif #ifdef DRV_SYSDISK SysDiskDrv(-1, NULL); #endif #ifdef DRV_CLOCK ClockDrv(-1, NULL); #endif #ifdef DRV_CONSOLE ConsoleIO(-1, NULL); #endif return 0; }
/* * Initialize sequence before T-Kernel starts */ EXPORT void init_system( void ) { ER ercd; /* if i'm first processor, execution */ if ( get_prid() == 0 ) { /* Platform dependent initialize sequence */ DispProgress(0x10); ercd = init_device(); if ( ercd < E_OK ) { goto err_ret; } /* Initialize subsystem */ DispProgress(0x11); ercd = init_subsystems(); if ( ercd < E_OK ) { goto err_ret; } /* Initialize segment manager */ DispProgress(0x12); ercd = init_segmgr(); if ( ercd < E_OK ) { goto err_ret; } /* Initialize memory manager */ DispProgress(0x13); ercd = init_memmgr(); if ( ercd < E_OK ) { goto err_ret; } /* Initialize Imalloc */ DispProgress(0x14); ercd = init_Imalloc(); if ( ercd < E_OK ) { goto err_ret; } } else { /* Platform dependent initialize sequence */ DispProgress(0x10); ercd = init_device(); if ( ercd < E_OK ) { goto err_ret; } /* Initialize segment manager */ DispProgress(0x12); ercd = init_segmgr(); if ( ercd < E_OK ) { goto err_ret; } } return; err_ret: #if USE_KERNEL_MESSAGE tm_putstring((UB*)"!ERROR! init_kernel\n"); #endif tm_monitor(); /* Stop */ }