From 61a636d1cc482bd1a2d98d95075b99155ad050bf Mon Sep 17 00:00:00 2001 From: Till Harbaum Date: Fri, 6 Sep 2024 11:16:22 +0200 Subject: [PATCH] Small hid and mfp adjustments finally fixing #61 --- src/atarist/atarist.v | 10 +++---- src/misc/mcu_spi.v | 65 ++++++++++++++++++++++--------------------- 2 files changed, 39 insertions(+), 36 deletions(-) diff --git a/src/atarist/atarist.v b/src/atarist/atarist.v index 92e5e53..ff1cc01 100644 --- a/src/atarist/atarist.v +++ b/src/atarist/atarist.v @@ -132,8 +132,8 @@ end reg [31:0] clk_cnt_mfp; reg clk_mfp_en; -wire [31:0] SYSTEM_CLOCK = 32'd32084988; -wire [31:0] MFP_CLOCK = 32'd2457600; +localparam SYSTEM_CLOCK = 32'd32_084_988; +localparam MFP_CLOCK = 32'd2_457_600; always @(posedge clk_32) begin if(!porb) begin @@ -142,10 +142,10 @@ always @(posedge clk_32) begin end else begin clk_mfp_en <= 1'b0; - if(clk_cnt_mfp < SYSTEM_CLOCK/2) + if(clk_cnt_mfp < SYSTEM_CLOCK) clk_cnt_mfp <= clk_cnt_mfp + MFP_CLOCK; else begin - clk_cnt_mfp <= clk_cnt_mfp - (SYSTEM_CLOCK/2 - MFP_CLOCK); + clk_cnt_mfp <= clk_cnt_mfp - SYSTEM_CLOCK + MFP_CLOCK; clk_mfp_en <= 1'b1; end end @@ -533,7 +533,7 @@ mfp mfp ( /* ------------------------------------------------------------------------------ */ wire ikbd_tx, ikbd_rx; - + ikbd #( .DIV(4) ) ikbd ( .clk(clk_32), // clock is divided to 2MHz (/16 == 2^4) inside ikbd .res(peripheral_reset), diff --git a/src/misc/mcu_spi.v b/src/misc/mcu_spi.v index 7f96d17..da81e21 100644 --- a/src/misc/mcu_spi.v +++ b/src/misc/mcu_spi.v @@ -15,10 +15,10 @@ module mcu_spi ( output reg spi_io_dout, // byte interface to the various core components - output mcu_sys_strobe, // byte strobe for system control target - output mcu_hid_strobe, // byte strobe for HID target - output mcu_osd_strobe, // byte strobe for OSD target - output mcu_sdc_strobe, // byte strobe for SD card target + output reg mcu_sys_strobe, // byte strobe for system control target + output reg mcu_hid_strobe, // byte strobe for HID target + output reg mcu_osd_strobe, // byte strobe for OSD target + output reg mcu_sdc_strobe, // byte strobe for SD card target output mcu_start, input [7:0] mcu_sys_din, input [7:0] mcu_hid_din, @@ -54,56 +54,59 @@ always @(negedge spi_io_clk or posedge spi_io_ss) begin if(spi_cnt[2:0] == 3'd7) begin // latch byte and raise ready flag spi_data_in <= { spi_sr_in, spi_io_din }; - spi_data_in_ready <= 1'b1; + spi_data_in_ready <= !spi_data_in_ready; end // Clear data ready at bit 3. If the reading side // runs at 32 Mhz, this will work up to 64 MHz // SPI clock. At higher clocks the word width must // be increased. - if(spi_cnt[2:0] == 3'd3) - spi_data_in_ready <= 1'b0; +// if(spi_cnt[2:0] == 3'd3) +// spi_data_in_ready <= 1'b0; end end // always @ (negedge spi_io_clk or posedge spi_io_ss) -// bring received byte into local clock domain - - -reg spi_in_strobe; -reg [7:0] spi_target; -assign mcu_sys_strobe = spi_in_strobe && spi_target == 8'd0; -assign mcu_hid_strobe = spi_in_strobe && spi_target == 8'd1; -assign mcu_osd_strobe = spi_in_strobe && spi_target == 8'd2; -assign mcu_sdc_strobe = spi_in_strobe && spi_target == 8'd3; - reg [7:0] spi_in_data; assign mcu_start = spi_in_cnt == 2; assign mcu_dout = spi_in_data; +reg [7:0] spi_target; reg [3:0] spi_in_cnt; always @(posedge clk) begin reg [1:0] spi_data_in_readyD; + spi_data_in_readyD <= { spi_data_in_readyD[0], spi_data_in_ready }; + + mcu_sys_strobe <= 1'b0; + mcu_hid_strobe <= 1'b0; + mcu_osd_strobe <= 1'b0; + mcu_sdc_strobe <= 1'b0; if(spi_io_ss) spi_in_cnt <= 4'd0; - - if(spi_data_in_readyD == 2'b01) begin - // incoming SPI byte is now in local clock domain + else begin + // parse incoming bit whenever ready toggles + // if(spi_data_in_readyD == 2'b01) begin + if(spi_data_in_readyD[1] ^ spi_data_in_readyD[0]) begin + // incoming SPI byte is now in local clock domain - // first byte is target id. Else send external trigger - if(spi_in_cnt == 4'd0) - spi_target <= spi_data_in; - else begin - spi_in_strobe <= 1'b1; - spi_in_data <= spi_data_in; - end + // first byte is target id. Else send external trigger + if(spi_in_cnt == 4'd0) + spi_target <= spi_data_in; + else begin + if(spi_target == 8'd0) mcu_sys_strobe <= 1'b1; + if(spi_target == 8'd1) mcu_hid_strobe <= 1'b1; + if(spi_target == 8'd2) mcu_osd_strobe <= 1'b1; + if(spi_target == 8'd3) mcu_sdc_strobe <= 1'b1; + + spi_in_data <= spi_data_in; + end - if(spi_in_cnt != 4'd15) - spi_in_cnt <= spi_in_cnt + 4'd1; - end else - spi_in_strobe <= 1'b0; + if(spi_in_cnt != 4'd15) + spi_in_cnt <= spi_in_cnt + 4'd1; + end + end end wire [7:0] in_byte =