| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- `timescale 1ns/1ps
- // Multi-axis jog dispatcher. DIR=0 open/up, DIR=1 close/down.
- // Commands: 00 stop, 01 DIR0, 02 DIR1. Latest door_action_valid overrides any
- // in-flight move (re-pulses motor_start with the new mask/dir, including stop).
- // AXIS_COUNT=2: exhaust X/Y only (production; intake is solenoid-owned elsewhere).
- // AXIS_COUNT=3: bit0=X, bit1=Y, bit2=intake (motor-compat; byte8 -> intake).
- module door_action_dispatcher #(
- parameter integer OPEN_DIR = 0,
- parameter integer CLOSE_DIR = 1,
- parameter integer AXIS_COUNT = 2
- ) (
- input wire clk,
- input wire rst_n,
- input wire door_action_valid,
- input wire [1:0] intake_door_cmd,
- input wire [1:0] exhaust_x_cmd,
- input wire [1:0] exhaust_y_cmd,
- input wire watchdog_abort,
- output reg motor_start,
- output reg [AXIS_COUNT-1:0] motor_active_mask,
- output reg [AXIS_COUNT-1:0] motor_dir_mask,
- input wire motor_busy
- );
- localparam [AXIS_COUNT-1:0] AXIS_ZERO = {AXIS_COUNT{1'b0}};
- wire x_active = (exhaust_x_cmd != 2'd0);
- wire y_active = (exhaust_y_cmd != 2'd0);
- wire intake_active = (intake_door_cmd != 2'd0);
- wire x_dir_bit = (exhaust_x_cmd == 2'd2) ? CLOSE_DIR[0] : OPEN_DIR[0];
- wire y_dir_bit = (exhaust_y_cmd == 2'd2) ? CLOSE_DIR[0] : OPEN_DIR[0];
- wire intake_dir_bit = (intake_door_cmd == 2'd2) ? CLOSE_DIR[0] : OPEN_DIR[0];
- // Bit packing: {intake?, y, x} so production X/Y bit positions stay stable.
- wire [AXIS_COUNT-1:0] next_active =
- (AXIS_COUNT == 3) ? {intake_active, y_active, x_active} :
- {y_active, x_active};
- wire [AXIS_COUNT-1:0] next_dir =
- (AXIS_COUNT == 3) ? {intake_dir_bit, y_dir_bit, x_dir_bit} :
- {y_dir_bit, x_dir_bit};
- wire needs_motor_event = door_action_valid &&
- ((next_active != AXIS_ZERO) || motor_busy);
- always @(posedge clk or negedge rst_n) begin
- if (!rst_n) begin
- motor_start <= 1'b0;
- motor_active_mask <= AXIS_ZERO;
- motor_dir_mask <= AXIS_ZERO;
- end else begin
- motor_start <= 1'b0;
- if (watchdog_abort) begin
- motor_active_mask <= AXIS_ZERO;
- end else if (needs_motor_event) begin
- motor_active_mask <= next_active;
- motor_dir_mask <= next_dir;
- motor_start <= 1'b1;
- end
- end
- end
- endmodule
|