Advertisement
Guest User

poypoycharly

a guest
Jun 17th, 2009
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.16 KB | None | 0 0
  1. /*****************************************************************************
  2.  *                                                                           *
  3.  * Module:       Altera_UP_Avalon_Parallel_Port                              *
  4.  * Description:                                                              *
  5.  *      This module can read and/or write data to a parallel I/O port based  *
  6.  *   on various user selected parameters. It has some predefined             *
  7.  *   configurations for some devices on the Altera DE boards.                *
  8.  *                                                                           *
  9.  *****************************************************************************/
  10.  
  11. module GPIO_1 (
  12.     // Inputs
  13.     clk,
  14.     reset,
  15.    
  16.     address,
  17.     byteenable,
  18.     chipselect,
  19.     read,
  20.     write,
  21.     writedata,
  22.  
  23.  
  24.     // Bidirectionals
  25.     GPIO_1,
  26.  
  27.     // Outputs
  28.     irq,
  29.     readdata
  30. );
  31.  
  32. /*****************************************************************************
  33.  *                           Parameter Declarations                          *
  34.  *****************************************************************************/
  35.  
  36. // DW represents the Data Width minus 1
  37. parameter DW = 35;
  38.  
  39. /*****************************************************************************
  40.  *                             Port Declarations                             *
  41.  *****************************************************************************/
  42. // Inputs
  43. input               clk;
  44. input               reset;
  45.  
  46. input       [1:0]   address;
  47. input       [3:0]   byteenable;
  48. input               chipselect;
  49. input               read;
  50. input               write;
  51. input       [35:0]  writedata;
  52.  
  53.  
  54. // Bidirectionals
  55. inout       [39:0]  GPIO_1;
  56.  
  57. // Outputs
  58.  
  59. output  reg         irq;
  60. output  reg [35:0]  readdata;
  61.  
  62. /*****************************************************************************
  63.  *                 Internal wires and registers Declarations                 *
  64.  *****************************************************************************/
  65. // Internal Wires
  66. wire        [DW:0]  new_capture;
  67.  
  68. // Internal Registers
  69. reg         [DW:0]  data;
  70. reg         [DW:0]  direction;
  71. reg         [DW:0]  interrupt;
  72. reg         [DW:0]  capture;
  73.  
  74. reg         [DW:0]  data_in;
  75. reg         [DW:0]  data_out;
  76.  
  77. reg         [DW:0]  last_data_in;
  78.  
  79. // State Machine Registers
  80.  
  81. // Internal Variables
  82. genvar              i;
  83.  
  84.  
  85. /*****************************************************************************
  86.  *                         Finite State Machine(s)                           *
  87.  *****************************************************************************/
  88.  
  89.  
  90. /*****************************************************************************
  91.  *                             Sequential logic                              *
  92.  *****************************************************************************/
  93.  
  94. // Input Registers
  95. always @(posedge clk)
  96.     data_in <= {GPIO_1[35:0]};
  97.  
  98. // Output Registers
  99. always @(posedge clk)
  100. begin
  101.     if (reset == 1'b1)
  102.         irq <= 1'b0;
  103.     else
  104.         irq <= (|(interrupt & capture));
  105. end
  106.  
  107. always @(posedge clk)
  108. begin
  109.     if (reset == 1'b1)
  110.         readdata <= 36'h00000000;
  111.     else if (chipselect == 1'b1)
  112.     begin
  113.         if (address == 2'h0)
  114.             readdata <= {{(35-DW){1'b0}}, data_in};
  115.         else if (address == 2'h1)
  116.             readdata <= {{(35-DW){1'b0}}, direction};
  117.         else if (address == 2'h2)
  118.             readdata <= {{(35-DW){1'b0}}, interrupt};
  119.         else if (address == 2'h3)
  120.             readdata <= {{(35-DW){1'b0}}, capture};
  121.         else
  122.             readdata <= 36'h00000000;
  123.     end
  124. end
  125.  
  126. // Internal Registers
  127. always @(posedge clk)
  128. begin
  129.     if (reset == 1'b1)
  130.         data <= {(DW + 1){1'b0}};
  131.     else if ((chipselect == 1'b1) &&
  132.             (write == 1'b1) &&
  133.             (address == 2'h0))
  134.         data <= {writedata[DW:0]};
  135. end
  136.  
  137. always @(posedge clk)
  138. begin
  139.     if (reset == 1'b1)
  140.         direction <= {(DW + 1){1'b0}};
  141.     else if ((chipselect == 1'b1) &&
  142.             (write == 1'b1) &&
  143.             (address == 2'h1))
  144.         direction <= {writedata[DW:0]};
  145. end
  146.  
  147. always @(posedge clk)
  148. begin
  149.     if (reset == 1'b1)
  150.         interrupt <= {(DW + 1){1'b0}};
  151.     else if ((chipselect == 1'b1) &&
  152.             (write == 1'b1) &&
  153.             (address == 2'h2))
  154.         interrupt <= {writedata[DW:0]};
  155. end
  156.  
  157. always @(posedge clk)
  158. begin
  159.     if (reset == 1'b1)
  160.         capture <= {(DW + 1){1'b0}};
  161.     else if ((chipselect == 1'b1) &&
  162.             (write == 1'b1) &&
  163.             (address == 2'h3))
  164.         capture <= {(DW + 1){1'b0}};
  165.     else
  166.         capture <= capture | new_capture;
  167. end
  168.  
  169. always @(posedge clk)
  170.     data_out <= data;
  171.  
  172. always @(posedge clk)
  173. begin
  174.     if (reset == 1'b1)
  175.         last_data_in <= {DW{1'b0}};
  176.     else
  177.         last_data_in <= data_in;
  178. end
  179.  
  180. /*****************************************************************************
  181. *                            Combinational logic                            *
  182. *****************************************************************************/
  183.  
  184. // Output Assignments
  185. generate
  186.    for (i=0; i <= DW; i = i + 1)
  187.    begin : assign_data_out
  188.        assign GPIO_1[i] = direction[i] ? data_out[i] : 1'bZ;
  189.     end
  190. endgenerate
  191.  
  192.  
  193. // Internal Assignments
  194. assign new_capture = ~data_in & last_data_in;
  195.  
  196. /*****************************************************************************
  197.  *                              Internal Modules                             *
  198.  *****************************************************************************/
  199.  
  200.  
  201. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement