Skip to content

Commit d0729b4

Browse files
alice-mchkostorr
authored andcommitted
Fixed busy logic for SCA read/write commands
* Fixed busy logic for SCA read/write commands Both read and write commands should wait for the busy flag to be cleared before being executed. In particular, the current implementation of the Sea::read() function stored the `command` variable only once, and then directly tests the channel busy state with `barRead(sc_regs::SCA_RD_CMD.index)`. When the busy is cleared, the initial value of the `command` variable is passed to the `checkError()` function, and an exception is thrown because the busy bit was still set when the `barRead(sc_regs::SCA_RD_CMD.index)` was initially called to set the `command` variable. The proposed change in the busy logic guarantees that the `command` variable gets fresher at each loop, until the busy flag is cleared or the timeout is reached.
1 parent e1a125b commit d0729b4

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/Sca/Sca.cxx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ void Sca::init()
6666

6767
void Sca::write(uint32_t command, uint32_t data)
6868
{
69+
waitOnBusyClear();
6970
barWrite(sc_regs::SCA_WR_DATA.index, data);
7071
barWrite(sc_regs::SCA_WR_CMD.index, command);
7172
auto transactionId = (command >> 16) & 0xff;
@@ -83,17 +84,20 @@ void Sca::write(uint32_t command, uint32_t data)
8384

8485
Sca::ReadResult Sca::read()
8586
{
87+
waitOnBusyClear();
8688
auto data = barRead(sc_regs::SCA_RD_DATA.index);
8789
auto command = barRead(sc_regs::SCA_RD_CMD.index);
8890
/* printf("Sca::read DATA=0x%x CH=0x%x TR=0x%x CMD=0x%x\n", data,
8991
command >> 24, (command >> 16) & 0xff, command & 0xff);*/
9092

9193
auto endTime = std::chrono::steady_clock::now() + CHANNEL_BUSY_TIMEOUT;
9294
while (std::chrono::steady_clock::now() < endTime) {
93-
if (!isChannelBusy(barRead(sc_regs::SCA_RD_CMD.index))) {
95+
if (!isChannelBusy(command)) {
9496
checkError(command);
9597
return { command, data };
9698
}
99+
data = barRead(sc_regs::SCA_RD_DATA.index);
100+
command = barRead(sc_regs::SCA_RD_CMD.index);
97101
}
98102

99103
std::stringstream ss;

0 commit comments

Comments
 (0)