2 // Copyright (C) 2008 Tomasz Malesinski <tmal@mimuw.edu.pl>
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // TODO: interrupt input/outputs
20 module pia(rst_i
, clk_i
,
53 wire [7:0] pa_i
, pb_i
;
54 wire [7:0] pa_o
, pb_o
;
56 reg [7:0] pa_out_reg
, pb_out_reg
;
57 reg [7:0] pa_dir_reg
, pb_dir_reg
;
58 reg [1:0] ca1ctl
, cb1ctl
;
60 reg [2:0] ca2ctl
, cb2ctl
;
64 assign pa_o
= (pa_out_reg
& pa_dir_reg
) |
~pa_dir_reg
;
65 assign pb_o
= (pb_out_reg
& pb_dir_reg
) |
~pb_dir_reg
;
68 always @ (adr_i
or pa_i
or pb_i
)
71 (pa_i
& ~pa_dir_reg
) |
(pa_out_reg
& pa_dir_reg
) :
74 (pb_i
& ~pb_dir_reg
) |
(pb_out_reg
& pb_dir_reg
) :
76 2: dat_o
= {2'b00, ca2ctl
, ddir_a
, ca1ctl
};
77 3: dat_o
= {2'b00, cb2ctl
, ddir_b
, cb1ctl
};
81 always @ (posedge clk_i
)
84 else if (stb_i
&& we_i
&& adr_i
== 0 && ddir_a
)
88 always @ (posedge clk_i
)
91 else if (stb_i
&& we_i
&& adr_i
== 0 && !ddir_a
)
95 always @ (posedge clk_i
)
98 else if (stb_i
&& we_i
&& adr_i
== 1 && ddir_b
)
102 always @ (posedge clk_i
)
105 else if (stb_i
&& we_i
&& adr_i
== 1 && !ddir_b
)
109 always @ (posedge clk_i
)
114 end else if (stb_i
&& we_i
&& adr_i
== 2) begin
115 ca2ctl
<= dat_i
[5:3];
117 ca1ctl
<= dat_i
[1:0];
121 always @ (posedge clk_i
)
126 end else if (stb_i
&& we_i
&& adr_i
== 3) begin
127 cb2ctl
<= dat_i
[5:3];
129 cb1ctl
<= dat_i
[1:0];