Ejemplo n.º 1
0
void
slapi_be_free(Slapi_Backend **be)
{
    be_done(*be);
    slapi_ch_free((void**)be);
    *be = NULL;
}
Ejemplo n.º 2
0
static void _hwpl_i2c_isr(int port) {
	uint8_t stat_value;
	LPC_I2C_TypeDef * i2c_regs;
	// this handler deals with master read and master write only
	i2c_regs = i2c_get_regs(port);

	if ( i2c_regs == NULL ){
		be_done(port);
	}
	stat_value = i2c_regs->STAT;
	switch ( stat_value ){
	case 0x08: //Start Condition has been sent
	case 0x10: //Repeated Start condition
		i2c_local[port].err = 0;
		if ( i2c_local[port].state == I2C_STATE_NONE){
			i2c_regs->DAT = i2c_local[port].addr | 0x01; //Set the Read bit -- repeated start after write ptr
		} else {
			i2c_regs->DAT = i2c_local[port].addr;
		}

		i2c_regs->CONSET = AA;
		i2c_regs->CONCLR = STA;
		break;
	case 0x18: //SLA+W transmitted -- Ack Received
		i2c_regs->DAT = i2c_local[port].ptr.ptr8[1]; //Send the offset pointer (MSB of 16 or 8 bit)
		i2c_regs->CONSET = AA;
		break;
	case 0x28: //Data byte transmitted -- Ack Received
		if (( i2c_local[port].state == I2C_STATE_RD_16_OP )||
				( i2c_local[port].state == I2C_STATE_WR_16_OP )){
			i2c_regs->DAT = i2c_local[port].ptr.ptr8[0]; //Send the offset pointer (LSB)
			i2c_regs->CONSET = AA;
			if ( i2c_local[port].state == I2C_STATE_RD_16_OP ){
				i2c_local[port].state = I2C_STATE_RD_OP;
			}
			break;
		}

		if ( i2c_local[port].state == I2C_STATE_RD_OP ){
			i2c_regs->CONSET = AA|STA; //Restart (then send read command)
			i2c_local[port].state = I2C_STATE_NONE;
			break;
		}

		//Transmit data
		if ( i2c_local[port].size ){
			i2c_regs->DAT = *(i2c_local[port].data);
			i2c_local[port].data++;
			i2c_regs->CONSET = AA;
			i2c_local[port].size--;
		} else {
			i2c_regs->CONSET = STO|AA;
			i2c_local[port].state = I2C_STATE_NONE | I2C_DONE_FLAG;
		}
		break;
	case 0x20:
	case 0x30:
	case 0x48:
		//Receiver nack'd
		i2c_regs->CONSET = STO;
		i2c_local[port].size = 0;
		i2c_local[port].err = I2C_ERROR_ACK;
		i2c_local[port].state = I2C_DONE_FLAG;
		break;
	case 0x38:
		i2c_local[port].size = 0;
		i2c_regs->CONSET = STO;
		i2c_local[port].err = I2C_ERROR_ARBITRATION_LOST;
		i2c_local[port].state = I2C_DONE_FLAG;
		break;
	case 0x40: //SLA+R transmitted -- Ack received
		if ( i2c_local[port].size > 1 ){
			i2c_regs->CONSET = AA; //only ACK if more than one byte is coming
		} else {
			i2c_regs->CONCLR = AA;
		}
		break;
	case 0x50: //Data Byte received -- Ack returned
		//Receive Data
		if ( i2c_local[port].size ) i2c_local[port].size--;
		*(i2c_local[port].data) = (char)i2c_regs->DAT;
		i2c_local[port].data++;
		if ( i2c_local[port].size > 1 ){
			i2c_regs->CONSET = AA;
		} else {
			i2c_regs->CONCLR = AA;
		}
		break;
	case 0x58: //Data byte received -- Not Ack returned
		if ( i2c_local[port].size ) i2c_local[port].size--;
		*(i2c_local[port].data) = (char)i2c_regs->DAT;
		i2c_local[port].data++;

		i2c_regs->CONSET = STO;
		i2c_local[port].state = I2C_STATE_NONE | I2C_DONE_FLAG;
		break;
	case 0x00:
		i2c_local[port].err = I2C_ERROR_START;
		i2c_local[port].state = I2C_DONE_FLAG;
		i2c_regs->CONSET = STO;
		break;
	}

	i2c_regs->CONCLR = SI; //clear the interrupt flag

	if ( i2c_local[port].state & I2C_DONE_FLAG ){
		exec_callback(port, 0);
	}
}