Browse Source

HAL_ChibiOS: implement thread_info()

c415-sdk
Andrew Tridgell 5 years ago
parent
commit
f0c9f4003e
  1. 39
      libraries/AP_HAL_ChibiOS/Util.cpp
  2. 3
      libraries/AP_HAL_ChibiOS/Util.h
  3. 2
      libraries/AP_HAL_ChibiOS/hwdef/common/chconf.h

39
libraries/AP_HAL_ChibiOS/Util.cpp

@ -303,3 +303,42 @@ bool Util::was_watchdog_reset() const @@ -303,3 +303,42 @@ bool Util::was_watchdog_reset() const
{
return stm32_was_watchdog_reset();
}
/*
display stack usage as text buffer for @SYS/threads.txt
*/
size_t Util::thread_info(char *buf, size_t bufsize)
{
thread_t *tp;
size_t total = 0;
// a header to allow for machine parsers to determine format
int n = snprintf(buf, bufsize, "ThreadsV1\n");
if (n <= 0) {
return 0;
}
buf += n;
bufsize -= n;
total += n;
tp = chRegFirstThread();
do {
uint32_t stklimit = (uint32_t)tp->wabase;
uint8_t *p = (uint8_t *)tp->wabase;
while (*p == CH_DBG_STACK_FILL_VALUE) {
p++;
}
uint32_t stack_left = ((uint32_t)p) - stklimit;
n = snprintf(buf, bufsize, "%-13.13s PRI=%3u STACK_LEFT=%u\n", tp->name, unsigned(tp->prio), unsigned(stack_left));
if (n <= 0) {
break;
}
buf += n;
bufsize -= n;
total += n;
tp = chRegNextThread(tp);
} while (tp != NULL);
return total;
}

3
libraries/AP_HAL_ChibiOS/Util.h

@ -65,6 +65,9 @@ public: @@ -65,6 +65,9 @@ public:
// return true if the reason for the reboot was a watchdog reset
bool was_watchdog_reset() const override;
// request information on running threads
size_t thread_info(char *buf, size_t bufsize) override;
private:
#ifdef HAL_PWM_ALARM
struct ToneAlarmPwmGroup {

2
libraries/AP_HAL_ChibiOS/hwdef/common/chconf.h

@ -575,7 +575,7 @@ @@ -575,7 +575,7 @@
* @p panic_msg variable set to @p NULL.
*/
#if !defined(CH_DBG_ENABLE_STACK_CHECK)
#define CH_DBG_ENABLE_STACK_CHECK FALSE
#define CH_DBG_ENABLE_STACK_CHECK TRUE
#endif
/**

Loading…
Cancel
Save