Implementation of 1-Wire with added Alarm Search Functionality
Dependents: Max32630_One_Wire_Interface
Diff: OneWire_Masters/DS248x/ds248x.cpp
- Revision:
- 15:f6cb0d906fb6
- Parent:
- 14:7b2886a50321
- Child:
- 17:b646b1e3970b
diff -r 7b2886a50321 -r f6cb0d906fb6 OneWire_Masters/DS248x/ds248x.cpp --- a/OneWire_Masters/DS248x/ds248x.cpp Tue Mar 15 01:38:17 2016 +0000 +++ b/OneWire_Masters/DS248x/ds248x.cpp Wed Mar 16 01:19:45 2016 +0000 @@ -329,20 +329,6 @@ //********************************************************************* -void Ds248x::OWWriteBit(uint8_t sendbit) -{ - OWTouchBit(sendbit); -} - - -//********************************************************************* -uint8_t Ds248x::OWReadBit() -{ - return(OWTouchBit(0x01)); -} - - -//********************************************************************* uint8_t Ds248x::OWTouchBit(uint8_t sendbit) { uint8_t rtn_val; @@ -487,173 +473,6 @@ //********************************************************************* -uint8_t Ds248x::OWTouchByte(uint8_t sendbyte) -{ - uint8_t rtn_val; - - if (sendbyte == 0xFF) - { - rtn_val = OWReadByte(); - } - else - { - OWWriteByte(sendbyte); - rtn_val = sendbyte; - } - - return(rtn_val); -} - - -//********************************************************************* -void Ds248x::OWBlock(uint8_t *tran_buf, uint8_t tran_len) -{ - uint8_t i; - - for (i = 0; i < tran_len; i++) - { - tran_buf[i] = OWTouchByte(tran_buf[i]); - } -} - - -//********************************************************************* -void Ds248x::OWWriteBlock(const uint8_t *tran_buf, uint8_t tran_len) -{ - uint8_t idx; - - for(idx = 0; idx < tran_len; idx++) - { - OWWriteByte(tran_buf[idx]); - } -} - - -//********************************************************************* -void Ds248x::OWReadBlock(uint8_t *recv_buf, uint8_t recv_len) -{ - uint8_t idx; - - for(idx = 0; idx < recv_len; idx++) - { - recv_buf[idx] = OWReadByte(); - } -} - - -//********************************************************************* -bool Ds248x::OWFirst(void) -{ - // reset the search state - _last_discrepancy = 0; - _last_device_flag = false; - _last_family_discrepancy = 0; - - return OWSearch(); -} - - -//********************************************************************* -bool Ds248x::OWNext(void) -{ - // leave the search state alone - return OWSearch(); -} - - -//********************************************************************* -bool Ds248x::OWVerify(void) -{ - bool rtn_val = false; - - uint8_t rom_backup[8]; - uint8_t i,rslt,ld_backup,ldf_backup,lfd_backup; - - // keep a backup copy of the current state - for (i = 0; i < 8; i++) - { - rom_backup[i] = _rom_number[i]; - } - - ld_backup = _last_discrepancy; - ldf_backup = _last_device_flag; - lfd_backup = _last_family_discrepancy; - - // set search to find the same device - _last_discrepancy = 64; - _last_device_flag = false; - - if (OWSearch()) - { - // check if same device found - rslt = true; - for (i = 0; i < 8; i++) - { - if (rom_backup[i] != _rom_number[i]) - { - rslt = false; - break; - } - } - } - else - { - rslt = false; - } - - // restore the search state - for (i = 0; i < 8; i++) - { - _rom_number[i] = rom_backup[i]; - } - - _last_discrepancy = ld_backup; - _last_device_flag = ldf_backup; - _last_family_discrepancy = lfd_backup; - - // return the result of the verify - rtn_val = rslt; - - return(rtn_val); -} - - -//********************************************************************* -void Ds248x::OWTargetSetup(uint8_t family_code) -{ - uint8_t i; - - // set the search state to find SearchFamily type devices - _rom_number[0] = family_code; - for (i = 1; i < 8; i++) - { - _rom_number[i] = 0; - } - - _last_discrepancy = 64; - _last_family_discrepancy = 0; - _last_device_flag = false; -} - - -//********************************************************************* -void Ds248x::OWFamilySkipSetup(void) -{ - // set the Last discrepancy to last family discrepancy - _last_discrepancy = _last_family_discrepancy; - - // clear the last family discrpepancy - _last_family_discrepancy = 0; - - // check for end of list - if (_last_discrepancy == 0) - { - _last_device_flag = true; - } -} - - -//********************************************************************* bool Ds248x::OWSearch(void) { uint8_t id_bit_number; @@ -779,172 +598,6 @@ //********************************************************************* -bool Ds248x::OWReadROM(void) -{ - bool rtn_val = false; - - if(!OWReset()) - { - rtn_val = false; - } - else - { - if(!OWWriteByte(READ_ROM)) - { - rtn_val = false; - } - else - { - OWReadBlock(_rom_number, ROMnumberLen); - rtn_val = true; - } - } - - return rtn_val; -} - - -//********************************************************************* -bool Ds248x::OWSkipROM(void) -{ - bool rtn_val = false; - - if(!OWReset()) - { - rtn_val = false; - } - else - { - if(!OWWriteByte(SKIP_ROM)) - { - rtn_val = false; - } - else - { - rtn_val = true; - } - } - - return rtn_val; -} - - -//********************************************************************* -bool Ds248x::OWMatchROM(void) -{ - bool rtn_val = false; - uint8_t idx; - - if(!OWReset()) - { - rtn_val = false; - } - else - { - if(!OWWriteByte(MATCH_ROM)) - { - rtn_val = false; - } - else - { - for(idx = 0; idx < ROMnumberLen; idx++) - { - OWWriteByte(_rom_number[idx]); - } - rtn_val = true; - } - } - - return rtn_val; -} - - -//********************************************************************* -bool Ds248x::OWOverdriveSkipROM(void) -{ - bool rtn_val = false; - - if(!OWReset()) - { - rtn_val = false; - } - else - { - if(!OWWriteByte(OVERDRIVE_SKIP)) - { - rtn_val = false; - } - else - { - //change speed for subsequent comands - OWSpeed(SPEED_OVERDRIVE); - rtn_val = true; - } - } - - return rtn_val; -} - - -//********************************************************************* -bool Ds248x::OWOverdriveMatchROM(void) -{ - bool rtn_val = false; - uint8_t idx; - - if(!OWReset()) - { - rtn_val = false; - } - else - { - if(!OWWriteByte(OVERDRIVE_MATCH)) - { - rtn_val = false; - } - else - { - //change speed before sending ROM number - OWSpeed(SPEED_OVERDRIVE); - - for(idx = 0; idx < ROMnumberLen; idx++) - { - OWWriteByte(_rom_number[idx]); - } - rtn_val = true; - } - } - - return rtn_val; -} - - -//********************************************************************* -bool Ds248x::OWResume(void) -{ - bool rtn_val = false; - - if(!OWReset()) - { - rtn_val = false; - } - else - { - if(!OWWriteByte(RESUME)) - { - rtn_val = false; - } - else - { - rtn_val = true; - } - } - - return rtn_val; -} - - -//********************************************************************* uint8_t Ds248x::OWSpeed(OW_SPEED new_speed) { // set the speed @@ -1046,13 +699,6 @@ //********************************************************************* -const uint8_t (&Ds248x::OWgetROMnumber() const)[ROMnumberLen] -{ - return _rom_number; -} - - -//********************************************************************* void Ds248x::set_i2c_adrs(DS248X_I2C_ADRS adrs) { _w_adrs = (adrs << 1);