int __sata_initialize(void) { int rc; int i; for (i = 0; i < CONFIG_SYS_SATA_MAX_DEVICE; i++) { memset(&sata_dev_desc[i], 0, sizeof(struct block_dev_desc)); sata_dev_desc[i].if_type = IF_TYPE_SATA; sata_dev_desc[i].dev = i; sata_dev_desc[i].part_type = PART_TYPE_UNKNOWN; sata_dev_desc[i].type = DEV_TYPE_HARDDISK; sata_dev_desc[i].lba = 0; sata_dev_desc[i].blksz = 512; sata_dev_desc[i].log2blksz = LOG2(sata_dev_desc[i].blksz); sata_dev_desc[i].block_read = sata_read; sata_dev_desc[i].block_write = sata_write; rc = init_sata(i); if (!rc) { rc = scan_sata(i); if (!rc && (sata_dev_desc[i].lba > 0) && (sata_dev_desc[i].blksz > 0)) init_part(&sata_dev_desc[i]); } } sata_curr_device = 0; return rc; }
// 初期化するためだけ void init_all_parts() { // 録音したノートをレセットするため parts_active = FALSE; if (touch_enabled) not_active_count = 0; else not_active_count = SILENCE_BEFORE_AUTO_PLAY_INIT; current_rec_part = 0; int i; int total_parts = TOTAL_PARTS; for (i = 0; i < total_parts; i++) { part* p = (parts + i); if (i == 0) init_part(p, TRUE); else init_part(p, FALSE); init_part_color(p, i); LOGD("init_part", "p->rgb->r: %f, g: %f, b: %f", p->rgb->r, p->rgb->g, p->rgb->b); } }
static int warp_ata_init(int dev, disk_partition_t * info, block_dev_desc_t ** dev_desc) { int ret; u32 lun, part; block_dev_desc_t *sata_get_dev(int dev); lun = WARP_DEV_TO_LUN(dev); part = WARP_DEV_TO_PART(dev); if (sata_dev_desc[lun].if_type != IF_TYPE_SATA) { memset(&sata_dev_desc[lun], 0, sizeof(struct block_dev_desc)); sata_dev_desc[lun].if_type = IF_TYPE_SATA; sata_dev_desc[lun].dev = lun; sata_dev_desc[lun].part_type = PART_TYPE_UNKNOWN; sata_dev_desc[lun].type = DEV_TYPE_HARDDISK; sata_dev_desc[lun].lba = 0; sata_dev_desc[lun].blksz = 512; sata_dev_desc[lun].block_read = sata_read; sata_dev_desc[lun].block_write = sata_write; if ((ret = init_sata(lun))) return ret; if ((ret = scan_sata(lun))) return ret; if ((sata_dev_desc[lun].lba > 0) && (sata_dev_desc[lun].blksz > 0)) init_part(&sata_dev_desc[lun]); } if ((*dev_desc = sata_get_dev(lun)) == NULL) { printf("device %d not found\n", lun); return -1; } if (part == 0) { info->start = 0; return 0; } if ((ret = get_partition_info(*dev_desc, part, info)) != 0) { printf("partition %d:%d not found\n", lun, part); return ret; } return 0; }
void part_tic_counter() { if (!playback_paused) { int i; for (i = 0; i < TOTAL_PARTS; i++) { part* p = (parts + i); if (p->current_tic >= p->total_tics && p->is_recording) { p->is_recording = FALSE; p->current_tic = 0; LOGI("part_tic_counter", "(p->current_tic >= p->total_tics && p->is_recording)"); init_part(parts + get_free_part(), TRUE); } else if (p->current_tic >= p->total_tics && !p->is_recording && p->is_alive) { count_part_ttl(p); p->current_tic = 0; } else if (p->current_tic < p->total_tics && p->is_recording && p->current_note > 0) { p->current_tic++; } else if (p->current_tic < p->total_tics && !p->is_recording && p->is_alive) { p->current_tic++; } } } }
int host_dev_bind(int dev, char *filename) { struct host_block_dev *host_dev = find_host_device(dev); if (!host_dev) return -1; if (host_dev->blk_dev.priv) { os_close(host_dev->fd); host_dev->blk_dev.priv = NULL; } if (host_dev->filename) free(host_dev->filename); if (filename && *filename) { host_dev->filename = strdup(filename); } else { host_dev->filename = NULL; return 0; } host_dev->fd = os_open(host_dev->filename, OS_O_RDWR); if (host_dev->fd == -1) { printf("Failed to access host backing file '%s'\n", host_dev->filename); return 1; } block_dev_desc_t *blk_dev = &host_dev->blk_dev; blk_dev->if_type = IF_TYPE_HOST; blk_dev->priv = host_dev; blk_dev->blksz = 512; blk_dev->lba = os_lseek(host_dev->fd, 0, OS_SEEK_END) / blk_dev->blksz; blk_dev->block_read = host_block_read; blk_dev->block_write = host_block_write; blk_dev->dev = dev; blk_dev->part_type = PART_TYPE_UNKNOWN; init_part(blk_dev); return 0; }
int mmc_init(int slot) { int ret = 1; switch (slot) { case 0: configure_controller(&cur_controller_data[slot], slot); ret = configure_mmc(&cur_card_data[slot], &cur_controller_data[slot]); break; case 1: configure_controller(&cur_controller_data[slot], slot); ret = configure_mmc(&cur_card_data[slot], &cur_controller_data[slot]); break; default: printf("mmc_init:mmc slot is not supported%d\n", slot); } if (ret != 1) { mmc_blk_dev[slot].dev = -1; } else { mmc_blk_dev[slot].if_type = IF_TYPE_MMC; mmc_blk_dev[slot].part_type = PART_TYPE_DOS; mmc_blk_dev[slot].dev = cur_controller_data[slot].slot; mmc_blk_dev[slot].lun = 0; mmc_blk_dev[slot].type = 0; /* FIXME fill in the correct size (is set to 32MByte) */ mmc_blk_dev[slot].blksz = MMCSD_SECTOR_SIZE; mmc_blk_dev[slot].lba = 0x10000; mmc_blk_dev[slot].removable = 0; mmc_blk_dev[slot].block_read = mmc_bread; mmc_blk_dev[slot].block_write = mmc_bwrite; init_part (&mmc_blk_dev[slot]); fat_register_device(&mmc_blk_dev[slot], 1); } return 0; }
int scan_sata(int dev) { /* dev is the index of each ata device in the system. one PATA port * contains 2 devices. one element in scan_done array indicates one * PATA port. device connected to one PATA port is selected by * bfin_dev_select() before access. */ struct ata_port *ap = &port[dev]; static int scan_done[(CONFIG_SYS_SATA_MAX_DEVICE+1)/PATA_DEV_NUM_PER_PORT]; if (scan_done[dev/PATA_DEV_NUM_PER_PORT]) return 0; /* Check for attached device */ if (!bfin_ata_probe_port(ap)) { if (bfin_softreset(ap)) { /* soft reset failed, try a hard one */ bfin_ata_reset_port(ap); if (bfin_softreset(ap)) scan_done[dev/PATA_DEV_NUM_PER_PORT] = 1; } else { scan_done[dev/PATA_DEV_NUM_PER_PORT] = 1; } } if (scan_done[dev/PATA_DEV_NUM_PER_PORT]) { /* Probe device and set xfer mode */ bfin_ata_identify(ap, dev%PATA_DEV_NUM_PER_PORT); bfin_ata_set_Feature_cmd(ap, dev%PATA_DEV_NUM_PER_PORT); init_part(&sata_dev_desc[dev]); return 0; } printf("PATA device#%d is not present on ATA port#%d.\n", ap->port_no%PATA_DEV_NUM_PER_PORT, ap->port_no/PATA_DEV_NUM_PER_PORT); return -1; }
block_dev_desc_t *systemace_get_dev(int dev) { /* The first time through this, the systemace_dev object is not yet initialized. In that case, fill it in. */ if (systemace_dev.blksz == 0) { systemace_dev.if_type = IF_TYPE_UNKNOWN; systemace_dev.dev = 0; systemace_dev.part_type = PART_TYPE_UNKNOWN; systemace_dev.type = DEV_TYPE_HARDDISK; systemace_dev.blksz = 512; systemace_dev.removable = 1; systemace_dev.block_read = systemace_read; /* * Ensure the correct bus mode (8/16 bits) gets enabled */ ace_writew(CONFIG_SYS_SYSTEMACE_WIDTH == 8 ? 0 : 0x0001, 0); init_part(&systemace_dev); } return &systemace_dev; }
int mmc_legacy_init(int verbose) { //test_switch_register(); printf("MMC Init Card ...\n"); InitCardReader(); ReInitCard(); mmc_blk_dev.if_type = IF_TYPE_MMC; mmc_blk_dev.part_type = PART_TYPE_DOS; mmc_blk_dev.dev = 0; mmc_blk_dev.lun = 0; mmc_blk_dev.type = 0; /* FIXME fill in the correct size (is set to 32MByte) */ mmc_blk_dev.blksz = 512; mmc_blk_dev.lba = 0x100000; mmc_blk_dev.removable = 0; mmc_blk_dev.block_read = mmc_bread; if (fat_register_device(&mmc_blk_dev, 1)) { printf("Could not register MMC fat device\n"); init_part(&mmc_blk_dev); } if (mmc_inited == 0) { mmc_inited = 1; //detect_program_bin(); //detect_test_bin(); } mmc_inited = 1; return 0; }
AyronBS::AyronBS(Vector2 opos, double shipAngle, ShipData *shipData, unsigned int code) : BigShip(opos, shipAngle, shipData, code | SpaceSprite::NO_AA) { STACKTRACE; int i; int ix, iy; // read the layout FILE *inp; inp = tw_fopen(data_full_path("shpayrbs_layout.txt").c_str(), "rt"); if (!inp) {tw_error("couldn't find the AyronBS layout");} fscanf(inp, "%i\n", &nBSinfo); Ntypes = nBSinfo; BSinfo = new AyronShipPartInfo* [nBSinfo]; for ( i = 0; i < nBSinfo; ++i ) { BSinfo[i] = new AyronShipPartInfo(); fscanf(inp, "%*10c %lf %lf %lf %lf %lf", &BSinfo[i]->crew, &BSinfo[i]->batt, &BSinfo[i]->dynamo, &BSinfo[i]->turning, &BSinfo[i]->thrusting); BSinfo[i]->spr_crewed = data->more_sprites[i]; BSinfo[i]->spr_uncrewed = data->more_sprites[i + Ntypes]; } fscanf(inp, "%i %i\n", &Nx, &Ny); Nparts = Nx * Ny; // ayronparts = new (AyronShipPart*) [N]; ayronparts = new AyronShipPart* [Nparts](); parts = (BigShipPart**) ayronparts; int *itype, *iweapon; double *anglecenter, *moveangle; itype = new int [Nparts]; iweapon = new int [Nparts]; anglecenter = new double [Nparts]; moveangle = new double [Nparts]; // the ship hull sprites for ( i = 0; i < Nparts; ++i ) { fscanf(inp, "%i", &itype[i]); } // the ship weapons for ( i = 0; i < Nparts; ++i ) { fscanf(inp, "%i %lf %lf", &iweapon[i], &anglecenter[i], &moveangle[i]); anglecenter[i] *= PI / 180.0; moveangle[i] *= PI / 180.0; } fclose(inp); // the dimension of a single block of the ship (on a regular grid). // note that each block should be square, and of each grid-block is // of the same size. w = data->more_sprites[0]->size(0).x; // the orig picture has 0.5 extra room to allow for rotation; this extra room // is empty. w /= 1.5; // initialize the ship ayronparts. for ( iy = 0; iy < Ny; ++iy ) { for ( ix = 0; ix < Nx; ++ix ) { int k; k = iy*Nx + ix; Vector2 relpos; relpos = w * Vector2(0.5*(Ny-1) - iy, ix - 0.5*(Nx-1)); ayronparts[k] = init_part(relpos, itype[k], BSinfo); if (ayronparts[k]) physics->add(ayronparts[k]); // AutoGun(AyronBS *aowner, Vector2 orelpos, int otype, SpaceSprite *spr); if (iweapon[k] == 1) game->add(new AutoGun(ayronparts[k], relpos, anglecenter[k], moveangle[k], data->spriteWeapon, data->spriteWeaponExplosion)); } } delete[] itype; delete[] iweapon; delete[] anglecenter; delete[] moveangle; for ( i = 0; i < nBSinfo; ++i ) delete BSinfo[i]; delete[] BSinfo; weaponColor = tw_get_config_int("Weapon", "Color", 0); weaponRange = scale_range(tw_get_config_float("Weapon", "Range", 0)); weaponDamage = tw_get_config_int("Weapon", "Damage", 0); recharge_rate_ref = recharge_rate; turn_rate_ref = turn_rate; accel_rate_ref = accel_rate; // remove this from the physics interaction //mass = 0; this value is needed by the ship ayronparts collide_flag_anyone = 0; collide_flag_sameship = 0; collide_flag_sameteam = 0; attributes |= ATTRIB_UNDETECTABLE; // also, add the ship's ayronparts to the physics target list // for (i = 0; i < N; ++i ) // if (ayronparts[i]) // game->add_target(ayronparts[i]); // update: no need to this here anymore, it's done in the part-constructor. crew_max = 0; for ( i = 0; i < Nparts; ++i ) if (ayronparts[i]) crew_max += ayronparts[i]->crew_max; }
/********************************************************************************* * (re)-scan the scsi bus and reports scsi device info * to the user if mode = 1 */ void scsi_scan(int mode) { unsigned char i,perq,modi,lun; lbaint_t capacity; unsigned long blksz; ccb* pccb=(ccb *)&tempccb; if(mode==1) { printf("scanning bus for devices...\n"); } for(i=0;i<CONFIG_SYS_SCSI_MAX_DEVICE;i++) { scsi_dev_desc[i].target=0xff; scsi_dev_desc[i].lun=0xff; scsi_dev_desc[i].lba=0; scsi_dev_desc[i].blksz=0; scsi_dev_desc[i].type=DEV_TYPE_UNKNOWN; scsi_dev_desc[i].vendor[0]=0; scsi_dev_desc[i].product[0]=0; scsi_dev_desc[i].revision[0]=0; scsi_dev_desc[i].removable=FALSE; scsi_dev_desc[i].if_type=IF_TYPE_SCSI; scsi_dev_desc[i].dev=i; scsi_dev_desc[i].part_type=PART_TYPE_UNKNOWN; scsi_dev_desc[i].block_read=scsi_read; scsi_dev_desc[i].block_write = scsi_write; } scsi_max_devs=0; for(i=0;i<CONFIG_SYS_SCSI_MAX_SCSI_ID;i++) { pccb->target=i; for(lun=0;lun<CONFIG_SYS_SCSI_MAX_LUN;lun++) { pccb->lun=lun; pccb->pdata=(unsigned char *)&tempbuff; pccb->datalen=512; scsi_setup_inquiry(pccb); if(scsi_exec(pccb)!=TRUE) { if(pccb->contr_stat==SCSI_SEL_TIME_OUT) { debug ("Selection timeout ID %d\n",pccb->target); continue; /* selection timeout => assuming no device present */ } /* Device present at this target/lun * but may not be ready yet. */ scsi_print_error(pccb); continue; } perq=tempbuff[0]; modi=tempbuff[1]; if((perq & 0x1f)==0x1f) { continue; /* skip unknown devices */ } if((modi&0x80)==0x80) /* drive is removable */ scsi_dev_desc[scsi_max_devs].removable=TRUE; /* get info for this device */ scsi_ident_cpy((unsigned char *)&scsi_dev_desc[scsi_max_devs].vendor[0], &tempbuff[8], 8); scsi_ident_cpy((unsigned char *)&scsi_dev_desc[scsi_max_devs].product[0], &tempbuff[16], 16); scsi_ident_cpy((unsigned char *)&scsi_dev_desc[scsi_max_devs].revision[0], &tempbuff[32], 4); scsi_dev_desc[scsi_max_devs].target=pccb->target; scsi_dev_desc[scsi_max_devs].lun=pccb->lun; pccb->datalen=0; scsi_setup_test_unit_ready(pccb); if(scsi_exec(pccb)!=TRUE) { if(scsi_dev_desc[scsi_max_devs].removable==TRUE) { scsi_dev_desc[scsi_max_devs].type=perq; goto removable; } scsi_print_error(pccb); continue; } if (scsi_read_capacity(pccb, &capacity, &blksz)) { scsi_print_error(pccb); continue; } scsi_dev_desc[scsi_max_devs].lba=capacity; scsi_dev_desc[scsi_max_devs].blksz=blksz; scsi_dev_desc[scsi_max_devs].type=perq; init_part(&scsi_dev_desc[scsi_max_devs]); removable: if(mode==1) { printf (" Device %d: ", scsi_max_devs); dev_print(&scsi_dev_desc[scsi_max_devs]); } /* if mode */ scsi_max_devs++; } /* next LUN */ } if(scsi_max_devs>0) scsi_curr_dev=0; else scsi_curr_dev = -1; printf("Found %d device(s).\n", scsi_max_devs); }
/********************************************************************************* * (re)-scan the scsi bus and reports scsi device info * to the user if mode = 1 */ void scsi_scan(int mode) { unsigned char i,perq,modi,lun; lbaint_t capacity; unsigned long blksz; ccb* pccb=(ccb *)&tempccb; static int scsi_detected = 0; if (scsi_detected) { printf("** scsi detection can run only once - please"); printf(" reset board before running detection again **\n"); return; } scsi_detected = 1; if(mode==1) { printf("scanning bus for devices...\n"); } if (tempbuff == NULL) { tempbuff = memalign(ARCH_DMA_MINALIGN, 512); if (tempbuff == NULL) { if (mode == 1) printf("error: cannot allocate buffer\n"); return; } } for(i = 0; i < CONFIG_SYS_SCSI_MAX_DEVICE; i++) { scsi_dev_desc[i].target=0xff; scsi_dev_desc[i].lun=0xff; scsi_dev_desc[i].lba=0; scsi_dev_desc[i].blksz=0; scsi_dev_desc[i].log2blksz = LOG2_INVALID(typeof(scsi_dev_desc[i].log2blksz)); scsi_dev_desc[i].type=DEV_TYPE_UNKNOWN; scsi_dev_desc[i].vendor[0]=0; scsi_dev_desc[i].product[0]=0; scsi_dev_desc[i].revision[0]=0; scsi_dev_desc[i].removable=FALSE; scsi_dev_desc[i].if_type=IF_TYPE_SCSI; scsi_dev_desc[i].dev=i; scsi_dev_desc[i].part_type=PART_TYPE_UNKNOWN; scsi_dev_desc[i].block_read=scsi_read; scsi_dev_desc[i].block_write = scsi_write; } scsi_max_devs=0; for(i=0; i<CONFIG_SYS_SCSI_MAX_SCSI_ID; i++) { pccb->target=i; for(lun=0; lun<CONFIG_SYS_SCSI_MAX_LUN; lun++) { pccb->lun=lun; pccb->pdata = (unsigned char *)tempbuff; pccb->datalen=512; scsi_setup_inquiry(pccb); if(scsi_exec(pccb)!=TRUE) { if(pccb->contr_stat==SCSI_SEL_TIME_OUT) { debug ("Selection timeout ID %d\n",pccb->target); continue; /* selection timeout => assuming no device present */ } scsi_print_error(pccb); continue; } perq=tempbuff[0]; modi=tempbuff[1]; if((perq & 0x1f)==0x1f) { continue; /* skip unknown devices */ } if((modi&0x80)==0x80) /* drive is removable */ scsi_dev_desc[scsi_max_devs].removable=TRUE; /* get info for this device */ scsi_ident_cpy((unsigned char *)&scsi_dev_desc[scsi_max_devs].vendor[0], &tempbuff[8], 8); scsi_ident_cpy((unsigned char *)&scsi_dev_desc[scsi_max_devs].product[0], &tempbuff[16], 16); scsi_ident_cpy((unsigned char *)&scsi_dev_desc[scsi_max_devs].revision[0], &tempbuff[32], 4); scsi_dev_desc[scsi_max_devs].target=pccb->target; scsi_dev_desc[scsi_max_devs].lun=pccb->lun; pccb->datalen=0; scsi_setup_test_unit_ready(pccb); if(scsi_exec(pccb)!=TRUE) { if(scsi_dev_desc[scsi_max_devs].removable==TRUE) { scsi_dev_desc[scsi_max_devs].type=perq; goto removable; } scsi_print_error(pccb); continue; } if (scsi_read_capacity(pccb, &capacity, &blksz)) { scsi_print_error(pccb); continue; } scsi_dev_desc[scsi_max_devs].lba=capacity; scsi_dev_desc[scsi_max_devs].blksz=blksz; scsi_dev_desc[scsi_max_devs].log2blksz = LOG2(scsi_dev_desc[scsi_max_devs].blksz); scsi_dev_desc[scsi_max_devs].type=perq; init_part(&scsi_dev_desc[scsi_max_devs]); removable: if(mode==1) { printf (" Device %d: ", scsi_max_devs); dev_print(&scsi_dev_desc[scsi_max_devs]); } /* if mode */ scsi_max_devs++; } /* next LUN */ } if (scsi_max_devs > 0) scsi_curr_dev = 0; else scsi_curr_dev = -1; printf("Found %d device(s).\n", scsi_max_devs); setenv_ulong("scsidevs", scsi_max_devs); }