void cpuexc_handler(VP p_excinf) { ID tskid; syslog(LOG_NOTICE, "CPU exception handler (p_excinf = %08p).", p_excinf); if (sns_ctx() != TRUE) { syslog(LOG_WARNING, "sns_ctx() is not TRUE in CPU exception handler."); } if (sns_dpn() != TRUE) { syslog(LOG_WARNING, "sns_dpn() is not TRUE in CPU exception handler."); } syslog(LOG_DEBUG, "sns_loc = %d sns_dsp = %d", (int)sns_loc(), (int)sns_dsp()); syslog(LOG_DEBUG, "vxsns_loc = %d vxsns_ctx = %d vxsns_dsp = %d vxsns_dpn = %d", (int)vxsns_loc(p_excinf), (int)vxsns_ctx(p_excinf), (int)vxsns_dsp(p_excinf), (int)vxsns_dpn(p_excinf)); if (!vxsns_loc(p_excinf) && !vxsns_ctx(p_excinf)) { syscall(iget_tid(&tskid)); syscall(iras_tex(tskid, 0x8000)); } else { syslog(LOG_NOTICE, "Sample program ends with exception."); kernel_exit(); } }
int main() { initialize_kernel(); active = task_create(first, 0, MEDIUM); make_ready(active); unsigned int kernel_cpu_time = 0; Request *req; FineTimer timer; fine_timer_reset(&timer); while((active = schedule())) { kernel_cpu_time += fine_timer_elapsed(&timer); fine_timer_reset(&timer); req = kernel_exit(active); active->cpu_time += fine_timer_elapsed(&timer); fine_timer_reset(&timer); int shutdown = handle(active, req); if (shutdown) break; } // Print out runtime stats dump_timing_info(kernel_cpu_time); log ("Kernel exiting\n"); disable_interrupts(); return 0; }
/* * メインタスク */ void main_task(VP_INT exinf) { int len; char buf[256]; const char cmnd[] = "RVAL\r"; unsigned char chr; vmsk_log(LOG_UPTO(LOG_INFO), LOG_UPTO(LOG_EMERG)); syslog(LOG_NOTICE, "Sample program starts (exinf = %d).", (INT) exinf); Initialize(); while(1) { SIO_FlashBuffer(); strcpy(buf, cmnd); len = SIO_Write((unsigned char*)buf, sizeof(cmnd)); // Send Command chr = 0; while(chr != '\r') { len = SIO_ReadForever((unsigned char*)buf, 1); chr = buf[0]; tslp_tsk(100); } tslp_tsk(100); } syslog(LOG_NOTICE, "Sample program ends."); kernel_exit(); }
/* * 並行実行されるタスク */ void task(VP_INT exinf) { volatile UW i; INT n = 0; INT tskno = (INT) exinf; const char *graph[] = { "|", " +", " *" }; char c; ena_tex(); while (1) { syslog(LOG_NOTICE, "task%d is running (%03d). %s", tskno, ++n, graph[tskno-1]); for (i = 0; i < task_loop; i++); c = message[tskno-1]; message[tskno-1] = 0; switch (c) { case 'e': syslog(LOG_INFO, "#%d#ext_tsk()", tskno); ext_tsk(); case 's': syslog(LOG_INFO, "#%d#slp_tsk()", tskno); syscall(slp_tsk()); break; case 'S': syslog(LOG_INFO, "#%d#tslp_tsk(10000)", tskno); syscall(tslp_tsk(10000)); break; case 'd': syslog(LOG_INFO, "#%d#dly_tsk(10000)", tskno); syscall(dly_tsk(10000)); break; case 'y': syslog(LOG_INFO, "#%d#dis_tex()", tskno); syscall(dis_tex()); break; case 'Y': syslog(LOG_INFO, "#%d#ena_tex()", tskno); syscall(ena_tex()); break; #ifdef CPUEXC1 case 'z': syslog(LOG_NOTICE, "#%d#raise CPU exception", tskno); RAISE_CPU_EXCEPTION; break; #endif /* CPUEXC1 */ case 'Z': syslog(LOG_NOTICE, "Sample program ends with exception."); kernel_exit(); break; default: break; } } }
/** * This is a thread with priority kernel_prio that synchronously waits for * rtdal_pipeline signals (usign sigwaitinfo). All signals except thread-specific * ones (SIGSEGV,SIGILL,SIGBUS,SIGFPE) are blocked by all threads except this one. * Thread-specific signals are handled by ProcThreads which send a SIGRTMIN+1, * SIGRTMIN+2,SIGRTMIN+3,SIGRTMIN+4 (respectively) to this thread, which takes * actions accordingly. * * for signals SIGRTMIN to SIGRTMIN+4, cast the rtdal_pipeline object from this * si_value pointer and call rtdal_pipeline_recover_thread(pipeline, * pipeline->running_process, TRUE) */ void sigwait_loop(void) { int signum; sigset_t set; siginfo_t info; sigfillset(&set); sigdelset(&set,TASK_TERMINATION_SIGNAL); while(!sigwait_stops) { do { signum = sigwaitinfo(&set, &info); } while (signum == -1 && errno == EINTR); if (signum == -1) { poserror(errno, "sigwaitinfo"); goto out; } hdebug("detected signal %d\n",signum); if (signum == KERNEL_SIG_THREAD_SPECIFIC) { printf("[rtdal]: Caught thread-specific signal\n"); #ifdef EXIT_ON_THREADSIG fflush(stdout); goto out; #else sigwait_loop_process_thread_signal(&info); #endif } else if (signum == SIGINT) { printf("Caught SIGINT, exiting\n"); fflush(stdout); goto out; } else if (signum != SIGWINCH && signum != SIGCHLD) { printf("Got signal %d, exiting\n", signum); fflush(stdout); goto out; } } out: kernel_exit(); }
/* * メインタスク */ void main_task(VP_INT exinf) { char c; ID tskid = TASK1; volatile UW i; INT tskno = 1; ER_UINT ercd; PRI tskpri; SYSTIM stime1, stime2; #ifndef OMIT_VGET_TIM SYSUTIM utime1, utime2; #endif /* OMIT_VGET_TIM */ vmsk_log(LOG_UPTO(LOG_INFO), LOG_UPTO(LOG_EMERG)); syslog(LOG_NOTICE, "Sample program starts (exinf = %d).", (int)exinf); syscall(serial_ctl_por(TASK_PORTID, (IOCTL_CRLF | IOCTL_FCSND | IOCTL_FCRCV))); /* * ループ回数の設定 */ task_loop = LOOP_REF; get_tim(&stime1); for (i = 0; i < task_loop; i++); get_tim(&stime2); task_loop = LOOP_REF * 400 / (stime2 - stime1); tex_loop = task_loop / 5; /* * タスクの起動 */ act_tsk(TASK1); act_tsk(TASK2); act_tsk(TASK3); /* * メインループ */ do { syscall(serial_rea_dat(TASK_PORTID, &c, 1)); switch (c) { case 'e': case 's': case 'S': case 'd': case 'y': case 'Y': case 'z': case 'Z': message[tskno-1] = c; break; case '1': tskno = 1; tskid = TASK1; break; case '2': tskno = 2; tskid = TASK2; break; case '3': tskno = 3; tskid = TASK3; break; case 'a': syslog(LOG_INFO, "#act_tsk(%d)", tskno); syscall(act_tsk(tskid)); break; case 'A': syslog(LOG_INFO, "#can_act(%d)", tskno); syscall(ercd = can_act(tskid)); if (ercd >= 0) { syslog(LOG_NOTICE, "can_act(%d) returns %d", tskno, ercd); } break; case 't': syslog(LOG_INFO, "#ter_tsk(%d)", tskno); syscall(ter_tsk(tskid)); break; case '>': syslog(LOG_INFO, "#chg_pri(%d, HIGH_PRIORITY)", tskno); chg_pri(tskid, HIGH_PRIORITY); break; case '=': syslog(LOG_INFO, "#chg_pri(%d, MID_PRIORITY)", tskno); chg_pri(tskid, MID_PRIORITY); break; case '<': syslog(LOG_INFO, "#chg_pri(%d, LOW_PRIORITY)", tskno); chg_pri(tskid, LOW_PRIORITY); break; case 'G': syslog(LOG_INFO, "#get_pri(%d, &tskpri)", tskno); syscall(ercd = get_pri(tskid, &tskpri)); if (ercd >= 0) { syslog(LOG_NOTICE, "priority of task %d is %d", tskno, tskpri); } break; case 'w': syslog(LOG_INFO, "#wup_tsk(%d)", tskno); syscall(wup_tsk(tskid)); break; case 'W': syslog(LOG_INFO, "#can_wup(%d)", tskno); syscall(ercd = can_wup(tskid)); if (ercd >= 0) { syslog(LOG_NOTICE, "can_wup(%d) returns %d", tskno, ercd); } break; case 'l': syslog(LOG_INFO, "#rel_wai(%d)", tskno); syscall(rel_wai(tskid)); break; case 'u': syslog(LOG_INFO, "#sus_tsk(%d)", tskno); syscall(sus_tsk(tskid)); break; case 'm': syslog(LOG_INFO, "#rsm_tsk(%d)", tskno); syscall(rsm_tsk(tskid)); break; case 'M': syslog(LOG_INFO, "#frsm_tsk(%d)", tskno); syscall(frsm_tsk(tskid)); break; case 'x': syslog(LOG_INFO, "#ras_tex(%d, 0x0001)", tskno); syscall(ras_tex(tskid, 0x0001)); break; case 'X': syslog(LOG_INFO, "#ras_tex(%d, 0x0002)", tskno); syscall(ras_tex(tskid, 0x0002)); break; case 'r': syslog(LOG_INFO, "#rot_rdq(three priorities)"); rot_rdq(HIGH_PRIORITY); rot_rdq(MID_PRIORITY); rot_rdq(LOW_PRIORITY); break; case 'c': sta_cyc(CYCHDR1); break; case 'C': stp_cyc(CYCHDR1); break; #ifndef OMIT_VGET_TIM case 'V': syscall(vxget_tim(&utime1)); syscall(vxget_tim(&utime2)); syslog(LOG_NOTICE, "utime1 = %d, utime2 = %d", (UINT) utime1, (UINT) utime2); break; #endif /* OMIT_VGET_TIM */ case 'v': vmsk_log(LOG_UPTO(LOG_INFO), LOG_UPTO(LOG_EMERG)); break; case 'q': vmsk_log(LOG_UPTO(LOG_NOTICE), LOG_UPTO(LOG_EMERG)); break; default: break; } } while (c != '\003' && c != 'Q'); syslog(LOG_NOTICE, "Sample program ends."); kernel_exit(); }
void exit(int status) { if (iniflg) kernel_exit(); _exit(status); }