__DEVICE__ void exec_final_outputs (solver_props *props, unsigned int modelid) { int i; for(i=0;i<NUM_ITERATORS;i++){ if (props[i].last_iteration[modelid]) { props[i].last_iteration[modelid] = 0; pre_process(&props[i], modelid); #if defined X_IR_SPIL model_flows(props[i].time[modelid], props[i].model_states, props[i].next_states, props[i].model_inputs, props[i].model_outputs, &props[i], 1, modelid); #else model_flows(props[i].time[modelid], props[i].model_states, props[i].next_states, &props[i], 1, modelid); #endif in_process(&props[i], modelid); // Updates and postprocess should not write to the output data structure // the output data structure holds outputs from the previous iteration and updates/postprocess set values // that will be written to output data by the solver flow of the next iteration /* update(&props[i], modelid); */ /* post_process(&props[i], modelid); */ #if NUM_OUTPUTS > 0 buffer_outputs(&props[i], modelid); #endif } } }
__DEVICE__ int exec_solver_and_inprocess (CDATAFORMAT min_time, solver_props *props, unsigned int modelid) { int i; for(i=0;i<NUM_ITERATORS;i++){ if(props[i].running[modelid] && props[i].time[modelid] == min_time){ if(0 != solver_eval(&props[i], modelid)) { return ERRCOMP; } // Now next_time == time + dt props[i].dirty_states[modelid] = 1; props[i].ready_outputs[modelid] = 1; // Run any in-process algebraic evaluations in_process(&props[i], modelid); } } return SUCCESS; }
/*======================================================================* keyboard_read *======================================================================*/ PUBLIC void keyboard_read(TTY* p_tty) { u8 scan_code; char output[2]; int make; /* 1: make; 0: break. */ u32 key = 0;/* 用一个整型来表示一个键。比如,如果 Home 被按下, * 则 key 值将为定义在 keyboard.h 中的 'HOME'。 */ u32* keyrow; /* 指向 keymap[] 的某一行 */ if(kb_in.count > 0){ code_with_E0 = 0; scan_code = get_byte_from_kbuf(); /* 下面开始解析扫描码 */ if (scan_code == 0xE1) { int i; u8 pausebrk_scode[] = {0xE1, 0x1D, 0x45, 0xE1, 0x9D, 0xC5}; int is_pausebreak = 1; for(i=1;i<6;i++){ if (get_byte_from_kbuf() != pausebrk_scode[i]) { is_pausebreak = 0; break; } } if (is_pausebreak) { key = PAUSEBREAK; } } else if (scan_code == 0xE0) { scan_code = get_byte_from_kbuf(); /* PrintScreen 被按下 */ if (scan_code == 0x2A) { if (get_byte_from_kbuf() == 0xE0) { if (get_byte_from_kbuf() == 0x37) { key = PRINTSCREEN; make = 1; } } } /* PrintScreen 被释放 */ if (scan_code == 0xB7) { if (get_byte_from_kbuf() == 0xE0) { if (get_byte_from_kbuf() == 0xAA) { key = PRINTSCREEN; make = 0; } } } /* 不是PrintScreen, 此时scan_code为0xE0紧跟的那个值. */ if (key == 0) { code_with_E0 = 1; } } if ((key != PAUSEBREAK) && (key != PRINTSCREEN)) { /* 首先判断Make Code 还是 Break Code */ make = (scan_code & FLAG_BREAK ? 0 : 1); /* 先定位到 keymap 中的行 */ keyrow = &keymap[(scan_code & 0x7F) * MAP_COLS]; column = 0; int caps = shift_l || shift_r; if (caps_lock) { if ((keyrow[0] >= 'a') && (keyrow[0] <= 'z')){ caps = !caps; } } if (caps) { column = 1; } if (code_with_E0) { column = 2; } key = keyrow[column]; ////////////////////////////////////////////////////////////////////// if((key==TAB)&&(make)) { tab=1; } else if((key==TAB)&&(!make)&&(!tabAndShift)) { tab=0; key=0x02; in_process(p_tty, key); } else if((key==TAB)&&(!make)&&(tabAndShift)) { tab=0; } tabAndShift=(tab&&caps); ////////////////////////////////////////////////////////////////////// switch(key) { case SHIFT_L: shift_l = make; break; case SHIFT_R: shift_r = make; break; case CTRL_L: ctrl_l = make; break; case CTRL_R: ctrl_r = make; break; case ALT_L: alt_l = make; break; case ALT_R: alt_l = make; break; case CAPS_LOCK: if (make) { caps_lock = !caps_lock; set_leds(); } break; case NUM_LOCK: if (make) { num_lock = !num_lock; set_leds(); } break; case SCROLL_LOCK: if (make) { scroll_lock = !scroll_lock; set_leds(); } break; default: break; } if (make) { /* 忽略 Break Code */ int pad = 0; /* 首先处理小键盘 */ if ((key >= PAD_SLASH) && (key <= PAD_9)) { pad = 1; switch(key) { case PAD_SLASH: key = '/'; break; case PAD_STAR: key = '*'; break; case PAD_MINUS: key = '-'; break; case PAD_PLUS: key = '+'; break; case PAD_ENTER: key = ENTER; break; default: if (num_lock && (key >= PAD_0) && (key <= PAD_9)) { key = key - PAD_0 + '0'; } else if (num_lock && (key == PAD_DOT)) { key = '.'; } else{ switch(key) { case PAD_HOME: key = HOME; break; case PAD_END: key = END; break; case PAD_PAGEUP: key = PAGEUP; break; case PAD_PAGEDOWN: key = PAGEDOWN; break; case PAD_INS: key = INSERT; break; case PAD_UP: key = UP; break; case PAD_DOWN: key = DOWN; break; case PAD_LEFT: key = LEFT; break; case PAD_RIGHT: key = RIGHT; break; case PAD_DOT: key = DELETE; break; default: break; } } break; } } key |= shift_l ? FLAG_SHIFT_L : 0; key |= shift_r ? FLAG_SHIFT_R : 0; key |= ctrl_l ? FLAG_CTRL_L : 0; key |= ctrl_r ? FLAG_CTRL_R : 0; key |= alt_l ? FLAG_ALT_L : 0; key |= alt_r ? FLAG_ALT_R : 0; key |= pad ? FLAG_PAD : 0; if(tabAndShift) { key = (u8)key; switch(key){ case 'Q': key = 'W'; break; case 'A': key = 'S'; break; case 'Z': key = 'X'; break; case 'W': key = 'E'; break; case 'S': key = 'D'; break; case 'X': key = 'C'; break; } } in_process(p_tty, key); } } } }
//处理键盘扫描缓冲区中的扫描码 PUBLIC void keyboard_read(TTY* p_tty) { u8 scan_code; char output[2]; int make; // TRUE: make code; FALSE: break code u32 key = 0; //一个被按下的键的键值 u32* keyrow; //指向 keymap[] 的某一行 if(kb_in.count > 0){ code_with_E0 = 0; scan_code = get_byte_from_kbuf(); //解析扫描码 if(scan_code == 0xE1){ int i; u8 pausebrk_scode[] = { 0xE1, 0x1D, 0x45, 0xE1, 0x9D, 0xC5 }; int is_pausebreak = 1; for(i = 1; i < 6; i++){ if(get_byte_from_kbuf() != pausebrk_scode[i]){ is_pausebreak = 0; break; } } if(is_pausebreak){ key = PAUSEBREAK; } } else if(scan_code == 0xE0){ scan_code = get_byte_from_kbuf(); // printscreen 被按下 if(scan_code == 0x2A){ if(get_byte_from_kbuf() == 0xE0){ if(get_byte_from_kbuf() == 0x37){ key = PRINTSCREEN; make = 1; } } } // printscreen 被释放 if(scan_code == 0xB7){ if(get_byte_from_kbuf() == 0xE0){ if(get_byte_from_kbuf() == 0xAA){ key = PRINTSCREEN; make = 0; } } } // 不是printscreen, 此时scan_code为0xE0紧跟的那个值 if(key == 0){ code_with_E0 = 1; } } //可打印字符 if((key != PAUSEBREAK) && (key != PRINTSCREEN)){ //先判断是MAKE CODE还是BREAK CODE make = (scan_code & FLAG_BREAK ? FALSE : TRUE); //定位到 keymap 中的行 keyrow = &keymap[(scan_code & 0x7F) * MAP_COLS]; column = 0; int caps = shift_l || shift_r; if(caps_lock){ if((keyrow[0] >= 'a') && (keyrow[0] <= 'z')){ caps = !caps; } } if(caps){ column = 1; } if(code_with_E0){ column = 2; } key = keyrow[column]; switch(key){ case SHIFT_L: shift_l = make; break; case SHIFT_R: shift_r = make; break; case CTRL_L: ctrl_l = make; break; case CTRL_R: ctrl_r = make; break; case ALT_L: alt_l = make; break; case ALT_R: alt_r = make; break; case CAPS_LOCK: if(make){ caps_lock = !caps_lock; set_leds(); } break; case NUM_LOCK: if(make){ num_lock = !num_lock; set_leds(); } break; case SCROLL_LOCK: if(make){ scroll_lock = !scroll_lock; set_leds(); } break; default: break; } if(make){//忽略 Break Code int pad = 0; // 首先处理小键盘 if((key >= PAD_SLASH) && (key <= PAD_9)){ pad = 1; switch(key){ case PAD_SLASH: key = '/'; break; case PAD_STAR: key = '*'; break; case PAD_MINUS: key = '-'; break; case PAD_PLUS: key = '+'; break; case PAD_ENTER: key = ENTER; break; default: if(num_lock && (key >= PAD_0) && (key <= PAD_9)){ key = key -PAD_0 + '0'; } else if(num_lock && (key == PAD_DOT)){ key = '.'; } else{ switch(key){ case PAD_HOME: key = HOME; break; case PAD_END: key = END; break; case PAD_PAGEUP: key = PAGEUP; break; case PAD_PAGEDOWN: key = PAGEDOWN; break; case PAD_INS: key = INSERT; break; case PAD_UP: key = UP; break; case PAD_DOWN: key = DOWN; break; case PAD_LEFT: key = LEFT; break; case PAD_RIGHT: key = RIGHT; break; case PAD_DOT: key = DELETE; break; default: break; } } break; } } key |= shift_l ? FLAG_SHIFT_L : 0; key |= shift_r ? FLAG_SHIFT_R : 0; key |= ctrl_l ? FLAG_CTRL_L : 0; key |= ctrl_r ? FLAG_CTRL_R : 0; key |= alt_l ? FLAG_ALT_L : 0; key |= alt_r ? FLAG_ALT_R : 0; key |= pad ? FLAG_PAD : 0; in_process(p_tty, key); } } } }
/*======================================================================* keyboard_read *======================================================================*/ PUBLIC void keyboard_read(TTY* p_tty) { t_8 scan_code; t_bool make; /* TRUE : make */ /* FALSE: break */ t_32 key = 0;/* 用一个整型来表示一个键。 */ /* 比如,如果 Home 被按下,则 key 值将为定义在 keyboard.h 中的 'HOME'。*/ t_32* keyrow; /* 指向 keymap[] 的某一行 */ if(kb_in.count > 0){ code_with_E0 = FALSE; scan_code = get_byte_from_kb_buf(); /* 下面开始解析扫描码 */ if (scan_code == 0xE1) { int i; t_8 pausebreak_scan_code[] = {0xE1, 0x1D, 0x45, 0xE1, 0x9D, 0xC5}; t_bool is_pausebreak = TRUE; for(i=1;i<6;i++){ if (get_byte_from_kb_buf() != pausebreak_scan_code[i]) { is_pausebreak = FALSE; break; } } if (is_pausebreak) { key = PAUSEBREAK; } } else if (scan_code == 0xE0) { scan_code = get_byte_from_kb_buf(); /* PrintScreen 被按下 */ if (scan_code == 0x2A) { if (get_byte_from_kb_buf() == 0xE0) { if (get_byte_from_kb_buf() == 0x37) { key = PRINTSCREEN; make = TRUE; } } } /* PrintScreen 被释放 */ if (scan_code == 0xB7) { if (get_byte_from_kb_buf() == 0xE0) { if (get_byte_from_kb_buf() == 0xAA) { key = PRINTSCREEN; make = FALSE; } } } /* 不是 PrintScreen。此时 scan_code 为 0xE0 紧跟的那个值。 */ if (key == 0) { code_with_E0 = TRUE; } } if ((key != PAUSEBREAK) && (key != PRINTSCREEN)) { /* 首先判断Make Code 还是 Break Code */ make = (scan_code & FLAG_BREAK ? FALSE : TRUE); /* 先定位到 keymap 中的行 */ keyrow = &keymap[(scan_code & 0x7F) * MAP_COLS]; column = 0; if (shift_l || shift_r) { column = 1; } if (code_with_E0) { column = 2; } key = keyrow[column]; switch(key) { case SHIFT_L: shift_l = make; break; case SHIFT_R: shift_r = make; break; case CTRL_L: ctrl_l = make; break; case CTRL_R: ctrl_r = make; break; case ALT_L: alt_l = make; break; case ALT_R: alt_l = make; break; default: break; } } if(make){ /* 忽略 Break Code */ key |= shift_l ? FLAG_SHIFT_L : 0; key |= shift_r ? FLAG_SHIFT_R : 0; key |= ctrl_l ? FLAG_CTRL_L : 0; key |= ctrl_r ? FLAG_CTRL_R : 0; key |= alt_l ? FLAG_ALT_L : 0; key |= alt_r ? FLAG_ALT_R : 0; in_process(p_tty, key); } } }
/** * Yes, it is an ugly function. * * @param tty Which TTY is reading the keyboard input. *****************************************************************************/ PUBLIC void keyboard_read(TTY* tty) { u8 scan_code; /** * 1 : make * 0 : break */ int make; /** * We use a integer to record a key press. * For instance, if the key HOME is pressed, key will be evaluated to * `HOME' defined in keyboard.h. */ u32 key = 0; /** * This var points to a row in keymap[]. I don't use two-dimension * array because I don't like it. */ u32* keyrow; while (kb_in.count > 0) { code_with_E0 = 0; scan_code = get_byte_from_kb_buf(); /* parse the scan code below */ if (scan_code == 0xE1) { int i; u8 pausebreak_scan_code[] = {0xE1, 0x1D, 0x45, 0xE1, 0x9D, 0xC5}; int is_pausebreak = 1; for (i = 1; i < 6; i++) { if (get_byte_from_kb_buf() != pausebreak_scan_code[i]) { is_pausebreak = 0; break; } } if (is_pausebreak) { key = PAUSEBREAK; } } else if (scan_code == 0xE0) { code_with_E0 = 1; scan_code = get_byte_from_kb_buf(); /* PrintScreen is pressed */ if (scan_code == 0x2A) { code_with_E0 = 0; if ((scan_code = get_byte_from_kb_buf()) == 0xE0) { code_with_E0 = 1; if ((scan_code = get_byte_from_kb_buf()) == 0x37) { key = PRINTSCREEN; make = 1; } } } /* PrintScreen is released */ else if (scan_code == 0xB7) { code_with_E0 = 0; if ((scan_code = get_byte_from_kb_buf()) == 0xE0) { code_with_E0 = 1; if ((scan_code = get_byte_from_kb_buf()) == 0xAA) { key = PRINTSCREEN; make = 0; } } } } if ((key != PAUSEBREAK) && (key != PRINTSCREEN)) { int caps; /* make or break */ make = (scan_code & FLAG_BREAK ? 0 : 1); keyrow = &keymap[(scan_code & 0x7F) * MAP_COLS]; column = 0; caps = shift_l || shift_r; if (caps_lock && keyrow[0] >= 'a' && keyrow[0] <= 'z') caps = !caps; if (caps) column = 1; if (code_with_E0) column = 2; key = keyrow[column]; switch(key) { case SHIFT_L: shift_l = make; break; case SHIFT_R: shift_r = make; break; case CTRL_L: ctrl_l = make; break; case CTRL_R: ctrl_r = make; break; case ALT_L: alt_l = make; break; case ALT_R: alt_l = make; break; case CAPS_LOCK: if (make) { caps_lock = !caps_lock; set_leds(); } break; case NUM_LOCK: if (make) { num_lock = !num_lock; set_leds(); } break; case SCROLL_LOCK: if (make) { scroll_lock = !scroll_lock; set_leds(); } break; default: break; } } if(make){ /* Break Code is ignored */ int pad = 0; /* deal with the numpad first */ if ((key >= PAD_SLASH) && (key <= PAD_9)) { pad = 1; switch(key) { /* '/', '*', '-', '+', * and 'Enter' in num pad */ case PAD_SLASH: key = '/'; break; case PAD_STAR: key = '*'; break; case PAD_MINUS: key = '-'; break; case PAD_PLUS: key = '+'; break; case PAD_ENTER: key = ENTER; break; default: /* the value of these keys * depends on the Numlock */ if (num_lock) { /* '0' ~ '9' and '.' in num pad */ if (key >= PAD_0 && key <= PAD_9) key = key - PAD_0 + '0'; else if (key == PAD_DOT) key = '.'; } else{ switch(key) { case PAD_HOME: key = HOME; break; case PAD_END: key = END; break; case PAD_PAGEUP: key = PAGEUP; break; case PAD_PAGEDOWN: key = PAGEDOWN; break; case PAD_INS: key = INSERT; break; case PAD_UP: key = UP; break; case PAD_DOWN: key = DOWN; break; case PAD_LEFT: key = LEFT; break; case PAD_RIGHT: key = RIGHT; break; case PAD_DOT: key = DELETE; break; default: break; } } break; } } key |= shift_l ? FLAG_SHIFT_L : 0; key |= shift_r ? FLAG_SHIFT_R : 0; key |= ctrl_l ? FLAG_CTRL_L : 0; key |= ctrl_r ? FLAG_CTRL_R : 0; key |= alt_l ? FLAG_ALT_L : 0; key |= alt_r ? FLAG_ALT_R : 0; key |= pad ? FLAG_PAD : 0; in_process(tty, key); } } }
PUBLIC void keyboard_read(TTY* p_tty) { u8 scan_code; int make; u32 key = 0; u32* keyrow; if(kb_in.count > 0) { code_with_E0 = 0; scan_code = get_byte_from_kbuf(); if(scan_code == 0xE1) { int i; u8 pausebrk_scode[] = {0xE1,0x1D,0x45,0xE1,0x9D,0xC5}; for(i=1;i<6;++i) { if(get_byte_from_kbuf() != pausebrk_scode[i]) break; } if(i == 6) key = PAUSEBREAK; } else if (scan_code == 0xE0) { scan_code = get_byte_from_kbuf(); if(scan_code == 0x2A && get_byte_from_kbuf() == 0xE0 && get_byte_from_kbuf() == 0x37) { key = PRINTSCREEN; make = 1; } else if(scan_code == 0xB7 && get_byte_from_kbuf() == 0xE0 && get_byte_from_kbuf() == 0xAA) { key = PRINTSCREEN; make = 0; } if(key == 0) code_with_E0 = 1; } if(key != PAUSEBREAK && key != PRINTSCREEN) { make = scan_code & FLAG_BREAK ? FALSE : TRUE; keyrow = &keymap[(scan_code & 0x7F) * MAP_COLS]; column = 0; int caps = shift_l || shift_r; if(caps_lock) { if(keyrow[0] >= 'a' && keyrow[0] <= 'z') caps = !caps; } if(caps) column = 1; if(code_with_E0) column = 2; key = keyrow[column]; switch(key) { case SHIFT_L: shift_l = make; break; case SHIFT_R: shift_r = make; break; case CTRL_L: ctrl_l = make; break; case CTRL_R: ctrl_r = make; break; case ALT_L: alt_l = make; break; case ALT_R: alt_l = make; break; case CAPS_LOCK: if(make) { caps_lock = !caps_lock; set_leds(); } break; case NUM_LOCK: if(make) { num_lock = !num_lock; set_leds(); } break; case SCROLL_LOCK: if(make) { scroll_lock = !scroll_lock; set_leds(); } break; default: break; } if(make)///忽略Break Code { int pad = 0; /* 首先处理小键盘 */ if (key >= PAD_SLASH && key <= PAD_9) { pad = 1; switch(key) { case PAD_SLASH: key = '/'; break; case PAD_STAR: key = '*'; break; case PAD_MINUS: key = '-'; break; case PAD_PLUS: key = '+'; break; case PAD_ENTER: key = ENTER; break; default: if (num_lock && key >= PAD_0 && key <= PAD_9) key = key - PAD_0 + '0'; else if (num_lock && key == PAD_DOT) key = '.'; else { switch(key) { case PAD_HOME: key = HOME; break; case PAD_END: key = END; break; case PAD_PAGEUP: key = PAGEUP; break; case PAD_PAGEDOWN: key = PAGEDOWN; break; case PAD_INS: key = INSERT; break; case PAD_UP: key = UP; break; case PAD_DOWN: key = DOWN; break; case PAD_LEFT: key = LEFT; break; case PAD_RIGHT: key = RIGHT; break; case PAD_DOT: key = DELETE; break; default: break; } } break; } } key |= shift_l ? FLAG_SHIFT_L : 0; key |= shift_r ? FLAG_SHIFT_R : 0; key |= ctrl_l ? FLAG_CTRL_L : 0; key |= ctrl_r ? FLAG_CTRL_R : 0; key |= alt_l ? FLAG_ALT_L : 0; key |= alt_r ? FLAG_ALT_R : 0; key |= pad ? FLAG_PAD : 0; in_process(p_tty,key); } } } }
/*======================================================================* keyboard_read *======================================================================*/ PUBLIC void keyboard_read(TTY* p_tty) { t_8 scan_code; t_bool make; /* TRUE : make */ /* FALSE: break */ t_32 key = 0;/* 用一个整型来表示一个键。 */ /* 比如,如果 Home 被按下,则 key 值将为定义在 keyboard.h 中的 'HOME'。*/ t_32* keyrow; /* 指向 keymap[] 的某一行 */ if(kb_in.count > 0){ code_with_E0 = FALSE; scan_code = get_byte_from_kb_buf(); /* 下面开始解析扫描码 */ if (scan_code == 0xE1) { int i; t_8 pausebreak_scan_code[] = {0xE1, 0x1D, 0x45, 0xE1, 0x9D, 0xC5}; t_bool is_pausebreak = TRUE; for(i=1;i<6;i++){ if (get_byte_from_kb_buf() != pausebreak_scan_code[i]) { is_pausebreak = FALSE; break; } } if (is_pausebreak) { key = PAUSEBREAK; } } else if (scan_code == 0xE0) { code_with_E0 = TRUE; scan_code = get_byte_from_kb_buf(); /* PrintScreen 被按下 */ if (scan_code == 0x2A) { code_with_E0 = FALSE; if ((scan_code = get_byte_from_kb_buf()) == 0xE0) { code_with_E0 = TRUE; if ((scan_code = get_byte_from_kb_buf()) == 0x37) { key = PRINTSCREEN; make = TRUE; } } } /* PrintScreen 被释放 */ else if (scan_code == 0xB7) { code_with_E0 = FALSE; if ((scan_code = get_byte_from_kb_buf()) == 0xE0) { code_with_E0 = TRUE; if ((scan_code = get_byte_from_kb_buf()) == 0xAA) { key = PRINTSCREEN; make = FALSE; } } } } /* 如果不是 PrintScreen。则此时 scan_code 为 0xE0 紧跟的那个值。 */ if ((key != PAUSEBREAK) && (key != PRINTSCREEN)) { /* 首先判断Make Code 还是 Break Code */ make = (scan_code & FLAG_BREAK ? FALSE : TRUE); /* 先定位到 keymap 中的行 */ keyrow = &keymap[(scan_code & 0x7F) * MAP_COLS]; column = 0; t_bool caps = shift_l || shift_r; if (caps_lock) { if ((keyrow[0] >= 'a') && (keyrow[0] <= 'z')){ caps = !caps; } } if (caps) { column = 1; } if (code_with_E0) { column = 2; } key = keyrow[column]; switch(key) { case SHIFT_L: shift_l = make; break; case SHIFT_R: shift_r = make; break; case CTRL_L: ctrl_l = make; break; case CTRL_R: ctrl_r = make; break; case ALT_L: alt_l = make; break; case ALT_R: alt_l = make; break; case CAPS_LOCK: if (make) { caps_lock = !caps_lock; set_leds(); } break; case NUM_LOCK: if (make) { num_lock = !num_lock; set_leds(); } break; case SCROLL_LOCK: if (make) { scroll_lock = !scroll_lock; set_leds(); } break; default: break; } } if(make){ /* 忽略 Break Code */ t_bool pad = FALSE; /* 首先处理小键盘 */ if ((key >= PAD_SLASH) && (key <= PAD_9)) { pad = TRUE; switch(key) { /* '/', '*', '-', '+', and 'Enter' in num pad */ case PAD_SLASH: key = '/'; break; case PAD_STAR: key = '*'; break; case PAD_MINUS: key = '-'; break; case PAD_PLUS: key = '+'; break; case PAD_ENTER: key = ENTER; break; default: /* keys whose value depends on the NumLock */ if (num_lock) { /* '0' ~ '9' and '.' in num pad */ if ((key >= PAD_0) && (key <= PAD_9)) { key = key - PAD_0 + '0'; } else if (key == PAD_DOT) { key = '.'; } } else{ switch(key) { case PAD_HOME: key = HOME; break; case PAD_END: key = END; break; case PAD_PAGEUP: key = PAGEUP; break; case PAD_PAGEDOWN: key = PAGEDOWN; break; case PAD_INS: key = INSERT; break; case PAD_UP: key = UP; break; case PAD_DOWN: key = DOWN; break; case PAD_LEFT: key = LEFT; break; case PAD_RIGHT: key = RIGHT; break; case PAD_DOT: key = DELETE; break; default: break; } } break; } } key |= shift_l ? FLAG_SHIFT_L : 0; key |= shift_r ? FLAG_SHIFT_R : 0; key |= ctrl_l ? FLAG_CTRL_L : 0; key |= ctrl_r ? FLAG_CTRL_R : 0; key |= alt_l ? FLAG_ALT_L : 0; key |= alt_r ? FLAG_ALT_R : 0; key |= pad ? FLAG_PAD : 0; in_process(p_tty, key); } } }
// Run a single model to completion on a single processor core int exec_cpu(solver_props *props, const char *outputs_dirname, double *progress, unsigned int modelid, int resuming){ unsigned int i; CDATAFORMAT min_time; unsigned int last_iteration[NUM_ITERATORS] = {0}; unsigned int dirty_states[NUM_ITERATORS] = {0}; unsigned int ready_outputs[NUM_ITERATORS] = {0}; int inputs_available = 1; // Initialize all iterators to running for(i=0;i<NUM_ITERATORS;i++){ props[i].running[modelid] = 1; } // Run simulation to completion while(model_running(props, modelid) && inputs_available){ // Initialize a temporary output buffer init_output_buffer((output_buffer*)(props->ob), modelid); // Run a set of iterations until the output buffer is full or the simulation is complete while (1) { // Find the nearest next_time and catch up min_time = find_min_time(props, modelid); // Advance any sampled inputs inputs_available = 1; #if NUM_SAMPLED_INPUTS > 0 for (i=NUM_CONSTANT_INPUTS; i<NUM_CONSTANT_INPUTS + NUM_SAMPLED_INPUTS; i++) { sampled_input_t *input = &sampled_inputs[STRUCT_IDX * NUM_SAMPLED_INPUTS + SAMPLED_INPUT_ID(i)]; if (!advance_sampled_input(input, min_time, props->modelid_offset, modelid)) { // If unable to advance, attempt to buffer more input data. inputs_available &= read_sampled_input(input, min_time, outputs_dirname, i, props->modelid_offset, modelid); } } #endif // Buffer any available outputs for(i=0;i<NUM_ITERATORS;i++){ if (ready_outputs[i]) { #if NUM_OUTPUTS > 0 buffer_outputs(&props[i], modelid); #endif ready_outputs[i] = 0; } if (dirty_states[i] && (resuming && props[i].next_time[modelid] == min_time)) { solver_writeback(&props[i], modelid); dirty_states[i] = 0; } } // Update and postprocess phase: x[t+dt] = f(x[t+dt]) // Update occurs before the first iteration and after every subsequent iteration. for(i=0;i<NUM_ITERATORS;i++){ if(props[i].running[modelid] && (!resuming || props[i].next_time[modelid] == min_time)){ dirty_states[i] = 0 == update(&props[i], modelid); } if(props[i].running[modelid] && (resuming && props[i].next_time[modelid] == min_time)){ dirty_states[i] |= 0 == post_process(&props[i], modelid); } } // Advance the iterator. for(i=0;i<NUM_ITERATORS;i++){ if(props[i].running[modelid] && (resuming && props[i].next_time[modelid] == min_time)){ // Now time == next_time last_iteration[i] = solver_advance(&props[i], modelid); } } for(i=0;i<NUM_ITERATORS;i++){ if (dirty_states[i] && props[i].next_time[modelid] == min_time) { solver_writeback(&props[i], modelid); dirty_states[i] = 0; } } // Capture outputs for final iteration for(i=0;i<NUM_ITERATORS;i++){ if (last_iteration[i]) { last_iteration[i] = 0; pre_process(&props[i], modelid); model_flows(props[i].time[modelid], props[i].model_states, props[i].next_states, &props[i], 1, modelid); in_process(&props[i], modelid); // Updates and postprocess should not write to the output data structure // the output data structure holds outputs from the previous iteration and updates/postprocess set values // that will be written to output data by the solver flow of the next iteration /* update(&props[i], modelid); */ /* post_process(&props[i], modelid); */ #if NUM_OUTPUTS > 0 buffer_outputs(&props[i], modelid); #endif } } // Cannot continue if a sampled input with halt condition has no more data if(!inputs_available) { break; } // Cannot continue if all the simulation is complete if (!model_running(props, modelid)) { break; } // Cannot continue if the output buffer is full if (((output_buffer *)(props->ob))->full[modelid]) { break; } resuming = 1; // Preprocess phase: x[t] = f(x[t]) for(i=0;i<NUM_ITERATORS;i++){ if(props[i].running[modelid] && props[i].time[modelid] == min_time){ dirty_states[i] = 0 == pre_process(&props[i], modelid); } } for(i=0;i<NUM_ITERATORS;i++){ if (dirty_states[i] && props[i].time[modelid] == min_time) { solver_writeback(&props[i], modelid); dirty_states[i] = 0; } } // Main solver evaluation phase, including inprocess. // x[t+dt] = f(x[t]) for(i=0;i<NUM_ITERATORS;i++){ if(props[i].running[modelid] && props[i].time[modelid] == min_time){ if(0 != solver_eval(&props[i], modelid)) { return ERRCOMP; } // Now next_time == time + dt dirty_states[i] = 1; ready_outputs[i] = 1; // Run any in-process algebraic evaluations in_process(&props[i], modelid); } } } // Log outputs from buffer to external api interface // All iterators share references to a single output buffer and outputs dirname. if(0 != log_outputs(props->ob, outputs_dirname, props->modelid_offset, modelid)){ return ERRMEM; } progress[modelid] = (props->time[modelid] - props->starttime) / (props->stoptime - props->starttime); } return SUCCESS; }
// Run a single model to completion on a single processor core int exec_cpu(solver_props *props, const char *outputs_dirname, double *progress, unsigned int modelid){ unsigned int i; CDATAFORMAT min_time; unsigned int before_first_iteration = 1; unsigned int last_iteration[NUM_ITERATORS] = {0}; unsigned int dirty_states[NUM_ITERATORS] = {0}; unsigned int ready_outputs[NUM_ITERATORS] = {0}; // Initialize all iterators to running for(i=0;i<NUM_ITERATORS;i++){ props[i].running[modelid] = 1; } init_states(props, modelid); for(i=0;i<NUM_ITERATORS;i++){ solver_writeback(&props[i], modelid); dirty_states[i] = 0; } // TODO Initialize non-constant state initial values // Run simulation to completion while(model_running(props, modelid)){ // Initialize a temporary output buffer init_output_buffer((output_buffer*)(props->ob), modelid); // Run a set of iterations until the output buffer is full or the simulation is complete while (1) { // Find the nearest next_time and catch up min_time = find_min_time(props, modelid); // Buffer any available outputs for(i=0;i<NUM_ITERATORS;i++){ if (ready_outputs[i]) { #if NUM_OUTPUTS > 0 buffer_outputs(&props[i], modelid); #endif ready_outputs[i] = 0; } if (dirty_states[i] && (!before_first_iteration && props[i].next_time[modelid] == min_time)) { solver_writeback(&props[i], modelid); dirty_states[i] = 0; } } // Update and postprocess phase: x[t+dt] = f(x[t+dt]) // Update occurs before the first iteration and after every subsequent iteration. for(i=0;i<NUM_ITERATORS;i++){ if(props[i].running[modelid] && (before_first_iteration || props[i].next_time[modelid] == min_time)){ dirty_states[i] = 0 == update(&props[i], modelid); } if(props[i].running[modelid] && (!before_first_iteration && props[i].next_time[modelid] == min_time)){ dirty_states[i] |= 0 == post_process(&props[i], modelid); } } // Advance the iterator. for(i=0;i<NUM_ITERATORS;i++){ if(props[i].running[modelid] && (!before_first_iteration && props[i].next_time[modelid] == min_time)){ // Now time == next_time last_iteration[i] = solver_advance(&props[i], modelid); } } for(i=0;i<NUM_ITERATORS;i++){ if (dirty_states[i] && props[i].next_time[modelid] == min_time) { solver_writeback(&props[i], modelid); dirty_states[i] = 0; } } // Capture outputs for final iteration for(i=0;i<NUM_ITERATORS;i++){ if (last_iteration[i]) { last_iteration[i] = 0; pre_process(&props[i], modelid); model_flows(props[i].time[modelid], props[i].model_states, props[i].next_states, &props[i], 1, modelid); in_process(&props[i], modelid); // Updates and postprocess should not write to the output data structure (right?) /* update(&props[i], modelid); */ /* post_process(&props[i], modelid); */ #if NUM_OUTPUTS > 0 buffer_outputs(&props[i], modelid); #endif } } // Cannot continue if all the simulation is complete if (!model_running(props, modelid)) { break; } // Cannot continue if the output buffer is full if (((output_buffer *)(props->ob))->full[modelid]) { break; } before_first_iteration = 0; // Preprocess phase: x[t] = f(x[t]) for(i=0;i<NUM_ITERATORS;i++){ if(props[i].running[modelid] && props[i].time[modelid] == min_time){ dirty_states[i] = 0 == pre_process(&props[i], modelid); } } for(i=0;i<NUM_ITERATORS;i++){ if (dirty_states[i] && props[i].time[modelid] == min_time) { solver_writeback(&props[i], modelid); dirty_states[i] = 0; } } // Main solver evaluation phase, including inprocess. // x[t+dt] = f(x[t]) for(i=0;i<NUM_ITERATORS;i++){ if(props[i].running[modelid] && props[i].time[modelid] == min_time){ if(0 != solver_eval(&props[i], modelid)) { return ERRCOMP; } // Now next_time == time + dt dirty_states[i] = 1; ready_outputs[i] = 1; // Run any in-process algebraic evaluations in_process(&props[i], modelid); } } } // Log outputs from buffer to external api interface // All iterators share references to a single output buffer and outputs dirname. if(0 != log_outputs(props->ob, outputs_dirname, props->modelid_offset, modelid)){ return ERRMEM; } progress[modelid] = (props->time[modelid] - props->starttime) / (props->stoptime - props->starttime); } return SUCCESS; }
PUBLIC void keyboard_read(TTY * p_tty) { u8 c = 0; u32 key = 0; u8 flag_make = 0; u32 * key_row = 0; if(kb_in.count > 0) { c = get_byte_from_kbuf(); if(c == 0xE1) { int i; u8 pause[] = {0x1D,0x45,0xE1,0x9D,0xC5}; key = PAUSE; for(i = 0;i < 5;i++) { c = get_byte_from_kbuf(); if(pause[i] != c) { key = 0; c = 0; break; } } } else if(c == 0xE0) { c = get_byte_from_kbuf(); if(c == 0x2A) { if(0xE0 == get_byte_from_kbuf()) if(0x37 == get_byte_from_kbuf()) key = PRTSCR; } else if(c == 0xB7) { if(0xE0 == get_byte_from_kbuf()) if(0xAA == get_byte_from_kbuf()) key = PRTSCR; } if(key == 0) flag_e0 = 1; } if((key != PAUSE) && (key != PRTSCR)) { int column = 0; int caps = 0; flag_make = c & 0x80?0:1; key_row = &key_map[(c & 0x7F) * KEY_MAP_COLS]; caps = l_shift || r_shift; if(caps_lock) { if(*key_row >= 'a' && *key_row <= 'z') { caps = !caps; } } if(caps) { column = 1; } if(flag_e0) { column = 2; flag_e0 = 0; } key = *(key_row + column); switch(key) { case LSHIFT: l_shift = flag_make; break; case RSHIFT: r_shift = flag_make; break; case LALT: l_alt = flag_make; break; case RALT: r_alt = flag_make; break; case LCTRL: l_ctrl = flag_make; break; case RCTRL: r_ctrl = flag_make; break; default: break; } } if(flag_make) { switch(key) { case CAPS: caps_lock = !caps_lock; kb_setleds(); break; case NUMLOCK: num_lock = !num_lock; kb_setleds(); break; case SCROLL: scroll_lock = !scroll_lock; kb_setleds(); break; } key = key | (l_shift ? FLAG_LSHIFT :0); key = key | (r_shift ? FLAG_RSHIFT :0); key = key | (l_alt ? FLAG_LALT :0); key = key | (r_alt ? FLAG_RALT :0); key = key | (l_ctrl ? FLAG_LCTRL :0); key = key | (r_ctrl ? FLAG_RCTRL :0); in_process(p_tty,key); } } }