diff options
author | David Crocker <dcrocker@eschertech.com> | 2022-05-23 09:32:29 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2022-05-23 09:32:29 +0300 |
commit | 25a579f60f01a5477816738e451146c4d70b91a1 (patch) | |
tree | 9058da74ba5b3adf123476503e4607d625d06bab | |
parent | 60536aa33e5965bba25ce130281e7761fa96e1a8 (diff) | |
parent | 386477f433041d9a74143d84605de24aacfd0838 (diff) |
Merge branch '3.4-dev' into 3.4-spi-tft
-rw-r--r-- | src/Networking/UploadingNetworkResponder.cpp | 10 | ||||
-rw-r--r-- | src/Networking/W5500Ethernet/Wiznet/Ethernet/WizSpi.cpp | 22 | ||||
-rw-r--r-- | src/ObjectModel/ObjectModel.cpp | 9 | ||||
-rw-r--r-- | src/Platform/OutputMemory.cpp | 68 | ||||
-rw-r--r-- | src/Platform/OutputMemory.h | 1 | ||||
-rw-r--r-- | src/Version.h | 2 |
6 files changed, 57 insertions, 55 deletions
diff --git a/src/Networking/UploadingNetworkResponder.cpp b/src/Networking/UploadingNetworkResponder.cpp index 5b4245de..6cac6b39 100644 --- a/src/Networking/UploadingNetworkResponder.cpp +++ b/src/Networking/UploadingNetworkResponder.cpp @@ -111,7 +111,14 @@ void UploadingNetworkResponder::FinishUpload(uint32_t fileLength, time_t fileLas const char *uploadFilename = filenameBeingProcessed.c_str(); if (uploadError) { +#if 0 // Temporary code to save files with upload errors and report successful uploads + String<MaxFilenameLength> newName; + MassStorage::CombineName(newName.GetRef(), Platform::GetGCodeDir(), "uploadError_"); + newName.catf("%04u", (unsigned int)(millis() % 10000)); + MassStorage::Rename(uploadFilename, newName.c_str(), true, true); +#else MassStorage::Delete(uploadFilename, true); +#endif } else { @@ -126,6 +133,9 @@ void UploadingNetworkResponder::FinishUpload(uint32_t fileLength, time_t fileLas // Update the file timestamp if it was specified (void)MassStorage::SetLastModifiedTime(origFilename.c_str(), fileLastModified); } +#if 0 // Temporary code to save files with upload errors and report successful uploads + GetPlatform().Message(GenericMessage, "Successful upload\n"); +#endif } filenameBeingProcessed.Clear(); } diff --git a/src/Networking/W5500Ethernet/Wiznet/Ethernet/WizSpi.cpp b/src/Networking/W5500Ethernet/Wiznet/Ethernet/WizSpi.cpp index 525767d5..3c1b79db 100644 --- a/src/Networking/W5500Ethernet/Wiznet/Ethernet/WizSpi.cpp +++ b/src/Networking/W5500Ethernet/Wiznet/Ethernet/WizSpi.cpp @@ -7,6 +7,7 @@ #include "WizSpi.h" #include <Config/Pins.h> +#include <Cache.h> // Define exactly one of the following as 1, the other as zero #define USE_PDC 1 // use peripheral DMA controller @@ -32,26 +33,25 @@ const unsigned int SpiPeripheralChannelId = 0; // we use NPCS0 as the slave se // Functions called by the W5500 module to transfer data to/from the W5500 via SPI #if USE_PDC -static Pdc *spi_pdc; static inline void spi_rx_dma_enable() noexcept { - pdc_enable_transfer(spi_pdc, PERIPH_PTCR_RXTEN | PERIPH_PTCR_TXTEN); // we have to transmit in order to receive + pdc_enable_transfer(spi_get_pdc_base(W5500_SPI), PERIPH_PTCR_RXTEN | PERIPH_PTCR_TXTEN); // we have to transmit in order to receive } static inline void spi_tx_dma_enable() noexcept { - pdc_enable_transfer(spi_pdc, PERIPH_PTCR_TXTEN); + pdc_enable_transfer(spi_get_pdc_base(W5500_SPI), PERIPH_PTCR_TXTEN); } static inline void spi_rx_dma_disable() noexcept { - pdc_disable_transfer(spi_pdc, PERIPH_PTCR_RXTDIS | PERIPH_PTCR_TXTDIS); // we have to transmit in order to receive + pdc_disable_transfer(spi_get_pdc_base(W5500_SPI), PERIPH_PTCR_RXTDIS | PERIPH_PTCR_TXTDIS); // we have to transmit in order to receive } static inline void spi_tx_dma_disable() noexcept { - pdc_disable_transfer(spi_pdc, PERIPH_PTCR_TXTDIS); + pdc_disable_transfer(spi_get_pdc_base(W5500_SPI), PERIPH_PTCR_TXTDIS); } static inline bool spi_dma_check_rx_complete() noexcept @@ -69,7 +69,7 @@ static void spi_tx_dma_setup(const uint8_t *buf, uint32_t length) noexcept pdc_packet_t pdc_spi_packet; pdc_spi_packet.ul_addr = reinterpret_cast<uint32_t>(buf); pdc_spi_packet.ul_size = length; - pdc_tx_init(spi_pdc, &pdc_spi_packet, nullptr); + pdc_tx_init(spi_get_pdc_base(W5500_SPI), &pdc_spi_packet, nullptr); } static void spi_rx_dma_setup(uint8_t *buf, uint32_t length) noexcept @@ -77,8 +77,8 @@ static void spi_rx_dma_setup(uint8_t *buf, uint32_t length) noexcept pdc_packet_t pdc_spi_packet; pdc_spi_packet.ul_addr = reinterpret_cast<uint32_t>(buf); pdc_spi_packet.ul_size = length; - pdc_rx_init(spi_pdc, &pdc_spi_packet, nullptr); - pdc_tx_init(spi_pdc, &pdc_spi_packet, nullptr); // we have to transmit in order to receive + pdc_rx_init(spi_get_pdc_base(W5500_SPI), &pdc_spi_packet, nullptr); + pdc_tx_init(spi_get_pdc_base(W5500_SPI), &pdc_spi_packet, nullptr); // we have to transmit in order to receive } #endif @@ -170,7 +170,6 @@ namespace WizSpi void Init() noexcept { #if USE_PDC - spi_pdc = spi_get_pdc_base(W5500_SPI); // The PDCs are masters 2 and 3 and the SRAM is slave 0. Give the receive PDCs the highest priority. matrix_set_master_burst_type(0, MATRIX_ULBT_8_BEAT_BURST); matrix_set_slave_default_master_type(0, MATRIX_DEFMSTR_LAST_DEFAULT_MASTER); @@ -371,7 +370,11 @@ namespace WizSpi { --timeout; } + // The SPI peripheral signals transfer complete at the start of transferring the last byte. If we disable the DMA too soon, there might be a chance + // that the transfer does not complete. Therefore, delay disabling DMA until we have invalidated the cache, which takes some time. + Cache::InvalidateAfterDMAReceive(rx_data, len); spi_rx_dma_disable(); + if (timeout == 0) { return SPI_ERROR_TIMEOUT; @@ -414,6 +417,7 @@ namespace WizSpi if (len != 0) { #if USE_PDC + Cache::FlushBeforeDMASend(tx_data, len); spi_tx_dma_setup(tx_data, len); spi_tx_dma_enable(); uint32_t timeout = SPI_TIMEOUT; diff --git a/src/ObjectModel/ObjectModel.cpp b/src/ObjectModel/ObjectModel.cpp index 215c7414..5bffcd3c 100644 --- a/src/ObjectModel/ObjectModel.cpp +++ b/src/ObjectModel/ObjectModel.cpp @@ -1072,10 +1072,6 @@ decrease(strlen(idString)) // recursion variant throw context.ConstructParseException("array index out of bounds"); } - if (context.WantExists()) - { - return ExpressionValue(true); - } return ExpressionValue((int32_t)(Bitmap<uint32_t>::MakeFromRaw(val.uVal).GetSetBitNumber(context.GetLastIndex()))); } } @@ -1121,11 +1117,6 @@ decrease(strlen(idString)) // recursion variant throw context.ConstructParseException("array index out of bounds"); } - if (context.WantExists()) - { - return ExpressionValue(true); - } - return ExpressionValue((int32_t)(Bitmap<uint64_t>::MakeFromRaw(val.Get56BitValue()).GetSetBitNumber(context.GetLastIndex()))); } } diff --git a/src/Platform/OutputMemory.cpp b/src/Platform/OutputMemory.cpp index b2ac7433..14a1e368 100644 --- a/src/Platform/OutputMemory.cpp +++ b/src/Platform/OutputMemory.cpp @@ -22,26 +22,29 @@ void OutputBuffer::Append(OutputBuffer *other) noexcept if (other != nullptr) { last->next = other; - last = other->last; + OutputBuffer * const newLast = other->last; if (other->hadOverflow) { hadOverflow = true; } - for (OutputBuffer *item = Next(); item != other; item = item->Next()) + OutputBuffer *item = this; + do { - item->last = last; + item->last = newLast; + item = item->Next(); } + while (item != other); } } void OutputBuffer::IncreaseReferences(size_t refs) noexcept { - if (refs > 0) + if (refs != 0) { TaskCriticalSectionLocker lock; - for(OutputBuffer *item = this; item != nullptr; item = item->Next()) + for (OutputBuffer *item = this; item != nullptr; item = item->Next()) { item->references += refs; item->isReferenced = true; @@ -59,20 +62,6 @@ size_t OutputBuffer::Length() const noexcept return totalLength; } -char &OutputBuffer::operator[](size_t index) noexcept -{ - // Get the right buffer to access - OutputBuffer *itemToIndex = this; - while (index >= itemToIndex->DataLength()) - { - index -= itemToIndex->DataLength(); - itemToIndex = itemToIndex->Next(); - } - - // Return the char reference - return itemToIndex->data[index]; -} - char OutputBuffer::operator[](size_t index) const noexcept { // Get the right buffer to access @@ -89,7 +78,7 @@ char OutputBuffer::operator[](size_t index) const noexcept const char *OutputBuffer::Read(size_t len) noexcept { - size_t offset = bytesRead; + const size_t offset = bytesRead; bytesRead += len; return data + offset; } @@ -120,7 +109,7 @@ size_t OutputBuffer::printf(const char *_ecv_array fmt, ...) noexcept { va_list vargs; va_start(vargs, fmt); - size_t ret = vprintf(fmt, vargs); + const size_t ret = vprintf(fmt, vargs); va_end(vargs); return ret; } @@ -138,7 +127,7 @@ size_t OutputBuffer::catf(const char *_ecv_array fmt, ...) noexcept { va_list vargs; va_start(vargs, fmt); - size_t ret = vcatf(fmt, vargs); + const size_t ret = vcatf(fmt, vargs); va_end(vargs); return ret; } @@ -146,9 +135,13 @@ size_t OutputBuffer::catf(const char *_ecv_array fmt, ...) noexcept size_t OutputBuffer::lcatf(const char *_ecv_array fmt, ...) noexcept { size_t extra = 0; - if (Length() != 0 && operator[](Length() - 1) != '\n') + if (last->dataLength != 0 && last->data[last->dataLength - 1] != '\n') { extra = cat('\n'); + if (extra == 0) + { + return 0; + } } va_list vargs; @@ -235,11 +228,12 @@ size_t OutputBuffer::cat(const char *_ecv_array src, size_t len) noexcept } nextBuffer->references = references; last->next = nextBuffer; - last = nextBuffer->last; - for (OutputBuffer *item = Next(); item != nextBuffer; item = item->Next()) + OutputBuffer *item = this; + do { - item->last = last; - } + item->last = nextBuffer; + item = item->Next(); + } while (item != nextBuffer); } const size_t copyLength = min<size_t>(len - copied, OUTPUT_BUFFER_SIZE - last->dataLength); memcpy(last->data + last->dataLength, src + copied, copyLength); @@ -251,11 +245,17 @@ size_t OutputBuffer::cat(const char *_ecv_array src, size_t len) noexcept size_t OutputBuffer::lcat(const char *_ecv_array src, size_t len) noexcept { - if (Length() != 0) + size_t extra = 0; + if (last->dataLength != 0 && last->data[last->dataLength - 1] != '\n') { - cat('\n'); + extra = cat('\n'); + if (extra == 0) + { + return 0; + } } - return cat(src, len); + + return cat(src, len) + extra; } size_t OutputBuffer::cat(StringRef &str) noexcept @@ -294,13 +294,11 @@ size_t OutputBuffer::EncodeChar(char c) noexcept if (esc != 0) { - cat('\\'); - cat(esc); - return 2; + const size_t written = cat('\\'); + return (written == 0) ? written : written + cat(esc); } - cat(c); - return 1; + return cat(c); } size_t OutputBuffer::EncodeReply(OutputBuffer *src) noexcept diff --git a/src/Platform/OutputMemory.h b/src/Platform/OutputMemory.h index c8a3f59b..0ef8cd53 100644 --- a/src/Platform/OutputMemory.h +++ b/src/Platform/OutputMemory.h @@ -35,7 +35,6 @@ public: size_t DataLength() const noexcept { return dataLength; } // How many bytes have been written to this instance? size_t Length() const noexcept; // How many bytes have been written to the whole chain? - char& operator[](size_t index) noexcept; char operator[](size_t index) const noexcept; const char *_ecv_array Read(size_t len) noexcept; void Taken(size_t len) noexcept { bytesRead += len; } diff --git a/src/Version.h b/src/Version.h index 8a6cdf11..f2a71146 100644 --- a/src/Version.h +++ b/src/Version.h @@ -10,7 +10,7 @@ #ifndef VERSION // Note: the complete VERSION string must be in standard version number format and must not contain spaces! This is so that DWC can parse it. -# define MAIN_VERSION "3.4.1rc1" +# define MAIN_VERSION "3.4.1rc1+1" # ifdef USE_CAN0 # define VERSION_SUFFIX "(CAN0)" # else |