Skip to content

Commit

Permalink
add control signals
Browse files Browse the repository at this point in the history
  • Loading branch information
DX990307 committed Jun 17, 2024
1 parent ff94d18 commit f0d2196
Showing 1 changed file with 25 additions and 26 deletions.
51 changes: 25 additions & 26 deletions mem/mem/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,57 +457,56 @@ func (b ControlMsgBuilder) ToNotifyDone() ControlMsgBuilder {
return b
}

func (b ControlMsgBuilder) ToDrain() ControlMsgBuilder {
b.drain = true
func (b ControlMsgBuilder) WithDrain(flag bool) ControlMsgBuilder {
b.drain = flag
return b
}

func (b ControlMsgBuilder) ToValid() ControlMsgBuilder {
if b.invalid {
panic("Cannot set both valid and invalid bits")
}
b.valid = true
func (b ControlMsgBuilder) WithValid(flag bool) ControlMsgBuilder {
b.valid = flag
return b
}

func (b ControlMsgBuilder) ToInvalid() ControlMsgBuilder {
if b.valid {
panic("Cannot set both valid and invalid bits")
}
b.valid = true
func (b ControlMsgBuilder) WithInvalid(flag bool) ControlMsgBuilder {
b.valid = flag
return b
}

func (b ControlMsgBuilder) ToEnable() ControlMsgBuilder {
if b.disable {
panic("Cannot set both enable and disable bits")
}
b.enable = true
func (b ControlMsgBuilder) WithEnable(flag bool) ControlMsgBuilder {
b.enable = flag
return b
}

func (b ControlMsgBuilder) ToDisable() ControlMsgBuilder {
if b.enable {
panic("Cannot set both enable and disable bits")
}
b.disable = true
func (b ControlMsgBuilder) WithDisable(flag bool) ControlMsgBuilder {
b.disable = flag
return b
}

func (b ControlMsgBuilder) ToReset() ControlMsgBuilder {
b.reset = true
func (b ControlMsgBuilder) WithReset(flag bool) ControlMsgBuilder {
b.reset = flag
return b
}

func (b ControlMsgBuilder) ToPause() ControlMsgBuilder {
b.pause = true
func (b ControlMsgBuilder) WithPause(flag bool) ControlMsgBuilder {
b.pause = flag
return b
}

func (b *ControlMsgBuilder) checkconflits() {
if b.disable == b.enable {
panic("cannot set enable and disable with the same value")
}

if b.valid == b.invalid {
panic("cannot set valid and invalid with the same value")
}
}

// Build creates a new ControlMsg.
func (b ControlMsgBuilder) Build() *ControlMsg {
m := &ControlMsg{}
m.ID = sim.GetIDGenerator().Generate()
b.checkconflits()
m.Src = b.src
m.Dst = b.dst
m.TrafficBytes = controlMsgByteOverhead
Expand Down

0 comments on commit f0d2196

Please sign in to comment.