/******************************************************************************* * mvTwsiStopBitSet - Set stop bit on the bus * * DESCRIPTION: * This routine set the stop bit on the TWSI bus. * The function then wait for the stop bit to be cleared by the HW. * Finally the function checks for status of 0xF8. * * INPUT: * chanNum - TWSI channel * * OUTPUT: * None. * * RETURN: * MV_TRUE is stop bit was set successfuly on the bus. * *******************************************************************************/ MV_STATUS mvTwsiStopBitSet(MV_U8 chanNum) { MV_U32 timeout, temp; /* Generate stop bit */ temp = MV_REG_READ(TWSI_CONTROL_REG(chanNum)); MV_REG_WRITE(TWSI_CONTROL_REG(chanNum), temp | TWSI_CONTROL_STOP_BIT); twsiIntFlgClr(chanNum); /* wait for stop bit to come down */ timeout = 0; while( ((MV_REG_READ(TWSI_CONTROL_REG(chanNum)) & TWSI_CONTROL_STOP_BIT) != 0) && (timeout++ < TWSI_TIMEOUT_VALUE)); /* check for timeout */ if(MV_TRUE == twsiTimeoutChk(timeout,"TWSI: mvTwsiStopBitSet ERROR - Stop bit TimeOut .\n")) return MV_TIMEOUT; /* check that the stop bit went down */ if((MV_REG_READ(TWSI_CONTROL_REG(chanNum)) & TWSI_CONTROL_STOP_BIT) != 0) { mvOsPrintf("TWSI: mvTwsiStopBitSet ERROR - stop bit didn't went down. \n"); return MV_FAIL; } /* check the status */ temp = twsiStsGet(chanNum); if( temp != TWSI_NO_REL_STS_INT_FLAG_IS_KEPT_0){ mvOsPrintf("TWSI: mvTwsiStopBitSet ERROR - status %x after Stop Bit. \n", temp); return MV_FAIL; } return MV_OK; }
/******************************************************************************* * mvTwsiStopBitSet - Set stop bit on the bus * * DESCRIPTION: * This routine set the stop bit on the TWSI bus. * The function then wait for the stop bit to be cleared by the HW. * Finally the function checks for status of 0xF8. * * INPUT: * chanNum - TWSI channel. * * OUTPUT: * None. * * RETURN: * MV_TRUE is stop bit was set successfuly on the bus. * *******************************************************************************/ MV_STATUS mvTwsiStopBitSet(MV_U8 chanNum) { MV_U32 timeout, temp; /* Generate stop bit */ temp = MV_REG_READ(TWSI_CONTROL_REG(chanNum)); MV_REG_WRITE(TWSI_CONTROL_REG(chanNum), temp | TWSI_CONTROL_STOP_BIT); twsiIntFlgClr(chanNum); /* wait for stop bit to come down */ timeout = 0; while (((MV_REG_READ(TWSI_CONTROL_REG(chanNum)) & TWSI_CONTROL_STOP_BIT) != 0) && (timeout++ < TWSI_TIMEOUT_VALUE)) ; /* check for timeout */ if (MV_TRUE == twsiTimeoutChk(timeout, "TWSI: mvTwsiStopBitSet ERROR - Stop bit TimeOut .\n")) return MV_TIMEOUT; /* check that the stop bit went down */ if ((MV_REG_READ(TWSI_CONTROL_REG(chanNum)) & TWSI_CONTROL_STOP_BIT) != 0) return MV_FAIL; /* check the status */ temp = twsiStsGet(chanNum); if ((TWSI_M_LOST_ARB_DUR_AD_OR_DATA_TRA == temp) || (TWSI_M_LOST_ARB_DUR_AD_TRA_GNL_CALL_AD_REC_ACK_TRA == temp)) return MV_TWSI_RETRY; else if (temp != TWSI_NO_REL_STS_INT_FLAG_IS_KEPT_0) return MV_FAIL; return MV_OK; }
/******************************************************************************* * mvTwsiStartBitSet - Set start bit on the bus * * DESCRIPTION: * This routine sets the start bit on the TWSI bus. * The routine first checks for interrupt flag condition, then it sets * the start bit in the TWSI Control register. * If the interrupt flag condition check previously was set, the function * will clear it. * The function then wait for the start bit to be cleared by the HW. * Then it waits for the interrupt flag to be set and eventually, the * TWSI status is checked to be 0x8 or 0x10(repeated start bit). * * INPUT: * chanNum - TWSI channel. * * OUTPUT: * None. * * RETURN: * MV_OK is start bit was set successfuly on the bus. * MV_FAIL if interrupt flag was set before setting start bit. * *******************************************************************************/ MV_STATUS mvTwsiStartBitSet(MV_U8 chanNum) { MV_BOOL isIntFlag = MV_FALSE; MV_U32 timeout, temp; DB(mvOsPrintf("TWSI: mvTwsiStartBitSet \n")); /* check Int flag */ if (twsiMainIntGet(chanNum)) isIntFlag = MV_TRUE; /* set start Bit */ temp = MV_REG_READ(TWSI_CONTROL_REG(chanNum)); MV_REG_WRITE(TWSI_CONTROL_REG(chanNum), temp | TWSI_CONTROL_START_BIT); /* in case that the int flag was set before i.e. repeated start bit */ if (isIntFlag) { DB(mvOsPrintf("TWSI: mvTwsiStartBitSet repeated start Bit\n")); twsiIntFlgClr(chanNum); } /* wait for interrupt */ timeout = 0; while (!twsiMainIntGet(chanNum) && (timeout++ < TWSI_TIMEOUT_VALUE)) ; /* check for timeout */ if (MV_TRUE == twsiTimeoutChk(timeout, (const MV_8 *)"TWSI: mvTwsiStartBitSet ERROR - Start Clear bit TimeOut .\n")) return MV_TIMEOUT; /* check that start bit went down */ if ((MV_REG_READ(TWSI_CONTROL_REG(chanNum)) & TWSI_CONTROL_START_BIT) != 0) { mvOsPrintf("TWSI: mvTwsiStartBitSet ERROR - start bit didn't went down\n"); return MV_FAIL; } /* check the status */ temp = twsiStsGet(chanNum); if ((TWSI_M_LOST_ARB_DUR_AD_OR_DATA_TRA == temp) || (TWSI_M_LOST_ARB_DUR_AD_TRA_GNL_CALL_AD_REC_ACK_TRA == temp)) { DB(mvOsPrintf("TWSI: Lost Arb, status %x \n", temp)); return MV_RETRY; } else if ((temp != TWSI_START_CON_TRA) && (temp != TWSI_REPEATED_START_CON_TRA)) { mvOsPrintf("TWSI: mvTwsiStartBitSet ERROR - status %x after Set Start Bit. \n", temp); return MV_FAIL; } return MV_OK; }
/******************************************************************************* * mvTwsiStartBitSet - Set start bit on the bus * * DESCRIPTION: * This routine sets the start bit on the TWSI bus. * The routine first checks for interrupt flag condition, then it sets * the start bit in the TWSI Control register. * If the interrupt flag condition check previously was set, the function * will clear it. * The function then wait for the start bit to be cleared by the HW. * Then it waits for the interrupt flag to be set and eventually, the * TWSI status is checked to be 0x8 or 0x10(repeated start bit). * * INPUT: * None. * * OUTPUT: * None. * * RETURN: * MV_OK is start bit was set successfuly on the bus. * MV_FAIL if interrupt flag was set before setting start bit. * *******************************************************************************/ MV_STATUS mvTwsiStartBitSet(MV_VOID) { MV_BOOL isIntFlag = MV_FALSE; MV_U32 timeout, temp; DB(mvOsPrintf("TWSI: mvTwsiStartBitSet \n")); /* check Int flag */ if(twsiMainIntGet()) isIntFlag = MV_TRUE; /* set start Bit */ temp = MV_REG_READ(TWSI_CONTROL_REG); MV_REG_WRITE(TWSI_CONTROL_REG, temp | TWSI_CONTROL_START_BIT); /* in case that the int flag was set before i.e. repeated start bit */ if(isIntFlag){ DB(mvOsPrintf("TWSI: mvTwsiStartBitSet repeated start Bit\n")); twsiIntFlgClr(); } /* wait for interrupt */ timeout = 0; while(!twsiMainIntGet() && (timeout++ < TWSI_TIMEOUT_VALUE)); /* check for timeout */ if(MV_TRUE == twsiTimeoutChk(timeout,"TWSI: mvTwsiStartBitSet ERROR - Start Clear bit TimeOut .\n")) return MV_TIMEOUT; /* check that start bit went down */ if((MV_REG_READ(TWSI_CONTROL_REG) & TWSI_CONTROL_START_BIT) != 0) { mvOsPrintf("TWSI: mvTwsiStartBitSet ERROR - start bit didn't went down\n"); return MV_FAIL; } /* check the status */ temp = twsiStsGet(); if(( temp != TWSI_START_CON_TRA ) && ( temp != TWSI_REPEATED_START_CON_TRA )) { mvOsPrintf("TWSI: mvTwsiStartBitSet ERROR - status %x after Set Start Bit. \n",temp); return MV_FAIL; } return MV_OK; }