xiaoxiang781216 commented on code in PR #7808:
URL: https://github.com/apache/nuttx/pull/7808#discussion_r1045097739


##########
arch/arm64/src/common/arm64_initialize.c:
##########
@@ -57,6 +62,10 @@
 
 volatile uint64_t *g_current_regs[CONFIG_SMP_NCPUS];
 
+#ifdef CONFIG_ARCH_FPU
+static struct notifier_block g_fpu_assert_block;

Review Comment:
   ```suggestion
   static struct notifier_block g_fpu_panic_block;
   ```



##########
sched/misc/assert.c:
##########
@@ -22,17 +22,157 @@
  * Included Files
  ****************************************************************************/
 
+#include <nuttx/config.h>
+
 #include <nuttx/arch.h>
+#include <nuttx/board.h>
+#include <nuttx/irq.h>
+#include <nuttx/panic_notifier.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

Review Comment:
   assert_end



##########
sched/misc/assert.c:
##########
@@ -22,17 +22,157 @@
  * Included Files
  ****************************************************************************/
 
+#include <nuttx/config.h>
+
 #include <nuttx/arch.h>
+#include <nuttx/board.h>
+#include <nuttx/irq.h>
+#include <nuttx/panic_notifier.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)
 {
+  /* Flush any buffered SYSLOG data (from prior to the assertion) */
+
+  syslog_flush();
+
+  if (up_interrupt_context() || running_task()->flink == NULL)
+    {
+      panic_notifier_call_chain(PANIC_INTERRUPT, NULL);
+    }
+  else
+    {
+      panic_notifier_call_chain(PANIC_TASK, NULL);
+    }
+
+#ifdef CONFIG_SMP
+#if CONFIG_TASK_NAME_SIZE > 0

Review Comment:
   ```suggestion
   #   if CONFIG_TASK_NAME_SIZE > 0
   ```



##########
sched/misc/assert.c:
##########
@@ -22,17 +22,157 @@
  * Included Files
  ****************************************************************************/
 
+#include <nuttx/config.h>
+
 #include <nuttx/arch.h>
+#include <nuttx/board.h>
+#include <nuttx/irq.h>
+#include <nuttx/panic_notifier.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)
 {
+  /* Flush any buffered SYSLOG data (from prior to the assertion) */
+
+  syslog_flush();
+
+  if (up_interrupt_context() || running_task()->flink == NULL)
+    {
+      panic_notifier_call_chain(PANIC_INTERRUPT, NULL);
+    }
+  else
+    {
+      panic_notifier_call_chain(PANIC_TASK, NULL);
+    }
+
+#ifdef CONFIG_SMP
+#if CONFIG_TASK_NAME_SIZE > 0
+  _alert("Assertion failed CPU%d at file:%s line: %d task: %s\n",
+         up_cpu_index(), filename, linenum, running_task()->name);
+#else
+  _alert("Assertion failed CPU%d at file:%s line: %d\n",
+         up_cpu_index(), filename, linenum);
+#endif
+#else
+#if CONFIG_TASK_NAME_SIZE > 0
+  _alert("Assertion failed at file:%s line: %d task: %s\n",
+         filename, linenum, running_task()->name);
+#else
+  _alert("Assertion failed at file:%s line: %d\n",
+         filename, linenum);
+#endif

Review Comment:
   ```suggestion
   #  endif
   ```



##########
include/nuttx/panic_notifier.h:
##########
@@ -0,0 +1,87 @@
+/****************************************************************************
+ * include/nuttx/panic_notifier.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_PANIC_NOTIFIER_H
+#define __INCLUDE_NUTTX_PANIC_NOTIFIER_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/notifier.h>
+
+#include <sys/types.h>
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+enum panic_type_e
+{
+  PANIC_INTERRUPT      =  0,

Review Comment:
   ```suggestion
     PANIC_KERNEL      =  0,
   ```



##########
arch/avr/src/common/avr_assert.c:
##########
@@ -23,102 +23,12 @@
  ****************************************************************************/
 
 #include <nuttx/config.h>
-
-#include <stdint.h>
-#include <stdlib.h>
-#include <assert.h>
-#include <debug.h>

Review Comment:
   why the inclusion is different? please ensure all xxx-assert.c contain the 
same header files.



##########
sched/misc/assert.c:
##########
@@ -22,17 +22,157 @@
  * Included Files
  ****************************************************************************/
 
+#include <nuttx/config.h>
+
 #include <nuttx/arch.h>
+#include <nuttx/board.h>
+#include <nuttx/irq.h>
+#include <nuttx/panic_notifier.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)
 {
+  /* Flush any buffered SYSLOG data (from prior to the assertion) */
+
+  syslog_flush();
+
+  if (up_interrupt_context() || running_task()->flink == NULL)
+    {
+      panic_notifier_call_chain(PANIC_INTERRUPT, NULL);
+    }
+  else
+    {
+      panic_notifier_call_chain(PANIC_TASK, NULL);
+    }
+
+#ifdef CONFIG_SMP
+#if CONFIG_TASK_NAME_SIZE > 0
+  _alert("Assertion failed CPU%d at file:%s line: %d task: %s\n",
+         up_cpu_index(), filename, linenum, running_task()->name);
+#else
+  _alert("Assertion failed CPU%d at file:%s line: %d\n",
+         up_cpu_index(), filename, linenum);
+#endif
+#else
+#if CONFIG_TASK_NAME_SIZE > 0

Review Comment:
   ```suggestion
   #  if CONFIG_TASK_NAME_SIZE > 0
   ```



##########
sched/misc/assert.c:
##########
@@ -22,17 +22,157 @@
  * Included Files
  ****************************************************************************/
 
+#include <nuttx/config.h>
+
 #include <nuttx/arch.h>
+#include <nuttx/board.h>
+#include <nuttx/irq.h>
+#include <nuttx/panic_notifier.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)
 {
+  /* Flush any buffered SYSLOG data (from prior to the assertion) */
+
+  syslog_flush();
+
+  if (up_interrupt_context() || running_task()->flink == NULL)

Review Comment:
   ```
   #if CONFIG_BOARD_RESET_ON_ASSERT < 2
   if (!up_interrupt_context() &&running_task()->flink != NULL)
     {
     }
   else
   #endif
     {
     }
   ```



##########
sched/misc/assert.c:
##########
@@ -22,17 +22,157 @@
  * Included Files
  ****************************************************************************/
 
+#include <nuttx/config.h>
+
 #include <nuttx/arch.h>
+#include <nuttx/board.h>
+#include <nuttx/irq.h>
+#include <nuttx/panic_notifier.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)
 {
+  /* Flush any buffered SYSLOG data (from prior to the assertion) */
+
+  syslog_flush();
+
+  if (up_interrupt_context() || running_task()->flink == NULL)
+    {
+      panic_notifier_call_chain(PANIC_INTERRUPT, NULL);
+    }
+  else
+    {
+      panic_notifier_call_chain(PANIC_TASK, NULL);
+    }
+
+#ifdef CONFIG_SMP
+#if CONFIG_TASK_NAME_SIZE > 0
+  _alert("Assertion failed CPU%d at file:%s line: %d task: %s\n",
+         up_cpu_index(), filename, linenum, running_task()->name);
+#else

Review Comment:
   ```suggestion
   #  else
   ```



##########
sched/misc/assert.c:
##########
@@ -22,17 +22,157 @@
  * Included Files
  ****************************************************************************/
 
+#include <nuttx/config.h>
+
 #include <nuttx/arch.h>
+#include <nuttx/board.h>
+#include <nuttx/irq.h>
+#include <nuttx/panic_notifier.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)
 {
+  /* Flush any buffered SYSLOG data (from prior to the assertion) */
+
+  syslog_flush();
+
+  if (up_interrupt_context() || running_task()->flink == NULL)
+    {
+      panic_notifier_call_chain(PANIC_INTERRUPT, NULL);
+    }
+  else
+    {
+      panic_notifier_call_chain(PANIC_TASK, NULL);
+    }
+
+#ifdef CONFIG_SMP
+#if CONFIG_TASK_NAME_SIZE > 0
+  _alert("Assertion failed CPU%d at file:%s line: %d task: %s\n",
+         up_cpu_index(), filename, linenum, running_task()->name);
+#else
+  _alert("Assertion failed CPU%d at file:%s line: %d\n",
+         up_cpu_index(), filename, linenum);
+#endif
+#else
+#if CONFIG_TASK_NAME_SIZE > 0
+  _alert("Assertion failed at file:%s line: %d task: %s\n",
+         filename, linenum, running_task()->name);
+#else

Review Comment:
   ```suggestion
   #  else
   ```



##########
sched/misc/assert.c:
##########
@@ -22,17 +22,157 @@
  * Included Files
  ****************************************************************************/
 
+#include <nuttx/config.h>
+
 #include <nuttx/arch.h>
+#include <nuttx/board.h>
+#include <nuttx/irq.h>
+#include <nuttx/panic_notifier.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)
 {
+  /* Flush any buffered SYSLOG data (from prior to the assertion) */
+
+  syslog_flush();
+
+  if (up_interrupt_context() || running_task()->flink == NULL)
+    {
+      panic_notifier_call_chain(PANIC_INTERRUPT, NULL);
+    }
+  else
+    {
+      panic_notifier_call_chain(PANIC_TASK, NULL);
+    }
+
+#ifdef CONFIG_SMP
+#if CONFIG_TASK_NAME_SIZE > 0
+  _alert("Assertion failed CPU%d at file:%s line: %d task: %s\n",
+         up_cpu_index(), filename, linenum, running_task()->name);
+#else
+  _alert("Assertion failed CPU%d at file:%s line: %d\n",
+         up_cpu_index(), filename, linenum);
+#endif

Review Comment:
   ```suggestion
   #   endif
   ```



-- 
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

Reply via email to