2007-12-29 02:05:26 +01:00
|
|
|
/****************************************************************************
|
2020-04-26 21:49:33 +02:00
|
|
|
* arch/z80/src/common/z80_assert.c
|
2007-12-29 02:05:26 +01:00
|
|
|
*
|
2020-03-10 19:14:43 +01:00
|
|
|
* 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
|
2007-12-29 02:05:26 +01:00
|
|
|
*
|
2020-03-10 19:14:43 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-12-29 02:05:26 +01:00
|
|
|
*
|
2020-03-10 19:14:43 +01:00
|
|
|
* 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.
|
2007-12-29 02:05:26 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2009-12-16 15:15:34 +01:00
|
|
|
#include <stdint.h>
|
2007-12-29 02:05:26 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include <nuttx/irq.h>
|
|
|
|
#include <nuttx/arch.h>
|
2015-02-28 00:19:38 +01:00
|
|
|
#include <nuttx/board.h>
|
2018-03-04 15:07:07 +01:00
|
|
|
#include <nuttx/syslog/syslog.h>
|
2014-03-20 17:56:30 +01:00
|
|
|
#include <nuttx/usb/usbdev_trace.h>
|
2007-12-29 02:05:26 +01:00
|
|
|
|
2017-10-01 15:43:59 +02:00
|
|
|
#include "chip.h"
|
2020-04-26 21:49:33 +02:00
|
|
|
#include "z80_arch.h"
|
2014-08-09 01:53:55 +02:00
|
|
|
#include "sched/sched.h"
|
2019-06-10 03:08:42 +02:00
|
|
|
#include "z80_internal.h"
|
2007-12-29 02:05:26 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
2014-03-20 17:56:30 +01:00
|
|
|
* Pre-processor Definitions
|
2007-12-29 02:05:26 +01:00
|
|
|
****************************************************************************/
|
2014-10-08 20:48:47 +02:00
|
|
|
|
2014-03-20 17:56:30 +01:00
|
|
|
/* USB trace dumping */
|
|
|
|
|
|
|
|
#ifndef CONFIG_USBDEV_TRACE
|
|
|
|
# undef CONFIG_ARCH_USBDUMP
|
|
|
|
#endif
|
2007-12-29 02:05:26 +01:00
|
|
|
|
2018-08-23 00:20:50 +02:00
|
|
|
#ifndef CONFIG_BOARD_RESET_ON_ASSERT
|
|
|
|
# define CONFIG_BOARD_RESET_ON_ASSERT 0
|
|
|
|
#endif
|
|
|
|
|
2007-12-29 02:05:26 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: _up_assert
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-06-07 08:51:54 +02:00
|
|
|
static void _up_assert(void)
|
2007-12-29 02:05:26 +01:00
|
|
|
{
|
2018-06-08 00:28:41 +02:00
|
|
|
/* Flush any buffered SYSLOG data */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
syslog_flush();
|
2018-06-08 00:28:41 +02:00
|
|
|
|
2007-12-29 02:05:26 +01:00
|
|
|
/* Are we in an interrupt handler or the idle task? */
|
|
|
|
|
2018-12-19 00:35:42 +01:00
|
|
|
if (up_interrupt_context() || running_task()->flink == NULL)
|
2007-12-29 02:05:26 +01:00
|
|
|
{
|
2020-03-05 21:17:48 +01:00
|
|
|
up_irq_save();
|
|
|
|
for (; ; )
|
|
|
|
{
|
2018-08-23 00:20:50 +02:00
|
|
|
#if CONFIG_BOARD_RESET_ON_ASSERT >= 1
|
2020-03-05 21:17:48 +01:00
|
|
|
board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE);
|
2018-08-23 00:20:50 +02:00
|
|
|
#endif
|
2007-12-29 02:05:26 +01:00
|
|
|
#ifdef CONFIG_ARCH_LEDS
|
2020-03-05 21:17:48 +01:00
|
|
|
board_autoled_on(LED_PANIC);
|
|
|
|
up_mdelay(250);
|
|
|
|
board_autoled_off(LED_PANIC);
|
|
|
|
up_mdelay(250);
|
2007-12-29 02:05:26 +01:00
|
|
|
#endif
|
2020-03-05 21:17:48 +01:00
|
|
|
}
|
2007-12-29 02:05:26 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-23 00:20:50 +02:00
|
|
|
#if CONFIG_BOARD_RESET_ON_ASSERT >= 2
|
2018-11-10 21:06:46 +01:00
|
|
|
board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE);
|
2018-08-23 00:20:50 +02:00
|
|
|
#endif
|
2007-12-29 02:05:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-20 17:56:30 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: assert_tracecallback
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_ARCH_USBDUMP
|
2014-10-08 20:48:47 +02:00
|
|
|
static int usbtrace_syslog(FAR const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
2020-05-06 18:07:34 +02:00
|
|
|
/* Let vsyslog do the real work */
|
2014-10-08 20:48:47 +02:00
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2020-05-06 18:07:34 +02:00
|
|
|
vsyslog(LOG_EMERG, fmt, ap);
|
2014-10-08 20:48:47 +02:00
|
|
|
va_end(ap);
|
2020-05-06 18:07:34 +02:00
|
|
|
return OK;
|
2014-10-08 20:48:47 +02:00
|
|
|
}
|
|
|
|
|
2014-03-20 17:56:30 +01:00
|
|
|
static int assert_tracecallback(struct usbtrace_s *trace, void *arg)
|
|
|
|
{
|
2014-10-08 20:48:47 +02:00
|
|
|
usbtrace_trprintf(FAR usbtrace_syslog, trace->event, FAR trace->value);
|
2014-03-20 17:56:30 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-12-29 02:05:26 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: up_assert
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-06-07 08:51:54 +02:00
|
|
|
void up_assert(const char *filename, int lineno)
|
2007-12-29 02:05:26 +01:00
|
|
|
{
|
2016-06-21 13:26:08 +02:00
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0 && defined(CONFIG_DEBUG_ALERT)
|
2018-11-15 14:11:51 +01:00
|
|
|
struct tcb_s *rtcb = running_task();
|
2007-12-29 02:05:26 +01:00
|
|
|
#endif
|
|
|
|
|
2015-11-01 16:07:06 +01:00
|
|
|
board_autoled_on(LED_ASSERTION);
|
2007-12-29 02:05:26 +01:00
|
|
|
|
2018-06-08 00:28:41 +02:00
|
|
|
/* Flush any buffered SYSLOG data (from prior to the assertion) */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
syslog_flush();
|
2018-06-08 00:28:41 +02:00
|
|
|
|
2007-12-29 02:05:26 +01:00
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
2016-06-16 20:38:05 +02:00
|
|
|
_alert("Assertion failed at file:%s line: %d task: %s\n",
|
2016-06-14 17:07:53 +02:00
|
|
|
filename, lineno, rtcb->name);
|
2007-12-29 02:05:26 +01:00
|
|
|
#else
|
2016-06-16 20:38:05 +02:00
|
|
|
_alert("Assertion failed at file:%s line: %d\n",
|
2016-06-14 17:07:53 +02:00
|
|
|
filename, lineno);
|
2007-12-29 02:05:26 +01:00
|
|
|
#endif
|
|
|
|
|
2008-02-14 18:24:14 +01:00
|
|
|
REGISTER_DUMP();
|
2018-11-11 19:53:59 +01:00
|
|
|
up_stackdump();
|
2014-03-20 17:56:30 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_ARCH_USBDUMP
|
|
|
|
/* Dump USB trace data */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
usbtrace_enumerate(assert_tracecallback, NULL);
|
2014-03-20 17:56:30 +01:00
|
|
|
#endif
|
|
|
|
|
2018-06-08 00:28:41 +02:00
|
|
|
/* Flush any buffered SYSLOG data (from the above) */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
syslog_flush();
|
2018-06-08 00:28:41 +02:00
|
|
|
|
2015-03-04 14:00:29 +01:00
|
|
|
#ifdef CONFIG_BOARD_CRASHDUMP
|
2020-03-05 21:17:48 +01:00
|
|
|
/* Execute board-specific crash dump logic */
|
|
|
|
|
2020-03-10 19:14:43 +01:00
|
|
|
board_crashdump(z80_getsp(), running_task(), filename, lineno);
|
2015-03-04 14:00:29 +01:00
|
|
|
#endif
|
|
|
|
|
2020-06-07 08:51:54 +02:00
|
|
|
_up_assert();
|
2007-12-29 02:05:26 +01:00
|
|
|
}
|