From 3dc36f622cc43a9da6613f833a7de4a5b558d5e0 Mon Sep 17 00:00:00 2001 From: Armando Date: Thu, 21 Jul 2022 21:23:31 +0800 Subject: [PATCH] spi_slave: add a private API to reset transaction queue --- .../include/esp_private/spi_slave_internal.h | 39 +++++++++++++++++++ components/driver/spi_slave.c | 27 +++++++++++++ components/hal/include/hal/spi_slave_hal.h | 18 +++------ tools/ci/check_copyright_ignore.txt | 1 - 4 files changed, 71 insertions(+), 14 deletions(-) create mode 100644 components/driver/include/esp_private/spi_slave_internal.h diff --git a/components/driver/include/esp_private/spi_slave_internal.h b/components/driver/include/esp_private/spi_slave_internal.h new file mode 100644 index 0000000000..aa5cd73ab8 --- /dev/null +++ b/components/driver/include/esp_private/spi_slave_internal.h @@ -0,0 +1,39 @@ +/* + * SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @brief + * This file contains SPI Slave private/internal APIs. Private/Internal APIs are: + * - Visible to other IDF components + * - Suggest NOT to use these APIs in your applications + * - We don't provide backward compatibility on these APIs either + */ + +#pragma once +#include "sdkconfig.h" +#include "esp_err.h" +#include "hal/spi_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * @note + * This API is used to reset SPI Slave transaction queue. After calling this function: + * - The SPI Slave transaction queue will be reset. + * + * @note This API shouldn't be called when the corresponding SPI Master is doing an SPI transaction. + * If this gets called when its corresponding SPI Master is doing an SPI transaction, the SPI Slave behaviour is undefined + * + * @param host SPI peripheral that is acting as a slave + * + * @return + * - ESP_ERR_INVALID_ARG if parameter is invalid + * - ESP_OK on success + */ +esp_err_t spi_slave_queue_reset(spi_host_device_t host); diff --git a/components/driver/spi_slave.c b/components/driver/spi_slave.c index a07f83fb57..c54c89d322 100644 --- a/components/driver/spi_slave.c +++ b/components/driver/spi_slave.c @@ -283,6 +283,33 @@ esp_err_t spi_slave_free(spi_host_device_t host) return ESP_OK; } +/** + * @note + * This API is used to reset SPI Slave transaction queue. After calling this function: + * - The SPI Slave transaction queue will be reset. + * + * Therefore, this API shouldn't be called when the corresponding SPI Master is doing an SPI transaction. + * + * @note + * We don't actually need to enter a critical section here. + * SPI Slave ISR will only get triggered when its corresponding SPI Master's transaction is done. + * As we don't expect this function to be called when its corresponding SPI Master is doing an SPI transaction, + * so concurrent call to these registers won't happen + * + */ +esp_err_t SPI_SLAVE_ATTR spi_slave_queue_reset(spi_host_device_t host) +{ + SPI_CHECK(is_valid_host(host), "invalid host", ESP_ERR_INVALID_ARG); + SPI_CHECK(spihost[host], "host not slave", ESP_ERR_INVALID_ARG); + + esp_intr_disable(spihost[host]->intr); + spi_ll_set_int_stat(spihost[host]->hal.hw); + + spihost[host]->cur_trans = NULL; + xQueueReset(spihost[host]->trans_queue); + + return ESP_OK; +} esp_err_t SPI_SLAVE_ATTR spi_slave_queue_trans(spi_host_device_t host, const spi_slave_transaction_t *trans_desc, TickType_t ticks_to_wait) { diff --git a/components/hal/include/hal/spi_slave_hal.h b/components/hal/include/hal/spi_slave_hal.h index 3ad5f485f1..14183a1da8 100644 --- a/components/hal/include/hal/spi_slave_hal.h +++ b/components/hal/include/hal/spi_slave_hal.h @@ -1,16 +1,8 @@ -// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /******************************************************************************* * NOTICE diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index 2a91495ea2..fee766aeda 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -699,7 +699,6 @@ components/hal/include/hal/rtc_io_types.h components/hal/include/hal/sdio_slave_ll.h components/hal/include/hal/sha_hal.h components/hal/include/hal/spi_flash_encrypt_hal.h -components/hal/include/hal/spi_slave_hal.h components/hal/include/hal/spi_slave_hd_hal.h components/hal/include/hal/uhci_types.h components/hal/include/hal/usb_hal.h