Exemplo n.º 1
0
void
setup_control_request(ntp_control_message *p, uint8_t opcode, uint16_t seq){
	memset(p, 0, sizeof(ntp_control_message));
	LI_SET(p->flags, LI_NOWARNING);
	VN_SET(p->flags, VN_RESERVED);
	MODE_SET(p->flags, MODE_CONTROLMSG);
	OP_SET(p->op, opcode);
	p->seq = htons(seq);
	/* Remaining fields are zero for requests */
}
Exemplo n.º 2
0
void setup_request(ntp_message *p){
	struct timeval t;

	memset(p, 0, sizeof(ntp_message));
	LI_SET(p->flags, LI_ALARM);
	VN_SET(p->flags, 4);
	MODE_SET(p->flags, MODE_CLIENT);
	p->poll=4;
	p->precision=(int8_t)0xfa;
	L16(p->rtdelay)=htons(1);
	L16(p->rtdisp)=htons(1);

	gettimeofday(&t, NULL);
	TVtoNTP64(t,p->txts);
}
Exemplo n.º 3
0
static int drv2604_init_procedure(struct i2c_client *i2c)
{
	int ret;

	/* exit stand-by mode */
	ret = drv2604_i2c_write_single_byte(i2c, DRV2604_MODE, MODE_INIT_MASK);
	if (ret) {
		VIB_ERR_MSG("I2C write failed\n");
		goto end;
	}

	/* Set RTP register to zero, prevent playback */
	ret = drv2604_i2c_write_single_byte(i2c, DRV2604_RTP, 0x0);
	if (ret) {
		VIB_ERR_MSG("I2C write failed\n");
		goto end;
	}

	/* Set Library Overdrive time to zero */
	ret = drv2604_i2c_write_single_byte(i2c, DRV2604_ODT, 0x0);
	if (ret) {
		VIB_ERR_MSG("I2C write failed\n");
		goto end;
	}

	/* Set Library Sustain positive time */
	ret = drv2604_i2c_write_single_byte(i2c, DRV2604_SPT, 0x0);
	if (ret) {
		VIB_ERR_MSG("I2C write failed\n");
		goto end;
	}

	/* Set Library Sustain negative time */
	ret = drv2604_i2c_write_single_byte(i2c, DRV2604_SNT, 0x0);
	if (ret) {
		VIB_ERR_MSG("I2C write failed\n");
		goto end;
	}

	/* Set Library Brake Time */
	ret = drv2604_i2c_write_single_byte(i2c, DRV2604_BRT, 0x0);
	if (ret) {
		VIB_ERR_MSG("I2C write failed\n");
		goto end;
	}

	/* perform Auto Calibration Procedure */
	ret = drv2604_auto_calibration_procedure(i2c);
	if (ret) {
		VIB_ERR_MSG("falied to perform auto calibration\n");
		goto end;
	}

	/* populate RAM with waveforms */
	ret = drv2604_write_waveform_to_ram(i2c);
	if (ret) {
		VIB_ERR_MSG("failed to write waveform to RAM\n");
		goto end;
	}

	/* set the desired sequence to be played */
	ret = drv2604_i2c_write_single_byte(i2c, DRV2604_WAVEFORMSEQ1, 0x1);
	if (ret) {
		VIB_ERR_MSG("I2C write failed\n");
		goto end;
	}

	/* Insert termination character in sequence register 2 */
	ret = drv2604_i2c_write_single_byte(i2c, DRV2604_WAVEFORMSEQ2,
							WAVEFORMSEQ_TERMINATE);
	if (ret) {
		VIB_ERR_MSG("I2C write failed\n");
		goto end;
	}

	/* slect internal trigger */
	ret = drv2604_i2c_write_single_byte(i2c, DRV2604_MODE,
					MODE_SET(MODE_TYPE_INT_TRIG));
	if (ret) {
		VIB_ERR_MSG("I2C write failed\n");
		goto end;
	}
end:
	return ret;
}
Exemplo n.º 4
0
static int drv2604_auto_calibration_procedure(struct i2c_client *i2c)
{
	int ret, i;
	/* set status as waiting for calibration process */
	unsigned char val = GO_CMD;

	/*
	 * Set DRV260x Control Registers
	 * =============================
	 */

	/* set rated-voltage register */
	ret = drv2604_i2c_write_single_byte(i2c,
				DRV2604_RATED_VOLTAGE, ERM_RV_2p6);
	if (ret) {
		VIB_ERR_MSG("I2C write failed\n");
		goto end;
	}

	/* set overdrive-clamp-voltage register */
	ret = drv2604_i2c_write_single_byte(i2c,
				DRV2604_OVERDRIVE_CLAMP_VOLTAGE, ERM_ODV_3p6);
	if (ret) {
		VIB_ERR_MSG("I2C write failed\n");
		goto end;
	}

	/* set feedback control register */
	ret = drv2604_i2c_write_single_byte(i2c, DRV2604_FBCTRL,
				FBCTRL_N_ERM_LRA(SET_ERM) |
				FBCTRL_BRAKE_FACTOR(DEFAULT_BF4ERM) |
				FBCTRL_LOOP_RESPONSE(DEFAULT_LR4ERM) |
				FBCTRL_BEMF_GAIN(DEFAULT_BEMF_GAIN_ERM));
	if (ret) {
		VIB_ERR_MSG("I2C write failed\n");
		goto end;
	}

	/*
	 * Run Auto-Calibration
	 * ====================
	 */

	/* exit stand-by mode and set to auto calibration mode */
	ret = drv2604_i2c_write_single_byte(i2c, DRV2604_MODE,
					MODE_SET(MODE_TYPE_AUTOCAL));
	if (ret) {
		VIB_ERR_MSG("I2C write failed\n");
		goto end;
	}

	/* set the GO bit */
	ret = drv2604_i2c_write_single_byte(i2c, DRV2604_GO, GO_CMD);
	if (ret) {
		VIB_ERR_MSG("I2C write failed\n");
		goto end;
	}

	/* wait for calibration process to end */
	i = CHECK_CAL_PROCESS_RETRIES;
	do {
		msleep_interruptible(WAIT_FOR_CAL_MSEC);
		ret = drv2604_i2c_read_single_byte(i2c, DRV2604_GO, &val);
		/* if read error occures- try in next iteration */
		if (ret)
			VIB_ERR_MSG("I2C read failed\n");
	} while (val && (--i));

	if (val) {
		VIB_ERR_MSG("calibration timeout\n");
		ret = -EAGAIN;
		goto end;
	}

	/* check calibration results */
	ret = drv2604_i2c_read_single_byte(i2c, DRV2604_STATUS, &val);
	if (ret) {
		VIB_ERR_MSG("I2C read failed\n");
		goto end;
	}
	if (val & STATUS_DIAG_RESULT) {
		VIB_ERR_MSG("calibration failed\n");
		goto end;
	}
end:
	return ret;
}