Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow redefining ETHERNET_MAX_SOCK_NUM, ETHERNET_SPI_SPEED #217

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Ethernet.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
// up to 4 sockets. W5200 & W5500 can have up to 8 sockets. Several bytes
// of RAM are used for each socket. Reducing the maximum can save RAM, but
// you are limited to fewer simultaneous connections.
#if defined(RAMEND) && defined(RAMSTART) && ((RAMEND - RAMSTART) <= 2048)
#if defined(ETHERNET_MAX_SOCK_NUM)
#define MAX_SOCK_NUM ETHERNET_MAX_SOCK_NUM
#elif defined(RAMEND) && defined(RAMSTART) && ((RAMEND - RAMSTART) <= 2048)
#define MAX_SOCK_NUM 4
#else
#define MAX_SOCK_NUM 8
Expand Down
40 changes: 15 additions & 25 deletions src/utility/w5100.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,28 @@
#include <Arduino.h>
#include <SPI.h>

// Safe for all chips
#define SPI_ETHERNET_SETTINGS SPISettings(14000000, MSBFIRST, SPI_MODE0)

// Safe for W5200 and W5500, but too fast for W5100
// Uncomment this if you know you'll never need W5100 support.
// Higher SPI clock only results in faster transfer to hosts on a LAN
// or with very low packet latency. With ordinary internet latency,
// the TCP window size & packet loss determine your overall speed.
//#define SPI_ETHERNET_SETTINGS SPISettings(30000000, MSBFIRST, SPI_MODE0)
#if defined(ETHERNET_SPI_SPEED)
// Good! Using the configured value.
#elif defined(ARDUINO_ARCH_ARC32)
// Arduino 101's SPI can not run faster than 8 MHz.
#define ETHERNET_SPI_SPEED 8000000
#elif defined(__SAMD21G18A__)
// Arduino Zero can't use W5100-based shields faster than 8 MHz
// https://github.com/arduino-libraries/Ethernet/issues/37#issuecomment-408036848
// W5500 does seem to work at 12 MHz. Delete this if only using W5500
#define ETHERNET_SPI_SPEED 8000000
#else
// Default. Safe for all chips.
#define ETHERNET_SPI_SPEED 14000000
#endif

#define SPI_ETHERNET_SETTINGS SPISettings(ETHERNET_SPI_SPEED, MSBFIRST, SPI_MODE0)

// Require Ethernet.h, because we need MAX_SOCK_NUM
#ifndef ethernet_h_
#error "Ethernet.h must be included before w5100.h"
#endif


// Arduino 101's SPI can not run faster than 8 MHz.
#if defined(ARDUINO_ARCH_ARC32)
#undef SPI_ETHERNET_SETTINGS
#define SPI_ETHERNET_SETTINGS SPISettings(8000000, MSBFIRST, SPI_MODE0)
#endif

// Arduino Zero can't use W5100-based shields faster than 8 MHz
// https://github.com/arduino-libraries/Ethernet/issues/37#issuecomment-408036848
// W5500 does seem to work at 12 MHz. Delete this if only using W5500
#if defined(__SAMD21G18A__)
#undef SPI_ETHERNET_SETTINGS
#define SPI_ETHERNET_SETTINGS SPISettings(8000000, MSBFIRST, SPI_MODE0)
#endif


typedef uint8_t SOCKET;

class SnMR {
Expand Down