/*=================================================================*/ /*=== RS232 LIBRARY =============================================*/ /*=================================================================*/ /* * FILE: RS232toMEM.v * PROGRAMMER: William L. Bahn * * CONTENTS: module RS232toMEM ( Test, WA, WD, RA, DataIn, WS, Echo, Escape, Lost, TXD, RXD, RTS, CTS, DSR, rst, clk ); * Digilent D2 RS-232 Pin Assignments: RXD P202 TXD P201 RTS P195 CTS P199 DSR P200 * Baud Rate Parameters BAUD Bit Period Half-Period @ 50MHz 9600 104.2 us 2604 cyc 19200 52.1 us 1302 cyc 38400 26.0 us 651 cyc 115200 8.68us 217 cyc */ /* * RS232toMEM() * * This module is the interface between the RS232 module and the global * register space. It is NOT a general purpose interface. It processes * commands of the following formats only: * * Register Write: * WAADD * * This command writes the one-byte data value DD to register address AA. * Both values are in hexadecimal and all characters are assumed to be * uppercase. * * Register Read: * RAA * * This command retrieves the one-byte data value presently stored at * regsiter address AA. * * Both commands generate the same response: * * -> REG[AA] = DD * * The command interpretter normally sits in an IDLE state waiting a * complete packet to be received from the RS-232 link. It then begins * processing the packet one character at a time. If, at any point, the * interpretter cannot process a character, it enters a Dump sequence that * discards the remainder of the command and generates the response: * * -> ERROR * */ /* After initialization, the FSM is in the S_IDLE state awaiting a new * command packet. Upon detection of a packet, the following event pipeline * starts: * * In order to accommodate common elements that must go different places * when finished, the concept of a "Restore To" State is implemented. This * is akin to a function call restore state, but is different in that the * 'calling function' can arbitrarily establish an unrelated restore state. * * State Responsibility Partition * *** SUBCALLS - CALLS THAT INVOKE THE RESTORE STATE TO END * * S_CRLF OUTPUTS A CR/LF PAIR * Outputs the string "\r\l" and restores * * S_IPROMPT INPUT PROMPT GENERATOR * Outputs the string "#> " and restores * * S_OPROMPT OUTPUT PROMPT GENERATOR * Outputs the string "-> " and restores * * S_TITLE OUTPUTS THE TITLE STRING * Outputs the string "DE248" and restores * * S_ERROR ERROR STRING GENERATOR * Outputs the string "ERROR" and restores * * S_BYTE EXTRACTS AN ASCII BYTE VALUE FROM COMMAND * Pops character and converts to nibble * Writes nibble to upper nibble of byte * Pops character and converts to nibble * Writes nibble to lower nibble of byte * Restores * * S_ASCII OUTPUTS ASCII REPRESENTATION OF BYTE * Outputs MSB of value * Outputs LSB of value * * S_ECHO ECHOS BACK THE INPUT LINE * * Echos remainder of line, pops packet, and restores * * S_DUMP DISCARDS REMAINDER OF COMMAND PACKET * Discards remainder of line, pops packet, and restores * *** MAIN CALLS - CALLS THAT INVOKE SUBCALLS * * S_IDLE WAITS FOR COMMAND PACKET * Calls S_CRLF and returns * Calls S_IPROMPT and returns * Stalls until a Command Packet is available * Transfers to S_PARSE * * S_INI INITIAL WELCOME STRING * Calls S_CRLF and returns * Calls S_OPROMPT and returns * Calls S_TITLE and returns * Calls S_CRLF and returns * Transfers to S_IDLE * * S_PARSE PARSES THE COMMAND TYPE * Calls the S_OPROMPT and returns * Examines the first character in the Command Packet * Pops character and transfers to S_READ if 'R' * Pops character and transfers to S_WRITE if 'W' * Calls S_ERROR and returns if not a command. * Calls S_ECHO and returns * Calls S_CRLF and returns * Transfers to S_IDLE * * S_READ EXTRACTS THE ADDRESS FROM THE COMMAND * Calls S_BYTE and returns * Writes byte to the Read Address Register * Transfers to S_WRITEBACK * * S_WRITE EXTRACTS THE ADDRESS AND DATA FROM THE COMMAND * Calls S_BYTE and returns * Writes byte to the Read and Write Address Registers * Calls S_BYTE and returns * Writes byte to the Write Data Register * Strobes the Write Strobe line * Transfers to S_WRITEBACK * * S_WRITEBACK OUTPUTS THE READ ADDRESS AND DATA * Strobes the Read Strobe line * Places RA value into ASCII converter * Calls S_ASCII and returns * Outputs the string "REG[" * Places RD value into ASCII converter * Calls S_ASCII and returns * Outputs the string "] = " * Calls S_CRLF and returns * Transfers to S_IDLE * */ module RS232toMEM ( Test16, Test, WA, WD, RA, DataIn, WS, NoEcho, NoXonXoff, Escape, Lost, TXD, RXD, RTS, CTS, DSR, rst, clk ); parameter LO = 1'b0, HI = 1'b1; // Data Busses output [15:0] Test16; // Test Signal Output output [15:0] Test; // Test Signal Output output [7:0] WA, WD, RA; // WA, WD, RA values input [7:0] DataIn; // RD value // Strobe Lines output WS; // Write Strobe // External RS-232 Controller Signals input NoEcho; // Disable incoming data echo back input NoXonXoff; // Disable XonXoff Flow Control output Escape; // ESC character detected output Lost; // Indicates incoming data was lost input TXD, RTS; // RS-232 external signals output RXD, CTS, DSR; // RS-232 external signals // Master reset and clock input rst, clk; // Master reset and clock // Internal RS-232 Controller Signals wire [15:0] UART_Test; // Test Output Signals wire [7:0] CharOut; // Data to be sent out RS-232 wire [7:0] CharIn; // Data received from RS-232 wire Push, Pop; // Push/Pop data to/from RS-232 wire PacketPushed; // An outgoing packet is complete wire PacketPopped; // An incoming packet has been retrieved wire NoPackets; // Input Packet Buffer has no complete packets. wire NoBytes; // Input Packet Buffer is completely empty wire Full; // Output Packet Buffer (to RS-232) is full // ====================================================================== // RS-232 Interface wire Dump, Dump_p; assign Dump = (((rst == HI)||(Dump_p == HI))? HI : LO); OneShot RS232ESC ( .Q(Dump_p), .Start(Escape), .Stop(Dump_p), .rst(rst), .clk(clk) ); RS232wPACKET UART ( .Test16(Test16), .Test(UART_Test), .ToOther(CharOut), .FromOther(CharIn), .NoXonXoff(NoXonXoff), .Escape(Escape), .Push(Push), .Pop(Pop), .PacketPushed(PacketPushed), .PacketPopped(PacketPopped), .NoEcho(NoEcho), .NoPackets(NoPackets), .NoBytes(NoBytes), .Full(Full), .Lost(Lost), .TXD(TXD), .RXD(RXD), .RTS(RTS), .CTS(CTS), .DSR(DSR), .rst(Dump), .clk(clk) ); // ====================================================================== // ====================================================================== // ASCII-to-BINARY Converters wire [7:0] binary_out, ascii_in, binary_in; wire [15:0] ascii_out; wire WE_MSB, WE_LSB, WE_ASC, HiByte; Ascii2Binary A2B ( .binary(binary_out), .ascii(ascii_in), .WE_MSB(WE_MSB), .WE_LSB(WE_LSB), .rst(rst), .clk(clk) ); Binary2Ascii B2A ( .ascii(ascii_out), .binary(binary_in), .WE(WE_ASC), .rst(rst), .clk(clk) ); // ====================================================================== // REGISTER SPACE INTERFACE REGISTERS parameter REGWIDTH = 8; // Address and Data Registers (byte-wide) wire [(REGWIDTH-1):0] RA, WA; wire [(REGWIDTH-1):0] WD, RD; // Read and Write Strobe lines wire WS, WAS, WDS; wire RAS, RDS; // RS232 Data Value wire [(REGWIDTH-1):0] RS232Byte; Reg8 MEM_WA (.Q(WA), .D(RS232Byte), .en(WAS), .rst(rst), .clk(clk)); Reg8 MEM_WD (.Q(WD), .D(RS232Byte), .en(WDS), .rst(rst), .clk(clk)); Reg8 MEM_RA (.Q(RA), .D(RS232Byte), .en(RAS), .rst(rst), .clk(clk)); Reg8 MEM_RD (.Q(RD), .D(DataIn), .en(RDS), .rst(rst), .clk(clk)); // ====================================================================== // ASCII non-alphanumeric character constants parameter NUL = 8'h00, BELL = 8'h07, TAB = 8'h09, LINEFEED = 8'h0A, CARRIAGE_RETURN = 8'h0D, ESCAPE = 8'h1B, SPACE = 8'h20, EXCLAMATION_MARK = 8'h21, DOUBLE_QUOTE = 8'h22, POUND_SIGN = 8'h23, DOLLAR_SIGN = 8'h24, PERCENT_SIGN = 8'h25, AMPERSAND = 8'h26, SINGLE_QUOTE = 8'h27, PAREN_OPEN = 8'h28, PAREN_CLOSE = 8'h29, ASTERISK = 8'h2A, PLUS_SIGN = 8'h2B, COMMA = 8'h2C, MINUS_SIGN = 8'h2D, HYPHEN = MINUS_SIGN, PERIOD = 8'h2E, SLASH = 8'h2F, COLON = 8'h3A, SEMICOLON = 8'h3B, LESS_THAN = 8'h3C, EQUALS_SIGN = 8'h3D, GREATER_THAN = 8'h3E, QUESTIONMARK = 8'h3F, AT_SIGN = 8'h40, SQUARE_BRACKET_OPEN = 8'h5B, BACKSLASH = 8'h5C, SQUARE_BRACKET_CLOSE = 8'h5D, CARAT = 8'h5E, UNDERSCORE = 8'h5F, UMLAT = 8'h60, CURLY_BRACE_OPEN = 8'h7B, PIPE = 8'h7C, CURLY_BRACE_CLOSE = 8'h7D, TILDE = 8'h7E; // ASCII Upper case character constants parameter CHAR_UC_A = 8'h41, CHAR_UC_D = 8'h44, CHAR_UC_E = 8'h45, CHAR_UC_O = 8'h4F, CHAR_UC_R = 8'h52, CHAR_UC_W = 8'h57, CHAR_UC_Z = 8'h5A; // ASCII numeric character constants parameter CHAR_0 = 8'h30, CHAR_1 = 8'h31, CHAR_2 = 8'h32, CHAR_3 = 8'h33, CHAR_4 = 8'h34, CHAR_5 = 8'h35, CHAR_6 = 8'h36, CHAR_7 = 8'h37, CHAR_8 = 8'h38, CHAR_9 = 8'h39; reg [7:0] DataOut_int; reg Push_int, Pop_int; reg PPush, PPop; reg [7:0] Character; assign DataOut = DataOut_int; assign Push = Push_int; assign Pop = Pop_int; assign CharOut = Character; assign PacketPushed = PPush; assign PacketPopped = PPop; reg [7:0] Strobes; assign WE_ASC = Strobes[7]; assign WE_MSB = Strobes[6]; assign WE_LSB = Strobes[5]; assign WS = Strobes[4]; assign WAS = Strobes[3]; assign WDS = Strobes[2]; assign RAS = Strobes[1]; assign RDS = Strobes[0]; // Strobe Table // Strobes <=> {WS,WAS,WDS,RS,RAS,RDS} parameter STROBE_NONE = 8'b00000000, STROBE_ASC = 8'b10000000, STROBE_MSB = 8'b01000000, STROBE_LSB = 8'b00100000, STROBE_WS = 8'b00010000, STROBE_WAS = 8'b00001000, STROBE_WDS = 8'b00000100, STROBE_RAS = 8'b00000010, STROBE_RDS = 8'b00000001; // FSM State Table parameter S_CRLF = 4'd11, S_OPROMPT = 4'd5, S_IPROMPT = 4'd4, S_TITLE = 4'd10, S_ERROR = 4'd6, S_INI = 4'd0, S_READ = 4'd1, S_WRITE = 4'd2, S_DUMP = 4'd3, S_IDLE = 4'd7, S_PARSE = 4'd8, S_ECHO = 4'd9, S_ASCII = 4'd12, S_BYTE = 4'd13, S_RESET = 4'd14, S_READBACK = 4'd15; // FSM SubState parameter S0 = 4'd0, S1 = 4'd1, S2 = 4'd2, S3 = 4'd3, S4 = 4'd4, S5 = 4'd5, S6 = 4'd6, S7 = 4'd7, S8 = 4'd8, S9 = 4'd9, SA = 4'd10, SB = 4'd11, SC = 4'd12, SD = 4'd13, SE = 4'd14, SF = 4'd15; // FSM State Variables reg [3:0] State, Next_State; reg [3:0] SubState, Next_SubState; reg Restore; reg [7:0] RestoreState, Next_RestoreState; // FSM State Transition Process always @ (posedge clk) begin if (Dump == HI) begin State <= S_INI; SubState <= S0; RestoreState <= {S_INI,S0}; end else if (Restore == HI) begin State <= RestoreState[7:4]; SubState <= RestoreState[3:0]; RestoreState <= RestoreState; end else begin State <= Next_State; SubState <= Next_SubState; RestoreState <= Next_RestoreState; end end reg [7:0] Byte, Next_Byte; // Register Updates always @ (posedge clk) begin if (Dump == HI) begin Byte <= NUL; end else begin Byte <= Next_Byte; end end wire [15:0] ascii; assign ascii_in = CharIn; assign binary_in = Byte; assign RS232Byte = binary_out; assign ascii = ascii_out; // Test Output Definitions assign Test[3:0] = State; assign Test[7:4] = SubState; assign Test[15:8] = RS232Byte; // FSM State Action Definitions always @ (State or SubState or RestoreState or NoPackets or CharIn or ascii or Byte or RA or RD) begin case (State) // SUBCALLS // These calls invoke the RestoreState when finished //--------------- OUTPUT CARRIAGE RETURN and LINE FEED -------- S_CRLF: case (SubState) S0: begin Push_int = HI; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = CARRIAGE_RETURN; Next_State = State; Next_SubState = S1; Restore = LO; Next_RestoreState = RestoreState; end S1: begin Push_int = HI; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = LINEFEED; Next_State = State; Next_SubState = S2; Restore = LO; Next_RestoreState = RestoreState; end S2: begin Push_int = HI; Pop_int = LO; PPush = HI; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = State; Next_SubState = SubState; Restore = HI; Next_RestoreState = RestoreState; end default: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_RESET; Next_SubState = S0; Restore = LO; Next_RestoreState = {S_RESET,S0}; end endcase //--------------- INPUT PROMPT ------------------ S_IPROMPT: case (SubState) S0: begin Push_int = HI; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = POUND_SIGN; Next_State = State; Next_SubState = S1; Restore = LO; Next_RestoreState = RestoreState; end S1: begin Push_int = HI; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = GREATER_THAN; Next_State = State; Next_SubState = S2; Restore = LO; Next_RestoreState = RestoreState; end S2: begin Push_int = HI; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = SPACE; Next_State = State; Next_SubState = S3; Restore = LO; Next_RestoreState = RestoreState; end S3: begin Push_int = HI; Pop_int = LO; PPush = HI; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = State; Next_SubState = SubState; Restore = HI; Next_RestoreState = RestoreState; end default: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_RESET; Next_SubState = S0; Restore = LO; Next_RestoreState = {S_RESET,S0}; end endcase //--------------- OUTPUT PROMPT ------------------ S_OPROMPT: case (SubState) S0: begin Push_int = HI; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = HYPHEN; Next_State = State; Next_SubState = S1; Restore = LO; Next_RestoreState = RestoreState; end S1: begin Push_int = HI; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = GREATER_THAN; Next_State = State; Next_SubState = S2; Restore = LO; Next_RestoreState = RestoreState; end S2: begin Push_int = HI; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = SPACE; Next_State = State; Next_SubState = S3; Restore = LO; Next_RestoreState = RestoreState; end S3: begin Push_int = HI; Pop_int = LO; PPush = HI; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = State; Next_SubState = SubState; Restore = HI; Next_RestoreState = RestoreState; end default: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_RESET; Next_SubState = S0; Restore = LO; Next_RestoreState = {S_RESET,S0}; end endcase //--------------- TITLE STRING ------------------ S_TITLE: case (SubState) S0: begin Push_int = HI; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = CHAR_UC_D; Next_State = State; Next_SubState = S1; Restore = LO; Next_RestoreState = RestoreState; end S1: begin Push_int = HI; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = CHAR_UC_E; Next_State = State; Next_SubState = S2; Restore = LO; Next_RestoreState = RestoreState; end S2: begin Push_int = HI; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = CHAR_2; Next_State = State; Next_SubState = S3; Restore = LO; Next_RestoreState = RestoreState; end S3: begin Push_int = HI; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = CHAR_4; Next_State = State; Next_SubState = S4; Restore = LO; Next_RestoreState = RestoreState; end S4: begin Push_int = HI; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = CHAR_8; Next_State = State; Next_SubState = S5; Restore = LO; Next_RestoreState = RestoreState; end S5: begin Push_int = HI; Pop_int = LO; PPush = HI; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = State; Next_SubState = SubState; Restore = HI; Next_RestoreState = RestoreState; end default: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_RESET; Next_SubState = S0; Restore = LO; Next_RestoreState = {S_RESET,S0}; end endcase //--------------- ERROR STRING ------------------ S_ERROR: case (SubState) S0: begin Push_int = HI; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = "E";//CHAR_UC_E; Next_State = State; Next_SubState = S1; Restore = LO; Next_RestoreState = RestoreState; end S1: begin Push_int = HI; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = CHAR_UC_R; Next_State = State; Next_SubState = S2; Restore = LO; Next_RestoreState = RestoreState; end S2: begin Push_int = HI; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = CHAR_UC_R; Next_State = State; Next_SubState = S3; Restore = LO; Next_RestoreState = RestoreState; end S3: begin Push_int = HI; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = CHAR_UC_O; Next_State = State; Next_SubState = S4; Restore = LO; Next_RestoreState = RestoreState; end S4: begin Push_int = HI; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = CHAR_UC_R; Next_State = State; Next_SubState = S5; Restore = LO; Next_RestoreState = RestoreState; end S5: begin Push_int = HI; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = "!"; Next_State = State; Next_SubState = S6; Restore = LO; Next_RestoreState = RestoreState; end S6: begin Push_int = HI; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = SPACE; Next_State = State; Next_SubState = S7; Restore = LO; Next_RestoreState = RestoreState; end S7: begin Push_int = HI; Pop_int = LO; PPush = HI; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = State; Next_SubState = SubState; Restore = HI; Next_RestoreState = RestoreState; end default: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_RESET; Next_SubState = S0; Restore = LO; Next_RestoreState = {S_RESET,S0}; end endcase //-------- CONVERT ASCII BYTE TO BINARY BYTE ---------------- S_BYTE: case (SubState) S0: begin Push_int = LO; Pop_int = HI; PPush = LO; PPop = LO; Strobes = STROBE_MSB; Next_Byte = Byte; Character = NUL; Next_State = State; Next_SubState = S1; Restore = LO; Next_RestoreState = RestoreState; end S1: begin Push_int = LO; Pop_int = HI; PPush = LO; PPop = LO; Strobes = STROBE_LSB; Next_Byte = Byte; Character = NUL; Next_State = S_RESET; Next_SubState = S0; Restore = HI; Next_RestoreState = RestoreState; end default: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_RESET; Next_SubState = S0; Restore = LO; Next_RestoreState = {S_RESET,S0}; end endcase //-------- OUTPUT BINARY BYTE AS TWO ASCII CHARACTERS ----------- S_ASCII: case (SubState) S0: begin Push_int = HI; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = ascii[15:8]; Next_State = State; Next_SubState = S1; Restore = LO; Next_RestoreState = RestoreState; end S1: begin Push_int = HI; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = ascii[7:0]; Next_State = State; Next_SubState = S2; Restore = LO; Next_RestoreState = RestoreState; end S2: begin Push_int = HI; Pop_int = LO; PPush = HI; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_RESET; Next_SubState = S0; Restore = HI; Next_RestoreState = RestoreState; end default: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_RESET; Next_SubState = S0; Restore = LO; Next_RestoreState = {S_RESET,S0}; end endcase //--------------- ECHO LOOP ------------------ // Echos remainder of input line and restores S_ECHO: case (SubState) S0: case (CharIn) NUL: begin Push_int = LO; Pop_int = HI; PPush = LO; PPop = HI; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_RESET; Next_SubState = S0; Restore = HI; Next_RestoreState = RestoreState; end default: begin Push_int = HI; Pop_int = HI; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = CharIn; Next_State = State; Next_SubState = S0; Restore = LO; Next_RestoreState = RestoreState; end endcase default: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_RESET; Next_SubState = S0; Restore = LO; Next_RestoreState = {S_RESET, S0}; end endcase //--------------- DUMP LOOP ------------------ S_DUMP: case (SubState) S0: case (CharIn) NUL: begin Push_int = LO; Pop_int = HI; PPush = LO; PPop = HI; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_RESET; Next_SubState = S0; Restore = HI; Next_RestoreState = RestoreState; end default: begin Push_int = LO; Pop_int = HI; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = State; Next_SubState = S0; Restore = LO; Next_RestoreState = RestoreState; end endcase default: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_RESET; Next_SubState = S0; Restore = LO; Next_RestoreState = {S_RESET,S0}; end endcase // MAIN ALLS // These calls invoke other SubCalls //--------------- IDLE LOOP ------------------ S_IDLE: case (SubState) S0: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_CRLF; Next_SubState = S0; Restore = LO; Next_RestoreState = {State, S1}; end S1: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_IPROMPT; Next_SubState = S0; Restore = LO; Next_RestoreState = {State, S2}; end S2: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; begin if (NoPackets == HI) begin Next_State = State; Next_SubState = SubState; end else begin Next_State = S_PARSE; Next_SubState = S0; end end Restore = LO; Next_RestoreState = RestoreState; end default: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_RESET; Next_SubState = S0; Restore = LO; Next_RestoreState = {S_RESET,S0}; end endcase //--------------- INITIALIZATION STRING ------------------ S_INI: begin case (SubState) S0: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_CRLF; Next_SubState = S0; Restore = LO; Next_RestoreState = {State, S1}; end S1: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_OPROMPT; Next_SubState = S0; Restore = LO; Next_RestoreState = {State, S2}; end S2: begin Push_int = HI; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = BELL; Next_State = S_TITLE; Next_SubState = S0; Restore = LO; Next_RestoreState = {State, S3}; end S3: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_CRLF; Next_SubState = S0; Restore = LO; Next_RestoreState = {State, S4}; end S4: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_IDLE; Next_SubState = S0; Restore = LO; Next_RestoreState = RestoreState; end default: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_RESET; Next_SubState = S0; Restore = LO; Next_RestoreState = {S_RESET,S0}; end endcase end //--------------- COMMAND PARSE ------------------ S_PARSE: case (SubState) S0: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_OPROMPT; Next_SubState = S0; Restore = LO; Next_RestoreState = {State, S1}; end S1: case (CharIn) "W": begin Push_int = LO; Pop_int = HI; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_WRITE; Next_SubState = S0; Restore = LO; Next_RestoreState = RestoreState; end "R": begin Push_int = LO; Pop_int = HI; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_READ; Next_SubState = S0; Restore = LO; Next_RestoreState = RestoreState; end "!": begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = State; Next_SubState = S3; Restore = LO; Next_RestoreState = RestoreState; end default: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = State; Next_SubState = S2; Restore = LO; Next_RestoreState = {S_RESET, S0}; end endcase S2: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_ERROR; Next_SubState = S0; Restore = LO; Next_RestoreState = {State, S3}; end S3: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_ECHO; Next_SubState = S0; Restore = LO; Next_RestoreState = {State, S4}; end S4: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_CRLF; Next_SubState = S0; Restore = LO; Next_RestoreState = {S_IDLE, S0}; end default: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_RESET; Next_SubState = S0; Restore = LO; Next_RestoreState = {S_RESET,S0}; end endcase //--------------- READ COMMAND ------------------ S_READ: case (SubState) S0: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_BYTE; Next_SubState = S0; Restore = LO; Next_RestoreState = {State, S1}; end S1: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_RAS; Next_Byte = Byte; Character = NUL; Next_State = S_DUMP; Next_SubState = S0; Restore = LO; Next_RestoreState = {State, S2}; end S2: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_READBACK; Next_SubState = S0; Restore = LO; Next_RestoreState = {S_RESET, S0}; end default: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_RESET; Next_SubState = S0; Restore = LO; Next_RestoreState = {S_RESET, S0}; end endcase //--------------- WRITE COMMAND ------------------ S_WRITE: case (SubState) S0: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_BYTE; Next_SubState = S0; Restore = LO; Next_RestoreState = {State, S1}; end S1: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = (STROBE_WAS | STROBE_RAS); Next_Byte = Byte; Character = NUL; Next_State = S_BYTE; Next_SubState = S0; Restore = LO; Next_RestoreState = {State, S2}; end S2: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_WDS; Next_Byte = Byte; Character = NUL; Next_State = S_DUMP; Next_SubState = S0; Restore = LO; Next_RestoreState = {S_WRITE, S3}; end S3: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_WS; Next_Byte = Byte; Character = NUL; Next_State = S_READBACK; Next_SubState = S0; Restore = LO; Next_RestoreState = {S_RESET, S0}; end default: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_RESET; Next_SubState = S0; Restore = LO; Next_RestoreState = {S_RESET, S0}; end endcase //--------------- READ ADDRESS and CONTENTS BACK TO HOST ---------- S_READBACK: case (SubState) S0: begin Push_int = HI; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = "R"; Next_State = State; Next_SubState = S1; Restore = LO; Next_RestoreState = {State, S1}; end S1: begin Push_int = HI; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = "E"; Next_State = State; Next_SubState = S2; Restore = LO; Next_RestoreState = {State, S1}; end S2: begin Push_int = HI; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = "G"; Next_State = State; Next_SubState = S3; Restore = LO; Next_RestoreState = {State, S1}; end S3: begin Push_int = HI; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = "["; Next_State = State; Next_SubState = S4; Restore = LO; Next_RestoreState = {State, S1}; end S4: begin Push_int = HI; Pop_int = LO; PPush = HI; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = State; Next_SubState = S5; Restore = LO; Next_RestoreState = {State, S1}; end S5: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_RDS; Next_Byte = RA; Character = NUL; Next_State = State; Next_SubState = S6; Restore = LO; Next_RestoreState = {State, S1}; end S6: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_ASC; Next_Byte = RD; Character = NUL; Next_State = S_ASCII; Next_SubState = S0; Restore = LO; Next_RestoreState = {State, S7}; end S7: begin Push_int = HI; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = "]"; Next_State = State; Next_SubState = S8; Restore = LO; Next_RestoreState = {State, S1}; end S8: begin Push_int = HI; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = "="; Next_State = State; Next_SubState = S9; Restore = LO; Next_RestoreState = {State, S1}; end S9: begin Push_int = HI; Pop_int = LO; PPush = HI; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = State; Next_SubState = SA; Restore = LO; Next_RestoreState = {State, S1}; end SA: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_ASC; Next_Byte = NUL; Character = NUL; Next_State = S_ASCII; Next_SubState = S0; Restore = LO; Next_RestoreState = {State, SB}; end SB: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_CRLF; Next_SubState = S0; Restore = LO; Next_RestoreState = {S_IDLE, S0}; end default: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_RESET; Next_SubState = S0; Restore = LO; Next_RestoreState = {S_RESET, S0}; end endcase default: begin Push_int = LO; Pop_int = LO; PPush = LO; PPop = LO; Strobes = STROBE_NONE; Next_Byte = Byte; Character = NUL; Next_State = S_RESET; Next_SubState = S0; Restore = LO; Next_RestoreState = {S_RESET,S0}; end endcase end endmodule