From 8a9b004d79cf0914ae7c8ba96f40da4aa9d8b93b Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Tue, 26 Nov 2024 06:05:17 +0100 Subject: [PATCH 1/4] Fix: actual type is bool, not uint8_t. --- src/T1SMacSettings.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/T1SMacSettings.h b/src/T1SMacSettings.h index 54c89d8..ac63ca4 100644 --- a/src/T1SMacSettings.h +++ b/src/T1SMacSettings.h @@ -43,7 +43,7 @@ class T1SMacSettings : public arduino::Printable virtual size_t printTo(Print & p) const override; - uint8_t mac_promiscuous_mode() const { return _mac_promiscuous_mode; } - uint8_t mac_tx_cut_through() const { return _mac_tx_cut_through; } - uint8_t mac_rx_cut_through() const { return _mac_rx_cut_through; } + bool mac_promiscuous_mode() const { return _mac_promiscuous_mode; } + bool mac_tx_cut_through() const { return _mac_tx_cut_through; } + bool mac_rx_cut_through() const { return _mac_rx_cut_through; } }; From 67e4d232e0c06d3a4131406eebc37a774611f6e3 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Tue, 26 Nov 2024 06:07:09 +0100 Subject: [PATCH 2/4] Turn function names from snake_case to camel_case. --- src/T1SMacSettings.h | 6 +++--- src/T1SPlcaSettings.h | 8 ++++---- src/microchip/TC6_Arduino_10BASE_T1S.cpp | 22 +++++++++++----------- src/microchip/TC6_Io.cpp | 6 +++--- src/microchip/TC6_Io.h | 6 +++--- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/T1SMacSettings.h b/src/T1SMacSettings.h index ac63ca4..0fc54ff 100644 --- a/src/T1SMacSettings.h +++ b/src/T1SMacSettings.h @@ -43,7 +43,7 @@ class T1SMacSettings : public arduino::Printable virtual size_t printTo(Print & p) const override; - bool mac_promiscuous_mode() const { return _mac_promiscuous_mode; } - bool mac_tx_cut_through() const { return _mac_tx_cut_through; } - bool mac_rx_cut_through() const { return _mac_rx_cut_through; } + bool isMacPromiscuousModeEnabled() const { return _mac_promiscuous_mode; } + bool isMacTxCutThroughEnabled() const { return _mac_tx_cut_through; } + bool isMacRxCutThroughEnabled() const { return _mac_rx_cut_through; } }; diff --git a/src/T1SPlcaSettings.h b/src/T1SPlcaSettings.h index 280215e..502da2c 100644 --- a/src/T1SPlcaSettings.h +++ b/src/T1SPlcaSettings.h @@ -49,8 +49,8 @@ class T1SPlcaSettings : public arduino::Printable virtual size_t printTo(Print & p) const override; - uint8_t node_id() const { return _node_id; } - uint8_t node_count() const { return _node_count; } - uint8_t burst_count() const { return _burst_count; } - uint8_t burst_timer() const { return _burst_timer; } + uint8_t nodeId() const { return _node_id; } + uint8_t nodeCount() const { return _node_count; } + uint8_t burstCount() const { return _burst_count; } + uint8_t burstTimer() const { return _burst_timer; } }; diff --git a/src/microchip/TC6_Arduino_10BASE_T1S.cpp b/src/microchip/TC6_Arduino_10BASE_T1S.cpp index 208040a..830650d 100644 --- a/src/microchip/TC6_Arduino_10BASE_T1S.cpp +++ b/src/microchip/TC6_Arduino_10BASE_T1S.cpp @@ -156,13 +156,13 @@ bool TC6_Arduino_10BASE_T1S::begin(IPAddress const ip_addr, , &_lw , _lw.ip.mac , true /* enable_plca */ - , t1s_plca_settings.node_id() - , t1s_plca_settings.node_count() - , t1s_plca_settings.burst_count() - , t1s_plca_settings.burst_timer() - , t1s_mac_settings.mac_promiscuous_mode() - , t1s_mac_settings.mac_tx_cut_through() - , t1s_mac_settings.mac_rx_cut_through())) + , t1s_plca_settings.nodeId() + , t1s_plca_settings.nodeCount() + , t1s_plca_settings.burstCount() + , t1s_plca_settings.burstTimer() + , t1s_mac_settings.isMacPromiscuousModeEnabled() + , t1s_mac_settings.isMacTxCutThroughEnabled() + , t1s_mac_settings.isMacRxCutThroughEnabled())) return false; /* Complete initialization. */ @@ -206,11 +206,11 @@ void TC6_Arduino_10BASE_T1S::service() { sys_check_timeouts(); /* LWIP timers - ARP, DHCP, TCP, etc. */ - if (_tc6_io->is_interrupt_active()) + if (_tc6_io->isInterruptActive()) { if (TC6_Service(_lw.tc.tc6, false)) { - _tc6_io->release_interrupt(); + _tc6_io->releaseInterrupt(); } } else if (_lw.tc.tc6NeedService) { @@ -229,7 +229,7 @@ bool TC6_Arduino_10BASE_T1S::getPlcaStatus(TC6LwIP_On_PlcaStatus on_plca_status) bool TC6_Arduino_10BASE_T1S::enablePlca() { - return TC6Regs_SetPlca(_lw.tc.tc6, true, _t1s_plca_settings.node_id(), _t1s_plca_settings.node_count()); + return TC6Regs_SetPlca(_lw.tc.tc6, true, _t1s_plca_settings.nodeId(), _t1s_plca_settings.nodeCount()); } bool TC6_Arduino_10BASE_T1S::sendWouldBlock() @@ -389,7 +389,7 @@ bool TC6_CB_OnSpiTransaction(TC6_t *pInst, uint8_t *pTx, uint8_t *pRx, uint16_t if (lw == nullptr) { return false; } - bool const success = lw->io->spi_transaction(pTx, pRx, len); + bool const success = lw->io->spiTransaction(pTx, pRx, len); TC6_SpiBufferDone(pInst /* tc6instance */, success /* success */); return success; } diff --git a/src/microchip/TC6_Io.cpp b/src/microchip/TC6_Io.cpp index 2886141..4ea90d3 100644 --- a/src/microchip/TC6_Io.cpp +++ b/src/microchip/TC6_Io.cpp @@ -73,19 +73,19 @@ void TC6_Io::onInterrupt() _int_in++; } -bool TC6_Io::is_interrupt_active() +bool TC6_Io::isInterruptActive() { _int_reported = _int_in; return (_int_reported != _int_out); } -void TC6_Io::release_interrupt() +void TC6_Io::releaseInterrupt() { if (digitalRead(_irq_pin) == HIGH) _int_out = _int_reported; } -bool TC6_Io::spi_transaction(uint8_t const *pTx, uint8_t *pRx, uint16_t const len) +bool TC6_Io::spiTransaction(uint8_t const *pTx, uint8_t *pRx, uint16_t const len) { digitalWrite(_cs_pin, LOW); _spi.beginTransaction(LAN865x_SPI_SETTING); diff --git a/src/microchip/TC6_Io.h b/src/microchip/TC6_Io.h index 0568974..2efc54a 100644 --- a/src/microchip/TC6_Io.h +++ b/src/microchip/TC6_Io.h @@ -44,11 +44,11 @@ class TC6_Io void onInterrupt(); - bool is_interrupt_active(); + bool isInterruptActive(); - void release_interrupt(); + void releaseInterrupt(); - bool spi_transaction(uint8_t const *pTx, uint8_t *pRx, uint16_t const len); + bool spiTransaction(uint8_t const *pTx, uint8_t *pRx, uint16_t const len); private: From e0c1bfc0c79e14e1cc6c6dfb4f15d3d330676532 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Mon, 2 Dec 2024 14:17:04 +0100 Subject: [PATCH 3/4] Replace pointers in favour of references. --- examples/UDP_Client/UDP_Client.ino | 16 ++++++++-------- examples/UDP_Server/UDP_Server.ino | 16 ++++++++-------- examples/tools/Control-DIOx/Control-DIOx.ino | 14 +++++++------- .../PoDL-Sink-Auto-TurnOff.ino | 16 ++++++++-------- examples/tools/PoDL-Source/PoDL-Source.ino | 16 ++++++++-------- src/microchip/TC6_Arduino_10BASE_T1S.cpp | 8 ++++---- src/microchip/TC6_Arduino_10BASE_T1S.h | 4 ++-- 7 files changed, 45 insertions(+), 45 deletions(-) diff --git a/examples/UDP_Client/UDP_Client.ino b/examples/UDP_Client/UDP_Client.ino index e34eb4f..dd7e69b 100644 --- a/examples/UDP_Client/UDP_Client.ino +++ b/examples/UDP_Client/UDP_Client.ino @@ -34,7 +34,7 @@ static uint16_t const UDP_SERVER_PORT = 8888; * GLOBAL VARIABLES **************************************************************************************/ -auto const tc6_io = new TC6::TC6_Io( +TC6::TC6_Io tc6_io( #if defined(ARDUINO_GIGA) || defined(ARDUINO_PORTENTA_C33) SPI1 #else @@ -43,7 +43,7 @@ auto const tc6_io = new TC6::TC6_Io( , CS_PIN , RESET_PIN , IRQ_PIN); -auto const tc6_inst = new TC6::TC6_Arduino_10BASE_T1S(tc6_io); +TC6::TC6_Arduino_10BASE_T1S tc6_inst(tc6_io); Arduino_10BASE_T1S_UDP udp_client; /************************************************************************************** @@ -61,11 +61,11 @@ void setup() */ pinMode(IRQ_PIN, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(IRQ_PIN), - []() { tc6_io->onInterrupt(); }, + []() { tc6_io.onInterrupt(); }, FALLING); /* Initialize IO module. */ - if (!tc6_io->begin()) + if (!tc6_io.begin()) { Serial.println("'TC6_Io::begin(...)' failed."); for (;;) { } @@ -73,7 +73,7 @@ void setup() MacAddress const mac_addr = MacAddress::create_from_uid(); - if (!tc6_inst->begin(ip_addr + if (!tc6_inst.begin(ip_addr , network_mask , gateway , mac_addr @@ -104,7 +104,7 @@ void loop() /* Services the hardware and the protocol stack. * Must be called cyclic. The faster the better. */ - tc6_inst->service(); + tc6_inst.service(); static unsigned long prev_beacon_check = 0; static unsigned long prev_udp_packet_sent = 0; @@ -114,7 +114,7 @@ void loop() if ((now - prev_beacon_check) > 1000) { prev_beacon_check = now; - if (!tc6_inst->getPlcaStatus(OnPlcaStatus)) + if (!tc6_inst.getPlcaStatus(OnPlcaStatus)) Serial.println("getPlcaStatus(...) failed"); } @@ -189,6 +189,6 @@ static void OnPlcaStatus(bool success, bool plcaStatus) Serial.println("PLCA Mode active"); else { Serial.println("CSMA/CD fallback"); - tc6_inst->enablePlca(); + tc6_inst.enablePlca(); } } diff --git a/examples/UDP_Server/UDP_Server.ino b/examples/UDP_Server/UDP_Server.ino index a552952..cb469ac 100644 --- a/examples/UDP_Server/UDP_Server.ino +++ b/examples/UDP_Server/UDP_Server.ino @@ -38,7 +38,7 @@ static uint16_t const UDP_SERVER_LOCAL_PORT = 8888; * GLOBAL VARIABLES **************************************************************************************/ -auto const tc6_io = new TC6::TC6_Io( +TC6::TC6_Io tc6_io( #if defined(ARDUINO_GIGA) || defined(ARDUINO_PORTENTA_C33) SPI1 #else @@ -47,7 +47,7 @@ auto const tc6_io = new TC6::TC6_Io( , CS_PIN , RESET_PIN , IRQ_PIN); -auto const tc6_inst = new TC6::TC6_Arduino_10BASE_T1S(tc6_io); +TC6::TC6_Arduino_10BASE_T1S tc6_inst(tc6_io); Arduino_10BASE_T1S_UDP udp_server; /************************************************************************************** @@ -65,11 +65,11 @@ void setup() */ pinMode(IRQ_PIN, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(IRQ_PIN), - []() { tc6_io->onInterrupt(); }, + []() { tc6_io.onInterrupt(); }, FALLING); /* Initialize IO module. */ - if (!tc6_io->begin()) + if (!tc6_io.begin()) { Serial.println("'TC6_Io::begin(...)' failed."); for (;;) { } @@ -77,7 +77,7 @@ void setup() MacAddress const mac_addr = MacAddress::create_from_uid(); - if (!tc6_inst->begin(ip_addr + if (!tc6_inst.begin(ip_addr , network_mask , gateway , mac_addr @@ -108,7 +108,7 @@ void loop() /* Services the hardware and the protocol stack. * Must be called cyclic. The faster the better. */ - tc6_inst->service(); + tc6_inst.service(); static unsigned long prev_beacon_check = 0; @@ -117,7 +117,7 @@ void loop() if ((now - prev_beacon_check) > 1000) { prev_beacon_check = now; - if (!tc6_inst->getPlcaStatus(OnPlcaStatus)) + if (!tc6_inst.getPlcaStatus(OnPlcaStatus)) Serial.println("getPlcaStatus(...) failed"); } @@ -180,6 +180,6 @@ static void OnPlcaStatus(bool success, bool plcaStatus) Serial.println("PLCA Mode active"); else { Serial.println("CSMA/CD fallback"); - tc6_inst->enablePlca(); + tc6_inst.enablePlca(); } } diff --git a/examples/tools/Control-DIOx/Control-DIOx.ino b/examples/tools/Control-DIOx/Control-DIOx.ino index 113f1b1..1a85bce 100644 --- a/examples/tools/Control-DIOx/Control-DIOx.ino +++ b/examples/tools/Control-DIOx/Control-DIOx.ino @@ -35,7 +35,7 @@ static auto const DIO_PIN = TC6::DIO::A0; * GLOBAL VARIABLES **************************************************************************************/ -auto const tc6_io = new TC6::TC6_Io( +TC6::TC6_Io tc6_io( #if defined(ARDUINO_GIGA) || defined(ARDUINO_PORTENTA_C33) SPI1 #else @@ -44,7 +44,7 @@ auto const tc6_io = new TC6::TC6_Io( , CS_PIN , RESET_PIN , IRQ_PIN); -auto const tc6_inst = new TC6::TC6_Arduino_10BASE_T1S(tc6_io); +TC6::TC6_Arduino_10BASE_T1S tc6_inst(tc6_io); /************************************************************************************** * SETUP/LOOP @@ -61,11 +61,11 @@ void setup() */ pinMode(IRQ_PIN, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(IRQ_PIN), - []() { tc6_io->onInterrupt(); }, + []() { tc6_io.onInterrupt(); }, FALLING); /* Initialize IO module. */ - if (!tc6_io->begin()) + if (!tc6_io.begin()) { Serial.println("'TC6_Io::begin(...)' failed."); for (;;) { } @@ -73,7 +73,7 @@ void setup() MacAddress const mac_addr = MacAddress::create_from_uid(); - if (!tc6_inst->begin(ip_addr + if (!tc6_inst.begin(ip_addr , network_mask , gateway , mac_addr @@ -96,7 +96,7 @@ void loop() /* Services the hardware and the protocol stack. * Must be called cyclic. The faster the better. */ - tc6_inst->service(); + tc6_inst.service(); static unsigned long prev_dio_toogle = 0; auto const now = millis(); @@ -112,7 +112,7 @@ void loop() Serial.print(" = "); Serial.println(dio_val); - tc6_inst->digitalWrite(DIO_PIN, dio_val); + tc6_inst.digitalWrite(DIO_PIN, dio_val); dio_val = !dio_val; } } diff --git a/examples/tools/PoDL-Sink-Auto-TurnOff/PoDL-Sink-Auto-TurnOff.ino b/examples/tools/PoDL-Sink-Auto-TurnOff/PoDL-Sink-Auto-TurnOff.ino index 4047e6a..22f3c36 100644 --- a/examples/tools/PoDL-Sink-Auto-TurnOff/PoDL-Sink-Auto-TurnOff.ino +++ b/examples/tools/PoDL-Sink-Auto-TurnOff/PoDL-Sink-Auto-TurnOff.ino @@ -32,7 +32,7 @@ static T1SMacSettings const t1s_default_mac_settings; * GLOBAL VARIABLES **************************************************************************************/ -auto const tc6_io = new TC6::TC6_Io( +TC6::TC6_Io tc6_io( #if defined(ARDUINO_GIGA) || defined(ARDUINO_PORTENTA_C33) SPI1 #else @@ -41,7 +41,7 @@ auto const tc6_io = new TC6::TC6_Io( , CS_PIN , RESET_PIN , IRQ_PIN); -auto const tc6_inst = new TC6::TC6_Arduino_10BASE_T1S(tc6_io); +TC6::TC6_Arduino_10BASE_T1S tc6_inst(tc6_io); /************************************************************************************** * SETUP/LOOP @@ -58,11 +58,11 @@ void setup() */ pinMode(IRQ_PIN, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(IRQ_PIN), - []() { tc6_io->onInterrupt(); }, + []() { tc6_io.onInterrupt(); }, FALLING); /* Initialize IO module. */ - if (!tc6_io->begin()) + if (!tc6_io.begin()) { Serial.println("'TC6_Io::begin(...)' failed."); for (;;) { } @@ -70,7 +70,7 @@ void setup() MacAddress const mac_addr = MacAddress::create_from_uid(); - if (!tc6_inst->begin(ip_addr + if (!tc6_inst.begin(ip_addr , network_mask , gateway , mac_addr @@ -88,9 +88,9 @@ void setup() Serial.println(t1s_default_mac_settings); /* A0 -> LOCAL_ENABLE -> DO NOT feed power from board to network. */ - tc6_inst->digitalWrite(TC6::DIO::A0, false); + tc6_inst.digitalWrite(TC6::DIO::A0, false); /* A1 -> T1S_DISABLE -> Open the switch connecting network to board by pulling EN LOW. */ - tc6_inst->digitalWrite(TC6::DIO::A1, true); + tc6_inst.digitalWrite(TC6::DIO::A1, true); Serial.println("PoDL-Sink-Auto-TurnOff"); } @@ -100,5 +100,5 @@ void loop() /* Services the hardware and the protocol stack. * Must be called cyclic. The faster the better. */ - tc6_inst->service(); + tc6_inst.service(); } diff --git a/examples/tools/PoDL-Source/PoDL-Source.ino b/examples/tools/PoDL-Source/PoDL-Source.ino index 6292f47..daa80ff 100644 --- a/examples/tools/PoDL-Source/PoDL-Source.ino +++ b/examples/tools/PoDL-Source/PoDL-Source.ino @@ -32,7 +32,7 @@ static T1SMacSettings const t1s_default_mac_settings; * GLOBAL VARIABLES **************************************************************************************/ -auto const tc6_io = new TC6::TC6_Io( +TC6::TC6_Io tc6_io( #if defined(ARDUINO_GIGA) || defined(ARDUINO_PORTENTA_C33) SPI1 #else @@ -41,7 +41,7 @@ auto const tc6_io = new TC6::TC6_Io( , CS_PIN , RESET_PIN , IRQ_PIN); -auto const tc6_inst = new TC6::TC6_Arduino_10BASE_T1S(tc6_io); +TC6::TC6_Arduino_10BASE_T1S tc6_inst(tc6_io); /************************************************************************************** * SETUP/LOOP @@ -58,11 +58,11 @@ void setup() */ pinMode(IRQ_PIN, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(IRQ_PIN), - []() { tc6_io->onInterrupt(); }, + []() { tc6_io.onInterrupt(); }, FALLING); /* Initialize IO module. */ - if (!tc6_io->begin()) + if (!tc6_io.begin()) { Serial.println("'TC6_Io::begin(...)' failed."); for (;;) { } @@ -70,7 +70,7 @@ void setup() MacAddress const mac_addr = MacAddress::create_from_uid(); - if (!tc6_inst->begin(ip_addr + if (!tc6_inst.begin(ip_addr , network_mask , gateway , mac_addr @@ -88,9 +88,9 @@ void setup() Serial.println(t1s_default_mac_settings); /* A0 -> LOCAL_ENABLE -> feed power from board to network. */ - tc6_inst->digitalWrite(TC6::DIO::A0, true); + tc6_inst.digitalWrite(TC6::DIO::A0, true); /* A1 -> T1S_DISABLE -> close the switch connecting network to board. */ - tc6_inst->digitalWrite(TC6::DIO::A1, true); + tc6_inst.digitalWrite(TC6::DIO::A1, true); Serial.println("PoDL-Source"); } @@ -100,5 +100,5 @@ void loop() /* Services the hardware and the protocol stack. * Must be called cyclic. The faster the better. */ - tc6_inst->service(); + tc6_inst.service(); } diff --git a/src/microchip/TC6_Arduino_10BASE_T1S.cpp b/src/microchip/TC6_Arduino_10BASE_T1S.cpp index 830650d..f14f503 100644 --- a/src/microchip/TC6_Arduino_10BASE_T1S.cpp +++ b/src/microchip/TC6_Arduino_10BASE_T1S.cpp @@ -103,10 +103,10 @@ static err_t lwIpOut(struct netif *netif, struct pbuf *p); * CTOR/DTOR **************************************************************************************/ -TC6_Arduino_10BASE_T1S::TC6_Arduino_10BASE_T1S(TC6_Io * tc6_io) +TC6_Arduino_10BASE_T1S::TC6_Arduino_10BASE_T1S(TC6_Io & tc6_io) : _tc6_io{tc6_io} { - _lw.io = tc6_io; + _lw.io = &tc6_io; } TC6_Arduino_10BASE_T1S::~TC6_Arduino_10BASE_T1S() @@ -206,11 +206,11 @@ void TC6_Arduino_10BASE_T1S::service() { sys_check_timeouts(); /* LWIP timers - ARP, DHCP, TCP, etc. */ - if (_tc6_io->isInterruptActive()) + if (_tc6_io.isInterruptActive()) { if (TC6_Service(_lw.tc.tc6, false)) { - _tc6_io->releaseInterrupt(); + _tc6_io.releaseInterrupt(); } } else if (_lw.tc.tc6NeedService) { diff --git a/src/microchip/TC6_Arduino_10BASE_T1S.h b/src/microchip/TC6_Arduino_10BASE_T1S.h index 33fa03f..08a1bdd 100644 --- a/src/microchip/TC6_Arduino_10BASE_T1S.h +++ b/src/microchip/TC6_Arduino_10BASE_T1S.h @@ -74,7 +74,7 @@ enum class DIO { A0, A1 }; class TC6_Arduino_10BASE_T1S : public Arduino_10BASE_T1S_PHY_Interface { public: - TC6_Arduino_10BASE_T1S(TC6_Io * tc6_io); + TC6_Arduino_10BASE_T1S(TC6_Io & tc6_io); virtual ~TC6_Arduino_10BASE_T1S(); @@ -98,7 +98,7 @@ class TC6_Arduino_10BASE_T1S : public Arduino_10BASE_T1S_PHY_Interface private: - TC6_Io * _tc6_io; + TC6_Io & _tc6_io; TC6LwIP_t _lw; T1SPlcaSettings _t1s_plca_settings; From 9bc3d516b232d65ab329a5e59c8e88eae2c53516 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Mon, 2 Dec 2024 14:30:30 +0100 Subject: [PATCH 4/4] Using macros for T1S class object instantiation. --- examples/UDP_Client/UDP_Client.ino | 21 +++++++------------ examples/UDP_Server/UDP_Server.ino | 21 +++++++------------ examples/tools/Control-DIOx/Control-DIOx.ino | 19 +++++++---------- .../PoDL-Sink-Auto-TurnOff.ino | 21 +++++++------------ examples/tools/PoDL-Source/PoDL-Source.ino | 21 +++++++------------ src/Arduino_10BASE_T1S.h | 8 +++++++ 6 files changed, 47 insertions(+), 64 deletions(-) diff --git a/examples/UDP_Client/UDP_Client.ino b/examples/UDP_Client/UDP_Client.ino index dd7e69b..018362a 100644 --- a/examples/UDP_Client/UDP_Client.ino +++ b/examples/UDP_Client/UDP_Client.ino @@ -34,16 +34,11 @@ static uint16_t const UDP_SERVER_PORT = 8888; * GLOBAL VARIABLES **************************************************************************************/ -TC6::TC6_Io tc6_io( #if defined(ARDUINO_GIGA) || defined(ARDUINO_PORTENTA_C33) - SPI1 + Arduino_10BASE_T1S_PHY_TC6(SPI1, CS_PIN, RESET_PIN, IRQ_PIN); #else - SPI + Arduino_10BASE_T1S_PHY_TC6(SPI, CS_PIN, RESET_PIN, IRQ_PIN); #endif - , CS_PIN - , RESET_PIN - , IRQ_PIN); -TC6::TC6_Arduino_10BASE_T1S tc6_inst(tc6_io); Arduino_10BASE_T1S_UDP udp_client; /************************************************************************************** @@ -61,11 +56,11 @@ void setup() */ pinMode(IRQ_PIN, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(IRQ_PIN), - []() { tc6_io.onInterrupt(); }, + []() { t1s_io.onInterrupt(); }, FALLING); /* Initialize IO module. */ - if (!tc6_io.begin()) + if (!t1s_io.begin()) { Serial.println("'TC6_Io::begin(...)' failed."); for (;;) { } @@ -73,7 +68,7 @@ void setup() MacAddress const mac_addr = MacAddress::create_from_uid(); - if (!tc6_inst.begin(ip_addr + if (!t1s_phy.begin(ip_addr , network_mask , gateway , mac_addr @@ -104,7 +99,7 @@ void loop() /* Services the hardware and the protocol stack. * Must be called cyclic. The faster the better. */ - tc6_inst.service(); + t1s_phy.service(); static unsigned long prev_beacon_check = 0; static unsigned long prev_udp_packet_sent = 0; @@ -114,7 +109,7 @@ void loop() if ((now - prev_beacon_check) > 1000) { prev_beacon_check = now; - if (!tc6_inst.getPlcaStatus(OnPlcaStatus)) + if (!t1s_phy.getPlcaStatus(OnPlcaStatus)) Serial.println("getPlcaStatus(...) failed"); } @@ -189,6 +184,6 @@ static void OnPlcaStatus(bool success, bool plcaStatus) Serial.println("PLCA Mode active"); else { Serial.println("CSMA/CD fallback"); - tc6_inst.enablePlca(); + t1s_phy.enablePlca(); } } diff --git a/examples/UDP_Server/UDP_Server.ino b/examples/UDP_Server/UDP_Server.ino index cb469ac..a98f8ad 100644 --- a/examples/UDP_Server/UDP_Server.ino +++ b/examples/UDP_Server/UDP_Server.ino @@ -38,16 +38,11 @@ static uint16_t const UDP_SERVER_LOCAL_PORT = 8888; * GLOBAL VARIABLES **************************************************************************************/ -TC6::TC6_Io tc6_io( #if defined(ARDUINO_GIGA) || defined(ARDUINO_PORTENTA_C33) - SPI1 + Arduino_10BASE_T1S_PHY_TC6(SPI1, CS_PIN, RESET_PIN, IRQ_PIN); #else - SPI + Arduino_10BASE_T1S_PHY_TC6(SPI, CS_PIN, RESET_PIN, IRQ_PIN); #endif - , CS_PIN - , RESET_PIN - , IRQ_PIN); -TC6::TC6_Arduino_10BASE_T1S tc6_inst(tc6_io); Arduino_10BASE_T1S_UDP udp_server; /************************************************************************************** @@ -65,11 +60,11 @@ void setup() */ pinMode(IRQ_PIN, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(IRQ_PIN), - []() { tc6_io.onInterrupt(); }, + []() { t1s_io.onInterrupt(); }, FALLING); /* Initialize IO module. */ - if (!tc6_io.begin()) + if (!t1s_io.begin()) { Serial.println("'TC6_Io::begin(...)' failed."); for (;;) { } @@ -77,7 +72,7 @@ void setup() MacAddress const mac_addr = MacAddress::create_from_uid(); - if (!tc6_inst.begin(ip_addr + if (!t1s_phy.begin(ip_addr , network_mask , gateway , mac_addr @@ -108,7 +103,7 @@ void loop() /* Services the hardware and the protocol stack. * Must be called cyclic. The faster the better. */ - tc6_inst.service(); + t1s_phy.service(); static unsigned long prev_beacon_check = 0; @@ -117,7 +112,7 @@ void loop() if ((now - prev_beacon_check) > 1000) { prev_beacon_check = now; - if (!tc6_inst.getPlcaStatus(OnPlcaStatus)) + if (!t1s_phy.getPlcaStatus(OnPlcaStatus)) Serial.println("getPlcaStatus(...) failed"); } @@ -180,6 +175,6 @@ static void OnPlcaStatus(bool success, bool plcaStatus) Serial.println("PLCA Mode active"); else { Serial.println("CSMA/CD fallback"); - tc6_inst.enablePlca(); + t1s_phy.enablePlca(); } } diff --git a/examples/tools/Control-DIOx/Control-DIOx.ino b/examples/tools/Control-DIOx/Control-DIOx.ino index 1a85bce..f9dcecb 100644 --- a/examples/tools/Control-DIOx/Control-DIOx.ino +++ b/examples/tools/Control-DIOx/Control-DIOx.ino @@ -35,16 +35,11 @@ static auto const DIO_PIN = TC6::DIO::A0; * GLOBAL VARIABLES **************************************************************************************/ -TC6::TC6_Io tc6_io( #if defined(ARDUINO_GIGA) || defined(ARDUINO_PORTENTA_C33) - SPI1 + Arduino_10BASE_T1S_PHY_TC6(SPI1, CS_PIN, RESET_PIN, IRQ_PIN); #else - SPI + Arduino_10BASE_T1S_PHY_TC6(SPI, CS_PIN, RESET_PIN, IRQ_PIN); #endif - , CS_PIN - , RESET_PIN - , IRQ_PIN); -TC6::TC6_Arduino_10BASE_T1S tc6_inst(tc6_io); /************************************************************************************** * SETUP/LOOP @@ -61,11 +56,11 @@ void setup() */ pinMode(IRQ_PIN, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(IRQ_PIN), - []() { tc6_io.onInterrupt(); }, + []() { t1s_io.onInterrupt(); }, FALLING); /* Initialize IO module. */ - if (!tc6_io.begin()) + if (!t1s_io.begin()) { Serial.println("'TC6_Io::begin(...)' failed."); for (;;) { } @@ -73,7 +68,7 @@ void setup() MacAddress const mac_addr = MacAddress::create_from_uid(); - if (!tc6_inst.begin(ip_addr + if (!t1s_phy.begin(ip_addr , network_mask , gateway , mac_addr @@ -96,7 +91,7 @@ void loop() /* Services the hardware and the protocol stack. * Must be called cyclic. The faster the better. */ - tc6_inst.service(); + t1s_phy.service(); static unsigned long prev_dio_toogle = 0; auto const now = millis(); @@ -112,7 +107,7 @@ void loop() Serial.print(" = "); Serial.println(dio_val); - tc6_inst.digitalWrite(DIO_PIN, dio_val); + t1s_phy.digitalWrite(DIO_PIN, dio_val); dio_val = !dio_val; } } diff --git a/examples/tools/PoDL-Sink-Auto-TurnOff/PoDL-Sink-Auto-TurnOff.ino b/examples/tools/PoDL-Sink-Auto-TurnOff/PoDL-Sink-Auto-TurnOff.ino index 22f3c36..7588535 100644 --- a/examples/tools/PoDL-Sink-Auto-TurnOff/PoDL-Sink-Auto-TurnOff.ino +++ b/examples/tools/PoDL-Sink-Auto-TurnOff/PoDL-Sink-Auto-TurnOff.ino @@ -32,16 +32,11 @@ static T1SMacSettings const t1s_default_mac_settings; * GLOBAL VARIABLES **************************************************************************************/ -TC6::TC6_Io tc6_io( #if defined(ARDUINO_GIGA) || defined(ARDUINO_PORTENTA_C33) - SPI1 + Arduino_10BASE_T1S_PHY_TC6(SPI1, CS_PIN, RESET_PIN, IRQ_PIN); #else - SPI + Arduino_10BASE_T1S_PHY_TC6(SPI, CS_PIN, RESET_PIN, IRQ_PIN); #endif - , CS_PIN - , RESET_PIN - , IRQ_PIN); -TC6::TC6_Arduino_10BASE_T1S tc6_inst(tc6_io); /************************************************************************************** * SETUP/LOOP @@ -58,11 +53,11 @@ void setup() */ pinMode(IRQ_PIN, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(IRQ_PIN), - []() { tc6_io.onInterrupt(); }, + []() { t1s_io.onInterrupt(); }, FALLING); /* Initialize IO module. */ - if (!tc6_io.begin()) + if (!t1s_io.begin()) { Serial.println("'TC6_Io::begin(...)' failed."); for (;;) { } @@ -70,7 +65,7 @@ void setup() MacAddress const mac_addr = MacAddress::create_from_uid(); - if (!tc6_inst.begin(ip_addr + if (!t1s_phy.begin(ip_addr , network_mask , gateway , mac_addr @@ -88,9 +83,9 @@ void setup() Serial.println(t1s_default_mac_settings); /* A0 -> LOCAL_ENABLE -> DO NOT feed power from board to network. */ - tc6_inst.digitalWrite(TC6::DIO::A0, false); + t1s_phy.digitalWrite(TC6::DIO::A0, false); /* A1 -> T1S_DISABLE -> Open the switch connecting network to board by pulling EN LOW. */ - tc6_inst.digitalWrite(TC6::DIO::A1, true); + t1s_phy.digitalWrite(TC6::DIO::A1, true); Serial.println("PoDL-Sink-Auto-TurnOff"); } @@ -100,5 +95,5 @@ void loop() /* Services the hardware and the protocol stack. * Must be called cyclic. The faster the better. */ - tc6_inst.service(); + t1s_phy.service(); } diff --git a/examples/tools/PoDL-Source/PoDL-Source.ino b/examples/tools/PoDL-Source/PoDL-Source.ino index daa80ff..dac81dd 100644 --- a/examples/tools/PoDL-Source/PoDL-Source.ino +++ b/examples/tools/PoDL-Source/PoDL-Source.ino @@ -32,16 +32,11 @@ static T1SMacSettings const t1s_default_mac_settings; * GLOBAL VARIABLES **************************************************************************************/ -TC6::TC6_Io tc6_io( #if defined(ARDUINO_GIGA) || defined(ARDUINO_PORTENTA_C33) - SPI1 + Arduino_10BASE_T1S_PHY_TC6(SPI1, CS_PIN, RESET_PIN, IRQ_PIN); #else - SPI + Arduino_10BASE_T1S_PHY_TC6(SPI, CS_PIN, RESET_PIN, IRQ_PIN); #endif - , CS_PIN - , RESET_PIN - , IRQ_PIN); -TC6::TC6_Arduino_10BASE_T1S tc6_inst(tc6_io); /************************************************************************************** * SETUP/LOOP @@ -58,11 +53,11 @@ void setup() */ pinMode(IRQ_PIN, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(IRQ_PIN), - []() { tc6_io.onInterrupt(); }, + []() { t1s_io.onInterrupt(); }, FALLING); /* Initialize IO module. */ - if (!tc6_io.begin()) + if (!t1s_io.begin()) { Serial.println("'TC6_Io::begin(...)' failed."); for (;;) { } @@ -70,7 +65,7 @@ void setup() MacAddress const mac_addr = MacAddress::create_from_uid(); - if (!tc6_inst.begin(ip_addr + if (!t1s_phy.begin(ip_addr , network_mask , gateway , mac_addr @@ -88,9 +83,9 @@ void setup() Serial.println(t1s_default_mac_settings); /* A0 -> LOCAL_ENABLE -> feed power from board to network. */ - tc6_inst.digitalWrite(TC6::DIO::A0, true); + t1s_phy.digitalWrite(TC6::DIO::A0, true); /* A1 -> T1S_DISABLE -> close the switch connecting network to board. */ - tc6_inst.digitalWrite(TC6::DIO::A1, true); + t1s_phy.digitalWrite(TC6::DIO::A1, true); Serial.println("PoDL-Source"); } @@ -100,5 +95,5 @@ void loop() /* Services the hardware and the protocol stack. * Must be called cyclic. The faster the better. */ - tc6_inst.service(); + t1s_phy.service(); } diff --git a/src/Arduino_10BASE_T1S.h b/src/Arduino_10BASE_T1S.h index a1a5e40..c015eb3 100644 --- a/src/Arduino_10BASE_T1S.h +++ b/src/Arduino_10BASE_T1S.h @@ -53,3 +53,11 @@ static int const RESET_PIN = -1; static int const IRQ_PIN = -1; # warning "No pins defined for your board" #endif + +/************************************************************************************** + * MACROS + **************************************************************************************/ + +#define Arduino_10BASE_T1S_PHY_TC6(__SPI, __CS_PIN, __RESET_PIN, __IRQ_PIN) \ + TC6::TC6_Io t1s_io(__SPI, __CS_PIN, __RESET_PIN, __IRQ_PIN); \ + TC6::TC6_Arduino_10BASE_T1S t1s_phy(t1s_io);