MCPcopy Create free account
hub / github.com/andysworkshop/stm32plus / run

Method run

examples/net_ping_client/net_ping_client.cpp:96–180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

94 */
95
96 void run() {
97
98 // reset state
99
100 _linkStatusChanged=false;
101
102 // declare an instance of the USART and the stream that we'll use to write to it
103
104 _usart=new MyUsart(57600);
105 _outputStream=new UsartPollingOutputStream(*_usart);
106
107 // declare the RTC that that stack requires. it's used for cache timeouts, DHCP lease expiry
108 // and such like so it does not have to be calibrated for accuracy. A few seconds here or there
109 // over a 24 hour period isn't going to make any difference.
110
111 Rtc<RtcLsiClockFeature<Rtc32kHzLsiFrequencyProvider>,RtcSecondInterruptFeature> rtc;
112 rtc.setTick(0);
113
114 // declare an instance of the network stack
115
116 MyNetworkStack::Parameters params;
117 _net=new MyNetworkStack;
118
119 params.base_rtc=&rtc;
120
121 // declare our IP address and subnet mask
122
123 params.staticip_address="192.168.0.10";
124 params.staticip_subnetMask="255.255.255.0";
125 params.staticip_defaultGateway="192.168.0.1";
126
127 // Initialise the stack. This will reset the PHY, initialise the MAC
128 // and attempt to create a link to our link partner. Ensure your cable
129 // is plugged in when you run this or be prepared to handle the error
130
131 if(!_net->initialise(params))
132 error();
133
134 // we'd like to be notified when there's a change in the link status so configure the
135 // PHY interrupt mask to report that change. My development board has the PHY interrupt
136 // line on PB14 so we'll need an active-low EXTI configured for that
137
138 GpioB<DefaultDigitalInputFeature<14> > pb;
139 Exti14 exti(EXTI_Mode_Interrupt,EXTI_Trigger_Falling,pb[14]);
140
141 exti.ExtiInterruptEventSender.insertSubscriber(
142 ExtiInterruptEventSourceSlot::bind(this,&NetPingClientTest::onLinkStatusChange)
143 );
144
145 if(!_net->phyEnableInterrupts(DP83848C::INTERRUPT_LINK_STATUS_CHANGE))
146 error();
147
148 // subscribe to error events from the network stack
149
150 _net->NetworkErrorEventSender.insertSubscriber(NetworkErrorEventSourceSlot::bind(this,&NetPingClientTest::onError));
151
152 // start the ethernet MAC Tx/Rx DMA channels
153

Callers 1

mainFunction · 0.45

Calls 8

bindFunction · 0.85
modp_uitoa10Function · 0.85
insertSubscriberMethod · 0.80
pingMethod · 0.80
setTickMethod · 0.45
initialiseMethod · 0.45
phyEnableInterruptsMethod · 0.45
startupMethod · 0.45

Tested by

no test coverage detected