KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
network.c
1 /*
2  * KM3NeT CLB v2 Firmware
3  * ----------------------
4  *
5  * Copyright 2013 KM3NeT Collaboration
6  *
7  * All Rights Reserved.
8  *
9  *
10  * File : network.c
11  * Created : 22 nov. 2013
12  * Author : Vincent van Beveren
13  */
14 
15 #include "net/network.h"
16 
17 #include <stdint.h>
18 #include <stdbool.h>
19 #include <stdio.h>
20 #include <time.h>
21 
22 #include "ms.h"
23 
24 #include "errorcode.h"
25 
26 #include "dbg/show.h"
27 #include "util/log.h"
28 
29 #include "kernel/err.h"
30 #include "kernel/scheduler.h"
31 #include "kernel/timer.h"
32 #include "kernel/tm.h"
33 #include "drv/wb/gpio.h"
34 #include "drv/wb/wrx.h"
35 
36 
37 #include "cfg_net.h"
38 #include "net/mcf.h"
39 #include "net/msg.h"
40 #include "net/srp.h"
41 #include "net/net.h"
42 
43 LOG_DEF(Net)
44 
45 // #define SHOW_ETH_RX
46 // #define SHOW_ETH_TX
47 
48 //#define BAD_NETWORK_TEST
49 #define BAD_NETWORK_RX_FAIL 3
50 #define BAD_NETWORK_TX_FAIL 3
51 #define BAD_NETWORK_TX_STUTTER 50
52 
53 
54 // #define SRP_ECHO_MODE
55 
56 #define _IP32_C(IP32, IDX) ( ( IP32 >> (IDX * 8)) & 0xFF )
57 #define IP32_TO_LIST(IP32) _IP32_C(IP32, 3),_IP32_C(IP32, 2),_IP32_C(IP32, 1),_IP32_C(IP32, 0)
58 
59 
60 #ifdef LOG_RX_PACKETS
61 
62 static PacketLog_t _pktLog[LOG_RX_PACKETS];
63 static uint32_t _pktLogPos = 0;
64 
65 static PacketLog_t * addPacketLogLine()
66 {
67  if (_pktLogPos == LOG_RX_PACKETS) return NULL;
68  return &_pktLog[_pktLogPos++];
69 }
70 
71 PacketLog_t * getPacketLog(uint32_t pos)
72 {
73  if (pos >= _pktLogPos) return NULL;
74  return &_pktLog[pos];
75 };
76 
78 {
79  _pktLogPos = 0;
80 };
81 #else
82 // When not enabled, this does nothing.
83 PacketLog_t * getPacketLog(uint32_t pos) { return NULL };
84 void resetPacketLog() {};
85 #endif
86 
87 /**
88  * Links the system clock to the MCF timestamp routine.
89  */
90 uint32_t _mcfTimeStamp()
91 {
92  return clock();
93 }
94 
95 // -------------------------------------------------------------------------------------------
96 // Below links IPMux to the UDP stack
97 // -------------------------------------------------------------------------------------------
98 
99 #ifndef UARTBRIDGE
100 
101 #include "drv/wb/ipmux.h"
102 #include "drv/wb/wrx.h"
103 #include "ms.h"
104 
105 #ifdef MS_USE_BOOTP
106 #define MODULE_IP NET_IP_U32( 0, 0, 0, 0 )
107 #define SERVER_IP NET_IP_U32(255, 255, 255, 255)
108 static bool _hasIp = false;
109 #else
110 #define MODULE_IP NET_IP_U32( 192, 168, 1, 10 )
111 #define SERVER_IP NET_IP_U32( 192, 168, 1, 1 )
112 static bool _hasIp = true;
113 #endif
114 #define SC_PORT 0xDACE
115 
116 typedef struct {
117  uint32_t ethRx;
118  uint32_t ethRxFail;
119  uint32_t ethTx;
120  uint32_t udpRx;
121  uint32_t udpRxFail;
122  // rxFail?
123  uint32_t udpTx;
124  uint32_t srpRx;
125  uint32_t srpTx;
126  uint32_t srpTxErr;
127  uint32_t srpTxLost;
128  uint16_t txHisto[8];
129  uint32_t _procTot;
130  uint32_t _procCnt;
131  uint32_t lastProcTime;
132 } NetStat;
133 
134 static NetStat _stats;
135 
136 
137 static uint8_t _rxbuf[NET_RX_BUFFER] __attribute__((aligned(4)));
138 static uint32_t _rxbuf_len;
139 
140 
141 #ifdef NET_SU_IP_FIX
142 
143 // import declartion of private function
144 void ms_bootp_periodic(bool force);
145 
146 // state of temporary IP
147 static bool _using_temp_ip = true;
148 static ms_ipa_t _temp_ip;
149 
150 #endif
151 
152 // Minimal LED flash time in MS
153 #define LED_FLASH_TIME 200
154 #define LED_OFFSET 2
155 
156 #define LED_TX 0
157 #define LED_RX 1
158 #define LED_COUNT 2
159 
160 
161 
162 static IpMuxCfg _ipMuxModCfg = {
163  .mac = { 0xFFFF, 0xFFFF, 0xFFFF }, // Module (source) MAC address
164  .ip = MODULE_IP, // Module (source) IP address
165  .prt = {
166  SC_PORT + 1, SC_PORT + 2, SC_PORT + 3, SC_PORT + 4
167  }
168  };
169 
170 
171 static IpMuxCfg _ipMuxSvrCfg = {
172  .mac = { 0xFFFF, 0xFFFF, 0xFFFF }, // Sever (source) MAC address
173  .ip = SERVER_IP, // Sever (source) IP address
174  .prt = {
175  SC_PORT + 1, SC_PORT + 2, SC_PORT + 3, SC_PORT + 4
176  }
177  };
178 
179 
180 #ifdef USE_LEDS
181 static uint32_t _ledsTo[LED_COUNT];
182 static uint32_t _ledsOn = 0;
183 
184 static void netSetLed(int idx)
185 {
186 
187  gpioPinSet(LED_OFFSET + idx, true);
188 
189  _ledsTo[idx] = timeOutInit(LED_FLASH_TIME);
190  _ledsOn |= (1 << idx);
191 }
192 
193 static void netHandleLeds()
194 {
195  if (_ledsOn == 0) return;
196  int i;
197 
198  for (i = 0; i < LED_COUNT; ++i)
199  {
200  if ((_ledsOn & (1 << i)) && timeOut(_ledsTo[i]))
201  {
202  gpioPinSet(LED_OFFSET + i, false);
203  _ledsOn &= ~(1 << i);
204  }
205  }
206 }
207 
208 #else
209 static inline void netSetLed(int idx) {};
210 static void netHandleLeds() {};
211 #endif
212 
213 
214 static bool linkUp() {
215  if (!wrxUp()) return false;
216 
217  volatile WrxInfo * info = wrxInfo();
218  if (info->status & WRX_STATUS_LINK_UP)
219  {
220  return true;
221  }
222  return false;
223 }
224 
225 static bool _prevLinkUp = false;
226 
227 void netExec()
228 {
229 
230  if (linkUp())
231  {
232  if (!_prevLinkUp)
233  {
234  // if the link was not up before, flush the CPU's input buffer
235  // before proceding.
236  logInfo("Link up");
237  ipMuxFlushCPU();
238  _prevLinkUp = true;
239  }
240  } else if (_prevLinkUp)
241  {
242  logInfo("Link down");
243  _prevLinkUp = false;
244  }
245 
246  // FIX 20160704 VVB - Send BOOTP anyway, even if LINK is not up
247 
248 #ifdef NET_SU_IP_FIX
249  if (_using_temp_ip)
250  {
251  // as long as the obtained IP matches the temporary IP, execute bootp.
252 
253  ms_ipa_t cur_ip;
254 
255  ms_get_config(NULL, &cur_ip);
256 
257  if (ms_ipa_eq(&_temp_ip, &cur_ip))
258  {
259  ms_bootp_periodic(true);
260  }
261  else
262  {
263  // a different IP, hurray! we're no longer using this temporary IP
264  _using_temp_ip = false;
265  }
266  } else {
267  // this block will only be executed if the temporary IP has
268  // been replace with a DHCP assigned one
269 #endif
270  ms_periodic();
271  if (!_hasIp)
272  {
273  if (ms_ip_has())
274  {
275  ms_ipa_t ip;
276  ms_get_config(NULL, &ip);
277  ms_ipa_get_u32(&ip, &_ipMuxModCfg.ip);
278  ipMuxInit(&_ipMuxModCfg, false);
279  _hasIp = true;
280  logInfo("IP Obtained: %d.%d.%d.%d", IP32_TO_LIST(_ipMuxModCfg.ip));
281  }
282  }
283 #ifdef NET_SU_IP_FIX
284  }
285 #endif
286  netHandleLeds();
287  if (ipMuxRxAvail()) {
288 
290  uint32_t t = ticks();
291 
292  netSetLed(LED_RX);
293 
294  if (ipMuxRx(_rxbuf, sizeof(_rxbuf), &_rxbuf_len))
295  {
296  _stats.ethRx++;
297 #ifdef SHOW_ETH_RX
298  showHex8("Receving from IPMUX: ", _rxbuf, _rxbuf_len);
299 #endif
300 #ifdef LOG_RX_PACKETS
301  PacketLog_t * pkt = addPacketLogLine();
302 
303  if (pkt != NULL)
304  {
305  pkt->ticks = ticks();
306  pkt->length = _rxbuf_len;
307  if (_rxbuf_len >= 14)
308  {
309  pkt->eth_type = ( _rxbuf[12] << 8 ) | ( _rxbuf[13] );
310  pkt->d_mac5 = _rxbuf[10];
311  pkt->d_mac6 = _rxbuf[11];
312  }
313  else
314  {
315  // truncated packet. No info to log.
316  pkt->eth_type = 0xFFFF;
317  pkt->d_mac5 = 0x00;
318  pkt->d_mac6 = 0x00;
319  }
320  }
321 
322  ms_rx(_rxbuf, _rxbuf_len);
323 
324 
325  if (pkt != NULL)
326  {
327  // store processing time
328  pkt->proc_time = ticks() - pkt->ticks;
329  }
330 #else
331  ms_rx(_rxbuf, _rxbuf_len);
332 #endif
333 
334 
335  } else {
336  _stats.ethRxFail++;
337  errPrint(true);
338  }
339  // calc delay
340  t = ticks() - t;
341 
342  _stats._procTot += t;
343  _stats._procCnt ++;
344  if (_stats._procCnt == 1024)
345  {
346  _stats.lastProcTime = (uint32_t) (( _stats._procTot * 1000) / 1024);
347  _stats._procTot = 0;
348  _stats._procCnt = 0;
349  }
350 
352  }
353 
354 
355 // uint64_t _procTot;
356 // uint32_t _procCnt;
357 // uint32_t lastProcTime;
358 
359 }
360 
361 bool netMuxDest(uint32_t destIp, uint16_t * destMac)
362 {
363 
364  ms_ipa_t ipa;
365  ms_ipa_set_u32(destIp, &ipa);
366  ms_mac_t * mac;
367 
368  if (destIp == 0xFFFFFFFF) {
369  return errSet(ERROR_CTX(E_INVARGUMENT));
370  }
371  if (destMac == NULL ||
372  (destMac[0] == 0xFFFF && destMac[1] == 0xFFFF && destMac[2] == 0xFFFF) ) {
373 
374  mac = ms_arp_lookup(&ipa);
375 
376  if (mac == NULL) return errSet(ERROR_CTX(E_INVARGUMENT));
377 
378  destMac = (uint16_t *)mac;
379  }
380 
381  memcpy(&_ipMuxSvrCfg.mac, destMac, 6);
382  _ipMuxSvrCfg.ip = destIp;
383 
384  ipMuxCfgRemote(&_ipMuxSvrCfg);
385 
386  return true;
387 }
388 
389 
390 /**
391  * Links the Simple Retransmission Protocol to the UDP layer (TX, UDP <= SRP)
392  */
393 void _srpUdpTx(SockAddr * txAddr, uint8_t * udpPayload, int len)
394 {
395  _stats.udpTx++;
396  ms_ipa_t ipa;
397  ms_ipa_set_u32(txAddr->ip, &ipa);
398  ms_udp_tx(&ipa, txAddr->port, SC_PORT, udpPayload, len);
399 }
400 
401 
402 void _ms_tx(void * hptr, unsigned int hlen, void * plptr, unsigned int pllen)
403 {
404 
405  _stats.ethTx++;
406 #ifdef SHOW_ETH_TX
407 // printf("Requested TX: , hptr=%08x, hlen=%d, plptr = %08x; pllen = %d\n", hptr, hlen, plptr, pllen);
408  showHex8("Sending to IPMUX (header): ", hptr, hlen);
409  if (pllen > 0) showHex8("Sending to IPMUX (payload): ", plptr, pllen);
410 #endif
411 
412 #ifdef BAD_NETWORK_TEST
413  int x = rand() % BAD_NETWORK_TX_FAIL;
414  if (x == 0) return;
415  int delay = rand() % BAD_NETWORK_TX_STUTTER;
416  timeDelay(delay);
417 #endif
418 
419  netSetLed(LED_TX);
420  bool r;
421 
422  uint32_t l = ticks();
423 
424  r = ipMuxTx(hptr, hlen, pllen > 0 ? false : true); // send header
425  if (r && (pllen > 0)) r = ipMuxTx(plptr, pllen, true); // send payload
426  if (!r) {
427  ipMuxFlushCPU();
428  errPrint(true);
429  }
430  l = ticks() - l;
431  if (l > 7) l = 7;
432  _stats.txHisto[l]++;
433  if (_stats.txHisto[l] == 0xFFFF) {
434  for (int i = 0; i < 7; ++i) {
435  _stats.txHisto[l] >>= 1;
436  }
437  }
438 }
439 
440 void _ms_udp_rx(ms_ipa_t * src_ip,
441  uint16_t src_port, uint16_t dst_port,
442  uint8_t * data, unsigned int len)
443 {
444  _stats.udpRx++;
445 #ifdef UDP_ECHO
446  // echo UDP for now
447 
448  ms_udp_tx(src_ip, src_port, dst_port, data, len);
449 #endif
450 
451 #ifdef BAD_NETWORK_TEST
452  int x = rand() % BAD_NETWORK_RX_FAIL;
453  if (x == 0) return;
454 #endif
455 
456  uint32_t ip32;
457  SockAddr sAddr;
458 
459  switch (dst_port)
460  {
461  case SC_PORT:
462  ms_ipa_get_u32(src_ip, &ip32);
463  sAddr.ip = ip32;
464  sAddr.port = src_port;
465  srpUdpRx(&sAddr, data, len);
466  break;
467  default:
468  _stats.udpRxFail++;
469  logWarn("UDP Rx on port: %d", dst_port);
470  break;
471  }
472 
473 }
474 
475 void netSetIp(uint8_t * ip)
476 {
477  ms_ipa_t ipa;
478  ms_ipa_set(&ipa, ip);
479  ms_set_ip(&ipa);
480  ms_ipa_get_u32(&ipa, &_ipMuxModCfg.ip);
481  ipMuxInit(&_ipMuxModCfg, false);
482 }
483 
484 
485 bool netStackInit()
486 {
487  ms_mac_t mac;
488  ms_ipa_t ip;
489 
490 #ifdef WHITERABBIT
491 
492  volatile WrxInfo * info = wrxInfo();
493  logInfo("WRX UP: %d, Status: %x", wrxUp(), info != NULL ? info->status : 0xDEAD);
494 
495  if (!wrxUp() || !(wrxInfo()->status & WRX_STATUS_MAC_ADDRESS_VALID))
496  return errSet(ERROR_CTX(E_NET_WRXMAC));
497  uint8_t * mac_bytes = (uint8_t *) wrxInfo()->macAddr;
498 #else
499  uint8_t mac_bytes[] = { 0x08, 0x00, 0x30, 0x6C, 0x27, 0x75 };
500 #endif
501 
502 
503  ms_mac_set(&mac, mac_bytes);
504 
505 
506 #ifdef NET_SU_IP_FIX
507 
508  const uint32_t lower_mac = NET_IP_U32(
509  wrxInfo()->macAddr[2],
510  wrxInfo()->macAddr[3],
511  wrxInfo()->macAddr[4],
512  wrxInfo()->macAddr[5]);
513 
514  // combine upper and lower things.
515  const uint32_t su_ip = NET_SU_IP_FIX | (lower_mac & NET_SU_IP_DYN_MASK);
516 
517 
518  logInfo("Using temporary IP: %d.%d.%d.%d", IP32_TO_LIST(su_ip));
519 
520  // copy for reference.
521  ms_ipa_set_u32(su_ip, &_temp_ip);
522 #else
523  const uint32_t su_ip = 0;
524 #endif
525 
526  ms_ipa_set_u32(su_ip, &ip);
527 
528 
529  // initialize w/o IP
530  ms_init(&mac, &ip);
531 
532  memcpy(_ipMuxModCfg.mac, &mac, MS_MAC_LEN);
533  _ipMuxModCfg.ip = su_ip;
534  ipMuxInit(&_ipMuxModCfg, false);
535 
536  srpInit();
537 
538  return true;
539 }
540 
541 void netShowInfo(bool extended)
542 {
543  logInfo("MAC: %04X:%04X:%04X", _ipMuxModCfg.mac[0], _ipMuxModCfg.mac[1],
544  _ipMuxModCfg.mac[2]);
545  logInfo("IP : %d.%d.%d.%d", IP32_TO_LIST(_ipMuxModCfg.ip));
546 
547 #ifdef MS_USE_BOOTP
548  logInfo("IP obtain automatic");
549 #endif
550  if (extended) {
551  volatile WrxInfo * wrx = wrxInfo();
552  if (wrx != NULL) {
553  logInfo("WR Exchange Status: %08lx (MAC mode: %s)", wrx->status, wrx->status & WRX_STATUS_BROADCAST_MODE ? "Broadcast" : "P2P");
554  logInfo("WR Core Status: WR=%d SERVO=%d PTP=%d", wrx->wState, wrx->sState, wrx->pState);
555  } else {
556  logInfo("WhiteRabbit communication link failure");
557  }
558  logInfo( "Proto RX TX RX ERR TX ERR LOST");
559  logInfo("SRP %6lu %6lu - %6lu %6lu", _stats.srpRx, _stats.srpTx, _stats.srpTxErr, _stats.srpTxLost);
560  logInfo("UDP %6lu %6lu %6lu - -", _stats.udpRx, _stats.udpTx, _stats.udpRxFail);
561  logInfo("ETH %6lu %6lu %6lu - -", _stats.ethRx, _stats.ethTx, _stats.ethRxFail);
562  logInfo("Average processing time (last 1024 packets)=%u us", _stats.lastProcTime);
563 }
564 }
565 
566 
567 #endif
568 
569 // -------------------------------------------------------------------------------------------
570 // Below links the UARTBRIDGE to the SRP
571 // -------------------------------------------------------------------------------------------
572 
573 #ifdef UARTBRIDGE
574 
575 #include "net/uartbridge.h"
576 
577 void netExec()
578 {
579  ubProcess();
580 }
581 
582 
583 bool netStackInit()
584 {
585  return true;
586 }
587 
588 void _srpUdpTx(SockAddr * addr, uint8_t * data, int len)
589 {
590  ubTx(addr, data, len);
591 }
592 
593 void _ubRx(SockAddr * addr, uint8_t * data, int len) {
594  srpUdpRx(addr, data, len);
595 }
596 
597 
598 #endif
599 
600 
601 
602 /**
603  * Links the Simple Retransmission Protocol to the Message Container Format (RX, SRP => MSG)
604  */
605 void _srpRx(SockAddr * addr, uint8_t * message, int len)
606 {
607  _stats.srpRx++;
608 // showHex8("Receiving SRP: ", message, len);
609 #ifndef SRP_ECHO_MODE
610  msgRx(addr, message, len);
611 #else
612  // test echo
613  printf("PING PONG! %s\n", message);
614  srpTx(addr, message, len);
615 #endif
616 }
617 
618 // MSG interpretation is done by the remote.c module in app.
619 
620 /**
621  * Links the Message Container Protocol to he Simple Retransmission Protocol (TX, SRP <= MSG)
622  */
623 void _msgTx(SockAddr * addr, uint8_t * message, int len)
624 {
625  if (!srpTx(addr, message, len))
626  {
627  _stats.srpTxErr++;
628  }
629  else
630  {
631  _stats.srpTx++;
632  }
633 }
634 
635 
636 void _ms_icmp_du(int code, ms_ipa_t * cause_ip)
637 {
638  // --> disabled, because it was to broad
639  // received destination unreachable message. Lets check if its our destination.
640  /*SockAddr evt_addr;
641  msgGetEvtTarget(&evt_addr);
642 
643  uint32_t cause_ip32;
644  ms_ipa_get_u32(cause_ip, &cause_ip32);
645 
646  if (cause_ip32 == evt_addr.ip) {
647  msgSetEvtTarget(NULL);
648  uint8_t ip[4];
649  ms_ipa_get(cause_ip, ip);
650  logWarn("Destination unreachable, events no longer send to %d.%d.%d.%d",
651  ip[0], ip[1], ip[2], ip[3]);
652  }*/
653 }
654 
655 static int _eventFailedCount = 0;
656 
657 void _srpLost(SockAddr * addr, uint8_t msgId)
658 {
659  SockAddr evt_addr;
660  msgGetEvtTarget(&evt_addr);
661  if (sockAddrEq(addr, &evt_addr)) {
662  _eventFailedCount++;
663  }
664  _stats.srpTxLost++;
665 }
666 
668 {
669  int t = _eventFailedCount;
670  _eventFailedCount = 0;
671  return t;
672 }
673 
674 
675 
676 
678 {
679 #ifdef NET_SU_IP_FIX
680  return !_using_temp_ip && ms_ip_has();
681 #else
682  return ms_ip_has();
683 #endif
684 }
685 
686 
687 bool netInit()
688 {
689 #ifdef BAD_NETWORK_TEST
690  logwarn("WARNING: Network test 'bad network' active");
691 #endif
692  schdAddIdleTask(netExec);
693 
694  return netStackInit();
695 }
696 
697 
void msgGetEvtTarget(SockAddr *sockAddr)
Returns the event target address.
Definition: msg.c:264
void _msgTx(SockAddr *addr, uint8_t *data, int len)
Stub function, invoked by RMT when sending a MCF packet.
Definition: network.c:623
void ipMuxCfgRemote(IpMuxCfg *svrCfg)
Configure IPmux with remote settings.
Definition: ipmux.c:71
uint32_t ip
IP address.
Definition: ipmux.h:30
int timerMark(int section)
Starts the timing of a new section, the previous section is returned, or -1 if it is the first...
Definition: timer.c:53
bool srpTx(SockAddr *txAddr, uint8_t *message, int len)
Invoked by application for sending an SRP packet.
Definition: srp.c:586
bool ipMuxTx(void *buf, uint32_t txlen, bool done)
Sends data to the IPMux&#39;s CPU interface.
Definition: ipmux.c:151
GPIO Driver.
uint32_t _mcfTimeStamp()
Dependency function.
Definition: network.c:90
void _srpUdpTx(SockAddr *txAddr, uint8_t *udpPayload, int len)
Transmit UDP packet.
Definition: network.c:393
IPMUX Driver for CLBv2.
bool netIpValid()
Returns whether or not the Ip is valid.
Definition: network.c:677
Message Container Format formatter / parser.
void _srpLost(SockAddr *addr, uint8_t msgId)
Stub, invoked when an SRP message is lost.
Definition: network.c:657
#define NET_IP_U32(A, B, C, D)
Creates a U32 IP address from components.
Definition: net.h:40
IPMux configuration structure.
Definition: ipmux.h:28
uint16_t port
Port number.
Definition: net.h:34
#define TIMER_SECT_IDLE
time spend being idle
Definition: timer.h:33
PacketLog_t * getPacketLog(uint32_t pos)
Get packet log at position pos.
Definition: network.c:71
SRP or Simple Retransmission Protocol is a protocol which retransmits packets if they have not been c...
Simple task scheduler for tasks.
bool ipMuxRx(void *buf, uint32_t buflen, uint32_t *rxlen)
Received data from the IPMux&#39;s CPU interface.
Definition: ipmux.c:96
static void ipMuxFlushCPU()
Flushes the.
Definition: ipmux.h:120
void timeDelay(uint32_t msec)
Simple busy-wait delay.
Definition: tm.c:18
bool ipMuxRxAvail()
Returns whether or not there is data available for reception.
Definition: ipmux.c:77
static uint32_t ticks()
Nr of ticks since device start up.
Definition: ticks.h:37
uint32_t ip
IP address.
Definition: net.h:33
bool netMuxDest(uint32_t destIp, uint16_t *destMac)
Sets the IPMux destination.
Definition: network.c:361
#define logWarn(MSG,...)
Format a log message with warning level.
Definition: log.h:219
void gpioPinSet(int pin, bool high)
Sets the pin state.
Definition: gpio.c:35
void srpUdpRx(SockAddr *rxAddr, uint8_t *udpPayload, int len)
Invoked by UDP stack for receiving a SRP packet.
Definition: srp.c:408
#define E_INVARGUMENT
Generic error: invalid argument.
Definition: errorcode.h:112
static bool sockAddrEq(SockAddr *addr1, SockAddr *addr2)
Checks if two socket addresses are equal.
Definition: net.h:51
static uint32_t timeOutInit(uint32_t msec)
Initializes a timeout with the specified no of msecs.
Definition: tm.h:53
uint16_t mac[3]
MAC address.
Definition: ipmux.h:31
Handles MCF packed messages from the higher protocol layer.
bool netInit()
Initializes the network.
Definition: network.c:687
static bool timeOut(uint32_t to)
Checks whether or not the timeout has expired.
Definition: tm.h:77
Combination of IP address and port.
Definition: net.h:31
Manages the global system error.
void errPrint(bool clear)
Prints the last error.
Definition: err.c:79
bool schdAddIdleTask(SchdTaskF idleTask)
Adds an idle task, the task which is executed when there is nothing else to do.
Definition: scheduler.c:135
void resetPacketLog()
Reset the packet log.
Definition: network.c:77
void msgRx(SockAddr *addr, uint8_t *data, int len)
Receive a packet with data as a command.
Definition: msg.c:194
Simple timer functions.
void ipMuxInit(IpMuxCfg *modCfg, bool flush)
Initializes the IPMux local (module) only.
Definition: ipmux.c:65
bool wrxUp()
Returns whether or not the WhiteRabbit interface is up and running.
Definition: wrx.c:58
volatile WrxInfo * wrxInfo()
Returns the whiteRabbit information structure if available, else NULL.
Definition: wrx.c:63
This module is responsible for distributing error codes.
Packet log.
Definition: network.h:35
uint32_t netEventFailedCount()
Returns the number of events failed to be transmitted since the the function was previously invoked...
Definition: network.c:667
#define LOG_DEF(NAME,...)
Define a logger for a module.
Definition: log.h:129
void netSetIp(uint8_t *ip)
Sets the Ip address to the network.
Definition: network.c:475
void netShowInfo(bool extended)
Shows network configuration information.
Definition: network.c:541
bool errSet(uint32_t code, const char *error, const char *name)
Sets an error.
#define TIMER_SECT_TASK
time spend executing a task
Definition: timer.h:34
Implements a generic logger facility.
void _srpRx(SockAddr *rxAddr, uint8_t *message, int len)
Process a received SRP packet.
Definition: network.c:605
WhiteRabbit exchange exchanges information between the 2nd LM32 and WhiteRabbit though a small client...
void srpInit()
Initializes the SRP protocol engine.
Definition: srp.c:648
#define logInfo(MSG,...)
Write a log message with formatting on info level.
Definition: log.h:202