package Top; import Counter::*; import StmtFSM::*; typedef struct { Integer active; Integer fporch; Integer sync; Integer bporch; } SyncDescriptor; SyncDescriptor horizontal = SyncDescriptor{ active: 640, fporch: 16, sync: 96, bporch: 48 }; SyncDescriptor vertical = SyncDescriptor{ active: 480, fporch: 10, sync: 2, bporch: 33 }; interface SyncGenerator; method Action tick(); method Bool preedge(); method Bool out_n(); method Bool out(); method Bool active(); endinterface interface ITop; (* always_ready *) method Bool paint(); (* always_ready *) method Bool hsync(); (* always_ready *) method Bool vsync(); endinterface (* synthesize *) module mkTop (ITop); Reg#(Bool) rPaint <- mkReg(False); Reg#(Bool) rHsync <- mkReg(False); Reg#(Bool) rVsync <- mkReg(False); let blank_line_fsm = seq // Sync pulse repeat (96) rHsync <= True; // Back porch repeat (48) rHsync <= False; // Visible area repeat (640) noAction; // Front porch repeat (16) noAction; endseq; let video_line_fsm = seq // Sync pulse repeat (96) rHsync <= True; // Back porch repeat (48) rHsync <= False; // Visible area repeat (640) rPaint <= True; // Front porch repeat (16) rPaint <= False; endseq; let frame_fsm = seq while (True) seq // Sync pulse repeat (2) par rVsync <= True; blank_line_fsm; endpar // Back porch repeat (33) par rVsync <= False; blank_line_fsm; endpar // Visible area repeat (480) video_line_fsm; // Front porch repeat (10) blank_line_fsm; endseq endseq; let fsm <- mkFSM(frame_fsm); rule run_timing (fsm.done()); fsm.start(); endrule method Bool paint = rPaint._read; method Bool hsync = rHsync._read; method Bool vsync = rVsync._read; endmodule endpackage