mirror of
https://github.com/marqs85/ossc
synced 2026-11-27 08:23:39 +03:00
Initial public release (FW 0.64)
This commit is contained in:
commit
388c464f63
264 files changed
+66416
No files matched your search
@@ -0,0 +1,99 @@
|
||||
/* these test were created to show how to use the opencores I2C along with a driver found in
|
||||
* the I2C_opencores component to talk to various components.
|
||||
* This test example uses a littel daughter board from microtronix
|
||||
* it has a I2c to parallel chip (PCA9554A) a EEPORM and real time clock.
|
||||
* I chose not to impliment the real time clock.
|
||||
* But you can see how the calls work
|
||||
* There are only 4 functions associalted with the I2C driver
|
||||
* I2C start - send start bit and address of the chip
|
||||
* I2C_read - read data
|
||||
* I2C_write. - write data
|
||||
* how and when each of these get used is based on the device you
|
||||
* are talking to.
|
||||
* See the driver code for details of each function.
|
||||
* */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "system.h"
|
||||
#include "i2c_opencores.h"
|
||||
int main()
|
||||
{
|
||||
int data;
|
||||
int i;
|
||||
// testing the PCA9554A paralle interface
|
||||
// this writes a 5 to the leds and read the position of the dip switches.
|
||||
printf(" tesing the PCA9554A interface the\n the LEDS should be at a 5 \n");
|
||||
// address 0x38
|
||||
// set the fequesncy that you want to run at
|
||||
// most devices work at 100Khz some faster
|
||||
I2C_init(I2CA_BASE,ALT_CPU_FREQ,100000);
|
||||
I2C_init(I2CA_BASE,ALT_CPU_FREQ,100000);
|
||||
// for the parallel io only the first 4 are output s
|
||||
|
||||
// the PCA9554A uses a command word right after the chip address word ( the start work)
|
||||
I2C_start(I2CA_BASE,0x38,0);// chip address in write mode
|
||||
I2C_write(I2CA_BASE,3,0); // write to register 3 command
|
||||
I2C_write(I2CA_BASE,0xf0,1); // set the bottom 4 bits to outputs for the LEDs set the stop
|
||||
|
||||
// now right to the leds
|
||||
I2C_start(I2CA_BASE,0x38,0); // address the chip in write mode
|
||||
I2C_write(I2CA_BASE,1,0); // set command to the pca9554 to be output register
|
||||
I2C_write(I2CA_BASE,5,1); // write the data to the output register and set the stop
|
||||
|
||||
//now read the dip switches
|
||||
// first set the command to 0
|
||||
I2C_start(I2CA_BASE,0x38,0); //address the chip in write mode
|
||||
data = I2C_write(I2CA_BASE,0,0); // set command to read input register.
|
||||
I2C_start(I2CA_BASE,0x38,1); //send start again but this time in read mode
|
||||
data = I2C_read(I2CA_BASE,1); // read the input register and send stop
|
||||
data = 0xff & (data >>4);
|
||||
printf("dip switch 0x%x\n",data);
|
||||
|
||||
printf("\nNow writing and reading from the EEPROM\n");
|
||||
//address 0x50-57
|
||||
I2C_start(I2CA_BASE,0x50,0); // chip address in write mode
|
||||
I2C_write(I2CA_BASE,0,0); // write to starting address of 0
|
||||
// now write the data
|
||||
for (i=0;i<7;i++) // can only write 8 bites at a time
|
||||
{
|
||||
I2C_write(I2CA_BASE,i,0); // writ the data
|
||||
}
|
||||
I2C_write(I2CA_BASE,i,1); // write last one with last flag
|
||||
|
||||
while ( I2C_start(I2CA_BASE,0x50,0)); // make sure the write is done be fore continuing.
|
||||
// can ony burst 8 at a time.
|
||||
|
||||
I2C_write(I2CA_BASE,8,0); // write to starting address of 8
|
||||
// now write the data
|
||||
for (i=0;i<7;i++) // write the next 8 bytes
|
||||
{
|
||||
I2C_write(I2CA_BASE,i+8,0); //
|
||||
}
|
||||
I2C_write(I2CA_BASE,i+8,1); // write last one with last flag
|
||||
|
||||
while ( I2C_start(I2CA_BASE,0x50,0)); // make sure the write is done be fore continuing.
|
||||
|
||||
//now read the values
|
||||
// first set the command to 0
|
||||
I2C_start(I2CA_BASE,0x50,0); //set chip address and set to write/
|
||||
I2C_write(I2CA_BASE,0,0); // set address to 0.
|
||||
I2C_start(I2CA_BASE,0x50,1); //set chip address in read mode
|
||||
for (i=0;i<15;i++)
|
||||
{
|
||||
data = I2C_read(I2CA_BASE,0); // memory array
|
||||
printf("\tdata = 0x%x\n",data);
|
||||
}
|
||||
|
||||
data = I2C_read(I2CA_BASE,1); // last memory read
|
||||
printf("\tdata = 0x%x\n",data);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
printf("Hello from Nios II!\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,33 @@
|
||||
#ifndef __I2C_OPENCORES_H__
|
||||
#define __I2C_OPENCORES_H__
|
||||
|
||||
|
||||
#include "alt_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
|
||||
|
||||
void I2C_init(alt_u32 base,alt_u32 clk,alt_u32 speed);
|
||||
int I2C_start(alt_u32 base, alt_u32 add, alt_u32 read);
|
||||
alt_u32 I2C_read(alt_u32 base,alt_u32 last);
|
||||
alt_u32 I2C_write(alt_u32 base,alt_u8 data, alt_u32 last);
|
||||
alt_u32 SPI_read(alt_u32 base);
|
||||
void SPI_write(alt_u32 base,alt_u8 data);
|
||||
#define I2C_OK (0)
|
||||
#define I2C_ACK (0)
|
||||
#define I2C_NOACK (1)
|
||||
#define I2C_ABITRATION_LOST (2)
|
||||
|
||||
#define I2C_OPENCORES_INSTANCE(name, dev) extern int alt_no_storage
|
||||
#define I2C_OPENCORES_INIT(name, dev) while (0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __I2C_OPENCORES_H__ */
|
||||
@@ -0,0 +1,38 @@
|
||||
# *******************************************************************************
|
||||
# * *
|
||||
# * License Agreement *
|
||||
# * *
|
||||
# * Copyright (c) 2003 Altera Corporation, San Jose, California, USA. *
|
||||
# * All rights reserved. *
|
||||
# * *
|
||||
# * Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
# * copy of this software and associated documentation files (the "Software"), *
|
||||
# * to deal in the Software without restriction, including without limitation *
|
||||
# * the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
||||
# * and/or sell copies of the Software, and to permit persons to whom the *
|
||||
# * Software is furnished to do so, subject to the following conditions: *
|
||||
# * *
|
||||
# * The above copyright notice and this permission notice shall be included in *
|
||||
# * all copies or substantial portions of the Software. *
|
||||
# * *
|
||||
# * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
||||
# * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
||||
# * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
||||
# * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
||||
# * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
||||
# * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
||||
# * DEALINGS IN THE SOFTWARE. *
|
||||
# * *
|
||||
# * This agreement shall be governed in all respects by the laws of the State *
|
||||
# * of California and by the laws of the United States of America. *
|
||||
# * *
|
||||
# * Altera does not recommend, suggest or require that this reference design *
|
||||
# * file be used in conjunction or combination with any other product. *
|
||||
# *******************************************************************************
|
||||
|
||||
# List all source files supplied by this component.
|
||||
|
||||
C_LIB_SRCS += i2c_opencores.c
|
||||
|
||||
ASM_LIB_SRCS +=
|
||||
|
||||
@@ -0,0 +1,206 @@
|
||||
|
||||
#include "alt_types.h"
|
||||
#include "i2c_opencores_regs.h"
|
||||
#include "i2c_opencores.h"
|
||||
|
||||
// #define I2C_DEBUG
|
||||
//int I2C_init(alt_u32 base,alt_u32 clk, alt_u32 speed)
|
||||
//int I2C_start(alt_u32 base, alt_u32 add, alt_u32 write);
|
||||
//alt_u32 I2C_read(alt_u32 base);
|
||||
//int I2C_write(alt_u32 base, alt_u8 data);
|
||||
//int I2C_stop(alt_u32 base);
|
||||
|
||||
/* these functions are polled only. */
|
||||
/* all functions wait until the I2C is done before exiting */
|
||||
|
||||
|
||||
/****************************************************************
|
||||
int I2C_init
|
||||
This function inititlizes the prescalor for the scl
|
||||
and then enables the core. This must be run before
|
||||
any other i2c code is executed
|
||||
inputs
|
||||
base = the base address of the component
|
||||
clk = freuqency of the clock driving this component ( in Hz)
|
||||
speed = SCL speed ie 100K, 400K ... (in Hz)
|
||||
15-OCT-07 initial release
|
||||
*****************************************************************/
|
||||
void I2C_init(alt_u32 base,alt_u32 clk,alt_u32 speed)
|
||||
{
|
||||
alt_u32 prescale = (clk/( 5 * speed))-1;
|
||||
#ifdef I2C_DEBUG
|
||||
printf(" Initializing I2C at 0x%x, \n\twith clock speed 0x%x \n\tand SCL speed 0x%x \n\tand prescale 0x%x\n",base,clk,speed,prescale);
|
||||
#endif
|
||||
IOWR_I2C_OPENCORES_CTR(base, 0x00); /* turn off the core*/
|
||||
|
||||
IOWR_I2C_OPENCORES_CR(base, I2C_OPENCORES_CR_IACK_MSK); /* clearn any pening IRQ*/
|
||||
|
||||
IOWR_I2C_OPENCORES_PRERLO(base, (0xff & prescale)); /* load low presacle bit*/
|
||||
|
||||
IOWR_I2C_OPENCORES_PRERHI(base, (0xff & (prescale>>8))); /* load upper prescale bit */
|
||||
|
||||
IOWR_I2C_OPENCORES_CTR(base, I2C_OPENCORES_CTR_EN_MSK); /* turn on the core*/
|
||||
|
||||
}
|
||||
|
||||
/****************************************************************
|
||||
int I2C_start
|
||||
Sets the start bit and then sends the first byte which
|
||||
is the address of the device + the write bit.
|
||||
inputs
|
||||
base = the base address of the component
|
||||
add = address of I2C device
|
||||
read = 1== read 0== write
|
||||
return value
|
||||
0 if address is acknowledged
|
||||
1 if address was not acknowledged
|
||||
15-OCT-07 initial release
|
||||
*****************************************************************/
|
||||
int I2C_start(alt_u32 base, alt_u32 add, alt_u32 read)
|
||||
{
|
||||
#ifdef I2C_DEBUG
|
||||
printf(" Start I2C at 0x%x, \n\twith address 0x%x \n\tand read 0x%x \n\tand prescale 0x%x\n",base,add,read);
|
||||
#endif
|
||||
|
||||
/* transmit the address shifted by one and the read/write bit*/
|
||||
IOWR_I2C_OPENCORES_TXR(base, ((add<<1) + (0x1 & read)));
|
||||
|
||||
/* set start and write bits which will start the transaction*/
|
||||
IOWR_I2C_OPENCORES_CR(base, I2C_OPENCORES_CR_STA_MSK | I2C_OPENCORES_CR_WR_MSK );
|
||||
|
||||
/* wait for the trnasaction to be over.*/
|
||||
while( IORD_I2C_OPENCORES_SR(base) & I2C_OPENCORES_SR_TIP_MSK);
|
||||
|
||||
/* now check to see if the address was acknowledged */
|
||||
if(IORD_I2C_OPENCORES_SR(base) & I2C_OPENCORES_SR_RXNACK_MSK)
|
||||
{
|
||||
#ifdef I2C_DEBUG
|
||||
printf("\tNOACK\n");
|
||||
#endif
|
||||
return (I2C_NOACK);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef I2C_DEBUG
|
||||
printf("\tACK\n");
|
||||
#endif
|
||||
return (I2C_ACK);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************
|
||||
int I2C_read
|
||||
assumes that any addressing and start
|
||||
has already been done.
|
||||
reads one byte of data from the slave. on the last read
|
||||
we don't acknowldge and set the stop bit.
|
||||
inputs
|
||||
base = the base address of the component
|
||||
last = on the last read there must not be a ack
|
||||
|
||||
return value
|
||||
byte read back.
|
||||
15-OCT-07 initial release
|
||||
*****************************************************************/
|
||||
alt_u32 I2C_read(alt_u32 base,alt_u32 last)
|
||||
{
|
||||
#ifdef I2C_DEBUG
|
||||
printf(" Read I2C at 0x%x, \n\twith last0x%x\n",base,last);
|
||||
#endif
|
||||
if( last)
|
||||
{
|
||||
/* start a read and no ack and stop bit*/
|
||||
IOWR_I2C_OPENCORES_CR(base, I2C_OPENCORES_CR_RD_MSK |
|
||||
I2C_OPENCORES_CR_NACK_MSK | I2C_OPENCORES_CR_STO_MSK);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* start read*/
|
||||
IOWR_I2C_OPENCORES_CR(base, I2C_OPENCORES_CR_RD_MSK );
|
||||
}
|
||||
/* wait for the trnasaction to be over.*/
|
||||
while( IORD_I2C_OPENCORES_SR(base) & I2C_OPENCORES_SR_TIP_MSK);
|
||||
|
||||
/* now read the data */
|
||||
return (IORD_I2C_OPENCORES_RXR(base));
|
||||
|
||||
}
|
||||
|
||||
/****************************************************************
|
||||
int I2C_write
|
||||
assumes that any addressing and start
|
||||
has already been done.
|
||||
writes one byte of data from the slave.
|
||||
If last is set the stop bit set.
|
||||
inputs
|
||||
base = the base address of the component
|
||||
data = byte to write
|
||||
last = on the last read there must not be a ack
|
||||
|
||||
return value
|
||||
0 if address is acknowledged
|
||||
1 if address was not acknowledged
|
||||
15-OCT-07 initial release
|
||||
*****************************************************************/
|
||||
alt_u32 I2C_write(alt_u32 base,alt_u8 data, alt_u32 last)
|
||||
{
|
||||
#ifdef I2C_DEBUG
|
||||
printf(" Read I2C at 0x%x, \n\twith data 0x%x,\n\twith last0x%x\n",base,data,last);
|
||||
#endif
|
||||
/* transmit the data*/
|
||||
IOWR_I2C_OPENCORES_TXR(base, data);
|
||||
|
||||
if( last)
|
||||
{
|
||||
/* start a write with ack and stop bit*/
|
||||
IOWR_I2C_OPENCORES_CR(base, I2C_OPENCORES_CR_WR_MSK |
|
||||
I2C_OPENCORES_CR_STO_MSK);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* start write with ack */
|
||||
IOWR_I2C_OPENCORES_CR(base, I2C_OPENCORES_CR_WR_MSK );
|
||||
}
|
||||
/* wait for the trnasaction to be over.*/
|
||||
while( IORD_I2C_OPENCORES_SR(base) & I2C_OPENCORES_SR_TIP_MSK);
|
||||
|
||||
/* now check to see if the address was acknowledged */
|
||||
if(IORD_I2C_OPENCORES_SR(base) & I2C_OPENCORES_SR_RXNACK_MSK)
|
||||
{
|
||||
#ifdef I2C_DEBUG
|
||||
printf("\tNOACK\n");
|
||||
#endif
|
||||
return (I2C_NOACK);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef I2C_DEBUG
|
||||
printf("\tACK\n");
|
||||
#endif
|
||||
return (I2C_ACK);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
alt_u32 SPI_read(alt_u32 base)
|
||||
{
|
||||
/* start read*/
|
||||
IOWR_I2C_OPENCORES_CR(base, I2C_OPENCORES_CR_RD_MSK|I2C_OPENCORES_CR_NACK_MSK|I2C_OPENCORES_CR_SPIM_MSK );
|
||||
|
||||
/* wait for the trnasaction to be over.*/
|
||||
while( IORD_I2C_OPENCORES_SR(base) & I2C_OPENCORES_SR_TIP_MSK);
|
||||
|
||||
/* now read the data */
|
||||
return (IORD_I2C_OPENCORES_RXR(base));
|
||||
}
|
||||
|
||||
void SPI_write(alt_u32 base,alt_u8 data) {
|
||||
/* transmit the data*/
|
||||
IOWR_I2C_OPENCORES_TXR(base, data);
|
||||
|
||||
/* start write */
|
||||
IOWR_I2C_OPENCORES_CR(base, I2C_OPENCORES_CR_WR_MSK|I2C_OPENCORES_CR_NACK_MSK|I2C_OPENCORES_CR_SPIM_MSK );
|
||||
|
||||
/* wait for the trnasaction to be over.*/
|
||||
while( IORD_I2C_OPENCORES_SR(base) & I2C_OPENCORES_SR_TIP_MSK);
|
||||
}
|
||||
@@ -0,0 +1,621 @@
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
//// ////
|
||||
//// WISHBONE rev.B2 compliant I2C Master bit-controller ////
|
||||
//// ////
|
||||
//// ////
|
||||
//// Author: Richard Herveille ////
|
||||
//// richard@asics.ws ////
|
||||
//// www.asics.ws ////
|
||||
//// ////
|
||||
//// Downloaded from: http://www.opencores.org/projects/i2c/ ////
|
||||
//// ////
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
//// ////
|
||||
//// Copyright (C) 2001 Richard Herveille ////
|
||||
//// richard@asics.ws ////
|
||||
//// ////
|
||||
//// This source file may be used and distributed without ////
|
||||
//// restriction provided that this copyright statement is not ////
|
||||
//// removed from the file and that any derivative work contains ////
|
||||
//// the original copyright notice and the associated disclaimer.////
|
||||
//// ////
|
||||
//// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY ////
|
||||
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED ////
|
||||
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ////
|
||||
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR ////
|
||||
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, ////
|
||||
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ////
|
||||
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ////
|
||||
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR ////
|
||||
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF ////
|
||||
//// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ////
|
||||
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ////
|
||||
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ////
|
||||
//// POSSIBILITY OF SUCH DAMAGE. ////
|
||||
//// ////
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
// CVS Log
|
||||
//
|
||||
// $Id: i2c_master_bit_ctrl.v,v 1.11 2004/05/07 11:02:26 rherveille Exp $
|
||||
//
|
||||
// $Date: 2004/05/07 11:02:26 $
|
||||
// $Revision: 1.11 $
|
||||
// $Author: rherveille $
|
||||
// $Locker: $
|
||||
// $State: Exp $
|
||||
//
|
||||
// Change History:
|
||||
// $Log: i2c_master_bit_ctrl.v,v $
|
||||
// Revision 1.11 2004/05/07 11:02:26 rherveille
|
||||
// Fixed a bug where the core would signal an arbitration lost (AL bit set), when another master controls the bus and the other master generates a STOP bit.
|
||||
//
|
||||
// Revision 1.10 2003/08/09 07:01:33 rherveille
|
||||
// Fixed a bug in the Arbitration Lost generation caused by delay on the (external) sda line.
|
||||
// Fixed a potential bug in the byte controller's host-acknowledge generation.
|
||||
//
|
||||
// Revision 1.9 2003/03/10 14:26:37 rherveille
|
||||
// Fixed cmd_ack generation item (no bug).
|
||||
//
|
||||
// Revision 1.8 2003/02/05 00:06:10 rherveille
|
||||
// Fixed a bug where the core would trigger an erroneous 'arbitration lost' interrupt after being reset, when the reset pulse width < 3 clk cycles.
|
||||
//
|
||||
// Revision 1.7 2002/12/26 16:05:12 rherveille
|
||||
// Small code simplifications
|
||||
//
|
||||
// Revision 1.6 2002/12/26 15:02:32 rherveille
|
||||
// Core is now a Multimaster I2C controller
|
||||
//
|
||||
// Revision 1.5 2002/11/30 22:24:40 rherveille
|
||||
// Cleaned up code
|
||||
//
|
||||
// Revision 1.4 2002/10/30 18:10:07 rherveille
|
||||
// Fixed some reported minor start/stop generation timing issuess.
|
||||
//
|
||||
// Revision 1.3 2002/06/15 07:37:03 rherveille
|
||||
// Fixed a small timing bug in the bit controller.\nAdded verilog simulation environment.
|
||||
//
|
||||
// Revision 1.2 2001/11/05 11:59:25 rherveille
|
||||
// Fixed wb_ack_o generation bug.
|
||||
// Fixed bug in the byte_controller statemachine.
|
||||
// Added headers.
|
||||
//
|
||||
|
||||
//
|
||||
/////////////////////////////////////
|
||||
// Bit controller section
|
||||
/////////////////////////////////////
|
||||
//
|
||||
// Translate simple commands into SCL/SDA transitions
|
||||
// Each command has 5 states, A/B/C/D/idle
|
||||
//
|
||||
// start: SCL ~~~~~~~~~~\____
|
||||
// SDA ~~~~~~~~\______
|
||||
// x | A | B | C | D | i
|
||||
//
|
||||
// repstart SCL ____/~~~~\___
|
||||
// SDA __/~~~\______
|
||||
// x | A | B | C | D | i
|
||||
//
|
||||
// stop SCL ____/~~~~~~~~
|
||||
// SDA ==\____/~~~~~
|
||||
// x | A | B | C | D | i
|
||||
//
|
||||
//- write SCL ____/~~~~\____
|
||||
// SDA ==X=========X=
|
||||
// x | A | B | C | D | i
|
||||
//
|
||||
//- read SCL ____/~~~~\____
|
||||
// SDA XXXX=====XXXX
|
||||
// x | A | B | C | D | i
|
||||
//
|
||||
|
||||
// Timing: Normal mode Fast mode
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Fscl 100KHz 400KHz
|
||||
// Th_scl 4.0us 0.6us High period of SCL
|
||||
// Tl_scl 4.7us 1.3us Low period of SCL
|
||||
// Tsu:sta 4.7us 0.6us setup time for a repeated start condition
|
||||
// Tsu:sto 4.0us 0.6us setup time for a stop conditon
|
||||
// Tbuf 4.7us 1.3us Bus free time between a stop and start condition
|
||||
//
|
||||
|
||||
// synopsys translate_off
|
||||
`include "timescale.v"
|
||||
// synopsys translate_on
|
||||
|
||||
`include "i2c_master_defines.v"
|
||||
|
||||
module i2c_master_bit_ctrl(
|
||||
clk, rst, nReset,
|
||||
clk_cnt, ena, cmd, cmd_ack, busy, al, din, dout,
|
||||
scl_i, scl_o, scl_oen, sda_i, sda_o, sda_oen
|
||||
);
|
||||
|
||||
//
|
||||
// inputs & outputs
|
||||
//
|
||||
input clk;
|
||||
input rst;
|
||||
input nReset;
|
||||
input ena; // core enable signal
|
||||
|
||||
input [15:0] clk_cnt; // clock prescale value
|
||||
|
||||
input [5:0] cmd;
|
||||
output cmd_ack; // command complete acknowledge
|
||||
reg cmd_ack;
|
||||
output busy; // i2c bus busy
|
||||
reg busy;
|
||||
output al; // i2c bus arbitration lost
|
||||
reg al;
|
||||
|
||||
input din;
|
||||
output dout;
|
||||
reg dout;
|
||||
|
||||
// I2C lines
|
||||
input scl_i; // i2c clock line input
|
||||
output scl_o; // i2c clock line output
|
||||
output scl_oen; // i2c clock line output enable (active low)
|
||||
reg scl_oen;
|
||||
input sda_i; // i2c data line input
|
||||
output sda_o; // i2c data line output
|
||||
output sda_oen; // i2c data line output enable (active low)
|
||||
reg sda_oen;
|
||||
|
||||
|
||||
//
|
||||
// variable declarations
|
||||
//
|
||||
|
||||
reg sSCL, sSDA; // synchronized SCL and SDA inputs
|
||||
reg dscl_oen; // delayed scl_oen
|
||||
reg sda_chk; // check SDA output (Multi-master arbitration)
|
||||
reg clk_en; // clock generation signals
|
||||
wire slave_wait;
|
||||
// reg [15:0] cnt = clk_cnt; // clock divider counter (simulation)
|
||||
reg [15:0] cnt; // clock divider counter (synthesis)
|
||||
|
||||
// state machine variable
|
||||
reg [24:0] c_state;
|
||||
|
||||
//
|
||||
// module body
|
||||
//
|
||||
|
||||
// whenever the slave is not ready it can delay the cycle by pulling SCL low
|
||||
// delay scl_oen
|
||||
always @(posedge clk)
|
||||
dscl_oen <= #1 scl_oen;
|
||||
|
||||
assign slave_wait = dscl_oen && !sSCL;
|
||||
|
||||
|
||||
// generate clk enable signal
|
||||
always @(posedge clk or negedge nReset)
|
||||
if(~nReset)
|
||||
begin
|
||||
cnt <= #1 16'h0;
|
||||
clk_en <= #1 1'b1;
|
||||
end
|
||||
else if (rst)
|
||||
begin
|
||||
cnt <= #1 16'h0;
|
||||
clk_en <= #1 1'b1;
|
||||
end
|
||||
else if ( ~|cnt || ~ena)
|
||||
if (~slave_wait)
|
||||
begin
|
||||
cnt <= #1 clk_cnt;
|
||||
clk_en <= #1 1'b1;
|
||||
end
|
||||
else
|
||||
begin
|
||||
cnt <= #1 cnt;
|
||||
clk_en <= #1 1'b0;
|
||||
end
|
||||
else
|
||||
begin
|
||||
cnt <= #1 cnt - 16'h1;
|
||||
clk_en <= #1 1'b0;
|
||||
end
|
||||
|
||||
|
||||
// generate bus status controller
|
||||
reg dSCL, dSDA;
|
||||
reg sta_condition;
|
||||
reg sto_condition;
|
||||
|
||||
// synchronize SCL and SDA inputs
|
||||
// reduce metastability risc
|
||||
always @(posedge clk or negedge nReset)
|
||||
if (~nReset)
|
||||
begin
|
||||
sSCL <= #1 1'b1;
|
||||
sSDA <= #1 1'b1;
|
||||
|
||||
dSCL <= #1 1'b1;
|
||||
dSDA <= #1 1'b1;
|
||||
end
|
||||
else if (rst)
|
||||
begin
|
||||
sSCL <= #1 1'b1;
|
||||
sSDA <= #1 1'b1;
|
||||
|
||||
dSCL <= #1 1'b1;
|
||||
dSDA <= #1 1'b1;
|
||||
end
|
||||
else
|
||||
begin
|
||||
sSCL <= #1 scl_i;
|
||||
sSDA <= #1 sda_i;
|
||||
|
||||
dSCL <= #1 sSCL;
|
||||
dSDA <= #1 sSDA;
|
||||
end
|
||||
|
||||
// detect start condition => detect falling edge on SDA while SCL is high
|
||||
// detect stop condition => detect rising edge on SDA while SCL is high
|
||||
always @(posedge clk or negedge nReset)
|
||||
if (~nReset)
|
||||
begin
|
||||
sta_condition <= #1 1'b0;
|
||||
sto_condition <= #1 1'b0;
|
||||
end
|
||||
else if (rst)
|
||||
begin
|
||||
sta_condition <= #1 1'b0;
|
||||
sto_condition <= #1 1'b0;
|
||||
end
|
||||
else
|
||||
begin
|
||||
sta_condition <= #1 ~sSDA & dSDA & sSCL;
|
||||
sto_condition <= #1 sSDA & ~dSDA & sSCL;
|
||||
end
|
||||
|
||||
// generate i2c bus busy signal
|
||||
always @(posedge clk or negedge nReset)
|
||||
if(!nReset)
|
||||
busy <= #1 1'b0;
|
||||
else if (rst)
|
||||
busy <= #1 1'b0;
|
||||
else
|
||||
busy <= #1 (sta_condition | busy) & ~sto_condition;
|
||||
|
||||
// generate arbitration lost signal
|
||||
// aribitration lost when:
|
||||
// 1) master drives SDA high, but the i2c bus is low
|
||||
// 2) stop detected while not requested
|
||||
reg cmd_stop;
|
||||
always @(posedge clk or negedge nReset)
|
||||
if (~nReset)
|
||||
cmd_stop <= #1 1'b0;
|
||||
else if (rst)
|
||||
cmd_stop <= #1 1'b0;
|
||||
else if (clk_en)
|
||||
cmd_stop <= #1 (cmd & (`I2C_CMD_STOP|`SPI_CMD_WRITE|`SPI_CMD_READ)) != 6'b000000;
|
||||
|
||||
always @(posedge clk or negedge nReset)
|
||||
if (~nReset)
|
||||
al <= #1 1'b0;
|
||||
else if (rst)
|
||||
al <= #1 1'b0;
|
||||
else
|
||||
al <= #1 (sda_chk & ~sSDA & sda_oen) | (|c_state & sto_condition & ~cmd_stop);
|
||||
|
||||
|
||||
// generate dout signal (store SDA on rising edge of SCL)
|
||||
always @(posedge clk)
|
||||
if(sSCL & ~dSCL)
|
||||
dout <= #1 sSDA;
|
||||
|
||||
// generate statemachine
|
||||
|
||||
// nxt_state decoder
|
||||
parameter [24:0] idle = 25'b0_0000_0000_0000_0000_0000_0000;
|
||||
parameter [24:0] start_a = 25'b0_0000_0000_0000_0000_0000_0001;
|
||||
parameter [24:0] start_b = 25'b0_0000_0000_0000_0000_0000_0010;
|
||||
parameter [24:0] start_c = 25'b0_0000_0000_0000_0000_0000_0100;
|
||||
parameter [24:0] start_d = 25'b0_0000_0000_0000_0000_0000_1000;
|
||||
parameter [24:0] start_e = 25'b0_0000_0000_0000_0000_0001_0000;
|
||||
parameter [24:0] stop_a = 25'b0_0000_0000_0000_0000_0010_0000;
|
||||
parameter [24:0] stop_b = 25'b0_0000_0000_0000_0000_0100_0000;
|
||||
parameter [24:0] stop_c = 25'b0_0000_0000_0000_0000_1000_0000;
|
||||
parameter [24:0] stop_d = 25'b0_0000_0000_0000_0001_0000_0000;
|
||||
parameter [24:0] rd_a = 25'b0_0000_0000_0000_0010_0000_0000;
|
||||
parameter [24:0] rd_b = 25'b0_0000_0000_0000_0100_0000_0000;
|
||||
parameter [24:0] rd_c = 25'b0_0000_0000_0000_1000_0000_0000;
|
||||
parameter [24:0] rd_d = 25'b0_0000_0000_0001_0000_0000_0000;
|
||||
parameter [24:0] wr_a = 25'b0_0000_0000_0010_0000_0000_0000;
|
||||
parameter [24:0] wr_b = 25'b0_0000_0000_0100_0000_0000_0000;
|
||||
parameter [24:0] wr_c = 25'b0_0000_0000_1000_0000_0000_0000;
|
||||
parameter [24:0] wr_d = 25'b0_0000_0001_0000_0000_0000_0000;
|
||||
|
||||
parameter [24:0] spi_rd_a = 25'b0_0000_0010_0000_0000_0000_0000;
|
||||
parameter [24:0] spi_rd_b = 25'b0_0000_0100_0000_0000_0000_0000;
|
||||
parameter [24:0] spi_rd_c = 25'b0_0000_1000_0000_0000_0000_0000;
|
||||
parameter [24:0] spi_rd_d = 25'b0_0001_0000_0000_0000_0000_0000;
|
||||
parameter [24:0] spi_wr_a = 25'b0_0010_0000_0000_0000_0000_0000;
|
||||
parameter [24:0] spi_wr_b = 25'b0_0100_0000_0000_0000_0000_0000;
|
||||
parameter [24:0] spi_wr_c = 25'b0_1000_0000_0000_0000_0000_0000;
|
||||
parameter [24:0] spi_wr_d = 25'b1_0000_0000_0000_0000_0000_0000;
|
||||
|
||||
always @(posedge clk or negedge nReset)
|
||||
if (!nReset)
|
||||
begin
|
||||
c_state <= #1 idle;
|
||||
cmd_ack <= #1 1'b0;
|
||||
scl_oen <= #1 1'b1;
|
||||
sda_oen <= #1 1'b1;
|
||||
sda_chk <= #1 1'b0;
|
||||
end
|
||||
else if (rst | al)
|
||||
begin
|
||||
c_state <= #1 idle;
|
||||
cmd_ack <= #1 1'b0;
|
||||
scl_oen <= #1 1'b1;
|
||||
sda_oen <= #1 1'b1;
|
||||
sda_chk <= #1 1'b0;
|
||||
end
|
||||
else
|
||||
begin
|
||||
cmd_ack <= #1 1'b0; // default no command acknowledge + assert cmd_ack only 1clk cycle
|
||||
|
||||
if (clk_en)
|
||||
case (c_state)
|
||||
// idle state
|
||||
idle:
|
||||
begin
|
||||
case (cmd)
|
||||
`I2C_CMD_START:
|
||||
c_state <= #1 start_a;
|
||||
|
||||
`I2C_CMD_STOP:
|
||||
c_state <= #1 stop_a;
|
||||
|
||||
`I2C_CMD_WRITE:
|
||||
c_state <= #1 wr_a;
|
||||
|
||||
`I2C_CMD_READ:
|
||||
c_state <= #1 rd_a;
|
||||
|
||||
`SPI_CMD_WRITE:
|
||||
c_state <= #1 spi_wr_a;
|
||||
|
||||
`SPI_CMD_READ:
|
||||
c_state <= #1 spi_rd_a;
|
||||
|
||||
default:
|
||||
c_state <= #1 idle;
|
||||
endcase
|
||||
|
||||
scl_oen <= #1 scl_oen; // keep SCL in same state
|
||||
sda_oen <= #1 sda_oen; // keep SDA in same state
|
||||
sda_chk <= #1 1'b0; // don't check SDA output
|
||||
end
|
||||
|
||||
// start
|
||||
start_a:
|
||||
begin
|
||||
c_state <= #1 start_b;
|
||||
scl_oen <= #1 scl_oen; // keep SCL in same state
|
||||
sda_oen <= #1 1'b1; // set SDA high
|
||||
sda_chk <= #1 1'b0; // don't check SDA output
|
||||
end
|
||||
|
||||
start_b:
|
||||
begin
|
||||
c_state <= #1 start_c;
|
||||
scl_oen <= #1 1'b1; // set SCL high
|
||||
sda_oen <= #1 1'b1; // keep SDA high
|
||||
sda_chk <= #1 1'b0; // don't check SDA output
|
||||
end
|
||||
|
||||
start_c:
|
||||
begin
|
||||
c_state <= #1 start_d;
|
||||
scl_oen <= #1 1'b1; // keep SCL high
|
||||
sda_oen <= #1 1'b0; // set SDA low
|
||||
sda_chk <= #1 1'b0; // don't check SDA output
|
||||
end
|
||||
|
||||
start_d:
|
||||
begin
|
||||
c_state <= #1 start_e;
|
||||
scl_oen <= #1 1'b1; // keep SCL high
|
||||
sda_oen <= #1 1'b0; // keep SDA low
|
||||
sda_chk <= #1 1'b0; // don't check SDA output
|
||||
end
|
||||
|
||||
start_e:
|
||||
begin
|
||||
c_state <= #1 idle;
|
||||
cmd_ack <= #1 1'b1;
|
||||
scl_oen <= #1 1'b0; // set SCL low
|
||||
sda_oen <= #1 1'b0; // keep SDA low
|
||||
sda_chk <= #1 1'b0; // don't check SDA output
|
||||
end
|
||||
|
||||
// stop
|
||||
stop_a:
|
||||
begin
|
||||
c_state <= #1 stop_b;
|
||||
scl_oen <= #1 1'b0; // keep SCL low
|
||||
sda_oen <= #1 1'b0; // set SDA low
|
||||
sda_chk <= #1 1'b0; // don't check SDA output
|
||||
end
|
||||
|
||||
stop_b:
|
||||
begin
|
||||
c_state <= #1 stop_c;
|
||||
scl_oen <= #1 1'b1; // set SCL high
|
||||
sda_oen <= #1 1'b0; // keep SDA low
|
||||
sda_chk <= #1 1'b0; // don't check SDA output
|
||||
end
|
||||
|
||||
stop_c:
|
||||
begin
|
||||
c_state <= #1 stop_d;
|
||||
scl_oen <= #1 1'b1; // keep SCL high
|
||||
sda_oen <= #1 1'b0; // keep SDA low
|
||||
sda_chk <= #1 1'b0; // don't check SDA output
|
||||
end
|
||||
|
||||
stop_d:
|
||||
begin
|
||||
c_state <= #1 idle;
|
||||
cmd_ack <= #1 1'b1;
|
||||
scl_oen <= #1 1'b1; // keep SCL high
|
||||
sda_oen <= #1 1'b1; // set SDA high
|
||||
sda_chk <= #1 1'b0; // don't check SDA output
|
||||
end
|
||||
|
||||
// read
|
||||
rd_a:
|
||||
begin
|
||||
c_state <= #1 rd_b;
|
||||
scl_oen <= #1 1'b0; // keep SCL low
|
||||
sda_oen <= #1 1'b1; // tri-state SDA
|
||||
sda_chk <= #1 1'b0; // don't check SDA output
|
||||
end
|
||||
|
||||
rd_b:
|
||||
begin
|
||||
c_state <= #1 rd_c;
|
||||
scl_oen <= #1 1'b1; // set SCL high
|
||||
sda_oen <= #1 1'b1; // keep SDA tri-stated
|
||||
sda_chk <= #1 1'b0; // don't check SDA output
|
||||
end
|
||||
|
||||
rd_c:
|
||||
begin
|
||||
c_state <= #1 rd_d;
|
||||
scl_oen <= #1 1'b1; // keep SCL high
|
||||
sda_oen <= #1 1'b1; // keep SDA tri-stated
|
||||
sda_chk <= #1 1'b0; // don't check SDA output
|
||||
end
|
||||
|
||||
rd_d:
|
||||
begin
|
||||
c_state <= #1 idle;
|
||||
cmd_ack <= #1 1'b1;
|
||||
scl_oen <= #1 1'b0; // set SCL low
|
||||
sda_oen <= #1 1'b1; // keep SDA tri-stated
|
||||
sda_chk <= #1 1'b0; // don't check SDA output
|
||||
end
|
||||
|
||||
// write
|
||||
wr_a:
|
||||
begin
|
||||
c_state <= #1 wr_b;
|
||||
scl_oen <= #1 1'b0; // keep SCL low
|
||||
sda_oen <= #1 din; // set SDA
|
||||
sda_chk <= #1 1'b0; // don't check SDA output (SCL low)
|
||||
end
|
||||
|
||||
wr_b:
|
||||
begin
|
||||
c_state <= #1 wr_c;
|
||||
scl_oen <= #1 1'b1; // set SCL high
|
||||
sda_oen <= #1 din; // keep SDA
|
||||
sda_chk <= #1 1'b1; // check SDA output
|
||||
end
|
||||
|
||||
wr_c:
|
||||
begin
|
||||
c_state <= #1 wr_d;
|
||||
scl_oen <= #1 1'b1; // keep SCL high
|
||||
sda_oen <= #1 din;
|
||||
sda_chk <= #1 1'b1; // check SDA output
|
||||
end
|
||||
|
||||
wr_d:
|
||||
begin
|
||||
c_state <= #1 idle;
|
||||
cmd_ack <= #1 1'b1;
|
||||
scl_oen <= #1 1'b0; // set SCL low
|
||||
sda_oen <= #1 din;
|
||||
sda_chk <= #1 1'b0; // don't check SDA output (SCL low)
|
||||
end
|
||||
|
||||
// read (last SPI bit)
|
||||
spi_rd_a:
|
||||
begin
|
||||
c_state <= #1 spi_rd_b;
|
||||
scl_oen <= #1 1'b0; // set SCL low
|
||||
sda_oen <= #1 1'b1; // tri-state SDA
|
||||
sda_chk <= #1 1'b0; // don't check SDA output
|
||||
end
|
||||
|
||||
spi_rd_b:
|
||||
begin
|
||||
c_state <= #1 spi_rd_c;
|
||||
scl_oen <= #1 1'b0; // keep SCL low
|
||||
sda_oen <= #1 1'b1; // keep SDA tri-stated
|
||||
sda_chk <= #1 1'b0; // don't check SDA output
|
||||
end
|
||||
|
||||
spi_rd_c:
|
||||
begin
|
||||
c_state <= #1 spi_rd_d;
|
||||
scl_oen <= #1 1'b1; // set SCL high
|
||||
sda_oen <= #1 1'b1; // keep SDA tri-stated
|
||||
sda_chk <= #1 1'b0; // don't check SDA output
|
||||
end
|
||||
|
||||
spi_rd_d:
|
||||
begin
|
||||
c_state <= #1 idle;
|
||||
cmd_ack <= #1 1'b1;
|
||||
scl_oen <= #1 1'b1; // tri-state SCL
|
||||
sda_oen <= #1 1'b1; // keep SDA tri-stated
|
||||
sda_chk <= #1 1'b0; // don't check SDA output
|
||||
end
|
||||
|
||||
// write (last SPI bit)
|
||||
spi_wr_a:
|
||||
begin
|
||||
c_state <= #1 spi_wr_b;
|
||||
scl_oen <= #1 1'b0; // set SCL low
|
||||
sda_oen <= #1 1'b1; // keep SDA
|
||||
sda_chk <= #1 1'b0; // don't check SDA output
|
||||
end
|
||||
|
||||
spi_wr_b:
|
||||
begin
|
||||
c_state <= #1 spi_wr_c;
|
||||
scl_oen <= #1 1'b0; // keep SCL low
|
||||
sda_oen <= #1 din; // set SDA
|
||||
sda_chk <= #1 1'b0; // don't check SDA output
|
||||
end
|
||||
|
||||
spi_wr_c:
|
||||
begin
|
||||
c_state <= #1 spi_wr_d;
|
||||
scl_oen <= #1 1'b1; // keep SCL high
|
||||
sda_oen <= #1 din; // keep SDA
|
||||
sda_chk <= #1 1'b0; // don't check SDA output
|
||||
end
|
||||
|
||||
spi_wr_d:
|
||||
begin
|
||||
c_state <= #1 idle;
|
||||
cmd_ack <= #1 1'b1;
|
||||
scl_oen <= #1 1'b1; // tri-state SCL
|
||||
sda_oen <= #1 1'b1; // tri-state SDA
|
||||
sda_chk <= #1 1'b0; // don't check SDA output
|
||||
end
|
||||
|
||||
default:
|
||||
c_state <= #1 idle;
|
||||
|
||||
endcase
|
||||
end
|
||||
|
||||
|
||||
// assign scl and sda output (always gnd)
|
||||
assign scl_o = 1'b0;
|
||||
assign sda_o = 1'b0;
|
||||
|
||||
endmodule
|
||||
@@ -0,0 +1,382 @@
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
//// ////
|
||||
//// WISHBONE rev.B2 compliant I2C Master byte-controller ////
|
||||
//// ////
|
||||
//// ////
|
||||
//// Author: Richard Herveille ////
|
||||
//// richard@asics.ws ////
|
||||
//// www.asics.ws ////
|
||||
//// ////
|
||||
//// Downloaded from: http://www.opencores.org/projects/i2c/ ////
|
||||
//// ////
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
//// ////
|
||||
//// Copyright (C) 2001 Richard Herveille ////
|
||||
//// richard@asics.ws ////
|
||||
//// ////
|
||||
//// This source file may be used and distributed without ////
|
||||
//// restriction provided that this copyright statement is not ////
|
||||
//// removed from the file and that any derivative work contains ////
|
||||
//// the original copyright notice and the associated disclaimer.////
|
||||
//// ////
|
||||
//// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY ////
|
||||
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED ////
|
||||
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ////
|
||||
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR ////
|
||||
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, ////
|
||||
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ////
|
||||
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ////
|
||||
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR ////
|
||||
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF ////
|
||||
//// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ////
|
||||
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ////
|
||||
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ////
|
||||
//// POSSIBILITY OF SUCH DAMAGE. ////
|
||||
//// ////
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
// CVS Log
|
||||
//
|
||||
// $Id: i2c_master_byte_ctrl.v,v 1.7 2004/02/18 11:40:46 rherveille Exp $
|
||||
//
|
||||
// $Date: 2004/02/18 11:40:46 $
|
||||
// $Revision: 1.7 $
|
||||
// $Author: rherveille $
|
||||
// $Locker: $
|
||||
// $State: Exp $
|
||||
//
|
||||
// Change History:
|
||||
// $Log: i2c_master_byte_ctrl.v,v $
|
||||
// Revision 1.7 2004/02/18 11:40:46 rherveille
|
||||
// Fixed a potential bug in the statemachine. During a 'stop' 2 cmd_ack signals were generated. Possibly canceling a new start command.
|
||||
//
|
||||
// Revision 1.6 2003/08/09 07:01:33 rherveille
|
||||
// Fixed a bug in the Arbitration Lost generation caused by delay on the (external) sda line.
|
||||
// Fixed a potential bug in the byte controller's host-acknowledge generation.
|
||||
//
|
||||
// Revision 1.5 2002/12/26 15:02:32 rherveille
|
||||
// Core is now a Multimaster I2C controller
|
||||
//
|
||||
// Revision 1.4 2002/11/30 22:24:40 rherveille
|
||||
// Cleaned up code
|
||||
//
|
||||
// Revision 1.3 2001/11/05 11:59:25 rherveille
|
||||
// Fixed wb_ack_o generation bug.
|
||||
// Fixed bug in the byte_controller statemachine.
|
||||
// Added headers.
|
||||
//
|
||||
|
||||
// synopsys translate_off
|
||||
`include "timescale.v"
|
||||
// synopsys translate_on
|
||||
|
||||
`include "i2c_master_defines.v"
|
||||
|
||||
module i2c_master_byte_ctrl (
|
||||
clk, rst, nReset, ena, clk_cnt, start, stop, read, write, ack_in, spi_mode, din,
|
||||
cmd_ack, ack_out, dout, i2c_busy, i2c_al, scl_i, scl_o, scl_oen, sda_i, sda_o, sda_oen );
|
||||
|
||||
//
|
||||
// inputs & outputs
|
||||
//
|
||||
input clk; // master clock
|
||||
input rst; // synchronous active high reset
|
||||
input nReset; // asynchronous active low reset
|
||||
input ena; // core enable signal
|
||||
|
||||
input [15:0] clk_cnt; // 4x SCL
|
||||
|
||||
// control inputs
|
||||
input start;
|
||||
input stop;
|
||||
input read;
|
||||
input write;
|
||||
input ack_in;
|
||||
input spi_mode;
|
||||
input [7:0] din;
|
||||
|
||||
// status outputs
|
||||
output cmd_ack;
|
||||
reg cmd_ack;
|
||||
output ack_out;
|
||||
reg ack_out;
|
||||
output i2c_busy;
|
||||
output i2c_al;
|
||||
output [7:0] dout;
|
||||
|
||||
// I2C signals
|
||||
input scl_i;
|
||||
output scl_o;
|
||||
output scl_oen;
|
||||
input sda_i;
|
||||
output sda_o;
|
||||
output sda_oen;
|
||||
|
||||
|
||||
//
|
||||
// Variable declarations
|
||||
//
|
||||
|
||||
// statemachine
|
||||
parameter [6:0] ST_IDLE = 7'b000_0000;
|
||||
parameter [6:0] ST_START = 7'b000_0001;
|
||||
parameter [6:0] ST_READ = 7'b000_0010;
|
||||
parameter [6:0] ST_WRITE = 7'b000_0100;
|
||||
parameter [6:0] ST_ACK = 7'b000_1000;
|
||||
parameter [6:0] ST_STOP = 7'b001_0000;
|
||||
parameter [6:0] ST_SPI_READ = 7'b010_0000;
|
||||
parameter [6:0] ST_SPI_WRITE = 7'b100_0000;
|
||||
|
||||
|
||||
// signals for bit_controller
|
||||
reg [5:0] core_cmd;
|
||||
reg core_txd;
|
||||
wire core_ack, core_rxd;
|
||||
|
||||
// signals for shift register
|
||||
reg [7:0] sr; //8bit shift register
|
||||
reg shift, ld;
|
||||
|
||||
// signals for state machine
|
||||
wire go;
|
||||
reg [2:0] dcnt;
|
||||
wire cnt_done;
|
||||
|
||||
//
|
||||
// Module body
|
||||
//
|
||||
|
||||
// hookup bit_controller
|
||||
i2c_master_bit_ctrl bit_controller (
|
||||
.clk ( clk ),
|
||||
.rst ( rst ),
|
||||
.nReset ( nReset ),
|
||||
.ena ( ena ),
|
||||
.clk_cnt ( clk_cnt ),
|
||||
.cmd ( core_cmd ),
|
||||
.cmd_ack ( core_ack ),
|
||||
.busy ( i2c_busy ),
|
||||
.al ( i2c_al ),
|
||||
.din ( core_txd ),
|
||||
.dout ( core_rxd ),
|
||||
.scl_i ( scl_i ),
|
||||
.scl_o ( scl_o ),
|
||||
.scl_oen ( scl_oen ),
|
||||
.sda_i ( sda_i ),
|
||||
.sda_o ( sda_o ),
|
||||
.sda_oen ( sda_oen )
|
||||
);
|
||||
|
||||
// generate go-signal
|
||||
assign go = (read | write | stop) & ~cmd_ack;
|
||||
|
||||
// assign dout output to shift-register
|
||||
assign dout = sr;
|
||||
|
||||
// generate shift register
|
||||
always @(posedge clk or negedge nReset)
|
||||
if (!nReset)
|
||||
sr <= #1 8'h0;
|
||||
else if (rst)
|
||||
sr <= #1 8'h0;
|
||||
else if (ld)
|
||||
sr <= #1 din;
|
||||
else if (shift)
|
||||
sr <= #1 {sr[6:0], core_rxd};
|
||||
|
||||
// generate counter
|
||||
always @(posedge clk or negedge nReset)
|
||||
if (!nReset)
|
||||
dcnt <= #1 3'h0;
|
||||
else if (rst)
|
||||
dcnt <= #1 3'h0;
|
||||
else if (ld)
|
||||
dcnt <= #1 3'h7;
|
||||
else if (shift)
|
||||
dcnt <= #1 dcnt - 3'h1;
|
||||
|
||||
assign cnt_done = ~(|dcnt);
|
||||
|
||||
//
|
||||
// state machine
|
||||
//
|
||||
reg [6:0] c_state; // synopsis enum_state
|
||||
|
||||
always @(posedge clk or negedge nReset)
|
||||
if (!nReset)
|
||||
begin
|
||||
core_cmd <= #1 `I2C_CMD_NOP;
|
||||
core_txd <= #1 1'b0;
|
||||
shift <= #1 1'b0;
|
||||
ld <= #1 1'b0;
|
||||
cmd_ack <= #1 1'b0;
|
||||
c_state <= #1 ST_IDLE;
|
||||
ack_out <= #1 1'b0;
|
||||
end
|
||||
else if (rst | i2c_al)
|
||||
begin
|
||||
core_cmd <= #1 `I2C_CMD_NOP;
|
||||
core_txd <= #1 1'b0;
|
||||
shift <= #1 1'b0;
|
||||
ld <= #1 1'b0;
|
||||
cmd_ack <= #1 1'b0;
|
||||
c_state <= #1 ST_IDLE;
|
||||
ack_out <= #1 1'b0;
|
||||
end
|
||||
else
|
||||
begin
|
||||
// initially reset all signals
|
||||
core_txd <= #1 sr[7];
|
||||
shift <= #1 1'b0;
|
||||
ld <= #1 1'b0;
|
||||
cmd_ack <= #1 1'b0;
|
||||
|
||||
case (c_state) // synopsys full_case parallel_case
|
||||
ST_IDLE:
|
||||
if (go)
|
||||
begin
|
||||
if (start)
|
||||
begin
|
||||
c_state <= #1 ST_START;
|
||||
core_cmd <= #1 `I2C_CMD_START;
|
||||
end
|
||||
else if (read)
|
||||
begin
|
||||
c_state <= #1 spi_mode ? ST_SPI_READ : ST_READ;
|
||||
core_cmd <= #1 spi_mode ? `SPI_CMD_READ : `I2C_CMD_READ;
|
||||
end
|
||||
else if (write)
|
||||
begin
|
||||
c_state <= #1 spi_mode ? ST_SPI_WRITE : ST_WRITE;
|
||||
core_cmd <= #1 spi_mode ? `SPI_CMD_WRITE : `I2C_CMD_WRITE;
|
||||
end
|
||||
else // stop
|
||||
begin
|
||||
c_state <= #1 ST_STOP;
|
||||
core_cmd <= #1 `I2C_CMD_STOP;
|
||||
end
|
||||
|
||||
ld <= #1 1'b1;
|
||||
end
|
||||
|
||||
ST_START:
|
||||
if (core_ack)
|
||||
begin
|
||||
if (read)
|
||||
begin
|
||||
c_state <= #1 ST_READ;
|
||||
core_cmd <= #1 `I2C_CMD_READ;
|
||||
end
|
||||
else
|
||||
begin
|
||||
c_state <= #1 ST_WRITE;
|
||||
core_cmd <= #1 `I2C_CMD_WRITE;
|
||||
end
|
||||
|
||||
ld <= #1 1'b1;
|
||||
end
|
||||
|
||||
ST_WRITE:
|
||||
if (core_ack)
|
||||
if (cnt_done)
|
||||
begin
|
||||
c_state <= #1 ST_ACK;
|
||||
core_cmd <= #1 `I2C_CMD_READ;
|
||||
end
|
||||
else
|
||||
begin
|
||||
c_state <= #1 ST_WRITE; // stay in same state
|
||||
core_cmd <= #1 `I2C_CMD_WRITE; // write next bit
|
||||
shift <= #1 1'b1;
|
||||
end
|
||||
|
||||
ST_READ:
|
||||
if (core_ack)
|
||||
begin
|
||||
if (cnt_done)
|
||||
begin
|
||||
c_state <= #1 ST_ACK;
|
||||
core_cmd <= #1 `I2C_CMD_WRITE;
|
||||
end
|
||||
else
|
||||
begin
|
||||
c_state <= #1 ST_READ; // stay in same state
|
||||
core_cmd <= #1 `I2C_CMD_READ; // read next bit
|
||||
end
|
||||
|
||||
shift <= #1 1'b1;
|
||||
core_txd <= #1 ack_in;
|
||||
end
|
||||
|
||||
ST_ACK:
|
||||
if (core_ack)
|
||||
begin
|
||||
if (stop)
|
||||
begin
|
||||
c_state <= #1 ST_STOP;
|
||||
core_cmd <= #1 `I2C_CMD_STOP;
|
||||
end
|
||||
else
|
||||
begin
|
||||
c_state <= #1 ST_IDLE;
|
||||
core_cmd <= #1 `I2C_CMD_NOP;
|
||||
|
||||
// generate command acknowledge signal
|
||||
cmd_ack <= #1 1'b1;
|
||||
end
|
||||
|
||||
// assign ack_out output to bit_controller_rxd (contains last received bit)
|
||||
ack_out <= #1 core_rxd;
|
||||
|
||||
core_txd <= #1 1'b1;
|
||||
end
|
||||
else
|
||||
core_txd <= #1 ack_in;
|
||||
|
||||
ST_STOP:
|
||||
if (core_ack)
|
||||
begin
|
||||
c_state <= #1 ST_IDLE;
|
||||
core_cmd <= #1 `I2C_CMD_NOP;
|
||||
|
||||
// generate command acknowledge signal
|
||||
cmd_ack <= #1 1'b1;
|
||||
end
|
||||
|
||||
ST_SPI_WRITE:
|
||||
if (core_ack)
|
||||
if (cnt_done)
|
||||
begin
|
||||
c_state <= #1 ST_IDLE;
|
||||
core_cmd <= #1 `I2C_CMD_NOP;
|
||||
cmd_ack <= #1 1'b1;
|
||||
end
|
||||
else
|
||||
begin
|
||||
c_state <= #1 ST_SPI_WRITE; // stay in same state
|
||||
core_cmd <= #1 `SPI_CMD_WRITE; // write next bit
|
||||
shift <= #1 1'b1;
|
||||
end
|
||||
|
||||
ST_SPI_READ:
|
||||
if (core_ack)
|
||||
begin
|
||||
if (cnt_done)
|
||||
begin
|
||||
c_state <= #1 ST_IDLE;
|
||||
core_cmd <= #1 `I2C_CMD_NOP;
|
||||
cmd_ack <= #1 1'b1;
|
||||
end
|
||||
else
|
||||
begin
|
||||
c_state <= #1 ST_SPI_READ; // stay in same state
|
||||
core_cmd <= #1 `SPI_CMD_READ; // read next bit
|
||||
end
|
||||
|
||||
shift <= #1 1'b1;
|
||||
core_txd <= #1 ack_in;
|
||||
end
|
||||
|
||||
endcase
|
||||
end
|
||||
endmodule
|
||||
@@ -0,0 +1,66 @@
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
//// ////
|
||||
//// WISHBONE rev.B2 compliant I2C Master controller defines ////
|
||||
//// ////
|
||||
//// ////
|
||||
//// Author: Richard Herveille ////
|
||||
//// richard@asics.ws ////
|
||||
//// www.asics.ws ////
|
||||
//// ////
|
||||
//// Downloaded from: http://www.opencores.org/projects/i2c/ ////
|
||||
//// ////
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
//// ////
|
||||
//// Copyright (C) 2001 Richard Herveille ////
|
||||
//// richard@asics.ws ////
|
||||
//// ////
|
||||
//// This source file may be used and distributed without ////
|
||||
//// restriction provided that this copyright statement is not ////
|
||||
//// removed from the file and that any derivative work contains ////
|
||||
//// the original copyright notice and the associated disclaimer.////
|
||||
//// ////
|
||||
//// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY ////
|
||||
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED ////
|
||||
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ////
|
||||
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR ////
|
||||
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, ////
|
||||
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ////
|
||||
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ////
|
||||
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR ////
|
||||
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF ////
|
||||
//// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ////
|
||||
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ////
|
||||
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ////
|
||||
//// POSSIBILITY OF SUCH DAMAGE. ////
|
||||
//// ////
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
// CVS Log
|
||||
//
|
||||
// $Id: i2c_master_defines.v,v 1.3 2001/11/05 11:59:25 rherveille Exp $
|
||||
//
|
||||
// $Date: 2001/11/05 11:59:25 $
|
||||
// $Revision: 1.3 $
|
||||
// $Author: rherveille $
|
||||
// $Locker: $
|
||||
// $State: Exp $
|
||||
//
|
||||
// Change History:
|
||||
// $Log: i2c_master_defines.v,v $
|
||||
// Revision 1.3 2001/11/05 11:59:25 rherveille
|
||||
// Fixed wb_ack_o generation bug.
|
||||
// Fixed bug in the byte_controller statemachine.
|
||||
// Added headers.
|
||||
//
|
||||
|
||||
|
||||
// I2C registers wishbone addresses
|
||||
|
||||
// bitcontroller states
|
||||
`define I2C_CMD_NOP 6'b000000
|
||||
`define I2C_CMD_START 6'b000001
|
||||
`define I2C_CMD_STOP 6'b000010
|
||||
`define I2C_CMD_WRITE 6'b000100
|
||||
`define I2C_CMD_READ 6'b001000
|
||||
`define SPI_CMD_WRITE 6'b010000
|
||||
`define SPI_CMD_READ 6'b100000
|
||||
@@ -0,0 +1,300 @@
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
//// ////
|
||||
//// WISHBONE revB.2 compliant I2C Master controller Top-level ////
|
||||
//// ////
|
||||
//// ////
|
||||
//// Author: Richard Herveille ////
|
||||
//// richard@asics.ws ////
|
||||
//// www.asics.ws ////
|
||||
//// ////
|
||||
//// Downloaded from: http://www.opencores.org/projects/i2c/ ////
|
||||
//// ////
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
//// ////
|
||||
//// Copyright (C) 2001 Richard Herveille ////
|
||||
//// richard@asics.ws ////
|
||||
//// ////
|
||||
//// This source file may be used and distributed without ////
|
||||
//// restriction provided that this copyright statement is not ////
|
||||
//// removed from the file and that any derivative work contains ////
|
||||
//// the original copyright notice and the associated disclaimer.////
|
||||
//// ////
|
||||
//// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY ////
|
||||
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED ////
|
||||
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ////
|
||||
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR ////
|
||||
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, ////
|
||||
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ////
|
||||
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ////
|
||||
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR ////
|
||||
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF ////
|
||||
//// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ////
|
||||
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ////
|
||||
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ////
|
||||
//// POSSIBILITY OF SUCH DAMAGE. ////
|
||||
//// ////
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
// CVS Log
|
||||
//
|
||||
// $Id: i2c_master_top.v,v 1.10 2003/09/01 10:34:38 rherveille Exp $
|
||||
//
|
||||
// $Date: 2003/09/01 10:34:38 $
|
||||
// $Revision: 1.10 $
|
||||
// $Author: rherveille $
|
||||
// $Locker: $
|
||||
// $State: Exp $
|
||||
//
|
||||
// Change History:
|
||||
// $Log: i2c_master_top.v,v $
|
||||
// Revision 1.10 2003/09/01 10:34:38 rherveille
|
||||
// Fix a blocking vs. non-blocking error in the wb_dat output mux.
|
||||
//
|
||||
// Revision 1.9 2003/01/09 16:44:45 rherveille
|
||||
// Fixed a bug in the Command Register declaration.
|
||||
//
|
||||
// Revision 1.8 2002/12/26 16:05:12 rherveille
|
||||
// Small code simplifications
|
||||
//
|
||||
// Revision 1.7 2002/12/26 15:02:32 rherveille
|
||||
// Core is now a Multimaster I2C controller
|
||||
//
|
||||
// Revision 1.6 2002/11/30 22:24:40 rherveille
|
||||
// Cleaned up code
|
||||
//
|
||||
// Revision 1.5 2001/11/10 10:52:55 rherveille
|
||||
// Changed PRER reset value from 0x0000 to 0xffff, conform specs.
|
||||
//
|
||||
|
||||
// synopsys translate_off
|
||||
`include "timescale.v"
|
||||
// synopsys translate_on
|
||||
|
||||
`include "i2c_master_defines.v"
|
||||
|
||||
module i2c_master_top(
|
||||
wb_clk_i, wb_rst_i, arst_i, wb_adr_i, wb_dat_i, wb_dat_o,
|
||||
wb_we_i, wb_stb_i, wb_cyc_i, wb_ack_o, wb_inta_o,
|
||||
scl_pad_i, scl_pad_o, scl_padoen_o, sda_pad_i, sda_pad_o, sda_padoen_o );
|
||||
|
||||
// parameters
|
||||
parameter ARST_LVL = 1'b0; // asynchronous reset level
|
||||
|
||||
//
|
||||
// inputs & outputs
|
||||
//
|
||||
|
||||
// wishbone signals
|
||||
input wb_clk_i; // master clock input
|
||||
input wb_rst_i; // synchronous active high reset
|
||||
input arst_i; // asynchronous reset
|
||||
input [2:0] wb_adr_i; // lower address bits
|
||||
input [7:0] wb_dat_i; // databus input
|
||||
output [7:0] wb_dat_o; // databus output
|
||||
input wb_we_i; // write enable input
|
||||
input wb_stb_i; // stobe/core select signal
|
||||
input wb_cyc_i; // valid bus cycle input
|
||||
output wb_ack_o; // bus cycle acknowledge output
|
||||
output wb_inta_o; // interrupt request signal output
|
||||
|
||||
reg [7:0] wb_dat_o;
|
||||
reg wb_ack_o;
|
||||
reg wb_inta_o;
|
||||
|
||||
// I2C signals
|
||||
// i2c clock line
|
||||
input scl_pad_i; // SCL-line input
|
||||
output scl_pad_o; // SCL-line output (always 1'b0)
|
||||
output scl_padoen_o; // SCL-line output enable (active low)
|
||||
|
||||
// i2c data line
|
||||
input sda_pad_i; // SDA-line input
|
||||
output sda_pad_o; // SDA-line output (always 1'b0)
|
||||
output sda_padoen_o; // SDA-line output enable (active low)
|
||||
|
||||
|
||||
//
|
||||
// variable declarations
|
||||
//
|
||||
|
||||
// registers
|
||||
reg [15:0] prer; // clock prescale register
|
||||
reg [ 7:0] ctr; // control register
|
||||
reg [ 7:0] txr; // transmit register
|
||||
wire [ 7:0] rxr; // receive register
|
||||
reg [ 7:0] cr; // command register
|
||||
wire [ 7:0] sr; // status register
|
||||
|
||||
// done signal: command completed, clear command register
|
||||
wire done;
|
||||
|
||||
// core enable signal
|
||||
wire core_en;
|
||||
wire ien;
|
||||
|
||||
// status register signals
|
||||
wire irxack;
|
||||
reg rxack; // received aknowledge from slave
|
||||
reg tip; // transfer in progress
|
||||
reg irq_flag; // interrupt pending flag
|
||||
wire i2c_busy; // bus busy (start signal detected)
|
||||
wire i2c_al; // i2c bus arbitration lost
|
||||
reg al; // status register arbitration lost bit
|
||||
|
||||
//
|
||||
// module body
|
||||
//
|
||||
|
||||
// generate internal reset
|
||||
wire rst_i = arst_i ^ ARST_LVL;
|
||||
|
||||
// generate wishbone signals
|
||||
wire wb_wacc = wb_cyc_i & wb_stb_i & wb_we_i;
|
||||
|
||||
// generate acknowledge output signal
|
||||
always @(posedge wb_clk_i)
|
||||
wb_ack_o <= #1 wb_cyc_i & wb_stb_i & ~wb_ack_o; // because timing is always honored
|
||||
|
||||
// assign DAT_O
|
||||
always @(posedge wb_clk_i)
|
||||
begin
|
||||
case (wb_adr_i) // synopsis full_case parallel_case
|
||||
3'b000: wb_dat_o <= #1 prer[ 7:0];
|
||||
3'b001: wb_dat_o <= #1 prer[15:8];
|
||||
3'b010: wb_dat_o <= #1 ctr;
|
||||
3'b011: wb_dat_o <= #1 rxr; // write is transmit register (txr)
|
||||
3'b100: wb_dat_o <= #1 sr; // write is command register (cr)
|
||||
3'b101: wb_dat_o <= #1 txr;
|
||||
3'b110: wb_dat_o <= #1 cr;
|
||||
3'b111: wb_dat_o <= #1 0; // reserved
|
||||
endcase
|
||||
end
|
||||
|
||||
// generate registers
|
||||
always @(posedge wb_clk_i or negedge rst_i)
|
||||
if (!rst_i)
|
||||
begin
|
||||
prer <= #1 16'hffff;
|
||||
ctr <= #1 8'h0;
|
||||
txr <= #1 8'h0;
|
||||
end
|
||||
else if (wb_rst_i)
|
||||
begin
|
||||
prer <= #1 16'hffff;
|
||||
ctr <= #1 8'h0;
|
||||
txr <= #1 8'h0;
|
||||
end
|
||||
else
|
||||
if (wb_wacc)
|
||||
case (wb_adr_i) // synopsis full_case parallel_case
|
||||
3'b000 : prer [ 7:0] <= #1 wb_dat_i;
|
||||
3'b001 : prer [15:8] <= #1 wb_dat_i;
|
||||
3'b010 : ctr <= #1 wb_dat_i;
|
||||
3'b011 : txr <= #1 wb_dat_i;
|
||||
endcase
|
||||
|
||||
// generate command register (special case)
|
||||
always @(posedge wb_clk_i or negedge rst_i)
|
||||
if (~rst_i)
|
||||
cr <= #1 8'h0;
|
||||
else if (wb_rst_i)
|
||||
cr <= #1 8'h0;
|
||||
else if (wb_wacc)
|
||||
begin
|
||||
if (core_en & (wb_adr_i == 3'b100) )
|
||||
cr <= #1 wb_dat_i;
|
||||
end
|
||||
else
|
||||
begin
|
||||
if (done | i2c_al)
|
||||
begin
|
||||
cr[7:4] <= #1 4'h0; // clear command bits when done
|
||||
cr[2] <= #1 1'b0; // or when aribitration lost
|
||||
end
|
||||
cr[1] <= #1 1'b0; // reserved bit
|
||||
cr[0] <= #1 1'b0; // clear IRQ_ACK bit
|
||||
end
|
||||
|
||||
|
||||
// decode command register
|
||||
wire sta = cr[7];
|
||||
wire sto = cr[6];
|
||||
wire rd = cr[5];
|
||||
wire wr = cr[4];
|
||||
wire ack = cr[3];
|
||||
wire spi = cr[2];
|
||||
wire iack = cr[0];
|
||||
|
||||
// decode control register
|
||||
assign core_en = ctr[7];
|
||||
assign ien = ctr[6];
|
||||
|
||||
// hookup byte controller block
|
||||
i2c_master_byte_ctrl byte_controller (
|
||||
.clk ( wb_clk_i ),
|
||||
.rst ( wb_rst_i ),
|
||||
.nReset ( rst_i ),
|
||||
.ena ( core_en ),
|
||||
.clk_cnt ( prer ),
|
||||
.start ( sta ),
|
||||
.stop ( sto ),
|
||||
.read ( rd ),
|
||||
.write ( wr ),
|
||||
.ack_in ( ack ),
|
||||
.spi_mode ( spi ),
|
||||
.din ( txr ),
|
||||
.cmd_ack ( done ),
|
||||
.ack_out ( irxack ),
|
||||
.dout ( rxr ),
|
||||
.i2c_busy ( i2c_busy ),
|
||||
.i2c_al ( i2c_al ),
|
||||
.scl_i ( scl_pad_i ),
|
||||
.scl_o ( scl_pad_o ),
|
||||
.scl_oen ( scl_padoen_o ),
|
||||
.sda_i ( sda_pad_i ),
|
||||
.sda_o ( sda_pad_o ),
|
||||
.sda_oen ( sda_padoen_o )
|
||||
);
|
||||
|
||||
// status register block + interrupt request signal
|
||||
always @(posedge wb_clk_i or negedge rst_i)
|
||||
if (!rst_i)
|
||||
begin
|
||||
al <= #1 1'b0;
|
||||
rxack <= #1 1'b0;
|
||||
tip <= #1 1'b0;
|
||||
irq_flag <= #1 1'b0;
|
||||
end
|
||||
else if (wb_rst_i)
|
||||
begin
|
||||
al <= #1 1'b0;
|
||||
rxack <= #1 1'b0;
|
||||
tip <= #1 1'b0;
|
||||
irq_flag <= #1 1'b0;
|
||||
end
|
||||
else
|
||||
begin
|
||||
al <= #1 i2c_al | (al & ~sta);
|
||||
rxack <= #1 irxack;
|
||||
tip <= #1 (rd | wr);
|
||||
irq_flag <= #1 (done | i2c_al | irq_flag) & ~iack; // interrupt request flag is always generated
|
||||
end
|
||||
|
||||
// generate interrupt request signals
|
||||
always @(posedge wb_clk_i or negedge rst_i)
|
||||
if (!rst_i)
|
||||
wb_inta_o <= #1 1'b0;
|
||||
else if (wb_rst_i)
|
||||
wb_inta_o <= #1 1'b0;
|
||||
else
|
||||
wb_inta_o <= #1 irq_flag && ien; // interrupt signal is only generated when IEN (interrupt enable bit is set)
|
||||
|
||||
// assign status register bits
|
||||
assign sr[7] = rxack;
|
||||
assign sr[6] = i2c_busy;
|
||||
assign sr[5] = al;
|
||||
assign sr[4:2] = 3'h0; // reserved
|
||||
assign sr[1] = tip;
|
||||
assign sr[0] = irq_flag;
|
||||
|
||||
endmodule
|
||||
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// fixed for 9.1 jan 21 2010 cruben
|
||||
//
|
||||
`include "timescale.v"
|
||||
`include "i2c_master_defines.v"
|
||||
|
||||
module i2c_opencores
|
||||
(
|
||||
wb_clk_i, wb_rst_i, wb_adr_i, wb_dat_i, wb_dat_o,
|
||||
wb_we_i, wb_stb_i, /*wb_cyc_i,*/ wb_ack_o, wb_inta_o,
|
||||
scl_pad_io, sda_pad_io
|
||||
);
|
||||
|
||||
|
||||
// Common bus signals
|
||||
input wb_clk_i; // WISHBONE clock
|
||||
input wb_rst_i; // WISHBONE reset
|
||||
|
||||
// Slave signals
|
||||
input [2:0] wb_adr_i; // WISHBONE address input
|
||||
input [7:0] wb_dat_i; // WISHBONE data input
|
||||
output [7:0] wb_dat_o; // WISHBONE data output
|
||||
input wb_we_i; // WISHBONE write enable input
|
||||
input wb_stb_i; // WISHBONE strobe input
|
||||
//input wb_cyc_i; // WISHBONE cycle input
|
||||
output wb_ack_o; // WISHBONE acknowledge output
|
||||
output wb_inta_o; // WISHBONE interrupt output
|
||||
|
||||
// I2C signals
|
||||
inout scl_pad_io; // I2C clock io
|
||||
inout sda_pad_io; // I2C data io
|
||||
|
||||
wire wb_cyc_i; // WISHBONE cycle input
|
||||
// Wire tri-state scl/sda
|
||||
wire scl_pad_i;
|
||||
wire scl_pad_o;
|
||||
wire scl_pad_io;
|
||||
wire scl_padoen_o;
|
||||
|
||||
assign wb_cyc_i = wb_stb_i;
|
||||
assign scl_pad_i = scl_pad_io;
|
||||
assign scl_pad_io = scl_padoen_o ? 1'bZ : scl_pad_o;
|
||||
|
||||
wire sda_pad_i;
|
||||
wire sda_pad_o;
|
||||
wire sda_pad_io;
|
||||
wire sda_padoen_o;
|
||||
|
||||
assign sda_pad_i = sda_pad_io;
|
||||
assign sda_pad_io = sda_padoen_o ? 1'bZ : sda_pad_o;
|
||||
|
||||
// Avalon doesn't have an asynchronous reset
|
||||
// set it to be inactive and just use synchronous reset
|
||||
// reset level is a parameter, 0 is the default (active-low reset)
|
||||
wire arst_i;
|
||||
|
||||
assign arst_i = 1'b1;
|
||||
|
||||
// Connect the top level I2C core
|
||||
i2c_master_top i2c_master_top_inst
|
||||
(
|
||||
.wb_clk_i(wb_clk_i), .wb_rst_i(wb_rst_i), .arst_i(arst_i),
|
||||
|
||||
.wb_adr_i(wb_adr_i), .wb_dat_i(wb_dat_i), .wb_dat_o(wb_dat_o),
|
||||
.wb_we_i(wb_we_i), .wb_stb_i(wb_stb_i), .wb_cyc_i(wb_cyc_i),
|
||||
.wb_ack_o(wb_ack_o), .wb_inta_o(wb_inta_o),
|
||||
|
||||
.scl_pad_i(scl_pad_i), .scl_pad_o(scl_pad_o), .scl_padoen_o(scl_padoen_o),
|
||||
.sda_pad_i(sda_pad_i), .sda_pad_o(sda_pad_o), .sda_padoen_o(sda_padoen_o)
|
||||
);
|
||||
|
||||
endmodule
|
||||
@@ -0,0 +1,166 @@
|
||||
# TCL File Generated by Component Editor 13.1
|
||||
# Sat May 17 17:29:02 EEST 2014
|
||||
# DO NOT MODIFY
|
||||
|
||||
|
||||
#
|
||||
# i2c_opencores "I2C Master (opencores.org)" v13.0
|
||||
# 2014.05.17.17:29:02
|
||||
# I2C Master Peripheral from opencores.org
|
||||
#
|
||||
|
||||
#
|
||||
# request TCL package from ACDS 13.1
|
||||
#
|
||||
package require -exact qsys 13.1
|
||||
|
||||
|
||||
#
|
||||
# module i2c_opencores
|
||||
#
|
||||
set_module_property DESCRIPTION "I2C Master Peripheral from opencores.org"
|
||||
set_module_property NAME i2c_opencores
|
||||
set_module_property VERSION 13.0
|
||||
set_module_property INTERNAL false
|
||||
set_module_property OPAQUE_ADDRESS_MAP true
|
||||
set_module_property GROUP "Interface Protocols/Serial"
|
||||
set_module_property AUTHOR ""
|
||||
set_module_property DISPLAY_NAME "I2C Master (opencores.org)"
|
||||
set_module_property INSTANTIATE_IN_SYSTEM_MODULE true
|
||||
set_module_property EDITABLE true
|
||||
set_module_property ANALYZE_HDL AUTO
|
||||
set_module_property REPORT_TO_TALKBACK false
|
||||
set_module_property ALLOW_GREYBOX_GENERATION false
|
||||
|
||||
|
||||
#
|
||||
# file sets
|
||||
#
|
||||
add_fileset quartus_synth QUARTUS_SYNTH "" "Quartus Synthesis"
|
||||
set_fileset_property quartus_synth TOP_LEVEL i2c_opencores
|
||||
set_fileset_property quartus_synth ENABLE_RELATIVE_INCLUDE_PATHS false
|
||||
add_fileset_file i2c_opencores.v VERILOG PATH i2c_opencores.v
|
||||
add_fileset_file i2c_master_top.v VERILOG PATH i2c_master_top.v
|
||||
add_fileset_file i2c_master_defines.v VERILOG PATH i2c_master_defines.v
|
||||
add_fileset_file i2c_master_byte_ctrl.v VERILOG PATH i2c_master_byte_ctrl.v
|
||||
add_fileset_file i2c_master_bit_ctrl.v VERILOG PATH i2c_master_bit_ctrl.v
|
||||
|
||||
add_fileset sim_verilog SIM_VERILOG "" "Verilog Simulation"
|
||||
set_fileset_property sim_verilog TOP_LEVEL i2c_opencores
|
||||
set_fileset_property sim_verilog ENABLE_RELATIVE_INCLUDE_PATHS false
|
||||
add_fileset_file i2c_opencores.v VERILOG PATH i2c_opencores.v
|
||||
add_fileset_file i2c_master_top.v VERILOG PATH i2c_master_top.v
|
||||
add_fileset_file i2c_master_defines.v VERILOG PATH i2c_master_defines.v
|
||||
add_fileset_file i2c_master_byte_ctrl.v VERILOG PATH i2c_master_byte_ctrl.v
|
||||
add_fileset_file i2c_master_bit_ctrl.v VERILOG PATH i2c_master_bit_ctrl.v
|
||||
add_fileset_file timescale.v VERILOG PATH timescale.v
|
||||
|
||||
|
||||
#
|
||||
# parameters
|
||||
#
|
||||
|
||||
|
||||
#
|
||||
# display items
|
||||
#
|
||||
|
||||
|
||||
#
|
||||
# connection point clock
|
||||
#
|
||||
add_interface clock clock end
|
||||
set_interface_property clock clockRate 0
|
||||
set_interface_property clock ENABLED true
|
||||
set_interface_property clock EXPORT_OF ""
|
||||
set_interface_property clock PORT_NAME_MAP ""
|
||||
set_interface_property clock CMSIS_SVD_VARIABLES ""
|
||||
set_interface_property clock SVD_ADDRESS_GROUP ""
|
||||
|
||||
add_interface_port clock wb_clk_i clk Input 1
|
||||
|
||||
|
||||
#
|
||||
# connection point clock_reset
|
||||
#
|
||||
add_interface clock_reset reset end
|
||||
set_interface_property clock_reset associatedClock clock
|
||||
set_interface_property clock_reset synchronousEdges DEASSERT
|
||||
set_interface_property clock_reset ENABLED true
|
||||
set_interface_property clock_reset EXPORT_OF ""
|
||||
set_interface_property clock_reset PORT_NAME_MAP ""
|
||||
set_interface_property clock_reset CMSIS_SVD_VARIABLES ""
|
||||
set_interface_property clock_reset SVD_ADDRESS_GROUP ""
|
||||
|
||||
add_interface_port clock_reset wb_rst_i reset Input 1
|
||||
|
||||
|
||||
#
|
||||
# connection point export
|
||||
#
|
||||
add_interface export conduit end
|
||||
set_interface_property export associatedClock ""
|
||||
set_interface_property export associatedReset ""
|
||||
set_interface_property export ENABLED true
|
||||
set_interface_property export EXPORT_OF ""
|
||||
set_interface_property export PORT_NAME_MAP ""
|
||||
set_interface_property export CMSIS_SVD_VARIABLES ""
|
||||
set_interface_property export SVD_ADDRESS_GROUP ""
|
||||
|
||||
add_interface_port export scl_pad_io export Bidir 1
|
||||
add_interface_port export sda_pad_io export Bidir 1
|
||||
|
||||
|
||||
#
|
||||
# connection point avalon_slave_0
|
||||
#
|
||||
add_interface avalon_slave_0 avalon end
|
||||
set_interface_property avalon_slave_0 addressAlignment NATIVE
|
||||
set_interface_property avalon_slave_0 addressUnits WORDS
|
||||
set_interface_property avalon_slave_0 associatedClock clock
|
||||
set_interface_property avalon_slave_0 associatedReset clock_reset
|
||||
set_interface_property avalon_slave_0 bitsPerSymbol 8
|
||||
set_interface_property avalon_slave_0 burstOnBurstBoundariesOnly false
|
||||
set_interface_property avalon_slave_0 burstcountUnits WORDS
|
||||
set_interface_property avalon_slave_0 explicitAddressSpan 0
|
||||
set_interface_property avalon_slave_0 holdTime 0
|
||||
set_interface_property avalon_slave_0 linewrapBursts false
|
||||
set_interface_property avalon_slave_0 maximumPendingReadTransactions 0
|
||||
set_interface_property avalon_slave_0 readLatency 0
|
||||
set_interface_property avalon_slave_0 readWaitTime 1
|
||||
set_interface_property avalon_slave_0 setupTime 0
|
||||
set_interface_property avalon_slave_0 timingUnits Cycles
|
||||
set_interface_property avalon_slave_0 writeWaitTime 0
|
||||
set_interface_property avalon_slave_0 ENABLED true
|
||||
set_interface_property avalon_slave_0 EXPORT_OF ""
|
||||
set_interface_property avalon_slave_0 PORT_NAME_MAP ""
|
||||
set_interface_property avalon_slave_0 CMSIS_SVD_VARIABLES ""
|
||||
set_interface_property avalon_slave_0 SVD_ADDRESS_GROUP ""
|
||||
|
||||
add_interface_port avalon_slave_0 wb_adr_i address Input 3
|
||||
add_interface_port avalon_slave_0 wb_dat_i writedata Input 8
|
||||
add_interface_port avalon_slave_0 wb_dat_o readdata Output 8
|
||||
add_interface_port avalon_slave_0 wb_we_i write Input 1
|
||||
add_interface_port avalon_slave_0 wb_stb_i chipselect Input 1
|
||||
add_interface_port avalon_slave_0 wb_ack_o waitrequest_n Output 1
|
||||
set_interface_assignment avalon_slave_0 embeddedsw.configuration.isFlash 0
|
||||
set_interface_assignment avalon_slave_0 embeddedsw.configuration.isMemoryDevice 0
|
||||
set_interface_assignment avalon_slave_0 embeddedsw.configuration.isNonVolatileStorage 0
|
||||
set_interface_assignment avalon_slave_0 embeddedsw.configuration.isPrintableDevice 0
|
||||
|
||||
|
||||
#
|
||||
# connection point interrupt_sender
|
||||
#
|
||||
add_interface interrupt_sender interrupt end
|
||||
set_interface_property interrupt_sender associatedAddressablePoint avalon_slave_0
|
||||
set_interface_property interrupt_sender associatedClock clock
|
||||
set_interface_property interrupt_sender associatedReset clock_reset
|
||||
set_interface_property interrupt_sender ENABLED true
|
||||
set_interface_property interrupt_sender EXPORT_OF ""
|
||||
set_interface_property interrupt_sender PORT_NAME_MAP ""
|
||||
set_interface_property interrupt_sender CMSIS_SVD_VARIABLES ""
|
||||
set_interface_property interrupt_sender SVD_ADDRESS_GROUP ""
|
||||
|
||||
add_interface_port interrupt_sender wb_inta_o irq Output 1
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
#
|
||||
# opencores_i2c_sw.tcl
|
||||
#
|
||||
|
||||
# Create a new driver
|
||||
create_driver i2c_opencores_driver
|
||||
|
||||
# Associate it with some hardware known as "opencores_i2c"
|
||||
set_sw_property hw_class_name i2c_opencores
|
||||
|
||||
# The version of this driver
|
||||
set_sw_property version 11.0
|
||||
|
||||
# This driver may be incompatible with versions of hardware less
|
||||
# than specified below. Updates to hardware and device drivers
|
||||
# rendering the driver incompatible with older versions of
|
||||
# hardware are noted with this property assignment.
|
||||
#
|
||||
# Multiple-Version compatibility was introduced in version 7.1;
|
||||
# prior versions are therefore excluded.
|
||||
set_sw_property min_compatible_hw_version 7.1
|
||||
|
||||
# Initialize the driver in alt_sys_init()
|
||||
set_sw_property auto_initialize true
|
||||
|
||||
# Location in generated BSP that above sources will be copied into
|
||||
set_sw_property bsp_subdirectory drivers
|
||||
|
||||
|
||||
# Interrupt properties:
|
||||
# This peripheral has an IRQ output but the driver doesn't currently
|
||||
# have any interrupt service routine. To ensure that the BSP tools
|
||||
# do not otherwise limit the BSP functionality for users of the
|
||||
# Nios II enhanced interrupt port, these settings advertise
|
||||
# compliance with both legacy and enhanced interrupt APIs, and to state
|
||||
# that any driver ISR supports preemption. If an interrupt handler
|
||||
# is added to this driver, these must be re-examined for validity.
|
||||
set_sw_property isr_preemption_supported true
|
||||
set_sw_property supported_interrupt_apis "legacy_interrupt_api enhanced_interrupt_api"
|
||||
|
||||
#
|
||||
# Source file listings...
|
||||
#
|
||||
|
||||
# C/C++ source files
|
||||
add_sw_property c_source HAL/src/i2c_opencores.c
|
||||
|
||||
# Include files
|
||||
add_sw_property include_source HAL/inc/i2c_opencores.h
|
||||
add_sw_property include_source inc/i2c_opencores_regs.h
|
||||
|
||||
# This driver supports HAL & UCOSII BSP (OS) types
|
||||
add_sw_property supported_bsp_type HAL
|
||||
add_sw_property supported_bsp_type UCOSII
|
||||
|
||||
# End of file
|
||||
@@ -0,0 +1,77 @@
|
||||
|
||||
|
||||
#ifndef __I2C_OPENCORES_REGS_H__
|
||||
#define __I2C_OPENCORES_REGS_H__
|
||||
|
||||
#include <io.h>
|
||||
/* prescal clock/(5*desired_SCL) */
|
||||
/* all registers are 8 bits wide but on 32 bit address boundaries.*/
|
||||
/* reg definitions take from i2c_specs.pdf in the docs folder */
|
||||
|
||||
#define IOADDR_I2C_OPENCORES_PRERLO(base) __IO_CALC_ADDRESS_NATIVE(base, 0)
|
||||
#define IORD_I2C_OPENCORES_PRERLO(base) IORD(base, 0)
|
||||
#define IOWR_I2C_OPENCORES_PRERLO(base, data) IOWR(base, 0, data)
|
||||
|
||||
|
||||
#define IOADDR_I2C_OPENCORES_PRERHI(base) __IO_CALC_ADDRESS_NATIVE(base, 0)
|
||||
#define IORD_I2C_OPENCORES_PRERHI(base) IORD(base, 1)
|
||||
#define IOWR_I2C_OPENCORES_PRERHI(base, data) IOWR(base, 1, data)
|
||||
|
||||
|
||||
#define IOADDR_I2C_OPENCORES_CTR(base) __IO_CALC_ADDRESS_NATIVE(base, 2)
|
||||
#define IORD_I2C_OPENCORES_CTR(base) IORD(base, 2)
|
||||
#define IOWR_I2C_OPENCORES_CTR(base, data) IOWR(base, 2, data)
|
||||
/* bit definitions*/
|
||||
#define I2C_OPENCORES_CTR_EN_MSK (0x80)
|
||||
#define I2C_OPENCORES_CTR_EN_OFST (7)
|
||||
#define I2C_OPENCORES_CTR_IEN_MSK (0x40)
|
||||
#define I2C_OPENCORES_CTR_IEN_OFST (6)
|
||||
|
||||
|
||||
#define IOADDR_I2C_OPENCORES_TXR(base) __IO_CALC_ADDRESS_NATIVE(base, 3)
|
||||
#define IOWR_I2C_OPENCORES_TXR(base, data) IOWR(base, 3, data)
|
||||
/* bit definitions*/
|
||||
#define I2C_OPENCORES_TXR_RD_MSK (0x1)
|
||||
#define I2C_OPENCORES_TXR_RD_OFST (0)
|
||||
#define I2C_OPENCORES_TXR_WR_MSK (0x0)
|
||||
#define I2C_OPENCORES_TXR_WR_OFST (0)
|
||||
|
||||
|
||||
#define IOADDR_I2C_OPENCORES_RXR(base) __IO_CALC_ADDRESS_NATIVE(base, 3)
|
||||
#define IORD_I2C_OPENCORES_RXR(base) IORD(base, 3)
|
||||
|
||||
|
||||
#define IOADDR_I2C_OPENCORES_CR(base) __IO_CALC_ADDRESS_NATIVE(base, 4)
|
||||
#define IOWR_I2C_OPENCORES_CR(base, data) IOWR(base, 4, data)
|
||||
/* bit definitions*/
|
||||
#define I2C_OPENCORES_CR_STA_MSK (0x80)
|
||||
#define I2C_OPENCORES_CR_STA_OFST (7)
|
||||
#define I2C_OPENCORES_CR_STO_MSK (0x40)
|
||||
#define I2C_OPENCORES_CR_STO_OFST (6)
|
||||
#define I2C_OPENCORES_CR_RD_MSK (0x20)
|
||||
#define I2C_OPENCORES_CR_RD_OFST (5)
|
||||
#define I2C_OPENCORES_CR_WR_MSK (0x10)
|
||||
#define I2C_OPENCORES_CR_WR_OFST (4)
|
||||
#define I2C_OPENCORES_CR_NACK_MSK (0x8)
|
||||
#define I2C_OPENCORES_CR_NACK_OFST (3)
|
||||
#define I2C_OPENCORES_CR_SPIM_MSK (0x4)
|
||||
#define I2C_OPENCORES_CR_SPIM_OFST (2)
|
||||
#define I2C_OPENCORES_CR_IACK_MSK (0x1)
|
||||
#define I2C_OPENCORES_CR_IACK_OFST (0)
|
||||
|
||||
|
||||
#define IOADDR_I2C_OPENCORES_SR(base) __IO_CALC_ADDRESS_NATIVE(base, 4)
|
||||
#define IORD_I2C_OPENCORES_SR(base) IORD(base, 4)
|
||||
/* bit definitions*/
|
||||
#define I2C_OPENCORES_SR_RXNACK_MSK (0x80)
|
||||
#define I2C_OPENCORES_SR_RXNACK_OFST (7)
|
||||
#define I2C_OPENCORES_SR_BUSY_MSK (0x40)
|
||||
#define I2C_OPENCORES_SR_BUSY_OFST (6)
|
||||
#define I2C_OPENCORES_SR_AL_MSK (0x20)
|
||||
#define I2C_OPENCORES_SR_AL_OFST (5)
|
||||
#define I2C_OPENCORES_SR_TIP_MSK (0x2)
|
||||
#define I2C_OPENCORES_SR_TIP_OFST (1)
|
||||
#define I2C_OPENCORES_SR_IF_MSK (0x1)
|
||||
#define I2C_OPENCORES_SR_IF_OFST (0)
|
||||
|
||||
#endif /* __I2C_OPENCORES_REGS_H__ */
|
||||
@@ -0,0 +1,2 @@
|
||||
`timescale 1ns / 10ps
|
||||
|
||||
Reference in new issue
Block a user