Changeset 10757
- Timestamp:
- 05/20/11 10:03:04 (14 years ago)
- Location:
- fact/FADctrl
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/FADctrl/FAD.cc
r10642 r10757 20 20 const char *Help; 21 21 } CommandList[] = 22 {{"board", &FAD::cmd_board, true, 1, "[+|-]<range>" ,"Activate or deactivate board(s)"},22 {{"board", &FAD::cmd_board, false, 1, "[+|-]<range>" ,"Activate or deactivate board(s)"}, 23 23 {"status", &FAD::cmd_status, false, 0, "[range]", "Show board status information"}, 24 24 {"domino", &FAD::cmd_domino, true, 1, "<on|off>", "Switch Domino wave"}, … … 28 28 {"sclk", &FAD::cmd_sclk, true, 1, "<on|off>", "Set SCLK"}, 29 29 {"trigger", &FAD::cmd_trigger, false, 0, "[n|cont [rate]|stop|enable|disable]", "Issue software triggers"}, 30 {"reset _trigger", &FAD::cmd_reset_trigger, true, 0, "", "Reset internal trigger counter"},30 {"reset", &FAD::cmd_reset, true, 0, "", "Reset internal trigger counter"}, 31 31 {"runnumber", &FAD::cmd_runnumber, true, 1, "<n>", "Set runnumber"}, 32 32 {"roi", &FAD::cmd_roi, true, 2, "<channel range> <value>", "Set region-of-interest to value"}, … … 199 199 // 200 200 201 void FAD::cmd_reset _trigger() {201 void FAD::cmd_reset() { 202 202 203 203 for (unsigned int i=0; i<Boards.size(); i++) Boards[i]->Send(CMD_RESET_TRIGGER_ID); … … 379 379 Buffer[2*i+1] = htons(Value); 380 380 } 381 382 // Send command buffer 381 382 // Disable triggers for all boards and wait (workaround for firmware bug) 383 for (unsigned int i=0; i<Boards.size(); i++) Boards[i]->Send(CMD_TRIGGERS_OFF); 384 usleep(500000); 385 386 // Send command buffer and enable triggers again 383 387 for (unsigned int i=0; i<Boards.size(); i++) { 384 388 Boards[i]->Send(Buffer, sizeof(Buffer)); 389 Boards[i]->Send(CMD_TRIGGERS_ON); 385 390 } 386 391 } … … 542 547 FILE *File; 543 548 struct FADBoard::CalibData Data; 549 bool Found = false; 544 550 545 551 // Open file … … 553 559 PrintMessage("Found calibration for board %d - %s", i, ctime(&Data.Time)); 554 560 Boards[i]->ACalib = Data; 561 Found = true; 555 562 } 556 563 } 564 if (!Found) PrintMessage("Did not find calibration data for any board\n"); 565 557 566 //Close file 558 567 if (fclose(File) != 0) PrintMessage("Could not close file '%s'\n", Parameter[1].c_str()); … … 596 605 597 606 // Print list of active boards 598 PrintMessage("Active are %d boards(s)", Count);607 PrintMessage("Active (%d)\t", Count); 599 608 for (unsigned int i=0; i<Boards.size(); i++) { 600 609 if (Boards[i]->Active) PrintMessage(" %d%s", i, Boards[i]->CommOK ? "":"!"); 601 610 } 611 PrintMessage("\nInactive (%d) ", Boards.size()-Count); 612 for (unsigned int i=0; i<Boards.size(); i++) { 613 if (!Boards[i]->Active) PrintMessage(" %d%s", i, Boards[i]->CommOK ? "":"!"); 614 } 602 615 PrintMessage("\n"); 603 616 604 // Current mode617 // Print current mode 605 618 if (Mode == idle) PrintMessage("Current mode is IDLE\n"); 606 619 else if (Mode == acalib) PrintMessage("Current mode is ACALIB (3x%d events, slowest board %d has %d events)\n", NumEventsRequested, SlowestBoard, MinCount); … … 945 958 // Fill M0 BoardStructure 946 959 S = Boards[Brd]->GetStatus(); 947 BStruct[Brd]->SerialNo = S.BoardID;960 BStruct[Brd]->SerialNo = (U32) S.DNA; 948 961 BStruct[Brd]->NomFreq = S.Frequency; 949 962 BStruct[Brd]->BoardTemp = 0; -
fact/FADctrl/FAD.h
r10617 r10757 69 69 void cmd_board(); void cmd_status(); 70 70 void cmd_acalib(); void cmd_serial(); 71 void cmd_trigger(); 72 void cmd_runnumber(); void cmd_reset_trigger(); 73 void cmd_socketmode(); 71 void cmd_trigger(); void cmd_socketmode(); 72 void cmd_runnumber(); void cmd_reset(); 74 73 void cmd_srclk(); void cmd_sclk(); 75 74 void cmd_dwrite(); void cmd_domino(); -
fact/FADctrl/FADBoard.cc
r10642 r10757 33 33 pthread_mutexattr_t Attr; 34 34 35 if ((Ret = pthread_mutexattr_init(&Attr)) != 0) { 36 m->Message(m->ERROR, "pthread_mutex_init() failed in FADBoard constructor (%s)", strerror(Ret)); 37 } 35 38 if ((Ret = pthread_mutexattr_settype(&Attr, PTHREAD_MUTEX_ERRORCHECK)) != 0) { 36 m->Message(m->ERROR, "pthread_mutex_settype() failed (%s)", strerror(Ret));39 m->Message(m->ERROR, "pthread_mutex_settype() failed in FADBoard constructor (%s)", strerror(Ret)); 37 40 } 38 41 if ((Ret = pthread_mutex_init(&Mutex, &Attr)) != 0) { 39 m->Message(m->FATAL, "pthread_mutex_init() failed (%s)", strerror(Ret));42 m->Message(m->FATAL, "pthread_mutex_init() failed in FADBoard constructor (%s)", strerror(Ret)); 40 43 } 41 44 42 45 // Initialise condition variable for synchronization 43 46 if ((Ret = pthread_cond_init(&CondVar, NULL)) != 0) { 44 m->Message(m->FATAL, "pthread_cond_init() failed (%s)", strerror(Ret));47 m->Message(m->FATAL, "pthread_cond_init() failed in FADBoard constructor (%s)", strerror(Ret)); 45 48 } 46 49 … … 63 66 SetStatus("Trying to connect..."); 64 67 65 if ((Ret = pthread_create(&Thread, NULL, (void * (*)(void *)) LaunchThread, (void *) this)) != 0) {68 if ((Ret = pthread_create(&Thread, NULL, (void * (*)(void *)) LaunchThread, (void *) this)) != 0) { 66 69 m->Message(m->FATAL, "pthread_create() failed in FADBoard() (%s)", strerror(Ret)); 67 70 } … … 177 180 Count = 0; 178 181 179 // Save initial board status, set all ROIs to 1024 and set DAC values 182 // Save initial board status, set all ROIs to 1024 and set DAC values (no triggers while setting ROI) 180 183 InitialStatus = GetStatus(); 184 185 Send(CMD_TRIGGERS_OFF); 186 usleep(500000); 181 187 182 188 for (unsigned int i=0; i<NChips*NChannels; i++) { … … 191 197 Send(DACCmd, sizeof(DACCmd)); 192 198 199 Send(CMD_TRIGGERS_ON); 200 193 201 // Clear sum vector and set state to accumulate 194 202 memset(Sum, 0, sizeof(Sum)); 195 203 State = baseline; 204 SetStatus("Starting calilbration"); 196 205 break; 197 206 … … 319 328 } 320 329 330 SetStatus("Finished calibration"); 321 331 State = cleanup; 322 332 break; … … 325 335 case cleanup: 326 336 // ROI values 337 Send(CMD_TRIGGERS_OFF); 338 usleep(100000); 339 327 340 ROICmd.clear(); 328 341 for (unsigned int i=0; i<NChips*NChannels; i++) { … … 331 344 } 332 345 Send(&ROICmd[0], ROICmd.size()*sizeof(unsigned short)); 346 347 Send(CMD_TRIGGERS_ON); 333 348 334 349 // DAC values … … 421 436 // If not active, discard incoming data 422 437 if (!Active) continue; 423 438 424 439 // Advance write pointer 425 440 Pos += Result; … … 461 476 Lock(); 462 477 while (!Continue) { 463 if ((Ret = pthread_cond_wait(&CondVar, &Mutex)) != 0) { 464 m->Message(m->ERROR, "pthread_cond_wait() failed (%s)", strerror(Ret)); 478 struct timespec Wakeup; 479 Wakeup.tv_sec = time(NULL)+5; 480 Wakeup.tv_nsec = 0; 481 if ((Ret = pthread_cond_timedwait(&CondVar, &Mutex, &Wakeup)) != 0) { 482 if (Ret == ETIMEDOUT) printf("Board %s timed out (5 s) waiting for condition\n", Name); 483 else m->Message(m->ERROR, "pthread_cond_wait() failed (%s)", strerror(Ret)); 465 484 } 466 485 } … … 580 599 581 600 // 582 // Launch read thread inside class601 // Install cleanup handler and launch read thread inside class 583 602 // 584 603 void FADBoard::LaunchThread(class FADBoard *m) { 585 604 605 pthread_cleanup_push((void (*)(void *)) FADBoard::ThreadCleanup, (void *) m); 586 606 m->ReadLoop(); 607 pthread_cleanup_pop(0); 587 608 } 588 609 … … 631 652 } 632 653 654 // Ensure that mutex is unlocked when before cancelling thread 655 void FADBoard::ThreadCleanup(class FADBoard *This) { 656 657 int Ret; 658 659 if ((Ret = pthread_mutex_trylock(&This->Mutex)) != 0) { 660 if (Ret != EBUSY) This->m->Message(This->m->FATAL, "pthread_mutex_trylock() failed in FADBoard::ThreadCleanup (%s)", strerror(Ret)); 661 } 662 This->Unlock(); 663 } 633 664 634 665 // -
fact/FADctrl/FADBoard.h
r10642 r10757 33 33 void ReadLoop(); 34 34 static void LaunchThread(class FADBoard *); 35 static void ThreadCleanup(class FADBoard *); 35 36 void threadHandler(); 36 37 void SetStatus(const char *, ...); -
fact/FADctrl/History.txt
r10617 r10757 25 25 4/5/2011 Removed 'daqmode' (had no function). Added 'reset_trigger' and 'runnumber' commands. 26 26 Event format adapted (ADC data not sent in network byte order anymore). 27 20/5/2011 Missing pthread_mutexattr_init() in FADBoard constructor caused spurious errors when 28 locking mutex 29 Added cleanup handler to thread in FADBoard class to ensure mutex is unlocked when thread 30 cancelled
Note:
See TracChangeset
for help on using the changeset viewer.