mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 09:28:40 +02:00
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:
committed by
Paul Hollinsky
parent
890eb1e1bc
commit
2d1bb381f6
@@ -23,7 +23,8 @@ enum class Command : uint8_t {
|
||||
GetVBattReq = 0xDF, // Previously known as RED_CMD_VBATT_REQUEST
|
||||
MiscControl = 0xE7,
|
||||
Extended = 0xF0,
|
||||
FlexRayControl = 0xF3
|
||||
FlexRayControl = 0xF3,
|
||||
PHYControlRegisters = 0xEF
|
||||
};
|
||||
|
||||
enum class ExtendedCommand : uint16_t {
|
||||
|
||||
@@ -22,6 +22,8 @@ public:
|
||||
bool encode(const Packetizer& packetizer, std::vector<uint8_t>& result, Command cmd, std::vector<uint8_t> arguments = {});
|
||||
|
||||
bool supportCANFD = false;
|
||||
bool supportEthPhy = false;
|
||||
|
||||
private:
|
||||
device_eventhandler_t report;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
#ifndef __ETHPHYMESSAGE_H__
|
||||
#define __ETHPHYMESSAGE_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "icsneo/communication/packet/ethphyregpacket.h"
|
||||
#include "icsneo/communication/message/message.h"
|
||||
#include "icsneo/communication/packet.h"
|
||||
#include "icsneo/api/eventmanager.h"
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
struct Clause22Message
|
||||
{
|
||||
uint8_t phyAddr;
|
||||
uint8_t page;
|
||||
uint16_t regAddr;
|
||||
uint16_t regVal;
|
||||
};
|
||||
|
||||
struct Clause45Message
|
||||
{
|
||||
uint8_t port;
|
||||
uint8_t device;
|
||||
uint16_t regAddr;
|
||||
uint16_t regVal;
|
||||
};
|
||||
|
||||
struct PhyMessage
|
||||
{
|
||||
bool Enabled;
|
||||
bool WriteEnable;
|
||||
bool Clause45Enable;
|
||||
uint8_t version;
|
||||
union
|
||||
{
|
||||
Clause22Message clause22;
|
||||
Clause45Message clause45;
|
||||
};
|
||||
};
|
||||
|
||||
//Internal message which provides an interface with device ethernet PHY registers,
|
||||
//with Clause22 and Clause45 message support
|
||||
class EthPhyMessage : public Message {
|
||||
public:
|
||||
EthPhyMessage() : Message(Message::Type::EthernetPhyRegister) {}
|
||||
bool appendPhyMessage(bool writeEnable, bool clause45, uint8_t phyAddrOrPort, uint8_t pageOrDevice, uint16_t regAddr, uint16_t regVal = 0x0000u, bool enabled = true);
|
||||
bool appendPhyMessage(std::shared_ptr<PhyMessage> message);
|
||||
size_t getMessageCount() const;
|
||||
|
||||
std::vector<std::shared_ptr<PhyMessage>> messages;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif
|
||||
@@ -26,6 +26,7 @@ public:
|
||||
DeviceVersion = 0x8004,
|
||||
Main51 = 0x8005,
|
||||
FlexRayControl = 0x8006,
|
||||
EthernetPhyRegister = 0x8007,
|
||||
};
|
||||
|
||||
Message(Type t) : type(t) {}
|
||||
|
||||
@@ -117,6 +117,7 @@ public:
|
||||
HSCAN7 = 97,
|
||||
LIN6 = 98,
|
||||
LSFTCAN2 = 99,
|
||||
EthPHYControl = 239,
|
||||
FlexRayControl = 243,
|
||||
HW_COM_Latency_Test = 512,
|
||||
DeviceStatus = 513,
|
||||
@@ -270,6 +271,7 @@ public:
|
||||
case NetID::FlexRayControl:
|
||||
case NetID::Main51:
|
||||
case NetID::ReadSettings:
|
||||
case NetID::EthPHYControl:
|
||||
return Type::Internal;
|
||||
case NetID::Invalid:
|
||||
case NetID::Any:
|
||||
@@ -504,6 +506,8 @@ public:
|
||||
return "LIN 6";
|
||||
case NetID::LSFTCAN2:
|
||||
return "LSFTCAN 2";
|
||||
case NetID::EthPHYControl:
|
||||
return "Ethernet PHY Register Control";
|
||||
case NetID::FlexRayControl:
|
||||
return "FlexRay Control";
|
||||
case NetID::HW_COM_Latency_Test:
|
||||
@@ -902,6 +906,7 @@ private:
|
||||
#define ICSNEO_NETID_HSCAN7 97
|
||||
#define ICSNEO_NETID_LIN6 98
|
||||
#define ICSNEO_NETID_LSFTCAN2 99
|
||||
#define ICSNEO_NETID_ETH_PHY_CONTROL 239
|
||||
#define ICSNEO_NETID_FLEXRAY_CONTROL 243
|
||||
#define ICSNEO_NETID_HW_COM_LATENCY_TEST 512
|
||||
#define ICSNEO_NETID_DEVICE_STATUS 513
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user