Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VeriLog 25.85 KB | None | 0 0
  1. `default_nettype none
  2.  
  3. ///////////////////////////////////////////////////////////////////////////////
  4. //
  5. // Switch Debounce Module
  6. //
  7. ///////////////////////////////////////////////////////////////////////////////
  8.  
  9. module debounce (
  10.   input wire reset, clock, noisy,
  11.   output reg clean
  12. );
  13.   reg [18:0] count;
  14.   reg new;
  15.  
  16.   always @(posedge clock)
  17.     if (reset) begin
  18.       count <= 0;
  19.       new <= noisy;
  20.       clean <= noisy;
  21.     end
  22.     else if (noisy != new) begin
  23.       // noisy input changed, restart the .01 sec clock
  24.       new <= noisy;
  25.       count <= 0;
  26.     end
  27.     else if (count == 270000)
  28.       // noisy input stable for .01 secs, pass it along!
  29.       clean <= new;
  30.     else
  31.       // waiting for .01 sec to pass
  32.       count <= count+1;
  33.  
  34. endmodule
  35.  
  36. ///////////////////////////////////////////////////////////////////////////////
  37. //
  38. // bi-directional monaural interface to AC97
  39. //
  40. ///////////////////////////////////////////////////////////////////////////////
  41.  
  42. module lab5audio (
  43.   input wire clock_27mhz,
  44.   input wire reset,
  45.   input wire [4:0] volume,
  46.   output wire [7:0] audio_in_data,
  47.   input wire [7:0] audio_out_data,
  48.   output wire ready,
  49.   output reg audio_reset_b,   // ac97 interface signals
  50.   output wire ac97_sdata_out,
  51.   input wire ac97_sdata_in,
  52.   output wire ac97_synch,
  53.   input wire ac97_bit_clock
  54. );
  55.  
  56.   wire [7:0] command_address;
  57.   wire [15:0] command_data;
  58.   wire command_valid;
  59.   wire [19:0] left_in_data, right_in_data;
  60.   wire [19:0] left_out_data, right_out_data;
  61.  
  62.   // wait a little before enabling the AC97 codec
  63.   reg [9:0] reset_count;
  64.   always @(posedge clock_27mhz) begin
  65.     if (reset) begin
  66.       audio_reset_b = 1'b0;
  67.       reset_count = 0;
  68.     end else if (reset_count == 1023)
  69.       audio_reset_b = 1'b1;
  70.     else
  71.       reset_count = reset_count+1;
  72.   end
  73.  
  74.   wire ac97_ready;
  75.   ac97 ac97(.ready(ac97_ready),
  76.             .command_address(command_address),
  77.             .command_data(command_data),
  78.             .command_valid(command_valid),
  79.             .left_data(left_out_data), .left_valid(1'b1),
  80.             .right_data(right_out_data), .right_valid(1'b1),
  81.             .left_in_data(left_in_data), .right_in_data(right_in_data),
  82.             .ac97_sdata_out(ac97_sdata_out),
  83.             .ac97_sdata_in(ac97_sdata_in),
  84.             .ac97_synch(ac97_synch),
  85.             .ac97_bit_clock(ac97_bit_clock));
  86.  
  87.   // ready: one cycle pulse synchronous with clock_27mhz
  88.   reg [2:0] ready_sync;
  89.   always @ (posedge clock_27mhz) ready_sync <= {ready_sync[1:0], ac97_ready};
  90.   assign ready = ready_sync[1] & ~ready_sync[2];
  91.  
  92.   reg [7:0] out_data;
  93.   always @ (posedge clock_27mhz)
  94.     if (ready) out_data <= audio_out_data;
  95.   assign audio_in_data = left_in_data[19:12];
  96.   assign left_out_data = {out_data, 12'b000000000000};
  97.   assign right_out_data = left_out_data;
  98.  
  99.   // generate repeating sequence of read/writes to AC97 registers
  100.   ac97commands cmds(.clock(clock_27mhz), .ready(ready),
  101.                     .command_address(command_address),
  102.                     .command_data(command_data),
  103.                     .command_valid(command_valid),
  104.                     .volume(volume),
  105.                     .source(3'b000));     // mic
  106. endmodule
  107.  
  108. // assemble/disassemble AC97 serial frames
  109. module ac97 (
  110.   output reg ready,
  111.   input wire [7:0] command_address,
  112.   input wire [15:0] command_data,
  113.   input wire command_valid,
  114.   input wire [19:0] left_data,
  115.   input wire left_valid,
  116.   input wire [19:0] right_data,
  117.   input wire right_valid,
  118.   output reg [19:0] left_in_data, right_in_data,
  119.   output reg ac97_sdata_out,
  120.   input wire ac97_sdata_in,
  121.   output reg ac97_synch,
  122.   input wire ac97_bit_clock
  123. );
  124.   reg [7:0] bit_count;
  125.  
  126.   reg [19:0] l_cmd_addr;
  127.   reg [19:0] l_cmd_data;
  128.   reg [19:0] l_left_data, l_right_data;
  129.   reg l_cmd_v, l_left_v, l_right_v;
  130.  
  131.   initial begin
  132.     ready <= 1'b0;
  133.     // synthesis attribute init of ready is "0";
  134.     ac97_sdata_out <= 1'b0;
  135.     // synthesis attribute init of ac97_sdata_out is "0";
  136.     ac97_synch <= 1'b0;
  137.     // synthesis attribute init of ac97_synch is "0";
  138.  
  139.     bit_count <= 8'h00;
  140.     // synthesis attribute init of bit_count is "0000";
  141.     l_cmd_v <= 1'b0;
  142.     // synthesis attribute init of l_cmd_v is "0";
  143.     l_left_v <= 1'b0;
  144.     // synthesis attribute init of l_left_v is "0";
  145.     l_right_v <= 1'b0;
  146.     // synthesis attribute init of l_right_v is "0";
  147.  
  148.     left_in_data <= 20'h00000;
  149.     // synthesis attribute init of left_in_data is "00000";
  150.     right_in_data <= 20'h00000;
  151.     // synthesis attribute init of right_in_data is "00000";
  152.   end
  153.  
  154.   always @(posedge ac97_bit_clock) begin
  155.     // Generate the sync signal
  156.     if (bit_count == 255)
  157.       ac97_synch <= 1'b1;
  158.     if (bit_count == 15)
  159.       ac97_synch <= 1'b0;
  160.  
  161.     // Generate the ready signal
  162.     if (bit_count == 128)
  163.       ready <= 1'b1;
  164.     if (bit_count == 2)
  165.       ready <= 1'b0;
  166.  
  167.     // Latch user data at the end of each frame. This ensures that the
  168.     // first frame after reset will be empty.
  169.     if (bit_count == 255) begin
  170.       l_cmd_addr <= {command_address, 12'h000};
  171.       l_cmd_data <= {command_data, 4'h0};
  172.       l_cmd_v <= command_valid;
  173.       l_left_data <= left_data;
  174.       l_left_v <= left_valid;
  175.       l_right_data <= right_data;
  176.       l_right_v <= right_valid;
  177.     end
  178.  
  179.     if ((bit_count >= 0) && (bit_count <= 15))
  180.       // Slot 0: Tags
  181.       case (bit_count[3:0])
  182.         4'h0: ac97_sdata_out <= 1'b1;      // Frame valid
  183.         4'h1: ac97_sdata_out <= l_cmd_v;   // Command address valid
  184.         4'h2: ac97_sdata_out <= l_cmd_v;   // Command data valid
  185.         4'h3: ac97_sdata_out <= l_left_v;  // Left data valid
  186.         4'h4: ac97_sdata_out <= l_right_v; // Right data valid
  187.         default: ac97_sdata_out <= 1'b0;
  188.       endcase
  189.     else if ((bit_count >= 16) && (bit_count <= 35))
  190.       // Slot 1: Command address (8-bits, left justified)
  191.       ac97_sdata_out <= l_cmd_v ? l_cmd_addr[35-bit_count] : 1'b0;
  192.     else if ((bit_count >= 36) && (bit_count <= 55))
  193.       // Slot 2: Command data (16-bits, left justified)
  194.       ac97_sdata_out <= l_cmd_v ? l_cmd_data[55-bit_count] : 1'b0;
  195.     else if ((bit_count >= 56) && (bit_count <= 75)) begin
  196.       // Slot 3: Left channel
  197.       ac97_sdata_out <= l_left_v ? l_left_data[19] : 1'b0;
  198.       l_left_data <= { l_left_data[18:0], l_left_data[19] };
  199.     end
  200.     else if ((bit_count >= 76) && (bit_count <= 95))
  201.       // Slot 4: Right channel
  202.       ac97_sdata_out <= l_right_v ? l_right_data[95-bit_count] : 1'b0;
  203.     else
  204.       ac97_sdata_out <= 1'b0;
  205.  
  206.     bit_count <= bit_count+1;
  207.   end // always @ (posedge ac97_bit_clock)
  208.  
  209.   always @(negedge ac97_bit_clock) begin
  210.     if ((bit_count >= 57) && (bit_count <= 76))
  211.       // Slot 3: Left channel
  212.       left_in_data <= { left_in_data[18:0], ac97_sdata_in };
  213.     else if ((bit_count >= 77) && (bit_count <= 96))
  214.       // Slot 4: Right channel
  215.       right_in_data <= { right_in_data[18:0], ac97_sdata_in };
  216.   end
  217. endmodule
  218.  
  219. // issue initialization commands to AC97
  220. module ac97commands (
  221.   input wire clock,
  222.   input wire ready,
  223.   output wire [7:0] command_address,
  224.   output wire [15:0] command_data,
  225.   output reg command_valid,
  226.   input wire [4:0] volume,
  227.   input wire [2:0] source
  228. );
  229.   reg [23:0] command;
  230.  
  231.   reg [3:0] state;
  232.   initial begin
  233.     command <= 4'h0;
  234.     // synthesis attribute init of command is "0";
  235.     command_valid <= 1'b0;
  236.     // synthesis attribute init of command_valid is "0";
  237.     state <= 16'h0000;
  238.     // synthesis attribute init of state is "0000";
  239.   end
  240.  
  241.   assign command_address = command[23:16];
  242.   assign command_data = command[15:0];
  243.  
  244.   wire [4:0] vol;
  245.   assign vol = 31-volume;  // convert to attenuation
  246.  
  247.   always @(posedge clock) begin
  248.     if (ready) state <= state+1;
  249.  
  250.     case (state)
  251.       4'h0: // Read ID
  252.         begin
  253.           command <= 24'h80_0000;
  254.           command_valid <= 1'b1;
  255.         end
  256.       4'h1: // Read ID
  257.         command <= 24'h80_0000;
  258.       4'h3: // headphone volume
  259.         command <= { 8'h04, 3'b000, vol, 3'b000, vol };
  260.       4'h5: // PCM volume
  261.         command <= 24'h18_0808;
  262.       4'h6: // Record source select
  263.         command <= { 8'h1A, 5'b00000, source, 5'b00000, source};
  264.       4'h7: // Record gain = max
  265.         command <= 24'h1C_0F0F;
  266.       4'h9: // set +20db mic gain
  267.         command <= 24'h0E_8048;
  268.       4'hA: // Set beep volume
  269.         command <= 24'h0A_0000;
  270.       4'hB: // PCM out bypass mix1
  271.         command <= 24'h20_8000;
  272.       default:
  273.         command <= 24'h80_0000;
  274.     endcase // case(state)
  275.   end // always @ (posedge clock)
  276. endmodule // ac97commands
  277.  
  278. ///////////////////////////////////////////////////////////////////////////////
  279. //
  280. // generate PCM data for 750hz sine wave (assuming f(ready) = 48khz)
  281. //
  282. ///////////////////////////////////////////////////////////////////////////////
  283.  
  284. module tone750hz (
  285.   input wire clock,
  286.   input wire ready,
  287.   output reg [19:0] pcm_data
  288. );
  289.   reg [8:0] index;
  290.  
  291.   initial begin
  292.     index <= 8'h00;
  293.     // synthesis attribute init of index is "00";
  294.     pcm_data <= 20'h00000;
  295.     // synthesis attribute init of pcm_data is "00000";
  296.   end
  297.  
  298.   always @(posedge clock) begin
  299.     if (ready) index <= index+1;
  300.   end
  301.  
  302.   // one cycle of a sinewave in 64 20-bit samples
  303.   always @(index) begin
  304.     case (index[5:0])
  305.       6'h00: pcm_data <= 20'h00000;
  306.       6'h01: pcm_data <= 20'h0C8BD;
  307.       6'h02: pcm_data <= 20'h18F8B;
  308.       6'h03: pcm_data <= 20'h25280;
  309.       6'h04: pcm_data <= 20'h30FBC;
  310.       6'h05: pcm_data <= 20'h3C56B;
  311.       6'h06: pcm_data <= 20'h471CE;
  312.       6'h07: pcm_data <= 20'h5133C;
  313.       6'h08: pcm_data <= 20'h5A827;
  314.       6'h09: pcm_data <= 20'h62F20;
  315.       6'h0A: pcm_data <= 20'h6A6D9;
  316.       6'h0B: pcm_data <= 20'h70E2C;
  317.       6'h0C: pcm_data <= 20'h7641A;
  318.       6'h0D: pcm_data <= 20'h7A7D0;
  319.       6'h0E: pcm_data <= 20'h7D8A5;
  320.       6'h0F: pcm_data <= 20'h7F623;
  321.       6'h10: pcm_data <= 20'h7FFFF;
  322.       6'h11: pcm_data <= 20'h7F623;
  323.       6'h12: pcm_data <= 20'h7D8A5;
  324.       6'h13: pcm_data <= 20'h7A7D0;
  325.       6'h14: pcm_data <= 20'h7641A;
  326.       6'h15: pcm_data <= 20'h70E2C;
  327.       6'h16: pcm_data <= 20'h6A6D9;
  328.       6'h17: pcm_data <= 20'h62F20;
  329.       6'h18: pcm_data <= 20'h5A827;
  330.       6'h19: pcm_data <= 20'h5133C;
  331.       6'h1A: pcm_data <= 20'h471CE;
  332.       6'h1B: pcm_data <= 20'h3C56B;
  333.       6'h1C: pcm_data <= 20'h30FBC;
  334.       6'h1D: pcm_data <= 20'h25280;
  335.       6'h1E: pcm_data <= 20'h18F8B;
  336.       6'h1F: pcm_data <= 20'h0C8BD;
  337.       6'h20: pcm_data <= 20'h00000;
  338.       6'h21: pcm_data <= 20'hF3743;
  339.       6'h22: pcm_data <= 20'hE7075;
  340.       6'h23: pcm_data <= 20'hDAD80;
  341.       6'h24: pcm_data <= 20'hCF044;
  342.       6'h25: pcm_data <= 20'hC3A95;
  343.       6'h26: pcm_data <= 20'hB8E32;
  344.       6'h27: pcm_data <= 20'hAECC4;
  345.       6'h28: pcm_data <= 20'hA57D9;
  346.       6'h29: pcm_data <= 20'h9D0E0;
  347.       6'h2A: pcm_data <= 20'h95927;
  348.       6'h2B: pcm_data <= 20'h8F1D4;
  349.       6'h2C: pcm_data <= 20'h89BE6;
  350.       6'h2D: pcm_data <= 20'h85830;
  351.       6'h2E: pcm_data <= 20'h8275B;
  352.       6'h2F: pcm_data <= 20'h809DD;
  353.       6'h30: pcm_data <= 20'h80000;
  354.       6'h31: pcm_data <= 20'h809DD;
  355.       6'h32: pcm_data <= 20'h8275B;
  356.       6'h33: pcm_data <= 20'h85830;
  357.       6'h34: pcm_data <= 20'h89BE6;
  358.       6'h35: pcm_data <= 20'h8F1D4;
  359.       6'h36: pcm_data <= 20'h95927;
  360.       6'h37: pcm_data <= 20'h9D0E0;
  361.       6'h38: pcm_data <= 20'hA57D9;
  362.       6'h39: pcm_data <= 20'hAECC4;
  363.       6'h3A: pcm_data <= 20'hB8E32;
  364.       6'h3B: pcm_data <= 20'hC3A95;
  365.       6'h3C: pcm_data <= 20'hCF044;
  366.       6'h3D: pcm_data <= 20'hDAD80;
  367.       6'h3E: pcm_data <= 20'hE7075;
  368.       6'h3F: pcm_data <= 20'hF3743;
  369.     endcase // case(index[5:0])
  370.   end // always @ (index)
  371. endmodule
  372.  
  373. /////////////////////////////////////////////////////////////////////////////////
  374. ////
  375. //// 6.111 FPGA Labkit -- Template Toplevel Module
  376. ////
  377. //// For Labkit Revision 004
  378. //// Created: October 31, 2004, from revision 003 file
  379. //// Author: Nathan Ickes, 6.111 staff
  380. ////
  381. /////////////////////////////////////////////////////////////////////////////////
  382.  
  383. module lab5   (beep, audio_reset_b, ac97_sdata_out, ac97_sdata_in, ac97_synch,
  384.         ac97_bit_clock,
  385.        
  386.         vga_out_red, vga_out_green, vga_out_blue, vga_out_sync_b,
  387.         vga_out_blank_b, vga_out_pixel_clock, vga_out_hsync,
  388.         vga_out_vsync,
  389.  
  390.         tv_out_ycrcb, tv_out_reset_b, tv_out_clock, tv_out_i2c_clock,
  391.         tv_out_i2c_data, tv_out_pal_ntsc, tv_out_hsync_b,
  392.         tv_out_vsync_b, tv_out_blank_b, tv_out_subcar_reset,
  393.  
  394.         tv_in_ycrcb, tv_in_data_valid, tv_in_line_clock1,
  395.         tv_in_line_clock2, tv_in_aef, tv_in_hff, tv_in_aff,
  396.         tv_in_i2c_clock, tv_in_i2c_data, tv_in_fifo_read,
  397.         tv_in_fifo_clock, tv_in_iso, tv_in_reset_b, tv_in_clock,
  398.  
  399.         ram0_data, ram0_address, ram0_adv_ld, ram0_clk, ram0_cen_b,
  400.         ram0_ce_b, ram0_oe_b, ram0_we_b, ram0_bwe_b,
  401.  
  402.         ram1_data, ram1_address, ram1_adv_ld, ram1_clk, ram1_cen_b,
  403.         ram1_ce_b, ram1_oe_b, ram1_we_b, ram1_bwe_b,
  404.  
  405.         clock_feedback_out, clock_feedback_in,
  406.  
  407.         flash_data, flash_address, flash_ce_b, flash_oe_b, flash_we_b,
  408.         flash_reset_b, flash_sts, flash_byte_b,
  409.  
  410.         rs232_txd, rs232_rxd, rs232_rts, rs232_cts,
  411.  
  412.         mouse_clock, mouse_data, keyboard_clock, keyboard_data,
  413.  
  414.         clock_27mhz, clock1, clock2,
  415.  
  416.         disp_blank, disp_data_out, disp_clock, disp_rs, disp_ce_b,
  417.         disp_reset_b, disp_data_in,
  418.  
  419.         button0, button1, button2, button3, button_enter, button_right,
  420.         button_left, button_down, button_up,
  421.  
  422.         switch,
  423.  
  424.         led,
  425.        
  426.         user1, user2, user3, user4,
  427.        
  428.         daughtercard,
  429.  
  430.         systemace_data, systemace_address, systemace_ce_b,
  431.         systemace_we_b, systemace_oe_b, systemace_irq, systemace_mpbrdy,
  432.        
  433.         analyzer1_data, analyzer1_clock,
  434.         analyzer2_data, analyzer2_clock,
  435.         analyzer3_data, analyzer3_clock,
  436.         analyzer4_data, analyzer4_clock);
  437.  
  438.   output beep, audio_reset_b, ac97_synch, ac97_sdata_out;
  439.   input  ac97_bit_clock, ac97_sdata_in;
  440.  
  441.   output [7:0] vga_out_red, vga_out_green, vga_out_blue;
  442.   output vga_out_sync_b, vga_out_blank_b, vga_out_pixel_clock,
  443.    vga_out_hsync, vga_out_vsync;
  444.  
  445.   output [9:0] tv_out_ycrcb;
  446.   output tv_out_reset_b, tv_out_clock, tv_out_i2c_clock, tv_out_i2c_data,
  447.    tv_out_pal_ntsc, tv_out_hsync_b, tv_out_vsync_b, tv_out_blank_b,
  448.    tv_out_subcar_reset;
  449.  
  450.   input  [19:0] tv_in_ycrcb;
  451.   input  tv_in_data_valid, tv_in_line_clock1, tv_in_line_clock2, tv_in_aef,
  452.    tv_in_hff, tv_in_aff;
  453.   output tv_in_i2c_clock, tv_in_fifo_read, tv_in_fifo_clock, tv_in_iso,
  454.    tv_in_reset_b, tv_in_clock;
  455.   inout  tv_in_i2c_data;
  456.        
  457.   inout  [35:0] ram0_data;
  458.   output [18:0] ram0_address;
  459.   output ram0_adv_ld, ram0_clk, ram0_cen_b, ram0_ce_b, ram0_oe_b, ram0_we_b;
  460.   output [3:0] ram0_bwe_b;
  461.  
  462.   inout  [35:0] ram1_data;
  463.   output [18:0] ram1_address;
  464.   output ram1_adv_ld, ram1_clk, ram1_cen_b, ram1_ce_b, ram1_oe_b, ram1_we_b;
  465.   output [3:0] ram1_bwe_b;
  466.  
  467.   input  clock_feedback_in;
  468.   output clock_feedback_out;
  469.  
  470.   inout  [15:0] flash_data;
  471.   output [23:0] flash_address;
  472.   output flash_ce_b, flash_oe_b, flash_we_b, flash_reset_b, flash_byte_b;
  473.   input  flash_sts;
  474.  
  475.   output rs232_txd, rs232_rts;
  476.   input  rs232_rxd, rs232_cts;
  477.  
  478.   input  mouse_clock, mouse_data, keyboard_clock, keyboard_data;
  479.  
  480.   input  clock_27mhz, clock1, clock2;
  481.  
  482.   output disp_blank, disp_clock, disp_rs, disp_ce_b, disp_reset_b;  
  483.   input  disp_data_in;
  484.   output  disp_data_out;
  485.  
  486.   input  button0, button1, button2, button3, button_enter, button_right,
  487.    button_left, button_down, button_up;
  488.   input  [7:0] switch;
  489.   output [7:0] led;
  490.  
  491.   inout [31:0] user1, user2, user3, user4;
  492.  
  493.   inout [43:0] daughtercard;
  494.  
  495.   inout  [15:0] systemace_data;
  496.   output [6:0]  systemace_address;
  497.   output systemace_ce_b, systemace_we_b, systemace_oe_b;
  498.   input  systemace_irq, systemace_mpbrdy;
  499.  
  500.   output [15:0] analyzer1_data, analyzer2_data, analyzer3_data,
  501.     analyzer4_data;
  502.   output analyzer1_clock, analyzer2_clock, analyzer3_clock, analyzer4_clock;
  503.  
  504.   ////////////////////////////////////////////////////////////////////////////
  505.   //
  506.   // I/O Assignments
  507.   //
  508.   ////////////////////////////////////////////////////////////////////////////
  509.  
  510.  
  511.   // Audio Input and Output
  512.   assign beep= 1'b0;
  513.   //lab5 assign audio_reset_b = 1'b0;
  514.   //lab5 assign ac97_synch = 1'b0;
  515.   //lab5 assign ac97_sdata_out = 1'b0;
  516.   // ac97_sdata_in is an input
  517.  
  518.   // VGA Output
  519.   assign vga_out_red = 10'h0;
  520.   assign vga_out_green = 10'h0;
  521.   assign vga_out_blue = 10'h0;
  522.   assign vga_out_sync_b = 1'b1;
  523.   assign vga_out_blank_b = 1'b1;
  524.   assign vga_out_pixel_clock = 1'b0;
  525.   assign vga_out_hsync = 1'b0;
  526.   assign vga_out_vsync = 1'b0;
  527.  
  528.   // Video Output
  529.   assign tv_out_ycrcb = 10'h0;
  530.   assign tv_out_reset_b = 1'b0;
  531.   assign tv_out_clock = 1'b0;
  532.   assign tv_out_i2c_clock = 1'b0;
  533.   assign tv_out_i2c_data = 1'b0;
  534.   assign tv_out_pal_ntsc = 1'b0;
  535.   assign tv_out_hsync_b = 1'b1;
  536.   assign tv_out_vsync_b = 1'b1;
  537.   assign tv_out_blank_b = 1'b1;
  538.   assign tv_out_subcar_reset = 1'b0;
  539.  
  540.   // Video Input
  541.   assign tv_in_i2c_clock = 1'b0;
  542.   assign tv_in_fifo_read = 1'b0;
  543.   assign tv_in_fifo_clock = 1'b0;
  544.   assign tv_in_iso = 1'b0;
  545.   assign tv_in_reset_b = 1'b0;
  546.   assign tv_in_clock = 1'b0;
  547.   assign tv_in_i2c_data = 1'bZ;
  548.   // tv_in_ycrcb, tv_in_data_valid, tv_in_line_clock1, tv_in_line_clock2,
  549.   // tv_in_aef, tv_in_hff, and tv_in_aff are inputs
  550.  
  551.   // SRAMs
  552.   assign ram0_data = 36'hZ;
  553.   assign ram0_address = 19'h0;
  554.   assign ram0_adv_ld = 1'b0;
  555.   assign ram0_clk = 1'b0;
  556.   assign ram0_cen_b = 1'b1;
  557.   assign ram0_ce_b = 1'b1;
  558.   assign ram0_oe_b = 1'b1;
  559.   assign ram0_we_b = 1'b1;
  560.   assign ram0_bwe_b = 4'hF;
  561.   assign ram1_data = 36'hZ;
  562.   assign ram1_address = 19'h0;
  563.   assign ram1_adv_ld = 1'b0;
  564.   assign ram1_clk = 1'b0;
  565.   assign ram1_cen_b = 1'b1;
  566.   assign ram1_ce_b = 1'b1;
  567.   assign ram1_oe_b = 1'b1;
  568.   assign ram1_we_b = 1'b1;
  569.   assign ram1_bwe_b = 4'hF;
  570.   assign clock_feedback_out = 1'b0;
  571.   // clock_feedback_in is an input
  572.  
  573.   // Flash ROM
  574.   // assign flash_data = 16'hZ;
  575.   // assign flash_address = 24'h0;
  576.   // assign flash_ce_b = 1'b1;
  577.   // assign flash_oe_b = 1'b1;
  578.   // assign flash_we_b = 1'b1;
  579.   // assign flash_reset_b = 1'b0;
  580.   // assign flash_byte_b = 1'b1;
  581.   // flash_sts is an input
  582.  
  583.   // RS-232 Interface
  584.   assign rs232_txd = 1'b1;
  585.   assign rs232_rts = 1'b1;
  586.   // rs232_rxd and rs232_cts are inputs
  587.  
  588.   // PS/2 Ports
  589.   // mouse_clock, mouse_data, keyboard_clock, and keyboard_data are inputs
  590.  
  591.   // LED Displays
  592.   // assign disp_blank = 1'b1;
  593.   // assign disp_clock = 1'b0;
  594.   // assign disp_rs = 1'b0;
  595.   // assign disp_ce_b = 1'b1;
  596.   // assign disp_reset_b = 1'b0;
  597.   // assign disp_data_out = 1'b0;
  598.   // disp_data_in is an input
  599.  
  600.   // Buttons, Switches, and Individual LEDs
  601.   //lab5 assign led = 8'hFF;
  602.   // button0, button1, button2, button3, button_enter, button_right,
  603.   // button_left, button_down, button_up, and switches are inputs
  604.  
  605.   // User I/Os
  606.   //assign user1 = 32'hZ;
  607.   assign user2 = 32'hZ;
  608.   assign user3 = 32'hZ;
  609.   assign user4 = 32'hZ;
  610.  
  611.   // Daughtercard Connectors
  612.   assign daughtercard = 44'hZ;
  613.  
  614.   // SystemACE Microprocessor Port
  615.   assign systemace_data = 16'hZ;
  616.   assign systemace_address = 7'h0;
  617.   assign systemace_ce_b = 1'b1;
  618.   assign systemace_we_b = 1'b1;
  619.   assign systemace_oe_b = 1'b1;
  620.   // systemace_irq and systemace_mpbrdy are inputs
  621.  
  622.   // Logic Analyzer
  623.   //lab5 assign analyzer1_data = 16'h0;
  624.   //lab5 assign analyzer1_clock = 1'b1;
  625.   assign analyzer2_data = 16'h0;
  626.   assign analyzer2_clock = 1'b1;
  627.   //lab5 assign analyzer3_data = 16'h0;
  628.   //lab5 assign analyzer3_clock = 1'b1;
  629.   assign analyzer4_data = 16'h0;
  630.   assign analyzer4_clock = 1'b1;
  631.          
  632. //   wire [7:0] from_ac97_data, to_ac97_data;
  633. //   wire ready;
  634.  
  635.   ////////////////////////////////////////////////////////////////////////////
  636.   //
  637.   // Reset Generation
  638.   //
  639.   // A shift register primitive is used to generate an active-high reset
  640.   // signal that remains high for 16 clock cycles after configuration finishes
  641.   // and the FPGA's internal clocks begin toggling.
  642.   //
  643.   ////////////////////////////////////////////////////////////////////////////
  644.   wire reset;
  645.   SRL16 #(.INIT(16'hFFFF)) reset_sr(.D(1'b0), .CLK(clock_27mhz), .Q(reset),
  646.                                     .A0(1'b1), .A1(1'b1), .A2(1'b1), .A3(1'b1));
  647.          
  648.   wire [7:0] from_ac97_data, to_ac97_data;
  649.   wire ready;
  650.  
  651.   // allow user to adjust volume
  652.   wire vup,vdown;
  653.   reg old_vup,old_vdown;
  654.   debounce bup(.reset(reset),.clock(clock_27mhz),.noisy(~button_up),.clean(vup));
  655.   debounce bdown(.reset(reset),.clock(clock_27mhz),.noisy(~button_down),.clean(vdown));
  656.   reg [4:0] volume;
  657.   always @ (posedge clock_27mhz) begin
  658.     if (reset) volume <= 5'd8;
  659.     else begin
  660.       if (vup & ~old_vup & volume != 5'd31) volume <= volume+1;      
  661.       if (vdown & ~old_vdown & volume != 5'd0) volume <= volume-1;      
  662.     end
  663.     old_vup <= vup;
  664.     old_vdown <= vdown;
  665.   end
  666.  
  667.   wire [63:0] hexdisp;
  668.   // wire disp_blank;
  669.   // wire disp_clock;
  670.   // wire disp_rs;
  671.   // wire disp_ce_b;
  672.   // wire disp_reset_b;
  673.   // wire disp_data_out;
  674.  
  675.   // hex display
  676.   display_16hex disp(
  677.     .reset(reset),
  678.     .clock_27mhz(clock_27mhz),
  679.     .data(hexdisp),
  680.     .disp_blank(disp_blank),
  681.     .disp_clock(disp_clock),
  682.     .disp_rs(disp_rs),
  683.     .disp_ce_b(disp_ce_b),
  684.     .disp_reset_b(disp_reset_b),
  685.     .disp_data_out(disp_data_out)
  686.   );
  687.  
  688.   // AC97 driver
  689.   lab5audio a(clock_27mhz, reset, volume, from_ac97_data, to_ac97_data, ready,
  690.         audio_reset_b, ac97_sdata_out, ac97_sdata_in,
  691.         ac97_synch, ac97_bit_clock);
  692.  
  693.   // writeSwitch UP to write, DOWN to read
  694.   wire writeSwitch;
  695.   debounce sw7(.reset(reset),.clock(clock_27mhz),.noisy(switch[7]),.clean(writeSwitch));
  696.  
  697.   wire memReset;
  698.   debounce benter(.reset(reset),.clock(clock_27mhz),.noisy(button_enter),.clean(memReset));
  699.  
  700.   // switch 0 up for filtering, down for no filtering
  701.   wire filter;
  702.   debounce sw0(.reset(reset),.clock(clock_27mhz),.noisy(switch[0]),.clean(filter));
  703.  
  704.   wire busy;
  705.   // light up LED when CF is busy
  706.   // led is active low
  707.   assign led = ~{busy, 6'h00, filter};
  708.  
  709.   // record module
  710.   audioManager management(
  711.     .clock(clock_27mhz),
  712.     .reset(memReset),
  713.     .writeSwitch(writeSwitch),
  714.     .ready(ready),
  715.     .filter(filter),
  716.     .from_ac97_data(from_ac97_data),
  717.     .to_ac97_data(to_ac97_data),
  718.     .hexdisp(hexdisp),
  719.     .flash_data(flash_data),
  720.     .flash_address(flash_address),
  721.     .flash_ce_b(flash_ce_b),
  722.     .flash_oe_b(flash_oe_b),
  723.     .flash_we_b(flash_we_b),
  724.     .flash_reset_b(flash_reset_b),
  725.     .flash_byte_b(flash_byte_b),
  726.     .flash_sts(flash_sts),
  727.     .busy(busy)
  728.   );
  729.  
  730.   // output useful things to the logic analyzer connectors
  731.   assign analyzer1_clock = ac97_bit_clock;
  732.   assign analyzer1_data[0] = audio_reset_b;
  733.   assign analyzer1_data[1] = ac97_sdata_out;
  734.   assign analyzer1_data[2] = ac97_sdata_in;
  735.   assign analyzer1_data[3] = ac97_synch;
  736.   assign analyzer1_data[15:4] = 0;
  737.  
  738.   assign analyzer3_clock = ready;
  739.   assign analyzer3_data = {from_ac97_data, to_ac97_data};
  740. endmodule
  741.  
  742. ///////////////////////////////////////////////////////////////////////////////
  743. //
  744. // Record/playback
  745. //
  746. ///////////////////////////////////////////////////////////////////////////////
  747.  
  748. module audioManager(
  749.   input wire clock,            // 27mhz system clock
  750.   input wire reset,                // 1 to reset to initial state
  751.   input wire writeSwitch,             // 1 for writeSwitch, 0 for record
  752.   input wire ready,                // 1 when AC97 data is available
  753.   input wire filter,               // 1 when using low-pass filter
  754.   input wire [7:0] from_ac97_data, // 8-bit PCM data from mic
  755.   output reg [7:0] to_ac97_data,    // 8-bit PCM data to headphone
  756.   output reg [63:0] hexdisp,
  757.   output wire [15:0] flash_data,
  758.   output wire [23:0] flash_address,
  759.   output wire flash_ce_b,
  760.   output wire flash_oe_b,
  761.   output wire flash_we_b,
  762.   output wire flash_reset_b,
  763.   output wire flash_byte_b,
  764.   input wire flash_sts,
  765.   output wire busy
  766. );
  767.  
  768.   wire [639:0] dots;
  769.   reg writemode;         //1=write mode; 0=read mode
  770.   reg [15:0] wdata;      //writeData
  771.   reg dowrite;           //1=new data, write it
  772.   reg [22:0] raddr;      //readAddress
  773.   wire [15:0] frdata;     //readData
  774.   reg doread;            //1=execute read
  775.   //wire busy;              //1=busy, wait
  776.  
  777.   // UNUSED -- LOW LEVEL ACCESS
  778.   //direct passthrough from labkit to low-level modules (flash_int and test_fsm)
  779.   // wire [15:0] flash_data;
  780.   // wire [23:0] flash_address;
  781.   // wire flash_ce_b;
  782.   // wire flash_oe_b;
  783.   // wire flash_we_b;
  784.   // wire flash_reset_b;
  785.   // wire flash_sts;
  786.   // wire flash_byte_b;
  787.  
  788.   wire [11:0] fsmstate;
  789.   // END UNUSED
  790.  
  791.   // FlashManager
  792.   flash_manager fm(
  793.     .clock(clock),
  794.     .reset(reset),
  795.     .dots(dots),
  796.     .writemode(writemode),
  797.     .wdata(wdata),
  798.     .dowrite(dowrite),
  799.     .raddr(raddr),
  800.     .frdata(frdata),
  801.     .doread(doread),
  802.     .busy(busy),
  803.     .flash_data(flash_data),
  804.     .flash_address(flash_address),
  805.     .flash_ce_b(flash_ce_b),
  806.     .flash_oe_b(flash_oe_b),
  807.     .flash_we_b(flash_we_b),
  808.     .flash_reset_b(flash_reset_b),
  809.     .flash_sts(flash_sts),
  810.     .flash_byte_b(flash_byte_b),
  811.     .fsmstate(fsmstate)
  812.   );
  813.  
  814.   always @ (posedge clock) begin
  815.     // write arbitrary data to CF if writeSwitch is UP
  816.     if (writeSwitch) begin
  817.       writemode <= 1'b1;
  818.       doread <= 1'b0;
  819.       //if (~busy) begin
  820.         wdata <= 16'hABCD;
  821.         dowrite <= 1'b1;
  822.       //end
  823.     end
  824.  
  825.     // if button is DOWN
  826.     if (~writeSwitch) begin
  827.       // show on display
  828.       dowrite <= 1'b0;
  829.       writemode <= 1'b0;
  830.       raddr <= 2;
  831.       doread <= 1'b1;
  832.       hexdisp <= {1'h0, fsmstate[11:9], 3'h0, fsmstate[8], 44'h0, frdata};
  833.     end // if (writeSwitch)
  834.   end // always @
  835. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement