Skip to content

Commit

Permalink
Merge pull request #39 from hideakitai/feature/wait-for-the-task-term…
Browse files Browse the repository at this point in the history
…ination

feat: wait for the task termination when end() called
  • Loading branch information
hideakitai committed Jun 13, 2024
2 parents acd7a24 + 76c7459 commit 135d9d7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
29 changes: 22 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ on:
- develop
paths-ignore:
- .git*
- '**.md'
- 'library.properties'
- 'library.json'
- "**.md"
- "library.properties"
- "library.json"
pull_request:
branches:
- main
- develop
paths-ignore:
- .git*
- '**.md'
- 'library.properties'
- 'library.json'
- "**.md"
- "library.properties"
- "library.json"

jobs:
build:
name: 'Build Test: ${{matrix.board.arch}}:${{matrix.board.name}}'
name: "Build Test: ${{matrix.board.arch}}:${{matrix.board.name}}"
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -29,12 +29,27 @@ jobs:
- vendor: esp32
arch: esp32
name: esp32
version: 2
- vendor: esp32
arch: esp32
name: esp32s3
version: 2
- vendor: esp32
arch: esp32
name: esp32c3
version: 2
- vendor: esp32
arch: esp32
name: esp32
version: 3
- vendor: esp32
arch: esp32
name: esp32s3
version: 3
- vendor: esp32
arch: esp32
name: esp32c3
version: 3
include:
- index: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
board:
Expand Down
7 changes: 7 additions & 0 deletions ESP32SPISlave.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <SPI.h>
#include <driver/spi_slave.h>
#include <vector>
#include <string>

#ifndef ARDUINO_ESP32_SPI_SLAVE_NAMESPACE_BEGIN
#define ARDUINO_ESP32_SPI_SLAVE_NAMESPACE_BEGIN \
Expand Down Expand Up @@ -69,6 +70,7 @@ struct spi_slave_context_t
.intr_flags = 0,
};
spi_host_device_t host {SPI2_HOST};
TaskHandle_t main_task_handle {NULL};
};

struct spi_transaction_context_t
Expand Down Expand Up @@ -203,6 +205,7 @@ void spi_slave_task(void *arg)

spi_slave_free(ctx->host);

xTaskNotifyGive(ctx->main_task_handle);
vTaskDelete(NULL);
}

Expand Down Expand Up @@ -291,6 +294,9 @@ class Slave
void end()
{
xTaskNotifyGive(spi_task_handle);
if (xTaskNotifyWait(0, 0, NULL, pdMS_TO_TICKS(5000)) != pdTRUE) {
ESP_LOGW(TAG, "timeout waiting for the termination of spi_slave_task");
}
}

/// @brief execute one transaction and wait for the completion
Expand Down Expand Up @@ -609,6 +615,7 @@ class Slave
{
this->ctx.host = this->hostFromBusNumber(spi_bus);
this->ctx.bus_cfg.flags |= SPICOMMON_BUSFLAG_SLAVE;
this->ctx.main_task_handle = xTaskGetCurrentTaskHandle();
this->transactions.reserve(this->ctx.if_cfg.queue_size);

// create spi slave task
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"url": "https://github.com/hideakitai",
"maintainer": true
},
"version": "0.6.0",
"version": "0.6.1",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*"
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=ESP32SPISlave
version=0.6.0
version=0.6.1
author=hideakitai
maintainer=hideakitai
sentence=SPI Slave library for ESP32
Expand Down

0 comments on commit 135d9d7

Please sign in to comment.