@@ -67,40 +67,47 @@ def __init__(self):
6767 self .data_in = Signal (8 )
6868 self .in_rdy = Signal ()
6969 self .in_ack = Signal ()
70+ self .eof = Signal ()
71+
72+ self .uart_data_out = Signal (8 )
73+ self .uart_rdy = Signal ()
74+ self .uart_ack = Signal ()
7075
71- self .data_out = Signal (8 )
72- self .out_rdy = Signal ()
73- self .out_ack = Signal ()
7476
7577 def elaborate (self , platform ):
7678 m = Module ()
7779
78- # For simplicity, we just output the command and value when out_rdy is high
7980 with m .FSM (init = "Idle" ) as fsm :
8081 with m .State ("Idle" ):
81- with m .If (self .out_rdy & self .in_rdy ):
82- m .d .sync += self .data_out .eq (0xA5 ) # Start word
82+ with m .If (self .uart_rdy & self .in_ack ):
83+ m .d .sync += self .uart_data_out .eq (0xA5 ) # Start word
84+ m .d .sync += self .uart_ack .eq (1 )
8385 m .next = "Second start word"
86+ with m .Else ():
87+ m .d .sync += self .uart_ack .eq (0 )
88+ m .d .sync += self .in_rdy .eq (self .uart_rdy )
8489 with m .State ("Second start word" ):
85- with m .If (self .out_ack ):
86- m .d .sync += self .data_out .eq (0x0F ) # Second start word
87- m .next = "Output second start word"
88- with m .State ("Output second start word" ):
89- with m .If (self .out_ack ):
90- # For simplicity, we just output a fixed command and value
91- m .d .sync += self .data_out .eq (0b101 ) # Command
92- m .next = "Output command"
93- with m .State ("Output command" ):
94- with m .If (self .out_ack ):
95- m .d .sync += self .data_out .eq (0x34 ) # Value LSB
96- m .next = "Output value LSB"
97- with m .State ("Output value LSB" ):
98- with m .If (self .out_ack ):
99- m .d .sync += self .data_out .eq (0x12 ) # Value MSB
100- m .next = "Output value MSB"
101- with m .State ("Output value MSB" ):
102- with m .If (self .out_ack ):
103- m .d .sync += self .out_rdy .eq (0 ) # Done
90+ with m .If (self .uart_rdy & self .in_ack ):
91+ m .d .sync += self .uart_data_out .eq (0x0F ) # Second start word
92+ m .next = "Output values"
93+ with m .Else ():
94+ m .d .sync += self .uart_ack .eq (0 )
95+ m .d .sync += self .in_rdy .eq (self .uart_rdy )
96+ with m .State ("Output values" ):
97+ with m .If (self .uart_rdy & self .in_ack ):
98+ m .d .sync += self .uart_data_out .eq (self .data_in )
99+ with m .Else ():
100+ m .d .sync += self .uart_ack .eq (0 )
101+ m .d .sync += self .in_rdy .eq (self .uart_rdy )
102+ with m .If (self .eof ):
103+ m .next = "EOF"
104+ with m .State ("EOF" ):
105+ m .d .sync += self .uart_data_out .eq (0xFF ) # EOF marker
106+ with m .If (self .uart_rdy & self .in_ack ):
107+ m .d .sync += self .uart_ack .eq (1 )
104108 m .next = "Idle"
109+ with m .Else ():
110+ m .d .sync += self .uart_ack .eq (0 )
111+ m .d .sync += self .in_rdy .eq (self .uart_rdy )
105112
106113 return m
0 commit comments