CloudSevenConsulting / DustyDuinoPro

ATAMO Dusty Project
MIT License
0 stars 0 forks source link

C7C.Atamo.Dusty.Mote (0.0.2) too much RAM #4

Closed ghost closed 6 years ago

ghost commented 6 years ago

Data memory (SRAM) is 125% full in solution

Diagnosis

Program Memory Usage:       10300 bytes     31.4% Full
Data Memory Usage:          2559 bytes      125.0% Full

Cause

The sm_clib and sm_qsl takes up 6158 bytes of program memory and 2116 of data memory (can verify this by commenting out dn_qsl_init() in main.cpp

What to do

We need to optimize the QSL library to reduce memory space.

Appropriate measures:

See this SO answer.

ghost commented 6 years ago

Timing Precision Reduction

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:

ghost commented 6 years ago

Single-membered Structs

No 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.

See SO: Size of struct with single element

ghost commented 6 years ago

IPMT Functions

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
}
ghost commented 6 years ago

Maximum HDLC Frame Length

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)

ghost commented 6 years ago

Frame Length in FSM

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.
ghost commented 6 years ago

Inbox

Buffered messages set to 4.

Setting in dn_fsm.h: #define DN_INBOX_SIZE 4

See: 414e44b3203b26485e4991362e4d27ab8231b4f1