mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'bugfix/fix_spi_slave_example_sender_ccount_issue' into 'release/v4.4'
spi: fix spi slave example sender ccount issue (v4.4) See merge request espressif/esp-idf!18423
This commit is contained in:
commit
724cbd4167
@ -10,29 +10,14 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "freertos/queue.h"
|
||||
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/dns.h"
|
||||
#include "lwip/netdb.h"
|
||||
#include "lwip/igmp.h"
|
||||
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_event.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "soc/rtc_periph.h"
|
||||
#include "driver/spi_master.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_spi_flash.h"
|
||||
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_intr_alloc.h"
|
||||
|
||||
#include "esp_timer.h"
|
||||
|
||||
/*
|
||||
SPI sender (master) example.
|
||||
@ -84,7 +69,7 @@ Pins in use. The SPI Master can use the GPIO mux, so feel free to change these i
|
||||
|
||||
|
||||
//The semaphore indicating the slave is ready to receive stuff.
|
||||
static xQueueHandle rdySem;
|
||||
static QueueHandle_t rdySem;
|
||||
|
||||
/*
|
||||
This ISR is called when the handshake line goes high.
|
||||
@ -93,16 +78,20 @@ static void IRAM_ATTR gpio_handshake_isr_handler(void* arg)
|
||||
{
|
||||
//Sometimes due to interference or ringing or something, we get two irqs after eachother. This is solved by
|
||||
//looking at the time between interrupts and refusing any interrupt too close to another one.
|
||||
static uint32_t lasthandshaketime;
|
||||
uint32_t currtime=esp_cpu_get_ccount();
|
||||
uint32_t diff=currtime-lasthandshaketime;
|
||||
if (diff<240000) return; //ignore everything <1ms after an earlier irq
|
||||
lasthandshaketime=currtime;
|
||||
static uint32_t lasthandshaketime_us;
|
||||
uint32_t currtime_us = esp_timer_get_time();
|
||||
uint32_t diff = currtime_us - lasthandshaketime_us;
|
||||
if (diff < 1000) {
|
||||
return; //ignore everything <1ms after an earlier irq
|
||||
}
|
||||
lasthandshaketime_us = currtime_us;
|
||||
|
||||
//Give the semaphore.
|
||||
BaseType_t mustYield=false;
|
||||
BaseType_t mustYield = false;
|
||||
xSemaphoreGiveFromISR(rdySem, &mustYield);
|
||||
if (mustYield) portYIELD_FROM_ISR();
|
||||
if (mustYield) {
|
||||
portYIELD_FROM_ISR();
|
||||
}
|
||||
}
|
||||
|
||||
//Main application
|
||||
|
Loading…
Reference in New Issue
Block a user