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>2020-01-10 23:38:29 +0300
committerDavid Crocker <dcrocker@eschertech.com>2020-01-10 23:38:29 +0300
commit5ff678917d3eee259687d5ef235c107126330898 (patch)
treedcac02636a9a751ac06c2a98cad33a12f483b262 /src
parent15d4d43dddd88fcff2591e38dc4bf29c1dfe8abf (diff)
Suspend Network task while waiting for WiFi SPI transfer to complete
Diffstat (limited to 'src')
-rw-r--r--src/DuetNG/DueXn.cpp2
-rw-r--r--src/Hardware/I2C.cpp15
-rw-r--r--src/Movement/HeightControl/HeightController.cpp2
-rw-r--r--src/Movement/Move.cpp2
-rw-r--r--src/Networking/ESP8266WiFi/WiFiInterface.cpp34
-rw-r--r--src/Networking/ESP8266WiFi/WiFiInterface.h1
-rw-r--r--src/RepRap.cpp14
-rw-r--r--src/Version.h2
8 files changed, 31 insertions, 41 deletions
diff --git a/src/DuetNG/DueXn.cpp b/src/DuetNG/DueXn.cpp
index f568691a..4f23199f 100644
--- a/src/DuetNG/DueXn.cpp
+++ b/src/DuetNG/DueXn.cpp
@@ -88,7 +88,7 @@ namespace DuetExpansion
{
taskWaiting = true;
cpu_irq_enable();
- TaskBase::Take();
+ (void)TaskBase::Take();
}
else
{
diff --git a/src/Hardware/I2C.cpp b/src/Hardware/I2C.cpp
index aca1c810..c62db5e7 100644
--- a/src/Hardware/I2C.cpp
+++ b/src/Hardware/I2C.cpp
@@ -19,7 +19,7 @@ void I2C::Init() noexcept
if (!i2cInitialised)
{
MutexLocker lock(Tasks::GetI2CMutex());
- if (!i2cInitialised) // test it again, now that we own the mutex
+ if (!i2cInitialised) // test it again, now that we own the mutex
{
I2C_IFACE.BeginMaster(I2cClockFreq);
i2cInitialised = true;
@@ -32,18 +32,13 @@ void I2C::Init() noexcept
#include "RTOSIface/RTOSIface.h"
-static TaskHandle_t twiTask = nullptr; // the task that is waiting for a TWI command to complete
+static TaskHandle twiTask = nullptr; // the task that is waiting for a TWI command to complete
extern "C" void WIRE_ISR_HANDLER() noexcept
{
WIRE_INTERFACE->TWI_IDR = 0xFFFFFFFF;
- if (twiTask != nullptr)
- {
- BaseType_t higherPriorityTaskWoken = pdFALSE;
- vTaskNotifyGiveFromISR(twiTask, &higherPriorityTaskWoken); // wake up the task
- twiTask = nullptr;
- portYIELD_FROM_ISR(higherPriorityTaskWoken);
- }
+ TaskBase::GiveFromISR(twiTask); // wake up the task
+ twiTask = nullptr;
}
uint32_t I2C::statusWaitFunc(Twi *twi, uint32_t bitsToWaitFor) noexcept
@@ -52,7 +47,7 @@ uint32_t I2C::statusWaitFunc(Twi *twi, uint32_t bitsToWaitFor) noexcept
if ((sr & bitsToWaitFor) == 0)
{
// Suspend this task until we get an interrupt indicating that a status bit that we are interested in has been set
- twiTask = xTaskGetCurrentTaskHandle();
+ twiTask = TaskBase::GetCallerTaskHandle();
twi->TWI_IER = bitsToWaitFor;
(void)TaskBase::Take(2);
sr = twi->TWI_SR;
diff --git a/src/Movement/HeightControl/HeightController.cpp b/src/Movement/HeightControl/HeightController.cpp
index 961ced31..40e27d41 100644
--- a/src/Movement/HeightControl/HeightController.cpp
+++ b/src/Movement/HeightControl/HeightController.cpp
@@ -149,7 +149,7 @@ void HeightController::Stop()
{
if (state == PidState::stopped)
{
- heightControllerTask->Take();
+ (void)TaskBase::Take();
// Here when we get woken up again, normally because the state has been changed to 'starting'. So get ready to start.
lastWakeTime = xTaskGetTickCount();
diff --git a/src/Movement/Move.cpp b/src/Movement/Move.cpp
index 3614b08c..9c573781 100644
--- a/src/Movement/Move.cpp
+++ b/src/Movement/Move.cpp
@@ -1006,7 +1006,7 @@ void Move::LaserTaskRun() noexcept
for (;;)
{
// Sleep until we are woken up by the start of a move
- TaskBase::Take();
+ (void)TaskBase::Take();
if (reprap.GetGCodes().GetMachineType() == MachineType::laser)
{
diff --git a/src/Networking/ESP8266WiFi/WiFiInterface.cpp b/src/Networking/ESP8266WiFi/WiFiInterface.cpp
index b3a3f6fb..6c2cd6a3 100644
--- a/src/Networking/ESP8266WiFi/WiFiInterface.cpp
+++ b/src/Networking/ESP8266WiFi/WiFiInterface.cpp
@@ -141,7 +141,7 @@ static inline void DisableEspInterrupt() noexcept
/*-----------------------------------------------------------------------------------*/
// WiFi interface class
-WiFiInterface::WiFiInterface(Platform& p) noexcept : platform(p), uploader(nullptr), ftpDataPort(0), closeDataPort(false),
+WiFiInterface::WiFiInterface(Platform& p) noexcept : platform(p), uploader(nullptr), espWaitingTask(nullptr), ftpDataPort(0), closeDataPort(false),
state(NetworkState::disabled), requestedMode(WiFiState::disabled), currentMode(WiFiState::disabled), activated(false),
espStatusChanged(false), spiTxUnderruns(0), spiRxOverruns(0), serialRunning(false), debugMessageChars(0)
{
@@ -1614,25 +1614,24 @@ int32_t WiFiInterface::SendCommand(NetworkCommand cmd, SocketNumber socketNum, u
// Tell the ESP that we are ready to accept data
digitalWrite(SamTfrReadyPin, HIGH);
- // Wait for the DMA complete interrupt, with timeout
- // When we use RTOS we should allow other tasks to run here
+ // Wait until the DMA transfer is complete, with timeout
+ do
{
- const uint32_t now = millis();
- while (transferPending || !spi_dma_check_rx_complete())
+ espWaitingTask = TaskBase::GetCallerTaskHandle();
+ if (TaskBase::Take(WifiResponseTimeoutMillis))
{
- if (digitalRead(SamCsPin) && millis() - now > WifiResponseTimeoutMillis) // if no transfer in progress and timed out
+ if (reprap.Debug(moduleNetwork))
{
- if (reprap.Debug(moduleNetwork))
- {
- debugPrintf("ResponseTimeout, pending=%d\n", (int)transferPending);
- }
- transferPending = false;
- spi_dma_disable();
- ++responseTimeoutCount;
- return ResponseTimeout;
+ debugPrintf("ResponseTimeout, pending=%d\n", (int)transferPending);
}
+ transferPending = false;
+ spi_dma_disable();
+ ++responseTimeoutCount;
+ return ResponseTimeout;
}
- }
+ } while (transferPending);
+
+ while (!spi_dma_check_rx_complete()) { } // Wait for DMA to complete
// Look at the response
if (bufferIn.hdr.formatVersion != MyFormatVersion)
@@ -1645,8 +1644,8 @@ int32_t WiFiInterface::SendCommand(NetworkCommand cmd, SocketNumber socketNum, u
}
if ( (bufferIn.hdr.state == WiFiState::autoReconnecting || bufferIn.hdr.state == WiFiState::reconnecting)
- && currentMode != WiFiState::autoReconnecting && currentMode != WiFiState::reconnecting
- )
+ && currentMode != WiFiState::autoReconnecting && currentMode != WiFiState::reconnecting
+ )
{
++reconnectCount;
}
@@ -1765,6 +1764,7 @@ void WiFiInterface::SpiInterrupt() noexcept
++spiTxUnderruns;
}
transferPending = false;
+ TaskBase::GiveFromISR(espWaitingTask);
}
}
diff --git a/src/Networking/ESP8266WiFi/WiFiInterface.h b/src/Networking/ESP8266WiFi/WiFiInterface.h
index 68d2485b..647fef05 100644
--- a/src/Networking/ESP8266WiFi/WiFiInterface.h
+++ b/src/Networking/ESP8266WiFi/WiFiInterface.h
@@ -126,6 +126,7 @@ private:
uint32_t lastTickMillis;
WifiFirmwareUploader *uploader;
+ TaskHandle espWaitingTask;
WiFiSocket *sockets[NumWiFiTcpSockets];
size_t currentSocket;
diff --git a/src/RepRap.cpp b/src/RepRap.cpp
index 6f09430b..a2031d88 100644
--- a/src/RepRap.cpp
+++ b/src/RepRap.cpp
@@ -57,7 +57,7 @@ static_assert(configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY <= NvicPriorityHSMCI,
#ifndef __LPC17xx__
-static TaskHandle_t hsmciTask = nullptr; // the task that is waiting for a HSMCI command to complete
+static TaskHandle hsmciTask = nullptr; // the task that is waiting for a HSMCI command to complete
// HSMCI interrupt handler
extern "C" void HSMCI_Handler() noexcept
@@ -66,13 +66,7 @@ extern "C" void HSMCI_Handler() noexcept
#if SAME70
XDMAC->XDMAC_CHID[DmacChanHsmci].XDMAC_CID = 0xFFFFFFFF; // disable all DMA interrupts for this channel
#endif
- if (hsmciTask != nullptr)
- {
- BaseType_t higherPriorityTaskWoken = pdFALSE;
- vTaskNotifyGiveFromISR(hsmciTask, &higherPriorityTaskWoken); // wake up the task
- hsmciTask = nullptr;
- portYIELD_FROM_ISR(higherPriorityTaskWoken);
- }
+ TaskBase::GiveFromISR(hsmciTask); // wake up the task
}
#if SAME70
@@ -105,14 +99,14 @@ extern "C" void hsmciIdle(uint32_t stBits, uint32_t dmaBits) noexcept
)
{
// Suspend this task until we get an interrupt indicating that a status bit that we are interested in has been set
- hsmciTask = xTaskGetCurrentTaskHandle();
+ hsmciTask = TaskBase::GetCallerTaskHandle();
HSMCI->HSMCI_IER = stBits;
#if SAME70
DmacManager::SetInterruptCallback(DmacChanHsmci, HsmciDmaCallback, CallbackParameter());
XDMAC->XDMAC_CHID[DmacChanHsmci].XDMAC_CIE = dmaBits;
XDMAC->XDMAC_GIE = 1u << DmacChanHsmci;
#endif
- if (ulTaskNotifyTake(pdTRUE, 200) == 0)
+ if (TaskBase::Take(200) == 0)
{
// We timed out waiting for the HSMCI operation to complete
reprap.GetPlatform().LogError(ErrorCode::HsmciTimeout);
diff --git a/src/Version.h b/src/Version.h
index 9d345c11..f1966a37 100644
--- a/src/Version.h
+++ b/src/Version.h
@@ -20,7 +20,7 @@
#endif
#ifndef DATE
-# define DATE "2020-01-10b1"
+# define DATE "2020-01-10b2"
#endif
#define AUTHORS "reprappro, dc42, chrishamm, t3p3, dnewman, printm3d"