示例#1
0
// range is 5=5V or 2=2.5V
static GOOD_OR_BAD OW_set_range( int range, struct parsedname * pn )
{
	int stored_range ;
	/* Range */
	if ( BAD( Cache_Get_SlaveSpecific(&stored_range, sizeof(stored_range), SlaveSpecificTag(RAN), pn))
		|| stored_range != range) {
			// need to set resolution
		BYTE p[_1W_2450_PAGESIZE];
		RETURN_BAD_IF_BAD( OW_r_mem(p, _1W_2450_PAGESIZE, _ADDRESS_CONTROL_PAGE, pn) ) ;
		switch ( range ) {
			case 2:
				p[_1W_2450_REG_A+1] &= ~_1W_2450_IR ;
				p[_1W_2450_REG_B+1] &= ~_1W_2450_IR ;
				p[_1W_2450_REG_C+1] &= ~_1W_2450_IR ;
				p[_1W_2450_REG_D+1] &= ~_1W_2450_IR ;
				break ;
			case 5:
			default:
				p[_1W_2450_REG_A+1] |= _1W_2450_IR ;
				p[_1W_2450_REG_B+1] |= _1W_2450_IR ;
				p[_1W_2450_REG_C+1] |= _1W_2450_IR ;
				p[_1W_2450_REG_D+1] |= _1W_2450_IR ;
				break ;
		}
		RETURN_BAD_IF_BAD( OW_w_mem(p, _1W_2450_PAGESIZE, _ADDRESS_CONTROL_PAGE, pn) );
		return Cache_Add_SlaveSpecific(&range, sizeof(int), SlaveSpecificTag(RAN), pn);
	}
	return gbGOOD ;
}
示例#2
0
文件: ow_2404.c 项目: M-o-a-T/owfs
/* write flag */
static ZERO_OR_ERROR FS_w_flag(struct one_wire_query *owq)
{
	struct parsedname *pn = PN(owq);
	BYTE cr;
	BYTE fl = pn->selected_filetype->data.c;
	OWQ_allocate_struct_and_pointer(owq_flag);
	
	OWQ_create_temporary(owq_flag, (char *) &cr, 1, 0x0201, pn);
	if (COMMON_read_memory_F0(owq_flag, 0, 0)) {
		return -EINVAL;
	}
	if (OWQ_Y(owq)) {
		if (cr & fl) {
			return 0;
		}
	} else {
		if ((cr & fl) == 0) {
			return 0;
		}
	}
	cr ^= fl;					/* flip the bit */
	if (OW_w_mem(&cr, 1, 0x0201, pn)) {
		return -EINVAL;
	}
	return 0;
}
示例#3
0
/* Write a pio register */
static GOOD_OR_BAD OW_w_pio( int pio, struct parsedname *pn)
{
	BYTE p[1];
	RETURN_BAD_IF_BAD( OW_r_mem(p, 1, _ADDRESS_CONTROL_PAGE + 2 * pn->extension, pn) ) ;
	p[0] |= _1W_2450_OE | _1W_2450_OC ;
	if ( pio==0 ) {
		p[0] &= ~_1W_2450_OC ;
	}
	return OW_w_mem(p, 1, _ADDRESS_CONTROL_PAGE + 2 * pn->extension, pn);
}
示例#4
0
/* write powered flag */
static ZERO_OR_ERROR FS_w_power(struct one_wire_query *owq)
{
	BYTE p = _1W_2450_POWERED;	/* powered */
	BYTE q = _1W_2450_UNPOWERED;	/* parasitic */
	if (OW_w_mem(OWQ_Y(owq) ? &p : &q, 1, _ADDRESS_POWERED, PN(owq))) {
		return -EINVAL;
	}
	Cache_Add_SlaveSpecific(&OWQ_Y(owq), sizeof(int), SlaveSpecificTag(POW), PN(owq));
	return 0;
}
示例#5
0
static GOOD_OR_BAD OW_w_mask( int y, BYTE mask, struct parsedname *pn)
{
	BYTE p[1];
	RETURN_BAD_IF_BAD( OW_r_mem(p, 1, _ADDRESS_CONTROL_PAGE + 2 * pn->extension + 1, pn) ) ;
	if ( y ) {
		p[0] |= mask ;
	} else {
		p[0] &= ~mask ;
	}
	// Clear POR as well
	p[0] &= ~_1W_2450_POR ;
	return OW_w_mem(p, 1, _ADDRESS_CONTROL_PAGE + 2 * pn->extension + 1, pn) ;
}
示例#6
0
文件: ow_2404.c 项目: M-o-a-T/owfs
/* write 4 or 5 byte number */
static GOOD_OR_BAD OW_w_ulong(uint64_t * L, size_t size, off_t offset, struct parsedname *pn)
{
	BYTE data[5] = { 0x00, 0x00, 0x00, 0x00, 0x00, };
	if (size > 5) {
		return -ERANGE;
	}
	data[0] = BYTE_MASK(L[0]);
	data[1] = BYTE_MASK(L[0] >> 8);
	data[2] = BYTE_MASK(L[0] >> 16);
	data[3] = BYTE_MASK(L[0] >> 24);
	data[4] = BYTE_MASK(L[0] >> 32);
	if (OW_w_mem(data, size, offset, pn)) {
		return gbBAD;
	}
	return gbGOOD;
}
示例#7
0
static GOOD_OR_BAD OW_w_vset( _FLOAT V, enum V_alarm_level ae, struct parsedname *pn)
{
	BYTE p[_1W_2450_PAGESIZE];
	RETURN_BAD_IF_BAD( OW_r_mem(p, 2, _ADDRESS_ALARM_PAGE + 2 * pn->extension, pn) ) ;
	switch ( ae ) {
		case V2_ae_high:
			p[1] = 100. * V ;
			break ;
		case V2_ae_low:
			p[0] = 100. * V ;
			break ;
		case V5_ae_high:
			p[1] = 50. * V ;
			break ;
		case V5_ae_low:
			p[0] = 50. * V ;
			break ;
	}
	return OW_w_mem(p, 2, _ADDRESS_ALARM_PAGE + 2 * pn->extension, pn) ;
}
示例#8
0
static GOOD_OR_BAD OW_set_resolution( int resolution, struct parsedname * pn )
{
	int stored_resolution ;
	/* Resolution */
	if ( BAD( Cache_Get_SlaveSpecific(&stored_resolution, sizeof(stored_resolution), SlaveSpecificTag(RES), pn))
		|| stored_resolution != resolution) {
			// need to set resolution
		BYTE p[_1W_2450_PAGESIZE];
		RETURN_BAD_IF_BAD( OW_r_mem(p, _1W_2450_PAGESIZE, _ADDRESS_CONTROL_PAGE, pn) ) ;
		p[_1W_2450_REG_A] &= ~_1W_2450_RC_MASK ;
		p[_1W_2450_REG_A] |= ( resolution & _1W_2450_RC_MASK ) ;
		p[_1W_2450_REG_B] &= ~_1W_2450_RC_MASK ;
		p[_1W_2450_REG_B] |= ( resolution & _1W_2450_RC_MASK ) ;
		p[_1W_2450_REG_C] &= ~_1W_2450_RC_MASK ;
		p[_1W_2450_REG_C] |= ( resolution & _1W_2450_RC_MASK ) ;
		p[_1W_2450_REG_D] &= ~_1W_2450_RC_MASK ;
		p[_1W_2450_REG_D] |= ( resolution & _1W_2450_RC_MASK ) ;
		RETURN_BAD_IF_BAD( OW_w_mem(p, _1W_2450_PAGESIZE, _ADDRESS_CONTROL_PAGE, pn) );
		return Cache_Add_SlaveSpecific(&resolution, sizeof(int), SlaveSpecificTag(RES), pn);
	}
	return gbGOOD ;
}
示例#9
0
文件: ow_2404.c 项目: M-o-a-T/owfs
/* alarm */
static ZERO_OR_ERROR FS_w_set_alarm(struct one_wire_query *owq)
{
	BYTE c;
	switch (OWQ_U(owq)) {
	case 0:
		c = 0 << 3;
		break;
	case 1:
		c = 1 << 3;
		break;
	case 10:
		c = 2 << 3;
		break;
	case 11:
		c = 3 << 3;
		break;
	case 100:
		c = 4 << 3;
		break;
	case 101:
		c = 5 << 3;
		break;
	case 110:
		c = 6 << 3;
		break;
	case 111:
		c = 7 << 3;
		break;
	default:
		return -ERANGE;
	}
	if (OW_w_mem(&c, 1, 0x200, PN(owq))) {
		return -EINVAL;
	}
	return 0;
}
示例#10
0
static ZERO_OR_ERROR FS_w_memory(struct one_wire_query *owq)
{
	return GB_to_Z_OR_E(OW_w_mem((BYTE *) OWQ_buffer(owq), OWQ_size(owq), (size_t) OWQ_offset(owq), PN(owq))) ;
}