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
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
parentc5e6d7179c5894cb0fcb56a018033080776cab5e (diff)
Improvements to Duet Ethernet code
-rw-r--r--.cproject19
-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
6 files changed, 57 insertions, 60 deletions
diff --git a/.cproject b/.cproject
index a05ce993..afafcbce 100644
--- a/.cproject
+++ b/.cproject
@@ -495,25 +495,6 @@
</tool>
</toolChain>
</folderInfo>
- <folderInfo id="cdt.managedbuild.config.gnu.cross.exe.release.516195201.976458850.241502451.1275216290.918081093" name="/" resourcePath="src/DuetNG/DuetEthernet/Ethernet3/examples">
- <toolChain id="cdt.managedbuild.toolchain.gnu.cross.exe.release.1204298812" name="Cross GCC" superClass="cdt.managedbuild.toolchain.gnu.cross.exe.release" unusedChildren="">
- <option id="cdt.managedbuild.option.gnu.cross.path.1965306885.1089315274" name="Path" superClass="cdt.managedbuild.option.gnu.cross.path.1965306885"/>
- <option id="cdt.managedbuild.option.gnu.cross.prefix.444696517.1334371693" name="Prefix" superClass="cdt.managedbuild.option.gnu.cross.prefix.444696517"/>
- <targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.targetPlatform.gnu.cross" isAbstract="false" osList="all" superClass="cdt.managedbuild.targetPlatform.gnu.cross"/>
- <tool id="cdt.managedbuild.tool.gnu.cross.c.compiler.1810696678" name="Cross GCC Compiler" superClass="cdt.managedbuild.tool.gnu.cross.c.compiler.1431507147">
- <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1777016137" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
- </tool>
- <tool id="cdt.managedbuild.tool.gnu.cross.cpp.compiler.2087502449" name="Cross G++ Compiler" superClass="cdt.managedbuild.tool.gnu.cross.cpp.compiler.1806370384">
- <inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1621428779" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
- </tool>
- <tool id="cdt.managedbuild.tool.gnu.cross.c.linker.1989294900" name="Cross GCC Linker" superClass="cdt.managedbuild.tool.gnu.cross.c.linker.212863977"/>
- <tool id="cdt.managedbuild.tool.gnu.cross.cpp.linker.414747286" name="Cross G++ Linker" superClass="cdt.managedbuild.tool.gnu.cross.cpp.linker.394147701"/>
- <tool id="cdt.managedbuild.tool.gnu.cross.archiver.442213441" name="Cross GCC Archiver" superClass="cdt.managedbuild.tool.gnu.cross.archiver.136873036"/>
- <tool id="cdt.managedbuild.tool.gnu.cross.assembler.1774190451" name="Cross GCC Assembler" superClass="cdt.managedbuild.tool.gnu.cross.assembler.2020291169">
- <inputType id="cdt.managedbuild.tool.gnu.assembler.input.801121233" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
- </tool>
- </toolChain>
- </folderInfo>
<sourceEntries>
<entry excluding="src/DuetNG/DuetEthernet/Wiznet/Internet/FTPServer|src/DuetNG/DuetEthernet/Wiznet/Internet/DNS|src/DuetNG/DuetEthernet/Wiznet/Internet/FTPClient|src/DuetNG/DuetEthernet/Wiznet/Internet/MQTT|src/DuetNG/DuetEthernet/Wiznet/Internet/SNMP|src/DuetNG/DuetEthernet/Wiznet/Internet/SNTP|src/DuetNG/DuetEthernet/Wiznet/Internet/TFTP|src/DuetNG/DuetEthernet/Wiznet/Internet/httpServer|src/DuetNG/DuetEthernet/Wiznet/Application|src/DuetNG/DuetEthernet/Ethernet3|src/DuetNG/DuetEthernet/Ethernet3/examples|src/RADDS|src/DuetNG/DuetWiFi|src/Duet" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
</sourceEntries>
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;
}