I'm writing an FPGA state machine in System Verilog to read bytes from a SPI port and parse them into commands to the FPGA. The "RXSPIBITS" state is used to read SPI bytes by multiple other states like "GetCommand" and "GetParams" so I've had to set up a ReturnState mechanism to tell the RXSPIBITS state where to return control.
Can a System Verilog TASK be used to encapsulate the RXSPIBITS state code to make it more easily reusable and callable from multiple other states?
Currently the state machine's RXSPIBITS Case code looks like this.
RXSPIBITS: begin
if (SCK_risingedge) begin
RxBits <= {RxBits[6:0], mosi};
BitCnt <= BitCnt + 1;
if (BitCnt == 7) state <= returnstate;
end
end
So instead of entering this state 8 times I'd like to just call a GetSPIByte TASK once and have the result returned to the code in the Task's calling state.
I've searched for answers but get conflicting results about whether this would be synthesizible in System Verilog. If it matters I'm using the Gowin IDE synthesizer.