From 4eac372cf29761f05d8ca0092808e9d5ca7bf0e9 Mon Sep 17 00:00:00 2001 From: Ryan Berg Date: Mon, 7 Dec 2015 01:21:48 -0500 Subject: [PATCH] it works! now with brams for metadata --- Nexys4Game/src/hdl/CL_block.v | 7 +- Nexys4Game/src/hdl/CL_metadata_controller.v | 130 +++++++++++++++----- Nexys4Game/src/hdl/SC_block.v | 12 -- Nexys4Game/src/hdl/SC_note_matching_sub.v | 74 ++++++----- 4 files changed, 140 insertions(+), 83 deletions(-) diff --git a/Nexys4Game/src/hdl/CL_block.v b/Nexys4Game/src/hdl/CL_block.v index 1d4a409..4f0453d 100644 --- a/Nexys4Game/src/hdl/CL_block.v +++ b/Nexys4Game/src/hdl/CL_block.v @@ -155,14 +155,13 @@ module CL_block( ////////////////////////////////////////////////////////////////////////////////// */ - wire [36:0] md_request; - assign md_request = metadata_request&(~pause); - CL_metadata_controller metadata_memory( + CL_metadata_controller metadata_controller( .clk(clk), .clk25(clk25), + .song_time(song_time), .write_en(write_data), .write_word(data_word), - .metadata_request(md_request), + .metadata_request(metadata_request), //TODO diff --git a/Nexys4Game/src/hdl/CL_metadata_controller.v b/Nexys4Game/src/hdl/CL_metadata_controller.v index 5e7088a..63fe254 100644 --- a/Nexys4Game/src/hdl/CL_metadata_controller.v +++ b/Nexys4Game/src/hdl/CL_metadata_controller.v @@ -1,6 +1,7 @@ module CL_metadata_controller( input clk, //100mhz clk input clk25, //25mhz clk + input [15:0] song_time, input write_en, //signals a new word to be written input [31:0] write_word, //word to be written input [36:0] metadata_request, @@ -15,15 +16,18 @@ module CL_metadata_controller( reg [11:0] new_pointer = 0; //1 clk delay on updating pointer */ + reg running; - + initial running = 0; initial loaded = 1; initial metadata_link = 0; + /* reg [255:0] note24; reg [255:0] note26; reg [255:0] note28; reg [255:0] note31; + initial begin note24[255:240] = 400; @@ -72,51 +76,109 @@ module CL_metadata_controller( note31[239:224] = 1600; note31[223:0] = 0; end + */ + + reg [3:0] addra24 = 0; + wire [15:0] douta24; + note24 note24( + .clka(clk), + .ena(1'b1), + .addra(addra24), + .douta(douta24) + ); + + reg [3:0] addra26 = 0; + wire [15:0] douta26; + note26 note26( + .clka(clk), + .ena(1'b1), + .addra(addra26), + .douta(douta26) + ); + + reg [3:0] addra28 = 0; + wire [15:0] douta28; + note28 note28( + .clka(clk), + .ena(1'b1), + .addra(addra28), + .douta(douta28) + ); + + reg [3:0] addra31 = 0; + wire [15:0] douta31; + note31 note31( + .clka(clk), + .ena(1'b1), + .addra(addra31), + .douta(douta31) + ); always @(posedge clk) begin - if(metadata_request[24] == 1) begin - metadata_link[24*16-1:23*16] <= note24[255:240]; - note24[255:0] <= {note24[240:0],16'b0}; + if(song_time > 5) + running <= 1; + + if(metadata_request[24] == 1 && running && metadata_available[24] == 0) begin + metadata_link[25*16-1:24*16] <= douta24; + if(addra24 < 15) + addra24 <= addra24 + 1; metadata_available[24] <= 1; - //if(note24[255:240] != 0) begin - // metadata_available[24] <= 1; - //end - //else - // metadata_available[24] <= 0; end - else metadata_available[24] <= 0; + else + metadata_available[24] <= 0; - if(metadata_request[26] == 1) begin - metadata_link[26*16-1:25*16] <= note26[255:240]; - note26[255:0] <= {note26[240:0],16'b0}; - if(note26[255:240] != 0) begin - metadata_available[26] <= 1; - end - else - metadata_available[26] <= 0; + if(metadata_request[26] == 1 && running && metadata_available[26] == 0) begin + metadata_link[27*16-1:26*16] <= douta26; + if(addra26 < 15) + addra26 <= addra26 + 1; + metadata_available[26] <= 1; end + else + metadata_available[26] <= 0; - if(metadata_request[28] == 1) begin - metadata_link[28*16-1:27*16] <= note28[255:240]; - note28[255:0] <= {note28[240:0],16'b0}; - if(note28[255:240] != 0) begin - metadata_available[28] <= 1; - end - else - metadata_available[28] <= 0; + if(metadata_request[28] == 1 && running && metadata_available[28] == 0) begin + metadata_link[29*16-1:28*16] <= douta28; + if(addra28 < 15) + addra28 <= addra28 + 1; + metadata_available[28] <= 1; end + else + metadata_available[28] <= 0; - if(metadata_request[31] == 1) begin - metadata_link[31*16-1:30*16] <= note31[255:240]; - note31[255:0] <= {note31[240:0],16'b0}; - if(note31[255:240] != 0) begin - metadata_available[31] <= 1; - end - else - metadata_available[31] <= 0; + if(metadata_request[31] == 1 && running && metadata_available[31] == 0) begin + metadata_link[32*16-1:31*16] <= douta31; + if(addra31 < 15) + addra31 <= addra31 + 1; + metadata_available[31] <= 1; end + else + metadata_available[31] <= 0; + + end + + + ila_metadata_controller dear_lord_save_me ( + .clk(clk), + .probe0(addra24), + .probe1(douta24), + .probe2(addra26), + .probe3(douta26), + .probe4(addra28), + .probe5(douta28), + .probe6(addra31), + .probe7(douta31), + + .probe8(metadata_link), + .probe9(metadata_available), + .probe10(metadata_request), + .probe11(running), + .probe12(song_time) + ); + + + /* reg we; reg [31:0] din; diff --git a/Nexys4Game/src/hdl/SC_block.v b/Nexys4Game/src/hdl/SC_block.v index e00aa43..b92281f 100644 --- a/Nexys4Game/src/hdl/SC_block.v +++ b/Nexys4Game/src/hdl/SC_block.v @@ -52,16 +52,4 @@ module SC_block( .score(score) ); - ila_SC_block help ( - .clk(clk), - .probe0(metadata_available), - .probe1(song_time), - .probe2(match_en), - .probe3(match_time), - .probe4(match_dt), - .probe5(score), - .probe6(metadata_link), - .probe7(metadata_request) - ); - endmodule \ No newline at end of file diff --git a/Nexys4Game/src/hdl/SC_note_matching_sub.v b/Nexys4Game/src/hdl/SC_note_matching_sub.v index 30c9526..ac2677d 100644 --- a/Nexys4Game/src/hdl/SC_note_matching_sub.v +++ b/Nexys4Game/src/hdl/SC_note_matching_sub.v @@ -1,6 +1,7 @@ module SC_note_matching_sub( input clk, input pause, + input reset, input [15:0] song_time, //current song time input note_edge, //if note has become active (must be a single-cycle pulse) input [15:0] note_time, //time of next note, or all 1's if no note in buffer @@ -14,47 +15,54 @@ module SC_note_matching_sub( localparam NOTE_TIMEOUT = 100; //time it takes for a note to no longer be considered, in 10ms (100 = 1s) initial past_note <= 0; - initial future_note <= 1000; + initial future_note <= 0; initial match_enable <= 0; initial match_time <= 0; always @(posedge clk) begin - - if(future_note < song_time && ~note_request) begin //if future note not in the future - past_note <= future_note; //shift in the new past_note - future_note <= 0; //invalid, will fail to match with extremely high probability due to overflow - end - - if(future_note == 0) begin - note_request <= 1; - end - - if(note_request && note_available) begin - note_request <= 0; //stop requesting - future_note <= note_time; //shift in new future note - end - - if(song_time > NOTE_TIMEOUT + past_note) begin //if nearest note is timed-out - past_note <= 0; //write invalid + if(reset) begin + past_note <= 0; + future_note <= 0; + note_request <= 0; + match_enable <= 0; + match_time <= 0; end - - if(note_edge && ~pause) begin - if( (song_time - past_note < future_note - song_time) && past_note != 0) - begin //match to past note. Note that if past_note is written invalid, this test will fail with extremely high probability - match_enable <= 1'b1; - match_time <= past_note; - past_note <= 0; + else begin + if(future_note < song_time && ~note_request) begin //if future note not in the future + past_note <= future_note; //shift in the new past_note + future_note <= 0; //invalid end - else if(future_note != 0 && (future_note - song_time < NOTE_TIMEOUT) ) begin //match to future note - match_enable <= 1'b1; - match_time <= future_note; - future_note <= 0; + + if(future_note == 0 && note_request == 0) begin //get a new note + note_request <= 1; + end + + if(note_request && note_available) begin + note_request <= 0; //stop requesting + future_note <= note_time; //shift in new future note + end + + if(song_time > NOTE_TIMEOUT + past_note) begin //if nearest note is timed-out + past_note <= 0; //write invalid + end + + if(note_edge && ~pause) begin + if( (song_time - past_note < future_note - song_time) && past_note != 0) + begin //match to past note + match_enable <= 1'b1; + match_time <= past_note; + past_note <= 0; + end + else if(future_note != 0 && (future_note - song_time < NOTE_TIMEOUT) ) begin //match to future note + match_enable <= 1'b1; + match_time <= future_note; + future_note <= 0; + end + end + else if(match_enable) begin //reset match_enable + match_enable <= 0; end end - else if(match_enable) begin //reset match_enable - match_enable <= 0; - end - end