static const struct zip_cd *find_cd_for_entry(const uint8_t *map, size_t size, const struct zip_eocd *eocd, const char *filename) { /* * eocd->cd_offset points to the beginning of eocd->entry_count number * of Central Directories, one per entry. Find the one representing the * requested filename. */ const struct zip_cd *cd; size_t i; die_if(eocd->cd_offset > size, "eocd offset too large"); cd = (struct zip_cd *)(map + dtohl(eocd->cd_offset)); for (i = 0; i < eocd->entry_count; i++) { uint16_t len; die_if(dtohl(cd->magic) != ZIP_CD_MAGIC, "bad zip cd magic 0x%08x", dtohl(cd->magic)); len = dtohs(cd->filename_length); if (len == strlen(filename) && !memcmp(cd->filename, filename, len)) return cd; cd = (const struct zip_cd *) ((const uint8_t *)cd + sizeof(*cd) + len + dtohs(cd->extra_length) + dtohs(cd->comment_length)); die_if((const uint8_t *)cd > map + size, "cd outside map"); } die("no entry '%s' found", filename); return NULL; }
int AdaptTempering_SyncAllNodes(at_t *at, MPI_Comm comm) { int mpisize = 1; int mpirank = 0; die_if (at == NULL, "null pointer at to at_t\n"); if (comm != MPI_COMM_NULL) die_if((MPI_SUCCESS != MPI_Comm_size(comm, &mpisize)), "cannot even get MPI size\n"); if (mpisize > 1) { die_if((MPI_SUCCESS != MPI_Comm_rank(comm, &mpirank)), "cannot get MPI rank\n"); /* Broadcast at_t */ die_if((MPI_SUCCESS != MPI_Bcast(at, sizeof(*at), MPI_BYTE, 0, comm)), "%3d/%3d: failed to bcast at (%p), type = *at, size = 1 (%d), comm = 0x%lX\n", mpirank, mpisize, at, 1, (unsigned long) comm); } at->mpi_comm = comm; at->mpi_size = mpisize; at->mpi_rank = mpirank; if (at->mpi_rank != 0) { at->rng_file = NULL; at->trace_file = NULL; at->mb = NULL; } return 0; }
int read_from_eeprom(struct eeprom *e, int addr, int size, int hex) { int ch, i; // hex print out die_if((ch = eeprom_read_byte(e, addr)) < 0, "read error"); i = 1; if(hex) printf("\n %.4x| %.2x ", addr, ch); else putchar(ch); while(--size) { die_if((ch = eeprom_read_current_byte(e)) < 0, "read error"); if(hex) { addr++; if( (i % 16) == 0 ) printf("\n %.4x| ", addr); else if( (i % 8) == 0 ) printf(" "); i++; printf("%.2x ", ch); } else { putchar(ch); } } if(hex) printf("\n\n"); fflush(stdout); return 0; }
/* return a pointer of an initialized at_t * if possible, initial values are taken from configuration * file `cfg', otherwise default values are assumed */ static at_t *AdaptTempering_OpenCfg(const char *cfgname, double tmstep, int suffix) { cfgdata_t *cfg; at_t *at; bool bLoaded; char *p; int delay; /* open configuration file */ die_if(!(cfg = cfgopen(cfgname)), "at_t: cannot open config. file %s.\n", cfgname); /* allocate memory for at_t */ xnew(at, 1); /* Get the file suffix first */ die_if(suffix >= 10, "do not support # of simulations > 10 currently\n"); at->suffix = (char)(((int)'0') + suffix); /* call low level function */ die_if (!(bLoaded = at_cfgopen_low(at,cfg,tmstep)), "at_t: error while reading configuration file %s\n", cfgname); printf("Successfully loaded cfg data!\n"); /* generate different random seeds in multi-simulation */ delay = suffix * 2; sleep(delay); /* load random number generator */ mtload(at->rng_file, 0); /* close handle to configuration file */ cfgclose(cfg); return at; }
void AdaptTempering_OpenLog(at_t *at) { die_if(at == NULL, "failed to load adaptive tempering data.\n"); die_if(at->trace_file == NULL, "failed to get the name of trace file. Is this function called by a non-master node?\n"); at->log = log_open(at->trace_file); /* set an attempt value for at->beta before reading the value from mb.av */ AdaptTempering_UpdateTemperature(at); /* update temperature */ }
static const struct zip_eocd *find_eocd(const uint8_t *map, size_t size) { const struct zip_eocd *eocd; eocd = (struct zip_eocd *)(map + size - sizeof(*eocd)); die_if(dtohl(eocd->magic) != ZIP_EOCD_MAGIC, "bad zip eocd magic 0x%08x", dtohl(eocd->magic)); die_if(dtohs(eocd->entry_count) == 0, "bad entry count 0"); return eocd; }
static TegraGpio *new_tegra_gpio(TegraGpioPort port, unsigned index, unsigned pinmux) { die_if(port < 0 || port >= GPIO_NUM_PORTS, "Bad GPIO port %d.\n", port); die_if(index >= GPIO_GPIOS_PER_PORT, "Bad GPIO index %d.\n", index); TegraGpio *gpio = xzalloc(sizeof(*gpio)); gpio->port = port; gpio->index = index; gpio->pinmux = pinmux; return gpio; }
static const struct zip_lfh *find_lfh_for_entry(const uint8_t *map, size_t size, const struct zip_cd *cd) { const struct zip_lfh *lfh; die_if(cd->lfh_offset > size, "lfh offset outside map"); lfh = (const struct zip_lfh *)(map + cd->lfh_offset); die_if(dtohs(lfh->compression_method) != 0, "unhandled compression method %d", dtohs(lfh->compression_method)); return lfh; }
int AdaptTempering_Langevin(at_t *at, llong_t step, bool bfirst, bool blast, bool btr, bool bflush) { double invwf = 1.0, T1 = 0., T2 = 0., Eav = 0., ndlnwfdbeta; int ib, rep; double *varr = NULL; double noise; noise = (*at->grand)(); die_if (at->grand == NULL, "no gaussian RNG\n"); /* update energy data, change at->beta */ /* repeat several times to change the temperature */ for (rep = 0; rep < at->mvreps; rep++) { /* 1. deposit the current energy and temperature */ mb_add(at->mb, at->Ea, varr, at->beta, &ib, &invwf, &ndlnwfdbeta); /* 2. use Langevin equation to update the temperature */ T1 = Beta2T(at->beta); at->beta = mb_move(at->mb, at->Ea, at->beta, ib, ndlnwfdbeta, noise, &Eav); T2 = Beta2T(at->beta); } if (at_doevery(step, at->mb->nstrefresh, 0, blast)) mb_refresh_et(at->mb, 1); at_output(at, step, ib, invwf, T1, T2, Eav, bfirst, blast, btr, bflush); return 0; }
void init_mpu6050(struct eeprom *e) { int result=0; die_if(eeprom_open("/dev/i2c/0", 0x68, EEPROM_TYPE_8BIT_ADDR, e) < 0, "unable to open MPU6050 device file "); result=mpu_init(); if(!result) { printf("mpu initialization complete......\n "); //mpu initialization complete if(!mpu_set_sensors(INV_XYZ_GYRO | INV_XYZ_ACCEL)) //mpu_set_sensor printf("mpu_set_sensor complete ......\n"); else printf("mpu_set_sensor come across error ......\n"); if(!mpu_configure_fifo(INV_XYZ_GYRO | INV_XYZ_ACCEL)) //mpu_configure_fifo printf("mpu_configure_fifo complete ......\n"); else printf("mpu_configure_fifo come across error ......\n"); if(!mpu_set_sample_rate(50)) //mpu_set_sample_rate printf("mpu_set_sample_rate complete ......\n"); else printf("mpu_set_sample_rate error ......\n"); if(!dmp_load_motion_driver_firmware()) //dmp_load_motion_driver_firmvare printf("dmp_load_motion_driver_firmware complete ......\n"); else printf("dmp_load_motion_driver_firmware come across error ......\n"); if(!dmp_set_orientation(inv_orientation_matrix_to_scalar(gyro_orientation))) //dmp_set_orientation printf("dmp_set_orientation complete ......\n"); else printf("dmp_set_orientation come across error ......\n"); if(!dmp_enable_feature(DMP_FEATURE_6X_LP_QUAT | DMP_FEATURE_TAP | DMP_FEATURE_ANDROID_ORIENT | DMP_FEATURE_SEND_RAW_ACCEL | DMP_FEATURE_SEND_CAL_GYRO | DMP_FEATURE_GYRO_CAL)) //dmp_enable_feature printf("dmp_enable_feature complete ......\n"); else printf("dmp_enable_feature come across error ......\n"); if(!dmp_set_fifo_rate(50)) //dmp_set_fifo_rate printf("dmp_set_fifo_rate complete ......\n"); else printf("dmp_set_fifo_rate come across error ......\n"); run_self_test(); //自检 if(!mpu_set_dmp_state(1)) printf("mpu_set_dmp_state complete ......\n"); else printf("mpu_set_dmp_state come across error ......\n"); } else { printf("mpu INIT INIT INIT error ......\r\n"); } }
void dealloc_obj(int i) { // printf("dealloc_obj %d\n", i); int n = g_nobjs; die_if(i >= n, "unknown object index"); --n; g_nobjs = n; if(n == 0 || i == n) { return; } g_obj_tid[i] = g_obj_tid[n]; g_obj_x[i] = g_obj_x[n]; g_obj_y[i] = g_obj_y[n]; g_obj_vx[i] = g_obj_vx[n]; g_obj_vy[i] = g_obj_vy[n]; g_obj_ax[i] = g_obj_ax[n]; g_obj_ay[i] = g_obj_vy[n]; }
int setup_serial_port() { struct termios newtio; char serialPort[32]; ini_gets("sms","usbserial","/dev/ttyUSB0", serialPort, sizeof(serialPort), inifile); info("Using serial device %s", serialPort); g_serial_fd = open(serialPort, O_RDWR | O_NOCTTY | O_NDELAY); die_if(g_serial_fd < 0, "Unable to open the serial port %s",serialPort); if(flock(g_serial_fd, LOCK_EX | LOCK_NB) == -1) { close(g_serial_fd); die_strerror("Serial port %s in use", serialPort); } bzero(&newtio, sizeof(newtio)); newtio.c_cflag = getBaud() | CRTSCTS | CS8 | CLOCAL | CREAD | O_NDELAY; // uncomment next line to disable hardware handshake newtio.c_cflag &= ~CRTSCTS; newtio.c_iflag = IGNPAR; newtio.c_oflag = 0; newtio.c_lflag = 0; newtio.c_cc[VTIME] = 1; newtio.c_cc[VMIN] = 0; /* no blocking read */ tcflush(g_serial_fd, TCIOFLUSH); tcsetattr(g_serial_fd, TCSANOW, &newtio); return g_serial_fd; }
int main(int argc, char** argv) { struct eeprom e; int op; op = 0; usage_if(argc != 2 || argv[1][0] != '-' || argv[1][2] != '\0'); op = argv[1][1]; fprintf(stderr, "Open /dev/i2c/0 with 8bit mode\n"); die_if(eeprom_open("/dev/i2c/0", 0x50, EEPROM_TYPE_8BIT_ADDR, &e) < 0, "unable to open eeprom device file " "(check that the file exists and that it's readable)"); switch(op) { case 'r': fprintf(stderr, " Reading 256 bytes from 0x0\n"); read_from_eeprom(&e, 0, 256); break; case 'w': fprintf(stderr, " Writing 0x00-0xff into 24C08 \n"); write_to_eeprom(&e, 0); break; default: usage_if(1); exit(1); } eeprom_close(&e); return 0; }
static int read_row(TDS_POOL_MEMBER * pmbr, const unsigned char *buf, int maxlen, int *bytes_read) { TDSCOLUMN *curcol; TDSRESULTINFO *info; int i, colsize; int pos = 1; /* skip marker */ info = pmbr->tds->res_info; die_if((!info), "Entered read_row() without a res_info structure."); for (i = 0; i < info->num_cols; i++) { curcol = info->columns[i]; if (!is_fixed_type(curcol->column_type)) { if (bytes_left(pmbr, buf, pos, maxlen, 1)) { *bytes_read = maxlen; return 0; } colsize = buf[pos++]; } else { colsize = tds_get_size_by_type(curcol->column_type); } if (bytes_left(pmbr, buf, pos, maxlen, colsize)) { *bytes_read = maxlen; return 0; } pos += colsize; } *bytes_read = pos; return 1; }
static void contact_ready_cb (GObject *object, GAsyncResult *result, gpointer user_data) { TpConnection *conn = (TpConnection *) object; GHashTable *asv; ContactPair *pair; GError *error = NULL; pair = g_slice_new0 (ContactPair); pair->contacts[0] = tp_connection_dup_contact_by_id_finish (conn, result, &error); pair->contacts[1] = g_object_ref (tp_connection_get_self_contact (conn)); if (die_if (error, "tp_connection_dup_contact_by_id_async()")) { g_clear_error (&error); contact_pair_free (pair); return; } asv = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) tp_g_value_slice_free); g_hash_table_insert (asv, "previous-owner", tp_g_value_slice_new_static_string ("Shadowman")); example_cli_connection_interface_hats_call_set_hat (conn, -1, "red", EXAMPLE_HAT_STYLE_FEDORA, asv, set_hat_cb, pair, contact_pair_free, NULL); g_hash_table_unref (asv); }
static void got_hats_cb (TpConnection *conn, const GPtrArray *hats, const GError *error, gpointer user_data, GObject *weak_object) { guint i; if (die_if (error, "GetHats()")) return; for (i = 0; i < hats->len; i++) { GValueArray *vals = g_ptr_array_index (hats, i); guint handle; const gchar *color; guint style; GHashTable *details; tp_value_array_unpack (vals, 4, &handle, &color, &style, &details); g_message ("Contact #%u has hat style %u, color \"%s\", with %u " "properties", handle, style, color, g_hash_table_size (details)); } tp_cli_connection_call_disconnect (conn, -1, disconnect_cb, NULL, NULL, NULL); }
int main(void) { char s[] = "hello world"; die_if (strlen(s) > 8, "string \"%s\" is too long\n", s); return 0; }
void display_set_ops(DisplayOps *ops) { die_if(display_ops, "%s: Display ops already set.\n", __func__); display_ops = ops; /* Call stop() when exiting depthcharge. */ list_insert_after(&display_cleanup_func.list_node, &cleanup_funcs); }
void exception_dispatch(void) { u32 vec = exception_state_ptr->vector; die_if(vec >= EXC_COUNT || !names[vec], "Bad exception vector %u", vec); dump_exception_state(); dump_stack(exception_state_ptr->regs.sp, 512); halt(); }
void alloc_timer_1s(int oid, Uint64 t) { int i = g_ntimers; printf("alloc_timer %d\n", i); die_if(i >= MAX_TIMERS, "unable to allocate timer"); ++g_ntimers; g_timer_expire[i] = t + g_perf_freq; g_timer_oid[i] = oid; }
void console_add_output_driver(struct console_output_driver *out) { die_if(!out->putchar && !out->write, "Need at least one output func\n"); /* Check if this driver was already added to the console list */ if (output_driver_exists(out)) return; out->next = console_out; console_out = out; }
int power_off(void) { die_if(!power_ops, "%s: No power ops set.\n", __func__); assert(power_ops->power_off); if (run_cleanup_funcs(CleanupOnPowerOff)) return -1; return power_ops->power_off(power_ops); }
int cold_reboot(void) { die_if(!power_ops, "%s: No power ops set.\n", __func__); assert(power_ops->cold_reboot); if (run_cleanup_funcs(CleanupOnReboot)) return -1; printf("Rebooting...\n"); return power_ops->cold_reboot(power_ops); }
SysinfoResetPowerOps *new_sysinfo_reset_power_ops(PowerOps *power_off_ops, new_gpio_from_coreboot_t new_gpio_from_coreboot) { SysinfoResetPowerOps *p = xzalloc(sizeof(*p)); p->ops.power_off = &pass_through_power_off; p->ops.cold_reboot = &gpio_reboot; p->power_off_ops = power_off_ops; p->reset_gpio = sysinfo_lookup_gpio("reset", 1, new_gpio_from_coreboot); die_if(!p->reset_gpio, "could not find 'reset' GPIO in coreboot table"); return p; }
void mainboard_keyboard_init(struct pk_sm_desc *desc) { pwr_btn_gpio = sysinfo_lookup_gpio("power", 1, new_tegra_gpio_input_from_coreboot); die_if(!pwr_btn_gpio, "No GPIO for power!!\n"); /* Inputs volup and voldown are active low. */ vol_down_gpio = new_gpio_not(&new_tegra_gpio_input(GPIO(X, 7))->ops); vol_up_gpio = new_gpio_not(&new_tegra_gpio_input(GPIO(X, 6))->ops); foster_sm_init(desc); }
int write_to_eeprom(struct eeprom *e, int addr) { int c; while((c = getchar()) != EOF) { print_info("."); fflush(stdout); die_if(eeprom_write_byte(e, addr++, c), "write error"); } print_info("\n\n"); return 0; }
static void disconnect_cb (TpConnection *conn, const GError *error, gpointer user_data, GObject *weak_object) { if (die_if (error, "Disconnect()")) return; main_ret = 0; g_main_loop_quit (mainloop); }
static PchGpio *new_pch_gpio(PchGpioCfg *cfg, unsigned bank, unsigned bit) { die_if(bank >= cfg->num_banks || bit >= 32, "GPIO parameters (%d, %d) out of bounds.\n", bank, bit); PchGpio *gpio = xzalloc(sizeof(*gpio)); gpio->cfg = cfg; gpio->use = &pch_gpio_use; gpio->bank = bank; gpio->bit = bit; return gpio; }
static int write_to_eeprom(struct eeprom *e, int addr) { int i; for(i=0, addr=0; i<256; i++, addr++) { if( (i % 16) == 0 ) printf("\n %.4x| ", addr); else if( (i % 8) == 0 ) printf(" "); printf("%.2x ", i); fflush(stdout); die_if(eeprom_write_byte(e, addr, i), "write error"); } fprintf(stderr, "\n\n"); return 0; }
static int read_from_eeprom(struct eeprom *e, int addr, int size) { int ch, i; for(i = 0; i < size; ++i, ++addr) { die_if((ch = eeprom_read_byte(e, addr)) < 0, "read error"); if( (i % 16) == 0 ) printf("\n %.4x| ", addr); else if( (i % 8) == 0 ) printf(" "); printf("%.2x ", ch); fflush(stdout); } fprintf(stderr, "\n\n"); return 0; }