Skip to content

Commit e8feb9a

Browse files
Cleanup of Crorc class
1 parent cfd46e3 commit e8feb9a

File tree

2 files changed

+41
-59
lines changed

2 files changed

+41
-59
lines changed

src/Crorc/Crorc.cxx

Lines changed: 39 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
/// \file Crorc.cxx
22
/// \brief Implementation of low level C-RORC functions
33
///
4-
/// This scary looking file is a work in progress translation of the low-level C interface
4+
/// This scary looking file is a work in progress translation of the old C interface.
5+
/// It contains functions that do the nitty-gritty low-level communication with the C-RORC.
6+
/// Much of it is not fully understood.
57
///
68
/// \author Pascal Boeschoten ([email protected])
79

@@ -389,24 +391,12 @@ void Crorc::stopDataReceiver()
389391
}
390392
}
391393

392-
/* ddlSendCommand sends one command to the given link.
393-
* Parameters: dev pointer to roc device. It defines the link
394-
* where the command will be sent
395-
* dest command destination: 0 RORC, 1 DIU, 2 SIU, 4 FEE.
396-
* if -1 then the full command is in the
397-
* command field
398-
* command command code
399-
* transid transaction id
400-
* param command parameter,
401-
* or the full command if dest == -1
402-
* time if > 0 then test if command can be sent and
403-
* wait as many cycles if necessary.
404-
*
405-
* Returns:
406-
* RORC_STATUS_OK (0) if command sent
407-
* RORC_TIMEOUT (-64) if the command can not be sent in timeout.
408-
* RORC_LINK_NOT_ON (-4) if destination > 1 and the link is not on
409-
*/
394+
/// Sends one command to the given link.
395+
/// \param dest Command destination: 0 RORC, 1 DIU, 2 SIU, 4 FEE. If -1 then the full command is in the command field.
396+
/// \param command Command code
397+
/// \param transid Transaction ID
398+
/// \param param Command parameter, or the full command if dest == -1
399+
/// \param time If > 0 then test if command can be sent and wait as many cycles if necessary.
410400
void Crorc::ddlSendCommand(int dest, uint32_t command, int transid, uint32_t param, long long int time)
411401
{
412402
uint32_t com;
@@ -438,17 +428,9 @@ void Crorc::ddlSendCommand(int dest, uint32_t command, int transid, uint32_t par
438428
putCommandRegister(com);
439429
}
440430

431+
/// Checks whether status mail box or register is not empty in timeout
432+
/// \param timeout Number of check cycles
441433
void Crorc::ddlWaitStatus(long long int timeout)
442-
443-
/* Checks whether status mail box or register is not empty in timeout
444-
*
445-
* Parameters: prorc pointer to pRORC device
446-
* timeout # of check cycles
447-
*
448-
* Returns: # of executed cycles
449-
*
450-
*/
451-
452434
{
453435
for (int i = 0; i < timeout; ++i) {
454436
if (checkRxStatus()) {
@@ -458,10 +440,9 @@ void Crorc::ddlWaitStatus(long long int timeout)
458440
BOOST_THROW_EXCEPTION(TimeoutException() << ErrorInfo::Message("Timed out waiting on DDL"));
459441
}
460442

443+
/// Call ddlWaitStatus() before this routine if status timeout is needed
461444
StWord Crorc::ddlReadStatus()
462445
{
463-
/* call ddlWaitStatus() before this routine
464-
if status timeout is needed */
465446
StWord stw;
466447
stw.stw = read(Rorc::C_DSR);
467448
// printf("ddlReadStatus: status = %08lx\n", stw.stw);
@@ -470,16 +451,16 @@ StWord Crorc::ddlReadStatus()
470451

471452
StWord Crorc::ddlReadDiu(int transid, long long int time)
472453
{
473-
/* prepare and send DDL command */
454+
/// Prepare and send DDL command
474455
int destination = Ddl::Destination::DIU;
475456
ddlSendCommand(destination, Rorc::RandCIFST, transid, 0, time);
476457
ddlWaitStatus(time);
477458
StWord stw = ddlReadStatus();
478459
if (stw.part.code != Rorc::IFSTW || stw.part.trid != transid || stw.part.dest != destination) {
479460
BOOST_THROW_EXCEPTION(
480461
Exception() << ErrorInfo::Message("Unexpected DIU STW (not IFSTW)")
481-
<< ErrorInfo::StwExpected(b::str(b::format("0x00000%x%x%x") % transid % Rorc::IFSTW % destination))
482-
<< ErrorInfo::StwReceived(b::str(b::format("0x%08lx") % stw.stw)));
462+
<< ErrorInfo::StwExpected((b::format("0x00000%x%x%x") % transid % Rorc::IFSTW % destination).str())
463+
<< ErrorInfo::StwReceived((b::format("0x%08lx") % stw.stw).str()));
483464
}
484465

485466
stw = ddlReadCTSTW(transid, destination, time); // XXX Not sure why we do this...
@@ -493,41 +474,42 @@ StWord Crorc::ddlReadCTSTW(int transid, int destination, long long int time){
493474
|| stw.part.trid != transid || stw.part.dest != destination) {
494475
BOOST_THROW_EXCEPTION(
495476
Exception() << ErrorInfo::Message("Unexpected STW (not CTSTW)")
496-
<< ErrorInfo::StwExpected(b::str(b::format("0x00000%x%x%x") % transid % Rorc::CTSTW % destination))
497-
<< ErrorInfo::StwReceived(b::str(b::format("0x%08lx") % stw.stw)));
477+
<< ErrorInfo::StwExpected((b::format("0x00000%x%x%x") % transid % Rorc::CTSTW % destination).str())
478+
<< ErrorInfo::StwReceived((b::format("0x%08lx") % stw.stw).str()));
498479
}
499480
return stw;
500481
}
501482

502483
StWord Crorc::ddlReadSiu(int transid, long long int time)
503484
{
504-
/* prepare and send DDL command */
485+
// prepare and send DDL command
505486
int destination = Ddl::Destination::SIU;
506487
ddlSendCommand(destination, Rorc::RandCIFST, transid, 0, time);
507488

508-
/* read and check the answer */
489+
// read and check the answer
509490
ddlWaitStatus(time);
510491
StWord stw = ddlReadStatus();
511492
if (stw.part.code != Rorc::IFSTW || stw.part.trid != transid || stw.part.dest != destination) {
512493
BOOST_THROW_EXCEPTION(
513494
Exception() << ErrorInfo::Message("Unexpected SIU STW (not IFSTW)")
514-
<< ErrorInfo::StwExpected(b::str(b::format("0x00000%x%x%x") % transid % Rorc::IFSTW % destination))
515-
<< ErrorInfo::StwReceived(b::str(b::format("0x%08lx") % stw.stw)));
495+
<< ErrorInfo::StwExpected((b::format("0x00000%x%x%x") % transid % Rorc::IFSTW % destination).str())
496+
<< ErrorInfo::StwReceived((b::format("0x%08lx") % stw.stw).str()));
516497
}
517498

518499
stw = ddlReadStatus();
519500
if ((stw.part.code != Rorc::CTSTW && stw.part.code != Rorc::ILCMD && stw.part.code != Rorc::CTSTW_TO)
520501
|| stw.part.trid != transid || stw.part.dest != destination) {
521502
BOOST_THROW_EXCEPTION(
522503
Exception() << ErrorInfo::Message("Unexpected SIU STW (not CTSTW)")
523-
<< ErrorInfo::StwExpected(b::str(b::format("0x00000%x%x%x") % transid % Rorc::CTSTW % destination))
524-
<< ErrorInfo::StwReceived(b::str(b::format("0x%08lx") % stw.stw)));
504+
<< ErrorInfo::StwExpected((b::format("0x00000%x%x%x") % transid % Rorc::CTSTW % destination).str())
505+
<< ErrorInfo::StwReceived((b::format("0x%08lx") % stw.stw).str()));
525506
}
526507
return stw;
527508
}
528509

529-
/// Interpret DIU or SIU IFSTW
530-
void ddlInterpretIFSTW(uint32_t ifstw)
510+
/// Interpret DIU or SIU IFSTW to user readable messages
511+
/// Unused, kept for now as "documentation"
512+
std::vector<std::string> ddlInterpretIFSTW(uint32_t ifstw)
531513
{
532514
using namespace Ddl;
533515
using Table = std::vector<std::pair<uint32_t, const char*>>;
@@ -624,15 +606,14 @@ void ddlInterpretIFSTW(uint32_t ifstw)
624606
}
625607
checkTableExclusive(mask(status, SIUSTMASK), portTable);
626608
}
609+
610+
return messages;
627611
}
628612

613+
/// Tries to reset the SIU.
614+
/// \param cycle Number of status checks
615+
/// \param time Number of cycles to wait for command sending and replies
629616
void Crorc::ddlResetSiu(int cycle, long long int time)
630-
/* ddlResetSiu tries to reset the SIU.
631-
* print # if != 0 then print link status
632-
* cycle # of status checks
633-
* time # of cycles to wait for command sending and replies
634-
* Returns: SIU status word or -1 if no status word can be read
635-
*/
636617
{
637618
ddlSendCommand(Ddl::Destination::DIU, Ddl::SRST, 0, 0, time);
638619
ddlWaitStatus(time);
@@ -677,6 +658,7 @@ void Crorc::ddlResetSiu(int cycle, long long int time)
677658
BOOST_THROW_EXCEPTION(Exception() << ErrorInfo::Message("Failed to reset SIU"));
678659
}
679660

661+
/// Sends a reset command
680662
void Crorc::resetCommand(int option, const DiuConfig& diuConfig)
681663
{
682664
uint32_t command = 0;
@@ -708,9 +690,8 @@ void Crorc::resetCommand(int option, const DiuConfig& diuConfig)
708690
}
709691
}
710692

711-
/* try to empty D-RORC's data FIFOs
712-
empty_time: time-out value in usecs
713-
*/
693+
/// Try to empty D-RORC's data FIFOs
694+
/// \param timeoutMicroseconds Time-out value in usecs
714695
void Crorc::emptyDataFifos(int timeoutMicroseconds)
715696
{
716697
auto endTime = chrono::steady_clock::now() + chrono::microseconds(timeoutMicroseconds);
@@ -840,13 +821,13 @@ void Crorc::startDataReceiver(uintptr_t readyFifoBusAddress)
840821
StWord Crorc::ddlSetSiuLoopBack(const DiuConfig& diuConfig){
841822
long long int timeout = diuConfig.pciLoopPerUsec * Ddl::RESPONSE_TIME;
842823

843-
/* check SIU fw version */
824+
// Check SIU fw version
844825
ddlSendCommand(Ddl::Destination::SIU, Ddl::IFLOOP, 0, 0, timeout);
845826
ddlWaitStatus(timeout);
846827

847828
StWord stword = ddlReadStatus();
848829
if (stword.part.code == Rorc::ILCMD){
849-
/* illegal command => old version => send TSTMODE for loopback */
830+
// Illegal command => old version => send TSTMODE for loopback
850831
ddlSendCommand(Ddl::Destination::SIU, Ddl::TSTMODE, 0, 0, timeout);
851832
ddlWaitStatus(timeout);
852833
}
@@ -855,13 +836,13 @@ StWord Crorc::ddlSetSiuLoopBack(const DiuConfig& diuConfig){
855836
BOOST_THROW_EXCEPTION(Exception() << ErrorInfo::Message("Error setting SIU loopback"));
856837
}
857838

858-
/* SIU loopback command accepted => check SIU loopback status */
839+
// SIU loopback command accepted => check SIU loopback status
859840
stword = ddlReadSiu(0, timeout);
860841
if (stword.stw & Siu::LBMOD) {
861842
return stword; // SIU loopback set
862843
}
863844

864-
/* SIU loopback not set => set it */
845+
// SIU loopback not set => set it
865846
ddlSendCommand(Ddl::Destination::SIU, Ddl::IFLOOP, 0, 0, timeout);
866847

867848
ddlWaitStatus(timeout);
@@ -907,7 +888,7 @@ void Crorc::setLoopbackOn(){
907888

908889
void Crorc::setLoopbackOff()
909890
{
910-
// switches off both loopback and stop_on_error
891+
// Switches off both loopback and stop_on_error
911892
if (isLoopbackOn()) {
912893
toggleLoopback();
913894
}

src/Crorc/Crorc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <atomic>
99
#include <iostream>
1010
#include <string>
11+
#include <vector>
1112
#include <boost/optional.hpp>
1213
#include "ReadoutCard/ParameterTypes/GeneratorPattern.h"
1314
#include "ReadoutCard/RegisterReadWriteInterface.h"
@@ -182,7 +183,7 @@ class Crorc
182183
StWord ddlReadCTSTW(int transid, int destination, long long int time);
183184
void emptyDataFifos(int timeoutMicroseconds);
184185
StWord ddlSetSiuLoopBack(const DiuConfig& diuConfig);
185-
void ddlInterpretIFSTW(uint32_t ifstw);
186+
std::vector<std::string> ddlInterpretIFSTW(uint32_t ifstw);
186187
};
187188

188189
} // namespace Crorc

0 commit comments

Comments
 (0)