|
| 1 | +/* |
| 2 | + * This example is used to test T1TOS PoDL source capabilities. |
| 3 | + * |
| 4 | + * This targets T1TOS v0.1. |
| 5 | + * |
| 6 | + * Author: |
| 7 | + * Alexander Entinger |
| 8 | + */ |
| 9 | + |
| 10 | +/************************************************************************************** |
| 11 | + * INCLUDE |
| 12 | + **************************************************************************************/ |
| 13 | + |
| 14 | +#include <Arduino_10BASE_T1S.h> |
| 15 | + |
| 16 | +#include <SPI.h> |
| 17 | + |
| 18 | +/************************************************************************************** |
| 19 | + * CONSTANTS |
| 20 | + **************************************************************************************/ |
| 21 | + |
| 22 | +static uint8_t const T1S_PLCA_NODE_ID = 0; /* Doubles as PLCA coordinator. */ |
| 23 | + |
| 24 | +static IPAddress const ip_addr {192, 168, 42, 100 + T1S_PLCA_NODE_ID}; |
| 25 | +static IPAddress const network_mask{255, 255, 255, 0}; |
| 26 | +static IPAddress const gateway {192, 168, 42, 100}; |
| 27 | + |
| 28 | +static T1SPlcaSettings const t1s_plca_settings{T1S_PLCA_NODE_ID}; |
| 29 | +static T1SMacSettings const t1s_default_mac_settings; |
| 30 | + |
| 31 | +/************************************************************************************** |
| 32 | + * GLOBAL VARIABLES |
| 33 | + **************************************************************************************/ |
| 34 | + |
| 35 | +auto const tc6_io = new TC6::TC6_Io |
| 36 | + ( SPI |
| 37 | + , CS_PIN |
| 38 | + , RESET_PIN |
| 39 | + , IRQ_PIN); |
| 40 | +auto const tc6_inst = new TC6::TC6_Arduino_10BASE_T1S(tc6_io); |
| 41 | + |
| 42 | +/************************************************************************************** |
| 43 | + * SETUP/LOOP |
| 44 | + **************************************************************************************/ |
| 45 | + |
| 46 | +void setup() |
| 47 | +{ |
| 48 | + Serial.begin(115200); |
| 49 | + while (!Serial) { } |
| 50 | + delay(1000); |
| 51 | + |
| 52 | + /* Initialize digital IO interface for interfacing |
| 53 | + * with the LAN8651. |
| 54 | + */ |
| 55 | + pinMode(IRQ_PIN, INPUT_PULLUP); |
| 56 | + attachInterrupt(digitalPinToInterrupt(IRQ_PIN), |
| 57 | + []() { tc6_io->onInterrupt(); }, |
| 58 | + FALLING); |
| 59 | + |
| 60 | + /* Initialize IO module. */ |
| 61 | + if (!tc6_io->begin()) |
| 62 | + { |
| 63 | + Serial.println("'TC6_Io::begin(...)' failed."); |
| 64 | + for (;;) { } |
| 65 | + } |
| 66 | + |
| 67 | + MacAddress const mac_addr = MacAddress::create_from_uid(); |
| 68 | + |
| 69 | + if (!tc6_inst->begin(ip_addr |
| 70 | + , network_mask |
| 71 | + , gateway |
| 72 | + , mac_addr |
| 73 | + , t1s_plca_settings |
| 74 | + , t1s_default_mac_settings)) |
| 75 | + { |
| 76 | + Serial.println("'TC6::begin(...)' failed."); |
| 77 | + for (;;) { } |
| 78 | + } |
| 79 | + |
| 80 | + Serial.print("IP\t"); |
| 81 | + Serial.println(ip_addr); |
| 82 | + Serial.println(mac_addr); |
| 83 | + Serial.println(t1s_plca_settings); |
| 84 | + Serial.println(t1s_default_mac_settings); |
| 85 | + |
| 86 | + /* A0 -> LOCAL_ENABLE -> feed power from board to network. */ |
| 87 | + tc6_inst->digitalWrite(TC6::DIO::A0, true); |
| 88 | + /* A1 -> T1S_DISBLE -> close the switch connecting network to board. */ |
| 89 | + tc6_inst->digitalWrite(TC6::DIO::A1, true); |
| 90 | + |
| 91 | + Serial.println("PoDL-Source"); |
| 92 | +} |
| 93 | + |
| 94 | +void loop() |
| 95 | +{ |
| 96 | + /* Services the hardware and the protocol stack. |
| 97 | + * Must be called cyclic. The faster the better. |
| 98 | + */ |
| 99 | + tc6_inst->service(); |
| 100 | +} |
0 commit comments