I2C: Network support

This commit is contained in:
Kyle Johannes
2022-10-18 00:12:16 +00:00
parent 13ec2bca98
commit 9817887523
12 changed files with 328 additions and 3 deletions
+1
View File
@@ -89,6 +89,7 @@ public:
AtomicOperationCompletedNonatomically = 0x2035,
WiVIStackRefreshFailed = 0x2036,
WiVIUploadStackOverflow = 0x2037,
I2CMessageExceedsMaxLength = 0x2038,
// Transport Events
FailedToRead = 0x3000,
@@ -0,0 +1,48 @@
#ifndef __I2CMESSAGE_H_
#define __I2CMESSAGE_H_
#ifdef __cplusplus
#include "icsneo/communication/message/message.h"
#include <vector>
namespace icsneo {
class I2CMessage : public Frame {
public:
enum class DeviceMode : uint8_t {
Target = 0,
Controller = 1
};
enum class Direction : uint8_t {
Write = 0,
Read = 1
};
bool isExtendedID = false;
bool isTXMsg = false;
bool txError = false;
bool txLostArb = false;
bool txAborted = false;
bool txNack = false;
bool txTimeout = false;
uint16_t stats = static_cast<uint16_t>(0x0000u);
uint16_t address;
Direction direction;
DeviceMode deviceMode;
//Must contain the target register address to read or write
std::vector<uint8_t> controlBytes;
//The device expects a dataBytes payload even if you're reading
//In the case of a read these bytes aren't interesting, but they have to be there
//Add bytes to write, or the same number of junk bytes you expect the device send back
std::vector<uint8_t> dataBytes;
};
}
#endif // __cplusplus
#endif
@@ -0,0 +1,61 @@
#ifndef __I2CPACKET_H__
#define __I2CPACKET_H__
#ifdef __cplusplus
#include "icsneo/communication/message/i2cmessage.h"
#include "icsneo/api/eventmanager.h"
#include "icsneo/communication/packetizer.h"
#include "icsneo/communication/network.h"
#include <cstdint>
#include <memory>
namespace icsneo {
static constexpr size_t I2CMaxLength = 1024u;
#pragma pack(push, 2)
struct I2CHeader {
struct {
// C1xI2C
uint16_t ID : 10;// i2c address, 7-bit or 10-bit
uint16_t EID : 1;// using extended addressing, i.e. 10-bit
uint16_t CT : 1;// Controller/Target
uint16_t DIR : 1;// read/write
uint16_t RESERVED_0 : 3;
// C2xI2C
uint16_t TXMsg: 1;
uint16_t CBLen: 11;
uint16_t RESERVED_1: 4;
// C3xI2C
uint16_t TXTimeout : 1;
uint16_t TXNack : 1;
uint16_t TXAborted : 1;
uint16_t TXLostArb : 1;
uint16_t TXError : 1;
uint16_t RESERVED_2: 11;
} CoreMiniBitsI2C;
uint8_t coreMiniMessageData[8];
uint16_t stats;
uint64_t timestamp;
uint16_t networkID;
uint16_t length;
};
#pragma pack(pop)
struct HardwareI2CPacket {
static std::shared_ptr<Message> DecodeToMessage(const std::vector<uint8_t>& bytestream);
static bool EncodeFromMessage(const I2CMessage& message, std::vector<uint8_t>& bytestream, const device_eventhandler_t& report);
};
}
#endif //_cplusplus
#endif
+4 -1
View File
@@ -28,7 +28,10 @@ public:
Network::NetID::LIN,
Network::NetID::A2B1,
Network::NetID::A2B2
Network::NetID::A2B2,
Network::NetID::I2C,
Network::NetID::I2C2
};
return supportedNetworks;
}
@@ -59,7 +59,12 @@ protected:
Network::NetID::LIN,
Network::NetID::FlexRay
Network::NetID::FlexRay,
Network::NetID::I2C,
Network::NetID::I2C2,
Network::NetID::I2C3,
Network::NetID::I2C4,
};
rxNetworks.insert(rxNetworks.end(), supportedRxNetworks.begin(), supportedRxNetworks.end());
}
+1
View File
@@ -16,6 +16,7 @@
#include "icsneo/communication/message/iso9141message.h"
#include "icsneo/communication/message/canerrorcountmessage.h"
#include "icsneo/communication/message/ethphymessage.h"
#include "icsneo/communication/message/i2cmessage.h"
#include "icsneo/communication/message/a2bmessage.h"
namespace icsneo {