Skip to content

Commit 6a49459

Browse files
committed
feat(eppp): Support for channels -- WIP
1 parent ea26044 commit 6a49459

File tree

3 files changed

+65
-20
lines changed

3 files changed

+65
-20
lines changed

components/eppp_link/eppp_sdio.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -8,12 +8,21 @@
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 SDIO_PACKET_SIZE SDIO_ALIGN(MAX_SDIO_PAYLOAD + 4)
1112
#define PPP_SOF 0x7E
1213

14+
#define NR_OF_CHANNELS 2
15+
1316
// Interrupts and registers
1417
#define SLAVE_INTR 0
1518
#define SLAVE_REG_REQ 0
1619

1720
// Requests from host to slave
1821
#define REQ_RESET 1
1922
#define REQ_INIT 2
23+
24+
struct header {
25+
uint8_t magic;
26+
uint8_t channel;
27+
uint16_t size;
28+
} __attribute__((packed));

components/eppp_link/eppp_sdio_host.c

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -28,8 +28,8 @@ static SemaphoreHandle_t s_essl_mutex = NULL;
2828
static essl_handle_t s_essl = NULL;
2929
static sdmmc_card_t *s_card = NULL;
3030

31-
static DRAM_DMA_ALIGNED_ATTR uint8_t send_buffer[SDIO_PAYLOAD];
32-
static DMA_ATTR uint8_t rcv_buffer[SDIO_PAYLOAD];
31+
static DRAM_DMA_ALIGNED_ATTR uint8_t send_buffer[SDIO_PACKET_SIZE];
32+
static DMA_ATTR uint8_t rcv_buffer[SDIO_PACKET_SIZE];
3333

3434
esp_err_t eppp_sdio_host_tx(void *h, void *buffer, size_t len)
3535
{
@@ -38,12 +38,17 @@ esp_err_t eppp_sdio_host_tx(void *h, void *buffer, size_t len)
3838
return ESP_OK;
3939
}
4040

41-
memcpy(send_buffer, buffer, len);
42-
size_t send_len = SDIO_ALIGN(len);
43-
if (send_len > len) {
44-
// pad with SOF's
45-
memset(&send_buffer[len], PPP_SOF, send_len - len);
46-
}
41+
42+
struct header *head = (void *)send_buffer;
43+
head->magic = PPP_SOF;
44+
head->channel = 0;
45+
head->size = len;
46+
memcpy(send_buffer + sizeof(struct header), buffer, len);
47+
size_t send_len = SDIO_ALIGN(len + sizeof(struct header));
48+
// if (send_len > len) {
49+
// // pad with SOF's
50+
// memset(&send_buffer[len], PPP_SOF, send_len - len);
51+
// }
4752
xSemaphoreTake(s_essl_mutex, portMAX_DELAY);
4853
esp_err_t ret = essl_send_packet(s_essl, send_buffer, send_len, PACKET_TIMEOUT_MS);
4954
if (ret != ESP_OK) {
@@ -145,15 +150,28 @@ esp_err_t eppp_sdio_host_rx(esp_netif_t *netif)
145150
if (intr & ESSL_SDIO_DEF_ESP32.new_packet_intr_mask) {
146151
esp_err_t ret;
147152
do {
148-
size_t size_read = SDIO_PAYLOAD;
149-
ret = essl_get_packet(s_essl, rcv_buffer, SDIO_PAYLOAD, &size_read, PACKET_TIMEOUT_MS);
153+
size_t size_read = SDIO_PACKET_SIZE;
154+
ret = essl_get_packet(s_essl, rcv_buffer, SDIO_PACKET_SIZE, &size_read, PACKET_TIMEOUT_MS);
150155
if (ret == ESP_ERR_NOT_FOUND) {
151156
ESP_LOGE(TAG, "interrupt but no data can be read");
152157
break;
153158
} else if (ret == ESP_OK) {
154159
ESP_LOGD(TAG, "receive data, size: %d", size_read);
160+
struct header *head = (void *)rcv_buffer;
161+
if (head->magic != PPP_SOF) {
162+
ESP_LOGE(TAG, "invalid magic %x", head->magic);
163+
break;
164+
}
165+
if (head->channel >= NR_OF_CHANNELS) {
166+
ESP_LOGE(TAG, "invalid channel %x", head->channel);
167+
break;
168+
}
169+
if (head->size > SDIO_PAYLOAD || head->size > size_read) {
170+
ESP_LOGE(TAG, "invalid size %x", head->size);
171+
break;
172+
}
155173
ESP_LOG_BUFFER_HEXDUMP(TAG, rcv_buffer, size_read, ESP_LOG_VERBOSE);
156-
esp_netif_receive(netif, rcv_buffer, size_read, NULL);
174+
esp_netif_receive(netif, rcv_buffer + sizeof(struct header), head->size, NULL);
157175
break;
158176
} else {
159177
ESP_LOGE(TAG, "rx packet error: %08X", ret);

components/eppp_link/eppp_sdio_slave.c

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,16 @@ esp_err_t eppp_sdio_slave_tx(void *h, void *buffer, size_t len)
2727
// silently skip the Tx if the SDIO not fully initialized
2828
return ESP_OK;
2929
}
30-
memcpy(sdio_slave_tx_buffer, buffer, len);
31-
size_t send_len = SDIO_ALIGN(len);
32-
if (send_len > len) {
33-
// pad with SOF's if the size is not 4 bytes aligned
34-
memset(&sdio_slave_tx_buffer[len], PPP_SOF, send_len - len);
35-
}
30+
struct header *head = (void *)sdio_slave_tx_buffer;
31+
head->magic = PPP_SOF;
32+
head->channel = 0;
33+
head->size = len;
34+
memcpy(sdio_slave_tx_buffer + sizeof(struct header), buffer, len);
35+
size_t send_len = SDIO_ALIGN(len + sizeof(struct header));
36+
// if (send_len > len) {
37+
// // pad with SOF's if the size is not 4 bytes aligned
38+
// memset(&sdio_slave_tx_buffer[len], PPP_SOF, send_len - len);
39+
// }
3640

3741
ESP_LOG_BUFFER_HEXDUMP(TAG, sdio_slave_tx_buffer, send_len, ESP_LOG_VERBOSE);
3842
esp_err_t ret = sdio_slave_transmit(sdio_slave_tx_buffer, send_len);
@@ -82,7 +86,21 @@ esp_err_t eppp_sdio_slave_rx(esp_netif_t *netif)
8286
if (ret == ESP_ERR_NOT_FINISHED || ret == ESP_OK) {
8387
again:
8488
ptr = sdio_slave_recv_get_buf(handle, &length);
85-
esp_netif_receive(netif, ptr, length, NULL);
89+
struct header *head = (void *)ptr;
90+
if (head->magic != PPP_SOF) {
91+
ESP_LOGE(TAG, "invalid magic %x", head->magic);
92+
return ESP_FAIL;
93+
}
94+
if (head->channel >= NR_OF_CHANNELS) {
95+
ESP_LOGE(TAG, "invalid channel %x", head->channel);
96+
return ESP_FAIL;
97+
}
98+
if (head->size > SDIO_PAYLOAD || head->size > length) {
99+
ESP_LOGE(TAG, "invalid size %x", head->size);
100+
return ESP_FAIL;
101+
}
102+
103+
esp_netif_receive(netif, ptr + sizeof(struct header), head->size, NULL);
86104
if (sdio_slave_recv_load_buf(handle) != ESP_OK) {
87105
ESP_LOGE(TAG, "Failed to recycle packet buffer");
88106
return ESP_FAIL;

0 commit comments

Comments
 (0)