static GOOD_OR_BAD OW_volts(_FLOAT * V, const struct parsedname *pn) { BYTE b4[] = { _1W_CONVERT_V, }; BYTE b2[] = { _1W_READ_REGISTERS, _ADDRESS_VOLTAGE, }; BYTE v[2]; struct transaction_log tconvert[] = { TRXN_START, TRXN_WRITE1(b4), TRXN_DELAY(10), TRXN_END, }; struct transaction_log tdata[] = { TRXN_START, TRXN_WRITE2(b2), TRXN_READ2(v), TRXN_END, }; // initiate conversion RETURN_BAD_IF_BAD(BUS_transaction(tconvert, pn)) ; /* Get data */ RETURN_BAD_IF_BAD( BUS_transaction(tdata, pn)) ; // success //V[0] = .01 * (_FLOAT)( ( ((uint32_t)v[1]) <<8 )|v[0] ) ; V[0] = .01 * (_FLOAT) (UT_uint16(v)); return gbGOOD; }
static GOOD_OR_BAD OW_w_pio(const BYTE data, const struct parsedname *pn) { BYTE write_string[] = { _1W_CHANNEL_ACCESS_WRITE, data, (BYTE) ~ data, }; BYTE read_back[2]; struct transaction_log t[] = { TRXN_START, TRXN_WRITE3(write_string), TRXN_READ2(read_back), TRXN_END, }; if ( BAD(BUS_transaction(t, pn)) ) { // may be in test mode, which causes Channel Access Write to fail // fix now, but need another attempt to see if will work OW_out_of_test_mode(pn) ; return gbBAD ; } if (read_back[0] != 0xAA) { return gbBAD; } /* Ignore byte 5 read_back[1] the PIO status byte */ return gbGOOD; }
/* read Charge Pump */ static GOOD_OR_BAD OW_r_cp(int *val, const struct parsedname *pn) { BYTE aa[] = { _1W_READ_CONTROL_REGISTER, }; BYTE resp[2]; struct transaction_log t[] = { TRXN_START, TRXN_WRITE1(aa), TRXN_READ2(resp), TRXN_END }; RETURN_BAD_IF_BAD(BUS_transaction(t, pn)) ; *val = ((resp[1] & 0x40) != 0); return gbGOOD; }
/* read Wiper */ static GOOD_OR_BAD OW_r_wiper(UINT * val, const struct parsedname *pn) { BYTE fo[] = { _1W_READ_POSITION, }; BYTE resp[2]; struct transaction_log t[] = { TRXN_START, TRXN_WRITE1(fo), TRXN_READ2(resp), TRXN_END }; RETURN_BAD_IF_BAD(BUS_transaction(t, pn)) ; *val = resp[1]; return gbGOOD; }
static GOOD_OR_BAD OW_w_std(BYTE *buf, size_t size, BYTE type, BYTE stype, const struct parsedname *pn) { BYTE p[4] = { _1W_WRITE_MOAT, type,stype, size}; BYTE crcbuf[2]; UINT crc; struct transaction_log tfirst[] = { TRXN_START, TRXN_WRITE(p,4), TRXN_WRITE(buf,size), TRXN_READ2(crcbuf), TRXN_END, }; struct transaction_log xmit_crc[] = { TRXN_WRITE2(crcbuf), TRXN_END, }; if (size == 0) { return gbGOOD; } if (size > 255) { return gbBAD; } LEVEL_DEBUG( "write: %d for %d %d",size,type,stype) ; if ( BAD(BUS_transaction(tfirst, pn))) { goto out_bad; } crc = CRC16compute(p,4,0); crc = CRC16compute(buf,size,crc); if ( CRC16seeded (crcbuf,2,crc) ) { LEVEL_DEBUG("CRC error"); goto out_bad; } LEVEL_DEBUG( "read CRC: GOOD, got %02x%02x",crcbuf[0],crcbuf[1]) ; crcbuf[0] = ~crcbuf[0]; crcbuf[1] = ~crcbuf[1]; if ( BAD(BUS_transaction(xmit_crc, pn)) ) { goto out_bad; } return gbGOOD; out_bad: return gbBAD; }
/* write to 2450 */ static GOOD_OR_BAD OW_w_mem(BYTE * p, size_t size, off_t offset, struct parsedname *pn) { // command, address(2) , data , crc(2), databack BYTE buf[6] = { _1W_WRITE_MEMORY, LOW_HIGH_ADDRESS(offset), p[0], }; BYTE echo[1]; size_t i; struct transaction_log tfirst[] = { TRXN_START, TRXN_WR_CRC16(buf, 4, 0), TRXN_READ1(echo), TRXN_COMPARE(echo, p, 1), TRXN_END, }; struct transaction_log trest[] = { // note no TRXN_START TRXN_WRITE1(buf), TRXN_READ2(&buf[1]), TRXN_READ1(echo), TRXN_END, }; //printf("2450 W mem size=%d location=%d\n",size,location) ; if (size == 0) { return gbGOOD; } /* Send the first byte (handled differently) */ RETURN_BAD_IF_BAD(BUS_transaction(tfirst, pn)) ; /* rest of the bytes */ for (i = 1; i < size; ++i) { buf[0] = p[i]; RETURN_BAD_IF_BAD( BUS_transaction(trest, pn) ) ; if ( CRC16seeded(buf, 3, offset + i) || (echo[0] != p[i]) ) { return gbBAD; } } return gbGOOD; }
static GOOD_OR_BAD OW_r_std(BYTE *buf, size_t *buflen, BYTE type, BYTE stype, const struct parsedname *pn) { BYTE p[3] = { _1W_READ_MOAT, type,stype }; size_t maxlen = *buflen; BYTE len; GOOD_OR_BAD ret = gbGOOD; struct transaction_log tfirst[] = { TRXN_START, TRXN_WRITE3(p), TRXN_READ1(&len), TRXN_END, }; if (maxlen == 0) { return gbGOOD; } LEVEL_DEBUG( "read: read len for %d %d",type,stype) ; /* 0xFF means the device was too slow */ if ( BAD(BUS_transaction(tfirst, pn)) || len == 0xFF) { goto out_bad; } LEVEL_DEBUG( "read: got len %d",len) ; if (len > maxlen) { /* don't read all and don't bother with CRC. * This will abort the read on the client side so that * there'll be no side effects like marked-as-sent buffers * or cleared 'conditional search' flags */ struct transaction_log tinfo[] = { TRXN_READ(buf,maxlen), TRXN_END, }; if ( BAD(BUS_transaction(tinfo, pn)) ) { goto out_bad; } } else { UINT crc; BYTE crcbuf[2]; struct transaction_log recv_buf[] = { TRXN_READ(buf,len), TRXN_READ2(crcbuf), TRXN_END, }; struct transaction_log recv_crc[] = { TRXN_READ2(crcbuf), TRXN_END, }; struct transaction_log xmit_crc[] = { TRXN_WRITE2(crcbuf), TRXN_END, }; if ( BAD(BUS_transaction(len ? recv_buf : recv_crc, pn)) ) { goto out_bad; } crc = CRC16compute(p,3,0); crc = CRC16compute(&len,1,crc); if (len) crc = CRC16compute(buf,len,crc); LEVEL_DEBUG( "read CRC: GOOD, got %02x%02x",crcbuf[0],crcbuf[1]) ; if ( CRC16seeded (crcbuf,2,crc) ) { LEVEL_DEBUG("CRC error"); goto out_bad; } crcbuf[0] = ~crcbuf[0]; crcbuf[1] = ~crcbuf[1]; if ( BAD(BUS_transaction(xmit_crc, pn)) ) { goto out_bad; } *buflen = len; } LEVEL_DEBUG( "read: GOOD, got %d",*buflen) ; return ret; out_bad: return gbBAD; }