Skip to content

Commit daef2a8

Browse files
committed
set bufferSizesto mz_ulong, removed critical sections
1 parent 5af5208 commit daef2a8

File tree

1 file changed

+9
-31
lines changed

1 file changed

+9
-31
lines changed

src/main.cpp

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,9 @@ AsyncServer *tcp;
9999
AsyncUDP *udp;
100100
DisplayDriver *display;
101101

102-
static portMUX_TYPE bufferMutex = portMUX_INITIALIZER_UNLOCKED;
103-
104102
// Buffers for storing data
105103
uint8_t *buffers[NUM_BUFFERS];
106-
uint16_t bufferSizes[NUM_BUFFERS] __attribute__((aligned(4))) = {0};
104+
mz_ulong bufferSizes[NUM_BUFFERS] __attribute__((aligned(4))) = {0};
107105
bool bufferCompressed[NUM_BUFFERS] __attribute__((aligned(4))) = {0};
108106

109107
// The uncompress buffer should be bug enough
@@ -171,6 +169,7 @@ uint8_t logoWaitCounter;
171169
uint32_t lastDataReceived;
172170
bool serverRunning;
173171
uint8_t throbberColors[6] __attribute__((aligned(4))) = {0};
172+
mz_ulong uncompressedBufferSize = 2048;
174173

175174
void DoRestart(int sec) {
176175
if (wifiActive) {
@@ -497,35 +496,25 @@ void AcquireNextBuffer() {
497496
// currentBuffer = (currentBuffer + 1) % NUM_BUFFERS;
498497
// return;
499498
while (1) {
500-
portENTER_CRITICAL(&bufferMutex);
501499
if (currentBuffer == lastBuffer &&
502500
((currentBuffer + 1) % NUM_BUFFERS) != processingBuffer) {
503501
currentBuffer = (currentBuffer + 1) % NUM_BUFFERS;
504-
portEXIT_CRITICAL(&bufferMutex);
505502
return;
506503
}
507-
portEXIT_CRITICAL(&bufferMutex);
508504
// Avoid busy-waiting
509505
vTaskDelay(pdMS_TO_TICKS(1));
510506
}
511507
}
512508

513-
void MarkCurrentBufferDone() {
514-
portENTER_CRITICAL(&bufferMutex);
515-
lastBuffer = currentBuffer;
516-
portEXIT_CRITICAL(&bufferMutex);
517-
}
509+
void MarkCurrentBufferDone() { lastBuffer = currentBuffer; }
518510

519511
bool AcquireNextProcessingBuffer() {
520-
portENTER_CRITICAL(&bufferMutex);
521512
if (processingBuffer != currentBuffer &&
522513
(((processingBuffer + 1) % NUM_BUFFERS) != currentBuffer ||
523514
currentBuffer == lastBuffer)) {
524515
processingBuffer = (processingBuffer + 1) % NUM_BUFFERS;
525-
portEXIT_CRITICAL(&bufferMutex);
526516
return true;
527517
}
528-
portEXIT_CRITICAL(&bufferMutex);
529518
return false;
530519
}
531520

@@ -733,12 +722,10 @@ static uint8_t IRAM_ATTR HandleData(uint8_t *pData, size_t len) {
733722
esp_task_wdt_reset();
734723
if (payloadSize > BUFFER_SIZE) {
735724
if (debug) {
736-
portENTER_CRITICAL(&bufferMutex);
737725
display->DisplayText("Error, payloadSize > BUFFER_SIZE", 0, 0, 255,
738726
0, 0);
739727
DisplayNumber(payloadSize, 5, 0, 19, 255, 0, 0);
740728
DisplayNumber(BUFFER_SIZE, 5, 0, 25, 255, 0, 0);
741-
portEXIT_CRITICAL(&bufferMutex);
742729
while (1);
743730
}
744731
headerBytesReceived = 0;
@@ -747,7 +734,6 @@ static uint8_t IRAM_ATTR HandleData(uint8_t *pData, size_t len) {
747734
}
748735

749736
if (debug) {
750-
portENTER_CRITICAL(&bufferMutex);
751737
display->DisplayText("Command:", 7 * (TOTAL_WIDTH / 128),
752738
(TOTAL_HEIGHT / 2) - 10, 128, 128, 128);
753739
DisplayNumber(command, 2, 7 * (TOTAL_WIDTH / 128) + (8 * 4),
@@ -756,7 +742,6 @@ static uint8_t IRAM_ATTR HandleData(uint8_t *pData, size_t len) {
756742
(TOTAL_HEIGHT / 2) - 4, 128, 128, 128);
757743
DisplayNumber(payloadSize, 2, 7 * (TOTAL_WIDTH / 128) + (8 * 4),
758744
(TOTAL_HEIGHT / 2) - 4, 255, 191, 0);
759-
portEXIT_CRITICAL(&bufferMutex);
760745
}
761746

762747
switch (command) {
@@ -1091,11 +1076,9 @@ static uint8_t IRAM_ATTR HandleData(uint8_t *pData, size_t len) {
10911076
case 11: // KeepAlive
10921077
{
10931078
if (debug) {
1094-
portENTER_CRITICAL(&bufferMutex);
10951079
display->DisplayText("KEEP ALIVE RECEIVED",
10961080
7 * (TOTAL_WIDTH / 128),
10971081
(TOTAL_HEIGHT / 2) - 10, 128, 128, 128);
1098-
portEXIT_CRITICAL(&bufferMutex);
10991082
}
11001083
lastDataReceived = millis();
11011084
headerBytesReceived = 0;
@@ -1279,10 +1262,10 @@ void Task_ReadSerial(void *pvParameters) {
12791262
Serial.flush();
12801263
vTaskDelay(pdMS_TO_TICKS(2));
12811264
Serial.end();
1282-
vTaskDelay(pdMS_TO_TICKS(10));
1265+
vTaskDelay(pdMS_TO_TICKS(2));
12831266
Serial.begin(SERIAL_BAUD);
12841267
while (!Serial) {
1285-
vTaskDelay(pdMS_TO_TICKS(10));
1268+
vTaskDelay(pdMS_TO_TICKS(1));
12861269
}
12871270
break; // Wait for the next FRAME header
12881271
}
@@ -2263,17 +2246,12 @@ void loop() {
22632246
0 == buffers[processingBuffer][1]) {
22642247
ClearScreen();
22652248
} else {
2266-
mz_ulong uncompressedBufferSize = (mz_ulong)TOTAL_BYTES;
22672249
if (bufferCompressed[processingBuffer]) {
2268-
mz_ulong compressedBufferSize =
2269-
(mz_ulong)bufferSizes[processingBuffer];
22702250
memset(uncompressBuffer, 0, 2048);
2271-
2272-
portENTER_CRITICAL(&bufferMutex);
2273-
int minizStatus =
2274-
mz_uncompress2(uncompressBuffer, &uncompressedBufferSize,
2275-
buffers[processingBuffer], &compressedBufferSize);
2276-
portEXIT_CRITICAL(&bufferMutex);
2251+
uncompressedBufferSize = 2048;
2252+
int minizStatus = mz_uncompress2(
2253+
uncompressBuffer, &uncompressedBufferSize,
2254+
buffers[processingBuffer], &bufferSizes[processingBuffer]);
22772255

22782256
if (MZ_OK != minizStatus) {
22792257
if (1 == debug) {

0 commit comments

Comments
 (0)