OpenCores
URL https://opencores.org/ocsvn/apbi2c/apbi2c/trunk

Subversion Repositories apbi2c

[/] [apbi2c/] [trunk/] [rtl/] [apb.v] - Blame information for rev 24

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 redbear
//////////////////////////////////////////////////////////////////
2
////
3
////
4
////    APB module to I2C Core
5
////
6
////
7
////
8
//// This file is part of the APB to I2C project
9
////
10
//// http://www.opencores.org/cores/apbi2c/
11
////
12
////
13
////
14
//// Description
15
////
16
//// Implementation of APB IP core according to
17
////
18
//// apbi2c_spec IP core specification document.
19
////
20
////
21
////
22
//// To Do: Things are right here but always all block can suffer changes
23
////
24
////
25
////
26
////
27
////
28
//// Author(s): - Felipe Fernandes Da Costa, fefe2560@gmail.com
29
////              Ronal Dario Celaya
30
////
31
///////////////////////////////////////////////////////////////// 
32
////
33
////
34
//// Copyright (C) 2009 Authors and OPENCORES.ORG
35
////
36
////
37
////
38
//// This source file may be used and distributed without
39
////
40
//// restriction provided that this copyright statement is not
41
////
42
//// removed from the file and that any derivative work contains
43
//// the original copyright notice and the associated disclaimer.
44
////
45
////
46
//// This source file is free software; you can redistribute it
47
////
48
//// and/or modify it under the terms of the GNU Lesser General
49
////
50
//// Public License as published by the Free Software Foundation;
51
//// either version 2.1 of the License, or (at your option) any
52
////
53
//// later version.
54
////
55
////
56
////
57
//// This source is distributed in the hope that it will be
58
////
59
//// useful, but WITHOUT ANY WARRANTY; without even the implied
60
////
61
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
62
////
63
//// PURPOSE. See the GNU Lesser General Public License for more
64
//// details.
65
////
66
////
67
////
68
//// You should have received a copy of the GNU Lesser General
69
////
70
//// Public License along with this source; if not, download it
71
////
72
//// from http://www.opencores.org/lgpl.shtml
73
////
74
////
75
///////////////////////////////////////////////////////////////////
76
 
77
`timescale 1ns/1ps //timescale 
78
 
79
module apb(
80
                        //standard ARM
81
                        input PCLK,
82
                        input PRESETn,
83
                        input PSELx,
84
                        input PWRITE,
85
                        input PENABLE,
86
                        input [31:0] PADDR,
87
                        input [31:0] PWDATA,
88
 
89
                        //internal pin
90
                        input [31:0] READ_DATA_ON_RX,
91
                        input ERROR,
92
                        input TX_EMPTY,
93
                        input RX_EMPTY,
94
 
95
                        //external pin
96
                        output [31:0] PRDATA,
97
 
98
                        //internal pin 
99
                        output reg [13:0] INTERNAL_I2C_REGISTER_CONFIG,
100 24 redbear
                        output reg [13:0] INTERNAL_I2C_REGISTER_TIMEOUT,
101 2 redbear
                        output [31:0] WRITE_DATA_ON_TX,
102
                        output  WR_ENA,
103
                        output  RD_ENA,
104
 
105
                        //outside port 
106
                        output PREADY,
107
                        output PSLVERR,
108
 
109
                        //interruption
110
                        output INT_RX,
111
                        output INT_TX
112
 
113
 
114
          );
115
 
116
//ENABLE WRITE ON TX FIFO
117 12 redbear
assign WR_ENA = (PWRITE == 1'b1 & PENABLE == 1'b1 & PADDR == 32'd0 & PSELx == 1'b1)?  1'b1:1'b0;
118 2 redbear
 
119
//ENABLE READ ON RX FIFO
120 12 redbear
assign RD_ENA = (PWRITE == 1'b0 & PENABLE == 1'b1  & PADDR == 32'd4 & PSELx == 1'b1)?  1'b1:1'b0;
121 2 redbear
 
122
//WRITE ON I2C MODULE
123 24 redbear
assign PREADY = ((WR_ENA == 1'b1 | RD_ENA == 1'b1 | PADDR == 32'd8 | PADDR == 32'd12) &  (PENABLE == 1'b1 & PSELx == 1'b1))? 1'b1:1'b0;
124 2 redbear
 
125
//INPUT TO WRITE ON TX FIFO
126
assign WRITE_DATA_ON_TX = (PADDR == 32'd0)? PWDATA:PWDATA;
127
 
128
//OUTPUT DATA FROM RX TO PRDATA
129
assign PRDATA = (PADDR == 32'd4)? READ_DATA_ON_RX:READ_DATA_ON_RX;
130
 
131
//ERROR FROM I2C CORE
132
assign PSLVERR = ERROR;
133
 
134
//INTERRUPTION FROM I2C
135
assign INT_TX = TX_EMPTY;
136
 
137
//INTERRUPTION FROM I2C
138
assign INT_RX = RX_EMPTY;
139
 
140
//This is sequential logic used only to register configuration
141
always@(posedge PCLK)
142
begin
143
 
144
        if(!PRESETn)
145
        begin
146
                INTERNAL_I2C_REGISTER_CONFIG <= 14'd0;
147 24 redbear
                INTERNAL_I2C_REGISTER_TIMEOUT <= 14'd0;
148 2 redbear
        end
149
        else
150
        begin
151
 
152
                // Set configuration to i2c
153
                if(PADDR == 32'd8 && PSELx == 1'b1 && PWRITE == 1'b1 && PREADY == 1'b1)
154
                begin
155
                        INTERNAL_I2C_REGISTER_CONFIG <= PWDATA[13:0];
156
                end
157 24 redbear
                else if(PADDR == 32'd12 && PSELx == 1'b1 && PWRITE == 1'b1 && PREADY == 1'b1)
158
                begin
159
                        INTERNAL_I2C_REGISTER_TIMEOUT <= PWDATA[13:0];
160
                end
161 2 redbear
                else
162
                begin
163
                        INTERNAL_I2C_REGISTER_CONFIG <= INTERNAL_I2C_REGISTER_CONFIG;
164
                end
165
 
166
        end
167
 
168
end
169
 
170
 
171
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.