/* Write a data buffer to the slave, when the master have obtained control of the bus, and waiting for all bus transmiton complete.(Write Buffer Step2) 
This function is always used in thread mode. */
unsigned long xI2CMasterWriteBufS2(unsigned long ulBase, unsigned char *pucDataBuf, unsigned long ulLen, xtBoolean bEndTransmition)
/* Write a data buffer to the slave, when the master have obtained control of the bus, and waiting for all bus transmiton complete.(Write Buffer Step2) 
This function is always used in thread mode. */
unsigned long xI2CMasterWriteBufS2(unsigned long ulBase, unsigned char *pucDataBuf, unsigned long ulLen, xtBoolean bEndTransmition)
{
    unsigned long i;
    unsigned long ulStatus;
    xASSERT((ulBase == I2C0_BASE));
    xASSERT(pucDataBuf);
    for(i = 0; i < ulLen - 1; i++)
    {
        ulStatus = I2CByteSend(ulBase, *pucDataBuf++);
        if(!(ulStatus == I2C_I2STAT_M_TX_DAT_ACK))
        {
            I2CStopSend(ulBase);
            return i;
        }
    }
    ulStatus = I2CByteSend(ulBase, *pucDataBuf);
    if(!(ulStatus == I2C_I2STAT_M_TX_DAT_ACK))
    {
        I2CStopSend(ulBase);
        return i;
    }
    if(bEndTransmition)
    {
        I2CStopSend(ulBase);
    }
    return ulLen;
}