TEST(PlatformTypes, EndianSwap)
{
   U32 swap32 = 0xABCDEF12;
   U16 swap16 = 0xABCD;
      
   EXPECT_EQ(endianSwap(swap32), 0x12EFCDAB)
      << "32 bit endianSwap should reverse byte order, but didn't.";
   EXPECT_EQ(endianSwap(swap16), 0xCDAB)
      << "16 bit endianSwap should reverse byte order, but didn't.";
};
Beispiel #2
0
HUBTEXT int  i2c_in(i2c *busID, int i2cAddr, 
                     int memAddr, int memAddrCount, 
                     unsigned char *data, int dataCount)
{
  int n  = 0;
  i2cAddr <<= 1;
  i2cAddr &= -2;                                        // Clear i2cAddr.bit0 (write)
  i2c_start(busID);
  if(i2c_writeByte(busID, i2cAddr)) return n; else n++;
  if(memAddrCount) 
  {
    int m;
    if(memAddrCount)
    {
      if(memAddrCount > 0)
      {
        endianSwap(&m, &memAddr, memAddrCount);
      }  
      else 
      {
        m = memAddr;
        memAddrCount = - memAddrCount;
      }  
      n += i2c_writeData(busID, (unsigned char*) &m, memAddrCount);
    }  
  }  
  i2cAddr |= 1;                                       // Set i2cAddr.bit0 (read)
  i2c_start(busID);
  if(i2c_writeByte(busID, i2cAddr)) return n; else n++;
  n += i2c_readData(busID, data, abs(dataCount));
  i2c_stop(busID);
  if(dataCount < 0)
  {
    dataCount = -dataCount;
    char temp[dataCount];
    memcpy(temp, data, dataCount);
    endianSwap(data, temp, dataCount);
  }
  return n;  
}
Beispiel #3
0
HUBTEXT int  i2c_out(i2c *busID, int i2cAddr, 
                     int memAddr, int memAddrCount, 
                     const unsigned char *data, int dataCount)
{
  int n  = 0;
  i2cAddr <<= 1;
  i2cAddr &= -2;
  i2c_start(busID);
  if(i2c_writeByte(busID, i2cAddr)) return n; else n++;
  int m;
  if(memAddrCount)
  {
    if(memAddrCount > 0)
    {
      endianSwap(&m, &memAddr, memAddrCount);
    }  
    else 
    {
      m = memAddr;
      memAddrCount = - memAddrCount;
    }  
    n += i2c_writeData(busID, (unsigned char*) &m, memAddrCount);
  }  
  if(dataCount)
  {
    if(dataCount > 0)
      n += i2c_writeData(busID, data, dataCount);
    else  
    {
      dataCount = -dataCount;
      unsigned char temp[dataCount];
      endianSwap(temp, (void*) data, dataCount);
      n += i2c_writeData(busID, temp, dataCount);
    }        
  }  
  i2c_stop(busID);
  return n;  
}