10 Commits

Author SHA1 Message Date
Philippe Teuwen
d97e14f5c9 umm: restore -fno-common to avoid overlap between ummHeapInfo and umm_heap, see also 3a39a9b64e 2020-09-01 01:53:24 +02:00
Philippe Teuwen
f0d779a7ca umm: umm_malloc.c includes already umm_*.c 2020-09-01 01:49:27 +02:00
Philippe Teuwen
4c5e981958 umm: work on DBGLOG 2020-09-01 00:15:35 +02:00
Philippe Teuwen
864a0a6abe Revert "remore force in order to fit our dbprint"
This reverts commit 7cd99ae4d7.
2020-08-31 23:11:53 +02:00
iceman1001
15dcc246d1 enable umm info 2020-08-31 23:04:39 +02:00
iceman1001
7cd99ae4d7 remore force in order to fit our dbprint 2020-08-31 23:04:14 +02:00
iceman1001
57346e3b24 faking it 2020-08-31 23:03:24 +02:00
iceman1001
268d40e686 test hw dbg 2020-08-31 23:03:01 +02:00
iceman1001
4cc3fd9397 assign size 2020-08-31 23:02:41 +02:00
Philippe Teuwen
e78898b483 wip 2020-08-31 11:12:16 +02:00
6 changed files with 83 additions and 35 deletions

View File

@@ -20,7 +20,7 @@ endif
#in the next section to remove that particular feature from compilation.
# NO space,TABs after the "\" sign.
APP_CFLAGS = $(PLATFORM_DEFS) \
-ffunction-sections -fdata-sections
-ffunction-sections -fdata-sections -fno-common
SRC_LF = lfops.c lfsampling.c pcf7931.c lfdemod.c lfadc.c
SRC_ISO15693 = iso15693.c iso15693tools.c
@@ -125,10 +125,7 @@ THUMBSRC = start.c \
ticks.c \
clocks.c \
hfsnoop.c \
umm_info.c \
umm_integrity.c \
umm_malloc.c \
umm_poison.c
umm_malloc.c
# These are to be compiled in ARM mode
ARMSRC = fpgaloader.c \

View File

@@ -46,6 +46,8 @@
#include "util.h"
#include "ticks.h"
#include "commonutil.h"
#include "umm_malloc.h"
#include "umm_malloc_cfg.h"
#ifdef WITH_LCD
#include "LCD.h"
@@ -67,14 +69,26 @@
extern uint32_t _stack_start, _stack_end;
struct common_area common_area __attribute__((section(".commonarea")));
static int button_status = BUTTON_NO_CLICK;
static bool allow_send_wtx = false;
static bool allow_send_wtx = false;
void send_wtx(uint16_t wtx) {
if (allow_send_wtx) {
reply_ng(CMD_WTX, PM3_SUCCESS, (uint8_t *)&wtx, sizeof(wtx));
}
}
static void umm_test(void) {
umm_info(NULL, true);
uint8_t* dest = (uint8_t*)umm_malloc(2000);
umm_free(dest);
umm_info(NULL, true);
dest = (uint8_t*)umm_malloc(12000);
umm_info(NULL, true);
umm_free(dest);
}
//-----------------------------------------------------------------------------
// Read an ADC channel and block till it completes, then return the result
// in ADC units (0 to 1023). Also a routine to sum up a number of samples and
@@ -721,8 +735,11 @@ static void PacketReceived(PacketCommandNG *packet) {
g_reply_via_usb = false;
break;
}
// emulator
// device side debug mode
case CMD_SET_DBGMODE: {
umm_test();
DBGLEVEL = packet->data.asBytes[0];
print_debug_level();
reply_ng(CMD_SET_DBGMODE, PM3_SUCCESS, NULL, 0);
@@ -2206,7 +2223,6 @@ void __attribute__((noreturn)) AppMain(void) {
// fall under the 2 contigous free blocks availables
rdv40_spiffs_check();
#endif
for (;;) {
WDT_HIT();

View File

@@ -14,6 +14,8 @@
#include "common.h"
#include "ansi.h"
#define NOLF "\xff"
#define Dbprintf_usb(...) {\
bool tmpfpc = g_reply_via_fpc;\
bool tmpusb = g_reply_via_usb;\
@@ -52,24 +54,46 @@ void print_result(const char *name, uint8_t *buf, size_t len);
// Functions for umm_malloc
// Alternatively, use https://github.com/rhempel/c-helper-macros/blob/develop/dbglog/dbglog.h
#define DBGLOG_FORCE(...) {\
Dbprintf (__VA_ARGS__); \
#define DBGLOGS_FORCE(force, format) {\
if (force) Dbprintf (format NOLF); \
}
#define DBGLOG_ERROR(...) {\
if (DBGLEVEL >= DBG_ERROR) Dbprintf (__VA_ARGS__); \
#define DBGLOG_FORCE(force, format, ...) {\
if (force) Dbprintf (format NOLF, __VA_ARGS__); \
}
#define DBGLOG_CRITICAL(...) {\
if (DBGLEVEL >= DBG_ERROR) Dbprintf (__VA_ARGS__); \
#define DBGLOGS_ERROR(format) {\
if (DBGLEVEL >= DBG_ERROR) Dbprintf (format NOLF); \
}
#define DBGLOG_DEBUG(...) {\
if (DBGLEVEL >= DBG_DEBUG) Dbprintf (__VA_ARGS__); \
#define DBGLOG_ERROR(format, ...) {\
if (DBGLEVEL >= DBG_ERROR) Dbprintf (format NOLF, __VA_ARGS__); \
}
#define DBGLOG_TRACE(...) {\
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf (__VA_ARGS__); \
#define DBGLOGS_CRITICAL(format) {\
if (DBGLEVEL >= DBG_ERROR) Dbprintf (format NOLF); \
}
#define DBGLOG_CRITICAL(format, ...) {\
if (DBGLEVEL >= DBG_ERROR) Dbprintf (format NOLF, __VA_ARGS__); \
}
#define DBGLOGS_DEBUG(format) {\
if (DBGLEVEL >= DBG_DEBUG) Dbprintf (format NOLF); \
}
#define DBGLOG_DEBUG(format, ...) {\
if (DBGLEVEL >= DBG_DEBUG) Dbprintf (format NOLF, __VA_ARGS__); \
}
#define DBGLOGS_TRACE(format) {\
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf (format NOLF); \
}
#define DBGLOG_TRACE(format, ...) {\
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf (format NOLF, __VA_ARGS__); \
}
#define DBGLOG_32_BIT_PTR(ptr) (ptr)
#endif

View File

@@ -3,7 +3,7 @@
#include <stddef.h>
#include <stdbool.h>
#include <math.h>
//#include <math.h>
#ifdef UMM_INFO
/* ----------------------------------------------------------------------------
@@ -40,8 +40,8 @@ void *umm_info( void *ptr, bool force ) {
*/
memset( &ummHeapInfo, 0, sizeof( ummHeapInfo ) );
DBGLOG_FORCE( force, "\n" );
DBGLOG_FORCE( force, "+----------+-------+--------+--------+-------+--------+--------+\n" );
DBGLOGS_FORCE( force, "\n" );
DBGLOGS_FORCE( force, "+----------+-------+--------+--------+-------+--------+--------+\n" );
DBGLOG_FORCE( force, "|0x%08x|B %5i|NB %5i|PB %5i|Z %5i|NF %5i|PF %5i|\n",
DBGLOG_32_BIT_PTR(&UMM_BLOCK(blockNo)),
blockNo,
@@ -125,7 +125,7 @@ void *umm_info( void *ptr, bool force ) {
UMM_NFREE(blockNo),
UMM_PFREE(blockNo) );
DBGLOG_FORCE( force, "+----------+-------+--------+--------+-------+--------+--------+\n" );
DBGLOGS_FORCE( force, "+----------+-------+--------+--------+-------+--------+--------+\n" );
DBGLOG_FORCE( force, "Total Entries %5i Used Entries %5i Free Entries %5i\n",
ummHeapInfo.totalEntries,
@@ -137,12 +137,12 @@ void *umm_info( void *ptr, bool force ) {
ummHeapInfo.usedBlocks,
ummHeapInfo.freeBlocks );
DBGLOG_FORCE( force, "+--------------------------------------------------------------+\n" );
DBGLOGS_FORCE( force, "+--------------------------------------------------------------+\n" );
DBGLOG_FORCE( force, "Usage Metric: %5i\n", umm_usage_metric());
DBGLOG_FORCE( force, "Fragmentation Metric: %5i\n", umm_fragmentation_metric());
DBGLOG_FORCE( force, "+--------------------------------------------------------------+\n" );
DBGLOGS_FORCE( force, "+--------------------------------------------------------------+\n" );
/* Release the critical section... */
UMM_CRITICAL_EXIT();
@@ -168,12 +168,20 @@ int umm_usage_metric( void ) {
return (int)((ummHeapInfo.usedBlocks * 100)/(ummHeapInfo.freeBlocks));
}
static uint32_t sqrt(uint32_t x) {
double n=x;
while((n*n-x>0.0001)||(n*n-x<-0.0001)){
n=(n+x/n)/2;
}
return (uint32_t)n;
}
int umm_fragmentation_metric( void ) {
DBGLOG_DEBUG( "freeBlocks %i freeBlocksSquared %i\n", ummHeapInfo.freeBlocks, ummHeapInfo.freeBlocksSquared);
if (0 == ummHeapInfo.freeBlocks) {
return 0;
} else {
return (100 - (((uint32_t)(sqrtf(ummHeapInfo.freeBlocksSquared)) * 100)/(ummHeapInfo.freeBlocks)));
return (100 - ((sqrt(ummHeapInfo.freeBlocksSquared) * 100)/(ummHeapInfo.freeBlocks)));
}
}

View File

@@ -49,11 +49,9 @@
#define DBGLOG_LEVEL 0
//#include "dbglog/dbglog.h"
#include "dbprint.h"
extern void *UMM_MALLOC_CFG_HEAP_ADDR;
extern uint32_t UMM_MALLOC_CFG_HEAP_SIZE;
extern uint8_t _stack_start, __bss_end__;
/* ------------------------------------------------------------------------- */
@@ -187,7 +185,7 @@ static void umm_assimilate_up( uint16_t c ) {
* the free list
*/
DBGLOG_DEBUG( "Assimilate up to next block, which is FREE\n" );
DBGLOGS_DEBUG( "Assimilate up to next block, which is FREE\n" );
/* Disconnect the next block from the FREE list */
@@ -232,6 +230,10 @@ static uint16_t umm_assimilate_down( uint16_t c, uint16_t freemask ) {
/* ------------------------------------------------------------------------- */
void umm_init( void ) {
void *UMM_MALLOC_CFG_HEAP_ADDR = &__bss_end__;
uint32_t UMM_MALLOC_CFG_HEAP_SIZE = (uint32_t)&_stack_start - (uint32_t)&__bss_end__;
/* init heap pointer and size, and memset it to 0 */
umm_heap = (umm_block *)UMM_MALLOC_CFG_HEAP_ADDR;
umm_numblocks = (UMM_MALLOC_CFG_HEAP_SIZE / sizeof(umm_block));
@@ -313,7 +315,7 @@ static void umm_free_core( void *ptr ) {
if( UMM_NBLOCK(UMM_PBLOCK(c)) & UMM_FREELIST_MASK ) {
DBGLOG_DEBUG( "Assimilate down to previous block, which is FREE\n" );
DBGLOGS_DEBUG( "Assimilate down to previous block, which is FREE\n" );
c = umm_assimilate_down(c, UMM_FREELIST_MASK);
} else {
@@ -323,7 +325,7 @@ static void umm_free_core( void *ptr ) {
*/
UMM_FRAGMENTATION_METRIC_ADD(c);
DBGLOG_DEBUG( "Just add to head of free list\n" );
DBGLOGS_DEBUG( "Just add to head of free list\n" );
UMM_PFREE(UMM_NFREE(0)) = c;
UMM_NFREE(c) = UMM_NFREE(0);
@@ -345,7 +347,7 @@ void umm_free( void *ptr ) {
/* If we're being asked to free a NULL pointer, well that's just silly! */
if( (void *)0 == ptr ) {
DBGLOG_DEBUG( "free a null pointer -> do nothing\n" );
DBGLOGS_DEBUG( "free a null pointer -> do nothing\n" );
return;
}
@@ -490,7 +492,7 @@ void *umm_malloc( size_t size ) {
*/
if( 0 == size ) {
DBGLOG_DEBUG( "malloc a block of 0 bytes -> do nothing\n" );
DBGLOGS_DEBUG( "malloc a block of 0 bytes -> do nothing\n" );
return( ptr );
}
@@ -532,7 +534,7 @@ void *umm_realloc( void *ptr, size_t size ) {
*/
if( ((void *)NULL == ptr) ) {
DBGLOG_DEBUG( "realloc the NULL pointer - call malloc()\n" );
DBGLOGS_DEBUG( "realloc the NULL pointer - call malloc()\n" );
return( umm_malloc(size) );
}
@@ -544,7 +546,7 @@ void *umm_realloc( void *ptr, size_t size ) {
*/
if( 0 == size ) {
DBGLOG_DEBUG( "realloc to 0 size, just free the block\n" );
DBGLOGS_DEBUG( "realloc to 0 size, just free the block\n" );
umm_free( ptr );

View File

@@ -12,6 +12,7 @@
#include <stddef.h>
#include <stdbool.h>
#define UMM_INFO
/*
* There are a number of defines you can set at compile time that affect how
* the memory allocator will operate.