Contiki-NG
Loading...
Searching...
No Matches
nrf_802154_platform_assert.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2026, RISE Research Institutes of Sweden AB.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the copyright holder nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28 * OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30/*---------------------------------------------------------------------------*/
31/**
32 * \file
33 * Platform assert override for nrf_802154 on the nRF5340 network core.
34 * Adapted from arch/cpu/nrf/nrf54l15/nrf_802154_platform_assert.h.
35 *
36 * The network core has no UARTE (NRF_HAS_UARTE 0); its debug output is
37 * forwarded to the application core over the IPC log ring buffer via
38 * dbg_putchar(). On an internal library assertion this reports
39 * "802154! file:line" through that path and then resets the core. BKPT
40 * is avoided on purpose: with a debugger attached it would halt in
41 * Debug state instead of escalating, hanging the core silently.
42 */
43/*---------------------------------------------------------------------------*/
44#ifndef NRF_802154_PLATFORM_ASSERT_H_
45#define NRF_802154_PLATFORM_ASSERT_H_
46/*---------------------------------------------------------------------------*/
47__attribute__((noreturn))
48static inline void
49nrf_802154_platform_assert_fail(const char *file, unsigned line)
50{
51 extern int dbg_putchar(int c);
52 const char *basename = file;
53 const char *p;
54 char digits[10];
55 int i;
56 volatile int d;
57
58 for(p = "802154! "; *p != '\0'; p++) {
59 dbg_putchar(*p);
60 }
61
62 /* Print the basename of __FILE__. */
63 for(p = file; *p != '\0'; p++) {
64 if(*p == '/') {
65 basename = p + 1;
66 }
67 }
68 for(p = basename; *p != '\0'; p++) {
69 dbg_putchar(*p);
70 }
71 dbg_putchar(':');
72
73 /* Print __LINE__ in decimal. */
74 if(line == 0) {
75 dbg_putchar('0');
76 } else {
77 i = 0;
78 while(line > 0) {
79 digits[i++] = (char)('0' + (line % 10));
80 line /= 10;
81 }
82 while(i-- > 0) {
83 dbg_putchar(digits[i]);
84 }
85 }
86 dbg_putchar('\n');
87
88 /* Brief spin so the IPC log drains before reset. */
89 for(d = 0; d < 100000; d++) {
90 }
91
92 /* System reset via SCB->AIRCR (CMSIS NVIC_SystemReset() equivalent). */
93 __asm volatile("dsb 0xF" ::: "memory");
94 *((volatile unsigned long *)0xE000ED0CUL) = 0x05FA0004UL;
95 __asm volatile("dsb 0xF" ::: "memory");
96 for(;;) {
97 __asm volatile("nop");
98 }
99}
100/*---------------------------------------------------------------------------*/
101#define NRF_802154_ASSERT(condition) \
102 do { \
103 if(!(condition)) { \
104 nrf_802154_platform_assert_fail(__FILE__, __LINE__); \
105 } \
106 } while(0)
107/*---------------------------------------------------------------------------*/
108#endif /* NRF_802154_PLATFORM_ASSERT_H_ */
int dbg_putchar(int c)
Print a character to debug output.
Definition dbg.c:54