8000 Merge pull request #115 from pycom/pybytes_config_block · pycom/pycom-micropython-sigfox@79ee9bf · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 79ee9bf

Browse files
authored
Merge pull request #115 from pycom/pybytes_config_block
Pybytes config block
2 parents ba5b4f1 + 873040c commit 79ee9bf

File tree

1 file changed

+36
-15
lines changed

1 file changed

+36
-15
lines changed

esp32/pycom_config.h

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,16 @@
1111
#define PYCOM_CONFIG_H_
1212

1313
#include "py/mpconfig.h"
14+
#include <assert.h>
1415

16+
/**
17+
* pycom_config_block_t is written and read directly to the config partition
18+
* (see ./esp32/lib/partitions_xMB.csv)
19+
* When adding attributes to this config block, be sure to only add them *after*
20+
* all existing attributes.
21+
*
22+
* the _Static_assert()'s below enforce that the memory layout doesn't change
23+
*/
1524

1625
/******************************************************************************
1726
DEFINE CONSTANTS
@@ -29,6 +38,7 @@ typedef struct {
2938
uint8_t sigfox_public_key[16];
3039
uint8_t lora_region;
3140
} pycom_lpwan_config_t;
41+
_Static_assert(sizeof(pycom_lpwan_config_t) == 53, "pycom_lpwan_config_t should have a size of 53 bytes");
3242

3343
typedef struct {
3444
uint8_t wifi_on_boot :1;
@@ -37,23 +47,27 @@ typedef struct {
3747
uint8_t wifi_auth :3;
3848
uint8_t wifi_antenna :1;
3949
} pycom_wifi_config_t;
50+
_Static_assert(sizeof(pycom_wifi_config_t) == 1, "pycom_wifi_config_t should have a size of 1 bytes");
4051

4152
typedef struct {
4253
uint8_t wifi_ssid[33];
4354
uint8_t wifi_pwd[65];
4455
} pycom_wifi_sta_config_t;
56+
_Static_assert(sizeof(pycom_wifi_sta_config_t) == 98, "pycom_wifi_sta_config_t should have a size of 98 bytes");
4557

4658
typedef struct {
4759
uint8_t wifi_ssid[33];
4860
uint8_t wifi_pwd[65];
4961
} pycom_wifi_ap_config_t;
62+
_Static_assert(sizeof(pycom_wifi_ap_config_t) == 98, "pycom_wifi_ap_config_t should have a size of 98 bytes");
5063

5164
typedef struct {
5265
uint8_t heartbeat_on_boot :1;
5366
uint8_t rgb_error_color[3];
5467
uint8_t rgb_safeboot_color[3];
5568
uint8_t rgb_heartbeat_color[3];
5669
} pycom_rgbled_config_t;
70+
_Static_assert(sizeof(pycom_rgbled_config_t) == 10, "pycom_rgbled_config_t should have a size of 10 bytes");
5771

5872
typedef struct {
5973
uint8_t device_token[40];
@@ -65,22 +79,26 @@ typedef struct {
6579
uint8_t auto_start;
6680
uint8_t reserved[11];
6781
} pycom_pybytes_config_t;
82+
_Static_assert(sizeof(pycom_pybytes_config_t) == 348, "pycom_pybytes_config_t should have a size of 348 bytes");
6883

6984
typedef struct {
7085
uint8_t sw_version[12];
7186
uint8_t boot_fs_type;
7287
uint8_t boot_partition;
7388
uint8_t hw_type;
7489
} pycom_config_t;
90+
_Static_assert(sizeof(pycom_config_t) == 15, "pycom_config_t should have a size of 15 bytes");
7591

7692
typedef struct {
77-
uint8_t wdt_on_boot;
93+
uint8_t wdt_on_boot; // 1byte + 3bytes padding
7894
uint32_t wdt_on_boot_timeout;
7995
} pycom_wdt_config_t;
96+
_Static_assert(sizeof(pycom_wdt_config_t) == 8, "pycom_wdt_config_t should have a size of 8 bytes");
8097

8198
typedef struct {
8299
uint8_t lte_modem_en_on_boot;
83100
} pycom_lte_config_t;
101+
_Static_assert(sizeof(pycom_lte_config_t) == 1, "pycom_lte_config_t should have a size of 1 bytes");
84102

85103
typedef struct {
86104
uint8_t carrier[129];
@@ -90,20 +108,23 @@ typedef struct {
90108
uint8_t band;
91109
uint8_t reset;
92110
} pycom_pybytes_lte_config_t;
93-
94-
typedef struct {
95-
pycom_lpwan_config_t lpwan_config;
96-
pycom_wifi_config_t wifi_config;
97-
pycom_wifi_sta_config_t wifi_sta_config;
98-
pycom_rgbled_config_t rgbled_config;
99-
pycom_pybytes_config_t pybytes_config;
100-
pycom_wdt_config_t wdt_config;
101-
pycom_lte_config_t lte_config;
102-
pycom_config_t pycom_config;
103-
pycom_wifi_ap_config_t wifi_ap_config;
104-
pycom_pybytes_lte_config_t pycom_pybytes_lte_config;
105-
uint8_t pycom_reserved[112];
106-
} pycom_config_block_t;
111+
// pycom_pybytes_lte_config_t is the last used member of pycom_config_block_t, so no _Static_assert(sizeof()) needed
112+
113+
typedef struct { // size
114+
pycom_lpwan_config_t lpwan_config; // 53
115+
pycom_wifi_config_t wifi_config; // 1
116+
pycom_wifi_sta_config_t wifi_sta_config; // 98
117+
pycom_rgbled_config_t rgbled_config; // 10
118+
pycom_pybytes_config_t pybytes_config; // 348
119+
uint8_t pycom_unused[2]; // 2 since wdt_config has 4byte-alignment, there are currently two bytes of padding before it
120+
pycom_wdt_config_t wdt_config; // 8 since wdt_config contains a uint32_t, it has 4byte-alignment
121+
pycom_lte_config_t lte_config; // 1
122+
pycom_config_t pycom_config; // 15
123+
pycom_wifi_ap_config_t wifi_ap_config; // 98
124+
pycom_pybytes_lte_config_t pycom_pybytes_lte_config; // 278
125+
uint8_t pycom_reserved[112]; // 112
126+
} pycom_config_block_t; // 1024
127+
_Static_assert(sizeof(pycom_config_block_t) == 1024, "pycom_config_block_t should have a size of 1024 bytes"); // partition is 4Kb, I think multiples of 1Kb <= 4Kb are ok
107128

108129
typedef enum
109130
{

0 commit comments

Comments
 (0)
0