static int ips_send_drive_info_cmd(ips_command_t *command) { int error = 0; ips_softc_t *sc = command->sc; ips_cmd_status_t *status = command->arg; ips_drive_info_t *driveinfo; if (bus_dma_tag_create( /* parent */ sc->adapter_dmatag, /* alignemnt */ 1, /* boundary */ 0, /* lowaddr */ BUS_SPACE_MAXADDR_32BIT, /* highaddr */ BUS_SPACE_MAXADDR, /* filter */ NULL, /* filterarg */ NULL, /* maxsize */ IPS_DRIVE_INFO_LEN, /* numsegs */ 1, /* maxsegsize*/ IPS_DRIVE_INFO_LEN, /* flags */ 0, &command->data_dmatag) != 0) { printf("ips: can't alloc dma tag for drive status\n"); error = ENOMEM; goto exit; } if(bus_dmamem_alloc(command->data_dmatag, &command->data_buffer, BUS_DMA_NOWAIT, &command->data_dmamap)){ error = ENOMEM; goto exit; } command->callback = ips_wakeup_callback; asleep(status, 0, "ips", 10*hz); bus_dmamap_load(command->data_dmatag, command->data_dmamap, command->data_buffer,IPS_DRIVE_INFO_LEN, ips_drive_info_callback, command, BUS_DMA_NOWAIT); if (await(-1, -1)) error = ETIMEDOUT; else { bus_dmamap_sync(command->data_dmatag, command->data_dmamap, BUS_DMASYNC_POSTREAD); driveinfo = command->data_buffer; memcpy(sc->drives, driveinfo->drives, sizeof(ips_drive_t) * 8); sc->drivecount = driveinfo->drivecount; device_printf(sc->dev, "logical drives: %d\n",sc->drivecount); } bus_dmamap_unload(command->data_dmatag, command->data_dmamap); exit: /* I suppose I should clean up my memory allocations */ bus_dmamem_free(command->data_dmatag, command->data_buffer, command->data_dmamap); bus_dma_tag_destroy(command->data_dmatag); ips_insert_free_cmd(sc, command); return error; }
int sync_tlock(lock_t* p, const char *wname, int timeout){ if(!wname) wname = "lock"; while(1){ asleep( (void*)p, wname ); if( !sync_lockedp(p) && sync_try_lock(p) ){ aunsleep(); return 1; } int t = await( -1, timeout ); if( t ) break; /* time out */ } return 0; }
static int ips_read_nvram(ips_command_t *command){ int error = 0; ips_softc_t *sc = command->sc; ips_cmd_status_t *status = command->arg; if (bus_dma_tag_create( /* parent */ sc->adapter_dmatag, /* alignemnt */ 1, /* boundary */ 0, /* lowaddr */ BUS_SPACE_MAXADDR_32BIT, /* highaddr */ BUS_SPACE_MAXADDR, /* filter */ NULL, /* filterarg */ NULL, /* maxsize */ IPS_NVRAM_PAGE_SIZE, /* numsegs */ 1, /* maxsegsize*/ IPS_NVRAM_PAGE_SIZE, /* flags */ 0, &command->data_dmatag) != 0) { printf("ips: can't alloc dma tag for nvram\n"); error = ENOMEM; goto exit; } if(bus_dmamem_alloc(command->data_dmatag, &command->data_buffer, BUS_DMA_NOWAIT, &command->data_dmamap)){ error = ENOMEM; goto exit; } command->callback = ips_write_nvram; asleep(status, 0, "ips", 0); bus_dmamap_load(command->data_dmatag, command->data_dmamap, command->data_buffer,IPS_NVRAM_PAGE_SIZE, ips_read_nvram_callback, command, BUS_DMA_NOWAIT); if (await(-1, -1)) error = ETIMEDOUT; else { bus_dmamap_sync(command->data_dmatag, command->data_dmamap, BUS_DMASYNC_POSTWRITE); } bus_dmamap_unload(command->data_dmatag, command->data_dmamap); exit: bus_dmamem_free(command->data_dmatag, command->data_buffer, command->data_dmamap); bus_dma_tag_destroy(command->data_dmatag); ips_insert_free_cmd(sc, command); return error; }
/* Below is a pair of functions for making sure data is safely * on disk by flushing the adapter's cache. */ static int ips_send_flush_cache_cmd(ips_command_t *command) { ips_softc_t *sc = command->sc; ips_cmd_status_t *status = command->arg; ips_generic_cmd *command_struct; PRINTF(10,"ips test: got a command, building flush command\n"); command->callback = ips_wakeup_callback; command_struct = (ips_generic_cmd *)command->command_buffer; command_struct->command = IPS_CACHE_FLUSH_CMD; command_struct->id = command->id; bus_dmamap_sync(sc->command_dmatag, command->command_dmamap, BUS_DMASYNC_PREWRITE); asleep(status, 0, "slush2", 0); sc->ips_issue_cmd(command); await(-1, -1); ips_insert_free_cmd(sc, command); return 0; }
static int ips_send_error_table_cmd(ips_command_t *command) { ips_softc_t *sc = command->sc; ips_cmd_status_t *status = command->arg; ips_generic_cmd *command_struct; PRINTF(10,"ips test: got a command, building errortable command\n"); command->callback = ips_wakeup_callback; command_struct = (ips_generic_cmd *)command->command_buffer; command_struct->command = IPS_ERROR_TABLE_CMD; command_struct->id = command->id; command_struct->reserve2 = IPS_CSL; bus_dmamap_sync(sc->command_dmatag, command->command_dmamap, BUS_DMASYNC_PREWRITE); asleep(status, 0, "ipsetc", 0); sc->ips_issue_cmd(command); await(-1, -1); ips_insert_free_cmd(sc, command); return 0; }
/* output a char */ int serial_putchar(FILE *f, char ch){ /* outputs a char over the serial line */ int i; struct Com *p; int plx; p = (struct Com*)f->d; USART_TypeDef *addr = p->addr; #ifdef USE_PROC if( f->flags & F_NONBLOCK ){ while(1){ plx = spltty(); if( addr->ISR & SR_TXE ) break; } }else{ while(1){ plx = splproc(); asleep( addr, "com/o" ); if( addr->ISR & SR_TXE ) break; addr->CR1 |= 0x80; /* enable TXE irq */ await( -1, 100000 ); if( addr->ISR & SR_TXE ) break; } aunsleep(); } #else while(1){ plx = spltty(); if( addr->ISR & SR_TXE ) break; } #endif addr->TDR = ch; splx(plx); return 1; }
static int ips_send_ffdc_reset_cmd(ips_command_t *command) { ips_softc_t *sc = command->sc; ips_cmd_status_t *status = command->arg; ips_adapter_ffdc_cmd *command_struct; PRINTF(10,"ips test: got a command, building ffdc reset command\n"); command->callback = ips_wakeup_callback; command_struct = (ips_adapter_ffdc_cmd *)command->command_buffer; command_struct->command = IPS_FFDC_CMD; command_struct->id = command->id; command_struct->reset_count = sc->ffdc_resetcount; command_struct->reset_type = 0x0; ips_ffdc_settime(command_struct, sc->ffdc_resettime.tv_sec); bus_dmamap_sync(sc->command_dmatag, command->command_dmamap, BUS_DMASYNC_PREWRITE); asleep(status, 0, "ips_ffdc", 0); sc->ips_issue_cmd(command); await(-1, -1); ips_insert_free_cmd(sc, command); return 0; }
void Player::move(char c){ //heal the player if(trueWithProbability(.1)){ if( health() < max_health) setHealth(health()+1); } //check if the player is asleep if( asleep() < 1){ switch (c) { case 'h': //if there is a monster above the player attack it if(checkForMonster("UP")) attack(dungeon()->returnMonster(row(), col()-1)); //if the next space is something the player can move onto(empty space or item) then move else if(dungeon()->gameGrid[row()][col()-1] == ' '|| dungeon()->gameGrid[row()][col()-1] == '>' || dungeon()->gameGrid[row()][col()-1] == '&') setCol(col()-1); break; case 'l': //if there is a monster below the player attack it if(checkForMonster("DOWN")) attack(dungeon()->returnMonster(row(), col()+1)); else if(dungeon()->gameGrid[row()][col()+1] == ' ' || dungeon()->gameGrid[row()][col()+1] == '>'|| dungeon()->gameGrid[row()][col()-1] == '&') setCol(col()+1); break; case 'k': //if there is a monster to the left of the player attack it if(checkForMonster("LEFT")) attack(dungeon()->returnMonster(row()-1, col())); else if(dungeon()->gameGrid[row()-1][col()] == ' '|| dungeon()->gameGrid[row()-1][col()] == '>'|| dungeon()->gameGrid[row()][col()-1] == '&') setRow(row()-1); break; case 'j': //if there is a monster to the right of the player attack it if(checkForMonster("RIGHT")) attack(dungeon()->returnMonster(row()+1, col())); else if(dungeon()->gameGrid[row()+1][col()] == ' '|| dungeon()->gameGrid[row()+1][col()] == '>'|| dungeon()->gameGrid[row()][col()-1] == '&') setRow(row() +1); break; default: break; } } else{ //if the player is asleep then each move reduce his sleepTime by 1 point setSleep(asleep()-1); dungeon()->action_vector.push_back("Player is asleep"); } }