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

Subversion Repositories apbi2c

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

Go to most recent revision | 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
                        output [31:0] WRITE_DATA_ON_TX,
101
                        output  WR_ENA,
102
                        output  RD_ENA,
103
 
104
                        //outside port 
105
                        output PREADY,
106
                        output PSLVERR,
107
 
108
                        //interruption
109
                        output INT_RX,
110
                        output INT_TX
111
 
112
 
113
          );
114
 
115
//ENABLE WRITE ON TX FIFO
116
assign WR_ENA = (PWRITE == 1'b1 & PENABLE == 1'b1 & PADDR == 32'd0)?  1'b1:1'b0;
117
 
118
//ENABLE READ ON RX FIFO
119
assign RD_ENA = (PWRITE == 1'b0 & PENABLE == 1'b1  & PADDR == 32'd4)?  1'b1:1'b0;
120
 
121
//WRITE ON I2C MODULE
122
assign PREADY = ((WR_ENA == 1'b1 | RD_ENA == 1'b1 | PADDR == 32'd8) &  (PENABLE == 1'b1 & PSELx == 1'b1))? 1'b1:1'b0;
123
 
124
//INPUT TO WRITE ON TX FIFO
125
assign WRITE_DATA_ON_TX = (PADDR == 32'd0)? PWDATA:PWDATA;
126
 
127
//OUTPUT DATA FROM RX TO PRDATA
128
assign PRDATA = (PADDR == 32'd4)? READ_DATA_ON_RX:READ_DATA_ON_RX;
129
 
130
//ERROR FROM I2C CORE
131
assign PSLVERR = ERROR;
132
 
133
//INTERRUPTION FROM I2C
134
assign INT_TX = TX_EMPTY;
135
 
136
//INTERRUPTION FROM I2C
137
assign INT_RX = RX_EMPTY;
138
 
139
//This is sequential logic used only to register configuration
140
always@(posedge PCLK)
141
begin
142
 
143
        if(!PRESETn)
144
        begin
145
                INTERNAL_I2C_REGISTER_CONFIG <= 14'd0;
146
        end
147
        else
148
        begin
149
 
150
                // Set configuration to i2c
151
                if(PADDR == 32'd8 && PSELx == 1'b1 && PWRITE == 1'b1 && PREADY == 1'b1)
152
                begin
153
                        INTERNAL_I2C_REGISTER_CONFIG <= PWDATA[13:0];
154
                end
155
                else
156
                begin
157
                        INTERNAL_I2C_REGISTER_CONFIG <= INTERNAL_I2C_REGISTER_CONFIG;
158
                end
159
 
160
        end
161
 
162
end
163
 
164
 
165
endmodule

powered by: WebSVN 2.1.0

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