Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Crocker <dcrocker@eschertech.com>2016-12-29 19:19:21 +0300
committerDavid Crocker <dcrocker@eschertech.com>2016-12-29 19:19:21 +0300
commitf4f6ad3c61a845fffaeee26f68369fe04e06db8d (patch)
tree5bc947ff929da6dbfeee05941e20c805337dce8d /src
parentc5e6d7179c5894cb0fcb56a018033080776cab5e (diff)
Improvements to Duet Ethernet code
Diffstat (limited to 'src')
-rw-r--r--src/DuetNG/DuetEthernet/Network.cpp8
-rw-r--r--src/DuetNG/DuetEthernet/NetworkBuffer.h8
-rw-r--r--src/DuetNG/DuetEthernet/NetworkDefs.h6
-rw-r--r--src/DuetNG/DuetEthernet/Socket.cpp2
-rw-r--r--src/DuetNG/DuetEthernet/Wiznet/Ethernet/WizSpi.cpp74
5 files changed, 57 insertions, 41 deletions
diff --git a/src/DuetNG/DuetEthernet/Network.cpp b/src/DuetNG/DuetEthernet/Network.cpp
index 5f7bd72c..1a2298d7 100644
--- a/src/DuetNG/DuetEthernet/Network.cpp
+++ b/src/DuetNG/DuetEthernet/Network.cpp
@@ -180,7 +180,12 @@ void Network::Start()
Platform::WriteDigital(EspResetPin, HIGH); // raise /Reset pin
delay(55); // W5500 needs 50ms to start up
- static const uint8_t bufSizes[8] = { 2, 2, 2, 2, 2, 2, 2, 2 };
+#ifdef USE_3K_BUFFERS
+ static const uint8_t bufSizes[8] = { 3, 3, 3, 3, 1, 1, 1, 1 }; // 3K buffers for http, 1K for everything else (FTP will be slow)
+#else
+ static const uint8_t bufSizes[8] = { 2, 2, 2, 2, 2, 2, 2, 2 }; // 2K buffers for everything
+#endif
+
wizchip_init(bufSizes, bufSizes);
setSHAR(platform->MACAddress());
@@ -195,7 +200,6 @@ void Network::Stop()
{
if (state != NetworkState::disabled)
{
-//TODO Ethernet.stop();
if (usingDhcp)
{
DHCP_stop();
diff --git a/src/DuetNG/DuetEthernet/NetworkBuffer.h b/src/DuetNG/DuetEthernet/NetworkBuffer.h
index 63384d89..b7ffcc0a 100644
--- a/src/DuetNG/DuetEthernet/NetworkBuffer.h
+++ b/src/DuetNG/DuetEthernet/NetworkBuffer.h
@@ -9,6 +9,7 @@
#define SRC_DUETNG_DUETETHERNET_NETWORKBUFFER_H_
#include "RepRapFirmware.h"
+#include "NetworkDefs.h"
// Network buffer class. These buffers are 2K long so that they can accept as much data as the W5500 can provide in one go.
class NetworkBuffer
@@ -55,7 +56,12 @@ public:
// Alocate buffers and put them in the freelist
static void AllocateBuffers(unsigned int number);
- static const size_t bufferSize = 2048;
+ static const size_t bufferSize =
+#ifdef USE_3K_BUFFERS
+ 3 * 1024;
+#else
+ 2 * 1024;
+#endif
private:
NetworkBuffer(NetworkBuffer *n);
diff --git a/src/DuetNG/DuetEthernet/NetworkDefs.h b/src/DuetNG/DuetEthernet/NetworkDefs.h
index 66bc25c6..c6408df0 100644
--- a/src/DuetNG/DuetEthernet/NetworkDefs.h
+++ b/src/DuetNG/DuetEthernet/NetworkDefs.h
@@ -36,6 +36,10 @@ const Port TELNET_PORT = 23;
const unsigned int TCP_MSS = 1460;
const size_t NetworkTransactionCount = 8; // number of NetworkTransactions to be used for network IO
-const size_t NetworkBufferCount = 12; // number of 2K network buffers
+const size_t NetworkBufferCount = 12; // number of 2K or 3K network buffers
+
+// Define the following to use 3K buffers on the W5500 for the HTTP sockets and smaller buffers for everything else
+// It doesn't seem to work, the chip keeps telling us that 1 byte is available.
+//#define USE_3K_BUFFERS 1
#endif /* SRC_DUETNG_DUETETHERNET_NETWORKDEFS_H_ */
diff --git a/src/DuetNG/DuetEthernet/Socket.cpp b/src/DuetNG/DuetEthernet/Socket.cpp
index 9624c56e..045b76a1 100644
--- a/src/DuetNG/DuetEthernet/Socket.cpp
+++ b/src/DuetNG/DuetEthernet/Socket.cpp
@@ -136,7 +136,7 @@ bool Socket::ReadBuffer(const char *&buffer, size_t &len)
return false;
}
- len = 2048; // initial value passed to TakeData is the maximum amount we will take
+ len = NetworkBuffer::bufferSize; // initial value passed to TakeData is the maximum amount we will take
buffer = reinterpret_cast<const char*>(receivedData->TakeData(len));
// debugPrintf("Taking %d bytes\n", len);
return true;
diff --git a/src/DuetNG/DuetEthernet/Wiznet/Ethernet/WizSpi.cpp b/src/DuetNG/DuetEthernet/Wiznet/Ethernet/WizSpi.cpp
index 70ebf1d4..e6c9d3ce 100644
--- a/src/DuetNG/DuetEthernet/Wiznet/Ethernet/WizSpi.cpp
+++ b/src/DuetNG/DuetEthernet/Wiznet/Ethernet/WizSpi.cpp
@@ -231,11 +231,7 @@ namespace WizSpi
ConfigurePin(g_APinDescription[APIN_SPI_SCK]);
ConfigurePin(g_APinDescription[APIN_SPI_MOSI]);
ConfigurePin(g_APinDescription[APIN_SPI_MISO]);
-#if 1
- pinMode(APIN_SPI_SS0, OUTPUT_HIGH); // use manual SS control for now
-#else
- ConfigurePin(g_APinDescription[APIN_SPI_SS0]);
-#endif
+ pinMode(APIN_SPI_SS0, OUTPUT_HIGH); // use manual SS control
pmc_enable_periph_clk(ID_SPI);
@@ -279,7 +275,10 @@ namespace WizSpi
#endif
}
- // Wait for transmitter ready returning true if timed out
+// The remaining functions are speed-critical, so use full optimisation
+#pragma GCC optimize ("O3")
+
+ // Wait for transmit buffer empty, returning true if timed out
static inline bool waitForTxReady()
{
uint32_t timeout = SPI_TIMEOUT;
@@ -293,7 +292,7 @@ namespace WizSpi
return false;
}
- // Wait for transmitter empty returning true if timed out
+ // Wait for transmitter empty, returning true if timed out
static inline bool waitForTxEmpty()
{
uint32_t timeout = SPI_TIMEOUT;
@@ -307,7 +306,7 @@ namespace WizSpi
return false;
}
- // Wait for receive data available returning true if timed out
+ // Wait for receive data available, returning true if timed out
static inline bool waitForRxReady()
{
uint32_t timeout = SPI_TIMEOUT;
@@ -369,7 +368,7 @@ namespace WizSpi
{
(void)SPI->SPI_RDR; // clear previous data
}
- SPI->SPI_TDR = 0x000000FF | SPI_TDR_LASTXFER;
+ SPI->SPI_TDR = 0x000000FF;
if (!waitForRxReady())
{
return (uint8_t)SPI->SPI_RDR;
@@ -381,49 +380,59 @@ namespace WizSpi
// Write a single byte. Called after sending the address.
void WriteByte(uint8_t b)
{
- const uint32_t dOut = b | SPI_TDR_LASTXFER;
+ const uint32_t dOut = b;
if (!waitForTxReady())
{
SPI->SPI_TDR = dOut;
}
}
+ // Read some data
spi_status_t ReadBurst(uint8_t* rx_data, size_t len)
{
- if (waitForTxEmpty())
- {
- return SPI_ERROR_TIMEOUT;
- }
-
- while ((SPI->SPI_SR & SPI_SR_RDRF) != 0)
- {
- (void)SPI->SPI_RDR; // clear previous data
- }
-
- for (size_t i = 0; i < len; ++i)
+ if (len != 0)
{
- const uint32_t dOut = ((i + 1) == len) ? 0x000000FF | SPI_TDR_LASTXFER : 0x000000FF;
- if (waitForTxReady())
+ if (waitForTxEmpty())
{
return SPI_ERROR_TIMEOUT;
}
- // Write to transmit register
- SPI->SPI_TDR = dOut;
+ while ((SPI->SPI_SR & SPI_SR_RDRF) != 0)
+ {
+ (void)SPI->SPI_RDR; // clear previous data
+ }
+
+ const uint32_t dOut = 0x000000FF;
+ SPI->SPI_TDR = dOut; // send first byte
+ while (--len != 0)
+ {
+ // Wait for receive data available and transmit buffer empty
+ uint32_t timeout = SPI_TIMEOUT + 1;
+ do
+ {
+ if (--timeout == 0)
+ {
+ return SPI_ERROR_TIMEOUT;
+ }
+ }
+ while ((SPI->SPI_SR & (SPI_SR_RDRF | SPI_SR_TDRE)) != (SPI_SR_RDRF | SPI_SR_TDRE));
+
+ const uint32_t din = SPI->SPI_RDR; // get data from receive register
+ SPI->SPI_TDR = dOut; // write to transmit register immediately
+ *rx_data++ = (uint8_t)din;
+ }
- // Wait for receive register
if (waitForRxReady())
{
return SPI_ERROR_TIMEOUT;
}
- // Get data from receive register
- *rx_data++ = (uint8_t)SPI->SPI_RDR;
+ *rx_data++ = (uint8_t)SPI->SPI_RDR; // Get last byte from receive register
}
-
return SPI_OK;
}
+ // Send some data
spi_status_t SendBurst(const uint8_t* tx_data, size_t len)
{
for (uint32_t i = 0; i < len; ++i)
@@ -441,13 +450,6 @@ namespace WizSpi
// Write to transmit register
SPI->SPI_TDR = dOut;
- // Wait for receive register
- if (waitForRxReady())
- {
- return SPI_ERROR_TIMEOUT;
- }
-
- // Get data from receive register
(void)SPI->SPI_RDR;
}