int json_copy_to_object(JsonNode * obj, JsonNode * object_or_array, int clobber) { JsonNode *node; if (obj->tag != JSON_OBJECT && obj->tag != JSON_ARRAY) return (FALSE); json_foreach(node, object_or_array) { if (!clobber & (json_find_member(obj, node->key) != NULL)) continue; /* Don't clobber existing keys */ if (obj->tag == JSON_OBJECT) { if (node->tag == JSON_STRING) json_append_member(obj, node->key, json_mkstring(node->string_)); else if (node->tag == JSON_NUMBER) json_append_member(obj, node->key, json_mknumber(node->number_)); else if (node->tag == JSON_BOOL) json_append_member(obj, node->key, json_mkbool(node->bool_)); else if (node->tag == JSON_NULL) json_append_member(obj, node->key, json_mknull()); else fprintf(stderr, "PANIC: unhandled JSON type %d\n", node->tag); } else if (obj->tag == JSON_ARRAY) { if (node->tag == JSON_STRING) json_append_element(obj, json_mkstring(node->string_)); if (node->tag == JSON_NUMBER) json_append_element(obj, json_mknumber(node->number_)); if (node->tag == JSON_BOOL) json_append_element(obj, json_mkbool(node->bool_)); if (node->tag == JSON_NULL) json_append_element(obj, json_mknull()); } } return (TRUE); }
int main(void) { JsonNode *node; (void) chomp; plan_tests(49); ok1(json_find_element(NULL, 0) == NULL); ok1(json_find_member(NULL, "") == NULL); ok1(json_first_child(NULL) == NULL); node = json_mknull(); should_be(node, "null"); json_delete(node); node = json_mkbool(false); should_be(node, "false"); json_delete(node); node = json_mkbool(true); should_be(node, "true"); json_delete(node); test_string(); test_number(); test_array(); test_object(); return exit_status(); }
JsonNode *boolnode(char *str) { if (strlen(str) == 0) { return json_mknull(); } if (tolower((unsigned char) *str) == 't') { return json_mkbool(1); } return json_mkbool(atoi(str)); }
static void log_failure_mkjson(void *json, const char *field_name, size_t field_namelen, unsigned int field_type, const void *field_value) { JsonNode *field = NULL; switch (field_type) { case LOG_FAILURE_FIELD_TYPE_STRING: field = json_mkstring((const char *) field_value); break; case LOG_FAILURE_FIELD_TYPE_NUMBER: field = json_mknumber(*((double *) field_value)); break; case LOG_FAILURE_FIELD_TYPE_BOOLEAN: field = json_mkbool(*((bool *) field_value)); break; default: (void) pr_log_writefile(log_failure_logfd, MOD_LOG_FAILURE_VERSION, "unsupported field type: %u", field_type); } if (field != NULL) { json_append_member(json, field_name, field); } }
JsonNode* oCharBool(const char* key, bool b) { JsonNode* oRet = json_mkobject(); json_append_member(oRet, key, json_mkbool(b)); return oRet; }
/** @internal Recursive Lua/JSON serialization. */ static JsonNode *l_pack_elem(lua_State *L, int top) { switch(lua_type(L, top)) { case LUA_TSTRING: return json_mkstring(lua_tostring(L, top)); case LUA_TNUMBER: return json_mknumber(lua_tonumber(L, top)); case LUA_TBOOLEAN: return json_mkbool(lua_toboolean(L, top)); case LUA_TTABLE: break; /* Table, iterate it. */ default: return json_mknull(); } /* Use absolute indexes here, as the table may be nested. */ JsonNode *node = NULL; lua_pushnil(L); while(lua_next(L, top) != 0) { JsonNode *val = l_pack_elem(L, top + 2); const bool no_key = lua_isnumber(L, top + 1); if (!node) { node = no_key ? json_mkarray() : json_mkobject(); if (!node) { return NULL; } } /* Insert to array/table */ if (no_key) { json_append_element(node, val); } else { json_append_member(node, lua_tostring(L, top + 1), val); } lua_pop(L, 1); } return node; }
JsonNode *vnode(char *str, int flags) { if (strlen(str) == 0) { return json_mknull(); } /* If str begins with a double quote, keep it a string */ if (*str == '"') { char *bp = str + strlen(str) - 1; if (bp > str && *bp == '"') *bp = 0; /* Chop closing double quote */ return json_mkstring(str + 1); } char *endptr; double num = strtod(str, &endptr); if (!*endptr && isfinite(num)) { return json_mknumber(num); } if (!(flags & FLAG_NOBOOL)) { if (strcmp(str, "true") == 0) { return json_mkbool(true); } else if (strcmp(str, "false") == 0) { return json_mkbool(false); } } if (*str == '{' || *str == '[') { JsonNode *obj = json_decode(str); if (obj == NULL) { /* JSON cannot be decoded; return the string */ // fprintf(stderr, "Cannot decode JSON from %s\n", str); obj = json_mkstring(str); } return (obj); } return json_mkstring(str); }
void csv_output(JsonNode *json, output_type otype, JsonNode *fields) { JsonNode *node, *inttypes; JsonNode *arr, *one, *j; short virgin = 1; /* Prime the inttypes object with types we consider "integer" */ inttypes = json_mkobject(); json_append_member(inttypes, "batt", json_mkbool(1)); json_append_member(inttypes, "vel", json_mkbool(1)); json_append_member(inttypes, "cog", json_mkbool(1)); json_append_member(inttypes, "tst", json_mkbool(1)); json_append_member(inttypes, "alt", json_mkbool(1)); json_append_member(inttypes, "dist", json_mkbool(1)); json_append_member(inttypes, "trip", json_mkbool(1)); arr = json_find_member(json, "locations"); json_foreach(one, arr) { /* Headings */ if (virgin) { virgin = !virgin; if (fields) { json_foreach(node, fields) { printf("%s%c", node->string_, (node->next) ? ',' : '\n'); } } else { json_foreach(j, one) { if (j->key) printf("%s%c", j->key, (j->next) ? ',' : '\n'); } } }
// Convert a Lua value into a JsonNode structure. static JsonNode *LuaValueToJson(lua_State *L) { assert(L); JsonNode *json = NULL; int top = lua_gettop(L); int type = lua_type(L, top); switch (type) { case LUA_TTABLE: // Check if the current value is a reference cycle if (IsRefCycle(L, JSON_REF_TABLE_IDX, top)) { luaL_error(L, "reference cycle detected in table"); return NULL; } // Add a reference to our tracking table AddTableRef(L, JSON_REF_TABLE_IDX, top); // Convert the table to JSON json = LuaTableToJsonPrivate(L, top); // Remove the table reference again after we unwind RemoveTableRef(L, JSON_REF_TABLE_IDX, top); break; case LUA_TSTRING: json = json_mkstring(luaL_tolstring(L, top, NULL)); lua_pop(L, 1); break; case LUA_TNUMBER: { int isnum; lua_Number num = lua_tonumberx(L, top, &isnum); if (isnum) { json = json_mknumber(num); } break; } case LUA_TBOOLEAN: json = json_mkbool((bool)lua_toboolean(L, top)); break; case LUA_TNIL: json = json_mknull(); break; default: break; } return json; }
/* Copy the node into obj */ int json_copy_element_to_object(JsonNode *obj, char *key, JsonNode *node) { if (obj->tag != JSON_OBJECT || node == NULL) return (FALSE); if (node->tag == JSON_STRING) json_append_member(obj, key, json_mkstring(node->string_)); else if (node->tag == JSON_NUMBER) json_append_member(obj, key, json_mknumber(node->number_)); else if (node->tag == JSON_BOOL) json_append_member(obj, key, json_mkbool(node->bool_)); else if (node->tag == JSON_NULL) json_append_member(obj, key, json_mknull()); return (TRUE); }
int ChinjScan(int crateNum, uint32_t slotMask, uint32_t channelMask, float frequency, int gtDelay, int pedWidth, int numPedestals, float upper, float lower, int qSelect, int pedOn, int updateDB, int finalTest) { lprintf("*** Starting Charge Injection Test *****\n"); float *qhls; float *qhss; float *qlxs; float *tacs; int *scan_errors; int errors = 0; int count,crateID,ch,cell,num_events; uint16_t dacvalue; uint32_t *pmt_buffer,*pmt_iter; struct pedestal *ped; uint32_t result, select_reg; uint32_t default_ch_mask; int chinj_err[16]; pmt_buffer = (uint32_t *) malloc( 0x20000*sizeof(uint32_t)); ped = (struct pedestal *) malloc( 32 * sizeof(struct pedestal)); qhls = (float *) malloc(32*16*2*26*sizeof(float)); qhss = (float *) malloc(32*16*2*26*sizeof(float)); qlxs = (float *) malloc(32*16*2*26*sizeof(float)); tacs = (float *) malloc(32*16*2*26*sizeof(float)); scan_errors = (int *) malloc(32*16*2*26*sizeof(int)); if (pmt_buffer == NULL || ped == NULL || qhls == NULL || qhss == NULL || qlxs == NULL || tacs == NULL || scan_errors == NULL){ lprintf("Problem mallocing! Exiting\n"); if (pmt_buffer != NULL) free(pmt_buffer); if (ped != NULL) free(ped); if (qhls != NULL) free(qhls); if (qhss != NULL) free(qhss); if (qlxs != NULL) free(qlxs); if (tacs != NULL) free(tacs); if (scan_errors != NULL) free(scan_errors); return -1; } for (int i=0;i<16;i++){ chinj_err[i] = 0; for (int j=0;j<32;j++) for (int k=0;k<26;k++) for (int l=0;l<2;l++){ qhls[k*16*32*2+i*32*2+j*2+l] = 0; qhss[k*16*32*2+i*32*2+j*2+l] = 0; qlxs[k*16*32*2+i*32*2+j*2+l] = 0; tacs[k*16*32*2+i*32*2+j*2+l] = 0; scan_errors[k*16*32*2+i*32*2+j*2+l] = 0; } } try { for (int dac_iter=0;dac_iter<26;dac_iter++){ dacvalue = dac_iter*10; for (int slot_iter = 0; slot_iter < 16; slot_iter ++){ if ((0x1 << slot_iter) & slotMask){ select_reg = FEC_SEL*slot_iter; xl3s[crateNum]->RW(CMOS_CHIP_DISABLE_R + select_reg + WRITE_REG,0xFFFFFFFF,&result); xl3s[crateNum]->RW(GENERAL_CSR_R + select_reg + WRITE_REG,0x2,&result); xl3s[crateNum]->RW(GENERAL_CSR_R + select_reg + WRITE_REG,0x0,&result); xl3s[crateNum]->RW(CMOS_CHIP_DISABLE_R + select_reg + WRITE_REG,~channelMask,&result); } } xl3s[crateNum]->DeselectFECs(); //pt_printsend("Reset FECs\n"); errors = 0; errors += xl3s[crateNum]->LoadCrateAddr(slotMask); if (pedOn){ //pt_printsend("enabling pedestals.\n"); errors += xl3s[crateNum]->SetCratePedestals(slotMask, channelMask); } xl3s[crateNum]->DeselectFECs(); if (errors){ lprintf("error setting up FEC crate for pedestals. Exiting.\n"); free(pmt_buffer); free(ped); free(qhls); free(qhss); free(qlxs); free(tacs); free(scan_errors); return -1; } //setup charge injection xl3s[crateNum]->SetupChargeInjection(slotMask,channelMask,dacvalue); errors = mtc->SetupPedestals(0,pedWidth,gtDelay,DEFAULT_GT_FINE_DELAY,(0x1<<crateNum),(0x1<<crateNum)); if (errors){ lprintf("Error setting up MTC for pedestals. Exiting.\n"); mtc->UnsetPedCrateMask(MASKALL); mtc->UnsetGTCrateMask(MASKALL); free(pmt_buffer); free(ped); free(qhls); free(qhss); free(qlxs); free(tacs); free(scan_errors); return -1; } // send the softgts mtc->MultiSoftGT(numPedestals*16); // LOOP OVER SLOTS for (int slot_iter = 0; slot_iter < 16; slot_iter ++){ if ((0x1<<slot_iter) & slotMask){ // initialize pedestal struct for (int i=0;i<32;i++){ //pedestal struct ped[i].channelnumber = i; //channel numbers start at 0!!! ped[i].per_channel = 0; for (int j=0;j<16;j++){ ped[i].thiscell[j].cellno = j; ped[i].thiscell[j].per_cell = 0; ped[i].thiscell[j].qlxbar = 0; ped[i].thiscell[j].qlxrms = 0; ped[i].thiscell[j].qhlbar = 0; ped[i].thiscell[j].qhlrms = 0; ped[i].thiscell[j].qhsbar = 0; ped[i].thiscell[j].qhsrms = 0; ped[i].thiscell[j].tacbar = 0; ped[i].thiscell[j].tacrms = 0; } } ///////////////////// // READOUT BUNDLES // ///////////////////// count = xl3s[crateNum]->ReadOutBundles(slot_iter, pmt_buffer, numPedestals*32*16,1); //check for readout errors if (count <= 0){ lprintf("there was an error in the count!\n"); lprintf("Errors reading out MB(%2d) (errno %i)\n", slot_iter, count); errors+=1; continue; }else{ //pt_printsend("MB(%2d): %5d bundles read out.\n", slot_iter, count); } if (count < numPedestals*32*16) errors += 1; //process data pmt_iter = pmt_buffer; for (int i=0;i<count;i++){ crateID = (int) UNPK_CRATE_ID(pmt_iter); if (crateID != crateNum){ lprintf("Invalid crate ID seen! (crate ID %2d, bundle %2i)\n", crateID, i); pmt_iter+=3; continue; } ch = (int) UNPK_CHANNEL_ID(pmt_iter); cell = (int) UNPK_CELL_ID(pmt_iter); ped[ch].thiscell[cell].qlxbar += (double) MY_UNPK_QLX(pmt_iter); ped[ch].thiscell[cell].qhsbar += (double) UNPK_QHS(pmt_iter); ped[ch].thiscell[cell].qhlbar += (double) UNPK_QHL(pmt_iter); ped[ch].thiscell[cell].tacbar += (double) UNPK_TAC(pmt_iter); ped[ch].thiscell[cell].qlxrms += pow((double) MY_UNPK_QLX(pmt_iter),2.0); ped[ch].thiscell[cell].qhsrms += pow((double) UNPK_QHS(pmt_iter),2.0); ped[ch].thiscell[cell].qhlrms += pow((double) UNPK_QHL(pmt_iter),2.0); ped[ch].thiscell[cell].tacrms += pow((double) UNPK_TAC(pmt_iter),2.0); ped[ch].per_channel++; ped[ch].thiscell[cell].per_cell++; pmt_iter += 3; //increment pointer } // do final step // final step of calculation for (int i=0;i<32;i++){ if (ped[i].per_channel > 0){ for (int j=0;j<16;j++){ num_events = ped[i].thiscell[j].per_cell; //don't do anything if there is no data here or n=1 since //that gives 1/0 below. if (num_events > 1){ // now x_avg = sum(x) / N, so now xxx_bar is calculated ped[i].thiscell[j].qlxbar /= num_events; ped[i].thiscell[j].qhsbar /= num_events; ped[i].thiscell[j].qhlbar /= num_events; ped[i].thiscell[j].tacbar /= num_events; // now x_rms^2 = n/(n-1) * (<xxx^2>*N/N - xxx_bar^2) ped[i].thiscell[j].qlxrms = num_events / (num_events -1) * ( ped[i].thiscell[j].qlxrms / num_events - pow( ped[i].thiscell[j].qlxbar, 2.0)); ped[i].thiscell[j].qhlrms = num_events / (num_events -1) * ( ped[i].thiscell[j].qhlrms / num_events - pow( ped[i].thiscell[j].qhlbar, 2.0)); ped[i].thiscell[j].qhsrms = num_events / (num_events -1) * ( ped[i].thiscell[j].qhsrms / num_events - pow( ped[i].thiscell[j].qhsbar, 2.0)); ped[i].thiscell[j].tacrms = num_events / (num_events -1) * ( ped[i].thiscell[j].tacrms / num_events - pow( ped[i].thiscell[j].tacbar, 2.0)); // finally x_rms = sqrt(x_rms^2) ped[i].thiscell[j].qlxrms = sqrt(ped[i].thiscell[j].qlxrms); ped[i].thiscell[j].qhsrms = sqrt(ped[i].thiscell[j].qhsrms); ped[i].thiscell[j].qhlrms = sqrt(ped[i].thiscell[j].qhlrms); ped[i].thiscell[j].tacrms = sqrt(ped[i].thiscell[j].tacrms); }else{ ped[i].thiscell[j].qlxrms = 0; ped[i].thiscell[j].qhsrms = 0; ped[i].thiscell[j].qhlrms = 0; ped[i].thiscell[j].tacrms = 0; } } } } /////////////////// // PRINT RESULTS // /////////////////// lprintf("########################################################\n"); lprintf("Slot (%2d)\n", slot_iter); lprintf("########################################################\n"); for (int i = 0; i<32; i++){ //pt_printsend("Ch Cell # Qhl Qhs Qlx TAC\n"); for (int j=0;j<16;j++){ if (j == 0){ qhls[dac_iter*16*32*2+slot_iter*32*2+i*2] = ped[i].thiscell[j].qhlbar; qhss[dac_iter*16*32*2+slot_iter*32*2+i*2] = ped[i].thiscell[j].qhsbar; qlxs[dac_iter*16*32*2+slot_iter*32*2+i*2] = ped[i].thiscell[j].qlxbar; tacs[dac_iter*16*32*2+slot_iter*32*2+i*2] = ped[i].thiscell[j].tacbar; } if (j == 1){ qhls[dac_iter*16*32*2+slot_iter*32*2+i*2+1] = ped[i].thiscell[j].qhlbar; qhss[dac_iter*16*32*2+slot_iter*32*2+i*2+1] = ped[i].thiscell[j].qhsbar; qlxs[dac_iter*16*32*2+slot_iter*32*2+i*2+1] = ped[i].thiscell[j].qlxbar; tacs[dac_iter*16*32*2+slot_iter*32*2+i*2+1] = ped[i].thiscell[j].tacbar; } if (qSelect == 0){ if (ped[i].thiscell[j].qhlbar < lower || ped[i].thiscell[j].qhlbar > upper) { chinj_err[slot_iter]++; //pt_printsend(">>>>>Qhl Extreme Value<<<<<\n"); if (j%2 == 0) scan_errors[dac_iter*16*32*2+slot_iter*32*2+i*2]++; else scan_errors[dac_iter*16*32*2+slot_iter*32*2+i*2+1]++; } } else if (qSelect == 1){ if (ped[i].thiscell[j].qhsbar < lower || ped[i].thiscell[j].qhsbar > upper) { chinj_err[slot_iter]++; //pt_printsend(">>>>>Qhs Extreme Value<<<<<\n"); if (j%2 == 0) scan_errors[dac_iter*16*32*2+slot_iter*32*2+i*2]++; else scan_errors[dac_iter*16*32*2+slot_iter*32*2+i*2+1]++; } } else if (qSelect == 2){ if (ped[i].thiscell[j].qlxbar < lower || ped[i].thiscell[j].qlxbar > upper) { chinj_err[slot_iter]++; //pt_printsend(">>>>>Qlx Extreme Value<<<<<\n"); if (j%2 == 0) scan_errors[dac_iter*16*32*2+slot_iter*32*2+i*2]++; else scan_errors[dac_iter*16*32*2+slot_iter*32*2+i*2+1]++; } } if (j==0){ lprintf("%2d %3d %4d %6.1f %4.1f %6.1f %4.1f %6.1f %4.1f %6.1f %4.1f\n", dacvalue,i,ped[i].thiscell[j].per_cell, ped[i].thiscell[j].qhlbar, ped[i].thiscell[j].qhlrms, ped[i].thiscell[j].qhsbar, ped[i].thiscell[j].qhsrms, ped[i].thiscell[j].qlxbar, ped[i].thiscell[j].qlxrms, ped[i].thiscell[j].tacbar, ped[i].thiscell[j].tacrms); } } } } // end if slotmask } // end loop over slots // if (arg.q_select == 0){ // pt_printsend("Qhl lower, Upper bounds = %f %f\n",arg.chinj_lower,arg.chinj_upper); // pt_printsend("Number of Qhl overflows = %d\n",chinj_err[slot_iter]); // } // else if (arg.q_select == 1){ // pt_printsend("Qhs lower, Upper bounds = %f %f\n",arg.chinj_lower,arg.chinj_upper); // pt_printsend("Number of Qhs overflows = %d\n",chinj_err[slot_iter]); // } // else if (arg.q_select == 2){ // pt_printsend("Qlx lower, Upper bounds = %f %f\n",arg.chinj_lower,arg.chinj_upper); // pt_printsend("Number of Qlx overflows = %d\n",chinj_err[slot_iter]); // } //disable trigger enables mtc->UnsetPedCrateMask(MASKALL); mtc->UnsetGTCrateMask(MASKALL); //unset pedestalenable errors += xl3s[crateNum]->SetCratePedestals(slotMask, 0x0); xl3s[crateNum]->DeselectFECs(); } // end loop over dacvalue free(pmt_buffer); free(ped); // lets update this database if (updateDB){ lprintf("updating the database\n"); for (int i=0;i<16;i++) { if ((0x1<<i) & slotMask){ JsonNode *newdoc = json_mkobject(); JsonNode *qhl_even = json_mkarray(); JsonNode *qhl_odd = json_mkarray(); JsonNode *qhs_even = json_mkarray(); JsonNode *qhs_odd = json_mkarray(); JsonNode *qlx_even = json_mkarray(); JsonNode *qlx_odd = json_mkarray(); JsonNode *tac_even = json_mkarray(); JsonNode *tac_odd = json_mkarray(); JsonNode *error_even = json_mkarray(); JsonNode *error_odd = json_mkarray(); for (int j=0;j<32;j++){ JsonNode *qhleventemp = json_mkarray(); JsonNode *qhloddtemp = json_mkarray(); JsonNode *qhseventemp = json_mkarray(); JsonNode *qhsoddtemp = json_mkarray(); JsonNode *qlxeventemp = json_mkarray(); JsonNode *qlxoddtemp = json_mkarray(); JsonNode *taceventemp = json_mkarray(); JsonNode *tacoddtemp = json_mkarray(); JsonNode *erroreventemp = json_mkarray(); JsonNode *erroroddtemp = json_mkarray(); for (int k=0;k<26;k++){ json_append_element(qhleventemp,json_mknumber(qhls[k*16*32*2+i*32*2+j*2])); json_append_element(qhloddtemp,json_mknumber(qhls[k*16*32*2+i*32*2+j*2+1])); json_append_element(qhseventemp,json_mknumber(qhss[k*16*32*2+i*32*2+j*2])); json_append_element(qhsoddtemp,json_mknumber(qhss[k*16*32*2+i*32*2+j*2+1])); json_append_element(qlxeventemp,json_mknumber(qlxs[k*16*32*2+i*32*2+j*2])); json_append_element(qlxoddtemp,json_mknumber(qlxs[k*16*32*2+i*32*2+j*2+1])); json_append_element(taceventemp,json_mknumber(tacs[k*16*32*2+i*32*2+j*2])); json_append_element(tacoddtemp,json_mknumber(tacs[k*16*32*2+i*32*2+j*2+1])); json_append_element(erroreventemp,json_mkbool(scan_errors[k*16*32*2+i*32*2+j*2])); json_append_element(erroroddtemp,json_mkbool(scan_errors[k*16*32*2+i*32*2+j*2+1])); } json_append_element(qhl_even,qhleventemp); json_append_element(qhl_odd,qhloddtemp); json_append_element(qhs_even,qhseventemp); json_append_element(qhs_odd,qhsoddtemp); json_append_element(qlx_even,qlxeventemp); json_append_element(qlx_odd,qlxoddtemp); json_append_element(tac_even,taceventemp); json_append_element(tac_odd,tacoddtemp); json_append_element(error_even,erroreventemp); json_append_element(error_odd,erroroddtemp); } json_append_member(newdoc,"type",json_mkstring("chinj_scan")); json_append_member(newdoc,"QHL_even",qhl_even); json_append_member(newdoc,"QHL_odd",qhl_odd); json_append_member(newdoc,"QHS_even",qhs_even); json_append_member(newdoc,"QHS_odd",qhs_odd); json_append_member(newdoc,"QLX_even",qlx_even); json_append_member(newdoc,"QLX_odd",qlx_odd); json_append_member(newdoc,"TAC_even",tac_even); json_append_member(newdoc,"TAC_odd",tac_odd); json_append_member(newdoc,"errors_even",error_even); json_append_member(newdoc,"errors_odd",error_odd); json_append_member(newdoc,"pass",json_mkbool(!(chinj_err[i]))); if (finalTest){ json_append_member(newdoc,"final_test_id",json_mkstring(finalTestIDs[crateNum][i])); } PostDebugDoc(crateNum,i,newdoc); } } } if (errors) lprintf("There were %d errors\n", errors); else lprintf("No errors seen\n"); free(qhls); free(qhss); free(qlxs); free(tacs); free(scan_errors); } catch(const char* s){ lprintf("ChinjScan: %s\n",s); if (pmt_buffer != NULL) free(pmt_buffer); if (ped != NULL) free(ped); if (qhls != NULL) free(qhls); if (qhss != NULL) free(qhss); if (qlxs != NULL) free(qlxs); if (tacs != NULL) free(tacs); if (scan_errors != NULL) free(scan_errors); } lprintf("****************************************\n"); return 0; }
void *pt_get_ttot(void *args) { get_ttot_t arg = *(get_ttot_t *) args; free(args); printf("**********************************\n"); printf("Starting get_ttot\n"); fd_set thread_fdset; FD_ZERO(&thread_fdset); FD_SET(rw_xl3_fd[arg.crate_num],&thread_fdset); uint16_t times[32*16]; int tot_errors[16][32]; // setup the mtc with the triggers going to the TUB int errors = setup_pedestals(0,60,100,0,(0x1<<arg.crate_num) | MSK_CRATE21,MSK_CRATE21); int result = disc_m_ttot(arg.crate_num,arg.slot_mask,150,times,&thread_fdset); // print out results pt_printsend("Crate\t Slot\t Channel\t Time:\n"); int i,j; for (i=0;i<16;i++){ if ((0x1<<i) & arg.slot_mask){ for (j=0;j<32;j++){ tot_errors[i][j] = 0; pt_printsend("%d\t %d\t %d\t %d",arg.crate_num,i,j,times[i*32+j]); if (arg.target_time > times[i*32+j]){ if (arg.target_time < 9999){ pt_printsend(">>> Warning: Time less than %d nsec",arg.target_time); tot_errors[i][j] = 1; } }else if(arg.target_time == 9999){ pt_printsend(">>> Problem measuring time for this channel\n"); tot_errors[i][j] = 2; } pt_printsend("\n"); } } } if (arg.update_db){ printsend("updating the database\n"); int slot; for (slot=0;slot<16;slot++){ if ((0x1<<slot) & arg.slot_mask){ JsonNode *newdoc = json_mkobject(); json_append_member(newdoc,"type",json_mkstring("get_ttot")); json_append_member(newdoc,"targettime",json_mknumber((double)arg.target_time)); JsonNode *channels = json_mkarray(); int passflag = 1; for (i=0;i<32;i++){ if (tot_errors[slot][i] == 1) passflag = 0; JsonNode *one_chan = json_mkobject(); json_append_member(one_chan,"id",json_mknumber((double) i)); json_append_member(one_chan,"time",json_mknumber((double) times[slot*32+i])); json_append_member(one_chan,"errors",json_mknumber(tot_errors[slot][i])); json_append_element(channels,one_chan); } json_append_member(newdoc,"channels",channels); json_append_member(newdoc,"pass",json_mkbool(passflag)); if (arg.final_test) json_append_member(newdoc,"final_test_id",json_mkstring(arg.ft_ids[slot])); if (arg.ecal) json_append_member(newdoc,"ecal_id",json_mkstring(arg.ecal_id)); post_debug_doc(arg.crate_num,slot,newdoc,&thread_fdset); json_delete(newdoc); // delete the head ndoe } } } unthread_and_unlock(1,(0x1<<arg.crate_num),arg.thread_num); }
void *pt_set_ttot(void *args) { set_ttot_t arg = *(set_ttot_t *) args; free(args); fd_set thread_fdset; FD_ZERO(&thread_fdset); FD_SET(rw_xl3_fd[arg.crate_num],&thread_fdset); uint16_t allrmps[16][8],allvsis[16][8],alltimes[16*32]; int tot_errors[16][32]; int i,j,k,l; uint16_t rmp[8],vsi[8],rmpup[8],vli[8]; uint16_t rmp_high[8],rmp_low[8]; uint16_t chips_not_finished; int diff[32]; uint32_t dac_nums[50],dac_values[50]; int num_dacs; int result; // setup the mtc with the triggers going to the TUB int errors = setup_pedestals(0,60,100,0,(0x1<<arg.crate_num) | MSK_CRATE21,MSK_CRATE21); for (i=0;i<16;i++){ if ((0x1<<i) & arg.slot_mask){ // set default values for (j=0;j<8;j++){ rmpup[j] = RMPUP_DEFAULT; vsi[j] = VSI_DEFAULT; vli[j] = VLI_DEFAULT; rmp_high[j] = MAX_RMP_VALUE; rmp_low[j] = RMP_DEFAULT-10; rmp[j] = (int) (rmp_high[j] + rmp_low[j])/2; } // first check that if we make ttot as short as possible, triggers show up num_dacs = 0; for (j=0;j<8;j++){ dac_nums[num_dacs] = d_rmpup[j]; dac_values[num_dacs] = rmpup[j]; num_dacs++; dac_nums[num_dacs] = d_vli[j]; dac_values[num_dacs] = vli[j]; num_dacs++; dac_nums[num_dacs] = d_rmp[j]; dac_values[num_dacs] = rmp_low[j]; num_dacs++; dac_nums[num_dacs] = d_vsi[j]; dac_values[num_dacs] = vsi[j]; num_dacs++; } multi_loadsDac(num_dacs,dac_nums,dac_values,arg.crate_num,i,&thread_fdset); for (k=0;k<32;k++){ result = disc_check_ttot(arg.crate_num,i,(0x1<<k),MAX_TIME,diff,&thread_fdset); tot_errors[i][k] = 0; if (diff[k] == 1){ pt_printsend("Error - Not getting TUB triggers on channel %d!\n",k); tot_errors[i][k] = 2; } } // load default values num_dacs = 0; for (j=0;j<8;j++){ dac_nums[num_dacs] = d_rmp[j]; dac_values[num_dacs] = rmp[j]; num_dacs++; dac_nums[num_dacs] = d_vsi[j]; dac_values[num_dacs] = vsi[j]; num_dacs++; } multi_loadsDac(num_dacs,dac_nums,dac_values,arg.crate_num,i,&thread_fdset); pt_printsend("Setting ttot for crate/board %d %d, target time %d\n",arg.crate_num,i,arg.target_time); chips_not_finished = 0xFF; // loop until all ttot measurements are larger than target ttime while(chips_not_finished){ // measure ttot for all chips result = disc_check_ttot(arg.crate_num,i,0xFFFFFFFF,arg.target_time,diff,&thread_fdset); // loop over disc chips for (j=0;j<8;j++){ if ((0x1<<j) & chips_not_finished){ // check if above or below if ((diff[4*j+0] > 0) && (diff[4*j+1] > 0) && (diff[4*j+2] > 0) && (diff[4*j+3] > 0)){ //pt_printsend("above\n"); rmp_high[j] = rmp[j]; // if we have narrowed it down to the first setting that works, we are done if ((rmp[j] - rmp_low[j]) == 1){ pt_printsend("Chip %d finished\n",j); chips_not_finished &= ~(0x1<<j); allrmps[i][j] = rmp[j]; allvsis[i][j] = vsi[j]; } }else{ //pt_printsend("below\n"); rmp_low[j] = rmp[j]; if (rmp[j] == MAX_RMP_VALUE){ if (vsi[j] > MIN_VSI_VALUE){ rmp_high[j] = MAX_RMP_VALUE; rmp_low[j] = RMP_DEFAULT-10; vsi[j] -= 2; //pt_printsend("%d - vsi: %d\n",j,vsi[j]); }else{ // out of bounds, end loop with error pt_printsend("RMP/VSI is too big for disc chip %d! (%d %d)\n",j,rmp[j],vsi[j]); pt_printsend("Aborting slot %d setup.\n",i); tot_errors[i][j*4+0] = 1; tot_errors[i][j*4+1] = 1; tot_errors[i][j*4+2] = 1; tot_errors[i][j*4+3] = 1; for (l=0;l<8;l++) if (chips_not_finished & (0x1<<l)){ pt_printsend("Slot %d Chip %d\tRMP/VSI: %d %d <- unfinished\n",i,l,rmp[l],vsi[l]); allrmps[i][l] = rmp[l]; allvsis[i][l] = vsi[l]; } chips_not_finished = 0x0; } }else if (rmp[j] == rmp_high[j]){ // in case it screws up and fails after it succeeded already rmp_high[j]++; } } rmp[j] = (int) ((float) (rmp_high[j] + rmp_low[j])/2.0 + 0.5); } // end if this chip not finished } // end loop over disc chips // load new values num_dacs = 0; for (j=0;j<8;j++){ dac_nums[num_dacs] = d_rmp[j]; dac_values[num_dacs] = rmp[j]; num_dacs++; dac_nums[num_dacs] = d_vsi[j]; dac_values[num_dacs] = vsi[j]; num_dacs++; } multi_loadsDac(num_dacs,dac_nums,dac_values,arg.crate_num,i,&thread_fdset); } // end while chips_not_finished // now get the final timing measurements num_dacs = 0; for (j=0;j<8;j++){ dac_nums[num_dacs] = d_rmp[j]; dac_values[num_dacs] = allrmps[i][j]; num_dacs++; dac_nums[num_dacs] = d_vsi[j]; dac_values[num_dacs] = allvsis[i][j]; num_dacs++; } multi_loadsDac(num_dacs,dac_nums,dac_values,arg.crate_num,i,&thread_fdset); result = disc_m_ttot(arg.crate_num,(0x1<<i),150,alltimes,&thread_fdset); pt_printsend("Final timing measurements:\n"); for (j=0;j<8;j++){ pt_printsend("Chip %d (RMP/VSI %d %d) Times:\t%d\t%d\t%d\t%d\n", j,rmp[j],vsi[j],alltimes[i*32+j*4+0],alltimes[i*32+j*4+1], alltimes[i*32+j*4+2],alltimes[i*32+j*4+3]); } if (arg.update_db){ pt_printsend("updating the database\n"); JsonNode *newdoc = json_mkobject(); json_append_member(newdoc,"type",json_mkstring("set_ttot")); json_append_member(newdoc,"targettime",json_mknumber((double)arg.target_time)); JsonNode *all_chips = json_mkarray(); int passflag = 1; int k; for (k=0;k<8;k++){ JsonNode *one_chip = json_mkobject(); json_append_member(one_chip,"rmp",json_mknumber((double) allrmps[i][k])); json_append_member(one_chip,"vsi",json_mknumber((double) allvsis[i][k])); JsonNode *all_chans = json_mkarray(); for (j=0;j<4;j++){ JsonNode *one_chan = json_mkobject(); if (tot_errors[i][k*4+j]> 0) passflag = 0; json_append_member(one_chan,"id",json_mknumber((double) k*4+j)); json_append_member(one_chan,"time",json_mknumber((double) alltimes[i*32+k*4+j])); json_append_member(one_chan,"errors",json_mknumber(tot_errors[i][k*4+j])); json_append_element(all_chans,one_chan); } json_append_member(one_chip,"channels",all_chans); json_append_element(all_chips,one_chip); } json_append_member(newdoc,"chips",all_chips); json_append_member(newdoc,"pass",json_mkbool(passflag)); if (arg.final_test) json_append_member(newdoc,"final_test_id",json_mkstring(arg.ft_ids[i])); if (arg.ecal) json_append_member(newdoc,"ecal_id",json_mkstring(arg.ecal_id)); post_debug_doc(arg.crate_num,i,newdoc,&thread_fdset); json_delete(newdoc); // head node needs deleting } } // if in slot mask } // end loop over slots pt_printsend("Set ttot complete\n"); pt_printsend("**************************\n"); unthread_and_unlock(1,(0x1<<arg.crate_num),arg.thread_num); }
void *pt_cald_test(void *args) { cald_test_t arg = *(cald_test_t *) args; free(args); fd_set thread_fdset; FD_ZERO(&thread_fdset); FD_SET(rw_xl3_fd[arg.crate_num],&thread_fdset); pt_printsend("Starting cald test! Make sure you have inited the right xilinx!\n"); uint16_t *point_buf; uint16_t *adc_buf; point_buf = malloc(16*MAX_SAMPLES*sizeof(uint16_t)); adc_buf = malloc(16*4*MAX_SAMPLES*sizeof(uint16_t)); if ((point_buf == NULL) || (adc_buf == NULL)){ pt_printsend("Problem mallocing for cald test. Exiting\n"); unthread_and_unlock(0,(0x1<<arg.crate_num),arg.thread_num); return; } int i,j; int num_slots = 0; for (i=0;i<16;i++) if ((0x1<<i) & arg.slot_mask) num_slots++; XL3_Packet packet; cald_test_args_t *packet_args = (cald_test_args_t *) packet.payload; packet.cmdHeader.packet_type = CALD_TEST_ID; packet_args->slot_mask = arg.slot_mask; packet_args->num_points = arg.num_points; packet_args->samples = arg.samples; packet_args->upper = arg.upper; packet_args->lower = arg.lower; SwapLongBlock(packet_args,sizeof(cald_test_args_t)/sizeof(uint32_t)); do_xl3_cmd_no_response(&packet,arg.crate_num,&thread_fdset); int total_points = wait_for_cald_test_results(arg.crate_num,point_buf,adc_buf,&thread_fdset); pt_printsend("Got results of cald test. %d points received.\n",total_points); if (arg.update_db){ pt_printsend("updating database\n"); for (i=0;i<16;i++){ if ((0x1<<i) & arg.slot_mask){ JsonNode *newdoc = json_mkobject(); json_append_member(newdoc,"type",json_mkstring("cald_test")); JsonNode *points = json_mkarray(); JsonNode *adc0 = json_mkarray(); JsonNode *adc1 = json_mkarray(); JsonNode *adc2 = json_mkarray(); JsonNode *adc3 = json_mkarray(); int iter = 0; while(iter<=MAX_SAMPLES){ if (iter != 0 && point_buf[i*MAX_SAMPLES+iter] == 0) break; pt_printsend("Slot %d - %u : %4u %4u %4u %4u\n",i,point_buf[i*MAX_SAMPLES+iter],adc_buf[i*4*MAX_SAMPLES+iter*4],adc_buf[i*4*MAX_SAMPLES+iter*4+1],adc_buf[i*4*MAX_SAMPLES+iter*4+2],adc_buf[i*4*MAX_SAMPLES+iter*4+3]); json_append_element(points,json_mknumber((double)point_buf[i*MAX_SAMPLES+iter])); json_append_element(adc0,json_mknumber((double)adc_buf[i*4*MAX_SAMPLES+iter*4])); json_append_element(adc1,json_mknumber((double)adc_buf[i*4*MAX_SAMPLES+iter*4+1])); json_append_element(adc2,json_mknumber((double)adc_buf[i*4*MAX_SAMPLES+iter*4+2])); json_append_element(adc3,json_mknumber((double)adc_buf[i*4*MAX_SAMPLES+iter*4+3])); iter++; } json_append_member(newdoc,"dac_value",points); json_append_member(newdoc,"adc_0",adc0); json_append_member(newdoc,"adc_1",adc1); json_append_member(newdoc,"adc_2",adc2); json_append_member(newdoc,"adc_3",adc3); json_append_member(newdoc,"pass",json_mkbool(1)); //FIXME if (arg.final_test) json_append_member(newdoc,"final_test_id",json_mkstring(arg.ft_ids[i])); post_debug_doc(arg.crate_num,i,newdoc,&thread_fdset); json_delete(newdoc); // only delete the head node } } } free(point_buf); free(adc_buf); unthread_and_unlock(0,(0x1<<arg.crate_num),arg.thread_num); }
int CGTTest(int crateNum, uint32_t slotMask, uint32_t channelMask, int updateDB, int finalTest, int ecal) { lprintf("*** Starting CGT Test ******************\n"); uint32_t result; uint32_t bundles[3]; int crate_id,slot_id,chan_id,nc_id,gt16_id,gt8_id,es16; int missing_bundles[16],chan_errors[16][32]; char error_history[16][5000]; char cur_msg[1000]; int max_errors[16]; uint32_t badchanmask; int num_chans; // zero some stuff memset(cur_msg,'\0',1000); num_chans = 0; for (int i=0;i<32;i++) if ((0x1<<i) & channelMask) num_chans++; for (int i=0;i<16;i++){ for (int j=0;j<32;j++) chan_errors[i][j] = 0; missing_bundles[i] = 0; max_errors[i] = 0; memset(error_history[i],'\0',5000); } try{ // set up mtc mtc->ResetMemory(); //if (setup_pedestals(0,25,150,0,(0x1<<arg.crate_num)+MSK_TUB,(0x1<<arg.crate_num)+MSK_TUB)) if (mtc->SetupPedestals(0,DEFAULT_PED_WIDTH,DEFAULT_GT_DELAY,DEFAULT_GT_FINE_DELAY, (0x1<<crateNum)+MSK_TUB,(0x1<<crateNum)+MSK_TUB)){ lprintf("Error setting up mtc. Exiting\n"); return -1; } mtc->SetGTCounter(0); // set up crate for (int i=0;i<16;i++){ uint32_t select_reg = FEC_SEL*i; uint32_t crate_val = crateNum << FEC_CSR_CRATE_OFFSET; xl3s[crateNum]->RW(PED_ENABLE_R + select_reg + WRITE_REG,0x0,&result); xl3s[crateNum]->RW(CMOS_CHIP_DISABLE_R + select_reg + WRITE_REG,0xFFFFFFFF,&result); xl3s[crateNum]->RW(GENERAL_CSR_R + select_reg + WRITE_REG,crate_val | 0x6,&result); xl3s[crateNum]->RW(GENERAL_CSR_R + select_reg + WRITE_REG,crate_val,&result); xl3s[crateNum]->RW(CMOS_CHIP_DISABLE_R + select_reg + WRITE_REG,0x0,&result); } xl3s[crateNum]->DeselectFECs(); lprintf("Crate number: %d\n" "Slot and Channel mask: %08x %08x\n",crateNum,slotMask,channelMask); // select desired fecs if (xl3s[crateNum]->SetCratePedestals(slotMask,channelMask)){ lprintf("Error setting up crate for pedestals. Exiting\n"); return -1; } xl3s[crateNum]->DeselectFECs(); uint32_t num_peds = 0xFFFF + 10000; lprintf("Going to fire pulser %u times.\n",num_peds); XL3Packet packet; int total_pulses = 0; int numgt = 0; // we now send out gts in bunches, checking periodically // that we are getting the right count at the fecs for (int j=0;j<16;j++){ // we skip 4999 gtids then check each 5000th one if (j != 13) numgt = 4999; else numgt = 534; mtc->MultiSoftGT(numgt); // now loop over slots and make sure we got all the gts for (int i=0;i<16;i++){ if (((0x1<<i) & slotMask) && (max_errors[i] == 0)){ xl3s[crateNum]->RW(FIFO_DIFF_PTR_R + FEC_SEL*i + READ_REG,0x0,&result); if ((result & 0x000FFFFF) != numgt*3*num_chans){ sprintf(cur_msg,"Not enough bundles slot %d: expected %d, found %u\n", i,numgt*3*num_chans,result & 0x000FFFFF); lprintf("%s",cur_msg); if ((strlen(error_history[i]) + strlen(cur_msg)) < sizeof(error_history[i])) sprintf(error_history[i]+strlen(error_history[i]),"%s",cur_msg); else max_errors[i] = 2; missing_bundles[i] = 1; } } // end if in slot mask and not max errors } // end loop over slots // reset the fifo packet.header.packetType = RESET_FIFOS_ID; ResetFifosArgs *args = (ResetFifosArgs *) packet.payload; args->slotMask = slotMask; SwapLongBlock(args,sizeof(ResetFifosArgs)/sizeof(uint32_t)); xl3s[crateNum]->SendCommand(&packet); for (int i=0;i<16;i++) if ((0x1<<i) & slotMask && (max_errors[i] == 0)) xl3s[crateNum]->RW(GENERAL_CSR_R + FEC_SEL*i + WRITE_REG, (crateNum << FEC_CSR_CRATE_OFFSET),&result); // now send a single soft gt and make sure it looks good mtc->SoftGT(); total_pulses += numgt+1; if (j == 13) total_pulses++; // rollover bug for (int i=0;i<16;i++){ if (((0x1<<i) & slotMask) && (max_errors[i] == 0)){ uint32_t select_reg = FEC_SEL*i; xl3s[crateNum]->RW(FIFO_DIFF_PTR_R + select_reg + READ_REG,0x0,&result); if ((result & 0x000FFFFF) != 3*num_chans){ sprintf(cur_msg,"Not enough bundles slot %d: expected %d, found %u\n", i,3*num_chans,result & 0x000FFFFF); lprintf("%s",cur_msg); if ((strlen(error_history[i]) + strlen(cur_msg)) < sizeof(error_history[i])) sprintf(error_history[i]+strlen(error_history[i]),"%s",cur_msg); else max_errors[i] = 2; missing_bundles[i] = 1; } // read out one bundle for each channel badchanmask = channelMask; for (int k=0;k<((result&0x000FFFFF)/3);k++){ xl3s[crateNum]->RW(READ_MEM + select_reg,0x0,&bundles[0]); xl3s[crateNum]->RW(READ_MEM + select_reg,0x0,&bundles[1]); xl3s[crateNum]->RW(READ_MEM + select_reg,0x0,&bundles[2]); crate_id = (int) UNPK_CRATE_ID(bundles); slot_id = (int) UNPK_BOARD_ID(bundles); chan_id = (int) UNPK_CHANNEL_ID(bundles); nc_id = (int) UNPK_NC_CC(bundles); gt16_id = (int) UNPK_FEC_GT16_ID(bundles); gt8_id = (int) UNPK_FEC_GT8_ID(bundles); es16 = (int) UNPK_CGT_ES_16(bundles); badchanmask &= ~(0x1<<chan_id); if (crate_id != crateNum){ sprintf(cur_msg,"Crate wrong for slot %d, chan %u: expected %d, read %u\n", i,chan_id,crateNum,crate_id); lprintf("%s",cur_msg); if ((strlen(error_history[i]) + strlen(cur_msg)) < sizeof(error_history[i])) sprintf(error_history[i]+strlen(error_history[i]),"%s",cur_msg); else max_errors[i] = 2; chan_errors[i][chan_id] = 1; } if (slot_id != i){ sprintf(cur_msg,"Slot wrong for slot %d chan %u: expected %d, read %u\n", i,chan_id,i,slot_id); lprintf("%s",cur_msg); if ((strlen(error_history[i]) + strlen(cur_msg)) < sizeof(error_history[i])) sprintf(error_history[i]+strlen(error_history[i]),"%s",cur_msg); else max_errors[i] = 2; chan_errors[i][chan_id] = 1; } if (nc_id != 0x0){ sprintf(cur_msg,"NC_CC wrong for slot %d chan %u: expected %d, read %u\n", i,chan_id,0,nc_id); lprintf("%s",cur_msg); if ((strlen(error_history[i]) + strlen(cur_msg)) < sizeof(error_history[i])) sprintf(error_history[i]+strlen(error_history[i]),"%s",cur_msg); else max_errors[i] = 2; chan_errors[i][chan_id] = 1; } if ((gt16_id + (65536*gt8_id)) != total_pulses){ if (gt16_id == total_pulses%65536){ sprintf(cur_msg,"Bad upper 8 Gtid bits for slot %d chan %u: expected %d, read %u\n" "%08x %08x %08x\n", i,chan_id,total_pulses-total_pulses%65536,(65536*gt8_id),bundles[0], bundles[1],bundles[2]); lprintf("%s",cur_msg); if ((strlen(error_history[i]) + strlen(cur_msg)) < sizeof(error_history[i])) sprintf(error_history[i]+strlen(error_history[i]),"%s",cur_msg); else max_errors[i] = 2; }else if (gt8_id == total_pulses/65536){ sprintf(cur_msg,"Bad lower 16 gtid bits for slot %d chan %u: expected %d, read %u\n" "%08x %08x %08x\n", i,chan_id,total_pulses%65536,gt16_id,bundles[0], bundles[1],bundles[2]); lprintf("%s",cur_msg); if ((strlen(error_history[i]) + strlen(cur_msg)) < sizeof(error_history[i])) sprintf(error_history[i]+strlen(error_history[i]),"%s",cur_msg); else max_errors[i] = 2; }else{ sprintf(cur_msg,"Bad gtid for slot %d chan %u: expected %d, read %u\n" "%08x %08x %08x\n", i,chan_id,total_pulses,gt16_id+(65536*gt8_id),bundles[0], bundles[1],bundles[2]); lprintf("%s",cur_msg); if ((strlen(error_history[i]) + strlen(cur_msg)) < sizeof(error_history[i])) sprintf(error_history[i]+strlen(error_history[i]),"%s",cur_msg); else max_errors[i] = 2; } chan_errors[i][chan_id] = 1; } if (es16 != 0x0 && j >= 13){ sprintf(cur_msg,"Synclear error for slot %d chan %u.\n", i,chan_id); lprintf("%s",cur_msg); if ((strlen(error_history[i]) + strlen(cur_msg)) < sizeof(error_history[i])) sprintf(error_history[i]+strlen(error_history[i]),"%s",cur_msg); else max_errors[i] = 2; chan_errors[i][chan_id] = 1; } } // end loop over bundles being read out for (int k=0;k<32;k++){ if ((0x1<<k) & badchanmask){ sprintf(cur_msg,"No bundle found for slot %d chan %d\n",i,k); lprintf("%s",cur_msg); if ((strlen(error_history[i]) + strlen(cur_msg)) < sizeof(error_history[i])) sprintf(error_history[i]+strlen(error_history[i]),"%s",cur_msg); else max_errors[i] = 2; chan_errors[i][k] = 1; } } } // end if in slot mask and not max errors } // end loop over slots // check if we should stop any slot // because there are too many errors for (int i=0;i<16;i++){ if (((strlen(error_history[i]) > 5000) && (max_errors[i] == 0)) || (max_errors[i] == 2)){ lprintf("Too many errors slot %d. Skipping that slot\n",i); max_errors[i] = 1; } } lprintf("%d pulses\n",total_pulses); for (int i=0;i<16;i++) sprintf(error_history[i]+strlen(error_history[i]),"%d pulses\n",total_pulses); } // end loop over gt bunches if (updateDB){ lprintf("updating the database\n"); int passflag; for (int slot=0;slot<16;slot++){ if ((0x1<<slot) & slotMask){ lprintf("updating slot %d\n",slot); passflag = 1; JsonNode *newdoc = json_mkobject(); json_append_member(newdoc,"type",json_mkstring("cgt_test")); json_append_member(newdoc,"missing_bundles",json_mkbool(missing_bundles[slot])); if (missing_bundles[slot] > 0) passflag = 0; JsonNode *chan_errs = json_mkarray(); for (int i=0;i<32;i++){ json_append_element(chan_errs,json_mkbool(chan_errors[slot][i])); if (chan_errors[slot][i] > 0) passflag = 0; } json_append_member(newdoc,"errors",chan_errs); json_append_member(newdoc,"printout",json_mkstring(error_history[slot])); json_append_member(newdoc,"pass",json_mkbool(passflag)); if (finalTest) json_append_member(newdoc,"final_test_id",json_mkstring(finalTestIDs[crateNum][slot])); if (ecal) json_append_member(newdoc,"ecal_id",json_mkstring(ecalID)); PostDebugDoc(crateNum,slot,newdoc); json_delete(newdoc); // only delete the head node } } } } catch(const char* s){ lprintf("CGTTest: %s\n",s); } lprintf("Ending cgt test\n"); lprintf("****************************************\n"); return 0; }
void *pt_fec_test(void *args) { fec_test_t arg = *(fec_test_t *) args; free(args); XL3_Packet packet; fec_test_args_t *packet_args = (fec_test_args_t *) packet.payload; fec_test_results_t *packet_results = (fec_test_results_t *) packet.payload; packet.cmdHeader.packet_type = FEC_TEST_ID; packet_args->slot_mask = arg.slot_mask; SwapLongBlock(packet.payload,1); fd_set thread_fdset; FD_ZERO(&thread_fdset); FD_SET(rw_xl3_fd[arg.crate_num],&thread_fdset); /* MultiFC *commands = (MultiFC *) packet.payload; commands->howmany = 50; int i; for (i=0;i<25;i++){ commands->cmd[i*2].address = 0x10F00023; commands->cmd[i*2+1].address = 0x00F00023; commands->cmd[i*2+1].data = i<<16; SwapLongBlock(&(commands->cmd[i*2].address),1); SwapLongBlock(&(commands->cmd[i*2+1].address),1); SwapLongBlock(&(commands->cmd[i*2+1].data),1); } SwapLongBlock(&(commands->howmany),1); packet.cmdHeader.packet_type = QUEUE_CMDS_ID; int errors = do_xl3_cmd(&packet,arg.crate_num,&thread_fdset); if (errors < 0){ pt_printsend("Error queuing command\n"); unthread_and_unlock(0,(0x1<<arg.crate_num),arg.thread_num); return; } uint32_t result[50]; errors = wait_for_multifc_results(50,command_number[arg.crate_num]-1,arg.crate_num,&result,&thread_fdset); if (errors < 0){ pt_printsend("Error getting result\n"); unthread_and_unlock(0,(0x1<<arg.crate_num),arg.thread_num); return; } for (i=0;i<50;i++){ pt_printsend("%d - %08x\n",i,result[i]); } unthread_and_unlock(0,(0x1<<arg.crate_num),arg.thread_num); return; ////////////////////////////////// */ do_xl3_cmd(&packet,arg.crate_num,&thread_fdset); SwapLongBlock(packet_results,sizeof(fec_test_results_t)/sizeof(uint32_t)); if (arg.update_db){ pt_printsend("updating the database\n"); int slot,i; for (slot=0;slot<16;slot++){ if ((0x1<<slot) & arg.slot_mask){ pt_printsend("updating slot %d\n",slot); JsonNode *newdoc = json_mkobject(); json_append_member(newdoc,"type",json_mkstring("fec_test")); json_append_member(newdoc,"pedestal", json_mkbool(!(packet_results->discrete_reg_errors[slot] & 0x1))); json_append_member(newdoc,"chip_disable", json_mkbool(!(packet_results->discrete_reg_errors[slot] & 0x2))); json_append_member(newdoc,"lgi_select", json_mkbool(!(packet_results->discrete_reg_errors[slot] & 0x4))); json_append_member(newdoc,"cmos_prog_low", json_mkbool(!(packet_results->discrete_reg_errors[slot] & 0x8))); json_append_member(newdoc,"cmos_prog_high", json_mkbool(!(packet_results->discrete_reg_errors[slot] & 0x10))); JsonNode *cmos_test_array = json_mkarray(); for (i=0;i<32;i++){ json_append_element(cmos_test_array, json_mkbool(!(packet_results->cmos_test_reg_errors[slot] & (0x1<<i)))); } json_append_element(cmos_test_array, json_mkbool(packet_results->cmos_test_reg_errors[slot] == 0x0)); json_append_member(newdoc,"cmos_test_reg",cmos_test_array); json_append_member(newdoc,"pass", json_mkbool((packet_results->discrete_reg_errors[slot] == 0x0) && (packet_results->cmos_test_reg_errors[slot] == 0x0))); if (arg.final_test) json_append_member(newdoc,"final_test_id",json_mkstring(arg.ft_ids[slot])); if (arg.ecal) json_append_member(newdoc,"ecal_id",json_mkstring(arg.ecal_id)); post_debug_doc(arg.crate_num,slot,newdoc,&thread_fdset); json_delete(newdoc); // Only have to delete the head node } } } unthread_and_unlock(0,(0x1<<arg.crate_num),arg.thread_num); }
void *pt_mem_test(void *args) { mem_test_t arg = *(mem_test_t *) args; free(args); XL3_Packet packet; mem_test_args_t *packet_args = (mem_test_args_t *) packet.payload; mem_test_results_t *packet_results = (mem_test_results_t *) packet.payload; packet.cmdHeader.packet_type = MEM_TEST_ID; packet_args->slot_num = arg.slot_num; SwapLongBlock(packet_args,sizeof(mem_test_args_t)/sizeof(uint32_t)); fd_set thread_fdset; FD_ZERO(&thread_fdset); FD_SET(rw_xl3_fd[arg.crate_num],&thread_fdset); pt_printsend("Getting crate configuration\n"); update_crate_config(arg.crate_num,(0x1<<arg.slot_num),&thread_fdset); pt_printsend("Starting mem_test\n"); do_xl3_cmd(&packet,arg.crate_num,&thread_fdset); SwapLongBlock(packet_results,sizeof(mem_test_results_t)/sizeof(uint32_t)); if (arg.update_db){ pt_printsend("updating the database\n"); char hextostr[50]; int i; JsonNode *newdoc = json_mkobject(); json_append_member(newdoc,"type",json_mkstring("mem_test")); // results of address test, which address bits are broken JsonNode* address_test = json_mkarray(); for (i=0;i<20;i++){ json_append_element(address_test, json_mkbool(!(packet_results->address_bit_failures & (0x1<<i)))); } json_append_member(newdoc,"address_test_ok",address_test); // results of pattern test, where first error was JsonNode* pattern_test = json_mkobject(); json_append_member(pattern_test,"error",json_mkbool(packet_results->error_location!=0xFFFFFFFF)); sprintf(hextostr,"%08x",packet_results->error_location); json_append_member(pattern_test,"error_location",json_mkstring(hextostr)); sprintf(hextostr,"%08x",packet_results->expected_data); json_append_member(pattern_test,"expected_data",json_mkstring(hextostr)); sprintf(hextostr,"%08x",packet_results->read_data); json_append_member(pattern_test,"read_data",json_mkstring(hextostr)); json_append_member(newdoc,"pattern_test",pattern_test); json_append_member(newdoc,"pass", json_mkbool((packet_results->address_bit_failures == 0x0) && (packet_results->error_location == 0xFFFFFFFF))); if (arg.final_test) json_append_member(newdoc,"final_test_id",json_mkstring(arg.ft_id)); post_debug_doc_mem_test(arg.crate_num,arg.slot_num,newdoc,&thread_fdset); json_delete(newdoc); // Only have to delete the head node } unthread_and_unlock(0,(0x1<<arg.crate_num),arg.thread_num); }
int FinalTest(int crateNum, uint32_t slotMask, uint32_t testMask, int skip) { int updateDB = 1; lprintf("*** Starting Final Test ****************\n"); JsonNode *ftDocs[16]; char comments[1000]; memset(comments,'\0',1000); int errors; // initialize the crate errors = CrateInit(crateNum,slotMask,1,0,0,0,0,0,0,0,0); if (errors){ lprintf("Problem initializing the crate, exiting final test\n"); return -1; } errors = MTCInit(1); if (errors){ lprintf("Problem intializing the mtcd, exiting final test\n"); } lprintf("----------------------------------------\n"); lprintf("If any boards could not initialize properly, type \"quit\" now " "to exit the test.\n Otherwise hit enter to continue.\n"); contConnection->GetInput(comments,1000); if (strncmp("quit",comments,4) == 0){ lprintf("Exiting final test\n"); lprintf("****************************************\n"); return 0; } for (int i=0;i<16;i++){ if ((0x1<<i) & slotMask){ GetNewID(finalTestIDs[crateNum][i]); ftDocs[i] = json_mkobject(); } } lprintf("Now starting board_id\n"); BoardID(crateNum,slotMask); lprintf("----------------------------------------\n"); if (!skip && updateDB){ for (int i=0;i<16;i++){ if ((0x1<<i) & slotMask){ lprintf("Please enter any comments for slot %i motherboard now.\n",i); contConnection->GetInput(comments); json_append_member(ftDocs[i],"fec_comments",json_mkstring(comments)); lprintf("Has this slot been refurbished? (y/n)\n",i); contConnection->GetInput(comments); json_append_member(ftDocs[i],"refurbished",json_mkbool(comments[0] == 'y')); lprintf("Has this slot been cleaned? (y/n)\n",i); contConnection->GetInput(comments); json_append_member(ftDocs[i],"cleaned",json_mkbool(comments[0] == 'y')); lprintf("Time to measure resistance across analog outs and cmos address lines. For the cmos address lines" "it's easier if you do it during the fifo mod\n"); contConnection->GetInput(comments); json_append_member(ftDocs[i],"analog_out_res",json_mkstring(comments)); lprintf("Please enter any comments for slot %i db 0 now.\n",i); contConnection->GetInput(comments); json_append_member(ftDocs[i],"db0_comments",json_mkstring(comments)); lprintf("Please enter any comments for slot %i db 1 now.\n",i); contConnection->GetInput(comments); json_append_member(ftDocs[i],"db1_comments",json_mkstring(comments)); lprintf("Please enter any comments for slot %i db 2 now.\n",i); contConnection->GetInput(comments); json_append_member(ftDocs[i],"db2_comments",json_mkstring(comments)); lprintf("Please enter any comments for slot %i db 3 now.\n",i); contConnection->GetInput(comments); json_append_member(ftDocs[i],"db3_comments",json_mkstring(comments)); lprintf("Please enter dark matter measurements for slot %i db 0 now.\n",i); contConnection->GetInput(comments); json_append_member(ftDocs[i],"db0_dark_matter",json_mkstring(comments)); lprintf("Please enter dark matter measurements for slot %i db 1 now.\n",i); contConnection->GetInput(comments); json_append_member(ftDocs[i],"db1_dark_matter",json_mkstring(comments)); lprintf("Please enter dark matter measurements for slot %i db 2 now.\n",i); contConnection->GetInput(comments); json_append_member(ftDocs[i],"db2_dark_matter",json_mkstring(comments)); lprintf("Please enter dark matter measurements for slot %i db 3 now.\n",i); contConnection->GetInput(comments); json_append_member(ftDocs[i],"db3_dark_matter",json_mkstring(comments)); } } lprintf("Enter N100 DC offset\n"); contConnection->GetInput(comments); for (int i=0;i<16;i++){ if ((0x1<<i) & slotMask){ json_append_member(ftDocs[i],"dc_offset_n100",json_mkstring(comments)); } } lprintf("Enter N20 DC offset\n"); contConnection->GetInput(comments); for (int i=0;i<16;i++){ if ((0x1<<i) & slotMask){ json_append_member(ftDocs[i],"dc_offset_n20",json_mkstring(comments)); } } lprintf("Enter esum hi DC offset\n"); contConnection->GetInput(comments); for (int i=0;i<16;i++){ if ((0x1<<i) & slotMask){ json_append_member(ftDocs[i],"dc_offset_esumhi",json_mkstring(comments)); } } lprintf("Enter esum lo DC offset\n"); contConnection->GetInput(comments); for (int i=0;i<16;i++){ if ((0x1<<i) & slotMask){ json_append_member(ftDocs[i],"dc_offset_esumlo",json_mkstring(comments)); } } lprintf("Thank you. Please hit enter to continue with the rest of final test. This may take a while.\n"); contConnection->GetInput(comments); } // update the database if (updateDB){ for (int i=0;i<16;i++){ if ((0x1<<i) & slotMask){ json_append_member(ftDocs[i],"type",json_mkstring("final_test")); PostDebugDocWithID(crateNum, i, finalTestIDs[crateNum][i], ftDocs[i]); } } } lprintf("----------------------------------------\n"); int testCounter = 0; if ((0x1<<testCounter) & testMask) FECTest(crateNum,slotMask,updateDB,1); testCounter++; if ((0x1<<testCounter) & testMask) VMon(crateNum,slotMask,updateDB,1); testCounter++; if ((0x1<<testCounter) & testMask) CGTTest(crateNum,slotMask,0xFFFFFFFF,updateDB,1); testCounter++; CrateInit(crateNum,slotMask,1,0,0,0,0,0,0,0,0); if ((0x1<<testCounter) & testMask) PedRun(crateNum,slotMask,0xFFFFFFFF,0,DEFAULT_GT_DELAY,DEFAULT_PED_WIDTH,50,1000,300,updateDB,0,1); testCounter++; CrateInit(crateNum,slotMask,1,0,0,0,0,0,0,0,0); MTCInit(1); if ((0x1<<testCounter) & testMask) CrateCBal(crateNum,slotMask,0xFFFFFFFF,updateDB,1); testCounter++; lprintf("----------------------------------------\n"); // load cbal values now CrateInit(crateNum,slotMask,0,1,0,0,0,0,0,0,0); if ((0x1<<testCounter) & testMask) PedRun(crateNum,slotMask,0xFFFFFFFF,0,DEFAULT_GT_DELAY,DEFAULT_PED_WIDTH,50,1000,300,updateDB,1,1); testCounter++; if ((0x1<<testCounter) & testMask) ChinjScan(crateNum,slotMask,0xFFFFFFFF,0,DEFAULT_GT_DELAY,DEFAULT_PED_WIDTH,10,5000,400,1,1,updateDB,1); testCounter++; if ((0x1<<testCounter) & testMask) SetTTot(crateNum,slotMask,400,updateDB,1); testCounter++; // load cbal and ttot values now CrateInit(crateNum,slotMask,0,1,0,1,0,0,0,0,0); if ((0x1<<testCounter) & testMask) GetTTot(crateNum,slotMask,390,updateDB,1); testCounter++; if ((0x1<<testCounter) & testMask) DiscCheck(crateNum,slotMask,500000,updateDB,1); testCounter++; uint32_t slotMasks[MAX_XL3_CON]; for (int ic=0;ic<MAX_XL3_CON;ic++) slotMasks[ic] = slotMask; if ((0x1<<testCounter) & testMask) GTValidTest((0x1)<<crateNum,slotMasks,0xFFFFFFFF,400,0,0,updateDB,0,1); testCounter++; CrateInit(crateNum,slotMask,1,0,0,0,0,0,0,0,0); if ((0x1<<testCounter) & testMask) ZDisc(crateNum,slotMask,10000,0,updateDB,0,1,0); testCounter++; MTCInit(0); CrateInit(crateNum,slotMask,1,0,0,0,0,0,0,0,0); if ((0x1<<testCounter) & testMask) MbStabilityTest(crateNum,slotMask,50,updateDB,1); testCounter++; if ((0x1<<testCounter) & testMask) FifoTest(crateNum,slotMask,updateDB,1); testCounter++; // load alternate xilinx CrateInit(crateNum,slotMask,2,0,0,0,0,0,0,0,0); if ((0x1<<testCounter) & testMask) CaldTest(crateNum,slotMask,3500,750,200,1,updateDB,1); testCounter++; for (int i=0;i<16;i++){ if ((0x1<<i) & slotMask){ CrateInit(crateNum,slotMask,1,0,0,0,0,0,0,0,0); if ((0x1<<testCounter) & testMask) MemTest(crateNum,i,updateDB,1); } } testCounter++; CrateInit(crateNum,slotMask,1,0,0,0,0,0,0,0,0); if ((0x1<<testCounter) & testMask){ lprintf("Ready for see_refl test. Hit enter to enable triggers and continue or quit to skip and finish.\n\a"); contConnection->GetInput(comments); if (strncmp("quit",comments,4) != 0){ SeeReflection(crateNum,slotMask,0xFFFFFFFF,255,1000,updateDB,0,1); } } CrateInit(crateNum,slotMask,0,0,0,0,0,0,0,0); lprintf("----------------------------------------\n"); lprintf("Final Test finished!\n"); lprintf("****************************************\n"); return 0; }
int FifoTest(int crateNum, uint32_t slotMask, int updateDB, int finalTest) { lprintf("*** Starting Fifo Test *****************\n"); uint32_t result; char error_history[10000]; char cur_msg[1000]; int slot_errors; uint32_t remainder,diff,write,read; uint32_t gt1[16],gt2[16],bundle[12]; uint32_t *readout_data; int gtstofire; readout_data = (uint32_t *) malloc( 0x000FFFFF * sizeof(uint32_t)); if (readout_data == NULL){ lprintf("Error mallocing. Exiting\n"); return -1; } try { // set up mtc mtc->ResetMemory(); mtc->SetGTCounter(0); //FIXME //if (setup_pedestals(0,25,150,0,(0x1<<crateNum)+MSK_TUB,(0x1<<crateNum)+MSK_TUB)) if (mtc->SetupPedestals(0,DEFAULT_PED_WIDTH,DEFAULT_GT_DELAY,DEFAULT_GT_FINE_DELAY, (0x1<<crateNum)+MSK_TUB,(0x1<<crateNum)+MSK_TUB)){ lprintf("Error setting up mtc. Exiting\n"); free(readout_data); return -1; } // set up crate int busErrors = 0; for (int i=0;i<16;i++){ if ((0x1<<i) & slotMask){ uint32_t select_reg = FEC_SEL*i; busErrors += xl3s[crateNum]->RW(GENERAL_CSR_R + select_reg + WRITE_REG,0xf,&result); busErrors += xl3s[crateNum]->RW(GENERAL_CSR_R + select_reg + WRITE_REG,crateNum<<FEC_CSR_CRATE_OFFSET,&result); if (busErrors != 0){ lprintf("FEC is not responding. Exiting\n"); free(readout_data); return -1; } } } // mask in one channel on each fec xl3s[crateNum]->SetCratePedestals(slotMask,0x1); // check initial conditions for (int i=0;i<16;i++){ if ((0x1<<i) & slotMask){ CheckFifo(crateNum,i,&diff,error_history); // get initial count mtc->GetGTCount(>1[i]); } } // now pulse the soft gts // we will fill the fifos almost to the top gtstofire = (0xFFFFF-32)/3; lprintf("Now firing %u soft gts.\n",gtstofire); int gtcount = 0; while (gtcount < gtstofire){ if (gtstofire - gtcount > 5000){ mtc->MultiSoftGT(5000); gtcount += 5000; }else{ mtc->MultiSoftGT(gtstofire-gtcount); gtcount += gtstofire-gtcount; } if (gtcount%15000 == 0){ lprintf("."); fflush(stdout); } } lprintf("\n"); for (int i=0;i<16;i++){ if ((0x1<<i) & slotMask){ // zero some stuff memset(cur_msg,'\0',1000); slot_errors = 0; memset(error_history,'\0',10000); // get the updated gt count mtc->GetGTCount(>2[i]); sprintf(cur_msg,"Slot %d - Number of GTs fired: %u\n",i,gt2[i]-gt1[i]); sprintf(cur_msg+strlen(cur_msg),"Slot %d - GT before: %u, after: %u\n",i,gt1[i],gt2[i]); lprintf("%s",cur_msg); sprintf(error_history+strlen(error_history),"%s",cur_msg); // make sure it matches the number of gts you sent CheckFifo(crateNum,i,&diff,error_history); if (diff != 3*(gt2[i]-gt1[i])){ sprintf(cur_msg,"Slot %d - Unexpected number of fifo counts!\n",i); sprintf(cur_msg+strlen(cur_msg),"Slot %d - Based on MTCD GTs fired, should be 0x%05x (%u)\n",i,3*(gt2[i]-gt1[i]),3*(gt2[i]-gt1[i])); sprintf(cur_msg+strlen(cur_msg),"Slot %d - Based on times looped, should be 0x%05x (%u)\n",i,gtstofire*3,gtstofire*3); lprintf("%s",cur_msg); sprintf(error_history+strlen(error_history),"%s",cur_msg); } // turn off all but one slot xl3s[crateNum]->SetCratePedestals(0x1<<i,0x1); // now pulse the last soft gts to fill fifo to the top remainder = diff/3; sprintf(cur_msg,"Slot %d - Now firing %d more soft gts\n",i,remainder); lprintf("%s",cur_msg); sprintf(error_history+strlen(error_history),"%s",cur_msg); gtcount = 0; while (gtcount < remainder){ if (remainder - gtcount > 5000){ mtc->MultiSoftGT(5000); gtcount += 5000; }else{ mtc->MultiSoftGT(remainder-gtcount); gtcount += remainder-gtcount; } } CheckFifo(crateNum,i,&diff,error_history); // now read out bundles for (int j=0;j<12;j++) xl3s[crateNum]->RW(READ_MEM + FEC_SEL*i,0x0,&bundle[j]); sprintf(cur_msg,"Slot %d - Read out %d longwords (%d bundles)\n",i,12,12/3); lprintf("%s",cur_msg); sprintf(error_history+strlen(error_history),"%s",cur_msg); CheckFifo(crateNum,i,&diff,error_history); remainder = diff/3; DumpPmtVerbose(12/3,bundle,error_history); // check overflow behavior sprintf(cur_msg,"Slot %d - Now overfill FEC (firing %d more soft GTs)\n",i,remainder+3); sprintf(error_history+strlen(error_history),"%s",cur_msg); lprintf("%s",cur_msg); gtcount = 0; remainder+=3; while (gtcount < remainder){ if (remainder - gtcount > 5000){ mtc->MultiSoftGT(5000); gtcount += 5000; }else{ mtc->MultiSoftGT(remainder-gtcount); gtcount += remainder-gtcount; } } CheckFifo(crateNum,i,&diff,error_history); uint32_t busy_bits,test_id; xl3s[crateNum]->RW(CMOS_BUSY_BIT(0) + READ_REG + FEC_SEL*i,0x0,&busy_bits); sprintf(cur_msg,"Should see %d cmos busy bits set. Busy bits are -> 0x%04x\n",3,busy_bits & 0x0000FFFF); sprintf(cur_msg+strlen(cur_msg),"(Note that there might be one less than expected as it might be caught up in sequencing.)\n"); xl3s[crateNum]->RW(CMOS_INTERN_TEST(0) + READ_REG + FEC_SEL*i,0x0,&test_id); sprintf(cur_msg+strlen(cur_msg),"See if we can read out test reg: 0x%08x\n",test_id); sprintf(error_history+strlen(error_history),"%s",cur_msg); lprintf("%s",cur_msg); // now read out bundles for (int j=0;j<12;j++) xl3s[crateNum]->RW(READ_MEM + FEC_SEL*i,0x0,&bundle[j]); sprintf(cur_msg,"Slot %d - Read out %d longwords (%d bundles). Should have cleared all busy bits\n",i,12,12/3); sprintf(error_history+strlen(error_history),"%s",cur_msg); lprintf("%s",cur_msg); DumpPmtVerbose(12/3,bundle,error_history); CheckFifo(crateNum,i,&diff,error_history); xl3s[crateNum]->RW(CMOS_BUSY_BIT(0) + READ_REG + FEC_SEL*i,0x0,&busy_bits); sprintf(cur_msg,"Should see %d cmos busy bits set. Busy bits are -> 0x%04x\n",0,busy_bits & 0x0000FFFF); sprintf(error_history+strlen(error_history),"%s",cur_msg); lprintf("%s",cur_msg); // read out data and check the stuff around the wrap of the write pointer int leftOver = 30; sprintf(cur_msg,"Slot %d - Dumping all but the last %d events.\n",i,leftOver); sprintf(error_history+strlen(error_history),"%s",cur_msg); lprintf("%s",cur_msg); int count = xl3s[crateNum]->ReadOutBundles(i,readout_data,(0xFFFFF-diff)/3-leftOver,0); lprintf("Managed to read out %d bundles\n",count); CheckFifo(crateNum,i,&diff,error_history); leftOver = (0x000FFFFF-diff)/3; sprintf(cur_msg,"Slot %d - Dumping last %d events!\n",i,leftOver); sprintf(error_history+strlen(error_history),"%s",cur_msg); lprintf("%s",cur_msg); if (leftOver > 0xFFFFF/3){ lprintf("There was an error calculating how much to read out. Will attempt to read everything thats left\n"); leftOver = 0xFFFFF/3; } xl3s[crateNum]->ReadOutBundles(i,readout_data,leftOver,0); if (leftOver > 20) DumpPmtVerbose(20,readout_data,error_history); else DumpPmtVerbose(leftOver,readout_data,error_history); CheckFifo(crateNum,i,&diff,error_history); sprintf(cur_msg,"Slot %d - Trying to read past the end... should get %d bus errors\n",i,12); sprintf(error_history+strlen(error_history),"%s",cur_msg); lprintf("%s",cur_msg); int busErrors = 0; for (int j=0;j<12;j++){ busErrors += xl3s[crateNum]->RW(READ_MEM + FEC_SEL*i,0x0,&bundle[j]); } if (busErrors){ sprintf(cur_msg,"Slot %d - Got expected bus errors (%d).\n",i,busErrors); }else{ sprintf(cur_msg,"Slot %d - Error! Read past end!\n",i); slot_errors = 1; } sprintf(error_history+strlen(error_history),"%s",cur_msg); lprintf("%s",cur_msg); xl3s[crateNum]->DeselectFECs(); sprintf(cur_msg,"Finished Slot %d\n",i); sprintf(cur_msg+strlen(cur_msg),"**************************************************\n"); sprintf(error_history+strlen(error_history),"%s",cur_msg); lprintf("%s",cur_msg); if (updateDB){ lprintf("updating the database\n"); lprintf("updating slot %d\n",i); JsonNode *newdoc = json_mkobject(); json_append_member(newdoc,"type",json_mkstring("fifo_test")); json_append_member(newdoc,"printout",json_mkstring(error_history)); json_append_member(newdoc,"pass",json_mkbool(~(slot_errors))); if (finalTest) json_append_member(newdoc,"final_test_id",json_mkstring(finalTestIDs[crateNum][i])); PostDebugDoc(crateNum,i,newdoc); json_delete(newdoc); } } // end if slot mask } // end loop over slot lprintf("Ending fifo test\n"); } catch(const char* s){ lprintf("FifoTest: %s\n",s); } free(readout_data); lprintf("********************************\n"); return 0; }
int GTValidTest(int crateNum, uint32_t slotMask, uint32_t channelMask, float gtCutoff, int twiddleOn, int updateDB, int finalTest, int ecal) { lprintf("*** Starting GT Valid Test *************\n"); uint32_t result; int error; int slot_errors; int chan_errors[32]; uint16_t tacbits[32]; uint16_t max_isetm[32],isetm[2]; float max_gtvalid[32], gtvalid_first[2][32], gtvalid_second[2][32], gtvalid_final[2][32]; float gmax[2],gmin[2]; int cmax[2],cmin[2]; try{ // setup crate for (int i=0;i<16;i++){ if ((0x1<<i) & slotMask){ uint32_t select_reg = FEC_SEL*i; // disable pedestals xl3s[crateNum]->RW(PED_ENABLE_R + select_reg + WRITE_REG,0x0,&result); // reset fifo xl3s[crateNum]->RW(CMOS_CHIP_DISABLE_R + select_reg + WRITE_REG,0xFFFFFFFF,&result); xl3s[crateNum]->RW(GENERAL_CSR_R + select_reg + READ_REG,0x0,&result); xl3s[crateNum]->RW(GENERAL_CSR_R + select_reg + WRITE_REG, result | (crateNum << FEC_CSR_CRATE_OFFSET) | 0x6,&result); xl3s[crateNum]->RW(GENERAL_CSR_R + select_reg + WRITE_REG, (crateNum << FEC_CSR_CRATE_OFFSET),&result); xl3s[crateNum]->RW(CMOS_CHIP_DISABLE_R + select_reg + WRITE_REG,0x0,&result); } } xl3s[crateNum]->DeselectFECs(); if (mtc->SetupPedestals(0,DEFAULT_PED_WIDTH,10,0,(0x1<<crateNum),(0x1<<crateNum))){ lprintf("Error setting up mtc. Exiting\n"); return -1; } // loop over slot for (int i=0;i<16;i++){ if ((0x1<<i) & slotMask){ uint32_t select_reg = FEC_SEL*i; slot_errors = 0; for (int j=0;j<32;j++){ chan_errors[j] = 0; } error = xl3s[crateNum]->LoadsDac(d_vmax,VMAX,i); error+= xl3s[crateNum]->LoadsDac(d_tacref,TACREF,i); // We first need to find the max gtvalid per channel, and find the // ISETM settings per channel for max gtvalid lprintf("Finding max possible gtvalids\n"); // turn off twiddle bits error+= xl3s[crateNum]->LoadsDac(d_iseta[0],ISETA_NO_TWIDDLE,i); error+= xl3s[crateNum]->LoadsDac(d_iseta[1],ISETA_NO_TWIDDLE,i); for (int j=0;j<32;j++) tacbits[j] = 0x00; error+= xl3s[crateNum]->LoadTacbits(i,tacbits); if (error){ lprintf("Error setting up TAC voltages. Exiting\n"); return -1; } // loop over channels for (int j=0;j<32;j++){ if ((0x1<<j) & channelMask){ xl3s[crateNum]->RW(PED_ENABLE_R + FEC_SEL*i + WRITE_REG,1<<j,&result); max_gtvalid[j] = 0; // first try with the default ISETM error+= xl3s[crateNum]->LoadsDac(d_isetm[0],ISETM_MAX_GTVALID,i); error+= xl3s[crateNum]->LoadsDac(d_isetm[1],ISETM_MAX_GTVALID,i); if (IsGTValidLonger(crateNum,i,GTMAX)){ max_gtvalid[j] = GTMAX; max_isetm[j] = ISETM_MAX_GTVALID; }else{ // scan to see if any ISETM value puts this channel over GTMAX int done = 0; for (int k=0;k<8;k++){ float max_time = 1000.0-100.0*k; for (int l=0;l<50;l++){ uint32_t isetm_temp = l*5; error+= xl3s[crateNum]->LoadsDac(d_isetm[0],isetm_temp,i); error+= xl3s[crateNum]->LoadsDac(d_isetm[1],isetm_temp,i); if (IsGTValidLonger(crateNum,i,max_time)){ max_gtvalid[j] = max_time; max_isetm[j] = isetm_temp; done = 1; break; } } if (done) break; } // if the max gtvalid time is too small, fail this channel if (max_gtvalid[j] == 0) chan_errors[j] = 1; } } // end channel mask } // end loop over channels // ok we now know what the max gtvalid is for each channel and what // isetm value will get us it // now we increment isetm until every channels gtvalid is shorter than // gtcutoff for (int wt=0;wt<2;wt++){ lprintf("Finding ISETM values for crate %d, slot %d TAC %d\n", crateNum,i,wt); int ot = (wt+1)%2; isetm[wt] = ISETM_MIN; for (int j=0;j<32;j++){ lprintf("."); fflush(stdout); xl3s[crateNum]->RW(PED_ENABLE_R + FEC_SEL*i + WRITE_REG,1<<j,&result); error+= xl3s[crateNum]->LoadsDac(d_isetm[ot],max_isetm[j],i); while (isetm[wt] < 255){ error+= xl3s[crateNum]->LoadsDac(d_isetm[wt],isetm[wt],i); if (IsGTValidLonger(crateNum,i,gtCutoff)){ isetm[wt]++; }else{ break; } } } for (int j=0;j<32;j++){ lprintf("."); fflush(stdout); xl3s[crateNum]->RW(PED_ENABLE_R + FEC_SEL*i + WRITE_REG,1<<j,&result); error+= xl3s[crateNum]->LoadsDac(d_isetm[ot],max_isetm[j],i); while (isetm[wt] < 255){ error+= xl3s[crateNum]->LoadsDac(d_isetm[wt],isetm[wt],i); if (IsGTValidLonger(crateNum,i,gtCutoff)){ isetm[wt]++; printf("incremented again!\n"); }else{ break; } } } printf("\n"); } // end loop over tacs // we are done getting our dac values. lets measure and display the final gtvalids for (int wt=0;wt<2;wt++){ lprintf("\nMeasuring GTVALID for crate %d, slot %d, TAC %d\n", crateNum,i,wt); // loop over channel to measure inital GTVALID and find channel with max for (int j=0;j<32;j++){ if ((0x1<<j) & channelMask){ error+= xl3s[crateNum]->LoadsDac(d_isetm[0],isetm[0],i); error+= xl3s[crateNum]->LoadsDac(d_isetm[1],isetm[1],i); xl3s[crateNum]->RW(PED_ENABLE_R + FEC_SEL*i + WRITE_REG,1<<j,&result); gtvalid_final[wt][j] = MeasureGTValid(crateNum,i,wt,max_gtvalid[j],max_isetm[j]); } // end if chan mask } // end loop over channels // find maximum gtvalid time gmax[wt] = 0.0; cmax[wt] = 0; for (int j=0;j<32;j++) if ((0x1<<j) & channelMask) if (gtvalid_final[wt][j] > gmax[wt]){ gmax[wt] = gtvalid_final[wt][j]; cmax[wt] = j; } // find minimum gtvalid time gmin[wt] = 9999.0; cmin[wt] = 0; for (int j=0;j<32;j++) if ((0x1<<j) & channelMask) if (gtvalid_final[wt][j] < gmin[wt]){ gmin[wt] = gtvalid_final[wt][j]; cmin[wt] = j; } } // end loop over tacs // print out lprintf("\n--------------------------------------------------------\n"); lprintf("Crate %d Slot %d - GTVALID FINAL results, time in ns:\n",crateNum,i); lprintf("--------------------------------------------------------\n"); if (!twiddleOn) lprintf(" >>> ISETA0/1 = 0, no TAC twiddle bits set\n"); lprintf("set up: VMAX: %hu, TACREF: %hu, ",VMAX,TACREF); if (twiddleOn) lprintf("ISETA: %hu\n",ISETA); else lprintf("ISETA: %hu\n",ISETA_NO_TWIDDLE); lprintf("Found ISETM0: %d, ISETM1: %d\n",isetm[0],isetm[1]); lprintf("Chan Tacbits GTValid 0/1:\n"); for (int j=0;j<32;j++){ if ((0x1<<j) & channelMask){ lprintf("%02d 0x%02x %4.1f %4.1f", j,tacbits[j], gtvalid_final[0][j],gtvalid_final[1][j]); if (isetm[0] == ISETM_MIN || isetm[1] == ISETM_MIN) lprintf(">>> Warning: isetm not adjusted\n"); else lprintf("\n"); } } lprintf(">>> Maximum TAC0 GTValid - Chan %02d: %4.1f\n", cmax[0],gmax[0]); lprintf(">>> Minimum TAC0 GTValid - Chan %02d: %4.1f\n", cmin[0],gmin[0]); lprintf(">>> Maximum TAC1 GTValid - Chan %02d: %4.1f\n", cmax[1],gmax[1]); lprintf(">>> Minimum TAC1 GTValid - Chan %02d: %4.1f\n", cmin[1],gmin[1]); if (abs(isetm[1] - isetm[0]) > 10) slot_errors |= 0x1; for (int j=0;j<32;j++){ if ((gtvalid_final[0][j] < 0) || gtvalid_final[1][j] < 0) chan_errors[j] = 1; } //store in DB if (updateDB){ lprintf("updating the database\n"); JsonNode *newdoc = json_mkobject(); json_append_member(newdoc,"type",json_mkstring("cmos_m_gtvalid")); json_append_member(newdoc,"vmax",json_mknumber((double)VMAX)); json_append_member(newdoc,"tacref",json_mknumber((double)TACREF)); JsonNode* isetm_new = json_mkarray(); JsonNode* iseta_new = json_mkarray(); json_append_element(isetm_new,json_mknumber((double)isetm[0])); json_append_element(isetm_new,json_mknumber((double)isetm[1])); if (twiddleOn){ json_append_element(iseta_new,json_mknumber((double)ISETA)); json_append_element(iseta_new,json_mknumber((double)ISETA)); }else{ json_append_element(iseta_new,json_mknumber((double)ISETA_NO_TWIDDLE)); json_append_element(iseta_new,json_mknumber((double)ISETA_NO_TWIDDLE)); } json_append_member(newdoc,"isetm",isetm_new); json_append_member(newdoc,"iseta",iseta_new); JsonNode* channels = json_mkarray(); for (int j=0;j<32;j++){ JsonNode *one_chan = json_mkobject(); json_append_member(one_chan,"id",json_mknumber((double) j)); json_append_member(one_chan,"tac_shift",json_mknumber((double) (tacbits[j]))); json_append_member(one_chan,"gtvalid0",json_mknumber((double) (gtvalid_final[0][j]))); json_append_member(one_chan,"gtvalid1",json_mknumber((double) (gtvalid_final[1][j]))); json_append_member(one_chan,"errors",json_mkbool(chan_errors[j])); if (chan_errors[j]) slot_errors |= 0x2; json_append_element(channels,one_chan); } json_append_member(newdoc,"channels",channels); json_append_member(newdoc,"pass",json_mkbool(!(slot_errors))); json_append_member(newdoc,"slot_errors",json_mknumber(slot_errors)); if (finalTest) json_append_member(newdoc,"final_test_id",json_mkstring(finalTestIDs[crateNum][i])); if (ecal) json_append_member(newdoc,"ecal_id",json_mkstring(ecalID)); PostDebugDoc(crateNum,i,newdoc); json_delete(newdoc); // only delete the head } lprintf("******************************************\n"); } // end in slotmask } // end loop over slots } // end try catch(const char* s){ lprintf("GTValidTest: %s\n",s); } return 0; }
void *pt_final_test(void *args) { final_test_t arg = *(final_test_t *) args; free(args); int i; int result; // once this is set we can no longer send other commands running_final_test = 1; // now we can unlock our things, since nothing else should use them sbc_lock = 0; xl3_lock[arg.crate_num] = 0; fd_set thread_fdset; FD_ZERO(&thread_fdset); FD_SET(rw_xl3_fd[arg.crate_num],&thread_fdset); char ft_ids[16][250]; char id_string[16*250]; JsonNode *ft_docs[16]; char comments[1000]; memset(comments,'\0',1000); char command_buffer[100]; system("clear"); pt_printsend("------------------------------------------\n"); pt_printsend("Welcome to final test!\nHit enter to start\n"); read_from_tut(comments); pt_printsend("------------------------------------------\n"); do { sprintf(command_buffer,"crate_init -c %d -s %04x -x -v",arg.crate_num,arg.slot_mask); result = crate_init(command_buffer); if (result == -2 || result == -3){ return; } } while (result != 0); while (xl3_lock[arg.crate_num] != 0){} pt_printsend("------------------------------------------\n"); while (rw_sbc_fd <= 0){ pt_printsend("Attempting to connecting to sbc\n"); do { sprintf(command_buffer,"sbc_control"); } while (sbc_control(command_buffer) != 0); while (sbc_lock != 0){} } pt_printsend("------------------------------------------\n"); do { sprintf(command_buffer,"mtc_init -x"); result = mtc_init(command_buffer); if (result == -2 || result == -3){ return; } } while (result != 0); while (sbc_lock != 0 || xl3_lock[arg.crate_num] != 0){} pt_printsend("------------------------------------------\n"); pt_printsend("If any boards could not initialize properly, type \"quit\" now " "to exit the test.\n Otherwise hit enter to continue.\n"); read_from_tut(comments); if (strncmp("quit",comments,4) == 0){ pt_printsend("Exiting final test\n"); running_final_test = 0; unthread_and_unlock(1,(0x1<<arg.crate_num),arg.thread_num); return; } // set up the final test documents for (i=0;i<16;i++){ if ((0x1<<i) & arg.slot_mask){ get_new_id(ft_ids[i]); ft_docs[i] = json_mkobject(); sprintf(id_string+strlen(id_string),"%s ",ft_ids[i]); pt_printsend(".%s.\n",id_string); } } pt_printsend("Now starting board_id\n"); do { sprintf(command_buffer,"board_id -c %d -s %04x",arg.crate_num,arg.slot_mask); result = board_id(command_buffer); if (result == -2 || result == -3){ return; } } while (result != 0); while (xl3_lock[arg.crate_num] != 0){} pt_printsend("-------------------------------------------\n"); if (arg.skip == 0){ for (i=0;i<16;i++){ if ((0x1<<i) & arg.slot_mask){ pt_printsend("Please enter any comments for slot %i motherboard now.\n",i); read_from_tut(comments); json_append_member(ft_docs[i],"fec_comments",json_mkstring(comments)); pt_printsend("Has this slot been refurbished? (y/n)\n",i); read_from_tut(comments); json_append_member(ft_docs[i],"refurbished",json_mkbool(comments[0] == 'y')); pt_printsend("Has this slot been cleaned? (y/n)\n",i); read_from_tut(comments); json_append_member(ft_docs[i],"cleaned",json_mkbool(comments[0] == 'y')); pt_printsend("Time to measure resistance across analog outs and cmos address lines. For the cmos address lines" "it's easier if you do it during the fifo mod\n"); read_from_tut(comments); json_append_member(ft_docs[i],"analog_out_res",json_mkstring(comments)); pt_printsend("Please enter any comments for slot %i db 0 now.\n",i); read_from_tut(comments); json_append_member(ft_docs[i],"db0_comments",json_mkstring(comments)); pt_printsend("Please enter any comments for slot %i db 1 now.\n",i); read_from_tut(comments); json_append_member(ft_docs[i],"db1_comments",json_mkstring(comments)); pt_printsend("Please enter any comments for slot %i db 2 now.\n",i); read_from_tut(comments); json_append_member(ft_docs[i],"db2_comments",json_mkstring(comments)); pt_printsend("Please enter any comments for slot %i db 3 now.\n",i); read_from_tut(comments); json_append_member(ft_docs[i],"db3_comments",json_mkstring(comments)); pt_printsend("Please enter dark matter measurements for slot %i db 0 now.\n",i); read_from_tut(comments); json_append_member(ft_docs[i],"db0_dark_matter",json_mkstring(comments)); pt_printsend("Please enter dark matter measurements for slot %i db 1 now.\n",i); read_from_tut(comments); json_append_member(ft_docs[i],"db1_dark_matter",json_mkstring(comments)); pt_printsend("Please enter dark matter measurements for slot %i db 2 now.\n",i); read_from_tut(comments); json_append_member(ft_docs[i],"db2_dark_matter",json_mkstring(comments)); pt_printsend("Please enter dark matter measurements for slot %i db 3 now.\n",i); read_from_tut(comments); json_append_member(ft_docs[i],"db3_dark_matter",json_mkstring(comments)); } } pt_printsend("Enter N100 DC offset\n"); read_from_tut(comments); for (i=0;i<16;i++){ if ((0x1<<i) & arg.slot_mask){ json_append_member(ft_docs[i],"dc_offset_n100",json_mkstring(comments)); } } pt_printsend("Enter N20 DC offset\n"); read_from_tut(comments); for (i=0;i<16;i++){ if ((0x1<<i) & arg.slot_mask){ json_append_member(ft_docs[i],"dc_offset_n20",json_mkstring(comments)); } } pt_printsend("Enter esum hi DC offset\n"); read_from_tut(comments); for (i=0;i<16;i++){ if ((0x1<<i) & arg.slot_mask){ json_append_member(ft_docs[i],"dc_offset_esumhi",json_mkstring(comments)); } } pt_printsend("Enter esum lo DC offset\n"); read_from_tut(comments); for (i=0;i<16;i++){ if ((0x1<<i) & arg.slot_mask){ json_append_member(ft_docs[i],"dc_offset_esumlo",json_mkstring(comments)); } } pt_printsend("Thank you. Please hit enter to continue with the rest of final test. This may take a while.\n"); read_from_tut(comments); } // starting the tests pt_printsend("-------------------------------------------\n"); do { sprintf(command_buffer,"fec_test -c %d -s %04x -d -# %s",arg.crate_num,arg.slot_mask,id_string); result = fec_test(command_buffer); if (result == -2 || result == -3){ return; } } while (result != 0); while (xl3_lock[arg.crate_num] != 0){} pt_printsend("-------------------------------------------\n"); do { sprintf(command_buffer,"vmon -c %d -s %04x -d -# %s",arg.crate_num,arg.slot_mask,id_string); result = vmon(command_buffer); if (result == -2 || result == -3){ return; } } while (result != 0); while (xl3_lock[arg.crate_num] != 0){} pt_printsend("-------------------------------------------\n"); do { sprintf(command_buffer,"cgt_test_1 -c %d -s %04x -d -# %s",arg.crate_num,arg.slot_mask,id_string); result = cgt_test(command_buffer); if (result == -2 || result == -3){ return; } } while (result != 0); while (xl3_lock[arg.crate_num] != 0){} ////////////////////////////////////////////////////////////// // now gotta turn pulser on and off to get rid of garbage //sprintf(command_buffer,"readout_add_mtc -c %d -f 0",arg.crate_num); //readout_add_mtc(command_buffer); //sprintf(command_buffer,"stop_pulser"); //stop_pulser(command_buffer); ////////////////////////////////////////////////////////////// pt_printsend("-------------------------------------------\n"); do { sprintf(command_buffer,"ped_run -c %d -s %04x -l 300 -u 1000 -d -# %s",arg.crate_num,arg.slot_mask,id_string); result = ped_run(command_buffer); if (result == -2 || result == -3){ return; } } while (result != 0); while (xl3_lock[arg.crate_num] != 0){} pt_printsend("-------------------------------------------\n"); do { sprintf(command_buffer,"crate_cbal -c %d -s %04x -d -# %s",arg.crate_num,arg.slot_mask,id_string); result = crate_cbal(command_buffer); if (result == -2 || result == -3){ return; } } while (result != 0); while (xl3_lock[arg.crate_num] != 0){} ////////////////////////////////////////////////////////////// // now gotta turn pulser on and off to get rid of garbage //sprintf(command_buffer,"readout_add_mtc -c %d -f 0",arg.crate_num); //readout_add_mtc(command_buffer); //sprintf(command_buffer,"stop_pulser"); //stop_pulser(command_buffer); ////////////////////////////////////////////////////////////// pt_printsend("-------------------------------------------\n"); do { sprintf(command_buffer,"crate_init -c %d -s %04x -B",arg.crate_num,arg.slot_mask); result = crate_init(command_buffer); if (result == -2 || result == -3){ return; } } while (result != 0); while (xl3_lock[arg.crate_num] != 0){} pt_printsend("-------------------------------------------\n"); do { sprintf(command_buffer,"ped_run -c %d -s %04x -b -d -# %s",arg.crate_num,arg.slot_mask,id_string); result = ped_run(command_buffer); if (result == -2 || result == -3){ return; } } while (result != 0); while (xl3_lock[arg.crate_num] != 0){} pt_printsend("-------------------------------------------\n"); do { sprintf(command_buffer,"chinj_scan -c %d -s %04x -l 400 -u 5000 -w 100 -n 10 -d -# %s",arg.crate_num,arg.slot_mask,id_string); result = chinj_scan(command_buffer); if (result == -2 || result == -3){ return; } } while (result != 0); while (xl3_lock[arg.crate_num] != 0){} pt_printsend("-------------------------------------------\n"); if (arg.tub_tests == 1){ pt_printsend("You should now connect the cable to ext_ped for ttot tests\nHit enter when ready\n"); read_from_tut(comments); do { sprintf(command_buffer,"set_ttot -c %d -s %04x -t 400 -d -# %s",arg.crate_num,arg.slot_mask,id_string); result = set_ttot(command_buffer); if (result == -2 || result == -3){ return; } } while (result != 0); while (xl3_lock[arg.crate_num] != 0){} } pt_printsend("-------------------------------------------\n"); do { sprintf(command_buffer,"crate_init -c %d -s %04x -B -D",arg.crate_num,arg.slot_mask); result = crate_init(command_buffer); if (result == -2 || result == -3){ return; } } while (result != 0); while (xl3_lock[arg.crate_num] != 0){} pt_printsend("-------------------------------------------\n"); if (arg.tub_tests == 1){ do { sprintf(command_buffer,"get_ttot -c %d -s %04x -t 390 -d -# %s",arg.crate_num,arg.slot_mask,id_string); result = get_ttot(command_buffer); if (result == -2 || result == -3){ return; } } while (result != 0); while (xl3_lock[arg.crate_num] != 0){} } pt_printsend("-------------------------------------------\n"); pt_printsend("You should now disconnect the cable to ext_ped\nHit enter when ready\n"); read_from_tut(comments); do { sprintf(command_buffer,"disc_check -c %d -s %04x -n 500000 -d -# %s",arg.crate_num,arg.slot_mask,id_string); result = disc_check(command_buffer); if (result == -2 || result == -3){ return; } } while (result != 0); while (xl3_lock[arg.crate_num] != 0){} pt_printsend("-------------------------------------------\n"); do { sprintf(command_buffer,"cmos_m_gtvalid -c %d -s %04x -g 400 -n -d -# %s",arg.crate_num,arg.slot_mask,id_string); result = cmos_m_gtvalid(command_buffer); if (result == -2 || result == -3){ return; } } while (result != 0); while (xl3_lock[arg.crate_num] != 0){} // would put see_reflections here pt_printsend("-------------------------------------------\n"); do { sprintf(command_buffer,"zdisc -c %d -s %04x -o 0 -r 100 -d -# %s",arg.crate_num,arg.slot_mask,id_string); result = zdisc(command_buffer); if (result == -2 || result == -3){ return; } } while (result != 0); while (xl3_lock[arg.crate_num] != 0){} pt_printsend("-------------------------------------------\n"); do { sprintf(command_buffer,"mtc_init"); result = mtc_init(command_buffer); if (result == -2 || result == -3){ return; } } while (result != 0); while (sbc_lock != 0){} pt_printsend("-------------------------------------------\n"); do { sprintf(command_buffer,"crate_init -c %d -s %04x -x",arg.crate_num,arg.slot_mask); result = crate_init(command_buffer); if (result == -2 || result == -3){ return; } } while (result != 0); while (xl3_lock[arg.crate_num] != 0){} pt_printsend("-------------------------------------------\n"); do{ sprintf(command_buffer,"mb_stability_test -c %d -s %04x -n 50 -d -# %s",arg.crate_num,arg.slot_mask,id_string); result = mb_stability_test(command_buffer); if (result == -2 || result == -3){ return; } } while (result != 0); while (xl3_lock[arg.crate_num] != 0){} pt_printsend("-------------------------------------------\n"); do { sprintf(command_buffer,"fifo_test -c %d -s %04x -d -# %s",arg.crate_num,arg.slot_mask,id_string); result = fifo_test(command_buffer); if (result == -2 || result == -3){ return; } } while (result != 0); while (xl3_lock[arg.crate_num] != 0){} pt_printsend("-------------------------------------------\n"); do { sprintf(command_buffer,"crate_init -c %d -s %04x -X",arg.crate_num,arg.slot_mask); result = crate_init(command_buffer); if (result == -2 || result == -3){ return; } } while (result != 0); while (xl3_lock[arg.crate_num] != 0){} pt_printsend("-------------------------------------------\n"); do { sprintf(command_buffer,"cald_test -c %d -s %04x -l 750 -u 3500 -n 200 -d -# %s",arg.crate_num,arg.slot_mask,id_string); result = cald_test(command_buffer); if (result == -2 || result == -3){ return; } } while (result != 0); while (xl3_lock[arg.crate_num] != 0){} for (i=0;i<16;i++){ if ((0x1<<i) & arg.slot_mask){ do { pt_printsend("-------------------------------------------\n"); do { sprintf(command_buffer,"crate_init -c %d -s %04x -x",arg.crate_num,arg.slot_mask); result = crate_init(command_buffer); if (result == -2 || result == -3){ return; } } while (result != 0); while (xl3_lock[arg.crate_num] != 0){} pt_printsend("-------------------------------------------\n"); sprintf(command_buffer,"mem_test -c %d -s %d -d -# %s",arg.crate_num,i,ft_ids[i]); result = mem_test(command_buffer); if (result == -2 || result == -3){ return; } } while (result != 0); while (xl3_lock[arg.crate_num] != 0){} } } pt_printsend("-------------------------------------------\n"); do { sprintf(command_buffer,"crate_init -c %d -s %04x -x",arg.crate_num,arg.slot_mask); result = crate_init(command_buffer); if (result == -2 || result == -3){ return; } } while (result != 0); while (xl3_lock[arg.crate_num] != 0){} pt_printsend("-------------------------------------------\n"); pt_printsend("Ready for see_refl test. Hit enter to begin or type \"skip\" to end the final test.\n"); read_from_tut(comments); if (strncmp("skip",comments,4) != 0){ do { sprintf(command_buffer,"see_refl -c %d -s %04x -d -# %s",arg.crate_num,arg.slot_mask,id_string); result = see_refl(command_buffer); if (result == -2 || result == -3){ return; } } while (result != 0); while (xl3_lock[arg.crate_num] != 0){} } pt_printsend("-------------------------------------------\n"); pt_printsend("Final test finished. Now updating the database.\n"); // update the database for (i=0;i<16;i++){ if ((0x1<<i) & arg.slot_mask){ json_append_member(ft_docs[i],"type",json_mkstring("final_test")); pthread_mutex_lock(&socket_lock); xl3_lock[arg.crate_num] = 1; // we gotta lock this shit down before we call post_doc pthread_mutex_unlock(&socket_lock); post_debug_doc_with_id(arg.crate_num, i, ft_ids[i], ft_docs[i],&thread_fdset); json_delete(ft_docs[i]); } } pt_printsend("-------------------------------------------\n"); running_final_test = 0; unthread_and_unlock(1,(0x1<<arg.crate_num),arg.thread_num); }