void cpuexc_handler(void *p_excinf) { 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_INFO, "sns_loc = %d sns_dsp = %d xsns_dpn = %d", sns_loc(), sns_dsp(), xsns_dpn(p_excinf)); if (xsns_dpn(p_excinf)) { syslog(LOG_NOTICE, "Sample program ends with exception."); SVC_PERROR(ext_ker()); assert(0); } #ifdef PREPARE_RETURN_CPUEXC PREPARE_RETURN_CPUEXC; SVC_PERROR(get_tid(&cpuexc_tskid)); SVC_PERROR(act_tsk(EXC_TASK)); #else /* PREPARE_RETURN_CPUEXC */ syslog(LOG_NOTICE, "Sample program ends with exception."); SVC_PERROR(ext_ker()); assert(0); #endif /* PREPARE_RETURN_CPUEXC */ }
/* * メインタスク */ void main_task(intptr_t exinf) { syslog(LOG_NOTICE, "Sample program starts (exinf = %d).", (int_t) exinf); /* GPIO0のLED制御ピンを出力にする */ GPIO_SetDir( 0, // GPIOポート番号 LEDMASK, // 操作するビットマスク 1 // 設定する値 ); while(1) { /* 500m秒待つ */ SVC_PERROR(tslp_tsk(500)); /* LED制御ピンをLにする */ GPIO_ClearValue( 0, // GPIOポート番号 LEDMASK // 操作するビットマスク ); /* 500m秒待つ */ SVC_PERROR(tslp_tsk(500)); /* LED制御ピンをHにする */ GPIO_SetValue( 0, // GPIOポート番号 LEDMASK // 操作するビットマスク ); } syslog(LOG_NOTICE, "Sample program ends."); SVC_PERROR(ext_ker()); assert(0); }
void cpuexc_handler(void *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_INFO, "sns_loc = %d sns_dsp = %d sns_tex = %d", sns_loc(), sns_dsp(), sns_tex()); syslog(LOG_INFO, "xsns_dpn = %d xsns_xpn = %d", xsns_dpn(p_excinf), xsns_xpn(p_excinf)); if (xsns_xpn(p_excinf)) { syslog(LOG_NOTICE, "Sample program ends with exception."); SVC_PERROR(ext_ker()); assert(0); } SVC_PERROR(iget_tid(&tskid)); SVC_PERROR(iras_tex(tskid, 0x8000U)); }
/* * アラームハンドラ * * HIGH_PRIORITY,MID_PRIORITY,LOW_PRIORITY の各優先度のレディキュー * を回転させる. */ void alarm_handler(intptr_t exinf) { ID prcid = exinf; syslog(LOG_NOTICE, "alarm_handler %d start!", exinf); SVC_PERROR(imrot_rdq(HIGH_PRIORITY, prcid)); SVC_PERROR(imrot_rdq(MID_PRIORITY, prcid)); SVC_PERROR(imrot_rdq(LOW_PRIORITY, prcid)); }
/* * 駆動ハンドラ * 機能: 駆動タスクを起床する */ void nxtrike_drive_handler(intptr_t exinf) { //iwup_tsk(NXTRIKE_DRIVE_TASK); while (1) { SVC_PERROR(wup_tsk(NXTRIKE_DRIVE_TASK)); SVC_PERROR(tslp_tsk(NXTRIKE_DRIVE_HANDLER_T)); } }
static void initialize(intptr_t unused) { btstack_memory_init(); hardware_initialize(); SVC_PERROR(act_tsk(BT_TSK)); SVC_PERROR(act_tsk(BT_QOS_TSK)); #if defined(DEBUG) syslog(LOG_NOTICE, "bluetooth_dri initialized."); #endif }
/* * 並行実行されるタスク */ void task(intptr_t exinf) { volatile ulong_t i; int_t n = 0; int_t tskno = (int_t) exinf; const char *graph[] = { "|", " +", " *" }; char c; SVC_PERROR(ena_tex()); while (true) { 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); SVC_PERROR(ext_tsk()); assert(0); case 's': syslog(LOG_INFO, "#%d#slp_tsk()", tskno); SVC_PERROR(slp_tsk()); break; case 'S': syslog(LOG_INFO, "#%d#tslp_tsk(10000)", tskno); SVC_PERROR(tslp_tsk(10000)); break; case 'd': syslog(LOG_INFO, "#%d#dly_tsk(10000)", tskno); SVC_PERROR(dly_tsk(10000)); break; case 'y': syslog(LOG_INFO, "#%d#dis_tex()", tskno); SVC_PERROR(dis_tex()); break; case 'Y': syslog(LOG_INFO, "#%d#ena_tex()", tskno); SVC_PERROR(ena_tex()); break; #ifdef CPUEXC1 case 'z': syslog(LOG_NOTICE, "#%d#raise CPU exception", tskno); RAISE_CPU_EXCEPTION; break; case 'Z': SVC_PERROR(loc_cpu()); syslog(LOG_NOTICE, "#%d#raise CPU exception", tskno); RAISE_CPU_EXCEPTION; SVC_PERROR(unl_cpu()); break; #endif /* CPUEXC1 */ default: break; } } }
ER load_application(const void *mod_data, SIZE mod_data_sz) { ER ercd; // ev3_led_set_color(LED_GREEN); // chg_status(STATUS_RUNNING); #if 0 // Wait for pressing center button SYSTIM time = 0; uint32_t ledcolor = 0; syslog(LOG_NOTICE, "Press center button to run the application."); while(!global_brick_info.button_pressed[BRICK_BUTTON_ENTER]) { SYSTIM newtime; get_tim(&newtime); if (newtime - time > 500) { // Blink LED brick_misc_command(MISCCMD_SET_LED, ledcolor); ledcolor ^= TA_LED_RED | TA_LED_GREEN; time = newtime; } } while(global_brick_info.button_pressed[BRICK_BUTTON_ENTER]) { SYSTIM newtime; get_tim(&newtime); if (newtime - time > 500) { // Blink LED brick_misc_command(MISCCMD_SET_LED, ledcolor); ledcolor ^= TA_LED_RED | TA_LED_GREEN; time = newtime; } } #endif brick_misc_command(MISCCMD_SET_LED, TA_LED_GREEN); platform_soft_reset(); ercd = dmloader_ins_ldm(mod_data, mod_data_sz, 1); if (ercd != E_OK) { syslog(LOG_ERROR, "Failed to load application, ercd: %d", ercd); } else { app_loaded = true; SVC_PERROR(sta_alm(APP_TER_BTN_ALM, 0)); SVC_PERROR(wai_sem(APP_TER_SEM)); syslog(LOG_NOTICE, "Terminate application."); SVC_PERROR(dmloader_rmv_ldm(1)); brick_misc_command(MISCCMD_SET_LED, TA_LED_GREEN); } // chg_status(STATUS_IDLE); platform_soft_reset(); tslp_tsk(500); return ercd; }
static void initialize(intptr_t unused) { /** * Initialize frame buffers */ static bitmap_t console_bitmap; static uint8_t lcd_console_fb_vmem[((WIDTH + 2) / 3 * HEIGHT)]; console_bitmap.height = HEIGHT; console_bitmap.width = WIDTH; console_bitmap.pixels = lcd_console_fb_vmem; ev3rt_console_fb = &console_bitmap; lcd_screen_fb = &lcd_screen; on_display_fb = lcd_screen_fb; initialize_lcd_font(); initialize_lcd_spi(); st7586fb_probe(&spidev); st7586fb_ioctl(spidev.drvdata, FB_ST7586_INIT_DISPLAY, 0); st7586fb_ioctl(spidev.drvdata, FB_ST7586_START_DISPLAY, 0); lcd_screen.pixels = ((struct fb_info *)(spidev.drvdata))->screen_base; lcd_screen.height = HEIGHT; lcd_screen.width = WIDTH; global_brick_info.lcd_screen = &lcd_screen; SVC_PERROR(act_tsk(LCD_REFRESH_TSK)); }
void initialize_console_dri() { /** * Fill dummy lines in log buffer with spaces */ for (int i = 0; i < CONSOLE_LOG_VIEW_LINES; ++i) for (int j = 0; j < CONSOLE_LOG_VIEW_LINE_WIDTH; ++j) log_buffer[i][j] = ' '; /** * Draw title */ int offset_x; if (strlen("EV3RT Console") * CONSOLE_TITLE_FONT_WIDTH > 178 /* screen width */) offset_x = 0; else offset_x = (178 /* screen width */ - strlen("EV3RT Console") * CONSOLE_TITLE_FONT_WIDTH) / 2; bitmap_bitblt(NULL, 0, 0, ev3rt_console_fb, 0, CONSOLE_TITLE_AREA_Y, 178 /* screen width */, CONSOLE_TITLE_FONT_HEIGHT, ROP_SET); // Clear bitmap_draw_string("EV3RT Console", ev3rt_console_fb, offset_x, CONSOLE_TITLE_AREA_Y, CONSOLE_TITLE_FONT, ROP_COPYINVERTED); // syslog(LOG_NOTICE, "%s", cm->title); /** * Draw menu */ console_menu_perform_action(CONSOLE_MENU_ACT_RESET); /** * Active by default */ SVC_PERROR(set_flg(console_button_flag, 1 << BRICK_BUTTON_BACK)); }
void test_ev3_cychdr(intptr_t idx) { ev3_lcd_fill_rect(0, fonth * idx, EV3_LCD_WIDTH, fonth, EV3_LCD_WHITE); char buf[100]; sprintf(buf, "EV3CYC %d count %d", idx, ++count[idx]); ev3_lcd_draw_string(buf, 0, fonth * idx); SVC_PERROR(tslp_tsk(10)); }
/* * タッチセンサハンドラ */ void nxtrike_touch_sensor_handler(intptr_t exinf) { //nxtrike_touch_sensor_value ^= (sensor_adc(TOUCH_SENSOR) < 512); while (1) { nxtrike_touch_sensor_value = ev3_touch_sensor_is_pressed(touch_sensor); SVC_PERROR(tslp_tsk(NXTRIKE_TOUCH_SENSOR_HANDLER_T)); } }
void initialize_lcd_dri() { initialize(0); softreset(0); ev3_driver_t driver; driver.init_func = NULL; driver.softreset_func = softreset; SVC_PERROR(platform_register_driver(&driver)); }
/* * 並行実行されるタスク */ void task(intptr_t exinf) { volatile ulong_t i; int_t n = 0; int_t tskno = (int_t) (exinf); const char *graph[] = { "|", " +", " *", "||", " ++", " **" }; char_t c; 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); SVC_PERROR(ext_tsk()); assert(0); case 's': syslog(LOG_INFO, "#%d#slp_tsk()", tskno); SVC_PERROR(slp_tsk()); break; case 'S': syslog(LOG_INFO, "#%d#tslp_tsk(10000)", tskno); SVC_PERROR(tslp_tsk(10000)); break; case 'd': syslog(LOG_INFO, "#%d#dly_tsk(10000)", tskno); SVC_PERROR(dly_tsk(10000)); break; case 'g': syslog(LOG_INFO, "#%d#mig_tsk(0,%d)", tskno,tsk_mig_prc); SVC_PERROR(mig_tsk(0,tsk_mig_prc)); break; default: break; } } }
void tcpClient_main(intptr_t exinf) { EthernetInterface network; TCPSocketConnection socket; /* syslogの設定 */ SVC_PERROR(syslog_msk_log(LOG_UPTO(LOG_INFO), LOG_UPTO(LOG_EMERG))); syslog(LOG_NOTICE, "tcpClient:"); syslog(LOG_NOTICE, "Sample program starts (exinf = %d).", (int_t) exinf); syslog(LOG_NOTICE, "LOG_NOTICE: Network Setting up..."); #if (USE_DHCP == 1) if (network.init() != 0) { //for DHCP Server #else if (network.init(IP_ADDRESS, SUBNET_MASK, DEFAULT_GATEWAY) != 0) { //for Static IP Address (IPAddress, NetMasks, Gateway) #endif syslog(LOG_NOTICE, "Network Initialize Error"); return; } syslog(LOG_NOTICE, "Network was initialized successfully"); while (network.connect(5000) != 0) { syslog(LOG_NOTICE, "LOG_NOTICE: Network Connect Error"); } syslog(LOG_NOTICE, "MAC Address is %s", network.getMACAddress()); syslog(LOG_NOTICE, "IP Address is %s", network.getIPAddress()); syslog(LOG_NOTICE, "NetMask is %s", network.getNetworkMask()); syslog(LOG_NOTICE, "Gateway Address is %s", network.getGateway()); syslog(LOG_NOTICE, "Network Setup OK..."); while (socket.connect(SERVER, HTTP_PORT) < 0) { syslog(LOG_EMERG, "Unable to connect to (%s) on port (%d)", SERVER, HTTP_PORT); wait(1.0); } ClientGreet(&socket); socket.close(); syslog(LOG_NOTICE, "program end"); } // set mac address void mbed_mac_address(char *mac) { // PEACH1 mac[0] = 0x00; mac[1] = 0x02; mac[2] = 0xF7; mac[3] = 0xF0; mac[4] = 0x00; mac[5] = 0x00; }
/* * 並行して実行されるタスク用のタスク例外処理ルーチン */ void tex_routine(TEXPTN texptn, intptr_t exinf) { volatile ulong_t i; int_t tskno = (int_t) exinf; syslog(LOG_NOTICE, "task%d receives exception 0x%04x.", tskno, texptn); for (i = 0; i < tex_loop; i++); if ((texptn & 0x8000U) != 0U) { syslog(LOG_INFO, "#%d#ext_tsk()", tskno); SVC_PERROR(ext_tsk()); assert(0); } }
ER load_application(const void *mod_data, SIZE mod_data_sz) { ER ercd; real_kernel_evt_hdr = kernel_evt_hdr; ev3_motors_init(NONE_MOTOR, NONE_MOTOR, NONE_MOTOR, NONE_MOTOR); handle_btn_clicked = false; ev3_led_set_color(LED_GREEN); chg_status(STATUS_RUNNING); ercd = dmloader_ins_ldm(mod_data, mod_data_sz, 1); if (ercd != E_OK) { syslog(LOG_ERROR, "Failed to load app, ercd: %d", ercd); } else { SVC_PERROR(wai_sem(APP_TER_SEM)); syslog(LOG_NOTICE, "HERE dmloader_rmv_ldm"); SVC_PERROR(dmloader_rmv_ldm(1)); } chg_status(STATUS_IDLE); for(ID i = EV3_PORT_A; i <= EV3_PORT_D; i++) ev3_motor_config(i, NONE_MOTOR); return ercd; }
void main_task(intptr_t exinf) { //串口任务初始化 ER_UINT ercd; SVC_PERROR(syslog_msk_log(LOG_UPTO(LOG_NOTICE), LOG_UPTO(LOG_EMERG))); syslog(LOG_NOTICE, "Sample program starts (exinf = %d).", (int_t) exinf); ercd = serial_opn_por(TASK_PORTID); if (ercd < 0 && MERCD(ercd) != E_OBJ) { syslog(LOG_ERROR, "%s (%d) reported by `serial_opn_por'.", itron_strerror(ercd), SERCD(ercd)); } SVC_PERROR(serial_ctl_por(TASK_PORTID, (IOCTL_CRLF | IOCTL_FCSND | IOCTL_FCRCV))); //初始化其它的任务 SVC_PERROR(act_tsk(SPEED_TASK)); SVC_PERROR(act_tsk(FOLLOW_TASK)); SVC_PERROR(act_tsk(SENSORS_TASK)); SVC_PERROR(sta_cyc(CYC_HANDLE)); //结束自己的使命 ext_tsk(); }
/* * 並行実行されるタスク */ void task(intptr_t exinf) { volatile ulong_t i; int_t n = 0; int_t tskno = (int_t) exinf; const char *graph[] = { "| ", " + ", " *" }; char c; #ifdef TOPPERS_SUPPORT_OVRHDR T_ROVR pk_rovr; #endif /* TOPPERS_SUPPORT_OVRHDR */ while (true) { #ifdef TOPPERS_SUPPORT_OVRHDR SVC_PERROR(ref_ovr(TSK_SELF, &pk_rovr)); if ((pk_rovr.ovrstat & TOVR_STA) != 0) { syslog(LOG_NOTICE, "task%d is running (%03d). %s [%ld]", tskno, ++n, graph[tskno-1], pk_rovr.leftotm); } else { syslog(LOG_NOTICE, "task%d is running (%03d). %s", tskno, ++n, graph[tskno-1]); } #else /* TOPPERS_SUPPORT_OVRHDR */ syslog(LOG_NOTICE, "task%d is running (%03d). %s", tskno, ++n, graph[tskno-1]); #endif /* TOPPERS_SUPPORT_OVRHDR */ 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); SVC_PERROR(ext_tsk()); assert(0); case 's': syslog(LOG_INFO, "#%d#slp_tsk()", tskno); SVC_PERROR(slp_tsk()); break; case 'S': syslog(LOG_INFO, "#%d#tslp_tsk(10000000)", tskno); SVC_PERROR(tslp_tsk(10000000)); break; case 'd': syslog(LOG_INFO, "#%d#dly_tsk(10000000)", tskno); SVC_PERROR(dly_tsk(10000000)); break; case 'y': syslog(LOG_INFO, "#%d#dis_ter()", tskno); SVC_PERROR(dis_ter()); break; case 'Y': syslog(LOG_INFO, "#%d#ena_ter()", tskno); SVC_PERROR(ena_ter()); break; #ifdef CPUEXC1 case 'z': syslog(LOG_NOTICE, "#%d#raise CPU exception", tskno); RAISE_CPU_EXCEPTION; break; case 'Z': SVC_PERROR(loc_cpu()); syslog(LOG_NOTICE, "#%d#raise CPU exception", tskno); RAISE_CPU_EXCEPTION; SVC_PERROR(unl_cpu()); break; #endif /* CPUEXC1 */ default: break; } } }
/* * メインタスク */ void main_task(intptr_t exinf) { char_t c; ER_UINT ercd; PRI tskpri; ID prcid = exinf; ID tskid = sample_tskid[(exinf - 1) * 3 ]; int_t tskno = (exinf-1) * 3 + 1; ID cycid = sample_cycid[(int_t)exinf-1]; ID almid = sample_almid[(int_t)exinf-1]; bool_t update_select = true; uint_t tme_select = exinf; uint_t prc_select = exinf; uint32_t server_req; #ifndef TASK_LOOP volatile ulong_t i; SYSTIM stime1, stime2; #endif /* TASK_LOOP */ #ifdef G_SYSLOG uint_t e; #endif /* G_SYSLOG */ SVC_PERROR(syslog_msk_log(LOG_UPTO(LOG_INFO), LOG_UPTO(LOG_EMERG))); syslog(LOG_NOTICE, "Sample program starts (exinf = %d).", (int_t) exinf); /* * シリアルポートの初期化 * * システムログタスクと同じシリアルポートを使う場合など,シリアル * ポートがオープン済みの場合にはここでE_OBJエラーになるが,支障は * ない. */ ercd = serial_opn_por(((int_t)serial_port[exinf-1])); if (ercd < 0 && MERCD(ercd) != E_OBJ) { syslog(LOG_ERROR, "%s (%d) reported by `serial_opn_por'.", itron_strerror(ercd), SERCD(ercd)); } SVC_PERROR(serial_ctl_por(serial_port[exinf-1], (IOCTL_CRLF | IOCTL_FCSND | IOCTL_FCRCV))); /* * ループ回数の設定 * * TASK_LOOPがマクロ定義されている場合,測定せずに,TASK_LOOPに定 * 義された値を,タスク内でのループ回数とする. * * MEASURE_TWICEがマクロ定義されている場合,1回目の測定結果を捨て * て,2回目の測定結果を使う.1回目の測定は長めの時間が出るため. */ #ifdef TASK_LOOP task_loop = TASK_LOOP; #else /* TASK_LOOP */ #ifdef MEASURE_TWICE task_loop = LOOP_REF; SVC_PERROR(get_tim(&stime1)); for (i = 0; i < task_loop; i++); SVC_PERROR(get_tim(&stime2)); #endif /* MEASURE_TWICE */ task_loop = LOOP_REF; SVC_PERROR(get_tim(&stime1)); for (i = 0; i < task_loop; i++); SVC_PERROR(get_tim(&stime2)); task_loop = LOOP_REF * 400UL / (stime2 - stime1); #endif /* TASK_LOOP */ /* * タスクの起動 */ SVC_PERROR(act_tsk(tskid)); /* * メインループ */ do { if (update_select) { prcid = prc_select; cycid = sample_cycid[tme_select-1]; almid = sample_almid[tme_select-1]; tsk_mig_prc = prcid; update_select = false; syslog(LOG_INFO, "select tskno 0x%x", tskno); syslog(LOG_INFO, "select cycid %d", cycid); syslog(LOG_INFO, "select almid %d", almid); syslog(LOG_INFO, "select processor %d", prcid); } SVC_PERROR(serial_rea_dat(serial_port[exinf-1], &c, 1)); switch (c) { case 'e': case 's': case 'S': case 'd': case 'g': message[tskno - 1] = c; break; case '1': tskno = 1; tskid = TASK1; update_select = true; break; case '2': tskno = 2; tskid = TASK2; update_select = true; break; case '3': tskno = 3; tskid = TASK3; update_select = true; break; case '4': tskno = 4; tskid = TASK4; update_select = true; break; case '5': tskno = 5; tskid = TASK5; update_select = true; break; case '6': tskno = 6; tskid = TASK6; update_select = true; break; case '8': prc_select = 1; update_select = true; break; case '9': prc_select = 2; update_select = true; break; case 'a': syslog(LOG_INFO, "#act_tsk(0x%x)", tskno); SVC_PERROR(act_tsk(tskid)); break; case 'A': syslog(LOG_INFO, "#can_act(0x%x)", tskno); SVC_PERROR(ercd = can_act(tskid)); if (ercd >= 0) { syslog(LOG_NOTICE, "can_act(0x%x) returns %d", tskno, ercd); } break; case '>': syslog(LOG_INFO, "#chg_pri(0x%x, HIGH_PRIORITY)", tskno); SVC_PERROR(chg_pri(tskid, HIGH_PRIORITY)); break; case '=': syslog(LOG_INFO, "#chg_pri(0x%x, MID_PRIORITY)", tskno); SVC_PERROR(chg_pri(tskid, MID_PRIORITY)); break; case '<': syslog(LOG_INFO, "#chg_pri(0x%x, LOW_PRIORITY)", tskno); SVC_PERROR(chg_pri(tskid, LOW_PRIORITY)); break; case 'G': syslog(LOG_INFO, "#get_pri(0x%x, &tskpri)", tskno); SVC_PERROR(ercd = get_pri(tskid, &tskpri)); if (ercd >= 0) { syslog(LOG_NOTICE, "priority of task 0x%x is %d", tskno, tskpri); } break; case 'w': syslog(LOG_INFO, "#wup_tsk(0x%x)", tskno); SVC_PERROR(wup_tsk(tskid)); break; case 'W': syslog(LOG_INFO, "#can_wup(0x%x)", tskno); SVC_PERROR(ercd = can_wup(tskid)); if (ercd >= 0) { syslog(LOG_NOTICE, "can_wup(0x%x) returns %d", tskno, ercd); } break; case 'c': syslog(LOG_INFO, "#sta_cyc(%d)", cycid); SVC_PERROR(sta_cyc(cycid)); break; case 'C': syslog(LOG_INFO, "#stp_cyc(%d)", cycid); SVC_PERROR(stp_cyc(cycid)); break; case 'b': syslog(LOG_INFO, "#sta_alm(%d, %d)", almid, ALM_TIME); SVC_PERROR(sta_alm(almid, ALM_TIME)); break; case 'B': syslog(LOG_INFO, "#stp_alm(%d)", almid); SVC_PERROR(stp_alm(almid)); break; case 'f': syslog(LOG_INFO, "#mact_tsk(%d, %d)", tskid, prcid); SVC_PERROR(mact_tsk(tskid, prcid)); break; default: break; } } while (c != '\003' && c != 'Q'); syslog(LOG_NOTICE, "Sample program ends."); SVC_PERROR(ext_ker()); assert(0); }
/* * main task */ void main_task(intptr_t exinf) { char_t c; ID tskid = TASK1; int_t tskno = 1; ER_UINT ercd; PRI tskpri; #ifndef TASK_LOOP volatile ulong_t i; SYSTIM stime1, stime2; #endif /* TASK_LOOP */ #ifdef TOPPERS_SUPPORT_GET_UTM SYSUTM utime1, utime2; #endif /* TOPPERS_SUPPORT_GET_UTM */ SVC_PERROR(syslog_msk_log(LOG_UPTO(LOG_INFO), LOG_UPTO(LOG_EMERG))); syslog(LOG_NOTICE, "Sample program starts (exinf = %d).", (int_t) exinf); /* * initialize the serial port * * If the same serial port is shared between main task and system * log task. As this serial port is already opened in system log * task, serial_opn_por will return E_OBJ which is not a real * error. */ ercd = serial_opn_por(TASK_PORTID); if (ercd < 0 && MERCD(ercd) != E_OBJ) { syslog(LOG_ERROR, "%s (%d) reported by `serial_opn_por'.", itron_strerror(ercd), SERCD(ercd)); } SVC_PERROR(serial_ctl_por(TASK_PORTID, (IOCTL_CRLF | IOCTL_FCSND | IOCTL_FCRCV))); /* * adjustment of task_loop. * * If TASK_LOOP is defined, the adjustment of task_loop will not be * done. * * If MEASURE_TWICE is defined, 2 measurements are made. The 2nd * result is adopted as the 1st is a little longer than the 2nd. */ #ifdef TASK_LOOP task_loop = TASK_LOOP; #else /* TASK_LOOP */ #ifdef MEASURE_TWICE task_loop = LOOP_REF; SVC_PERROR(get_tim(&stime1)); for (i = 0; i < task_loop; i++); SVC_PERROR(get_tim(&stime2)); #endif /* MEASURE_TWICE */ task_loop = LOOP_REF; SVC_PERROR(get_tim(&stime1)); for (i = 0; i < task_loop; i++); SVC_PERROR(get_tim(&stime2)); task_loop = LOOP_REF * 400UL / (stime2 - stime1); #endif /* TASK_LOOP */ tex_loop = task_loop / 5; /* * activate the target tasks */ SVC_PERROR(act_tsk(TASK1)); SVC_PERROR(act_tsk(TASK2)); SVC_PERROR(act_tsk(TASK3)); /* * main loop */ do { SVC_PERROR(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); SVC_PERROR(act_tsk(tskid)); break; case 'A': syslog(LOG_INFO, "#can_act(%d)", tskno); SVC_PERROR(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); SVC_PERROR(ter_tsk(tskid)); break; case '>': syslog(LOG_INFO, "#chg_pri(%d, HIGH_PRIORITY)", tskno); SVC_PERROR(chg_pri(tskid, HIGH_PRIORITY)); break; case '=': syslog(LOG_INFO, "#chg_pri(%d, MID_PRIORITY)", tskno); SVC_PERROR(chg_pri(tskid, MID_PRIORITY)); break; case '<': syslog(LOG_INFO, "#chg_pri(%d, LOW_PRIORITY)", tskno); SVC_PERROR(chg_pri(tskid, LOW_PRIORITY)); break; case 'G': syslog(LOG_INFO, "#get_pri(%d, &tskpri)", tskno); SVC_PERROR(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); SVC_PERROR(wup_tsk(tskid)); break; case 'W': syslog(LOG_INFO, "#can_wup(%d)", tskno); SVC_PERROR(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); SVC_PERROR(rel_wai(tskid)); break; case 'u': syslog(LOG_INFO, "#sus_tsk(%d)", tskno); SVC_PERROR(sus_tsk(tskid)); break; case 'm': syslog(LOG_INFO, "#rsm_tsk(%d)", tskno); SVC_PERROR(rsm_tsk(tskid)); break; case 'x': syslog(LOG_INFO, "#ras_tex(%d, 0x0001U)", tskno); SVC_PERROR(ras_tex(tskid, 0x0001U)); break; case 'X': syslog(LOG_INFO, "#ras_tex(%d, 0x0002U)", tskno); SVC_PERROR(ras_tex(tskid, 0x0002U)); break; case 'r': syslog(LOG_INFO, "#rot_rdq(three priorities)"); SVC_PERROR(rot_rdq(HIGH_PRIORITY)); SVC_PERROR(rot_rdq(MID_PRIORITY)); SVC_PERROR(rot_rdq(LOW_PRIORITY)); break; case 'c': syslog(LOG_INFO, "#sta_cyc(1)"); SVC_PERROR(sta_cyc(CYCHDR1)); break; case 'C': syslog(LOG_INFO, "#stp_cyc(1)"); SVC_PERROR(stp_cyc(CYCHDR1)); break; case 'b': syslog(LOG_INFO, "#sta_alm(1, 5000)"); SVC_PERROR(sta_alm(ALMHDR1, 5000)); break; case 'B': syslog(LOG_INFO, "#stp_alm(1)"); SVC_PERROR(stp_alm(ALMHDR1)); break; case 'V': #ifdef TOPPERS_SUPPORT_GET_UTM SVC_PERROR(get_utm(&utime1)); SVC_PERROR(get_utm(&utime2)); syslog(LOG_NOTICE, "utime1 = %ld, utime2 = %ld", (ulong_t) utime1, (ulong_t) utime2); #else /* TOPPERS_SUPPORT_GET_UTM */ syslog(LOG_NOTICE, "get_utm is not supported."); #endif /* TOPPERS_SUPPORT_GET_UTM */ break; case 'v': SVC_PERROR(syslog_msk_log(LOG_UPTO(LOG_INFO), LOG_UPTO(LOG_EMERG))); break; case 'q': SVC_PERROR(syslog_msk_log(LOG_UPTO(LOG_NOTICE), LOG_UPTO(LOG_EMERG))); break; #ifdef BIT_KERNEL case ' ': SVC_PERROR(loc_cpu()); { extern ER bit_kernel(void); SVC_PERROR(ercd = bit_kernel()); if (ercd >= 0) { syslog(LOG_NOTICE, "bit_kernel passed."); } } SVC_PERROR(unl_cpu()); break; #endif /* BIT_KERNEL */ default: break; } } while (c != '\003' && c != 'Q'); syslog(LOG_NOTICE, "Sample program ends."); SVC_PERROR(ext_ker()); assert(0); }
/* * メインタスク */ void main_task(intptr_t exinf) { char_t c; ID tskid = TASK1; int_t tskno = 1; ER_UINT ercd; PRI tskpri; #ifndef TASK_LOOP volatile ulong_t i; SYSTIM stime1, stime2; #endif /* TASK_LOOP */ #ifdef TOPPERS_SUPPORT_GET_UTM SYSUTM utime1, utime2; #endif /* TOPPERS_SUPPORT_GET_UTM */ SVC_PERROR(syslog_msk_log(LOG_UPTO(LOG_INFO), LOG_UPTO(LOG_EMERG))); syslog(LOG_NOTICE, "Sample program starts (exinf = %d).", (int_t) exinf); /* * シリアルポートの初期化 * * システムログタスクと同じシリアルポートを使う場合など,シリアル * ポートがオープン済みの場合にはここでE_OBJエラーになるが,支障は * ない. */ ercd = serial_opn_por(TASK_PORTID); if (ercd < 0 && MERCD(ercd) != E_OBJ) { syslog(LOG_ERROR, "%s (%d) reported by `serial_opn_por'.", itron_strerror(ercd), SERCD(ercd)); } SVC_PERROR(serial_ctl_por(TASK_PORTID, (IOCTL_CRLF | IOCTL_FCSND | IOCTL_FCRCV))); /* * ループ回数の設定 * * TASK_LOOPがマクロ定義されている場合,測定せずに,TASK_LOOPに定 * 義された値を,タスク内でのループ回数とする. * * MEASURE_TWICEがマクロ定義されている場合,1回目の測定結果を捨て * て,2回目の測定結果を使う.1回目の測定は長めの時間が出るため. */ #ifdef TASK_LOOP task_loop = TASK_LOOP; #else /* TASK_LOOP */ #ifdef MEASURE_TWICE task_loop = LOOP_REF; SVC_PERROR(get_tim(&stime1)); for (i = 0; i < task_loop; i++); SVC_PERROR(get_tim(&stime2)); #endif /* MEASURE_TWICE */ task_loop = LOOP_REF; SVC_PERROR(get_tim(&stime1)); for (i = 0; i < task_loop; i++); SVC_PERROR(get_tim(&stime2)); task_loop = LOOP_REF * 400UL / (stime2 - stime1); #endif /* TASK_LOOP */ tex_loop = task_loop / 5; /* * タスクの起動 */ SVC_PERROR(act_tsk(TASK1)); SVC_PERROR(act_tsk(TASK2)); SVC_PERROR(act_tsk(TASK3)); /* * メインループ */ do { SVC_PERROR(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); SVC_PERROR(act_tsk(tskid)); break; case 'A': syslog(LOG_INFO, "#can_act(%d)", tskno); SVC_PERROR(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); SVC_PERROR(ter_tsk(tskid)); break; case '>': syslog(LOG_INFO, "#chg_pri(%d, HIGH_PRIORITY)", tskno); SVC_PERROR(chg_pri(tskid, HIGH_PRIORITY)); break; case '=': syslog(LOG_INFO, "#chg_pri(%d, MID_PRIORITY)", tskno); SVC_PERROR(chg_pri(tskid, MID_PRIORITY)); break; case '<': syslog(LOG_INFO, "#chg_pri(%d, LOW_PRIORITY)", tskno); SVC_PERROR(chg_pri(tskid, LOW_PRIORITY)); break; case 'G': syslog(LOG_INFO, "#get_pri(%d, &tskpri)", tskno); SVC_PERROR(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); SVC_PERROR(wup_tsk(tskid)); break; case 'W': syslog(LOG_INFO, "#can_wup(%d)", tskno); SVC_PERROR(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); SVC_PERROR(rel_wai(tskid)); break; case 'u': syslog(LOG_INFO, "#sus_tsk(%d)", tskno); SVC_PERROR(sus_tsk(tskid)); break; case 'm': syslog(LOG_INFO, "#rsm_tsk(%d)", tskno); SVC_PERROR(rsm_tsk(tskid)); break; case 'x': syslog(LOG_INFO, "#ras_tex(%d, 0x0001U)", tskno); SVC_PERROR(ras_tex(tskid, 0x0001U)); break; case 'X': syslog(LOG_INFO, "#ras_tex(%d, 0x0002U)", tskno); SVC_PERROR(ras_tex(tskid, 0x0002U)); break; case 'r': syslog(LOG_INFO, "#rot_rdq(three priorities)"); SVC_PERROR(rot_rdq(HIGH_PRIORITY)); SVC_PERROR(rot_rdq(MID_PRIORITY)); SVC_PERROR(rot_rdq(LOW_PRIORITY)); break; case 'c': syslog(LOG_INFO, "#sta_cyc(1)"); SVC_PERROR(sta_cyc(CYCHDR1)); break; case 'C': syslog(LOG_INFO, "#stp_cyc(1)"); SVC_PERROR(stp_cyc(CYCHDR1)); break; case 'b': syslog(LOG_INFO, "#sta_alm(1, 5000)"); SVC_PERROR(sta_alm(ALMHDR1, 5000)); break; case 'B': syslog(LOG_INFO, "#stp_alm(1)"); SVC_PERROR(stp_alm(ALMHDR1)); break; case 'V': #ifdef TOPPERS_SUPPORT_GET_UTM SVC_PERROR(get_utm(&utime1)); SVC_PERROR(get_utm(&utime2)); syslog(LOG_NOTICE, "utime1 = %ld, utime2 = %ld", (ulong_t) utime1, (ulong_t) utime2); #else /* TOPPERS_SUPPORT_GET_UTM */ syslog(LOG_NOTICE, "get_utm is not supported."); #endif /* TOPPERS_SUPPORT_GET_UTM */ break; case 'v': SVC_PERROR(syslog_msk_log(LOG_UPTO(LOG_INFO), LOG_UPTO(LOG_EMERG))); break; case 'q': SVC_PERROR(syslog_msk_log(LOG_UPTO(LOG_NOTICE), LOG_UPTO(LOG_EMERG))); break; #ifdef BIT_KERNEL case ' ': SVC_PERROR(loc_cpu()); { extern ER bit_kernel(void); SVC_PERROR(ercd = bit_kernel()); if (ercd >= 0) { syslog(LOG_NOTICE, "bit_kernel passed."); } } SVC_PERROR(unl_cpu()); break; #endif /* BIT_KERNEL */ default: break; } } while (c != '\003' && c != 'Q'); syslog(LOG_NOTICE, "Sample program ends."); SVC_PERROR(ext_ker()); assert(0); }
/* * 例外処理タスク */ void exc_task(intptr_t exinf) { SVC_PERROR(ras_ter(cpuexc_tskid)); }
void initialize_i2c_dri(intptr_t unused) { ev3_driver_t driver; driver.init_func = initialize; driver.softreset_func = NULL; SVC_PERROR(platform_register_driver(&driver)); }
/** * Application task wrapper * \param exinf Pointer of actual T_CTSK */ static void app_tsk_wrapper(intptr_t exinf) { const T_CTSK *pk_ctsk = (const T_CTSK *)exinf; SVC_PERROR(ena_tex()); pk_ctsk->task(pk_ctsk->exinf); }
/* * メインタスク */ void main_task(intptr_t exinf) { char c; ID tskid = TASK1; int_t tskno = 1; ER_UINT ercd; PRI tskpri; #ifndef TASK_LOOP volatile ulong_t i; SYSTIM stime1, stime2; #endif /* TASK_LOOP */ #ifdef TOPPERS_SUPPORT_GET_UTM SYSUTM utime1, utime2; #endif /* TOPPERS_SUPPORT_GET_UTM */ T_CTSK ctsk; T_DTEX dtex; ID TASK3 = -1; SVC_PERROR(syslog_msk_log(LOG_UPTO(LOG_INFO), LOG_UPTO(LOG_EMERG))); syslog(LOG_NOTICE, "Sample program starts (exinf = %d).", (int_t) exinf); /* * シリアルポートの初期化 * * システムログタスクと同じシリアルポートを使う場合など,シリアル * ポートがオープン済みの場合にはここでE_OBJエラーになるが,支障は * ない. */ ercd = serial_opn_por(TASK_PORTID); if (ercd < 0 && MERCD(ercd) != E_OBJ) { syslog(LOG_ERROR, "%s (%d) reported by `serial_opn_por'.", itron_strerror(ercd), SERCD(ercd)); } SVC_PERROR(serial_ctl_por(TASK_PORTID, (IOCTL_CRLF | IOCTL_FCSND | IOCTL_FCRCV))); /* * ループ回数の設定 * * 並行実行されるタスク内での空ループの回数(task_loop)は,空ルー * プの実行時間が約0.4秒になるように設定する.この設定のために, * LOOP_REF回の空ループの実行時間を,その前後でget_timを呼ぶことで * 測定し,その測定結果から空ループの実行時間が0.4秒になるループ回 * 数を求め,task_loopに設定する. * * LOOP_REFは,デフォルトでは1,000,000に設定しているが,想定したよ * り遅いプロセッサでは,サンプルプログラムの実行開始に時間がかか * りすぎるという問題を生じる.逆に想定したより速いプロセッサでは, * LOOP_REF回の空ループの実行時間が短くなり,task_loopに設定する値 * の誤差が大きくなるという問題がある. * * そこで,そのようなターゲットでは,target_test.hで,LOOP_REFを適 * 切な値に定義するのが望ましい. * * また,task_loopの値を固定したい場合には,その値をTASK_LOOPにマ * クロ定義する.TASK_LOOPがマクロ定義されている場合,上記の測定を * 行わずに,TASK_LOOPに定義された値を空ループの回数とする. * * ターゲットによっては,空ループの実行時間の1回目の測定で,本来よ * りも長めになるものがある.このようなターゲットでは,MEASURE_TWICE * をマクロ定義することで,1回目の測定結果を捨てて,2回目の測定結果 * を使う. * * タスク例外処理ルーチン内での空ループの回数(tex_loop)は, * task_loopの4分の1の値(空ループの実行時間が0.1秒になるループ回 * 数)に設定する. */ #ifdef TASK_LOOP task_loop = TASK_LOOP; #else /* TASK_LOOP */ #ifdef MEASURE_TWICE task_loop = LOOP_REF; SVC_PERROR(get_tim(&stime1)); for (i = 0; i < task_loop; i++); SVC_PERROR(get_tim(&stime2)); #endif /* MEASURE_TWICE */ task_loop = LOOP_REF; SVC_PERROR(get_tim(&stime1)); for (i = 0; i < task_loop; i++); SVC_PERROR(get_tim(&stime2)); task_loop = LOOP_REF * 400UL / (stime2 - stime1); #endif /* TASK_LOOP */ tex_loop = task_loop / 4; /* * タスクの起動 */ SVC_PERROR(act_tsk(TASK1)); SVC_PERROR(act_tsk(TASK2)); /* * メインループ */ do { SVC_PERROR(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); SVC_PERROR(act_tsk(tskid)); break; case 'A': syslog(LOG_INFO, "#can_act(%d)", tskno); SVC_PERROR(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); SVC_PERROR(ter_tsk(tskid)); break; case '>': syslog(LOG_INFO, "#chg_pri(%d, HIGH_PRIORITY)", tskno); SVC_PERROR(chg_pri(tskid, HIGH_PRIORITY)); break; case '=': syslog(LOG_INFO, "#chg_pri(%d, MID_PRIORITY)", tskno); SVC_PERROR(chg_pri(tskid, MID_PRIORITY)); break; case '<': syslog(LOG_INFO, "#chg_pri(%d, LOW_PRIORITY)", tskno); SVC_PERROR(chg_pri(tskid, LOW_PRIORITY)); break; case 'G': syslog(LOG_INFO, "#get_pri(%d, &tskpri)", tskno); SVC_PERROR(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); SVC_PERROR(wup_tsk(tskid)); break; case 'W': syslog(LOG_INFO, "#can_wup(%d)", tskno); SVC_PERROR(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); SVC_PERROR(rel_wai(tskid)); break; case 'u': syslog(LOG_INFO, "#sus_tsk(%d)", tskno); SVC_PERROR(sus_tsk(tskid)); break; case 'm': syslog(LOG_INFO, "#rsm_tsk(%d)", tskno); SVC_PERROR(rsm_tsk(tskid)); break; case 'x': syslog(LOG_INFO, "#ras_tex(%d, 0x0001U)", tskno); SVC_PERROR(ras_tex(tskid, 0x0001U)); break; case 'X': syslog(LOG_INFO, "#ras_tex(%d, 0x0002U)", tskno); SVC_PERROR(ras_tex(tskid, 0x0002U)); break; case 'r': syslog(LOG_INFO, "#rot_rdq(three priorities)"); SVC_PERROR(rot_rdq(HIGH_PRIORITY)); SVC_PERROR(rot_rdq(MID_PRIORITY)); SVC_PERROR(rot_rdq(LOW_PRIORITY)); break; case 'c': syslog(LOG_INFO, "#sta_cyc(1)"); SVC_PERROR(sta_cyc(CYCHDR1)); break; case 'C': syslog(LOG_INFO, "#stp_cyc(1)"); SVC_PERROR(stp_cyc(CYCHDR1)); break; case 'b': syslog(LOG_INFO, "#sta_alm(1, 5000)"); SVC_PERROR(sta_alm(ALMHDR1, 5000)); break; case 'B': syslog(LOG_INFO, "#stp_alm(1)"); SVC_PERROR(stp_alm(ALMHDR1)); break; case '@': ctsk.tskatr = TA_NULL; ctsk.exinf = 3; ctsk.task = task; ctsk.itskpri = MID_PRIORITY; ctsk.stksz = STACK_SIZE; ctsk.stk = NULL; SVC_PERROR(TASK3 = acre_tsk(&ctsk)); dtex.texatr = TA_NULL; dtex.texrtn = tex_routine; SVC_PERROR(def_tex(TASK3, &dtex)); syslog(LOG_NOTICE, "task3 is created with tskid = %d.", (int_t) TASK3); break; case '!': syslog(LOG_INFO, "#del_tsk(%d)", tskno); SVC_PERROR(del_tsk(tskid)); break; case 'V': #ifdef TOPPERS_SUPPORT_GET_UTM SVC_PERROR(get_utm(&utime1)); SVC_PERROR(get_utm(&utime2)); syslog(LOG_NOTICE, "utime1 = %ld, utime2 = %ld", (ulong_t) utime1, (ulong_t) utime2); #else /* TOPPERS_SUPPORT_GET_UTM */ syslog(LOG_NOTICE, "get_utm is not supported."); #endif /* TOPPERS_SUPPORT_GET_UTM */ break; case 'v': SVC_PERROR(syslog_msk_log(LOG_UPTO(LOG_INFO), LOG_UPTO(LOG_EMERG))); break; case 'q': SVC_PERROR(syslog_msk_log(LOG_UPTO(LOG_NOTICE), LOG_UPTO(LOG_EMERG))); break; #ifdef BIT_KERNEL case ' ': SVC_PERROR(loc_cpu()); { extern ER bit_kernel(void); SVC_PERROR(ercd = bit_kernel()); if (ercd >= 0) { syslog(LOG_NOTICE, "bit_kernel passed."); } } SVC_PERROR(unl_cpu()); break; #endif /* BIT_KERNEL */ case '$': syslog(LOG_INFO, "#%d#twai_sem(10000)", tskno); SVC_PERROR(twai_sem(TEST_SEM, 10000)); break; default: break; } } while (c != '\003' && c != 'Q'); syslog(LOG_NOTICE, "Sample program ends."); SVC_PERROR(ext_ker()); assert(0); }
/* * アラームハンドラ * * HIGH_PRIORITY,MID_PRIORITY,LOW_PRIORITY の各優先度のレディキュー * を回転させる. */ void alarm_handler(intptr_t exinf) { SVC_PERROR(rot_rdq(HIGH_PRIORITY)); SVC_PERROR(rot_rdq(MID_PRIORITY)); SVC_PERROR(rot_rdq(LOW_PRIORITY)); }
/* * 周期ハンドラ * * HIGH_PRIORITY,MID_PRIORITY,LOW_PRIORITY の各優先度のレディキュー * を回転させる. */ void cyclic_handler(intptr_t exinf) { SVC_PERROR(irot_rdq(HIGH_PRIORITY)); SVC_PERROR(irot_rdq(MID_PRIORITY)); SVC_PERROR(irot_rdq(LOW_PRIORITY)); }
/* * メインタスク */ void main_task(intptr_t exinf) { char c; ID tskid = TASK1; int_t tskno = 1; ER_UINT ercd; PRI tskpri; #ifndef TASK_LOOP volatile ulong_t i; SYSTIM stime1, stime2; #endif /* TASK_LOOP */ HRTCNT hrtcnt1, hrtcnt2; SVC_PERROR(syslog_msk_log(LOG_UPTO(LOG_INFO), LOG_UPTO(LOG_EMERG))); syslog(LOG_NOTICE, "Sample program starts (exinf = %d).", (int_t) exinf); /* * シリアルポートの初期化 * * システムログタスクと同じシリアルポートを使う場合など,シリアル * ポートがオープン済みの場合にはここでE_OBJエラーになるが,支障は * ない. */ ercd = serial_opn_por(TASK_PORTID); if (ercd < 0 && MERCD(ercd) != E_OBJ) { syslog(LOG_ERROR, "%s (%d) reported by `serial_opn_por'.", itron_strerror(ercd), SERCD(ercd)); } SVC_PERROR(serial_ctl_por(TASK_PORTID, (IOCTL_CRLF | IOCTL_FCSND | IOCTL_FCRCV))); /* * ループ回数の設定 * * 並行実行されるタスク内での空ループの回数(task_loop)は,空ルー * プの実行時間が約0.4秒になるように設定する.この設定のために, * LOOP_REF回の空ループの実行時間を,その前後でget_timを呼ぶことで * 測定し,その測定結果から空ループの実行時間が0.4秒になるループ回 * 数を求め,task_loopに設定する. * * LOOP_REFは,デフォルトでは1,000,000に設定しているが,想定したよ * り遅いプロセッサでは,サンプルプログラムの実行開始に時間がかか * りすぎるという問題を生じる.逆に想定したより速いプロセッサでは, * LOOP_REF回の空ループの実行時間が短くなり,task_loopに設定する値 * の誤差が大きくなるという問題がある. * * そこで,そのようなターゲットでは,target_test.hで,LOOP_REFを適 * 切な値に定義するのが望ましい. * * また,task_loopの値を固定したい場合には,その値をTASK_LOOPにマ * クロ定義する.TASK_LOOPがマクロ定義されている場合,上記の測定を * 行わずに,TASK_LOOPに定義された値を空ループの回数とする. * * ターゲットによっては,空ループの実行時間の1回目の測定で,本来よ * りも長めになるものがある.このようなターゲットでは,MEASURE_TWICE * をマクロ定義することで,1回目の測定結果を捨てて,2回目の測定結果 * を使う. */ #ifdef TASK_LOOP task_loop = TASK_LOOP; #else /* TASK_LOOP */ #ifdef MEASURE_TWICE task_loop = LOOP_REF; SVC_PERROR(get_tim(&stime1)); for (i = 0; i < task_loop; i++); SVC_PERROR(get_tim(&stime2)); #endif /* MEASURE_TWICE */ task_loop = LOOP_REF; SVC_PERROR(get_tim(&stime1)); for (i = 0; i < task_loop; i++); SVC_PERROR(get_tim(&stime2)); task_loop = LOOP_REF * 400LU / (ulong_t)(stime2 - stime1) * 1000LU; #endif /* TASK_LOOP */ /* * タスクの起動 */ SVC_PERROR(act_tsk(TASK1)); SVC_PERROR(act_tsk(TASK2)); SVC_PERROR(act_tsk(TASK3)); /* * メインループ */ do { SVC_PERROR(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); SVC_PERROR(act_tsk(tskid)); break; case 'A': syslog(LOG_INFO, "#can_act(%d)", tskno); SVC_PERROR(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); SVC_PERROR(ter_tsk(tskid)); break; case '>': syslog(LOG_INFO, "#chg_pri(%d, HIGH_PRIORITY)", tskno); SVC_PERROR(chg_pri(tskid, HIGH_PRIORITY)); break; case '=': syslog(LOG_INFO, "#chg_pri(%d, MID_PRIORITY)", tskno); SVC_PERROR(chg_pri(tskid, MID_PRIORITY)); break; case '<': syslog(LOG_INFO, "#chg_pri(%d, LOW_PRIORITY)", tskno); SVC_PERROR(chg_pri(tskid, LOW_PRIORITY)); break; case 'G': syslog(LOG_INFO, "#get_pri(%d, &tskpri)", tskno); SVC_PERROR(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); SVC_PERROR(wup_tsk(tskid)); break; case 'W': syslog(LOG_INFO, "#can_wup(%d)", tskno); SVC_PERROR(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); SVC_PERROR(rel_wai(tskid)); break; case 'u': syslog(LOG_INFO, "#sus_tsk(%d)", tskno); SVC_PERROR(sus_tsk(tskid)); break; case 'm': syslog(LOG_INFO, "#rsm_tsk(%d)", tskno); SVC_PERROR(rsm_tsk(tskid)); break; case 'x': syslog(LOG_INFO, "#ras_ter(%d)", tskno); SVC_PERROR(ras_ter(tskid)); break; case 'r': syslog(LOG_INFO, "#rot_rdq(three priorities)"); SVC_PERROR(rot_rdq(HIGH_PRIORITY)); SVC_PERROR(rot_rdq(MID_PRIORITY)); SVC_PERROR(rot_rdq(LOW_PRIORITY)); break; case 'c': syslog(LOG_INFO, "#sta_cyc(1)"); SVC_PERROR(sta_cyc(CYCHDR1)); break; case 'C': syslog(LOG_INFO, "#stp_cyc(1)"); SVC_PERROR(stp_cyc(CYCHDR1)); break; case 'b': syslog(LOG_INFO, "#sta_alm(1, 5000000)"); SVC_PERROR(sta_alm(ALMHDR1, 5000000)); break; case 'B': syslog(LOG_INFO, "#stp_alm(1)"); SVC_PERROR(stp_alm(ALMHDR1)); break; case 'V': hrtcnt1 = fch_hrt(); hrtcnt2 = fch_hrt(); syslog(LOG_NOTICE, "hrtcnt1 = %tu, hrtcnt2 = %tu", hrtcnt1, hrtcnt2); break; case 'o': #ifdef TOPPERS_SUPPORT_OVRHDR syslog(LOG_INFO, "#sta_ovr(%d, 2000000)", tskno); SVC_PERROR(sta_ovr(tskid, 2000000)); #else /* TOPPERS_SUPPORT_OVRHDR */ syslog(LOG_NOTICE, "sta_ovr is not supported."); #endif /* TOPPERS_SUPPORT_OVRHDR */ break; case 'O': #ifdef TOPPERS_SUPPORT_OVRHDR syslog(LOG_INFO, "#stp_ovr(%d)", tskno); SVC_PERROR(stp_ovr(tskid)); #else /* TOPPERS_SUPPORT_OVRHDR */ syslog(LOG_NOTICE, "stp_ovr is not supported."); #endif /* TOPPERS_SUPPORT_OVRHDR */ break; case 'v': SVC_PERROR(syslog_msk_log(LOG_UPTO(LOG_INFO), LOG_UPTO(LOG_EMERG))); break; case 'q': SVC_PERROR(syslog_msk_log(LOG_UPTO(LOG_NOTICE), LOG_UPTO(LOG_EMERG))); break; #ifdef BIT_KERNEL case ' ': SVC_PERROR(loc_cpu()); { extern ER bit_kernel(void); SVC_PERROR(ercd = bit_kernel()); if (ercd >= 0) { syslog(LOG_NOTICE, "bit_kernel passed."); } } SVC_PERROR(unl_cpu()); break; #endif /* BIT_KERNEL */ default: break; } } while (c != '\003' && c != 'Q'); syslog(LOG_NOTICE, "Sample program ends."); SVC_PERROR(ext_ker()); assert(0); }
void ev3_main_task(intptr_t exinf) { ER_UINT ercd; // Pause application at first platform_pause_application(true); /** * Initialize FatFS */ initialize_fatfs_dri(); /** * Load configurations */ ev3rt_load_configuration(); /** * Initialize LCD */ initialize_lcd_dri(); /** * Initialize EV3RT console and open its SIO port. */ initialize_console_dri(); ercd = serial_opn_por(SIO_PORT_LCD); if (ercd < 0 && MERCD(ercd) != E_OBJ) { syslog(LOG_ERROR, "%s (%d) reported by `serial_opn_por'.", itron_strerror(ercd), SERCD(ercd)); } SVC_PERROR(serial_ctl_por(SIO_PORT_LCD, IOCTL_NULL)); platform_pause_application(false); is_initialized = false; // syslog(LOG_NOTICE, "Sample program starts (exinf = %d).", (int_t) exinf); /** * Initialize all drivers */ for(uint32_t i = 0; i < tnum_drivers; ++i) if (drivers[i].init_func != NULL) drivers[i].init_func(0); platform_soft_reset(); // Banner syslog(LOG_NOTICE, ""); syslog(LOG_NOTICE, ""); syslog(LOG_NOTICE, ""); syslog(LOG_NOTICE, ""); syslog(LOG_NOTICE, " _____ ______ ___ ______"); syslog(LOG_NOTICE, " / __/ | / /_ // _ \/_ __/"); syslog(LOG_NOTICE, " / _/ | |/ //_ </ , _/ / /"); syslog(LOG_NOTICE, "/___/ |___/____/_/|_| /_/"); syslog(LOG_NOTICE, "============================="); syslog(LOG_NOTICE, "Powered by TOPPERS/HRP2 RTOS"); syslog(LOG_NOTICE, "Initialization is completed.."); platform_pause_application(true); is_initialized = true; brick_misc_command(MISCCMD_SET_LED, TA_LED_GREEN); #if 0 // Legacy code initialize_analog_dri(); initialize_uart_dri(); initialize_motor_dri(); initialize_sound_dri(); initialize_fatfs_dri(); // initialize_ev3(); // syslog(LOG_ERROR, "TEST ZMODEM"); // uint8_t c; // while(1) { // serial_rea_dat(SIO_PORT_UART, &c, 1); // ER ercd; // switch (c) { // case 'r': // ercd = zmodem_recv_file(app_text_mempool, sizeof(app_text_mempool)); // syslog(LOG_ERROR, "ZMODEM ercd = %d.", ercd); // break; // default: // syslog(LOG_ERROR, "Key %c pressed.", c); // } // } //EV3::ev3 = new EV3::EV3(); //#define TEST_ANALOG_SENSOR // //#ifdef TEST_ANALOG_SENSOR // while(1) { // /* // * Debug Analog Port 2 // */ // int sv = analog_get_short(1); // printk("Sensor PIN1: %d\n", sv); // printk("Sensor PIN6: %d\n", analog_get_short_pin6(1)); // // GPIO67.OUT_DATA ^= GPIO_ED_PIN7 | GPIO_ED_PIN14; // target_fput_log('H'); // target_fput_log('E'); // target_fput_log('R'); // target_fput_log('E'); // target_fput_log('\n'); // tslp_tsk(1000); // } //#endif //#ifdef TEST_UART // //init_pwm(); // //ev3_motor_set_speed(PortA, 50); // //tslp_tsk(3000); // //ev3_motor_brake(PortA, true); // init_uart(); // while(1) { // /* // * Debug UART Port 2 // */ // int sv = uart_get_short(1); // printk("Sensor value: %d\n", sv); // // GPIO67.OUT_DATA ^= GPIO_ED_PIN7 | GPIO_ED_PIN14; // target_fput_log('H'); // target_fput_log('E'); // target_fput_log('R'); // target_fput_log('E'); // target_fput_log('\n'); // tslp_tsk(1000); // } //#endif #endif }