Ejemplo n.º 1
0
/*
** ISR to handler i2c interrupts
*/
void I2CCodecIsr(void)
{
    unsigned int status;

    status = I2CMasterIntStatus(SOC_I2C_1_REGS);
    I2CMasterIntClearEx(SOC_I2C_1_REGS,
                        (status & ~(I2C_INT_RECV_READY | I2C_INT_TRANSMIT_READY)));

    if (status & I2C_INT_TRANSMIT_READY)
    {
         /* Put data to data transmit register of i2c */
         I2CMasterDataPut(SOC_I2C_1_REGS, slaveData[dataIdx]);
         I2CMasterIntClearEx(SOC_I2C_1_REGS, I2C_INT_TRANSMIT_READY);
         dataIdx++;
 
         if(dataMax == dataIdx)
         {
              I2CMasterIntDisableEx(SOC_I2C_1_REGS, I2C_INT_TRANSMIT_READY);
         }
    }

    if(status & I2C_INT_RECV_READY)
    {
         /* Receive data from data receive register */
         slaveData[dataIdx] = I2CMasterDataGet(SOC_I2C_1_REGS);
         I2CMasterIntClearEx(SOC_I2C_1_REGS, I2C_INT_RECV_READY);
         dataIdx++;
 
         if(dataMax == dataIdx)
         {
              I2CMasterIntDisableEx(SOC_I2C_1_REGS, I2C_INT_RECV_READY);

              /* Generate a STOP */
              I2CMasterStop(SOC_I2C_1_REGS);
         }
    }

    if (status & I2C_INT_STOP_CONDITION)
    {
         /* Disable transmit data ready and receive data read interupt */
         I2CMasterIntDisableEx(SOC_I2C_1_REGS, I2C_INT_TRANSMIT_READY |
                                               I2C_INT_STOP_CONDITION |
                                               I2C_INT_RECV_READY);
         txCompFlag = 0;
    }

    if(status & I2C_INT_NO_ACK)
    {
         I2CMasterIntDisableEx(SOC_I2C_1_REGS, I2C_INT_TRANSMIT_READY |
                                                 I2C_INT_RECV_READY |
                                                 I2C_INT_NO_ACK |
                                                 I2C_INT_STOP_CONDITION);
         /* Generate a STOP */
         I2CMasterStop(SOC_I2C_1_REGS);

         txCompFlag = 0;
    }
}
Ejemplo n.º 2
0
/**
 * \brief   This function reads data from EEPROM.
 *
 * \param   data    Address where data is to be read.
 * \param   length  Length of data to be read
 * \param   offset  Address of the byte from which data to be read.
 *
 * \return  None.
 *
 * \note    This muxing depends on the profile in which the EVM is configured.
 *          EEPROMI2CSetUp Shall be called Before this API is used
 */
void EEPROMI2CRead(unsigned char *data, unsigned int length,
                   unsigned short offset)
{
    unsigned int idx = 0;

    /* First send the register offset - TX operation */
    I2CSetDataCount(I2C_BASE_ADDR, 2);

    StatusClear();

    I2CMasterControl(I2C_BASE_ADDR, I2C_CFG_MST_TX);

    I2CMasterStart(I2C_BASE_ADDR);

    /* Wait for the START to actually occir on the bus */
    while (0 == I2CMasterBusBusy(I2C_BASE_ADDR));

    I2CMasterDataPut(I2C_BASE_ADDR, (unsigned char)((offset >> 8) & 0xFF));

    /* Wait for the Tx register to be empty */
    while (0 == I2CMasterIntRawStatusEx(I2C_BASE_ADDR,
                                        I2C_INT_TRANSMIT_READY));

    /* Push offset out and tell CPLD from where we intend to read the data */
    I2CMasterDataPut(I2C_BASE_ADDR, (unsigned char)(offset & 0xFF));

    I2CMasterIntClearEx(I2C_BASE_ADDR, I2C_INT_TRANSMIT_READY);

    while(0 == (I2CMasterIntRawStatus(I2C_BASE_ADDR) & I2C_INT_ADRR_READY_ACESS));

    StatusClear();

    I2CSetDataCount(I2C_BASE_ADDR, length);

    /* Now that we have sent the register offset, start a RX operation*/
    I2CMasterControl(I2C_BASE_ADDR, I2C_CFG_MST_RX);

    /* Repeated start condition */
    I2CMasterStart(I2C_BASE_ADDR);

    while (length--)
    {
        while (0 == I2CMasterIntRawStatusEx(I2C_BASE_ADDR,
                                            I2C_INT_RECV_READY));
        data[idx++] = (unsigned char)I2CMasterDataGet(I2C_BASE_ADDR);
        I2CMasterIntClearEx(I2C_BASE_ADDR, I2C_INT_RECV_READY);
    }

    I2CMasterStop(I2C_BASE_ADDR);

    while(0 == (I2CMasterIntRawStatus(I2C_BASE_ADDR) & I2C_INT_STOP_CONDITION));

    I2CMasterIntClearEx(I2C_BASE_ADDR, I2C_INT_STOP_CONDITION);
}
Ejemplo n.º 3
0
/*
** This function will read/write data from/to PMIC through I2C bus.
*/
void I2CPMICInteract(void)
{
    volatile unsigned int intCode = 0;

    /* Get interrupt vector code */
    intCode = I2CInterruptVectorGet(SOC_I2C_0_REGS);

    while(intCode!=0)
    {
         /* Clear status of interrupt */
         IntSystemStatusClear(SYS_INT_I2CINT0);

         if (intCode == I2C_INTCODE_TX_READY)
         {
              /* Put data to data transmit register of i2c */
              I2CMasterDataPut(SOC_I2C_0_REGS, dataToPmic[count++]);
         }  

         if(intCode == I2C_INTCODE_RX_READY)
         {
              /* Receive data from data receive register */
              dataFromSlave[rCount] = I2CMasterDataGet(SOC_I2C_0_REGS);
         }        
   
         if (intCode == I2C_INTCODE_STOP)
         {
	      /* Disable transmit data ready and receive data read interupt */
              I2CMasterIntDisableEx(SOC_I2C_0_REGS,I2C_INT_TRANSMIT_READY|
                                                       I2C_INT_DATA_READY);
              flag = 0;
         }

         if (intCode == I2C_INTCODE_NACK)
         {
             I2CMasterIntDisableEx(SOC_I2C_0_REGS, I2C_INT_TRANSMIT_READY |
                                                   I2C_INT_DATA_READY |
                                                   I2C_INT_NO_ACK |
                                                   I2C_INT_STOP_CONDITION);
             /* Generate a STOP */
             I2CMasterStop(SOC_I2C_0_REGS);

             I2CStatusClear(SOC_I2C_0_REGS, I2C_CLEAR_STOP_CONDITION);

             /* Clear interrupt at AINTC, if we missed any, in case of error */

             flag = 0;
         }


         intCode = I2CInterruptVectorGet(SOC_I2C_0_REGS);
    }
}
Ejemplo n.º 4
0
/*
** I2C Interrupt Service Routine. This function will read and write
** data through I2C bus.
*/
void I2CIsr(new_twi* TwiStruct)
{
    unsigned int status = 0;

    /* Get only Enabled interrupt status */
    status = I2CMasterIntStatus(TwiStruct->BaseAddr);

    /*
    ** Clear all enabled interrupt status except receive ready and
    ** transmit ready interrupt status
    */
    I2CMasterIntClearEx(TwiStruct->BaseAddr,
	                    (status & ~(I2C_INT_RECV_READY | I2C_INT_TRANSMIT_READY | I2C_INT_NO_ACK)));

    if(status & I2C_INT_RECV_READY)
    {
         /* Receive data from data receive register */
    	TwiStruct->RxBuff[TwiStruct->rCount++] = I2CMasterDataGet(TwiStruct->BaseAddr);

	/* Clear receive ready interrupt status */
        I2CMasterIntClearEx(TwiStruct->BaseAddr,  I2C_INT_RECV_READY);

         if(TwiStruct->rCount == TwiStruct->numOfBytes)
         {
              /* Disable the receive ready interrupt */
              I2CMasterIntDisableEx(TwiStruct->BaseAddr, I2C_INT_RECV_READY);
              /* Generate a STOP */
              I2CMasterStop(TwiStruct->BaseAddr);

         }
    }

    if (status & I2C_INT_TRANSMIT_READY)
    {
        /* Put data to data transmit register of i2c */
        I2CMasterDataPut(TwiStruct->BaseAddr, TwiStruct->TxBuff[TwiStruct->tCount++]);

        /* Clear Transmit interrupt status */
	I2CMasterIntClearEx(TwiStruct->BaseAddr, I2C_INT_TRANSMIT_READY);

         if(TwiStruct->tCount == TwiStruct->numOfBytes)
         {
              /* Disable the transmit ready interrupt */
              I2CMasterIntDisableEx(TwiStruct->BaseAddr, I2C_INT_TRANSMIT_READY);
         }

    }

    if (status & I2C_INT_STOP_CONDITION)
    {
      	 /* Disable transmit data ready and receive data read interupt */
         I2CMasterIntDisableEx(TwiStruct->BaseAddr, I2C_INT_TRANSMIT_READY |
                                               I2C_INT_RECV_READY     |
					       I2C_INT_STOP_CONDITION);
         TwiStruct->flag = 0;
    }

    if(status & I2C_INT_NO_ACK)
    {
         I2CMasterIntDisableEx(TwiStruct->BaseAddr, I2C_INT_TRANSMIT_READY  |
                                               I2C_INT_RECV_READY      |
                                               I2C_INT_NO_ACK          |
                                               I2C_INT_STOP_CONDITION);
         /* Generate a STOP */
         I2CMasterStop(TwiStruct->BaseAddr);

         TwiStruct->flag = 0;
         TwiStruct->error_flag = 1;
    }

    //I2CEndOfInterrupt(TwiStruct->BaseAddr, 0);
}
Ejemplo n.º 5
0
/*
** ISR to handler i2c interrupts
*/
static void I2C0Isr(void)
{
    volatile unsigned int intCode = 0;

    /* Get interrupt vector code */
    intCode = I2CInterruptVectorGet(SOC_I2C_0_REGS);

    while(intCode!=0)
    {
         /* Clear status of interrupt */
#ifdef _TMS320C6X
    	IntEventClear(SYS_INT_I2C0_INT);
#else
        IntSystemStatusClear(15);
#endif

         if (intCode == I2C_INTCODE_TX_READY)
         {
              I2CMasterDataPut(SOC_I2C_0_REGS, slaveData[dataIdx]);
              dataIdx++;
         }

         if(intCode == I2C_INTCODE_RX_READY)
         {
              slaveData[dataIdx] = I2CMasterDataGet(SOC_I2C_0_REGS);
              dataIdx++;
         }

         if (intCode == I2C_INTCODE_STOP)
         {
             I2CMasterIntDisableEx(SOC_I2C_0_REGS, I2C_INT_TRANSMIT_READY |
                                                   I2C_INT_DATA_READY |
                                                   I2C_INT_NO_ACK |
                                                   I2C_INT_STOP_CONDITION);
              txCompFlag = 0;
         }

         if (intCode == I2C_INTCODE_NACK)
         {
             I2CMasterIntDisableEx(SOC_I2C_0_REGS, I2C_INT_TRANSMIT_READY |
                                                   I2C_INT_DATA_READY |
                                                   I2C_INT_NO_ACK |
                                                   I2C_INT_STOP_CONDITION);
             /* Generate a STOP */
             I2CMasterStop(SOC_I2C_0_REGS);

             I2CStatusClear(SOC_I2C_0_REGS, I2C_CLEAR_STOP_CONDITION);

             /* Clear interrupt at AINTC, if we missed any, in case of error */ 
#ifdef _TMS320C6X
             IntEventClear(SYS_INT_I2C0_INT);
#else
             IntSystemStatusClear(15);
#endif

             txCompFlag = 0;
         }

         if (I2CMasterIntStatus(SOC_I2C_0_REGS) & I2C_ICSTR_NACKSNT)
         {
             I2CMasterIntDisableEx(SOC_I2C_0_REGS, I2C_INT_TRANSMIT_READY |
                                                   I2C_INT_DATA_READY |
                                                   I2C_INT_NO_ACK |
                                                   I2C_INT_STOP_CONDITION);

             /* Generate a STOP */
             I2CMasterStop(SOC_I2C_0_REGS);
 
             I2CStatusClear(SOC_I2C_0_REGS, (I2C_CLEAR_NO_ACK_SENT |
                                             I2C_CLEAR_STOP_CONDITION));

             /* Clear interrupt at AINTC, if we missed any, in case of error */ 
#ifdef _TMS320C6X
             IntEventClear(SYS_INT_I2C0_INT);
#else
             IntSystemStatusClear(15);
#endif

             txCompFlag = 0;
         }

         intCode = I2CInterruptVectorGet(SOC_I2C_0_REGS);
    }
}
Ejemplo n.º 6
0
/*
** I2C Interrupt Service Routine. This function will read and write
** data through I2C bus. 
*/
static void mpu6050_isr(int irqno, void* param)
{
    unsigned int status = 0;

    /* Get only Enabled interrupt status */
    status = I2CMasterIntStatus(I2C0_BASE);

    /* 
    ** Clear all enabled interrupt status except receive ready and
    ** transmit ready interrupt status 
    */
    I2CMasterIntClearEx(I2C0_BASE,
                        (status & ~(I2C_INT_RECV_READY | I2C_INT_TRANSMIT_READY)));
                        
    if(status & I2C_INT_RECV_READY)
    {
         /* Receive data from data receive register */
        dataFromSlave[rCount++] = I2CMasterDataGet(I2C0_BASE);

    /* Clear receive ready interrupt status */  
        I2CMasterIntClearEx(I2C0_BASE,  I2C_INT_RECV_READY);
        
         if(rCount == numOfBytes)
         {
              /* Disable the receive ready interrupt */
              I2CMasterIntDisableEx(I2C0_BASE, I2C_INT_RECV_READY);
              /* Generate a STOP */
              I2CMasterStop(I2C0_BASE);
              
         }
    }

    if (status & I2C_INT_TRANSMIT_READY)
    {
        /* Put data to data transmit register of i2c */
        I2CMasterDataPut(I2C0_BASE, dataToSlave[tCount++]);

        /* Clear Transmit interrupt status */
    I2CMasterIntClearEx(I2C0_BASE, I2C_INT_TRANSMIT_READY);         
                        
         if(tCount == numOfBytes)
         {
              /* Disable the transmit ready interrupt */
              I2CMasterIntDisableEx(I2C0_BASE, I2C_INT_TRANSMIT_READY);
         }

    }
        
    if (status & I2C_INT_STOP_CONDITION)
    {
         /* Disable transmit data ready and receive data read interupt */
         I2CMasterIntDisableEx(I2C0_BASE, I2C_INT_TRANSMIT_READY |
                                               I2C_INT_RECV_READY     |
                           I2C_INT_STOP_CONDITION);
         flag = 0;
    }
   
    if(status & I2C_INT_NO_ACK)
    {
         I2CMasterIntDisableEx(I2C0_BASE, I2C_INT_TRANSMIT_READY  |
                                               I2C_INT_RECV_READY      |
                                               I2C_INT_NO_ACK          |
                                               I2C_INT_STOP_CONDITION);
         /* Generate a STOP */
         I2CMasterStop(I2C0_BASE);

         flag = 0;
    }
}
void I2C_0_ISR(void)
{
	unsigned int status = 0;

	/* interrupt status */
	status = I2CMasterIntStatus(SOC_I2C_0_REGS);

	if(status & I2C_INT_RECV_READY)
	{
		/* Receive data from data receive register */
		*I2C_0_Buffers.p_Receive = I2CMasterDataGet(SOC_I2C_0_REGS);
		I2C_0_Buffers.p_Receive++;
		I2C_0_Buffers.BytesReceived++;

		/* Clear interrupt flag */
		I2CMasterIntClearEx(SOC_I2C_0_REGS,  I2C_INT_RECV_READY);

		if(I2C_0_Buffers.BytesReceived == I2C_0_Buffers.ReceiveBytes)
		{
			/* Disable the receive ready interrupt */
			I2CMasterIntDisableEx(SOC_I2C_0_REGS, I2C_INT_RECV_READY);
			/* Generate a STOP */
			I2CMasterStop(SOC_I2C_0_REGS);
		}
	}

	if (status & I2C_INT_TRANSMIT_READY)
	{
		/* Put data to data transmit register of i2c */
		I2CMasterDataPut(SOC_I2C_0_REGS, *I2C_0_Buffers.p_Transmit);
		I2C_0_Buffers.p_Transmit++;
		I2C_0_Buffers.BytesTransmitted++;

		/* Clear Transmit interrupt status */
		I2CMasterIntClearEx(SOC_I2C_0_REGS, I2C_INT_TRANSMIT_READY);

		if(I2C_0_Buffers.BytesTransmitted == I2C_0_Buffers.TransmitBytes)
		{
			/* Disable the transmit ready interrupt */
			I2CMasterIntDisableEx(SOC_I2C_0_REGS, I2C_INT_TRANSMIT_READY);

			if(!I2C_0_Buffers.ReceiveBytes)
			{
				/* Generate a STOP */
				I2CMasterStop(SOC_I2C_0_REGS);
			}
		}
	}

	if (status & I2C_INT_STOP_CONDITION)
	{
		/* Disable transmit data ready and receive data read interupt */
		I2CMasterIntDisableEx(SOC_I2C_0_REGS, I2C_INT_TRANSMIT_READY | I2C_INT_RECV_READY | I2C_INT_STOP_CONDITION);

		/* Clear interrupt flag */
		I2CMasterIntClearEx(SOC_I2C_0_REGS,  I2C_INT_STOP_CONDITION);

		I2C_SetFailFlag0();
	}

	if(status & I2C_INT_NO_ACK)
	{
		I2CMasterIntDisableEx(SOC_I2C_0_REGS, I2C_INT_TRANSMIT_READY  | I2C_INT_RECV_READY | I2C_INT_NO_ACK | I2C_INT_STOP_CONDITION);

		/* Generate a STOP */
		I2CMasterStop(SOC_I2C_0_REGS);

		/* Clear interrupt flag */
		I2CMasterIntClearEx(SOC_I2C_0_REGS,  I2C_INT_NO_ACK);

		I2C_SetFailFlag0();
	}
}