void execute( const uint_fast8_t symbol ) { bit_history.add(symbol); switch(state) { case State::Preamble: if( preamble(bit_history, packet.size()) ) { state = State::Payload; } break; case State::Payload: if( !unstuff(bit_history, packet.size()) ) { packet.add(symbol); } if( end(bit_history, packet.size()) ) { packet.set_timestamp(Timestamp::now()); payload_handler(packet); reset_state(); } else { if( packet_truncated() ) { reset_state(); } } break; default: reset_state(); break; } }
void CParser::parse_char_tok(const char c) { switch(c) { case '(': current_mode.push(SParserMode(current_mode.top().super_mode,EM_PARAMETER)); break; case ';': reset_state(); break; case '\n': reset_state(); break; case ':': current_mode.pop(); break; case ' ': //if(language->allows_whitespace_in_identifiers) output_line << c; break; case '=': current_mode.push(SParserMode(current_mode.top().super_mode,EM_VALUE)); can_generate = false; // until we know we have an appropriate value break; case '\\': current_mode.push(SParserMode(current_mode.top().super_mode,EM_ESCAPED_CHAR)); break; default: output_line << c; can_generate = true; // at this stage there's no reason to believe we can't generate valid code break; } }
// Optimization: in der Funktion selbst loopen (spart function calls) void read_data_fn(struct state *s) { debug(__func__, s); byte current_byte = read_next_byte(s); switch (current_byte) { case START_BYTE_CASE: reset_state(s); s->next = length_fn; break; case STOP_BYTE_CASE: s->flush_cb(s); reset_state(s); s->next = start_fn; break; case ESCAPE_BYTE_CASE: s->next = read_data_esc_fn; break; default: if (s->already_read > s->next_packet_size) { printf("We're exceeding the new length\n"); // unescaped START in payload? } s->buffer[s->already_read] = current_byte; s->already_read++; break; } }
void bench_operating_system_entry() { printf("\nbenchmark on Operating system entry\n"); printf("-------------------------------------\n"); sc_state_t state; reset_state(&state); state.prepare = NULL; state.bench = do_getpid; state.cooldown = NULL; printf("getpid() cost: %lfus\n", get_syscall_elapse(&state)); reset_state(&state); state.bench = do_getppid; printf("getppid() cost: %lfus\n", get_syscall_elapse(&state)); reset_state(&state); state.prepare = do_write_prepare; state.bench = do_write; state.cooldown = do_write_clean; printf("write 1 byte to /dev/null cost: %lfus\n", get_syscall_elapse(&state)); reset_state(&state); state.prepare = do_read_prepare; state.bench = do_read; state.cooldown = do_read_clean; printf("read 1 byte from /dev/zero cost: %lfus\n", get_syscall_elapse(&state)); printf("\n--------------end--------------------\n"); }
pstate *udon_init_from_file(char *filename) { ssize_t bytes_read; int fd; struct stat statbuf; pstate *state; if( (state = (pstate *) udon_malloc(sizeof(pstate))) == NULL) err(EX_OSERR, "Couldn't allocate memory for parser state."); if( (fd = open(filename, O_RDONLY)) < 0) err(EX_NOINPUT, "Couldn't open %s.", filename); if( fstat(fd, &statbuf) == -1) err(EX_NOINPUT, "Opened, but couldn't stat %s.", filename); state->size = statbuf.st_size; state->qsize = state->size >> 3; // size in uint64_t chunks state->filename = filename; // padding to the right so that quickscan stuff can look in bigger chunks if( (state->p_start = (char *) udon_malloc(state->size+8)) == NULL) err(EX_OSERR, "Couldn't allocate memory for file contents (%s).", filename); if( (bytes_read = read(fd, state->p_start, state->size)) != state->size) err(EX_DATAERR, "Only read %zd of %zd bytes from %s.", bytes_read, state->size, filename); reset_state(state); state->p_end = &(state->p_start[state->size - 1]); state->p_qend = &(state->p_quick[state->qsize - 1]); state->p_curr[state->size] = 0; // Null terminate the whole thing just in case close(fd); return state; }
void pre_init(void) { morecore_area = core_buf; morecore_size = SERVER_CORE_SIZE; serial_lock(); // Initialize the serial port set_dlab(0); // we always assume the dlab is 0 unless we explicitly change it disable_interrupt(); disable_fifo(); reset_lcr(); reset_mcr(); clear_iir(); set_baud_rate(BAUD_RATE); reset_state(); enable_fifo(); enable_interrupt(); clear_iir(); // all done init_colours(); /* query what getchar clients exist */ num_getchar_clients = getchar_num_badges(); getchar_clients = calloc(num_getchar_clients, sizeof(getchar_client_t)); for (int i = 0; i < num_getchar_clients; i++) { unsigned int badge = getchar_enumerate_badge(i); assert(badge <= num_getchar_clients); getchar_clients[badge].client_id = badge; getchar_clients[badge].buf = getchar_buf(badge); getchar_clients[badge].last_head = -1; } set_putchar(serial_putchar); serial_irq_reg_callback(serial_irq, 0); /* Start regular heartbeat of 500ms */ timeout_periodic(0, 500000000); serial_unlock(); }
int WavefrontDisplayDevice::open_file(const char *filename) { if (isOpened) { close_file(); } if ((outfile = fopen(filename, "w")) == NULL) { msgErr << "Could not open file " << filename << " in current directory for writing!" << sendmsg; return FALSE; } my_filename = stringdup(filename); #ifdef VMDGENMTLFILE mtlfilename = stringdup(filename); if (replacefileextension(mtlfilename, ".obj", ".mtl")) { msgErr << "Could not generate material filename" << sendmsg; return FALSE; } if ((mtlfile = fopen(mtlfilename, "w")) == NULL) { msgErr << "Could not open file " << mtlfilename << " in current directory for writing!" << sendmsg; return FALSE; } #endif isOpened = TRUE; reset_state(); oldColorIndex = -1; oldMaterialIndex = -1; oldMaterialState = -1; return TRUE; }
void ahrs_update_mag(void) { struct FloatVect3 imu_h; MAGS_FLOAT_OF_BFP(imu_h, imu.mag); const float h_noise[] = { 0.1610, 0.1771, 0.2659}; update_state(&ahrs_impl.mag_h, &imu_h, h_noise); reset_state(); }
/**************** * MAINFUNCTION * ****************/ int main(void) { struct state state; /* Einlesen der uebergebenen Argumente */ read_env(param); /* * Initialisieren der Datenstruktur zum Abbilden des programminternen * Berechnungsstatus */ init_values(&state); /* Schreiben des KML-Headers */ print_header(&state); /* Schreiben der zu verwendenden Farbkonfigurationen */ print_colorstyles(&state); /* Plotten der einzelnen Netzelemente (Dichtedarstellung) und * verwendeten Trajketorien (unsichtbar) */ plot(&state); /* Schliessen der KML-Strukturen */ print_end(&state); /* Reservierte Speicherbereiche wieder freigeben */ reset_state(&state); return 0; }
/* * USB Device Initialize Function * Called by the User to initialize USB Device * Return Value: None */ void USBD_Init (void) { uint32_t reg; /* Enable USB power domain */ MXC_PWRMAN->pwr_rst_ctrl |= MXC_F_PWRMAN_PWR_RST_CTRL_USB_POWERED; /* Setup the USB clocking, select */ MXC_CLKMAN->clk_ctrl |= MXC_F_CLKMAN_CLK_CTRL_USB_CLOCK_ENABLE; /* Force USB clock gater */ reg = MXC_CLKMAN->clk_gate_ctrl0; reg &= ~MXC_F_CLKMAN_CLK_GATE_CTRL0_USB_CLK_GATER; reg |= (0x2 << MXC_F_CLKMAN_CLK_GATE_CTRL0_USB_CLK_GATER_POS); MXC_CLKMAN->clk_gate_ctrl0 = reg; MXC_USB->cn = 0; MXC_USB->cn = MXC_F_USB_CN_USB_EN; MXC_USB->dev_inten = 0; MXC_USB->dev_intfl = 0xFFFF; // clear interrupts MXC_USB->dev_cn = 0; MXC_USB->dev_cn |= MXC_F_USB_DEV_CN_URST; MXC_USB->dev_cn = 0; reset_state(); /* set the descriptor location */ MXC_USB->ep_base = (uint32_t)&ep_buffer_descriptor; /* enable some interrupts */ MXC_USB->dev_inten = INIT_INTS; NVIC_EnableIRQ(USB_IRQn); }
static void mcus_compiler_finalize (GObject *object) { reset_state (MCUS_COMPILER (object)); /* Chain up to the parent class */ G_OBJECT_CLASS (mcus_compiler_parent_class)->finalize (object); }
static void command (int cmd) { switch (cmd) { case ' ': reset_state(); break; } }
void cam_device_free (CamDevice * device) { if (device->state != CAM_DEVICE_STATE_CLOSED) GST_WARNING ("device not in CLOSED state when free'd"); reset_state (device); g_free (device); }
void cam_device_close (CamDevice * device) { g_return_if_fail (device != NULL); g_return_if_fail (device->state == CAM_DEVICE_STATE_OPEN); GST_INFO ("closing ca device %s", device->filename); reset_state (device); }
void configure( const PreambleMatcher preamble_matcher, const UnstuffMatcher unstuff_matcher ) { preamble = preamble_matcher; unstuff = unstuff_matcher; reset_state(); }
void cam_sw_client_close (CamSwClient * client) { g_return_if_fail (client != NULL); g_return_if_fail (client->state == CAM_SW_CLIENT_STATE_OPEN); reset_state (client); client->state = CAM_SW_CLIENT_STATE_CLOSED; }
int test_cons() { CT_Cons *c = ct_cons("CCC", ct_cons("BBB", ct_cons("AAA", NULL, NULL), NULL), NULL); ConsTestState cs = {.count = 0, .err = 0}; ct_cons_iterate(c, count_cons, &cs); CT_IS(cs.count == 3, "c length != 3 (%zu)", cs.count); ct_cons_free_all(c, NULL, NULL, NULL); c = ct_cons_append("AAA", NULL, NULL); ct_cons_append("CCC", ct_cons_append("BBB", c, NULL), NULL); ct_cons_iterate(c, count_cons, reset_state(&cs, NULL)); CT_IS(cs.count == 3, "c append length != 3 (%zu)", cs.count); ct_cons_iterate(c, trace_cons, NULL); ct_cons_free_all(c, NULL, NULL, NULL); CT_DEF_MPOOL(pool, 256, CT_Cons); c = ct_cons("CCC", ct_cons("BBB", ct_cons("AAA", NULL, &pool), &pool), &pool); ct_cons_iterate(c, count_cons, reset_state(&cs, NULL)); CT_IS(cs.count == 3, "c mpool length != 3 (%zu)", cs.count); char *vals[] = {"DDD", "EEE", "FFF"}; CT_Cons *c2 = ct_cons_from_parray((void **)vals, 3, NULL, &pool); ct_cons_iterate(c2, verify_cons_char, reset_state(&cs, vals)); CT_IS(!cs.err, "cons != src array (%zu errors)", cs.err); CT_IS(cs.count == 3, "c2 length != 3 (%zu)", cs.count); float fvals[] = {23, 24, 25}; CT_Cons *cf = ct_cons_from_array(fvals, 3, sizeof(float), NULL, &pool); ct_cons_iterate(cf, verify_cons_float, reset_state(&cs, fvals)); CT_IS(!cs.err, "cons != src array (%zu errors)", cs.err); CT_IS(cs.count == 3, "c2 length != 3 (%zu)", cs.count); ct_cons_iterate(ct_cons_concat_imm(c, c2), count_cons, reset_state(&cs, NULL)); CT_IS(cs.count == 6, "concat_imm(c,c2) length != 6 (%zu)", cs.count); CT_Cons *c3 = ct_cons_concat(c, c, &pool); ct_cons_iterate(c3, count_cons, reset_state(&cs, NULL)); CT_IS(cs.count == 12, "concat(c,c) length != 12 (%zu)", cs.count); ct_cons_iterate(c2, verify_cons_char, reset_state(&cs, vals)); CT_IS(!cs.err, "cons != src array (%zu errors)", cs.err); CT_IS(cs.count == 3, "c2 length != 3 (%zu)", cs.count); ct_cons_iterate(ct_cons_take(ct_cons_concat_imm(c, c), 20, &pool), count_cons, reset_state(&cs, NULL)); ct_mpool_free(&pool); return 0; fail: return 1; }
static void vendor_enable_disable_callback(bool success) { if (success) state = (state == LPM_ENABLING) ? LPM_ENABLED : LPM_DISABLED; else state = (state == LPM_ENABLING) ? LPM_DISABLED : LPM_ENABLED; if (state == LPM_DISABLED) { reset_state(); } }
int main (int argc, char *argv[]) { int i; int found = 0; pstate *state = init_from_file("../sjson-examples/big.txt"); for(i=0; i<10000; i++) { found += parse(state); reset_state(state); } free_state(state); printf("%d\n", found); }
void cam_sw_client_free (CamSwClient * client) { g_return_if_fail (client != NULL); if (client->state != CAM_SW_CLIENT_STATE_CLOSED) GST_WARNING ("client not in CLOSED state when free'd"); reset_state (client); g_free (client); }
void ahrs_update_accel(void) { struct FloatVect3 imu_g; ACCELS_FLOAT_OF_BFP(imu_g, imu.accel); const float alpha = 0.92; ahrs_impl.lp_accel = alpha * ahrs_impl.lp_accel + (1. - alpha) *(FLOAT_VECT3_NORM(imu_g) - 9.81); const struct FloatVect3 earth_g = {0., 0., -9.81 }; const float dn = 250*fabs( ahrs_impl.lp_accel ); struct FloatVect3 g_noise = {1.+dn, 1.+dn, 1.+dn}; update_state(&earth_g, &imu_g, &g_noise); reset_state(); }
void Estimator::init(Params* _params, bool use_matrix_exponential, bool use_quadratic_integration, bool use_accelerometer) { params = _params; mat_exp = use_matrix_exponential; quad_int = use_quadratic_integration; use_acc = use_accelerometer; last_time = 0; reset_state(); }
static void reset_session(plugin_data *p) { if (p->state.fd != -1) { close(p->state.fd); p->state.fd = -1; } free(p->state.vhd.bat.bat); p->state.vhd.bat.bat = NULL; free(p->state.curr_bitmap); p->state.curr_bitmap = NULL; reset_state(&p->state); uuid_clear(p->session_id); }
static void init(thread_t *post_thread) { assert(post_thread != NULL); thread = post_thread; vendor->set_callback(VENDOR_SET_LPM_MODE, vendor_enable_disable_callback); vendor->send_command(VENDOR_GET_LPM_IDLE_TIMEOUT, &idle_timeout_ms); idle_alarm = alarm_new(); if (!idle_alarm) { LOG_ERROR(LOG_TAG, "%s could not create idle alarm.", __func__); } reset_state(); }
void Input::end_frame() { auto device = core::get_subsystem<graphics::WindowDevice>(); // _window_size = core::get_subsystem<graphics::WindowDevice>()->get_window_size(); _last_mouse_position = get_mouse_position(); // check for focus change this frame if( device->get_window_flags() & SDL_WINDOW_INPUT_FOCUS ) { if( !_input_focus ) { reset_state(); if( !_mouse_visible ) SDL_ShowCursor(SDL_FALSE); } _input_focus = true; } else { if( _input_focus ) { reset_state(); SDL_ShowCursor(SDL_TRUE); } _input_focus = false; } // recenter mouse if no mouse visibility if( _input_focus && !_mouse_visible && !_touch_emulation ) { SDL_WarpMouseInWindow((SDL_Window*)device->get_window_object(), _window_size[0]/2, _window_size[1]/2); } }
static void trace_print_short(void) { char bytes_string[(BYTES_BUF_SIZE*2)+1]; int i; if (bytes_count == 0) return; if (state != WANT_PRINT) return; bytes_string[0] = '\0'; for (i = 0; i < bytes_count; i++) { snprintf(bytes_string + i*2, 3, "%02x", bytes_buf[i]); } LOG_DEBUG(0, "%04x| %-12s%-8s%-20s\n", instr_pc, bytes_string, mnemonic, operand_text); reset_state(); }
int MayaDisplayDevice::open_file(const char *filename) { if (isOpened) { close_file(); } if ((outfile = fopen(filename, "w")) == NULL) { msgErr << "Could not open file " << filename << " in current directory for writing!" << sendmsg; return FALSE; } my_filename = stringdup(filename); isOpened = TRUE; reset_state(); objnameindex = 0; oldColorIndex = -1; oldMaterialIndex = -1; oldMaterialState = -1; return TRUE; }
void m6809_trace_print(unsigned int reg_cc, unsigned int reg_a, unsigned int reg_b, unsigned int reg_dp, unsigned int reg_x, unsigned int reg_y, unsigned int reg_u, unsigned int reg_s) { char bytes_string[(BYTES_BUF_SIZE*2)+1]; int i; if (bytes_count == 0) return; if (state != WANT_PRINT) return; bytes_string[0] = '\0'; for (i = 0; i < bytes_count; i++) { snprintf(bytes_string + i*2, 3, "%02x", bytes_buf[i]); } LOG_DEBUG(0, "%04x| %-12s%-8s%-20s", instr_pc, bytes_string, mnemonic, operand_text); LOG_DEBUG(0, "cc=%02x a=%02x b=%02x dp=%02x x=%04x y=%04x u=%04x s=%04x\n", reg_cc, reg_a, reg_b, reg_dp, reg_x, reg_y, reg_u, reg_s); reset_state(); }
void m6809_base_device::device_reset() { m_nmi_line = false; m_nmi_asserted = false; m_firq_line = false; m_irq_line = false; m_lds_encountered = false; m_dp = 0x00; // reset direct page register m_cc |= CC_I; // IRQ disabled m_cc |= CC_F; // FIRQ disabled m_pc.b.h = m_addrspace[AS_PROGRAM]->read_byte(VECTOR_RESET_FFFE + 0); m_pc.b.l = m_addrspace[AS_PROGRAM]->read_byte(VECTOR_RESET_FFFE + 1); // reset sub-instruction state reset_state(); }
void serial_init(gdb_state_t *gdb) { // Initialize the serial port int UNUSED error; error = serial_lock(); gdb_state = gdb; set_dlab(0); // we always assume the dlab is 0 unless we explicitly change it disable_interrupt(); disable_fifo(); reset_lcr(); reset_mcr(); clear_iir(); set_baud_rate(BAUD_RATE); reset_state(); enable_fifo(); enable_interrupt(); clear_iir(); initialise_buffer(); error = serial_unlock(); }