forked from Archive/PX4-Autopilot
IO: Fix access to free memory
The free memory was accessed from interrupt context where it should not be accessed from. We build the statistic now at a fixed rate while not armed.
This commit is contained in:
parent
8bfa84f73f
commit
1bb56e775e
|
@ -89,6 +89,7 @@ static char msg[NUM_MSG][CONFIG_USART1_TXBUFSIZE];
|
|||
|
||||
static void heartbeat_blink(void);
|
||||
static void ring_blink(void);
|
||||
static void update_mem_usage(void);
|
||||
|
||||
/*
|
||||
* add a debug message to be printed on the console
|
||||
|
@ -128,6 +129,27 @@ show_debug_messages(void)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the memory usage at 2 Hz while not armed
|
||||
*/
|
||||
static void
|
||||
update_mem_usage(void)
|
||||
{
|
||||
if (/* IO armed */ (r_status_flags & PX4IO_P_STATUS_FLAGS_SAFETY_OFF)
|
||||
/* and FMU is armed */ && (r_setup_arming & PX4IO_P_SETUP_ARMING_FMU_ARMED)) {
|
||||
return;
|
||||
}
|
||||
|
||||
static uint64_t last_mem_time = 0;
|
||||
uint64_t now = hrt_absolute_time();
|
||||
|
||||
if (now - last_mem_time > (500 * 1000)) {
|
||||
struct mallinfo minfo = mallinfo();
|
||||
r_page_status[PX4IO_P_STATUS_FREEMEM] = minfo.fordblks;
|
||||
last_mem_time = now;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
heartbeat_blink(void)
|
||||
{
|
||||
|
@ -311,6 +333,7 @@ user_start(int argc, char *argv[])
|
|||
perf_counter_t loop_perf = perf_alloc(PC_INTERVAL, "loop");
|
||||
|
||||
struct mallinfo minfo = mallinfo();
|
||||
r_page_status[PX4IO_P_STATUS_FREEMEM] = minfo.mxordblk;
|
||||
syslog(LOG_INFO, "MEM: free %u, largest %u\n", minfo.mxordblk, minfo.fordblks);
|
||||
|
||||
/* initialize PWM limit lib */
|
||||
|
@ -418,6 +441,8 @@ user_start(int argc, char *argv[])
|
|||
LED_BLUE(true);
|
||||
}
|
||||
|
||||
update_mem_usage();
|
||||
|
||||
ring_blink();
|
||||
|
||||
check_reboot();
|
||||
|
|
|
@ -880,10 +880,6 @@ registers_get(uint8_t page, uint8_t offset, uint16_t **values, unsigned *num_val
|
|||
*/
|
||||
case PX4IO_PAGE_STATUS:
|
||||
/* PX4IO_P_STATUS_FREEMEM */
|
||||
{
|
||||
struct mallinfo minfo = mallinfo();
|
||||
r_page_status[PX4IO_P_STATUS_FREEMEM] = minfo.fordblks;
|
||||
}
|
||||
|
||||
/* XXX PX4IO_P_STATUS_CPULOAD */
|
||||
|
||||
|
|
Loading…
Reference in New Issue