xiaoxiang781216 commented on code in PR #7808: URL: https://github.com/apache/nuttx/pull/7808#discussion_r1043437699
########## include/nuttx/misc/panic.h: ########## @@ -0,0 +1,77 @@ +/**************************************************************************** + * include/nuttx/misc/panic.h Review Comment: ```suggestion * include/nuttx/panic_notifier.h ``` ########## include/nuttx/misc/panic.h: ########## @@ -0,0 +1,77 @@ +/**************************************************************************** + * include/nuttx/misc/panic.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_MISC_PANIC_H Review Comment: ```suggestion #ifndef __INCLUDE_NUTTX_PANIC_NOTIFIER_H ``` ########## arch/z80/src/common/z80_assert.c: ########## @@ -33,91 +33,11 @@ #include <nuttx/arch.h> #include <nuttx/board.h> #include <nuttx/syslog/syslog.h> -#include <nuttx/usb/usbdev_trace.h> #include "chip.h" #include "sched/sched.h" Review Comment: don't need include sched/sched.h ########## sched/misc/assert.c: ########## @@ -22,17 +22,150 @@ * Included Files ****************************************************************************/ +#include <nuttx/config.h> + #include <nuttx/arch.h> +#include <nuttx/board.h> +#include <nuttx/irq.h> +#include <nuttx/misc/panic.h> +#include <nuttx/usb/usbdev_trace.h> +#include <nuttx/syslog/syslog.h> #include <assert.h> +#include <debug.h> #include <stdlib.h> +#include "irq/irq.h" +#include "sched/sched.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifndef CONFIG_BOARD_RESET_ON_ASSERT +# define CONFIG_BOARD_RESET_ON_ASSERT 0 +#endif + +/* USB trace dumping */ + +#ifndef CONFIG_USBDEV_TRACE +# undef CONFIG_ARCH_USBDUMP +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: assert_tracecallback + ****************************************************************************/ + +#ifdef CONFIG_ARCH_USBDUMP +static int usbtrace_syslog(FAR const char *fmt, ...) +{ + va_list ap; + + /* Let vsyslog do the real work */ + + va_start(ap, fmt); + vsyslog(LOG_EMERG, fmt, ap); + va_end(ap); + return OK; +} + +static int assert_tracecallback(FAR struct usbtrace_s *trace, FAR void *arg) +{ + usbtrace_trprintf(usbtrace_syslog, trace->event, trace->value); + return 0; +} +#endif + +/**************************************************************************** + * Name: riscv_assert + ****************************************************************************/ + +static void assert_end(void) +{ + /* Flush any buffered SYSLOG data */ + + syslog_flush(); + + /* Are we in an interrupt handler or the idle task? */ + + if (up_interrupt_context() || running_task()->flink == NULL) + { +#if CONFIG_BOARD_RESET_ON_ASSERT >= 1 + board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); +#endif + + /* Disable interrupts on this CPU */ + + up_irq_save(); + +#ifdef CONFIG_SMP + /* Try (again) to stop activity on other CPUs */ + + spin_trylock(&g_cpu_irqlock); +#endif + + for (; ; ) + { + up_mdelay(250); + } + } + else + { +#if CONFIG_BOARD_RESET_ON_ASSERT >= 2 + board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); +#endif + } +} + /**************************************************************************** * Public Functions ****************************************************************************/ void _assert(FAR const char *filename, int linenum) { + panic_notifier_call_chain(0, NULL); Review Comment: move after line 134 ########## sched/misc/panic.c: ########## @@ -0,0 +1,88 @@ +/**************************************************************************** + * sched/misc/panic.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/arch.h> +#include <nuttx/notifier.h> + +#include <sys/types.h> + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +ATOMIC_NOTIFIER_HEAD(g_panic_notifier_list); Review Comment: add static ########## sched/misc/assert.c: ########## @@ -22,17 +22,150 @@ * Included Files ****************************************************************************/ +#include <nuttx/config.h> + #include <nuttx/arch.h> +#include <nuttx/board.h> +#include <nuttx/irq.h> +#include <nuttx/misc/panic.h> +#include <nuttx/usb/usbdev_trace.h> +#include <nuttx/syslog/syslog.h> #include <assert.h> +#include <debug.h> #include <stdlib.h> +#include "irq/irq.h" +#include "sched/sched.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifndef CONFIG_BOARD_RESET_ON_ASSERT +# define CONFIG_BOARD_RESET_ON_ASSERT 0 +#endif + +/* USB trace dumping */ + +#ifndef CONFIG_USBDEV_TRACE +# undef CONFIG_ARCH_USBDUMP +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: assert_tracecallback + ****************************************************************************/ + +#ifdef CONFIG_ARCH_USBDUMP +static int usbtrace_syslog(FAR const char *fmt, ...) +{ + va_list ap; + + /* Let vsyslog do the real work */ + + va_start(ap, fmt); + vsyslog(LOG_EMERG, fmt, ap); + va_end(ap); + return OK; +} + +static int assert_tracecallback(FAR struct usbtrace_s *trace, FAR void *arg) +{ + usbtrace_trprintf(usbtrace_syslog, trace->event, trace->value); + return 0; +} +#endif + +/**************************************************************************** + * Name: riscv_assert + ****************************************************************************/ + +static void assert_end(void) +{ + /* Flush any buffered SYSLOG data */ + + syslog_flush(); + + /* Are we in an interrupt handler or the idle task? */ + + if (up_interrupt_context() || running_task()->flink == NULL) + { +#if CONFIG_BOARD_RESET_ON_ASSERT >= 1 + board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); +#endif + + /* Disable interrupts on this CPU */ + + up_irq_save(); + +#ifdef CONFIG_SMP + /* Try (again) to stop activity on other CPUs */ + + spin_trylock(&g_cpu_irqlock); +#endif + + for (; ; ) + { + up_mdelay(250); + } + } + else + { +#if CONFIG_BOARD_RESET_ON_ASSERT >= 2 + board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); +#endif + } +} + /**************************************************************************** * Public Functions ****************************************************************************/ void _assert(FAR const char *filename, int linenum) { + panic_notifier_call_chain(0, NULL); Review Comment: need tell callback whether it's fatal error or not ########## arch/z80/src/common/z80_assert.c: ########## @@ -129,37 +49,10 @@ static int assert_tracecallback(struct usbtrace_s *trace, void *arg) void up_assert(const char *filename, int lineno) { board_autoled_on(LED_ASSERTION); - - /* Flush any buffered SYSLOG data (from prior to the assertion) */ - - syslog_flush(); - -#if CONFIG_TASK_NAME_SIZE > 0 - _alert("Assertion failed at file:%s line: %d task: %s\n", - filename, lineno, running_task()->name); -#else - _alert("Assertion failed at file:%s line: %d\n", - filename, lineno); -#endif - Z80_REGISTER_DUMP(); z80_stackdump(); -#ifdef CONFIG_ARCH_USBDUMP - /* Dump USB trace data */ - - usbtrace_enumerate(assert_tracecallback, NULL); -#endif - /* Flush any buffered SYSLOG data (from the above) */ syslog_flush(); Review Comment: remove all syslog_flush in up_assert ########## arch/z80/src/common/z80_assert.c: ########## @@ -33,91 +33,11 @@ #include <nuttx/arch.h> #include <nuttx/board.h> #include <nuttx/syslog/syslog.h> Review Comment: remove the unneeded header files: nuttx/syslog/syslog.h nuttx/irq.h stdint.h stdlib.h assert.h -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org