mirror of https://github.com/rusefi/ChibiOS.git
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1564 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
e32275f84a
commit
217d1529c1
|
@ -32,7 +32,60 @@ static Thread *cdtp;
|
|||
static Thread *shelltp1;
|
||||
static Thread *shelltp2;
|
||||
|
||||
void cmd_test(BaseChannel *chp, int argc, char *argv[]) {
|
||||
static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) {
|
||||
size_t n, size;
|
||||
char buf[52];
|
||||
|
||||
(void)argv;
|
||||
if (argc > 0) {
|
||||
shellPrintLine(chp, "Usage: mem");
|
||||
return;
|
||||
}
|
||||
n = chHeapStatus(NULL, &size);
|
||||
sprintf(buf, "core free memory : %i bytes", chCoreFree());
|
||||
shellPrintLine(chp, buf);
|
||||
sprintf(buf, "heap fragments : %i", n);
|
||||
shellPrintLine(chp, buf);
|
||||
sprintf(buf, "heap free total : %i bytes", size);
|
||||
shellPrintLine(chp, buf);
|
||||
}
|
||||
|
||||
static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) {
|
||||
static const char *states[] = {
|
||||
"READY",
|
||||
"CURRENT",
|
||||
"SUSPENDED",
|
||||
"WTSEM",
|
||||
"WTMTX",
|
||||
"WTCOND",
|
||||
"SLEEPING",
|
||||
"WTEXIT",
|
||||
"WTOREVT",
|
||||
"WTANDEVT",
|
||||
"SNDMSG",
|
||||
"WTMSG",
|
||||
"FINAL"
|
||||
};
|
||||
Thread *tp;
|
||||
char buf[60];
|
||||
|
||||
(void)argv;
|
||||
if (argc > 0) {
|
||||
shellPrintLine(chp, "Usage: threads");
|
||||
return;
|
||||
}
|
||||
shellPrintLine(chp, " addr stack prio refs state time");
|
||||
tp = chRegFirstThread();
|
||||
do {
|
||||
sprintf(buf, "%8p %8p %4i %4i %9s %i",
|
||||
tp, tp->p_ctx.esp, tp->p_prio, tp->p_refs - 1,
|
||||
states[tp->p_state], tp->p_time);
|
||||
shellPrintLine(chp, buf);
|
||||
tp = chRegNextThread(tp);
|
||||
} while (tp != NULL);
|
||||
}
|
||||
|
||||
static void cmd_test(BaseChannel *chp, int argc, char *argv[]) {
|
||||
Thread *tp;
|
||||
|
||||
(void)argv;
|
||||
|
@ -50,6 +103,8 @@ void cmd_test(BaseChannel *chp, int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
static const ShellCommand commands[] = {
|
||||
{"mem", cmd_mem},
|
||||
{"threads", cmd_threads},
|
||||
{"test", cmd_test},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
|
|
@ -64,6 +64,7 @@ extern "C" {
|
|||
void core_init(void);
|
||||
void *chCoreAlloc(size_t size);
|
||||
void *chCoreAllocI(size_t size);
|
||||
size_t chCoreFree(void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -32,9 +32,8 @@ static uint8_t *nextmem;
|
|||
static uint8_t *endmem;
|
||||
|
||||
/**
|
||||
* @brief Low level memory manager initialization.
|
||||
*
|
||||
* @note Internal use only.
|
||||
* @brief Low level memory manager initialization.
|
||||
* @note Internal use only.
|
||||
*/
|
||||
void core_init(void) {
|
||||
#if CH_MEMCORE_SIZE == 0
|
||||
|
@ -50,15 +49,15 @@ void core_init(void) {
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Allocates a memory block.
|
||||
* @brief Allocates a memory block.
|
||||
* @details The size of the returned block is aligned to the alignment
|
||||
* type @p align_t so it is not possible to allocate less than
|
||||
* <code>sizeof(align_t)</code>.
|
||||
*
|
||||
*
|
||||
* @param[in] size the size of the block to be allocated
|
||||
* @return A pointer to the allocated memory block.
|
||||
* @retval NULL allocation failed, core memory exhausted.
|
||||
* @param[in] size the size of the block to be allocated
|
||||
* @return A pointer to the allocated memory block.
|
||||
* @retval NULL allocation failed, core memory exhausted.
|
||||
*/
|
||||
void *chCoreAlloc(size_t size) {
|
||||
void *p;
|
||||
|
@ -70,14 +69,14 @@ void *chCoreAlloc(size_t size) {
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Allocates a memory block.
|
||||
* @brief Allocates a memory block.
|
||||
* @details The size of the returned block is aligned to the alignment
|
||||
* type @p align_t so it is not possible to allocate less than
|
||||
* <code>sizeof(align_t)</code>.
|
||||
*
|
||||
* @param[in] size the size of the block to be allocated.
|
||||
* @return A pointer to the allocated memory block.
|
||||
* @retval NULL allocation failed, core memory exhausted.
|
||||
* @param[in] size the size of the block to be allocated.
|
||||
* @return A pointer to the allocated memory block.
|
||||
* @retval NULL allocation failed, core memory exhausted.
|
||||
*/
|
||||
void *chCoreAllocI(size_t size) {
|
||||
void *p;
|
||||
|
@ -90,6 +89,15 @@ void *chCoreAllocI(size_t size) {
|
|||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Core memory left.
|
||||
*
|
||||
* @return The size, in bytes, of the free core memory.
|
||||
*/
|
||||
size_t chCoreFree(void) {
|
||||
|
||||
return (size_t)(endmem - nextmem);
|
||||
}
|
||||
#endif /* CH_USE_MEMCORE */
|
||||
|
||||
/** @} */
|
||||
|
|
|
@ -33,6 +33,8 @@
|
|||
* the main thread unless it terminated.
|
||||
* @note A reference is added to the returned thread in order to make sure
|
||||
* it status is not lost.
|
||||
* @note This function cannot return @p NULL because there is always at
|
||||
* least one thread in the system.
|
||||
*
|
||||
* @return A reference to the first thread.
|
||||
*/
|
||||
|
|
|
@ -62,7 +62,11 @@
|
|||
- NEW: Implemented a new threads registry subsystem, the registry allows to
|
||||
enumerate the active threads at runtime. The registry is meant as both
|
||||
a runtime API and a support for debuggers.
|
||||
|
||||
- NEW: New chCoreFree() API that returns the core memory left.
|
||||
- NEW: Added to the simulators shell demos two new commands: threads and mem,
|
||||
that show the active threads (using the new registry) and the memory
|
||||
allocators state.
|
||||
|
||||
*** 1.5.0 ***
|
||||
- FIX: Fixed missing dependencies check for CH_USE_DYNAMIC (bug 2942757)
|
||||
(backported in 1.4.1).
|
||||
|
|
Loading…
Reference in New Issue