/* calculate the center of mass for a group gnx = the number of atoms/molecules index = the indices xcur = the current coordinates xprev = the previous coordinates box = the box matrix atoms = atom data (for mass) com(output) = center of mass */ static void calc_com(gmx_bool bMol, int gnx, atom_id index[], rvec xcur[],rvec xprev[],matrix box, t_atoms *atoms, rvec com) { int i,m,ind; real mass; double tmass; dvec sx; clear_dvec(sx); tmass = 0; mass = 1; prep_data(bMol, gnx, index, xcur, xprev, box); for(i=0; (i<gnx); i++) { if (bMol) ind = i; else ind = index[i]; mass = atoms->atom[ind].m; for(m=0; m<DIM; m++) sx[m] += mass*xcur[ind][m]; tmass += mass; } for(m=0; m<DIM; m++) com[m] = sx[m]/tmass; }
void Test_sdcard(void) { if (Sdio_verification!=FALSE) { #ifdef ENABLE_WRITE_MODE /* Write a single sector of data (512 bytes) */ if (!sdcardinfo.sdck_wp()) { prep_data(0, 1); /* Warning: This may corrupt SD card data! */ if (sdmmc_write_blocks((void *) lbuff, 1, 1) == 0) { errorc = -3; goto error_exit1; } /* Wait for write to finish (at the card) */ wait_for_program_finish(); } #endif memset(lbuff, 0, sizeof(lbuff)); /* Read a single sector of data (512 bytes) */ if (sdmmc_read_blocks((void *) lbuff, 1, 1) == 0) { errorc = -4; goto error_exit1; } #ifdef ENABLE_WRITE_MODE /* Verify data and halt if an error occurs */ if (!sdcardinfo.sdck_wp()) { if (verify_data(1, 0, 1) == 0) { errorc = -5; goto error_exit1; } lpc_printf("SD card Verified!"); Sdio_verification = TRUE; goto exit1; } #endif exit1: return; } error_exit1: lpc_printf("\n\rSD Card read/write operation not succeeded."); Sdio_verification = FALSE; }
/** * Store the qstate.return_msg in extcache for key qstate.info */ static void cachedb_extcache_store(struct module_qstate* qstate, struct cachedb_env* ie) { char key[(CACHEDB_HASHSIZE/8)*2+1]; calc_hash(qstate, key, sizeof(key)); /* prepare data in scratch buffer */ if(!prep_data(qstate, qstate->env->scratch_buffer)) return; /* call backend */ (*ie->backend->store)(qstate->env, ie, key, sldns_buffer_begin(qstate->env->scratch_buffer), sldns_buffer_limit(qstate->env->scratch_buffer)); }
/*********************************************************************//** * @brief Main SDIO program body * @param[in] None * @return int **********************************************************************/ void Sdio_init(void) { uint32_t dms, sdio_clk; int32_t loops, blk; uint8_t buf[50]; errorc = 1; /* Configure the IO's for the LEDs */ /* Setup muxing for SD interface */ /*Xplorer*/ scu_pinmux(0x1 ,11 , SDFASTINOUTPIN, FUNC7); /* P1.11 SDIO D2 */ scu_pinmux(0x1 ,10 , SDFASTINOUTPIN, FUNC7); /* P1.10 SDIO D1 */ scu_pinmux(0x1 ,9 , SDFASTINOUTPIN, FUNC7); /* P1.9 SDIO D0 */ scu_pinmux(0x1 ,6, SDFASTINOUTPIN, FUNC7); /* P1.6 SDIO command */ scu_pinmux(0x1 ,12 , SDFASTINOUTPIN, FUNC7); /* P1.12 SDIO D3 */ LPC_SCU->SFSCLK_2 = 0x04; /* CLK2 Enable*/ CGU_EntityConnect(CGU_CLKSRC_PLL1, CGU_BASE_SDIO); /* Generate interrupt @ 100 Hz */ /* The SDIO driver needs to know the SDIO clock rate */ sdio_clk = CGU_GetPCLKFrequency(CGU_PERIPHERAL_SDIO); /* This init sdio with sdio_clk */ sdif_init(sdio_clk, sdmmc_irq); /* Wait for a card to be inserted (note CD is not on the SDMMC power rail and can be polled without enabling SD slot power */ /* Allow some time for the power supply to settle and the card to fully seat in the slot */ dms = u32Milliseconds + 250; while (dms > u32Milliseconds); /* Enumerate the card once detected. Note this function may block for a little while. */ if (!sdmmc_acquire(sdmmc_setup_wakeup, sdmmc_irq_driven_wait, sdmmc_waitms, &sdcardinfo)) { errorc = -1; goto error_exit; } lpc_printf("SD card detected and initialized..!\r\n"); /* Setup card specific callbacks - use driver functions, but these can be changed to custom functions or unique functions per slot. These aren't used in the drivers, so setup of these is optional, but they are setup here to be complete. */ sdcardinfo.sdck_det = sdif_card_ndetect; sdcardinfo.sdck_wp = sdif_card_wp_on; sdcardinfo.sd_setpow = sdif_power_onoff; sdcardinfo.sd_setrst = sdif_reset; memset(lbuff, 0, sizeof(lbuff)); if (sdmmc_read_blocks((void *) lbuff, 0, 0) == 0) { errorc = -2; goto error_exit; } #ifdef ENABLE_WRITE_MODE lpc_printf("Writing data to sector 1 of SD card and verifying:\r\n"); /* Write a single sector of data (512 bytes) */ if (!sdcardinfo.sdck_wp()) { prep_data(0, 1); /* Warning: This may corrupt SD card data! */ if (sdmmc_write_blocks((void *) lbuff, 1, 1) == 0) { errorc = -3; goto error_exit; } /* Wait for write to finish (at the card) */ wait_for_program_finish(); } #endif memset(lbuff, 0, sizeof(lbuff)); /* Read a single sector of data (512 bytes) */ if (sdmmc_read_blocks((void *) lbuff, 1, 1) == 0) { errorc = -4; goto error_exit; } #ifdef ENABLE_WRITE_MODE /* Verify data and halt if an error occurs */ if (!sdcardinfo.sdck_wp()) { if (verify_data(1, 0, 1) == 0) { errorc = -5; goto error_exit; } lpc_printf("Verified!\r\n"); } #endif #ifdef USE_MULTPLE_TRANSFER #ifdef ENABLE_WRITE_MODE lpc_printf("Writing data in Multitransfer mode and verifying:\r\n"); /* Write data using multiple sector write */ if (!sdcardinfo.sdck_wp()) { prep_data(0x10, 3); /* Warning: This may corrupt SD card data! */ if (sdmmc_write_blocks((void *) lbuff, 1, MULT_XFER_MAX_SECTORS) == 0) { errorc = -6; goto error_exit; } wait_for_program_finish(); } #endif memset(lbuff, 0, sizeof(lbuff)); /* Read data using multiple sector read */ if (sdmmc_read_blocks((void *) lbuff, 1, MULT_XFER_MAX_SECTORS) == 0) { errorc = -7; goto error_exit; } #ifdef ENABLE_WRITE_MODE /* Verify data and halt if an error occurs */ if (!sdcardinfo.sdck_wp()) { if (verify_data(MULT_XFER_MAX_SECTORS, 0x10, 3) == 0) { errorc = -8; goto error_exit; } lpc_printf("Verified!\r\n"); } #endif lpc_printf("measure continuous read speed...\r\n"); tstartr = u32Milliseconds; loops = 1000; blk = 64; while (loops-- > 0) { if (sdmmc_read_blocks((void *) lbuff, blk, (blk + MULT_XFER_MAX_SECTORS - 1)) == 0) { errorc = -8; goto error_exit; } blk += MULT_XFER_MAX_SECTORS; } tstopr = u32Milliseconds; memset(buf, 0, sizeof(buf)); lpc_printf("read speed = %d kB/s\r\n", MULT_XFER_MAX_SECTORS*512*1000/(tstopr-tstartr)); #ifdef ENABLE_WRITE_MODE lpc_printf("measure continuous write speed...\r\n"); if (!sdcardinfo.sdck_wp()) { tstartw = u32Milliseconds; loops = 200; blk = 64; while (loops-- > 0) { if (sdmmc_write_blocks((void *) lbuff, blk, (blk + MULT_XFER_MAX_SECTORS - 1)) == 0) { errorc = -9; goto error_exit; } blk += MULT_XFER_MAX_SECTORS; wait_for_program_finish(); } tstopw = u32Milliseconds; } memset(buf, 0, sizeof(buf)); lpc_printf("write speed = %d kB/s\r\n", MULT_XFER_MAX_SECTORS*512*200/(tstopw-tstartw)); #endif #endif goto exit; error_exit: lpc_printf("SD Card read/write operation not succeeded.\r\n"); Sdio_verification = FALSE; exit: return; }
/* this is the main loop for the correlation type functions * fx and nx are file pointers to things like read_first_x and * read_next_x */ int corr_loop(t_corr *curr, const char *fn, t_topology *top, int ePBC, gmx_bool bMol, int gnx[], atom_id *index[], t_calc_func *calc1, gmx_bool bTen, int *gnx_com, atom_id *index_com[], real dt, real t_pdb, rvec **x_pdb, matrix box_pdb, const output_env_t oenv) { rvec *x[2]; /* the coordinates to read */ rvec *xa[2]; /* the coordinates to calculate displacements for */ rvec com = {0}; real t, t_prev = 0; int natoms, i, j, cur = 0, maxframes = 0; t_trxstatus *status; #define prev (1-cur) matrix box; gmx_bool bFirst; gmx_rmpbc_t gpbc = NULL; natoms = read_first_x(oenv, &status, fn, &curr->t0, &(x[cur]), box); #ifdef DEBUG fprintf(stderr, "Read %d atoms for first frame\n", natoms); #endif if ((gnx_com != NULL) && natoms < top->atoms.nr) { fprintf(stderr, "WARNING: The trajectory only contains part of the system (%d of %d atoms) and therefore the COM motion of only this part of the system will be removed\n", natoms, top->atoms.nr); } snew(x[prev], natoms); if (bMol) { curr->ncoords = curr->nmol; snew(xa[0], curr->ncoords); snew(xa[1], curr->ncoords); } else { curr->ncoords = natoms; xa[0] = x[0]; xa[1] = x[1]; } bFirst = TRUE; t = curr->t0; if (x_pdb) { *x_pdb = NULL; } if (bMol) { gpbc = gmx_rmpbc_init(&top->idef, ePBC, natoms); } /* the loop over all frames */ do { if (x_pdb && ((bFirst && t_pdb < t) || (!bFirst && t_pdb > t - 0.5*(t - t_prev) && t_pdb < t + 0.5*(t - t_prev)))) { if (*x_pdb == NULL) { snew(*x_pdb, natoms); } for (i = 0; i < natoms; i++) { copy_rvec(x[cur][i], (*x_pdb)[i]); } copy_mat(box, box_pdb); } /* check whether we've reached a restart point */ if (bRmod(t, curr->t0, dt)) { curr->nrestart++; srenew(curr->x0, curr->nrestart); snew(curr->x0[curr->nrestart-1], curr->ncoords); srenew(curr->com, curr->nrestart); srenew(curr->n_offs, curr->nrestart); srenew(curr->lsq, curr->nrestart); snew(curr->lsq[curr->nrestart-1], curr->nmol); for (i = 0; i < curr->nmol; i++) { curr->lsq[curr->nrestart-1][i] = gmx_stats_init(); } if (debug) { fprintf(debug, "Extended data structures because of new restart %d\n", curr->nrestart); } } /* create or extend the frame-based arrays */ if (curr->nframes >= maxframes-1) { if (maxframes == 0) { for (i = 0; (i < curr->ngrp); i++) { curr->ndata[i] = NULL; curr->data[i] = NULL; if (bTen) { curr->datam[i] = NULL; } } curr->time = NULL; } maxframes += 10; for (i = 0; (i < curr->ngrp); i++) { srenew(curr->ndata[i], maxframes); srenew(curr->data[i], maxframes); if (bTen) { srenew(curr->datam[i], maxframes); } for (j = maxframes-10; j < maxframes; j++) { curr->ndata[i][j] = 0; curr->data[i][j] = 0; if (bTen) { clear_mat(curr->datam[i][j]); } } } srenew(curr->time, maxframes); } /* set the time */ curr->time[curr->nframes] = t - curr->t0; /* for the first frame, the previous frame is a copy of the first frame */ if (bFirst) { std::memcpy(xa[prev], xa[cur], curr->ncoords*sizeof(xa[prev][0])); bFirst = FALSE; } /* make the molecules whole */ if (bMol) { gmx_rmpbc(gpbc, natoms, box, x[cur]); } /* calculate the molecules' centers of masses and put them into xa */ if (bMol) { calc_mol_com(gnx[0], index[0], &top->mols, &top->atoms, x[cur], xa[cur]); } /* first remove the periodic boundary condition crossings */ for (i = 0; i < curr->ngrp; i++) { prep_data(bMol, gnx[i], index[i], xa[cur], xa[prev], box); } /* calculate the center of mass */ if (gnx_com) { prep_data(bMol, gnx_com[0], index_com[0], xa[cur], xa[prev], box); calc_com(bMol, gnx_com[0], index_com[0], xa[cur], xa[prev], box, &top->atoms, com); } /* loop over all groups in index file */ for (i = 0; (i < curr->ngrp); i++) { /* calculate something useful, like mean square displacements */ calc_corr(curr, i, gnx[i], index[i], xa[cur], (gnx_com != NULL), com, calc1, bTen); } cur = prev; t_prev = t; curr->nframes++; } while (read_next_x(oenv, status, &t, x[cur], box)); fprintf(stderr, "\nUsed %d restart points spaced %g %s over %g %s\n\n", curr->nrestart, output_env_conv_time(oenv, dt), output_env_get_time_unit(oenv), output_env_conv_time(oenv, curr->time[curr->nframes-1]), output_env_get_time_unit(oenv) ); if (bMol) { gmx_rmpbc_done(gpbc); } close_trj(status); return natoms; }