Skip to content

Commit 402176c

Browse files
committed
fix(eppp): Fix SIDO host to check/clear interrupts atomically
1 parent 085dd79 commit 402176c

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

components/eppp_link/eppp_sdio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define MAX_SDIO_PAYLOAD 1500
99
#define SDIO_ALIGN(size) (((size) + 3U) & ~(3U))
1010
#define SDIO_PAYLOAD SDIO_ALIGN(MAX_SDIO_PAYLOAD)
11+
#define PPP_SOF 0x7E
1112

1213
// Interrupts and registers
1314
#define SLAVE_INTR 0

components/eppp_link/eppp_sdio_host.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@
2222
#define TIMEOUT_MAX UINT32_MAX
2323
// Short timeout for sending/receiving ESSL packets
2424
#define PACKET_TIMEOUT_MS 50
25-
// Used for padding unaligned packets, to simplify the logic and keep PPP protocol intact when padded
26-
#define PPP_SOF 0x7E
25+
2726
static const char *TAG = "eppp_sdio_host";
2827
static SemaphoreHandle_t s_essl_mutex = NULL;
2928
static essl_handle_t s_essl = NULL;
3029
static sdmmc_card_t *s_card = NULL;
3130

32-
static CACHE_ALIGNED_ATTR uint8_t send_buffer[SDIO_PAYLOAD];
31+
static DRAM_DMA_ALIGNED_ATTR uint8_t send_buffer[SDIO_PAYLOAD];
3332
static DMA_ATTR uint8_t rcv_buffer[SDIO_PAYLOAD];
3433

3534
esp_err_t eppp_sdio_host_tx(void *h, void *buffer, size_t len)
@@ -92,6 +91,7 @@ esp_err_t eppp_sdio_host_init(struct eppp_config_sdio_s *eppp_config)
9291

9392
sdmmc_host_t config = SDMMC_HOST_DEFAULT();
9493
config.flags = SDMMC_HOST_FLAG_4BIT;
94+
config.flags |= SDMMC_HOST_FLAG_ALLOC_ALIGNED_BUF;
9595
config.max_freq_khz = SDMMC_FREQ_HIGHSPEED;
9696

9797
s_card = (sdmmc_card_t *)malloc(sizeof(sdmmc_card_t));
@@ -117,9 +117,8 @@ esp_err_t eppp_sdio_host_init(struct eppp_config_sdio_s *eppp_config)
117117
static esp_err_t get_intr(uint32_t *out_raw)
118118
{
119119
esp_err_t ret = ESP_OK;
120-
ESP_GOTO_ON_ERROR(essl_wait_int(s_essl, TIMEOUT_MAX), err, TAG, "essl-wait-int failed");
121-
ESP_GOTO_ON_ERROR(essl_get_intr(s_essl, out_raw, NULL, TIMEOUT_MAX), err, TAG, "essl-get-int failed");
122-
ESP_GOTO_ON_ERROR(essl_clear_intr(s_essl, *out_raw, TIMEOUT_MAX), err, TAG, "essl-clear-int failed");
120+
ESP_GOTO_ON_ERROR(essl_get_intr(s_essl, out_raw, NULL, 0), err, TAG, "essl-get-int failed");
121+
ESP_GOTO_ON_ERROR(essl_clear_intr(s_essl, *out_raw, 0), err, TAG, "essl-clear-int failed");
123122
ESP_LOGD(TAG, "intr: %08"PRIX32, *out_raw);
124123
err:
125124
return ret;
@@ -128,16 +127,22 @@ static esp_err_t get_intr(uint32_t *out_raw)
128127
esp_err_t eppp_sdio_host_rx(esp_netif_t *netif)
129128
{
130129
uint32_t intr;
131-
esp_err_t err = get_intr(&intr);
130+
esp_err_t err = essl_wait_int(s_essl, TIMEOUT_MAX);
132131
if (err == ESP_ERR_TIMEOUT) {
133132
return ESP_OK;
134133
}
134+
xSemaphoreTake(s_essl_mutex, portMAX_DELAY);
135+
err = get_intr(&intr);
136+
if (err == ESP_ERR_TIMEOUT) {
137+
xSemaphoreGive(s_essl_mutex);
138+
return ESP_OK;
139+
}
135140
if (err != ESP_OK) {
136141
ESP_LOGE(TAG, "failed to check for interrupts %d", err);
142+
xSemaphoreGive(s_essl_mutex);
137143
return ESP_FAIL;
138144
}
139145
if (intr & ESSL_SDIO_DEF_ESP32.new_packet_intr_mask) {
140-
xSemaphoreTake(s_essl_mutex, portMAX_DELAY);
141146
esp_err_t ret;
142147
do {
143148
size_t size_read = SDIO_PAYLOAD;
@@ -158,8 +163,8 @@ esp_err_t eppp_sdio_host_rx(esp_netif_t *netif)
158163
}
159164
}
160165
} while (ret == ESP_ERR_NOT_FINISHED);
161-
xSemaphoreGive(s_essl_mutex);
162166
}
167+
xSemaphoreGive(s_essl_mutex);
163168
return ESP_OK;
164169
}
165170

components/eppp_link/eppp_sdio_slave.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
#include "eppp_sdio.h"
1313
#include "esp_check.h"
1414

15-
#if CONFIG_EPPP_LINK_DEVICE_SDIO_SLAV
15+
#if CONFIG_EPPP_LINK_DEVICE_SDIO_SLAVE
1616
#define BUFFER_NUM 4
17-
17+
#define BUFFER_SIZE SDIO_PAYLOAD
1818
static const char *TAG = "eppp_sdio_slave";
19-
static WORD_ALIGNED_ATTR uint8_t sdio_slave_rx_buffer[BUFFER_NUM][SDIO_PAYLOAD];
20-
static WORD_ALIGNED_ATTR uint8_t sdio_slave_tx_buffer[SDIO_PAYLOAD];
19+
static DMA_ATTR uint8_t sdio_slave_rx_buffer[BUFFER_NUM][BUFFER_SIZE];
20+
static DMA_ATTR uint8_t sdio_slave_tx_buffer[SDIO_PAYLOAD];
2121
static int s_slave_request = 0;
2222

2323
esp_err_t eppp_sdio_slave_tx(void *h, void *buffer, size_t len)
@@ -30,7 +30,7 @@ esp_err_t eppp_sdio_slave_tx(void *h, void *buffer, size_t len)
3030
size_t send_len = SDIO_ALIGN(len);
3131
if (send_len > len) {
3232
// pad with SOF's if the size is not 4 bytes aligned
33-
memset(&sdio_slave_tx_buffer[len], 0x7E, send_len - len);
33+
memset(&sdio_slave_tx_buffer[len], PPP_SOF, send_len - len);
3434
}
3535

3636
ESP_LOG_BUFFER_HEXDUMP(TAG, sdio_slave_tx_buffer, send_len, ESP_LOG_VERBOSE);
@@ -92,6 +92,7 @@ esp_err_t eppp_sdio_slave_rx(esp_netif_t *netif)
9292
goto again;
9393
}
9494
}
95+
ESP_LOG_BUFFER_HEXDUMP(TAG, ptr, length, ESP_LOG_VERBOSE);
9596
return ESP_OK;
9697
}
9798
ESP_LOGE(TAG, "Error when receiving packet %d", ret);
@@ -113,10 +114,8 @@ esp_err_t eppp_sdio_slave_init(void)
113114
sdio_slave_config_t config = {
114115
.sending_mode = SDIO_SLAVE_SEND_PACKET,
115116
.send_queue_size = BUFFER_NUM,
116-
.recv_buffer_size = SDIO_PAYLOAD,
117+
.recv_buffer_size = BUFFER_SIZE,
117118
.event_cb = event_cb,
118-
.flags = SDIO_SLAVE_FLAG_HIGH_SPEED,
119-
.timing = SDIO_SLAVE_TIMING_NSEND_PSAMPLE,
120119
};
121120
esp_err_t ret = sdio_slave_initialize(&config);
122121
if (ret != ESP_OK) {

0 commit comments

Comments
 (0)