Ejemplo n.º 1
0
UInt32 getBufferFromI2C0(UInt8 addr, UInt8 *buffer, UInt32 len)
{
    UInt32 i;
    UInt8 status;
    UInt8 *ptr;

    ptr = buffer;
    if( i2c0_start()!=I2C_OK)
    {
        //DebugPrintf("GetBufferFromI2C0.i2c0_start I2C_ERROR\r\n");
        //i2c0_stop();
        return I2C_ERROR;
    }

    addr = addr|1;
    while( i2c0_write(addr) == I2C_BUSY);

    for(i=0;i<len;i++)
    {
        while(1)
        {
            GET_I2C_STATUS();

            /*
             * SLA+R transmitted, ACK received or
             * SLA+R transmitted, ACK not received
             * data byte received in master mode, ACK transmitted
             */
            if((status == 0x40 ) || (status == 0x48 ) || (status == 0x50 ))
            {
                if(i==len-1)
                {
                        SEND_NACK();
                }
                else
                {
                        SEND_ACK();
                }

                while(i2c0_read(ptr)==I2C_EMPTY);

                ptr++;
                break;

            }
            else if(status != 0xf8 )
            {
                i2c0_stop();
                //DebugPrintf("GetBufferFromI2C0 I2C_ERROR\r\n");
                return I2C_ERROR;
            }

        }//while(1)
    }//for

    i2c0_stop();

    return I2C_OK;
}
Ejemplo n.º 2
0
/*!
   Receive from appointed slave with sending firstly, and with stop operation after sending.
   start-slave-data(w)-...-stop-start-slave-data(r)-...-stop
  */
static RET_CODE i2c_jazz_std_read(lld_i2c_t *p_lld,
                                  u8 slv_addr,
                                  u8 *p_buf,
                                  u32 wlen,
                                  u32 rlen,
                                  u32 param)
{

    ////OS_PRINTF(" i2c_jazz_std_read  1111 %d %s\n",__LINE__, __FILE__);

    i2c_ctrller_jazz_priv_t *p_priv = (i2c_ctrller_jazz_priv_t *)p_lld->p_priv;
    u8 times = 0;

    i2c_jazz_pinmux(p_priv->i2c_id);
    if(wlen == 0)
    {
        return i2c0_read(p_lld, slv_addr, p_buf, rlen);
    }
    ////OS_PRINTF(" i2c_jazz_std_read  1111 %d %s\n",__LINE__, __FILE__);

    for(times = 0; times < 3; times++)
    {
        if(SUCCESS != i2c0_write(p_lld, slv_addr, p_buf, wlen))
        {
            ////OS_PRINTF(" i2c_jazz_std_read  1111 %d %s\n",__LINE__, __FILE__);

            return ERR_HARDWARE;
        }
        ////OS_PRINTF(" i2c_jazz_std_read  1111 %d %s\n",__LINE__, __FILE__);

        if(SUCCESS != i2c0_read_no_stop(p_priv->i2c_id, slv_addr, p_buf, rlen))
        {
            i2c0_fatal_err_restore(p_priv->i2c_id, p_priv->i2c_clk);
            continue;
        }  ////OS_PRINTF(" i2c_jazz_std_read  1111 %d %s\n",__LINE__, __FILE__);


        if(SUCCESS != i2c0_stop_retry(p_priv->i2c_id, 3))
        {
            i2c0_fatal_err_restore(p_priv->i2c_id, p_priv->i2c_clk);
            continue;
        }

        break;
    }
    ////OS_PRINTF(" i2c_jazz_std_read  1111 %d %s\n",__LINE__, __FILE__);

    if(times == 3)
    {
        return ERR_HARDWARE;
    }
    ////OS_PRINTF(" i2c_jazz_std_read  1111 %d %s\n",__LINE__, __FILE__);
    // Todo: fix me! control reaches end of non-void function
    return SUCCESS;
}
Ejemplo n.º 3
0
UInt32 private_i2c0_send(UInt8 data)
{
    UInt32 cnt = I2C_CNT;
    while( i2c0_write(data) == I2C_BUSY)
    {
        cnt--;
        waitUs(1);
        if(cnt==0)
        {
            return I2C_TIMEOUT;
        }
    }
    return 0;
}
Ejemplo n.º 4
0
void i2c0_write_wait(UInt8 data)
{
    UInt32 cnt = I2C_CNT;
    while( i2c0_write(data) == I2C_BUSY)
    {
        cnt--;
         waitUs(1);
        if(cnt==0)
        {
            //DebugPrintf("i2c0_write_wait timeout\r\n");
            return;
        }
    }

    i2c0_wait_after_write();
}