diff options
author | Tobias Jahnke <tjahnk@users.noreply.github.com> | 2017-08-23 10:53:41 +0200 |
---|---|---|
committer | Tobias Jahnke <tjahnk@users.noreply.github.com> | 2017-08-23 13:15:10 +0200 |
commit | 620164975a968c4404c96f3e9ed1a7b9a63d6cb6 (patch) | |
tree | 23d80092c94c0b6100b2c8a03be0fc863f27a600 /HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src | |
parent | c3d250fbc63c05d7f0ad5c4d95d725a16f3cece4 (diff) |
implements value retransmit and reload on failure
Diffstat (limited to 'HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src')
-rw-r--r-- | HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/device_container.cpp | 11 | ||||
-rw-r--r-- | HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/device_value.cpp | 66 |
2 files changed, 47 insertions, 30 deletions
diff --git a/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/device_container.cpp b/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/device_container.cpp index 4c99c89..f8b1961 100644 --- a/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/device_container.cpp +++ b/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/device_container.cpp @@ -24,7 +24,7 @@ #include <stddef.h> #include "device_container.h" -#define DEVCONT_TIME_RETRIGGER (uint16_t)100U +#define DEVCONT_TIME_RETRIGGER (uint16_t)30U #define DEVCONT_TIME_NOW (uint16_t)0U #define DEVCONT_TIME_STOP (uint16_t)0xFFFFU @@ -123,13 +123,14 @@ void CDeviceContainer::Update() &OnI2cResult, this)) { - /*Clb_RegisterI2CResultCB(&OnI2cResult, this);*/ this->_tx_busy = true; + error = false; break; } else { error = true; + break; } } } @@ -142,9 +143,11 @@ void CDeviceContainer::Update() void CDeviceContainer::HandleI2cResult(uint8_t result) { - DEVCONT_UNUSED(result); this->_tx_busy = false; - this->RequestService(DEVCONT_TIME_NOW); + if (result == 0) + this->RequestService(DEVCONT_TIME_NOW); + else + this->RequestService(DEVCONT_TIME_RETRIGGER); } void CDeviceContainer::OnI2cResult(uint8_t result, void *obj_ptr) diff --git a/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/device_value.cpp b/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/device_value.cpp index b5f5679..7103192 100644 --- a/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/device_value.cpp +++ b/HAL-afb/HAL_MOST_UNICENS/ucs2-vol/src/device_value.cpp @@ -20,7 +20,7 @@ * Please contact Microchip for further information. * */ - +#include <stddef.h> #include "device_value.h" #include "setup.h" @@ -34,11 +34,14 @@ CDeviceValue::CDeviceValue(uint16_t address, DeviceValueType type, uint16_t key) { - this->_is_initial = true; this->_is_available = false; + this->_is_busy = false; this->_address = address; this->_target_value = 0x01u; this->_actual_value = 0x01u; + + this->_result_fptr = NULL; + this->_result_user_ptr = NULL; this->_type = type; this->_key = key; @@ -86,7 +89,7 @@ void CDeviceValue::ApplyMostValue(uint8_t value, DeviceValueType type, uint8_t t // returns true if target is not actual value bool CDeviceValue::RequiresUpdate() { - if (this->_is_available && (this->_target_value != this->_actual_value)) + if (this->_is_available && !this->_is_busy && (this->_target_value != this->_actual_value)) { return true; } @@ -101,34 +104,45 @@ bool CDeviceValue::FireUpdateMessage(lib_most_volume_writei2c_cb_t writei2c_fptr int ret = -1; ApplyMostValue(this->_target_value, _type, _tx_payload); - if (this->_is_available) + if (this->_is_available && !this->_is_busy) { ret = writei2c_fptr(this->_address, &_tx_payload[0], _tx_payload_sz, - result_fptr, - result_user_ptr); + &OnI2cResult, + this); + + if (ret == 0) + { + this->_transmitted_value = this->_target_value; + this->_is_busy = true; + this->_result_fptr = result_fptr; + this->_result_user_ptr = result_user_ptr; + return true; + } } - if (ret == 0) + return false; +} + +void CDeviceValue::HandleI2cResult(uint8_t result) +{ + if (result == 0) { - // Clb_RegisterI2CResultCB(OnI2cResult, this); - // mark value as set! - this->_actual_value = this->_target_value; - return true; + /* transmission succeeded - now apply transmitted value */ + this->_actual_value = this->_transmitted_value; } - - return false; + + if (this->_result_fptr) + { + /* notify container */ + this->_result_fptr(result, this->_result_user_ptr); + } + + this->_result_fptr = NULL; + this->_result_user_ptr = NULL; + this->_is_busy = false; } -#if 0 - ret = Ucs_I2c_WritePort( CSetup::GetInstance()->RetrieveUnicensInst(), - this->_address, - 0x0F00u, /* i2c port handle */ - UCS_I2C_DEFAULT_MODE, /* 0 */ - 0u, /* block count */ - 0x2Au, /* i2c slave address */ - 0x03E8u, /* timeout 1000 milliseconds */ - _tx_payload_sz, /* data length */ - &_tx_payload[0], /* data pointer */ - &Clb_OnWriteI2CPortResult - ); -#endif +void CDeviceValue::OnI2cResult(uint8_t result, void *obj_ptr) +{ + ((CDeviceValue*)obj_ptr)->HandleI2cResult(result); +} |