📄 i2cbus.cpp
字号:
/* [Power ON and STOP condition] = */
/* DO */
/* [Select LPT port number, correct FI2C_LPT_PORT] */
/* [Erase LPT data buffer, set SDA and SCL to '1'] */
/* [Power ON the conversion card, set Alim to '1'] */
/* OD */
/* OD */
/*--- END FUNCTION HEADER ----------------------------------------------------*/
void FluxI2C::InitI2C(int AskedLptPort)
{
FI2C_LPT_PORT=AskedLptPort-1; // AskedLptPort -> FI2C_LPT_PORT
FI2C_LPT_PORT=FI2C_LPT_PORT%1; // Garde le Bit 0 UNIQUEMENT
// Ne marche pas avec la ligne juste AVANT
// LPT1 = 1 -> 0
// LPT2 = 2 -> 1
// On passe SDA et SCL a '1' (bit 1 et 2 a '0')
FI2C_LPT_DATA=0;
// On alimente le Convertisseur //->I2C (bit 0 a '1') : AlimON
SetBitI2C(CNST_BITN_LPTP_ALIM);
delay(CNST_DATA_TIME_TEMPO);
}
/*--- START FUNCTION HEADER --------------------------------------------------*/
/* Name : PowerOffI2C */
/* Role : Restore I2C bus mode */
/* Interface : None */
/* Pre-condition : None */
/* Constraints : None */
/* Behavior : */
/* DO */
/* [Clear the I2C and cut off the power] */
/* OD */
/*----------------------------------------------------------------------------*/
/* PROC PowerOffI2C */
/* ( */
/* ) */
/* DATA */
/* ATAD */
/* */
/* DO */
/* [Clear the I2C and cut off the power] = */
/* DO */
/* [Put the I2C bus lines to low level, set SDA and SCL to '0'] */
/* [Cut off the power, set Alim to '0'] */
/* OD */
/* OD */
/*--- END FUNCTION HEADER ----------------------------------------------------*/
void FluxI2C::PowerOffI2C(void)
{
// On passe SDA et SCL a '0'
SetBitI2C(CNST_BITN_LPTP_WSDA);
SetBitI2C(CNST_BITN_LPTP_WSCL);
// On coupe l'alim -> AlimOFF
ClearBitI2C(CNST_BITN_LPTP_ALIM);
delay(CNST_DATA_TIME_TEMPO);
}
/*--- START FUNCTION HEADER --------------------------------------------------*/
/* Name : TestBusI2C */
/* Role : Test if the I2C bus is FREE, in STOP mode (SDA and SCL to '1') */
/* Interface : OUT TestBusI2C */
/* 0 - Error */
/* 1 - OK, bus FREE */
/* Pre-condition : None */
/* Constraints : Cannot define in which context we are : Read, Write or Ack ? */
/* Behavior : */
/* DO */
/* [Test if the I2C bus is in STOP mode] */
/* OD */
/*----------------------------------------------------------------------------*/
/* PROC TestBusI2C */
/* ( */
/* ) */
/* DATA */
/* ATAD */
/* */
/* DO */
/* [Test if the I2C bus is in STOP mode] = */
/* IF [SDA and SCL to '1', then the I2C bus is FREE, return 1] THEN */
/* [The I2C is FREE, return 1] */
/* ELSE */
/* [The I2C is NOT FREE, return 0] */
/* FI */
/* OD */
/*--- END FUNCTION HEADER ----------------------------------------------------*/
int FluxI2C::TestBusI2C(void)
{
// On verifie si SDA et SCL sont a '1'
// ATTENTION : C'est pas parfait !!! -> Lecture, Ecriture ou Ack ?
if(TestBitI2C(CNST_BITN_LPTP_RSDA) && TestBitI2C(CNST_BITN_LPTP_RSCL))
return 1;
else
return 0;
}
/*--- START FUNCTION HEADER --------------------------------------------------*/
/* Name : SetBitI2C */
/* Role : Set a bit of the LPT data port to '1' */
/* Interface : IN NbBit */
/* [0-7] - Bit number to set to '1' */
/* Pre-condition : None */
/* Constraints : None */
/* Behavior : */
/* DO */
/* [Set the selected bit to '1'] */
/* OD */
/*----------------------------------------------------------------------------*/
/* PROC SetBitI2C */
/* ( */
/* ) */
/* DATA */
/* ATAD */
/* */
/* DO */
/* [Set the selected bit to '1'] = */
/* DO */
/* [Set the bit to '1' in the LPT data buffer, using OR and ROL modulo 8] */
/* [Output the buffer onto the selected LPT data port] */
/* OD */
/* OD */
/*--- END FUNCTION HEADER ----------------------------------------------------*/
void FluxI2C::SetBitI2C(int NbBit)
{
FI2C_LPT_DATA=FI2C_LPT_DATA|(1<<(NbBit%8));
outportb(CNST_ADDR_BASE_WLPT-0x0100*FI2C_LPT_PORT, FI2C_LPT_DATA);
}
/*--- START FUNCTION HEADER --------------------------------------------------*/
/* Name : ClearBitI2C */
/* Role : Set a bit of the LPT data port to '0' */
/* Interface : IN NbBit */
/* [0-7] - Bit number to set to '0' */
/* Pre-condition : None */
/* Constraints : None */
/* Behavior : */
/* DO */
/* [Set the selected bit to '0'] */
/* OD */
/*----------------------------------------------------------------------------*/
/* PROC ClearBitI2C */
/* ( */
/* ) */
/* DATA */
/* ATAD */
/* */
/* DO */
/* [Set the selected bit to '0'] = */
/* DO */
/* [Set the bit to '0' in the LPT data buffer, AND, XOR and ROL modulo 8] */
/* [Output the buffer onto the selected LPT data port] */
/* OD */
/* OD */
/*--- END FUNCTION HEADER ----------------------------------------------------*/
void FluxI2C::ClearBitI2C(int NbBit)
{
FI2C_LPT_DATA=FI2C_LPT_DATA&((-1)^(1<<(NbBit%8)));
outportb(CNST_ADDR_BASE_WLPT-0x0100*FI2C_LPT_PORT, FI2C_LPT_DATA);
}
/*--- START FUNCTION HEADER --------------------------------------------------*/
/* Name : TestBitI2C */
/* Role : Return the state of a selected bit of the LPT data port */
/* Interface : IN NbBit */
/* [0-7] - Bit number to set to '0' */
/* OUT TestBitI2C */
/* Pre-condition : None */
/* Constraints : None */
/* Behavior : */
/* DO */
/* [Test the status of the selected bit] */
/* OD */
/*----------------------------------------------------------------------------*/
/* PROC TestBitI2C */
/* ( */
/* ) */
/* DATA */
/* ATAD */
/* */
/* DO */
/* [Test the status of the selected bit] = */
/* DO */
/* [Return the selected bit state, using ROR modulo 8 and AND %1] */
/* OD */
/* OD */
/*--- END FUNCTION HEADER ----------------------------------------------------*/
int FluxI2C::TestBitI2C(int NbBit)
{
return (inportb(CNST_ADDR_BASE_RLPT-0x0100*FI2C_LPT_PORT)>>(NbBit%8))&1;
}
/*--- START FUNCTION HEADER --------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -