PX4 Firmware
PX4 Autopilot Software http://px4.io
hardfault_log.c File Reference
#include <px4_platform_common/px4_config.h>
#include <px4_platform_common/module.h>
#include <nuttx/compiler.h>
#include <nuttx/arch.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <debug.h>
#include <stm32_bbsram.h>
#include <systemlib/px4_macros.h>
#include <systemlib/hardfault_log.h>
#include <lib/version/version.h>
Include dependency graph for hardfault_log.c:

Go to the source code of this file.

Macros

#define OUT_BUFFER_LEN   200
 

Functions

__EXPORT int hardfault_log_main (int argc, char *argv[])
 
static int genfault (int fault)
 
 CCASSERT (TIME_FMT_LEN==HEADER_TIME_FMT_LEN)
 
static int format_fault_time (char *format, struct timespec *ts, char *buffer, unsigned int maxsz)
 
static int format_fault_file_name (struct timespec *ts, char *buffer, unsigned int maxsz)
 
static void identify (const char *caller)
 
static int hardfault_get_desc (char *caller, struct bbsramd_s *desc, bool silent)
 
static int write_stack_detail (bool inValid, _stack_s *si, char *sp_name, char *buffer, int max, int fd)
 
static int read_stack (int fd, stack_word_t *words, int num)
 
static int write_stack (bool inValid, int winsize, uint32_t wtopaddr, uint32_t topaddr, uint32_t spaddr, uint32_t botaddr, char *sp_name, char *buffer, int max, int infd, int outfd)
 
static int write_registers (uint32_t regs[], char *buffer, int max, int fd)
 
static int write_registers_info (int fdout, info_s *pi, char *buffer, int sz)
 
static int write_interrupt_stack_info (int fdout, info_s *pi, char *buffer, unsigned int sz)
 
static int write_user_stack_info (int fdout, info_s *pi, char *buffer, unsigned int sz)
 
static int write_dump_info (int fdout, info_s *info, struct bbsramd_s *desc, char *buffer, unsigned int sz)
 
static int write_dump_time (char *caller, char *tag, int fdout, struct timespec *ts, char *buffer, unsigned int sz)
 
static int write_dump_header (char *caller, int fdout, struct timespec *ts, char *buffer, unsigned int sz)
 
static int write_dump_footer (char *caller, int fdout, struct timespec *ts, char *buffer, unsigned int sz)
 
static int write_intterupt_stack (int fdin, int fdout, info_s *pi, char *buffer, unsigned int sz)
 
static int write_user_stack (int fdin, int fdout, info_s *pi, char *buffer, unsigned int sz)
 
static int hardfault_append_to_ulog (const char *caller, int fdin)
 Append hardfault data to the stored ULog file (the log path is stored in BBSRAM). More...
 
static int hardfault_commit (char *caller)
 
static int hardfault_dowrite (char *caller, int infd, int outfd, struct bbsramd_s *desc, int format)
 
__EXPORT int hardfault_rearm (char *caller)
 
__EXPORT int hardfault_check_status (char *caller)
 
__EXPORT int hardfault_increment_reboot (char *caller, bool reset)
 
__EXPORT int hardfault_write (char *caller, int fd, int format, bool rearm)
 
static void print_usage (void)
 

Macro Definition Documentation

◆ OUT_BUFFER_LEN

#define OUT_BUFFER_LEN   200

Definition at line 71 of file hardfault_log.c.

Referenced by hardfault_dowrite().

Function Documentation

◆ CCASSERT()

Referenced by genfault().

Here is the caller graph for this function:

◆ format_fault_file_name()

static int format_fault_file_name ( struct timespec *  ts,
char *  buffer,
unsigned int  maxsz 
)
static

Definition at line 164 of file hardfault_log.c.

References arraySize, format_fault_time(), LOG_NAME_FMT, LOG_NAME_LEN, LOG_PATH_BASE, LOG_PATH_BASE_LEN, LOG_PATH_LEN, OK, TIME_FMT, and TIME_FMT_LEN.

Referenced by hardfault_commit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ format_fault_time()

static int format_fault_time ( char *  format,
struct timespec *  ts,
char *  buffer,
unsigned int  maxsz 
)
static

Definition at line 139 of file hardfault_log.c.

References OK, and TIME_FMT_LEN.

Referenced by format_fault_file_name(), hardfault_check_status(), write_dump_info(), and write_dump_time().

Here is the caller graph for this function:

◆ genfault()

static int genfault ( int  fault)
static

Definition at line 94 of file hardfault_log.c.

References CCASSERT(), HEADER_TIME_FMT_LEN, OK, TIME_FMT_LEN, and UNUSED.

Referenced by hardfault_log_main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hardfault_append_to_ulog()

static int hardfault_append_to_ulog ( const char *  caller,
int  fdin 
)
static

Append hardfault data to the stored ULog file (the log path is stored in BBSRAM).

Parameters
caller
fdinfile descriptor for plain-text hardhault log to read from
Returns
0 on success, -errno otherwise

Definition at line 592 of file hardfault_log.c.

References fd, HARDFAULT_MAX_ULOG_FILE_LEN, HARDFAULT_ULOG_PATH, identify(), read(), and write().

Referenced by hardfault_commit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hardfault_check_status()

__EXPORT int hardfault_check_status ( char *  caller)

Definition at line 985 of file hardfault_log.c.

References arraySize, fd, format_fault_time(), hardfault_get_desc(), HARDFAULT_PATH, hardfault_rearm(), HEADER_TIME_FMT, identify(), OK, state, and TIME_FMT_LEN.

Referenced by hardfault_log_main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hardfault_commit()

static int hardfault_commit ( char *  caller)
static

Definition at line 787 of file hardfault_log.c.

References arraySize, fd, format_fault_file_name(), hardfault_append_to_ulog(), HARDFAULT_FILE_FORMAT, hardfault_get_desc(), hardfault_write(), identify(), LOG_PATH_LEN, OK, and state.

Referenced by hardfault_log_main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hardfault_dowrite()

static int hardfault_dowrite ( char *  caller,
int  infd,
int  outfd,
struct bbsramd_s *  desc,
int  format 
)
static

Definition at line 862 of file hardfault_log.c.

References HARDFAULT_DISPLAY_FORMAT, HARDFAULT_FILE_FORMAT, HARDFAULT_PATH, identify(), lps22hb::info(), OK, OUT_BUFFER_LEN, read(), write_dump_footer(), write_dump_header(), write_dump_info(), write_interrupt_stack_info(), write_intterupt_stack(), write_registers_info(), write_user_stack(), and write_user_stack_info().

Referenced by hardfault_write().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hardfault_get_desc()

static int hardfault_get_desc ( char *  caller,
struct bbsramd_s *  desc,
bool  silent 
)
static

Definition at line 206 of file hardfault_log.c.

References fd, HARDFAULT_PATH, and identify().

Referenced by hardfault_check_status(), hardfault_commit(), and hardfault_write().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hardfault_increment_reboot()

__EXPORT int hardfault_increment_reboot ( char *  caller,
bool  reset 
)

Definition at line 1038 of file hardfault_log.c.

References fd, HARDFAULT_REBOOT_PATH, identify(), OK, read(), and write().

Referenced by hardfault_log_main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hardfault_log_main()

__EXPORT int hardfault_log_main ( int  argc,
char *  argv[] 
)

Definition at line 1162 of file hardfault_log.c.

References genfault(), hardfault_check_status(), hardfault_commit(), hardfault_increment_reboot(), hardfault_rearm(), and print_usage().

Here is the call graph for this function:

◆ hardfault_rearm()

__EXPORT int hardfault_rearm ( char *  caller)

Definition at line 964 of file hardfault_log.c.

References HARDFAULT_PATH, identify(), and OK.

Referenced by hardfault_check_status(), hardfault_log_main(), and hardfault_write().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hardfault_write()

__EXPORT int hardfault_write ( char *  caller,
int  fd,
int  format,
bool  rearm 
)

Definition at line 1085 of file hardfault_log.c.

References HARDFAULT_DISPLAY_FORMAT, hardfault_dowrite(), HARDFAULT_FILE_FORMAT, hardfault_get_desc(), hardfault_rearm(), identify(), and OK.

Referenced by hardfault_commit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ identify()

static void identify ( const char *  caller)
static

Definition at line 195 of file hardfault_log.c.

Referenced by hardfault_append_to_ulog(), hardfault_check_status(), hardfault_commit(), hardfault_dowrite(), hardfault_get_desc(), hardfault_increment_reboot(), hardfault_rearm(), and hardfault_write().

Here is the caller graph for this function:

◆ print_usage()

static void print_usage ( void  )
static

Definition at line 1137 of file hardfault_log.c.

Referenced by hardfault_log_main().

Here is the caller graph for this function:

◆ read_stack()

static int read_stack ( int  fd,
stack_word_t words,
int  num 
)
static

Definition at line 275 of file hardfault_log.c.

References read().

Referenced by write_stack().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_dump_footer()

static int write_dump_footer ( char *  caller,
int  fdout,
struct timespec *  ts,
char *  buffer,
unsigned int  sz 
)
static

Definition at line 536 of file hardfault_log.c.

References write_dump_time().

Referenced by hardfault_dowrite().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_dump_header()

static int write_dump_header ( char *  caller,
int  fdout,
struct timespec *  ts,
char *  buffer,
unsigned int  sz 
)
static

Definition at line 528 of file hardfault_log.c.

References write_dump_time().

Referenced by hardfault_dowrite().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_dump_info()

static int write_dump_info ( int  fdout,
info_s info,
struct bbsramd_s *  desc,
char *  buffer,
unsigned int  sz 
)
static

Definition at line 450 of file hardfault_log.c.

References info_s::current_regs, info_s::filename, format_fault_time(), HEADER_TIME_FMT, info_s::lineno, OK, info_s::pid, px4_build_uri(), px4_firmware_version_string(), TIME_FMT_LEN, and write().

Referenced by hardfault_dowrite().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_dump_time()

static int write_dump_time ( char *  caller,
char *  tag,
int  fdout,
struct timespec *  ts,
char *  buffer,
unsigned int  sz 
)
static

Definition at line 511 of file hardfault_log.c.

References format_fault_time(), HEADER_TIME_FMT, OK, TIME_FMT_LEN, and write().

Referenced by write_dump_footer(), and write_dump_header().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_interrupt_stack_info()

static int write_interrupt_stack_info ( int  fdout,
info_s pi,
char *  buffer,
unsigned int  sz 
)
static

Definition at line 417 of file hardfault_log.c.

References eIntStackPresent, eInvalidIntStackPrt, info_s::flags, info_s::stacks, and write_stack_detail().

Referenced by hardfault_dowrite().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_intterupt_stack()

static int write_intterupt_stack ( int  fdin,
int  fdout,
info_s pi,
char *  buffer,
unsigned int  sz 
)
static

Definition at line 544 of file hardfault_log.c.

References CONFIG_ISTACK_SIZE, eIntStackPresent, eInvalidIntStackPrt, info_s::flags, info_s::stacks, and write_stack().

Referenced by hardfault_dowrite().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_registers()

static int write_registers ( uint32_t  regs[],
char *  buffer,
int  max,
int  fd 
)
static

Definition at line 348 of file hardfault_log.c.

References OK, and write().

Referenced by write_registers_info().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_registers_info()

static int write_registers_info ( int  fdout,
info_s pi,
char *  buffer,
int  sz 
)
static

Definition at line 398 of file hardfault_log.c.

References info_s::current_regs, eRegsPresent, info_s::flags, info_s::regs, write(), and write_registers().

Referenced by hardfault_dowrite().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_stack()

static int write_stack ( bool  inValid,
int  winsize,
uint32_t  wtopaddr,
uint32_t  topaddr,
uint32_t  spaddr,
uint32_t  botaddr,
char *  sp_name,
char *  buffer,
int  max,
int  infd,
int  outfd 
)
static

Definition at line 285 of file hardfault_log.c.

References arraySize, OK, read_stack(), and write().

Referenced by write_intterupt_stack(), and write_user_stack().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_stack_detail()

static int write_stack_detail ( bool  inValid,
_stack_s si,
char *  sp_name,
char *  buffer,
int  max,
int  fd 
)
static

Definition at line 236 of file hardfault_log.c.

References OK, _stack_s::size, _stack_s::sp, _stack_s::top, and write().

Referenced by write_interrupt_stack_info(), and write_user_stack_info().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_user_stack()

static int write_user_stack ( int  fdin,
int  fdout,
info_s pi,
char *  buffer,
unsigned int  sz 
)
static

Definition at line 567 of file hardfault_log.c.

References CONFIG_USTACK_SIZE, eInvalidUserStackPtr, eUserStackPresent, info_s::flags, _stack_s::size, _stack_s::sp, info_s::stacks, _stack_s::top, stack_t::user, and write_stack().

Referenced by hardfault_dowrite().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_user_stack_info()

static int write_user_stack_info ( int  fdout,
info_s pi,
char *  buffer,
unsigned int  sz 
)
static

Definition at line 434 of file hardfault_log.c.

References eInvalidUserStackPtr, eUserStackPresent, info_s::flags, info_s::stacks, stack_t::user, and write_stack_detail().

Referenced by hardfault_dowrite().

Here is the call graph for this function:
Here is the caller graph for this function: