⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rs232_syscon.v

📁 This build is for developing a "binary-to-BCD" converter for use in // displaying numerals in base-
💻 V
📖 第 1 页 / 共 4 页
字号:
  reset_rd_field_count <= 0;
  reset_rd_digit_count <= 0;

  case (m1_state) // synthesis parallel_case

    m1_initial_state :
      begin
        incr_msg_offset <= rs232_tx_load;
        if ((msg_offset == 15) && rs232_tx_load) begin
          m1_next_state <= m1_send_prompt;
          reset_msg_offset <= 1;
        end
        else m1_next_state <= m1_initial_state;
      end

    m1_send_ok :
      begin
        msg_base <= 5'b10101;     // Address of the OK message
        incr_msg_offset <= rs232_tx_load;
        if ((msg_offset == 1) && rs232_tx_load) begin
          m1_next_state <= m1_send_prompt;
          reset_msg_offset <= 1;
        end
        else m1_next_state <= m1_send_ok;
      end

    m1_send_prompt :
      begin
        msg_base <= 5'b10111;     // Address of the cr,lf,prompt message
        incr_msg_offset <= rs232_tx_load;
        if ((msg_offset == 4) && rs232_tx_load) begin
          m1_next_state <= m1_check_received_char;
          reset_cmd_ptr <= 1;
        end
        else m1_next_state <= m1_send_prompt;
      end

    // This state always leads to activating the parser...
    m1_send_crlf :
      begin
        msg_base <= 5'b10111;     // Address of the cr/lf message
        incr_msg_offset <= rs232_tx_load;
        if ((msg_offset == 1) && rs232_tx_load) begin
          m1_next_state <= m1_scan_command;
          reset_cmd_ptr <= 1;
        end
        else m1_next_state <= m1_send_crlf;
      end

    m1_check_received_char :
      begin
        rs232_echo <= 1;          // Allow echoing of characters
        if (rx_char_is_backspace && rs232_tx_load)
        begin
          m1_next_state <= m1_check_received_char;
          decr_cmd_ptr <= 1;     // This effectively eliminates the last char
        end
        else if (rx_char_is_enter && rs232_tx_load)
        begin
          m1_next_state <= m1_send_crlf;
          cmd_buffer_write <= 1;  // Store the enter as "marker" for parsing
          reset_msg_offset <= 1;
        end
        else if (rs232_tx_load && (cmd_ptr == CMD_BUFFER_SIZE_PP-1))
        begin
          m1_next_state <= m1_parse_error_indicator_crlf;
          reset_msg_offset <= 1;
          reset_cmd_ptr <= 1;
        end
        else if (rs232_tx_load)
        begin
          incr_cmd_ptr <= 1;
          cmd_buffer_write <= 1;
          m1_next_state <= m1_check_received_char;
        end
        else m1_next_state <= m1_check_received_char;
      end

    m1_bg_error_indicator :
      begin
        msg_base <= 5'b01011;    // Address of the B character
        incr_msg_offset <= rs232_tx_load;
        if ((msg_offset == 0) && rs232_tx_load) begin
          m1_next_state <= m1_ack_error_indicator;
          reset_msg_offset <= 1;
        end
        else m1_next_state <= m1_bg_error_indicator;
      end

    m1_ack_error_indicator :
      begin
        msg_base <= 5'b10100;    // Address of the ! error message
        incr_msg_offset <= rs232_tx_load;
        if ((msg_offset == 0) && rs232_tx_load) begin
          m1_next_state <= m1_send_prompt;
          reset_msg_offset <= 1;
        end
        else m1_next_state <= m1_ack_error_indicator;
      end

    // This state is used when the line is too long...
    m1_parse_error_indicator_crlf :
      begin
        msg_base <= 5'b10111;    // Address of the cr,lf message.
        incr_msg_offset <= rs232_tx_load;
        if ((msg_offset == 1) && rs232_tx_load) begin
          m1_next_state <= m1_parse_error_indicator;
          reset_msg_offset <= 1;
        end
        else m1_next_state <= m1_parse_error_indicator_crlf;
      end

    m1_parse_error_indicator :
      begin
        msg_base <= 5'b10011;    // Address of the ? message.
        incr_msg_offset <= rs232_tx_load;
        if ((msg_offset == 0) && rs232_tx_load) begin
          m1_next_state <= m1_send_prompt;
          reset_msg_offset <= 1;
        end
        else m1_next_state <= m1_parse_error_indicator;
      end

    m1_cmd_error_indicator :
      begin
        msg_base <= 5'b01100;    // Address of 'C'
        incr_msg_offset <= rs232_tx_load;
        if ((msg_offset == 0) && rs232_tx_load) begin
          m1_next_state <= m1_parse_error_indicator;
          reset_msg_offset <= 1;
        end
        else m1_next_state <= m1_cmd_error_indicator;
      end

    m1_adr_error_indicator :
      begin
        msg_base <= 5'b01010;    // Address of 'A'
        incr_msg_offset <= rs232_tx_load;
        if ((msg_offset == 0) && rs232_tx_load)
        begin
          m1_next_state <= m1_parse_error_indicator;
          reset_msg_offset <= 1;
        end
        else m1_next_state <= m1_adr_error_indicator;
      end

    m1_dat_error_indicator :
      begin
        msg_base <= 5'b01101;    // Address of 'D'
        incr_msg_offset <= rs232_tx_load;
        if ((msg_offset == 0) && rs232_tx_load)
        begin
          m1_next_state <= m1_parse_error_indicator;
          reset_msg_offset <= 1;
        end
        else m1_next_state <= m1_dat_error_indicator;
      end

    m1_qty_error_indicator :
      begin
        msg_base <= 5'b11100;    // Address of 'Q'
        incr_msg_offset <= rs232_tx_load;
        if ((msg_offset == 0) && rs232_tx_load)
        begin
          m1_next_state <= m1_parse_error_indicator;
          reset_msg_offset <= 1;
        end
        else m1_next_state <= m1_qty_error_indicator;
      end

    // The following states are for parsing and executing the command.

    // This state takes care of leading whitespace before the command
    m1_scan_command :
      begin
        rs232_echo <= 1;          // Don't send message characters
        reset_msg_offset <= 1;    // This one reset should cover all of the
                                  // parse/exec. states.  With rs232_echo
                                  // on, and no receive characters arrive,
                                  // then the msg_offset will remain reset.
                                  // This means the watchdog timer can take
                                  // a long time, if need be, during exec.
                                  // (NOTE: It might be better to disable
                                  //  the echoing of rx chars during these
                                  //  states.)
        init_qty <= 1;         // Set qty = 1 by default.  That can be
                               // overridden later, if the command has
                               // a different qty field.
        if (char_is_whitespace) begin
          m1_next_state <= m1_scan_command;
          incr_cmd_ptr <= 1;
        end
        else if (char_is_r) begin
          m1_next_state <= m1_scan_adr_whitespace;
          incr_cmd_ptr <= 1;
          cmd_r <= 1;
        end
        else if (char_is_w) begin
          m1_next_state <= m1_scan_adr_whitespace;
          incr_cmd_ptr <= 1;
          cmd_w <= 1;
        end
        else if (char_is_i) begin
          m1_next_state <= m1_start_execution;
          cmd_i <= 1;
        end
        else m1_next_state <= m1_cmd_error_indicator;
      end

    // The only way to determine the end of a valid field is to find
    // whitespace.  Therefore, char_is_whitespace must be used as an exit
    // condition from the "get_xxx_field" states.  So, this state is used to
    // scan through any leading whitespace prior to it.
    m1_scan_adr_whitespace :
      begin
        rs232_echo <= 1;          // Don't send message characters
        if (char_is_whitespace) begin
          m1_next_state <= m1_scan_adr_whitespace;
          incr_cmd_ptr <= 1;
        end
        else if (char_is_enter) m1_next_state <= m1_start_execution;
        else begin
          m1_next_state <= m1_get_adr_field;
          reset_adr <= 1;
        end
      end

    m1_get_adr_field :
      begin
        rs232_echo <= 1;          // Don't send message characters
        if (char_is_hex) begin
          m1_next_state <= m1_get_adr_field;
          store_adr <= 1;
          incr_cmd_ptr <= 1;
        end
        else if (char_is_whitespace) begin            // Normal exit
          m1_next_state <= m1_scan_dat_whitespace;
        end
        else if (char_is_enter) m1_next_state <= m1_start_execution;
        else m1_next_state <= m1_adr_error_indicator;
      end

    m1_scan_dat_whitespace :
      begin
        rs232_echo <= 1;          // Don't send message characters
        // There is no DAT field for reads, so skip it.
        if (command == `CMD_R) m1_next_state <= m1_scan_qty_whitespace;
        else if (char_is_whitespace) begin
          m1_next_state <= m1_scan_dat_whitespace;
          incr_cmd_ptr <= 1;
        end
        else if (char_is_enter) m1_next_state <= m1_start_execution;
        else begin
          m1_next_state <= m1_get_dat_field;
          reset_dat <= 1;
        end
      end

    m1_get_dat_field :
      begin
        rs232_echo <= 1;          // Don't send message characters
        if (char_is_hex) begin
          m1_next_state <= m1_get_dat_field;
          store_dat <= 1;
          incr_cmd_ptr <= 1;
        end
        else if (char_is_whitespace) begin            // Normal exit
          m1_next_state <= m1_scan_qty_whitespace;
        end
        else if (char_is_enter) m1_next_state <= m1_start_execution;
        else m1_next_state <= m1_dat_error_indicator;
      end

    m1_scan_qty_whitespace :
      begin
        rs232_echo <= 1;          // Don't send message characters
        if (char_is_whitespace) begin
          m1_next_state <= m1_scan_qty_whitespace;
          incr_cmd_ptr <= 1;
        end
        else if (char_is_enter) m1_next_state <= m1_start_execution;
        else begin
          m1_next_state <= m1_get_qty_field;
          reset_qty <= 1;
        end
      end

    m1_get_qty_field :
      begin
        rs232_echo <= 1;          // Don't send message characters
        if (char_is_hex) begin
          m1_next_state <= m1_get_qty_field;
          store_qty <= 1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -