Skip to content

Commit 9455a6c

Browse files
Allow configuring maximum frame length more precisely
This deprecates the `LMIC_ENABLE_long_messages` configuration macro and allows configuring LMIC_MAX_FRAME_LENGTH instead, allowing a more fine-grained balance between memory usage and maximum frame length.
1 parent 89c28c5 commit 9455a6c

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,11 @@ All reference to `onEvent()` can be suppressed by setting `LMIC_ENABLE_onEvent`
406406

407407
#### Enabling long messages
408408

409-
To save RAM for simple devices, the LMIC allows message length to be limited to 64 bytes instead of the LoRaWAN standard of 255 bytes max. This saves about 2*192 bytes of RAM. Unfortunately, compliance tests require the full message size. Long messages are enabled by setting `LMIC_ENABLE_long_messages` to 1, or disabled by setting it to zero. This C preprocessor macro is always defined as a post-condition of `#include "config.h"`; if non-zero, the maximum frame size is 255 bytes, and if zero, the maximum frame size is 64 bytes.
409+
By default, LMIC allows messages up to 255 bytes, as defined in the LoRaWAN standard and required by compliance testing. To save RAM for simple devices, this can be limited using the `LMIC_MAX_FRAME_LENGTH` macro. This macro defines the length of the full frame, the maximum payload size is a bit smaller (and can be read from the `MAX_LEN_PAYLOAD` constant).
410+
411+
This value controls both the TX and RX buffers, so reducing it by 1 saves 2 bytes of RAM. The value should be not be set too small, since that can prevent properly receiving network downlinks (e.g. join accepts or MAC commands). Using `#define LMIC_MAX_FRAME_LENGTH 64` is common and should be big enough for most operation, while saving 384 bytes of RAM.
412+
413+
Originally, this was configured using the `LMIC_ENABLE_long_messages` macro, which is still supported for compatibility. Setting `LMIC_ENABLE_long_messages` to 0 is equivalent to setting `LMIC_MAX_FRAME_LENGTH` to 64.
410414

411415
#### Enabling LMIC event logging calls
412416

src/lmic/config.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,17 @@
187187
#endif
188188

189189
// LMIC_ENABLE_long_messages
190-
// LMIC certification requires that this be enabled.
191-
#if !defined(LMIC_ENABLE_long_messages)
192-
# define LMIC_ENABLE_long_messages 1 /* PARAM */
190+
// LMIC certification requires full-length 255 frames, but to save RAM,
191+
// a shorter maximum can be set. This controls both RX and TX buffers,
192+
// so reducing this by 1 saves 2 bytes of RAM.
193+
#if defined(LMIC_ENABLE_long_messages) && defined(LMIC_MAX_FRAME_LENGTH)
194+
#error "Use only one of LMIC_ENABLE_long_messages or LMIC_MAX_FRAME_LENGTH"
195+
#elif defined(LMIC_ENABLE_long_messages) && LMIC_ENABLE_long_messages == 0
196+
# define LMIC_MAX_FRAME_LENGTH 64
197+
#elif !defined(LMIC_MAX_FRAME_LENGTH)
198+
# define LMIC_MAX_FRAME_LENGTH 255
199+
#elif LMIC_MAX_FRAME_LENGTH > 255
200+
#error "LMIC_MAX_FRAME_LENGTH cannot be larger than 255"
193201
#endif
194202

195203
// LMIC_ENABLE_event_logging

src/lmic/lorabase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ enum { ILLEGAL_RPS = 0xFF };
6060

6161
// Global maximum frame length
6262
enum { STD_PREAMBLE_LEN = 8 };
63-
enum { MAX_LEN_FRAME = LMIC_ENABLE_long_messages ? 255 : 64 };
63+
enum { MAX_LEN_FRAME = LMIC_MAX_FRAME_LENGTH };
6464
enum { LEN_DEVNONCE = 2 };
6565
enum { LEN_ARTNONCE = 3 };
6666
enum { LEN_NETID = 3 };

0 commit comments

Comments
 (0)