Skip to content

Commit 6bb5ee1

Browse files
committed
high priority thread start postpone
1 parent 1bc4a0a commit 6bb5ee1

File tree

4 files changed

+15
-20
lines changed

4 files changed

+15
-20
lines changed

src/eez/firmware.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,9 @@ void boot() {
106106
#if OPTION_ETHERNET
107107
mcu::ethernet::initMessageQueue();
108108
#endif
109+
initHighPriorityMessageQueue();
109110
initLowPriorityMessageQueue();
110111

111-
startHighPriorityThread();
112-
113112
// INIT
114113
psu::init();
115114

@@ -207,6 +206,8 @@ void boot() {
207206
#if OPTION_ETHERNET
208207
mcu::ethernet::startThread();
209208
#endif
209+
210+
startHighPriorityThread();
210211
startLowPriorityThread();
211212

212213
mp::initMessageQueue();

src/eez/platform/stm32/spi.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,6 @@ void deselect(uint8_t slotIndex) {
105105
}
106106

107107
HAL_StatusTypeDef SPI_TransmitReceive(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size) {
108-
/* Process Locked */
109-
__HAL_LOCK(hspi);
110-
if (hspi->State != HAL_SPI_STATE_BUSY_RX) {
111-
hspi->State = HAL_SPI_STATE_BUSY_TX_RX;
112-
}
113-
114108
// Variable used to alternate Rx and Tx during transfer
115109
bool txAllowed = true;
116110

@@ -197,9 +191,6 @@ HAL_StatusTypeDef SPI_TransmitReceive(SPI_HandleTypeDef *hspi, uint8_t *pTxData,
197191

198192
// Control if the RX fifo is empty
199193
while ((hspi->Instance->SR & SPI_FLAG_FRLVL) != SPI_FTLVL_EMPTY);
200-
201-
hspi->State = HAL_SPI_STATE_READY;
202-
__HAL_UNLOCK(hspi);
203194

204195
return HAL_OK;
205196
}

src/eez/tasks.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ osThreadDef(g_highPriorityThread, highPriorityThreadMainLoop, osPriorityAboveNor
7777
osThreadId g_highPriorityThreadHandle;
7878

7979
#if defined(EEZ_PLATFORM_STM32)
80-
#define HIGH_PRIORITY_QUEUE_SIZE 10
80+
#define HIGH_PRIORITY_QUEUE_SIZE 50
8181
#endif
8282

8383
#if defined(EEZ_PLATFORM_SIMULATOR)
@@ -117,9 +117,12 @@ static uint32_t g_timer1LastTickCount;
117117

118118
////////////////////////////////////////////////////////////////////////////////
119119

120-
void startHighPriorityThread() {
120+
void initHighPriorityMessageQueue() {
121121
g_highPriorityMessageQueueId = osMessageCreate(osMessageQ(g_highPriorityMessageQueue), NULL);
122-
g_highPriorityThreadHandle = osThreadCreate(osThread(g_highPriorityThread), nullptr);
122+
}
123+
124+
void startHighPriorityThread() {
125+
g_highPriorityThreadHandle = osThreadCreate(osThread(g_highPriorityThread), nullptr);
123126
}
124127

125128
void highPriorityThreadOneIter();
@@ -128,6 +131,8 @@ void highPriorityThreadMainLoop(const void *) {
128131
#ifdef __EMSCRIPTEN__
129132
highPriorityThreadOneIter();
130133
#else
134+
g_highPriorityThreadHandle = osThreadGetId();
135+
131136
while (1) {
132137
highPriorityThreadOneIter();
133138
}
@@ -143,11 +148,6 @@ void highPriorityThreadOneIter() {
143148
psu::onThreadMessage(type, param);
144149
} else {
145150
WATCHDOG_RESET();
146-
147-
if (!g_isBooted) {
148-
return;
149-
}
150-
151151
for (int i = 0; i < NUM_SLOTS; i++) {
152152
g_slots[i]->tick();
153153
}
@@ -157,7 +157,7 @@ void highPriorityThreadOneIter() {
157157
}
158158

159159
bool isPsuThread() {
160-
return osThreadGetId() == g_highPriorityThreadHandle;
160+
return !g_isBooted || osThreadGetId() == g_highPriorityThreadHandle;
161161
}
162162

163163
void sendMessageToPsu(HighPriorityThreadMessage messageType, uint32_t messageParam, uint32_t timeoutMillisec) {
@@ -184,6 +184,8 @@ void lowPriorityThreadMainLoop(const void *) {
184184
lowPriorityThreadOneIter();
185185
}
186186
#else
187+
g_lowPriorityTaskHandle = osThreadGetId();
188+
187189
while (g_isLowPriorityThreadAlive) {
188190
lowPriorityThreadOneIter();
189191
}

src/eez/tasks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ enum LowPriorityThreadMessage {
9797

9898
extern bool g_screenshotGenerating;
9999

100+
void initHighPriorityMessageQueue();
100101
void startHighPriorityThread();
101102

102103
bool isPsuThread();

0 commit comments

Comments
 (0)