mirror of
https://github.com/eclipse/upm.git
synced 2025-03-24 01:10:22 +03:00
m24lr64e: throw exception(s) on fatal errors
Signed-off-by: Jon Trulson <jtrulson@ics.com> Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
parent
36237ae596
commit
6db7dfd3d9
@ -44,8 +44,8 @@ M24LR64E::M24LR64E(int bus, AccessMode mode):
|
|||||||
mraa::Result rv;
|
mraa::Result rv;
|
||||||
if ( (rv = m_i2c.address(m_addr)) != mraa::SUCCESS)
|
if ( (rv = m_i2c.address(m_addr)) != mraa::SUCCESS)
|
||||||
{
|
{
|
||||||
cerr << "M24LR64E: Could not initialize i2c address. " << endl;
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
printError(rv);
|
": I2c.address() failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,7 +78,8 @@ bool M24LR64E::submitPasswd(uint32_t passwd)
|
|||||||
|
|
||||||
if (m_i2c.write(buf, pktLen))
|
if (m_i2c.write(buf, pktLen))
|
||||||
{
|
{
|
||||||
cerr << __FUNCTION__ << "@" << __LINE__ << ": write failed" << endl;
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
|
": I2c.write() failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +109,8 @@ bool M24LR64E::writePasswd(uint32_t passwd)
|
|||||||
|
|
||||||
if (m_i2c.write(buf, pktLen))
|
if (m_i2c.write(buf, pktLen))
|
||||||
{
|
{
|
||||||
cerr << __FUNCTION__ << "@" << __LINE__ << ": write failed" << endl;
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
|
": I2c.write() failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,7 +220,8 @@ mraa::Result M24LR64E::EEPROM_Write_Byte(unsigned int address, uint8_t data)
|
|||||||
buf[2] = data;
|
buf[2] = data;
|
||||||
|
|
||||||
if ((rv = m_i2c.write(buf, pktLen)))
|
if ((rv = m_i2c.write(buf, pktLen)))
|
||||||
cerr << __FUNCTION__ << "@" << __LINE__ << ": write failed" << endl;
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
|
": I2c.write() failed");
|
||||||
|
|
||||||
usleep(I2C_WRITE_TIME * 1000);
|
usleep(I2C_WRITE_TIME * 1000);
|
||||||
return rv;
|
return rv;
|
||||||
@ -238,7 +241,8 @@ mraa::Result M24LR64E::EEPROM_Write_Bytes(unsigned int address, uint8_t* data,
|
|||||||
buf[2+i] = data[i];
|
buf[2+i] = data[i];
|
||||||
|
|
||||||
if ((rv = m_i2c.write(buf, pktLen)))
|
if ((rv = m_i2c.write(buf, pktLen)))
|
||||||
cerr << __FUNCTION__ << "@" << __LINE__ << ": write failed" << endl;
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
|
": I2c.write() failed");
|
||||||
|
|
||||||
usleep(I2C_WRITE_TIME * 1000);
|
usleep(I2C_WRITE_TIME * 1000);
|
||||||
|
|
||||||
@ -255,7 +259,8 @@ uint8_t M24LR64E::EEPROM_Read_Byte(unsigned int address)
|
|||||||
|
|
||||||
if (m_i2c.write(abuf, apktLen))
|
if (m_i2c.write(abuf, apktLen))
|
||||||
{
|
{
|
||||||
cerr << __FUNCTION__ << "@" << __LINE__ << ": write failed" << endl;
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
|
": I2c.write() failed");
|
||||||
return 0x00;
|
return 0x00;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,7 +271,8 @@ uint8_t M24LR64E::EEPROM_Read_Byte(unsigned int address)
|
|||||||
|
|
||||||
if (m_i2c.read(buf, pktLen) != pktLen)
|
if (m_i2c.read(buf, pktLen) != pktLen)
|
||||||
{
|
{
|
||||||
cerr << __FUNCTION__ << "@" << __LINE__ << ": read failed" << endl;
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
|
": I2c.write() failed");
|
||||||
return 0x00;
|
return 0x00;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,14 +290,16 @@ int M24LR64E::EEPROM_Read_Bytes(unsigned int address,
|
|||||||
|
|
||||||
if (m_i2c.write(abuf, apktLen))
|
if (m_i2c.write(abuf, apktLen))
|
||||||
{
|
{
|
||||||
cerr << __FUNCTION__ << "@" << __LINE__ << ": write failed" << endl;
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
|
": I2c.write() failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rv = m_i2c.read(buffer, len);
|
int rv = m_i2c.read(buffer, len);
|
||||||
if (rv != len)
|
if (rv != len)
|
||||||
{
|
{
|
||||||
cerr << __FUNCTION__ << "@" << __LINE__ << ": read failed" << endl;
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
|
": I2c.read() failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user