Skip to content

Commit

Permalink
Decouple restoring credits from dequeuing an Rx FIFO
Browse files Browse the repository at this point in the history
  • Loading branch information
krame505 authored and quark17 committed Jan 3, 2024
1 parent d824b20 commit b151d96
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Libraries/GenC/GenCMsg/GenCMsg.bs
Original file line number Diff line number Diff line change
Expand Up @@ -307,19 +307,25 @@ instance (GenCRepr a gcrBytes, GenAllCDecls a, Bits a bBits) =>
fifo <- mkSizedFIFOF (valueOf bFIFOSize)
let credits :: Reg (UInt 8)
credits = head rxCredits

restoreCredits :: FIFOF ()
restoreCredits <- mkFIFOF

let fifo_o = Rx {
first = fifo.first;
deq = do { credits := credits + 1; fifo.deq };
deq = do { restoreCredits.enq (); fifo.deq };
notEmpty = fifo.notEmpty;
}

let ruleName = "handle_rx_" +++ stringOf name
let rs =
rules
ruleName: when rxTagEq (valueOf i + 1) ==> do
("handle_rx_" +++ stringOf name): when rxTagEq (valueOf i + 1) ==> do
fifo.enq (unpackBytes rxBody).fst
deq

("restore_credits_" +++ stringOf name): when True ==> do
restoreCredits.deq
credits := credits + 1

return (Meta $ Conc fifo_o, rs)

Expand Down Expand Up @@ -376,10 +382,9 @@ instance (GenCRepr a gcrBytes, GenAllCDecls a, Bits a bBits) =>
let credits :: Reg (UInt 8)
credits = head txCredits

let ruleName = "handle_tx_" +++ stringOf name
let rs =
rules
ruleName: when credits > 0 ==> do
("handle_tx_" +++ stringOf name): when credits > 0 ==> do
credits := credits - 1
enq (fromInteger $ valueOf i + 1) $ packBytes fifo.first
fifo.deq
Expand Down

0 comments on commit b151d96

Please sign in to comment.