void init_telnet(void) { env_init(); SB_CLEAR(); ClearArray(options); connected = ISend = localflow = donebinarytoggle = 0; #ifdef AUTHENTICATION #ifdef ENCRYPTION auth_encrypt_connect(connected); #endif #endif restartany = -1; SYNCHing = 0; /* Don't change NetTrace */ escape = CONTROL(']'); rlogin = _POSIX_VDISABLE; #ifdef KLUDGELINEMODE echoc = CONTROL('E'); #endif flushline = 1; telrcv_state = TS_DATA; }
CARCONTROLMAP_LOCAL::CONTROL CARCONTROLMAP_LOCAL::GetControl(const std::string & inputname, size_t controlid) { size_t input = GetInputFromString(inputname); if (input == CARINPUT::INVALID) return CONTROL(); std::vector<CONTROL> & input_controls = controls[input]; if (controlid < input_controls.size()) return input_controls[controlid]; else return CONTROL(); }
static int aha1542_test_port(struct Scsi_Host *sh) { u8 inquiry_result[4]; int i; /* Quick and dirty test for presence of the card. */ if (inb(STATUS(sh->io_port)) == 0xff) return 0; /* Reset the adapter. I ought to make a hard reset, but it's not really necessary */ /* In case some other card was probing here, reset interrupts */ aha1542_intr_reset(sh->io_port); /* reset interrupts, so they don't block */ outb(SRST | IRST /*|SCRST */ , CONTROL(sh->io_port)); mdelay(20); /* Wait a little bit for things to settle down. */ /* Expect INIT and IDLE, any of the others are bad */ if (!wait_mask(STATUS(sh->io_port), STATMASK, INIT | IDLE, STST | DIAGF | INVDCMD | DF | CDF, 0)) return 0; /* Shouldn't have generated any interrupts during reset */ if (inb(INTRFLAGS(sh->io_port)) & INTRMASK) return 0; /* Perform a host adapter inquiry instead so we do not need to set up the mailboxes ahead of time */ aha1542_outb(sh->io_port, CMD_INQUIRY); for (i = 0; i < 4; i++) { if (!wait_mask(STATUS(sh->io_port), DF, DF, 0, 0)) return 0; inquiry_result[i] = inb(DATA(sh->io_port)); } /* Reading port should reset DF */ if (inb(STATUS(sh->io_port)) & DF) return 0; /* When HACC, command is completed, and we're though testing */ if (!wait_mask(INTRFLAGS(sh->io_port), HACC, HACC, 0, 0)) return 0; /* Clear interrupts */ outb(IRST, CONTROL(sh->io_port)); return 1; }
SML_PRIMITIVE void sml_control_suspend() { struct sml_control *control = CONTROL(); control->frame_stack_top = CALLER_FRAME_END_ADDRESS(); control_suspend(control); }
static gboolean do_console_raw_local_read(GObject *stream, gpointer opaque) { GUnixInputStream *localStdin = G_UNIX_INPUT_STREAM(stream); GVirSandboxConsoleRaw *console = GVIR_SANDBOX_CONSOLE_RAW(opaque); GVirSandboxConsoleRawPrivate *priv = console->priv; GError *err = NULL; gssize ret = g_pollable_input_stream_read_nonblocking (G_POLLABLE_INPUT_STREAM(localStdin), priv->localToConsole + priv->localToConsoleOffset, priv->localToConsoleLength - priv->localToConsoleOffset, NULL, &err); if (ret < 0) { g_debug("Error from local read %s", err ? err->message : ""); do_console_raw_close(console, err); g_error_free(err); goto cleanup; } if (ret == 0) priv->localEOF = TRUE; else if (priv->localToConsole[priv->localToConsoleOffset] == CONTROL(gvir_sandbox_console_get_escape(GVIR_SANDBOX_CONSOLE(console)))) { do_console_raw_close(console, err); goto cleanup; } priv->localToConsoleOffset += ret; priv->localStdinSource = NULL; do_console_raw_update_events(console); cleanup: return FALSE; }
static void control_enum_ptr(struct sml_control *control, void (*trace)(void **), enum sml_gc_mode mode) { printf("enum 1 %p %p\n", control, CONTROL()); stack_enum_ptr(control, trace); printf("enum 2 %p\n", CONTROL()); sml_exn_enum_ptr(control->exn, trace); if (control->tmp_root[0]) { printf("enum 2 tmp_root 0 %p\n", &control->tmp_root[0]); trace(&control->tmp_root[0]); } if (control->tmp_root[1]) trace(&control->tmp_root[1]); }
combuf_t combuf_create(const uint8_t control, const combuf_size_t payload_size) { const cb_store_t cb_size = COMBUF_HEAD_SIZE + payload_size + COMBUF_END_SIZE; cb_store_t _busy = cb_size; result_t res = ENOERR; cb_offset_t _front; /* критическая секция нужна, потому что combuf_create может быть * вызвана как из прерывания, так и из задачи. */ __critical_enter(); _busy += busy; if (_busy <= COMBUF_STORE_SIZE) { _front = front; front = SUM(front, cb_size); busy = _busy; } else res = ENOMEM; __critical_exit(); if (ENOERR != res) return res; /* Можно не вносить в критическую секцию, поскольку доступ к этим * полям осуществляется пользователем по описателю буфера, который * ему ещё не возвращён. */ BEGIN(_front) = BEGIN_MARKER; SIZE(_front) = cb_size; CONTROL(_front) = control | CREATE_MASK; return (combuf_t) _front; }
/* функция поиска буфера по полю контроля буфера. * Функция вызывается только из задач данного модуля. */ static combuf_t combuf_search(const uint8_t mask, const uint8_t value) { cb_store_t cb_size; cb_offset_t _front; uint8_t cb_ctrl; combuf_t cb_iter = back; while (cb_iter != front) { /* не защищаем CONTROL( cb_iter ), так как предполагаем, * что вычитывание атомарно */ if (value == (CONTROL(cb_iter) & mask)) return cb_iter; /* поле SIZE( cb_iter ) можно не вычитывать в крит. секции, так как * это поле не изменяется никем. Изменяется только в combuf_create, но * это не страшно: * 1. если combuf_create выз. из задачи, то всё хорошо. * front и поле size будут согласованы. * 2. если из прерывания, то тоже согласованы. */ cb_iter = SUM(cb_iter, SIZE(cb_iter)); } return ENOTFOUND; }
void sml_mutex_lock(pthread_mutex_t *m) { struct sml_control *control = CONTROL(); control_suspend(control); MUTEX_LOCK(m); control_resume(control); }
static char virshGetEscapeChar(const char *s) { if (*s == '^') return CONTROL(c_toupper(s[1])); return *s; }
/* * Handle a char of a search command. */ static int mca_search_char(int c) { int flag = 0; /* * Certain characters as the first char of * the pattern have special meaning: * ! Toggle the NO_MATCH flag * * Toggle the PAST_EOF flag * @ Toggle the FIRST_FILE flag */ if (len_cmdbuf() > 0) return (NO_MCA); switch (c) { case CONTROL('E'): /* ignore END of file */ case '*': if (mca != A_FILTER) flag = SRCH_PAST_EOF; break; case CONTROL('F'): /* FIRST file */ case '@': if (mca != A_FILTER) flag = SRCH_FIRST_FILE; break; case CONTROL('K'): /* KEEP position */ if (mca != A_FILTER) flag = SRCH_NO_MOVE; break; case CONTROL('R'): /* Don't use REGULAR EXPRESSIONS */ flag = SRCH_NO_REGEX; break; case CONTROL('N'): /* NOT match */ case '!': flag = SRCH_NO_MATCH; break; } if (flag != 0) { search_type ^= flag; mca_search(); return (MCA_MORE); } return (NO_MCA); }
/* * Checks for port existence, all ports support SPP MODE */ static int __devinit parport_SPP_supported(struct parport *pb) { unsigned char r, w; /* * first clear an eventually pending EPP timeout * I ([email protected]) have an SMSC chipset * that does not even respond to SPP cycles if an EPP * timeout is pending */ clear_epp_timeout(pb); /* Do a simple read-write test to make sure the port exists. */ w = 0xc; parport_writeb (w, CONTROL (pb)); /* Is there a control register that we can read from? Some * ports don't allow reads, so read_control just returns a * software copy. Some ports _do_ allow reads, so bypass the * software copy here. In addition, some bits aren't * writable. */ r = parport_readb (CONTROL (pb)); if ((r & 0xf) == w) { w = 0xe; parport_writeb (w, CONTROL (pb)); r = parport_readb (CONTROL (pb)); parport_writeb (0xc, CONTROL (pb)); if ((r & 0xf) == w) return PARPORT_MODE_PCSPP; } /* Try the data register. The data lines aren't tri-stated at * this stage, so we expect back what we wrote. */ w = 0xaa; parport_gsc_write_data (pb, w); r = parport_gsc_read_data (pb); if (r == w) { w = 0x55; parport_gsc_write_data (pb, w); r = parport_gsc_read_data (pb); if (r == w) return PARPORT_MODE_PCSPP; } return 0; }
SML_PRIMITIVE void sml_push_fp() { struct sml_control *control = CONTROL(); if (control->frame_stack_top_override != NULL) FATAL((0, "sml_push_fp overfull")); control->frame_stack_top_override = CALLER_FRAME_END_ADDRESS(); }
void TerminalDefaultChars (void) { memmove (new_tc.c_cc, old_tc.c_cc, sizeof (old_tc.c_cc)); # ifndef VDISCARD termFlushChar = CONTROL ('O'); # endif # ifndef VWERASE termWerasChar = CONTROL ('W'); # endif # ifndef VREPRINT termRprntChar = CONTROL ('R'); # endif # ifndef VLNEXT termLiteralNextChar = CONTROL ('V'); # endif # ifndef VSTART termStartChar = CONTROL ('Q'); # endif # ifndef VSTOP termStopChar = CONTROL ('S'); # endif # ifndef VSTATUS termAytChar = CONTROL ('T'); # endif }
void TerminalSaveState (void) { tcgetattr (0, &old_tc); new_tc = old_tc; #ifndef VDISCARD termFlushChar = CONTROL ('O'); #endif #ifndef VWERASE termWerasChar = CONTROL ('W'); #endif #ifndef VREPRINT termRprntChar = CONTROL ('R'); #endif #ifndef VLNEXT termLiteralNextChar = CONTROL ('V'); #endif #ifndef VSTART termStartChar = CONTROL ('Q'); #endif #ifndef VSTOP termStopChar = CONTROL ('S'); #endif #ifndef VSTATUS termAytChar = CONTROL ('T'); #endif }
void TerminalDefaultChars(void) { #ifndef USE_TERMIO ntc = otc; nltc = oltc; nttyb.sg_kill = ottyb.sg_kill; nttyb.sg_erase = ottyb.sg_erase; #else /* USE_TERMIO */ memcpy(new_tc.c_cc, old_tc.c_cc, sizeof(old_tc.c_cc)); #ifndef VDISCARD termFlushChar = CONTROL('O'); #endif #ifndef VWERASE termWerasChar = CONTROL('W'); #endif #ifndef VREPRINT termRprntChar = CONTROL('R'); #endif #ifndef VLNEXT termLiteralNextChar = CONTROL('V'); #endif #ifndef VSTART termStartChar = CONTROL('Q'); #endif #ifndef VSTOP termStopChar = CONTROL('S'); #endif #ifndef VSTATUS termAytChar = CONTROL('T'); #endif #endif /* USE_TERMIO */ }
void TIM4_IRQHandler(void) { if(TIM_GetITStatus(TIM4,TIM_IT_Update)==SET) //溢出中断 { inv_mpu_read(); CONTROL();//电机控制 } TIM_ClearITPendingBit(TIM4,TIM_IT_Update); //清除中断标志位 }
SML_PRIMITIVE void sml_pop_fp() { struct sml_control *control = CONTROL(); ASSERT(control->frame_stack_top_override != NULL); control->frame_stack_top_override = NULL; control->tmp_root[0] = NULL; control->tmp_root[1] = NULL; }
enum sml_sync_phase sml_current_phase() { struct sml_control *control = CONTROL(); if (control->phase == SYNC2 || control->phase == MARK) if (sml_check_gc_flag != control->phase) control->phase = sml_check_gc_flag; return control->phase; }
int main(void) { struct usb_dev_handle *myhandle; myhandle = find_rl78(); if (myhandle != NULL) { fd_set s_rd; struct timeval delay; char ch, ch2; configure_rl78(myhandle); configure_screen(); while (ch != EOF && ch != CONTROL('d')) { delay.tv_sec = 0; delay.tv_usec = 0; FD_ZERO(&s_rd); FD_SET(fileno(stdin), &s_rd); select(fileno(stdin)+1, &s_rd, NULL, NULL, &delay); if (FD_ISSET (fileno(stdin), &s_rd)) { ch=getch(); if (ch != EOF && ch != CONTROL('d')) rl78_write(myhandle, &ch, 1, 100); } int ret = rl78_read(myhandle, &ch2, 1, 50); if (ret >= 0) { putchar (ch2); } } usb_close(myhandle); endwin(); } return 0; }
void init_telnet(void) { env_init(); SB_CLEAR(); memset(options, 0, sizeof options); connected = ISend = localflow = donebinarytoggle = 0; restartany = -1; SYNCHing = 0; escape = CONTROL(']'); rlogin = _POSIX_VDISABLE; #ifdef KLUDGELINEMODE echoc = CONTROL('E'); #endif flushline = 1; telrcv_state = TS_DATA; }
/* * Read one key and modify the provided string accordingly. * Returns 0 when more input is expected and 1 on completion. */ int readmore(char **str) { int c, ret = 0; int i; char *ln = *str; timeout(-1); if (ln != NULL) i = strlen(ln); else i = 0; DPRINTF_D(i); curs_set(TRUE); c = getch(); switch (c) { case KEY_ENTER: case '\r': ret = 1; break; case KEY_BACKSPACE: case CONTROL('H'): i--; if (i > 0) { ln = xrealloc(ln, (i + 1) * sizeof(*ln)); ln[i] = '\0'; } else { free(ln); ln = NULL; } break; default: i++; ln = xrealloc(ln, (i + 1) * sizeof(*ln)); ln[i - 1] = c; ln[i] = '\0'; } curs_set(FALSE); *str = ln; timeout(1000); return ret; }
result_t combuf_send(const combuf_t combuf) { cb_offset_t _out_offset; ASSERT1(CHECK_COMBUF(combuf), "invalid combuf = %d", combuf); __critical_enter(); CONTROL(combuf) |= READY_MASK; _out_offset = out_offset; if (-2 == out_offset) out_offset = 0; __critical_exit(); if (-2 == _out_offset) if( ISZIGLOAD ) __post_task( &task_combuf_send ); return ENOERR; }
void tmain(void) { size_t start, stop, t; char c; start = stop = 0; if (field(in.v, 1, &start, &stop)) tdraw(in.v, in.pmemb, start, stop); else twrite(in.v, in.pmemb); for (;;) { if (read(tty.in, &c, 1) < 0) perror("read"); switch (c) { case '\n': sel.nmemb = stop - start + 1; sel.v = in.v + start; /* FALLTHROUGH */ case CONTROL('C'): case CONTROL('D'): return; case CONTROL('A'): t = 0; /* FALLTHROUGH */ if (0) { case CONTROL('N'): t = stop + rune(in.v, stop, 1); } if (!field(in.v, 1, &t, &stop)) continue; start = t; break; case CONTROL('E'): t = in.pmemb - 1; /* FALLTHROUGH */ if (0) { case CONTROL('P'): t = start + rune(in.v, start, -1); } if (!field(in.v, -1, &t, &start)) continue; stop = t; break; default: continue; } if (in.nlines) tprintf(T_CURSOR_UP, in.nlines); tprintf(T_COLUMN_ADDRESS, 1); tdraw(in.v, in.pmemb, start, stop); } }
SML_PRIMITIVE void sml_control_finish() { struct sml_control *control = CONTROL(); void **frame_end = CALLER_FRAME_END_ADDRESS(); short *layout; if (control->frame_stack_bottom == frame_end) { DBG(("CONTROL_FINISH %p", control)); control_suspend(control); control_finalize(control); } else { layout = lookup_stack_layout(FRAME_CODE_ADDRESS(frame_end)); ASSERT(layout != NULL); ASSERT(NUM_ROOTS(layout) > 0); control->frame_stack_top = frame_end[ROOTS(layout)[0]]; control_suspend(control); } }
SML_PRIMITIVE void sml_control_start() { struct sml_control *control = CONTROL(); void **frame_end = CALLER_FRAME_END_ADDRESS(); short *layout; if (control != NULL) { control_resume(control); layout = lookup_stack_layout(FRAME_CODE_ADDRESS(frame_end)); ASSERT(layout != NULL); ASSERT(NUM_ROOTS(layout) > 0); frame_end[ROOTS(layout)[0]] = control->frame_stack_top; control->frame_stack_top = frame_end; return; } control = xmalloc(sizeof(struct sml_control)); control->state = RUN; #ifdef MULTITHREAD if (pthread_mutex_init(&control->state_lock, NULL) != 0) sml_sysfatal("pthread_mutex_init failed"); if (pthread_cond_init(&control->state_cond, NULL) != 0) sml_sysfatal("pthread_cond_init failed"); #ifdef CONCURRENT control->phase = ASYNC; #endif /* CONCURRENT */ #endif /* MULTITHREAD */ control->frame_stack_top_override = NULL; control->frame_stack_top = frame_end; control->frame_stack_bottom = frame_end; control->tmp_root[0] = NULL; control->tmp_root[1] = NULL; control->heap = sml_heap_thread_init(); control->exn = sml_exn_init(); SET_CONTROL(control); attach_control(control); DBG(("START THREAD %p", control)); }
void std_in(int fd, short event, void *arg) { struct ae_msg am; int i, end = 0; bzero(&am, sizeof(am)); am.len = read(fd, am.u.buf, sizeof(am.u.buf)); if (am.len < 0) exit(1); for (i = 0; i < am.len; i++) { switch(am.u.buf[i]) { case CONTROL('A'): /* A command was propably triggert */ ctrl_a++; break; case 'd': if (ctrl_a) { am.type = MSG_DTACH; printf("\r\n[detached]\r\n"); end++; break; } /* FALLTRHOUGH */ default: if (ctrl_a > 0 && ctrl_a < 3) break; else ctrl_a = 0; am.type = MSG_PUSH; break; } if (end) exit(0); } write(m_socket, &am, sizeof(am)); }
void TerminalSaveState (void) { #ifndef USE_TERMIO ioctl (0, TIOCGETP, (char *) &ottyb); ioctl (0, TIOCGETC, (char *) &otc); ioctl (0, TIOCGLTC, (char *) &oltc); ioctl (0, TIOCLGET, (char *) &olmode); ntc = otc; nltc = oltc; nttyb = ottyb; #else /* USE_TERMIO */ tcgetattr (0, &old_tc); new_tc = old_tc; # ifndef VDISCARD termFlushChar = CONTROL ('O'); # endif # ifndef VWERASE termWerasChar = CONTROL ('W'); # endif # ifndef VREPRINT termRprntChar = CONTROL ('R'); # endif # ifndef VLNEXT termLiteralNextChar = CONTROL ('V'); # endif # ifndef VSTART termStartChar = CONTROL ('Q'); # endif # ifndef VSTOP termStopChar = CONTROL ('S'); # endif # ifndef VSTATUS termAytChar = CONTROL ('T'); # endif #endif /* USE_TERMIO */ }
/* * Handle the first char of an option (after the initial dash). */ static int mca_opt_first_char(int c) { int flag = (optflag & ~OPT_NO_PROMPT); if (flag == OPT_NO_TOGGLE) { switch (c) { case '_': /* "__" = long option name. */ optgetname = TRUE; mca_opt_toggle(); return (MCA_MORE); } } else { switch (c) { case '+': /* "-+" = UNSET. */ optflag = (flag == OPT_UNSET) ? OPT_TOGGLE : OPT_UNSET; mca_opt_toggle(); return (MCA_MORE); case '!': /* "-!" = SET */ optflag = (flag == OPT_SET) ? OPT_TOGGLE : OPT_SET; mca_opt_toggle(); return (MCA_MORE); case CONTROL('P'): optflag ^= OPT_NO_PROMPT; mca_opt_toggle(); return (MCA_MORE); case '-': /* "--" = long option name. */ optgetname = TRUE; mca_opt_toggle(); return (MCA_MORE); } } /* Char was not handled here. */ return (NO_MCA); }
void uart_rx_done(uint8_t data) { static combuf_t in_combuf; static cb_offset_t in_offset = 0; static uint8_t in_xor_char = 0; if (BEGIN_MARKER == data) { in_offset = 1; in_xor_char = 0; return; } if (in_offset == 0) return; if (ESC_MARKER == data) { in_xor_char = XOR_MARKER; return; } data ^= in_xor_char; in_xor_char = 0; if (1 == in_offset) { in_combuf = combuf_create(0, (data - COMBUF_HEAD_SIZE - COMBUF_END_SIZE)); if (in_combuf < 0) { in_offset = 0; return; } } ITEM(in_combuf, in_offset) = data; if (++in_offset == SIZE(in_combuf)) { /*XXX пофиксить поле control и расчет контрольной суммы*/ CONTROL(in_combuf) |= READY_MASK | CREATE_MASK | INPUT_MASK; if( ISZIGLOAD ) __post_task( &task_combuf_recv ); in_offset = 0; } }