Closed ghost closed 7 years ago
Saved 3 bytes. Data Memory = 2556 bytes
fsmEventSchedule_ms
Commit: Yet to Commit
Convert this structure member (in dn_fsm.c
) to uint8_t
from uint32_t
. Saves 3 bytes. Required changes:
dn_time.c
use uint8_t
for dn_time_ms
and dn_sleep_ms
as opposed to uint32_t
.dn_fsm_cmd_timeout
cmdStart_ms
convertedtimePassed_ms
convertedNo optimisation achieved
No padding seems to occur from these. No optimisation can be achieved by changing them to their natural types.
E.g.
typedef struct {
uint8_t RC;
} dn_ipmt_setParameter_macAddress_rpt;
Seems to have the same size as uint8_t dn_ipmt_setParameter_macAddress_rpt
.
Note that the majority (if not all) functions from dn_ipmt.c
are not called in the solution, and hence are
not built onto the device.
As an example, the following inclusion in main.cpp
results in an increase of 358 bytes in program memory (no increase to SRAM)
extern "C" {
#include "sm_clib/dn_ipmt.h"
};
// ...
void loop()
{
#else //Not TEST_MODE
while(1)
{
dn_ipmt_getParameter_powerSrcInfo_rpt* reply;
dn_ipmt_getParameter_powerSrcInfo(reply);
}
#endif
}
Saved 120 bytes. Data memory = 2436 bytes. Reduce 1 byte of memory per reduction in maximum allowed frame length
In dn_hdlc.h
we have the pre-processor #define DN_HDLC_MAX_FRAME_LENGTH 128
.
This is used to initialise the structure in dn_ipmt.c
:
typedef struct {
// sending requests
uint8_t outputBuf[MAX_FRAME_LENGTH];
bool busyTx;
uint8_t cmdId;
uint8_t paramId;
// receiving replies
dn_ipmt_reply_cbt replyCb;
uint8_t* replyContents;
// receiving notifications
dn_ipmt_notif_cbt notifCb;
uint8_t* notifBuf;
uint8_t notifBufLen;
} dn_ipmt_vars_t;
dn_ipmt_vars_t dn_ipmt_vars;
Modify this define to reduce maximum frame length (currently set to 8)
in dn_fsm.c
the buffers:
typedef struct
{
// ...
uint8_t replyBuf[MAX_FRAME_LENGTH];
uint8_t notifBuf[MAX_FRAME_LENGTH];
// ...
} dn_fsm_vars_t;
static dn_fsm_vars_t dn_fsm_vars;
Use a different `MAX_FRAME_LENGTH` found in `dn_ipmt.h`. This is set to above.
Buffered messages set to 4.
Setting in dn_fsm.h
: #define DN_INBOX_SIZE 4
See: 414e44b3203b26485e4991362e4d27ab8231b4f1
Data memory (SRAM) is 125% full in solution
Diagnosis
Cause
The
sm_clib
andsm_qsl
takes up 6158 bytes of program memory and 2116 of data memory (can verify this by commenting outdn_qsl_init()
inmain.cpp
What to do
We need to optimize the QSL library to reduce memory space.
Appropriate measures:
uint8_t
as opposed touint16_t
oruint32_t
). Note that this will sacrifice precision, or possible number of enumerations. (e.g. if we reduce the NetworkID touint8_t
fromuint16_t
then we reduce the number of possible network ID's - we can pad the remaining bits with 0)See this SO answer.