The file Common.c contains a collection of useful common support functions:
Use AppInit() as the first step in your main program:
The prg_exit() macro logs the file name and the line number and calls exit(). During exit function PrintExitCode() is executed. Depending on fatal errors like BUFFEROVERFLOW_ERROR GPIO's can be set or exit messages can be printed on a terminal containing file name and line number to identify the exit reason and position.
Will print in case of an error:
EXIT: DSPCommander.c line 203: error adding device. exiting...
When the Common Support Functions Framework is used, GetFreeHeapSize() is called from AppInit() to get the initial configured heap size. Use global variable initial_heap_size to compare current available heap size to initial configured heap size. Macro ASSERT_HEAP() can be used to test for sufficient heap before a malloc() fails.
Function memmap() prints the current dynamic memory map on the activated CPrintf device. Repetitive calls may discover memory leaks.
Example memmap() outpout:
>> Used:1 size:264 addr:b0040000 >> Used:0 size:96 addr:b0040110 >> Used:1 size:384 addr:b0040178 >> Used:0 size:112 addr:b0040300 >> Used:1 size:128 addr:b0040378 >> Used:0 size:112 addr:b0040400 >> Used:1 size:512 addr:b0040478 >> Used:0 size:112 addr:b0040680 >> Used:1 size:128 addr:b00406f8 >> Used:0 size:112 addr:b0040780 >> Used:1 size:512 addr:b00407f8 >> Used:0 size:112 addr:b0040a00 >> Used:1 size:256 addr:b0040a78 >> Used:0 size:112 addr:b0040b80 >> Used:1 size:128 addr:b0040bf8 >> Used:0 size:112 addr:b0040c80 >> Used:1 size:1536 addr:b0040cf8 >> Used:0 size:60664 addr:b0041300 fr_nm:9 fr_sp:f068 fr_mx:ecf8 us_nm:9 us_sp:f08 us_mx:600 ovr:90
This memory map shows 9 free blocks (fr_nm), 0xf068 free memory (fr_sp) and the largest free block size of 0xecf8 (fr_mx).
Use net_print_error() e.g. after net_recv() function call to signal a connection status change:
Use net_recv_event_handler() immediately after net_recv() function calls or within callback functions to handle events properly and to determine the received data length.
E.g.: usage after net_recv():
E.g.: usage in a callback function:
Use net_send_event_handler() immediately after net_send() function calls to detect fatal errors during a send process. A send process calling this handler must be terminated, if a fatal error was detected (return value 1). In case of a return value 0 the calling process may continue sending further data or wait for completion (TCP only).
Also a global variable is defined that reflects the current link status:
Use this status in your application to wait for a valid link
or to prevent a message from being sent without a link