mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-18 11:03:50 +01:00
cpu/msp430_common: changes for heap command
This commit is contained in:
parent
a63c0dda9c
commit
a9db53e04a
@ -77,6 +77,11 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Declare the heap_stats function as available
|
||||||
|
*/
|
||||||
|
#define HAVE_HEAP_STATS
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -224,6 +224,10 @@ free(void *p)
|
|||||||
|
|
||||||
state = irq_disable();
|
state = irq_disable();
|
||||||
|
|
||||||
|
if (__brkval == NULL) {
|
||||||
|
__brkval = __malloc_heap_start;
|
||||||
|
}
|
||||||
|
|
||||||
/* ISO C says free(NULL) must be a no-op */
|
/* ISO C says free(NULL) must be a no-op */
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
irq_restore(state);
|
irq_restore(state);
|
||||||
@ -457,4 +461,26 @@ calloc(size_t nele, size_t size)
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void heap_stats(void)
|
||||||
|
{
|
||||||
|
if (__brkval == NULL) {
|
||||||
|
__brkval = __malloc_heap_start;
|
||||||
|
}
|
||||||
|
|
||||||
|
long int heap_size = __malloc_heap_end - __malloc_heap_start;
|
||||||
|
long int free = __malloc_heap_end - __brkval;
|
||||||
|
struct __freelist *fp;
|
||||||
|
for (fp = __flp; fp; fp = fp->nx) {
|
||||||
|
free += fp->sz;
|
||||||
|
}
|
||||||
|
printf("heap: %ld (used %ld, free %ld) [bytes]\n",
|
||||||
|
heap_size, heap_size - free, free);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
void heap_stats(void) {
|
||||||
|
puts("heap statistics are not supported");
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* MODULE_MSP430_MALLOC */
|
#endif /* MODULE_MSP430_MALLOC */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user