static error_code_t IS_Enabled_I2C(lpc17xx_i2c_config_t *config) {
	error_code_t error = NO_ERROR;
	uint32_t status;


	switch (config->i2c_port) {
		case I2C0:
			error = ReadReg ( &(LPC_I2C0->I2CONSET), &status, 6, 6) ;
			break;
		case I2C1:
			error = ReadReg ( &(LPC_I2C1->I2CONSET),&status,  6, 6) ;
			break;
		case I2C2:
			error = ReadReg ( &(LPC_I2C2->I2CONSET),&status,  6, 6) ;
			break;
	}

	if ( status == 0) {
		return UNITIALIZED_I2C;
	}
	return error;
}
Exemple #2
0
static inline int
WaitForBusy(struct IsdnCardState *cs)
{
	int to = 130;

	while (!(ReadReg(cs, HFCD_DATA, HFCD_STAT) & HFCD_BUSY) && to) {
		udelay(1);
		to--;
	}
	if (!to)
		printk(KERN_WARNING "HiSax: WaitForBusy timeout\n");
	return (to);
}
/*******************************************************************************
* Function Name  : SetAxis
* Description    : Enable/Disable LSM303DLHC Axis
* Input          : X_ENABLE/X_DISABLE | Y_ENABLE/Y_DISABLE | Z_ENABLE/Z_DISABLE
* Output         : None
* Note           : You MUST use all input variable in the argument, as example
* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
*******************************************************************************/
status_t SetAxis(Axis_t axis) {
  u8_t value;
  
  if( !ReadReg(ACC_I2C_ADDRESS, CTRL_REG1_A, &value) )
    return MEMS_ERROR;
  value &= 0xF8;
  value |= (0x07 & axis);
   
  if( !WriteReg(ACC_I2C_ADDRESS, CTRL_REG1_A, value) )
    return MEMS_ERROR;   
  
  return MEMS_SUCCESS;
}
Exemple #4
0
int b1pciv4_detect(avmcard *card)
{
	int ret, i;

	if ((ret = b1dma_detect(card)) != 0)
		return ret;
	
	for (i=0; i < 5 ; i++) {
		if (WriteReg(card, 0x80A00000, 0x21) != 0)
			return 6;
		if ((ReadReg(card, 0x80A00000) & 0x01) != 0x01)
			return 7;
	}
	for (i=0; i < 5 ; i++) {
		if (WriteReg(card, 0x80A00000, 0x20) != 0)
			return 8;
		if ((ReadReg(card, 0x80A00000) & 0x01) != 0x00)
			return 9;
	}
	
	return 0;
}
/*******************************************************************************
* Function Name  : FIFOModeEnable
* Description    : Sets Fifo Modality
* Input          :
* Output         : None
* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
*******************************************************************************/
status_t FIFOModeEnable(FifoMode_t fm) {
    u8_t value;

    if(fm == FIFO_DISABLE) {

        if( !ReadReg(CTRL_REG5, &value) )
            return MEMS_ERROR;

        value &= 0xBF;

        if( !WriteReg(CTRL_REG5, value) )
            return MEMS_ERROR;

    }
    else {

        if( !ReadReg(CTRL_REG5, &value) )
            return MEMS_ERROR;

        value &= 0xBF;
        value |= MEMS_SET<<FIFO_EN;

        if( !WriteReg(CTRL_REG5, value) )
            return MEMS_ERROR;


        if( !ReadReg(FIFO_CTRL_REG, &value) )
            return MEMS_ERROR;

        value &= 0x1f;
        value |= (fm<<FM0);

        if( !WriteReg(FIFO_CTRL_REG, value) )
            return MEMS_ERROR;
    }

    return MEMS_SUCCESS;
}
/*******************************************************************************
* Function Name  : SetHPFMode
* Description    : Set High Pass Filter Modality
* Input          : HPM_NORMAL_MODE_RES/HPM_REF_SIGNAL/HPM_NORMAL_MODE/HPM_AUTORESET_INT
* Output         : None
* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
*******************************************************************************/
status_t SetHPFMode(HPFMode_t hpm) {
  u8_t value;
  
  if( !ReadReg(ACC_I2C_ADDRESS, CTRL_REG2_A, &value) )
    return MEMS_ERROR;
                  
  value &= 0x3F;
  value |= (hpm<<HPM);
  
  if( !WriteReg(ACC_I2C_ADDRESS, CTRL_REG2_A, value) )
    return MEMS_ERROR;
  
  return MEMS_SUCCESS;
}
/*******************************************************************************
* Function Name  : HPFAOI2
* Description    : Enable/Disable High Pass Filter for AOI on INT_2
* Input          : MEMS_ENABLE/MEMS_DISABLE
* Output         : None
* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
*******************************************************************************/
status_t HPFAOI2Enable(State_t hpfe) {
  u8_t value;
  
  if( !ReadReg(ACC_I2C_ADDRESS, CTRL_REG2_A, &value) )
    return MEMS_ERROR;
                  
  value &= 0xFD;
  value |= (hpfe<<HPIS2);
  
  if( !WriteReg(ACC_I2C_ADDRESS, CTRL_REG2_A, value) )
    return MEMS_ERROR;
  
  return MEMS_SUCCESS;
}
/*******************************************************************************
* Function Name  : SetSelfTest
* Description    : Set Self Test Modality
* Input          : SELF_TEST_DISABLE/ST_0/ST_1
* Output         : None
* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
*******************************************************************************/
status_t SetSelfTest(SelfTest_t st) {
  u8_t value;
  
  if( !ReadReg(ACC_I2C_ADDRESS, CTRL_REG4_A, &value) )
    return MEMS_ERROR;
                  
  value &= 0xF9;
  value |= (st<<ST);
  
  if( !WriteReg(ACC_I2C_ADDRESS, CTRL_REG4_A, value) )
    return MEMS_ERROR;
  
  return MEMS_SUCCESS;
}
/*******************************************************************************
* Function Name  : SetBLE
* Description    : Set Endianess (MSB/LSB)
* Input          : BLE_LSB / BLE_MSB
* Output         : None
* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
*******************************************************************************/
status_t SetBLE(Endianess_t ble) {
  u8_t value;
  
  if( !ReadReg(ACC_I2C_ADDRESS, CTRL_REG4_A, &value) )
    return MEMS_ERROR;
                  
  value &= 0xBF;	
  value |= (ble<<BLE);
  
  if( !WriteReg(ACC_I2C_ADDRESS, CTRL_REG4_A, value) )
    return MEMS_ERROR;
  
  return MEMS_SUCCESS;
}
/*******************************************************************************
* Function Name  : SetHPFMode
* Description    : Set High Pass Filter Modality
* Input          : HPM_NORMAL_MODE_RES/HPM_REF_SIGNAL/HPM_NORMAL_MODE/HPM_AUTORESET_INT
* Output         : None
* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
*******************************************************************************/
status_t SetHPFMode(HPFMode_t hpf) {
    u8_t value;

    if( !ReadReg(CTRL_REG2, &value) )
        return MEMS_ERROR;

    value &= 0xCF;
    value |= (hpf<<HPM);

    if( !WriteReg(CTRL_REG2, value) )
        return MEMS_ERROR;

    return MEMS_SUCCESS;
}
/*******************************************************************************
* Function Name  : SetInt2Pin
* Description    : Set Interrupt2 pin Function
* Input          : I2_DRDY_ON_INT2_ENABLE/DISABLE |
                   WTM_ON_INT2_ENABLE/DISABLE |
                   OVERRUN_ON_INT2_ENABLE/DISABLE |
                   EMPTY_ON_INT2_ENABLE/DISABLE
* Output         : None
* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
*******************************************************************************/
status_t SetInt2Pin(Int2PinConf_t pinConf) {
    u8_t value;

    if( !ReadReg(CTRL_REG3, &value) )
        return MEMS_ERROR;

    value &= 0xF0;
    value |= pinConf;

    if( !WriteReg(CTRL_REG3, value) )
        return MEMS_ERROR;

    return MEMS_SUCCESS;
}
/*******************************************************************************
* Function Name  : Int1LatchEnable
* Description    : Enable Interrupt 1 Latching function
* Input          : ENABLE/DISABLE
* Output         : None
* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
*******************************************************************************/
status_t Int1LatchEnable(State_t latch) {
  u8_t value;
  
  if( !ReadReg(ACC_I2C_ADDRESS, CTRL_REG5_A, &value) )
    return MEMS_ERROR;
                  
  value &= 0xF7;
  value |= latch<<LIR_INT1;
  
  if( !WriteReg(ACC_I2C_ADDRESS, CTRL_REG5_A, value) )
    return MEMS_ERROR;
  
  return MEMS_SUCCESS;
}
/*******************************************************************************
* Function Name  : SetModeMag
* Description    : Sets LSM303DLHC Magnetometer Modality
* Input          : Modality (CONTINUOUS_MODE, or SINGLE_MODE, or SLEEP_MODE)	
* Output         : None
* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
*******************************************************************************/
status_t SetModeMag(Mode_M_t Mode){
  u8_t value;

  if( !ReadReg(MAG_I2C_ADDRESS, MR_REG_M, &value) )
    return MEMS_ERROR;

  value &= 0x00; //bit<7-3> must be =0 for correct working
  value |= Mode<<MODE_SEL_M;

  if( !WriteReg(MAG_I2C_ADDRESS, MR_REG_M, value) )
    return MEMS_ERROR;

  return MEMS_SUCCESS;
}
/*******************************************************************************
* Function Name  : SetGainMag
* Description    : Sets LSM303DLHC Magnetometer Gain
* Input          : GAIN_1100_M or GAIN_855_M or GAIN_670_M or GAIN_450_M....
* Output         : None
* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
*******************************************************************************/
status_t SetGainMag(GAIN_M_t Gain){
  u8_t value;

  if( !ReadReg(MAG_I2C_ADDRESS, CRB_REG_M, &value) )
    return MEMS_ERROR;

  value &= 0x00; //bit<4-0> must be =0 for correct working
  value |= Gain<<GN_CFG;

  if( !WriteReg(MAG_I2C_ADDRESS, CRB_REG_M, value) )
    return MEMS_ERROR;

  return MEMS_SUCCESS;
}
/*******************************************************************************
* Function Name  : SetTemperature
* Description    : Sets LSM303DLHC Output Temperature
* Input          : MEMS_ENABLE, MEMS_DISABLE
* Output         : None
* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
*******************************************************************************/
status_t SetTemperature(State_t state){
  u8_t value;

  if( !ReadReg(MAG_I2C_ADDRESS, CRA_REG_M, &value) )
    return MEMS_ERROR;

  value &= 0x7F;
  value |= state<<TEMP_EN;

  if( !WriteReg(MAG_I2C_ADDRESS, CRA_REG_M, value) )
    return MEMS_ERROR;

  return MEMS_SUCCESS;
}
/*******************************************************************************
* Function Name  : SetTriggerInt
* Description    : Trigger event liked to trigger signal INT1/INT2
* Input          : TRIG_INT1/TRIG_INT2
* Output         : None
* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
*******************************************************************************/
status_t SetTriggerInt(TrigInt_t tr) {
  u8_t value;  
  
  if( !ReadReg(ACC_I2C_ADDRESS, FIFO_CTRL_REG_A, &value) )
      return MEMS_ERROR;
    
    value &= 0xDF;
    value |= (tr<<TR); 

  if( !WriteReg(ACC_I2C_ADDRESS, FIFO_CTRL_REG_A, value) )
    return MEMS_ERROR;

  return MEMS_SUCCESS;
}
/*******************************************************************************
* Function Name  : SetODR_M
* Description    : Sets LSM303DLHC Output Data Rate Magnetometer
* Input          : Output Data Rate
* Output         : None
* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
*******************************************************************************/
status_t SetODR_M(ODR_M_t ov){
  u8_t value;

  if( !ReadReg(MAG_I2C_ADDRESS, CRA_REG_M, &value) )
    return MEMS_ERROR;

  value &= 0x80; //bit<6,5,1,0> must be =0 for correct working
  value |= ov<<ODR_M;

  if( !WriteReg(MAG_I2C_ADDRESS, CRA_REG_M, value) )
    return MEMS_ERROR;

  return MEMS_SUCCESS;
}
/*******************************************************************************
* Function Name  : Int1LatchEnable
* Description    : Enable Interrupt 1 Latching function
* Input          : ENABLE/DISABLE
* Output         : None
* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
*******************************************************************************/
status_t Int1LatchEnable(State_t latch) {
    u8_t value;

    if( !ReadReg(INT1_CFG, &value) )
        return MEMS_ERROR;

    value &= 0xBF;
    value |= latch<<LIR;

    if( !WriteReg(INT1_CFG, value) )
        return MEMS_ERROR;

    return MEMS_SUCCESS;
}
/*******************************************************************************
* Function Name  : SetInt2Pin
* Description    : Set Interrupt2 pin Function
* Input          : CLICK_ON_PIN_INT2_ENABLE/DISABLE   | I2_INT1_ON_PIN_INT2_ENABLE/DISABLE |               
                   I2_INT2_ON_PIN_INT2_ENABLE/DISABLE | I2_BOOT_ON_INT2_ENABLE/DISABLE |                   
                   INT_ACTIVE_HIGH/LOW
* example        : SetInt2Pin(CLICK_ON_PIN_INT2_ENABLE/DISABLE | I2_INT1_ON_PIN_INT2_ENABLE/DISABLE |               
                   I2_INT2_ON_PIN_INT2_ENABLE/DISABLE | I2_BOOT_ON_INT2_ENABLE/DISABLE |                   
                   INT_ACTIVE_HIGH/LOW)
* Note           : To enable Interrupt signals on INT2 Pad (You MUST use all input variable in the argument, as example)
* Output         : None
* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
*******************************************************************************/
status_t SetInt2Pin(IntPinConf_t pinConf) {
  u8_t value;
  
  if( !ReadReg(ACC_I2C_ADDRESS, CTRL_REG6_A, &value) )
    return MEMS_ERROR;
                  
  value &= 0x00;
  value |= pinConf;
  
  if( !WriteReg(ACC_I2C_ADDRESS, CTRL_REG6_A, value) )
    return MEMS_ERROR;
  
  return MEMS_SUCCESS;
}                       
/*******************************************************************************
* Function Name  : SetIntMode
* Description    : Interrupt 1 Configuration mode (OR, 6D Movement, AND, 6D Position)
* Input          : INT_MODE_OR, INT_MODE_6D_MOVEMENT, INT_MODE_AND, INT_MODE_6D_POSITION
* Output         : None
* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
*******************************************************************************/
status_t SetIntMode(Int1Mode_t int_mode) {
  u8_t value;
  
  if( !ReadReg(ACC_I2C_ADDRESS, INT1_CFG_A, &value) )
    return MEMS_ERROR;
  
  value &= 0x3F; 
  value |= (int_mode<<INT_6D);
  
  if( !WriteReg(ACC_I2C_ADDRESS, INT1_CFG_A, value) )
    return MEMS_ERROR;

  return MEMS_SUCCESS;
}
/*******************************************************************************
* Function Name  : SetClickCFG
* Description    : Set Click Interrupt config Function
* Input          : ZD_ENABLE/DISABLE | ZS_ENABLE/DISABLE  | YD_ENABLE/DISABLE  | 
                   YS_ENABLE/DISABLE | XD_ENABLE/DISABLE  | XS_ENABLE/DISABLE 
* example        : SetClickCFG( ZD_ENABLE | ZS_DISABLE | YD_ENABLE | 
                               YS_DISABLE | XD_ENABLE | XS_ENABLE)
* Note           : You MUST use all input variable in the argument, as example
* Output         : None
* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
*******************************************************************************/
status_t SetClickCFG(u8_t status) {
  u8_t value;
  
  if( !ReadReg(ACC_I2C_ADDRESS, CLICK_CFG_A, &value) )
    return MEMS_ERROR;
                  
  value &= 0xC0;
  value |= status;
  
  if( !WriteReg(ACC_I2C_ADDRESS, CLICK_CFG_A, value) )
    return MEMS_ERROR;
  
  return MEMS_SUCCESS;
}  
void DMediaDriverNVMemory::Isr(TAny* aPtr)
	{
	__DEBUG_PRINT(">DMediaDriverNVMemory::Isr");

    DMediaDriverNVMemory* nvMem = reinterpret_cast<DMediaDriverNVMemory*>(aPtr);

	// Save the amount of transferred sectors. This clears the interrupt from HW as well
	nvMem->iLatestTransferSectorCount = ReadReg( KHwNVMemoryDevice, R_NVMEM_STATUS );

	// Clear from framework
	Interrupt::Clear( EIntNVMemoryDevice );

	nvMem->iSessionEndDfc.Add();
	}
/*******************************************************************************
* Function Name  : SetInt2Configuration
* Description    : Interrupt 1 Configuration (whitout 6D_INT)
* Input          : INT_AND/OR | INT_ZHIE_ENABLE/DISABLE | INT_ZLIE_ENABLE/DISABLE...
* Output         : None
* Note           : You MUST use all input variable in the argument, as example
* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
*******************************************************************************/
status_t SetInt2Configuration(IntConf_t ic) {
  u8_t value;
  
  if( !ReadReg(ACC_I2C_ADDRESS, INT2_CFG_A, &value) )
    return MEMS_ERROR;
  
  value &= 0x40; 
  value |= ic;
  
  if( !WriteReg(ACC_I2C_ADDRESS, INT2_CFG_A, value) )
    return MEMS_ERROR;

  return MEMS_SUCCESS;
}
/*******************************************************************************
* Function Name  : SetIntPinMode
* Description    : Set Interrupt Pin Modality (push pull or Open drain)
* Input          : PUSH_PULL/OPEN_DRAIN
* Output         : None
* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
*******************************************************************************/
status_t SetIntPinMode(IntPinMode_t pm) {
    u8_t value;

    if( !ReadReg(CTRL_REG3, &value) )
        return MEMS_ERROR;

    value &= 0xEF;
    value |= (pm<<PP_OD);

    if( !WriteReg(CTRL_REG3, value) )
        return MEMS_ERROR;

    return MEMS_SUCCESS;
}
uint8_t MPU9250::AK8963_whoami(){
  char response;
  WriteReg(MPUREG_I2C_SLV0_ADDR,AK8963_I2C_ADDR|READ_FLAG); //Set the I2C slave addres of AK8963 and set for read.
  WriteReg(MPUREG_I2C_SLV0_REG, AK8963_WIA); //I2C slave 0 register address from where to begin data transfer
  WriteReg(MPUREG_I2C_SLV0_CTRL, 0x81); //Read 1 byte from the magnetometer

  //WriteReg(MPUREG_I2C_SLV0_CTRL, 0x81);    //Enable I2C and set bytes
  bcm2835_delayMicroseconds(10000);
  response=ReadReg(MPUREG_EXT_SENS_DATA_00); //Read I2C
  //ReadRegs(MPUREG_EXT_SENS_DATA_00,response,1);
  //response=WriteReg(MPUREG_I2C_SLV0_DO, 0x00);    //Read I2C

  return response;
}
/*******************************************************************************
* Function Name  : SetSelfTest
* Description    : Set Self Test Modality
* Input          : ST_NORMAL_MODE/ST_0/ST_1
* Output         : None
* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
*******************************************************************************/
status_t SetSelfTest(SelfTest_t st) {
    u8_t value;

    if( !ReadReg(CTRL_REG4, &value) )
        return MEMS_ERROR;

    value &= 0xF9;
    value |= (st<<SELF_TEST);

    if( !WriteReg(CTRL_REG4, value) )
        return MEMS_ERROR;

    return MEMS_SUCCESS;
}
/*******************************************************************************
* Function Name  : SetFullScale
* Description    : Sets the LSM303DLHC FullScale
* Input          : FULLSCALE_2/FULLSCALE_4/FULLSCALE_8/FULLSCALE_16
* Output         : None
* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
*******************************************************************************/
status_t SetFullScale(Fullscale_t fs) {
  u8_t value;
  
  if( !ReadReg(ACC_I2C_ADDRESS, CTRL_REG4_A, &value) )
    return MEMS_ERROR;
                  
  value &= 0xCF;	
  value |= (fs<<FS);
  
  if( !WriteReg(ACC_I2C_ADDRESS, CTRL_REG4_A, value) )
    return MEMS_ERROR;
  
  return MEMS_SUCCESS;
}
/*******************************************************************************
* Function Name  : HPFEnable
* Description    : Enable/Disable High Pass Filter
* Input          : ENABLE/DISABLE
* Output         : None
* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
*******************************************************************************/
status_t HPFEnable(State_t hpf) {
    u8_t value;

    if( !ReadReg(CTRL_REG5, &value) )
        return MEMS_ERROR;

    value &= 0xEF;
    value |= (hpf<<HPEN);

    if( !WriteReg(CTRL_REG5, value) )
        return MEMS_ERROR;

    return MEMS_SUCCESS;
}
/*******************************************************************************
* Function Name  : SetBDU
* Description    : Enable/Disable Block Data Update Functionality
* Input          : ENABLE/DISABLE
* Output         : None
* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
*******************************************************************************/
status_t SetBDU(State_t bdu) {
  u8_t value;
  
  if( !ReadReg(ACC_I2C_ADDRESS, CTRL_REG4_A, &value) )
    return MEMS_ERROR;
 
  value &= 0x7F;
  value |= (bdu<<BDU);

  if( !WriteReg(ACC_I2C_ADDRESS, CTRL_REG4_A, value) )
    return MEMS_ERROR;

  return MEMS_SUCCESS;
}
/*******************************************************************************
* Function Name  : SetAxis
* Description    : Enable/Disable L3G4200D Axis
* Input          : X_ENABLE/X_DISABLE | Y_ENABLE/Y_DISABLE | Z_ENABLE/Z_DISABLE
* Output         : None
* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
*******************************************************************************/
status_t SetAxis(Axis_t axis) {
    u8_t value;

    if( !ReadReg(CTRL_REG1, &value) )
        return MEMS_ERROR;

    value &= 0xf8;
    value |= axis;

    if( !WriteReg(CTRL_REG1, value) )
        return MEMS_ERROR;

    return MEMS_SUCCESS;
}