URL
https://opencores.org/ocsvn/yifive/yifive/trunk
Subversion Repositories yifive
[/] [yifive/] [trunk/] [caravel_yifive/] [verilog/] [rtl/] [spi_master/] [src/] [spim_tx.sv] - Rev 21
Compare with Previous | Blame | View Log
////////////////////////////////////////////////////////////////////////// //////// SPI TX Module //////// //////// This file is part of the YIFive cores project //////// http://www.opencores.org/cores/yifive/ //////// //////// Description //////// This is SPI Master Transmit Word control logic. //////// This logic transmit data upto 32 bit in bit or Quad spi //////// mode //////// //////// To Do: //////// nothing //////// //////// Author(s): //////// - Dinesh Annayya, dinesha@opencores.org //////// //////// Revision: //////// 0.1 - 16th Feb 2021, Dinesh A //////// Initial version //////// 0.2 - 24th Mar 2021, Dinesh A //////// 1. Comments are added //////// 2. RTL clean-up done and the output are registred//////// ////////////////////////////////////////////////////////////////////////////// //////// Copyright (C) 2000 Authors and OPENCORES.ORG //////// //////// This source file may be used and distributed without //////// restriction provided that this copyright statement is not //////// removed from the file and that any derivative work contains //////// the original copyright notice and the associated disclaimer. //////// //////// This source file is free software; you can redistribute it //////// and/or modify it under the terms of the GNU Lesser General //////// Public License as published by the Free Software Foundation; //////// either version 2.1 of the License, or (at your option) any //////// later version. //////// //////// This source is distributed in the hope that it will be //////// useful, but WITHOUT ANY WARRANTY; without even the implied //////// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //////// PURPOSE. See the GNU Lesser General Public License for more //////// details. //////// //////// You should have received a copy of the GNU Lesser General //////// Public License along with this source; if not, download it //////// from http://www.opencores.org/lgpl.shtml //////// //////////////////////////////////////////////////////////////////////////module spim_tx(// General Inputinput logic clk, // SPI clockinput logic rstn, // Active low Resetinput logic en, // Transmit Enableinput logic tx_edge, // Transmiting Edgeoutput logic tx_done, // Transmission completionoutput logic sdo0, // SPI Dout0output logic sdo1, // SPI Dout1output logic sdo2, // SPI Dout2output logic sdo3, // SPI Dout3input logic en_quad_in, // SPI quad mode indicationinput logic [15:0] counter_in, // Transmit counterinput logic [31:0] txdata, // 32 bit tranmsit datainput logic data_valid, // Input data validoutput logic data_ready, // Data in acepted, this for txfifooutput logic clk_en_o // Enable Tx clock);logic [31:0] data_int ; // Data Inputlogic [31:0] data_int_next ; // Next Data Inputlogic [15:0] counter ; // Tx Counterlogic [15:0] counter_next ; // tx next counterlogic [15:0] counter_trgt ; // counter exit counterlogic tx32b_done ; // 32 bit Transmit donelogic en_quad;enum logic [0:0] { IDLE, TRANSMIT } tx_CS, tx_NS;// Indicate 32 bit data done, usefull for readining next 32b from txfifoassign tx32b_done = (!en_quad && (counter[4:0] == 5'b11111)) || (en_quad && (counter[2:0] == 3'b111)) && tx_edge;always_combbegintx_NS = tx_CS;data_int_next = data_int;data_ready = 1'b0;counter_next = counter;case (tx_CS)IDLE: begindata_int_next = txdata;counter_next = '0;if (en && data_valid) begindata_ready = 1'b1;tx_NS = TRANSMIT;endendTRANSMIT: begincounter_next = counter + 1;data_int_next = (en_quad) ? {data_int[27:0],4'b0000} : {data_int[30:0],1'b0};if (tx_done) begincounter_next = 0;// Check if there is next dataif (en && data_valid) begindata_int_next = txdata;data_ready = 1'b1;tx_NS = TRANSMIT;end else begintx_NS = IDLE;endend else if (tx32b_done) beginif (data_valid) begindata_int_next = txdata;data_ready = 1'b1;end else begintx_NS = IDLE;endendendendcaseendalways_ff @(posedge clk, negedge rstn)beginif (~rstn)begincounter <= 0;data_int <= 'h0;tx_CS <= IDLE;en_quad <= 0;tx_done <= '0;clk_en_o <= '0;sdo0 <= '0;sdo1 <= '0;sdo2 <= '0;sdo3 <= '0;counter_trgt <= '0;endelsebeginif(tx_edge) begincounter <= counter_next;data_int <= data_int_next;sdo0 <= (en_quad_in) ? data_int_next[28] : data_int_next[31];sdo1 <= (en_quad_in) ? data_int_next[29] : 1'b0;sdo2 <= (en_quad_in) ? data_int_next[30] : 1'b0;sdo3 <= (en_quad_in) ? data_int_next[31] : 1'b0;tx_CS <= tx_NS;en_quad <= en_quad_in;tx_done <= (counter_next == (counter_trgt -1)) && (tx_NS == TRANSMIT);clk_en_o <= (tx_NS == TRANSMIT);end// Counter Exit condition, quad mode div-4 , else actual counterif (en && data_valid) begincounter_trgt <= (en_quad_in) ? {2'b00,counter_in[15:2]} : counter_in;endendendendmodule
