Skip to content

Commit 5be9e55

Browse files
authored
Merge pull request #3142 from cesanta/wonder
Add support for SDIO
2 parents 6b6acd3 + 1b06403 commit 5be9e55

File tree

16 files changed

+2053
-276
lines changed

16 files changed

+2053
-276
lines changed

mongoose.c

Lines changed: 506 additions & 136 deletions
Large diffs are not rendered by default.

mongoose.h

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3009,7 +3009,9 @@ struct mg_profitem {
30093009
#endif
30103010

30113011

3012-
#if MG_ENABLE_TCPIP && defined(MG_ENABLE_DRIVER_CYW) && MG_ENABLE_DRIVER_CYW
3012+
#if MG_ENABLE_TCPIP && \
3013+
((defined(MG_ENABLE_DRIVER_CYW) && MG_ENABLE_DRIVER_CYW) || \
3014+
(defined(MG_ENABLE_DRIVER_CYW_SDIO) && MG_ENABLE_DRIVER_CYW_SDIO))
30133015

30143016
struct mg_tcpip_spi_ {
30153017
void *spi; // Opaque SPI bus descriptor
@@ -3029,7 +3031,7 @@ struct mg_tcpip_driver_cyw_firmware {
30293031
};
30303032

30313033
struct mg_tcpip_driver_cyw_data {
3032-
struct mg_tcpip_spi_ *spi;
3034+
void *bus;
30333035
struct mg_tcpip_driver_cyw_firmware *fw;
30343036
char *ssid;
30353037
char *pass;
@@ -3279,6 +3281,45 @@ struct mg_tcpip_driver_same54_data {
32793281
#endif
32803282

32813283

3284+
#if MG_ENABLE_TCPIP && \
3285+
(defined(MG_ENABLE_DRIVER_CYW_SDIO) && MG_ENABLE_DRIVER_CYW_SDIO)
3286+
3287+
// Specific chip/card driver --> SDIO driver --> HAL --> SDIO hw controller
3288+
3289+
// API with HAL for hardware controller
3290+
// - Provide a function to init the controller (external)
3291+
// - Provide these functions:
3292+
struct mg_tcpip_sdio {
3293+
void *sdio; // Opaque SDIO bus descriptor
3294+
void (*cfg)(void *, uint8_t); // select operating parameters
3295+
// SDIO transaction: send cmd with a possible 1-byte read or write
3296+
bool (*txn)(void *, uint8_t cmd, uint32_t arg, uint32_t *r);
3297+
// SDIO extended transaction: write or read len bytes, using blksz blocks
3298+
bool (*xfr)(void *, bool write, uint32_t arg, uint16_t blksz, uint32_t *,
3299+
uint32_t len, uint32_t *r);
3300+
};
3301+
3302+
// API with driver (e.g.: cyw.c)
3303+
// Once the hardware controller has been initialized:
3304+
// - Init card: selects the card, sets F0 block size, sets bus width and speed
3305+
bool mg_sdio_init(struct mg_tcpip_sdio *sdio);
3306+
// - Enable other possible functions (F1 to F7)
3307+
bool mg_sdio_enable_f(struct mg_tcpip_sdio *sdio, unsigned int f);
3308+
// - Wait for them to be ready
3309+
bool mg_sdio_waitready_f(struct mg_tcpip_sdio *sdio, unsigned int f);
3310+
// - Set their transfer block length
3311+
bool mg_sdio_set_blksz(struct mg_tcpip_sdio *sdio, unsigned int f,
3312+
uint16_t blksz);
3313+
// - Transfer data to/from a function (abstracts from transaction type)
3314+
// - Requesting a read transfer > blocksize means block transfer will be used.
3315+
// - Drivers must have room to accomodate a whole block transfer, see sdio.c
3316+
// - Transfers of > 1 byte --> (uint32_t *) data. 1-byte --> (uint8_t *) data
3317+
bool mg_sdio_transfer(struct mg_tcpip_sdio *sdio, bool write, unsigned int f,
3318+
uint32_t addr, void *data, uint32_t len);
3319+
3320+
#endif
3321+
3322+
32823323
#if MG_ENABLE_TCPIP && defined(MG_ENABLE_DRIVER_STM32F) && \
32833324
MG_ENABLE_DRIVER_STM32F
32843325

0 commit comments

Comments
 (0)