void __irq Cam_IICInt(void)
{
#if REBIS //REBIS = 1
U32 iicSt, i;
ClearPending(BIT_IIC);
//#define ClearPending(bit) {\ //BIT_IIC = 0x1 << 27
// rSRCPND = bit;\ //INT_IIC Requested(Source pending register)
// rINTPND = bit;\ //INT_IIC Requested(Interrupt pending register)
// rINTPND;\
// }
iicSt = rIICSTAT;
rINTMSK |= BIT_IIC;
if(iicSt & 0x8){} //When bus arbitration is failed.
if(iicSt & 0x4){} //When a slave address is matched with IICADD
if(iicSt & 0x2){} //When a slave address is 0000000b
if(iicSt & 0x1){} //When ACK isn't received
switch( _CAMiicMode )
{
case CAMRDDATA:
if( (_CAMiicDataCount--) == 0 ) // case by I2C_Read16 or Rd_CamIIC
{
_CAMiicData[_CAMiicPt++] = rIICDS;
rIICSTAT = 0x90; // Stop MasRx condition
// Rx/Tx Enable & Master receive mode
rIICCON = 0xEF; // Resuems IIC operation.
//prescaler? Tx clock = IICLK/(15 + 1)
// No interrupt pending
// IIC-Bus Tx/Rx interrupt enable
// IICCLK = fPCLK/512
// IIC-bus acknowledge enable
Delay(1); // Wait until stop condtion is in effect., Too long time...
//# need the time 2440:Delay(1), 24A0: Delay(2)
// The pending bit will not be set after issuing stop condition.
break;
}
_CAMiicData[_CAMiicPt++] = rIICDS; //The last data has to be read with no ack.
//IICDS : Multi-master IIC-bus transmit/receive data shift register
if( (_CAMiicDataCount) == 0 )
{
rIICCON = 0x6F; // Resumes IIC operation with NOACK
//in case of S5X532 Camera.
//prescaler? Tx clock = IICLK/(15 + 1)
// No interrupt pending
// IIC-Bus Tx/Rx interrupt enable
// IICCLK = fPCLK/512
// IIC-bus acknowledge disable
}
else
{
rIICCON = 0xEF; // Resumes IIC operaton with ACK.
}
break;
case CAMWRDATA: //case by I2C_Write16 or Wr_CamIIC
if( (_CAMiicDataCount--) == 0 )
{
rIICSTAT = 0xD0; // stop MasTx condition
rIICCON = 0xEF; // resumes IIC operation.
Delay(1); // wait until stop condtion is in effect.
// # need the time 2440:Delay(1), 24A0: Delay(2)
// The pending bit will not be set after issuing stop condition.
break;
}
rIICDS = _CAMiicData[_CAMiicPt++]; //_iicData[0] has dummy.
for(i=0;i<10;i++); //for setup time until rising edge of IICSCL
rIICCON = 0xEF; //resumes IIC operation.
break;
case CAMSETRDADDR: // case by I2C_Read16 or Rd_CamIIC
// Uart_Printf("[S%d]",_iicDataCount);
if( (_CAMiicDataCount--) == 0 )
{
rIICSTAT = 0xD0; //stop MasTx condition
rIICCON = 0xEF; //resumes IIC operation.
Delay(1); //wait until stop condtion is in effect.
break; //IIC operation is stopped because of IICCON[4]
}
rIICDS = _CAMiicData[_CAMiicPt++];
for(i=0;i<10;i++); //for setup time until rising edge of IICSCL
rIICCON = 0xEF; //resumes IIC operation.
break;
default:
break;
}
rINTMSK &= ~BIT_IIC;
#else // #if REBIS
U32 iicSt,i;
ClearPending(BIT_IIC);
iicSt = rIICSTAT;
rINTMSK |= BIT_IIC;
if(iicSt & 0x8){} //When bus arbitration is failed.
if(iicSt & 0x4){} //When a slave address is matched with IICADD
if(iicSt & 0x2){} //When a slave address is 0000000b
if(iicSt & 0x1){} //When ACK isn't received
switch(_CAMiicMode) {
case CAMRDDATA:
if((_CAMiicDataCount--)==0) {
_CAMiicData[_CAMiicPt++] = rIICDS;
rIICSTAT = 0x90; //Stop MasRx condition
rIICCON &= ~(1<<4); //Resumes IIC operation.
Delay(1); //Wait until stop condtion is in effect., Too long time...
// # need the time 2440:Delay(1), 24A0: Delay(2)
//The pending bit will not be set after issuing stop condition.
break;
}
_CAMiicData[_CAMiicPt++] = rIICDS; //The last data has to be read with no ack.
if((_CAMiicDataCount)==0)
rIICCON &= ~((1<<7)|(1<<4)); //Resumes IIC operation with NOACK
// in case of S5X532 Cameara
// rIICCON = 0x6f; //Resumes IIC operation with NOACK
// in case of S5X532 Cameara
else
rIICCON &= ~(1<<4); // Resumes IIC operation with ACK
// No interrupt pending
break;
case CAMWRDATA:
if((_CAMiicDataCount--)==0) {
rIICSTAT = 0xd0; //stop MasTx condition
rIICCON &= ~(1<<4); //resumes IIC operation.
Delay(1); // wait until stop condtion is in effect.
// # need the time 2440:Delay(1), 24A0: Delay(2)
//The pending bit will not be set after issuing stop condition.
break;
}
rIICDS = _CAMiicData[_CAMiicPt++]; //_iicData[0] has dummy.
for(i=0;i<10;i++); //for setup time until rising edge of IICSCL
rIICCON &= ~(1<<4); //resumes IIC operation.
break;
case CAMSETRDADDR: //Uart_Printf("[S%d]",_iicDataCount);
if((_CAMiicDataCount--)==0) {
rIICSTAT = 0xd0; //stop MasTx condition
rIICCON &= ~(1<<4); //resumes IIC operation.
Delay(1); //wait until stop condtion is in effect.
break; //IIC operation is stopped because of IICCON[4]
}
rIICDS = _CAMiicData[_CAMiicPt++];
for(i=0;i<10;i++); //for setup time until rising edge of IICSCL
rIICCON &= ~(1<<4); //resumes IIC operation.
break;
default:
break;
}
rINTMSK &= ~BIT_IIC;
#endif // #if REBIS #else
}
void Camera_WriteByte(void)
{
#if REBIS
U32 RegAddr;
U16 RegData;
Uart_Printf("Input Write Register Address of %s\n=>", CAM_NAME);
RegAddr = (U32)Uart_GetIntNum();
Uart_Printf("Input Write Transfer Data into %s\n=>", CAM_NAME);
RegData = (U16)Uart_GetIntNum();
I2C_Write16( CAM_ID, RegAddr, RegData );
#else
unsigned int i, j, save_E, save_PE, RegAddr, RegData, pageNo;
#if (USED_CAM_TYPE==CAM_S5X532)||(USED_CAM_TYPE==CAM_S5X3A1)
Uart_Printf("Input Write Page No of %s\n=>", CAM_NAME);
pageNo = (U8)Uart_GetIntNum();
#endif
Uart_Printf("Input Write Register Address of %s\n=>", CAM_NAME);
RegAddr = (U8)Uart_GetIntNum();
Uart_Printf("Input Write Transfer Data into %s\n=>", CAM_NAME);
RegData = (U8)Uart_GetIntNum();
#if (USED_CAM_TYPE==CAM_S5X532)||(USED_CAM_TYPE==CAM_S5X3A1)
Wr_CamIIC(CAM_ID, (U8)0xec, pageNo); // set Page no
#endif
Wr_CamIIC(CAM_ID, (U8)RegAddr, RegData); // set register after setting page number
#endif // #if REBIS #else
}
|