8000 build config: make openthread over lora a build-time configuration op… · pycom/pycom-micropython-sigfox@98000bb · 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 98000bb

Browse files
martijntheiwahdan88
authored and
iwahdan88
committed
build config: make openthread over lora a build-time configuration option (#253)
Adds a make variable to disable openthread. By default it's still enabled. To disable it, add `OPENTHREAD=off` to the `make` invocation. This shaves off 160KB of the .bin, making the firmware fit in the old OTA slot of 1536KB.
1 parent 1eb354a commit 98000bb

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

esp32/Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ RELEASE_DIR ?= build/
3636

3737
COPY_IDF_LIB ?= 0
3838

39+
# by default openthread over LoRa is enabled
40+
OPENTHREAD ?= on
41+
3942
# by default Secure Boot and Flash Encryption are disabled
4043
SECURE ?= off
4144

@@ -97,7 +100,7 @@ LIBS = -L$(ESP_IDF_COMP_PATH)/esp32/lib -L$(ESP_IDF_COMP_PATH)/esp32/ld -L$(ESP_
97100
$(ESP_IDF_COMP_PATH)/newlib/lib/libm-psram-workaround.a \
98101
$(ESP_IDF_COMP_PATH)/newlib/lib/libc-psram-workaround.a \
99102
-lfreertos -ljson -ljsmn -llwip -lnewlib -lvfs -lopenssl -lmbedtls -lwpa_supplicant \
100-
-lxtensa-debug-module -lbt -lsdmmc -lsoc -lheap -lbootloader_support -lmicro-ecc -lopenthread \
103+
-lxtensa-debug-module -lbt -lsdmmc -lsoc -lheap -lbootloader_support -lmicro-ecc \
101104
-u ld_include_panic_highint_hdl -lsmartconfig_ack -lmesh
102105
ifeq ($(BOARD), $(filter $(BOARD), FIPY))
103106
LIBS += sigfox/modsigfox_fipy.a
@@ -111,6 +114,11 @@ ifeq ($(BOARD), $(filter $(BOARD), SIPY))
111114
LIBS += sigfox/modsigfox_sipy.a
112115
endif
113116

117+
ifeq ($(OPENTHREAD), on)
118+
LIBS += -lopenthread
119+
CFLAGS += -DLORA_OPENTHREAD_ENABLED
120+
endif
121+
114122
B_LIBS = -Lbootloader/lib -Lbootloader -L$(BUILD)/bootloader -L$(ESP_IDF_COMP_PATH)/esp32/ld \
115123
-L$(ESP_IDF_COMP_PATH)/esp32/lib -llog -lcore -lbootloader_support \
116124
-lspi_flash -lsoc -lmicro-ecc -lgcc -lstdc++ -lgcov

esp32/mods/modlora.c

Lines changed: 30 additions & 8000 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include "lora/mac/region/RegionEU868.h"
5555

5656
// openThread includes
57+
#ifdef LORA_OPENTHREAD_ENABLED
5758
#include <openthread/udp.h>
5859
#include <openthread/instance.h>
5960
#include <openthread/ip6.h>
@@ -70,6 +71,7 @@
7071
#include "lora/ot-settings.h"
7172
#include "lora/ot-log.h"
7273
#include "lora/ot-task.h"
74+
#endif // #ifdef LORA_OPENTHREAD_ENABLED
7375

7476
/******************************************************************************
7577
DEFINE PRIVATE CONSTANTS
@@ -269,7 +271,7 @@ static const char *modlora_nvs_data_key[E_LORA_NVS_NUM_KEYS] = { "JOINED", "UPLN
269271
"MACPARAMS", "CHANNELS", "SRVACK", "MACNXTTX",
270272
"MACBUFIDX", "MACRPTIDX", "MACBUF", "MACRPTBUF",
271273
"REGION", "CHANMASK", "CHANMASKREM" };
272-
274+
#ifdef LORA_OPENTHREAD_ENABLED
273275
static otInstance *ot = NULL;
274276
bool ot_ready = false;
275277

@@ -279,6 +281,7 @@ int otCliBufferLen = 0;
279281
static char meshCliOutput[MESH_CLI_OUTPUT_SIZE];
280282
static int meshCliOutputLen = 0;
281283
static bool meshCliOutputDone = false;
284+
#endif // #ifdef LORA_OPENTHREAD_ENABLED
282285

283286
/******************************************************************************
284287
DECLARE PUBLIC DATA
@@ -405,6 +408,7 @@ bool modlora_is_module_sleep(void)
405408
}
406409
}
407410

411+
#ifdef LORA_OPENTHREAD_ENABLED
408412
int lora_ot_recv(uint8_t *buf, int8_t *rssi) {
409413

410414
// put Lora into RX mode
@@ -429,6 +433,7 @@ void lora_ot_send(const uint8_t *buf, uint16_t len) {
429433

430434
otPlatLog(OT_LOG_LEVEL_INFO, 0, "radio TX: %d", len);
431435
}
436+
#endif // #ifdef LORA_OPENTHREAD_ENABLED
432437

433438
/******************************************************************************
434439
DEFINE PRIVATE FUNCTIONS
@@ -2208,6 +2213,7 @@ STATIC mp_obj_t lora_nvram_erase (mp_obj_t self_in) {
22082213
}
22092214
STATIC MP_DEFINE_CONST_FUN_OBJ_1(lora_nvram_erase_obj, lora_nvram_erase);
22102215

2216+
#ifdef LORA_OPENTHREAD_ENABLED
22112217
/*
22122218
* openthread CLI callback, triggered when an response from openthread has to be published on REPL
22132219
*/
@@ -2312,6 +2318,7 @@ STATIC mp_obj_t lora_cli(mp_obj_t self_in, mp_obj_t data) {
23122318
return mp_obj_new_str("", 0);
23132319
}
23142320
STATIC MP_DEFINE_CONST_FUN_OBJ_2(lora_cli_obj, lora_cli);
2321+
#endif // #ifdef LORA_OPENTHREAD_ENABLED
23152322

23162323

23172324
STATIC const mp_map_elem_t lora_locals_dict_table[] = {
@@ -2338,8 +2345,10 @@ STATIC const mp_map_elem_t lora_locals_dict_table[] = {
23382345
{ MP_OBJ_NEW_QSTR(MP_QSTR_nvram_save), (mp_obj_t)&lora_nvram_save_obj },
23392346
{ MP_OBJ_NEW_QSTR(MP_QSTR_nvram_restore), (mp_obj_t)&lora_nvram_restore_obj },
23402347
{ MP_OBJ_NEW_QSTR(MP_QSTR_nvram_erase), (mp_obj_t)&lora_nvram_erase_obj },
2348+
#ifdef LORA_OPENTHREAD_ENABLED
23412349
{ MP_OBJ_NEW_QSTR(MP_QSTR_mesh), (mp_obj_t)&lora_mesh_obj },
23422350
{ MP_OBJ_NEW_QSTR(MP_QSTR_cli), (mp_obj_t)&lora_cli_obj },
2351+
#endif // #ifdef LORA_OPENTHREAD_ENABLED
23432352

23442353
// exceptions
23452354
{ MP_OBJ_NEW_QSTR(MP_QSTR_timeout), (mp_obj_t)&mp_type_TimeoutError },
@@ -2409,10 +2418,12 @@ static int lora_socket_socket (mod_network_socket_obj_t *s, int *_errno) {
24092418
}
24102419
s->sock_base.u.sd = 1;
24112420

2421+
#ifdef LORA_OPENTHREAD_ENABLED
24122422
// if mesh is enabled, assume socket is for mesh, not for LoraWAN
24132423
if (ot_ready) {
24142424
return mesh_socket_open(_errno);
24152425
}
2426+
#endif // #ifdef LORA_OPENTHREAD_ENABLED
24162427

24172428
uint32_t dr = DR_0;
24182429
switch (lora_obj.region) {
@@ -2437,18 +2448,22 @@ static int lora_socket_socket (mod_network_socket_obj_t *s, int *_errno) {
24372448

24382449
static void lora_socket_close (mod_network_socket_obj_t *s) {
24392450
s->sock_base.u.sd = -1;
2451+
#ifdef LORA_OPENTHREAD_ENABLED
24402452
mesh_socket_close();
2453+
#endif // #ifdef LORA_OPENTHREAD_ENABLED
24412454
}
24422455

24432456
static int lora_socket_send (mod_network_socket_obj_t *s, const byte *buf, mp_uint_t len, int *_errno) {
24442457
mp_int_t n_bytes = -1;
24452458

24462459
LORA_CHECK_SOCKET(s);
24472460

2461+
#ifdef LORA_OPENTHREAD_ENABLED
24482462
if (ot_ready) {
24492463
*_errno = MP_EOPNOTSUPP;
24502464
return -1;
24512465
}
2466+
#endif // #ifdef LORA_OPENTHREAD_ENABLED
24522467

24532468
// is the radio able to transmit
24542469
if (lora_obj.pwr_mode == E_LORA_MODE_SLEEP) {
@@ -2484,10 +2499,12 @@ static int lora_socket_send (mod_network_socket_obj_t *s, const byte *buf, mp_ui
24842499
static int lora_socket_recv (mod_network_socket_obj_t *s, byte *buf, mp_uint_t len, int *_errno) {
24852500
LORA_CHECK_SOCKET(s);
24862501

2502+
#ifdef LORA_OPENTHREAD_ENABLED
24872503
if (ot_ready) {
24882504
*_errno = MP_EOPNOTSUPP;
24892505
return -1;
24902506
}
2507+
#endif // #ifdef LORA_OPENTHREAD_ENABLED
24912508

24922509
int ret = lora_recv (buf, len, s->sock_base.timeout, NULL);
24932510
if (ret < 0) {
@@ -2500,9 +2517,11 @@ static int lora_socket_recv (mod_network_socket_obj_t *s, byte *buf, mp_uint_t l
25002517
static int lora_socket_recvfrom (mod_network_socket_obj_t *s, byte *buf, mp_uint_t len, byte *ip, mp_uint_t *port, int *_errno) {
25012518
LORA_CHECK_SOCKET(s);
25022519

2520+
#ifdef LORA_OPENTHREAD_ENABLED
25032521
if (ot_ready) {
25042522
return mesh_socket_recvfrom(buf, len, ip, port, _errno);
25052523
}
2524+
#endif // #ifdef LORA_OPENTHREAD_ENABLED
25062525

25072526
*port = 0; // in case there's no data received
25082527
int ret = lora_recv (buf, len, s->sock_base.timeout, (uint32_t *)port);
@@ -2516,10 +2535,12 @@ static int lora_socket_recvfrom (mod_network_socket_obj_t *s, byte *buf, mp_uint
25162535
static int lora_socket_setsockopt(mod_network_socket_obj_t *s, mp_uint_t level, mp_uint_t opt, const void *optval, mp_uint_t optlen, int *_errno) {
25172536
LORA_CHECK_SOCKET(s);
25182537

2538+
#ifdef LORA_OPENTHREAD_ENABLED
25192539
if (ot_ready) {
25202540
*_errno = MP_EOPNOTSUPP;
25212541
return -1;
25222542
}
2543+
#endif // #ifdef LORA_OPENTHREAD_ENABLED
25232544

25242545
if (level != SOL_LORA) {
25252546
*_errno = MP_EOPNOTSUPP;
@@ -2548,10 +2569,12 @@ static int lora_socket_setsockopt(mod_network_socket_obj_t *s, mp_uint_t level,
25482569
static int lora_socket_settimeout (mod_network_socket_obj_t *s, mp_int_t timeout_ms, int *_errno) {
25492570
LORA_CHECK_SOCKET(s);
25502571

2572+
#ifdef LORA_OPENTHREAD_ENABLED
25512573
if (ot_ready) {
25522574
*_errno = MP_EOPNOTSUPP;
25532575
return -1;
25542576
}
2577+
#endif // #ifdef LORA_OPENTHREAD_ENABLED
25552578

25562579
s->sock_base.timeout = timeout_ms;
25572580
return 0;
@@ -2560,9 +2583,11 @@ static int lora_socket_settimeout (mod_network_socket_obj_t *s, mp_int_t timeout
25602583
static int lora_socket_bind(mod_network_socket_obj_t *s, byte *ip, mp_uint_t port, int *_errno) {
25612584
LORA_CHECK_SOCKET(s);
25622585

2586+
#ifdef LORA_OPENTHREAD_ENABLED
25632587
if (ot_ready) {
25642588
return mesh_socket_bind(ip, port, _errno);
25652589
}
2590+
#endif // #ifdef LORA_OPENTHREAD_ENABLED
25662591

25672592
if (port > 224) {
25682593
*_errno = MP_EOPNOTSUPP;
@@ -2577,10 +2602,12 @@ static int lora_socket_ioctl (mod_network_socket_obj_t *s, mp_uint_t request, mp
25772602

25782603
LORA_CHECK_SOCKET(s);
25792604

2605+
#ifdef LORA_OPENTHREAD_ENABLED
25802606
if (ot_ready) {
25812607
*_errno = MP_EOPNOTSUPP;
25822608
return -1;
25832609
}
2610+
#endif // #ifdef LORA_OPENTHREAD_ENABLED
25842611

25852612
if (request == MP_STREAM_POLL) {
25862613
mp_uint_t flags = arg;
@@ -2600,9 +2627,11 @@ static int lora_socket_ioctl (mod_network_socket_obj_t *s, mp_uint_t request, mp
26002627
static int lora_socket_sendto(struct _mod_network_socket_obj_t *s, const byte *buf, mp_uint_t len, byte *ip, mp_uint_t port, int *_errno) {
26012628
LORA_CHECK_SOCKET(s);
26022629

2630+
#ifdef LORA_OPENTHREAD_ENABLED
26032631
if (ot_ready) {
26042632
return mesh_socket_sendto(buf, len, ip, port, _errno);
26052633
}
2634+
#endif // #ifdef LORA_OPENTHREAD_ENABLED
26062635

26072636
// not implemented for LoraWAN
26082637
*_errno = MP_EOPNOTSUPP;

esp32/mptask.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@
5050

5151
#if defined (LOPY) || defined (LOPY4) || defined (FIPY)
5252
#include "modlora.h"
53+
#ifdef LORA_OPENTHREAD_ENABLED
5354
#include "lora/ot-task.h"
55+
#endif // #ifdef LORA_OPENTHREAD_ENABLED
5456
#endif
5557
#if defined (SIPY) || defined(LOPY4) || defined (FIPY)
5658
#include "sigfox/modsigfox.h"
@@ -243,7 +245,9 @@ void TASK_Micropython (void *pvParameters) {
243245
// these ones are special because they need uPy running and they launch tasks
244246
#if defined(LOPY) || defined (LOPY4) || defined (FIPY)
245247
modlora_init0();
248+
# ifdef LORA_OPENTHREAD_ENABLED
246249
openthread_task_init();
250+
# endif // #ifdef LORA_OPENTHREAD_ENABLED
247251
#endif
248252
#if defined(SIPY) || defined(LOPY4) || defined (FIPY)
249253
modsigfox_init0();

0 commit comments

Comments
 (0)
0