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

📄 cmd_parse.v

📁 32位单精度浮点加法器
💻 V
📖 第 1 页 / 共 2 页
字号:
              CMD_R,       // R - read              CMD_N,       // N - set nsamp              CMD_P,       // P - set prescale              CMD_S: begin // S - set speed                // Get 4 characters of arguments                state   <= GET_ARG;                arg_cnt <= 3'd3;              end  // R, N, P, or S                            CMD_n: begin // n - print nsamp                send_resp_val  <= 1'b1;                send_resp_type <= RESP_DATA;                send_resp_data <= nsamp;                state          <= SEND_RESP;              end // n                              CMD_p: begin // p - print prescale                send_resp_val  <= 1'b1;                send_resp_type <= RESP_DATA;                send_resp_data <= prescale;                state          <= SEND_RESP;              end // p                CMD_s: begin // s - print nsamp                send_resp_val  <= 1'b1;                send_resp_type <= RESP_DATA;                send_resp_data <= speed;                state          <= SEND_RESP;              end // s                CMD_G,       // G - go              CMD_C,       // C - continuous              CMD_H: begin // H - halt                send_resp_val  <= 1'b1;                send_resp_type <= RESP_OK;                state          <= SEND_RESP;              end // G C H                default: begin                send_resp_val  <= 1'b1;                send_resp_type <= RESP_ERR;                state          <= SEND_RESP;              end // default            endcase // current character case          end // if new character has arrived        end // state CMD_WAIT                GET_ARG: begin          // Get the correct number of characters of argument. Check that          // all characters are legel HEX values.          // Once the last character is successfully received, take action          // based on what the current command is          if (new_char)          begin            if (!char_is_digit)            begin              // Send an error response              send_resp_val  <= 1'b1;              send_resp_type <= RESP_ERR;              state          <= SEND_RESP;            end            else // character IS a digit            begin              if (arg_cnt != 3'b000) // This is NOT the last char of arg              begin                // append the current digit to the saved ones                arg_sav <= arg_val;                  // Wait for the next character                arg_cnt <= arg_cnt - 1'b1;              end // Not last char of arg              else // This IS the last character of the argument - process              begin                case (cur_cmd)                   CMD_W: begin                    // Initiate a write to the RAM if in range                    //                    // The first argument is the address - it needs to be                    // less than 1024 for the write to be valid. Thus we                    // need to check arg_val[31:16] - if its valid, then                    // the bottom ten bits of this are the address, and                     // arg_val[15:0] is the data to write                    if (arg_val[31:16] <= RAM_MAX) // Valid address                    begin                      // Write the RAM and send OK                      cmd_samp_ram_we   <= 1'b1; // Write it to the RAM                      cmd_samp_ram_addr <= arg_val[25:16];                       cmd_samp_ram_din  <= arg_val[15:0];                      send_resp_val     <= 1'b1;                      send_resp_type    <= RESP_OK;                      state             <= SEND_RESP;                    end                     else // not valid address                    begin                      // Send ERR                      send_resp_val  <= 1'b1;                      send_resp_type <= RESP_ERR;                      state          <= SEND_RESP;                    end                  end // CMD_W                  CMD_R: begin                    // Initiate a read from the RAM if in range                    // The first (and only) arg is the read address (in 15:0)                    if (arg_val[15:0] <= RAM_MAX) // Valid address                    begin                      // Initiate the read                      cmd_samp_ram_addr <= arg_val[NSAMP_WID-1:0];                       state             <= READ_RAM;                    end                     else // not valid address                    begin                      // Send ERR                      send_resp_val  <= 1'b1;                      send_resp_type <= RESP_ERR;                      state          <= SEND_RESP;                    end                  end // CMD_R                  CMD_N: begin                    // Update nsamp with the only arg, if in range                    if ((arg_val[15:0]  >= NSAMP_MIN) &&                        (arg_val[15:0] <= NSAMP_MAX) )// Valid range                    begin                      // Update nsamp                      nsamp          <= arg_val[NSAMP_WID:0];                      nsamp_new      <= 1'b1;                      // Send OK                      send_resp_val  <= 1'b1;                      send_resp_type <= RESP_OK;                      state          <= SEND_RESP;                    end                     else // not in range                    begin                      // Send ERR                      send_resp_val  <= 1'b1;                      send_resp_type <= RESP_ERR;                      state          <= SEND_RESP;                    end                  end // CMD_N                  CMD_P: begin                    // Update prescale with the only arg, if in range                    if (arg_val[15:0]  >= PRESCALE_MIN) // In range                    begin                      // Update nsamp                      prescale       <= arg_val[15:0];                      prescale_new   <= 1'b1;                      // Send OK                      send_resp_val  <= 1'b1;                      send_resp_type <= RESP_OK;                      state          <= SEND_RESP;                    end                     else // not valid range                    begin                      // Send ERR                      send_resp_val  <= 1'b1;                      send_resp_type <= RESP_ERR;                      state          <= SEND_RESP;                    end                  end // CMD_P                  CMD_S: begin                    // Update speed with the only arg, if in range                    if (arg_val[15:0]  >= SPEED_MIN) // In range                    begin                      // Update speed                      speed          <= arg_val[15:0];                      speed_new      <= 1'b1;                      // Send OK                      send_resp_val  <= 1'b1;                      send_resp_type <= RESP_OK;                      state          <= SEND_RESP;                    end                     else // not valid range                    begin                      // Send ERR                      send_resp_val  <= 1'b1;                      send_resp_type <= RESP_ERR;                      state          <= SEND_RESP;                    end                  end // CMD_P                endcase              end // received last char of arg            end // if the char is a valid HEX digit          end // if new_char        end // state GET_ARG        READ_RAM: begin          // The read request to the RAM is being issued this cycle          // We need to wait for the data to be ready...          // There is nothing to do other than wait one clock          state <= READ_RAM2;        end // state READ_RAM        READ_RAM2: begin          // The read request from the RAM is done, and the data is on the          // dout port of the RAM - initiate the response          send_resp_val  <= 1'b1;          send_resp_type <= RESP_DATA;          send_resp_data <= cmd_samp_ram_dout;          state          <= SEND_RESP;        end // state READ_RAM        SEND_RESP: begin          // The response request has already been sent - all we need to          // do is keep the request asserted until the response is complete.          // Once it is complete, we return to IDLE          if (send_resp_done)          begin            send_resp_val <= 1'b0;            state         <= IDLE;          end        end // state SEND_RESP        default: begin          state <= IDLE;        end // state default      endcase    end // if !rst  end // always  assign nsamp_clk_rx     = nsamp;  assign pre_clk_rx       = prescale;  assign spd_clk_rx       = speed;  assign nsamp_new_clk_rx = nsamp_new;  assign pre_new_clk_rx   = prescale_new;  assign spd_new_clk_rx   = speed_new;  // Now handle the control to the Sample Generator  // It has two functions  //    - on receipt of a *G it asserts the output for PW clocks.  //    - on receipt of a *C it asserts the output continuously.  //    - on receipt of a *H it deasserts the output  // To assert for PW clocks, we use the one where the *G is detected  // and the PW-1 following clocks. To do that, we count from PW-1 to 0, and  // keep the output asserted whenever the counter is not 0  wire found_go = (state == CMD_WAIT) && new_char && (rx_data[6:0] == CMD_G);  always @(posedge clk_rx)  begin    if (rst_clk_rx)    begin      samp_gen_go_ctr <= 0;    end    else if (samp_gen_go_ctr != 0) // If not zero, in a count, so decrement    begin      samp_gen_go_ctr <= samp_gen_go_ctr - 1'b1;    end    else if (found_go)    begin      samp_gen_go_ctr <= PW - 1'b1;    end  end // always  always @(posedge clk_rx)  begin    if (rst_clk_rx)    begin      samp_gen_go_cont <= 1'b0;    end    else     begin      if ((state == CMD_WAIT) && new_char)      begin        if (rx_data[6:0] == CMD_C)          samp_gen_go_cont <= 1'b1;        else if (rx_data[6:0] == CMD_H)          samp_gen_go_cont <= 1'b0;      end // Have a new character in CMD_WAIT    end // !rst  end // always  always @(posedge clk_rx)  begin    if (rst_clk_rx)    begin      samp_gen_go_clk_rx <= 1'b0;    end    else     begin      samp_gen_go_clk_rx <= found_go ||                             (samp_gen_go_ctr != 0) ||                             samp_gen_go_cont;    end  endendmodule

⌨️ 快捷键说明

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