Device: Implement Ethernet PHY MDIO Communication

The following fixups were added during the squash/merge:

Fix formatting in EthPhyMessage and EthPhyRegPacket
Device: Use std::make_shared when creating the EthPHYControl filter
Network: Create NetID String for EthPHYControl
EthPhyRegPacket: Constants in PascalCase
This commit is contained in:
Kyle Johannes
2021-12-08 19:07:07 -05:00
committed by Paul Hollinsky
parent 890eb1e1bc
commit 2d1bb381f6
21 changed files with 421 additions and 1 deletions
@@ -0,0 +1,77 @@
#ifndef __ETHPHYREGPACKET_H__
#define __ETHPHYREGPACKET_H__
#ifdef __cplusplus
#include "icsneo/communication/message/ethphymessage.h"
#include "icsneo/api/eventmanager.h"
#include <cstdint>
#include <memory>
namespace icsneo
{
class Packetizer;
class EthPhyMessage;
typedef struct
{
uint16_t numEntries;
uint8_t version;
uint8_t entryBytes;
} PhyRegisterHeader_t;
typedef struct
{
uint8_t phyAddr; //5 bits
uint8_t page; //8 bits
uint16_t regAddr; //5 bits
uint16_t regVal;
} Clause22Message_t; //6 bytes
typedef struct
{
uint8_t port; //5 bits
uint8_t device; //5 bits
uint16_t regAddr;
uint16_t regVal;
} Clause45Message_t; //6 bytes
typedef struct
{
union
{
struct
{
uint16_t Enabled : 1;
uint16_t WriteEnable : 1;
uint16_t Clause45Enable : 1;
uint16_t reserved : 9;
uint16_t version : 4;
};
uint16_t flags;
};
union
{
Clause22Message_t clause22;
Clause45Message_t clause45;
};
} PhyRegisterPacket_t;
static constexpr size_t MaxPhyEntries = 128u;
static constexpr size_t MaxBytesPhyEntries = MaxPhyEntries * sizeof(PhyRegisterHeader_t);
static constexpr uint8_t PhyPacketVersion = 1u;
static constexpr uint8_t FiveBits = 0x1Fu;
struct HardwareEthernetPhyRegisterPacket
{
static std::shared_ptr<EthPhyMessage> DecodeToMessage(const std::vector<uint8_t>& bytestream, const device_eventhandler_t& report);
static bool EncodeFromMessage(const EthPhyMessage& message, std::vector<uint8_t>& bytestream, const device_eventhandler_t& report);
};
}
#endif //__cplusplus
#endif