11
11
#define PYCOM_CONFIG_H_
12
12
13
13
#include "py/mpconfig.h"
14
+ #include <assert.h>
14
15
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
+ */
15
24
16
25
/******************************************************************************
17
26
DEFINE CONSTANTS
@@ -29,6 +38,7 @@ typedef struct {
29
38
uint8_t sigfox_public_key [16 ];
30
39
uint8_t lora_region ;
31
40
} pycom_lpwan_config_t ;
41
+ _Static_assert (sizeof (pycom_lpwan_config_t ) == 53 , "pycom_lpwan_config_t should have a size of 53 bytes" );
32
42
33
43
typedef struct {
34
44
uint8_t wifi_on_boot :1 ;
@@ -37,23 +47,27 @@ typedef struct {
37
47
uint8_t wifi_auth :3 ;
38
48
uint8_t wifi_antenna :1 ;
39
49
} pycom_wifi_config_t ;
50
+ _Static_assert (sizeof (pycom_wifi_config_t ) == 1 , "pycom_wifi_config_t should have a size of 1 bytes" );
40
51
41
52
typedef struct {
42
53
uint8_t wifi_ssid [33 ];
43
54
uint8_t wifi_pwd [65 ];
44
55
} 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" );
45
57
46
58
typedef struct {
47
59
uint8_t wifi_ssid [33 ];
48
60
uint8_t wifi_pwd [65 ];
49
61
} 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" );
50
63
51
64
typedef struct {
52
65
uint8_t heartbeat_on_boot :1 ;
53
66
uint8_t rgb_error_color [3 ];
54
67
uint8_t rgb_safeboot_color [3 ];
55
68
uint8_t rgb_heartbeat_color [3 ];
56
69
} pycom_rgbled_config_t ;
70
+ _Static_assert (sizeof (pycom_rgbled_config_t ) == 10 , "pycom_rgbled_config_t should have a size of 10 bytes" );
57
71
58
72
typedef struct {
59
73
uint8_t device_token [40 ];
@@ -65,22 +79,26 @@ typedef struct {
65
79
uint8_t auto_start ;
66
80
uint8_t reserved [11 ];
67
81
} pycom_pybytes_config_t ;
82
+ _Static_assert (sizeof (pycom_pybytes_config_t ) == 348 , "pycom_pybytes_config_t should have a size of 348 bytes" );
68
83
69
84
typedef struct {
70
85
uint8_t sw_version [12 ];
71
86
uint8_t boot_fs_type ;
72
87
uint8_t boot_partition ;
73
88
uint8_t hw_type ;
74
89
} pycom_config_t ;
90
+ _Static_assert (sizeof (pycom_config_t ) == 15 , "pycom_config_t should have a size of 15 bytes" );
75
91
76
92
typedef struct {
77
- uint8_t wdt_on_boot ;
93
+ uint8_t wdt_on_boot ; // 1byte + 3bytes padding
78
94
uint32_t wdt_on_boot_timeout ;
79
95
} pycom_wdt_config_t ;
96
+ _Static_assert (sizeof (pycom_wdt_config_t ) == 8 , "pycom_wdt_config_t should have a size of 8 bytes" );
80
97
81
98
typedef struct {
82
99
uint8_t lte_modem_en_on_boot ;
83
100
} pycom_lte_config_t ;
101
+ _Static_assert (sizeof (pycom_lte_config_t ) == 1 , "pycom_lte_config_t should have a size of 1 bytes" );
84
102
85
103
typedef struct {
86
104
uint8_t carrier [129 ];
@@ -90,20 +108,23 @@ typedef struct {
90
108
uint8_t band ;
91
109
uint8_t reset ;
92
110
} 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
107
128
108
129
typedef enum
109
130
{
0 commit comments