From cad1655330d36edb0b29fed6f1957cc8cb51f9ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag=20=C3=85gren?= Date: Thu, 19 Nov 2015 21:14:16 +0200 Subject: [PATCH] Add static asserts and create slc.h header for descriptor struct --- core/include/esp/i2s_regs.h | 8 +++++--- core/include/esp/slc.h | 37 +++++++++++++++++++++++++++++++++++++ core/include/esp/slc_regs.h | 28 +++------------------------- 3 files changed, 45 insertions(+), 28 deletions(-) create mode 100644 core/include/esp/slc.h diff --git a/core/include/esp/i2s_regs.h b/core/include/esp/i2s_regs.h index 452299f..4414677 100644 --- a/core/include/esp/i2s_regs.h +++ b/core/include/esp/i2s_regs.h @@ -26,9 +26,11 @@ struct I2S_REGS { uint32_t volatile FIFO_CONF; // 0x20 uint32_t volatile RX_EOF_NUM; // 0x24 uint32_t volatile CONF_SINGLE_DATA; // 0x28 - uint32_t volatile CONF_CHANNELS; // 0x2c + uint32_t volatile CONF_CHANNELS; // 0x2c }; +_Static_assert(sizeof(struct I2S_REGS) == 0x30, "I2S_REGS is the wrong size"); + /* Details for CONF register */ #define I2S_CONF_BCK_DIV_M 0x0000003f @@ -120,9 +122,9 @@ struct I2S_REGS { #define I2S_FIFO_CONF_TX_FIFO_MOD_M 0x00000007 #define I2S_FIFO_CONF_TX_FIFO_MOD_S 13 #define I2S_FIFO_CONF_DESCRIPTOR_ENABLE BIT(12) -#define I2S_FIFO_CONF_TX_DATA_NUM_M 0x0000003F +#define I2S_FIFO_CONF_TX_DATA_NUM_M 0x0000003f #define I2S_FIFO_CONF_TX_DATA_NUM_S 6 -#define I2S_FIFO_CONF_RX_DATA_NUM_M 0x0000003F +#define I2S_FIFO_CONF_RX_DATA_NUM_M 0x0000003f #define I2S_FIFO_CONF_RX_DATA_NUM_S 0 /* Details for CONF_CHANNEL register */ diff --git a/core/include/esp/slc.h b/core/include/esp/slc.h new file mode 100644 index 0000000..0322bad --- /dev/null +++ b/core/include/esp/slc.h @@ -0,0 +1,37 @@ +/* esp/slc_regs.h + * + * ESP8266 SLC functions + */ + +#ifndef _ESP_SLC_H +#define _ESP_SLC_H + +#include "esp/slc_regs.h" + +/* Memory layout for DMA transfer descriptors. */ + +struct SLCDescriptor +{ + uint32_t flags; + uint32_t buf_ptr; + uint32_t next_link_ptr; +}; + +#define SLC_DESCRIPTOR_FLAGS_BLOCKSIZE_M 0x00000fff +#define SLC_DESCRIPTOR_FLAGS_BLOCKSIZE_S 0 +#define SLC_DESCRIPTOR_FLAGS_DATA_LENGTH_M 0x00000fff +#define SLC_DESCRIPTOR_FLAGS_DATA_LENGTH_S 12 +#define SLC_DESCRIPTOR_FLAGS_SUB_SOF BIT(29) +#define SLC_DESCRIPTOR_FLAGS_EOF BIT(30) +#define SLC_DESCRIPTOR_FLAGS_OWNER BIT(31) + +#define SLC_DESCRIPTOR_FLAGS(blocksize,datalen,sub_sof,eof,owner) ( \ + VAL2FIELD_M(SLC_DESCRIPTOR_FLAGS_BLOCKSIZE,blocksize)| \ + VAL2FIELD_M(SLC_DESCRIPTOR_FLAGS_DATA_LENGTH,datalen)| \ + ((sub_sof)?SLC_DESCRIPTOR_FLAGS_SUB_SOF:0)| \ + ((eof)?SLC_DESCRIPTOR_FLAGS_EOF:0)| \ + ((owner)?SLC_DESCRIPTOR_FLAGS_OWNER:0) \ +) + + +#endif /* _ESP_SLC_REGS_H */ diff --git a/core/include/esp/slc_regs.h b/core/include/esp/slc_regs.h index 5640e70..52d9a99 100644 --- a/core/include/esp/slc_regs.h +++ b/core/include/esp/slc_regs.h @@ -65,6 +65,8 @@ struct SLC_REGS { uint32_t volatile HOST_CONF_W5; // 0xbc }; +_Static_assert(sizeof(struct SLC_REGS) == 0xc0, "SLC_REGS is the wrong size"); + /* Details for CONF0 register */ #define SLC_CONF0_MODE_M 0x00000003 @@ -269,7 +271,7 @@ struct SLC_REGS { #define SLC_SDIO_STATUS_BUS_M 0x00000007 #define SLC_SDIO_STATUS_BUS_S 12 #define SLC_SDIO_STATUS_WAKEUP BIT(8) -#define SLC_SDIO_STATUS_FUNC_M 0x0000000F +#define SLC_SDIO_STATUS_FUNC_M 0x0000000f #define SLC_SDIO_STATUS_FUNC_S 4 #define SLC_SDIO_STATUS_COMMAND_M 0x00000007 #define SLC_SDIO_STATUS_COMMAND_S 0 @@ -284,28 +286,4 @@ struct SLC_REGS { #define SLC_RX_DESCRIPTOR_CONF_POP_IDLE_COUNT_M 0x0000ffff #define SLC_RX_DESCRIPTOR_CONF_POP_IDLE_COUNT_S 0 -struct SLCDescriptor -{ - uint32_t flags; - uint32_t buf_ptr; - uint32_t next_link_ptr; -}; - -#define SLC_DESCRIPTOR_FLAGS_BLOCKSIZE_M 0x00000fff -#define SLC_DESCRIPTOR_FLAGS_BLOCKSIZE_S 0 -#define SLC_DESCRIPTOR_FLAGS_DATA_LENGTH_M 0x00000fff -#define SLC_DESCRIPTOR_FLAGS_DATA_LENGTH_S 12 -#define SLC_DESCRIPTOR_FLAGS_SUB_SOF BIT(29) -#define SLC_DESCRIPTOR_FLAGS_EOF BIT(30) -#define SLC_DESCRIPTOR_FLAGS_OWNER BIT(31) - -#define SLC_DESCRIPTOR_FLAGS(blocksize,datalen,sub_sof,eof,owner) ( \ - (((blocksize)&SLC_DESCRIPTOR_FLAGS_BLOCKSIZE_M)<