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:
Jon Trulson 2015-09-10 13:57:15 -06:00 committed by Mihai Tudor Panu
parent 36237ae596
commit 6db7dfd3d9

View File

@ -44,8 +44,8 @@ M24LR64E::M24LR64E(int bus, AccessMode mode):
mraa::Result rv;
if ( (rv = m_i2c.address(m_addr)) != mraa::SUCCESS)
{
cerr << "M24LR64E: Could not initialize i2c address. " << endl;
printError(rv);
throw std::runtime_error(std::string(__FUNCTION__) +
": I2c.address() failed");
return;
}
}
@ -78,7 +78,8 @@ bool M24LR64E::submitPasswd(uint32_t passwd)
if (m_i2c.write(buf, pktLen))
{
cerr << __FUNCTION__ << "@" << __LINE__ << ": write failed" << endl;
throw std::runtime_error(std::string(__FUNCTION__) +
": I2c.write() failed");
return false;
}
@ -108,7 +109,8 @@ bool M24LR64E::writePasswd(uint32_t passwd)
if (m_i2c.write(buf, pktLen))
{
cerr << __FUNCTION__ << "@" << __LINE__ << ": write failed" << endl;
throw std::runtime_error(std::string(__FUNCTION__) +
": I2c.write() failed");
return false;
}
@ -218,7 +220,8 @@ mraa::Result M24LR64E::EEPROM_Write_Byte(unsigned int address, uint8_t data)
buf[2] = data;
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);
return rv;
@ -238,7 +241,8 @@ mraa::Result M24LR64E::EEPROM_Write_Bytes(unsigned int address, uint8_t* data,
buf[2+i] = data[i];
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);
@ -255,7 +259,8 @@ uint8_t M24LR64E::EEPROM_Read_Byte(unsigned int address)
if (m_i2c.write(abuf, apktLen))
{
cerr << __FUNCTION__ << "@" << __LINE__ << ": write failed" << endl;
throw std::runtime_error(std::string(__FUNCTION__) +
": I2c.write() failed");
return 0x00;
}
@ -266,7 +271,8 @@ uint8_t M24LR64E::EEPROM_Read_Byte(unsigned int address)
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;
}
@ -284,14 +290,16 @@ int M24LR64E::EEPROM_Read_Bytes(unsigned int address,
if (m_i2c.write(abuf, apktLen))
{
cerr << __FUNCTION__ << "@" << __LINE__ << ": write failed" << endl;
throw std::runtime_error(std::string(__FUNCTION__) +
": I2c.write() failed");
return false;
}
int rv = m_i2c.read(buffer, len);
if (rv != len)
{
cerr << __FUNCTION__ << "@" << __LINE__ << ": read failed" << endl;
throw std::runtime_error(std::string(__FUNCTION__) +
": I2c.read() failed");
}
return rv;