Advertisement
Guest User

Untitled

a guest
Oct 17th, 2016
491
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. `timescale 1ns / 1ps
  2.  
  3.  module top(
  4.         input iClk_32Mhz,
  5.         input iRst_n,
  6.  
  7.         //input [3:0]iDip,
  8.  
  9.         input iSpi_sck,
  10.         input iSpi_mosi,
  11.         //input iSpi_miso,
  12.         input iSpi_cs_n,
  13.  
  14.         input iI2s_lrcin,
  15.         input iI2s_lrcout,
  16.         input iI2s_din,
  17.         input iI2s_bclk,
  18.  
  19.         //input iRotEncA,
  20.         //input iRotEncB,
  21.  
  22.         //input iHiZSat,
  23.  
  24.         output oCodecClk,
  25.  
  26.         output oI2s_dout,
  27.  
  28.         //output oInterrupt,
  29.         output [2:0]oLed
  30.     );
  31.  
  32.     // Clocking
  33.     wire wClkMain;
  34.     wire wPllLocked;
  35.     wire wChipReady;
  36.     assign wChipReady = (iRst_n & wPllLocked);
  37.  
  38.     // SPI
  39.     wire wSpiNewData;
  40.     wire [15:0] wSpiRegAddr;
  41.     wire [7:0] wSpiData;
  42.    
  43.     // Registers
  44.     wire [7:0] oDistoLevel;
  45.  
  46.     //I2S
  47.     wire [15:0] wI2sDataInRight;
  48.     wire [15:0] wI2sDataInLeft;
  49.  
  50.     reg [15:0] rRightLoopback;
  51.     reg [15:0] rLeftLoopback;
  52.  
  53.     reg rLastRightReady;
  54.     reg rLastLeftReady;
  55.  
  56.     wire wRightReady;
  57.     wire wLeftReady;
  58.  
  59.     // Outputs
  60.     assign oLed[1:0] = oDistoLevel[1:0];
  61.     assign oLed[2] = wChipReady;
  62.     //assign oInterrupt = |oDistoLevel;
  63.  
  64.     pll chip_pll
  65.     (
  66.         .iClk(iClk_32Mhz),      
  67.         .oClk_main(wClkMain),
  68.         .oClkCodec(oCodecClk),
  69.         .oReset(!iRst_n),
  70.         .oLocked(wPllLocked)
  71.     );  
  72.  
  73.     spi spi_in(
  74.         .iClk(wClkMain),
  75.         .iRst_n(wChipReady),
  76.  
  77.         .iMosi(iSpi_mosi),
  78.         .iSck(iSpi_sck),
  79.         .iCs_n(iSpi_cs_n),
  80.         .oNewData(wSpiNewData),
  81.         .oRegAddr(wSpiRegAddr),
  82.         .oData(wSpiData)
  83.     );
  84.    
  85.    
  86.     register_map register_map1(
  87.         .iClk(wClkMain),
  88.         .iRst_n(wChipReady),
  89.         .iAddr(wSpiRegAddr),
  90.         .iData(wSpiData),
  91.         .iLatch(wSpiNewData),
  92.  
  93.         .oDistoLevel(oDistoLevel)
  94.     );
  95.  
  96.     i2s_slave i2s_instance
  97.     (
  98.         .iClk(wClkMain),
  99.         .iRst_n(wChipReady),
  100.         .iLrcIn(iI2s_lrcin),
  101.         .iLrcOut(iI2s_lrcout),
  102.         .iBclk(iI2s_bclk),
  103.         .iDin(iI2s_din),
  104.  
  105.         .iLeftOutData(rLeftLoopback),
  106.         .iRightOutData(rRightLoopback),
  107.        
  108.         .oDout(oI2s_dout),
  109.         .oLeftInData(wI2sDataInLeft),
  110.         .oRightInData(wI2sDataInRight),
  111.         .oLeftInReady(wLeftReady),
  112.         .oLeftOutStart(),
  113.         .oRightInReady(wRightReady),
  114.         .oRightOutStart()
  115.     );
  116.  
  117.     always @(posedge wClkMain) begin
  118.         if (!wChipReady)    begin
  119.             rLastRightReady <= 1'b0;
  120.             rLastLeftReady <= 1'b0;
  121.             rRightLoopback <= 16'h0000;
  122.             rLeftLoopback   <= 16'h0000;
  123.         end
  124.         else begin
  125.             rLastRightReady <= wRightReady;
  126.             rLastLeftReady  <= wLeftReady;
  127.  
  128.             if (!rLastRightReady & wRightReady)
  129.                 rRightLoopback <= wI2sDataInRight;
  130.             if (!rLastLeftReady & wLeftReady)
  131.                 rLeftLoopback<= wI2sDataInLeft;
  132.         end
  133.     end
  134.  
  135. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement