-
Notifications
You must be signed in to change notification settings - Fork 7
/
ec_w5100.cpp
56 lines (46 loc) · 1.09 KB
/
ec_w5100.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <Arduino.h>
#include "w5100.h"
#include <SPI.h> // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include "xgeneral.h"
#include "ethercattype.h"
#include "ecs_slave.h"
#include "ec_device.h"
#include "fsm_slave.h"
#include "ec_sii.h"
#include "ec_regs.h"
#include "ec_net.h"
#include "ec_cmd.h"
#include "ec_com.h"
static byte mac[6] = { 0x54, 0x55, 0x58, 0x10, 0x00, 0x24 };
#define BUFFER_SIZE 600
uint8_t buf[BUFFER_SIZE];
SOCKET s;
extern "C" int ethernetSetup()
{
W5100.init();
W5100.writeSnMR(s, SnMR::MACRAW);
W5100.execCmdSn(s, Sock_OPEN);
return 0;
}
void ecat_rcv(ecat_slave *ecs)
{
int16_t len;
uint8_t *ecat;
len = W5100.getRXReceivedSize(s);
if (len <= 0){
return;
}
W5100.recv_data_processing(s, buf, len);
W5100.execCmdSn(s, Sock_RECV);
ecat = (uint8_t *)&buf[2];
if (eth_hdr(ecat)->ether_type != htons(ETH_P_ECAT)){
return;
}
ec_process_datagrams(ecs, len - 2, ecat);
}
extern "C" void ec_tx_pkt(uint8_t *buf, int sz, struct ec_device *txdev)
{
W5100.send_data_processing(s, buf, sz);
W5100.execCmdSn(s, Sock_SEND_MAC);
}