diff --git a/examples/UDP_Client/UDP_Client.ino b/examples/UDP_Client/UDP_Client.ino index e34eb4f..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 **************************************************************************************/ -auto const tc6_io = new TC6::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); -auto const tc6_inst = new TC6::TC6_Arduino_10BASE_T1S(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 a552952..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 **************************************************************************************/ -auto const tc6_io = new TC6::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); -auto const tc6_inst = new TC6::TC6_Arduino_10BASE_T1S(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 113f1b1..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 **************************************************************************************/ -auto const tc6_io = new TC6::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); -auto const tc6_inst = new TC6::TC6_Arduino_10BASE_T1S(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 4047e6a..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 **************************************************************************************/ -auto const tc6_io = new TC6::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); -auto const tc6_inst = new TC6::TC6_Arduino_10BASE_T1S(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 6292f47..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 **************************************************************************************/ -auto const tc6_io = new TC6::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); -auto const tc6_inst = new TC6::TC6_Arduino_10BASE_T1S(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); diff --git a/src/T1SMacSettings.h b/src/T1SMacSettings.h index 54c89d8..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; - 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 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..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() @@ -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_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; 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: