diff --git a/pipelined-cpu/srcs/board/cpu21_board_top.v b/pipelined-cpu/srcs/board/cpu21_board_top.v index 7e6022d..f5e87c5 100644 --- a/pipelined-cpu/srcs/board/cpu21_board_top.v +++ b/pipelined-cpu/srcs/board/cpu21_board_top.v @@ -54,8 +54,12 @@ module cpu21_board_top #( parameter integer CLK_DIV_INTRUPT = 32, // 鼠标事件源:0 = 板上 5 向按键(免外设,默认);1 = PS/2 鼠标(Pmod JA) parameter integer USE_PS2_MOUSE = 1, // 1 = 启用板载 USB HID 口(PS/2 键鼠),板载按键同时有效 - // 调试:1 = 把 PS/2 收到的字节数显示在 LED[15:3](LED[2:0] 仍是中断指示)。 - // 验证 PS/2 通不通时打开:鼠标一动数字就跳;一直是 0 说明根本没收到 PS/2 数据。 + // 调试:1 = 用 LED 高位显示 PS/2 诊断信息: + // LED[15:6] = PS/2 收到的字节数低 10 位(一动鼠标就跳 = 收发都通了) + // LED[5] = ps2_clk 有边沿活动(时钟在动就快速翻转) + // LED[4] = ps2_data 当前电平 + // LED[3] = ps2_clk 当前电平 + // LED[2:0] 始终是三路中断指示。 parameter integer DEBUG_PS2_RX_LED = 1, // 5 向按键去抖的采样周期(CPU 周期数):上板默认 50000(1 ms @50 MHz)。 // 仿真里可以传一个小值,让"按一下"在几十微秒内就被识别。 @@ -341,10 +345,31 @@ module cpu21_board_top #( end end - // LED[15:3] 平时熄灭;DEBUG_PS2_RX_LED=1 时用它显示 PS/2 收到的字节数, - // 便于在没有调试器的情况下判断"鼠标到底有没有数据进来"。 - assign led = (DEBUG_PS2_RX_LED != 0) ? {ps2_rx_count[12:0], irq_led_q} - : {{13{1'b0}}, irq_led_q}; + // ---- PS/2 输入诊断:把两根线的电平与活动情况摆到 LED 上, + // 便于判断"板载 USB HID 芯片到底有没有在发 PS/2 数据" ---- + reg ps2_clk_s1, ps2_clk_s2, ps2_data_s1, ps2_data_s2; + reg [7:0] ps2_edge_cnt; + always @(posedge clk_cpu or posedge reset) begin + if (reset) begin + ps2_clk_s1 <= 1'b1; + ps2_clk_s2 <= 1'b1; + ps2_data_s1 <= 1'b1; + ps2_data_s2 <= 1'b1; + ps2_edge_cnt <= 8'd0; + end else begin + ps2_clk_s1 <= ps2_clk; + ps2_clk_s2 <= ps2_clk_s1; + ps2_data_s1 <= ps2_data; + ps2_data_s2 <= ps2_data_s1; + if (ps2_clk_s1 != ps2_clk_s2) + ps2_edge_cnt <= ps2_edge_cnt + 8'd1; + end + end + + // LED[15:3] 平时熄灭;DEBUG_PS2_RX_LED=1 时显示 PS/2 诊断信息(含义见参数注释) + assign led = (DEBUG_PS2_RX_LED != 0) + ? {ps2_rx_count[9:0], ps2_edge_cnt[0], ps2_data_s2, ps2_clk_s2, irq_led_q} + : {{13{1'b0}}, irq_led_q}; reg [23:0] led_we_cnt;