voidshell_run(void) { printf("\n"); printf("========================================\n"); printf(" xOS - Simple Operating System\n"); printf(" for LoongArch32R SoC\n"); printf("========================================\n"); printf("\n"); printf("Type 'help' for available commands.\n"); printf("\n");
shell_print_prompt();
/* Main loop - keyboard input comes from interrupt buffer */ while (1) { int scancode = kb_get_scancode(); if (scancode >= 0) { process_scancode((uint8_t)scancode); } } }
voidps2_update(void) { // Cooldown period between scancodes if (ps2_cooldown > 0) { ps2_cooldown--; return; } // If currently injecting a scancode, keep valid signal high for a short time if (ps2_valid_signal) { if (ps2_inject_delay > 0) { ps2_inject_delay--; } else { // Clear valid signal after injection pulse complete ps2_clear_scancode(); // Start cooldown to give CPU time to process ps2_cooldown = PS2_COOLDOWN_CYCLES; } return; } // If queue has scancodes and we're not currently injecting if (!ps2_scancode_queue.empty()) { // Get next scancode from queue ps2_current_scancode = ps2_scancode_queue.front(); ps2_scancode_queue.pop();
// Set valid signal for a short pulse ps2_valid_signal = 1; ps2_inject_delay = PS2_VALID_CYCLES; } }
always @(posedge clk ornegedge resetn) begin if (!resetn) begin sim_scancode_valid_prev <= 1'b0; endelsebegin sim_scancode_valid_prev <= sim_scancode_valid; end end
// PS2 status register (read-only, directly from controller) wire [31:0] ps2_status = {28'd0, ps2_overflow, ps2_frame_err, ps2_parity_err, ps2_rx_valid}; always @(posedge clk) begin if (~resetn) begin conf_rdata_reg <= 32'd0; end elseif (conf_ren) begin case (conf_raddr[15:0]) ... `PS2_DATA_ADDR: conf_rdata_reg <= {24'd0, ps2_rx_data}; ...
always @(posedge clk) begin if (!resetn) begin ps2_ctrl_reg <= 32'h6; // Default: enable=1, int_enable=1, clear_err=0 ps2_rd_ack_reg <= 1'b0; end elsebegin // Read acknowledge: pulse when reading PS2_DATA ps2_rd_ack_reg <= conf_ren & (conf_raddr[15:0] == `PS2_DATA_ADDR);
// Write PS2_CTRL register if (write_ps2_ctrl) begin ps2_ctrl_reg <= conf_wdata[31:0]; end elsebegin // Auto-clear bit0 (clear_err) after one cycle ps2_ctrl_reg[0] <= 1'b0; end end end
voidps2_update2(void) { if (ps2_valid_signal) { ps2_clear_scancode(); } if (ps2_cooldown > 0) { ps2_cooldown--; return; } // If queue has scancodes and we're not currently injecting if (!ps2_scancode_queue.empty()) { // Get next scancode from queue // printf("\n[SIM] ps2_current_scancode pop!\n"); ps2_current_scancode = ps2_scancode_queue.front(); ps2_scancode_queue.pop();
// Set valid signal for a short pulse ps2_valid_signal = 1; ps2_cooldown = 60000; } }