Contiki-NG
Toggle main menu visibility
Loading...
Searching...
No Matches
startup-stubs.c
1
/*
2
* Copyright (c) 2026, RISE Research Institutes of Sweden AB
3
* All rights reserved.
4
*
5
* SPDX-License-Identifier: BSD-3-Clause
6
*/
7
8
#include "flpr-shared.h"
9
#include <stddef.h>
10
11
/* Minimal mem-routines (no libc available). */
12
void
*memset(
void
*s,
int
c,
size_t
n) {
13
unsigned
char
*p = s;
14
while
(n--) *p++ = (
unsigned
char)c;
15
return
s;
16
}
17
18
void
*memcpy(
void
*d,
const
void
*s,
size_t
n) {
19
unsigned
char
*dp = d;
20
const
unsigned
char
*sp = s;
21
while
(n--) *dp++ = *sp++;
22
return
d;
23
}
24
25
void
*memmove(
void
*d,
const
void
*s,
size_t
n) {
26
unsigned
char
*dp = d;
27
const
unsigned
char
*sp = s;
28
if
(dp < sp) {
29
while
(n--) *dp++ = *sp++;
30
}
else
{
31
dp += n; sp += n;
32
while
(n--) *--dp = *--sp;
33
}
34
return
d;
35
}
36
37
int
memcmp(
const
void
*a,
const
void
*b,
size_t
n) {
38
const
unsigned
char
*ap = a, *bp = b;
39
while
(n--) {
40
if
(*ap != *bp)
return
(
int
)*ap - (int)*bp;
41
ap++; bp++;
42
}
43
return
0;
44
}
45
46
void
SystemInit(
void
) { }
47
48
extern
int
main(
void
);
49
50
/* Override the spinning Trap_Handler from nrfx startup. Read mcause + mepc
51
* so we know what kind of exception fired and at what PC. The literal
52
* addresses/markers below mirror flpr-shared.h (a naked asm body cannot use the
53
* C macros): 0x2003F000 = FLPR_SHARED_COUNTER_ADDR (+4 = FLPR_FAULT_PC_ADDR),
54
* 0xFA110000 = FLPR_MARK_FAULT_BASE. */
55
__attribute__((naked,aligned(8)))
56
void my_trap_handler(
void
)
57
{
58
__asm__
volatile
(
59
"csrr t0, mcause \n"
60
"csrr t1, mepc \n"
61
"li t2, 0x2003F000 \n"
/* FLPR_SHARED_COUNTER_ADDR */
62
"li a4, 0xFA110000 \n"
/* FLPR_MARK_FAULT_BASE */
63
"andi t0, t0, 0xFF \n"
64
"or a4, a4, t0 \n"
65
"sw a4, 0(t2) \n"
/* counter = 0xFA1100|cause */
66
"sw t1, 4(t2) \n"
/* +4 = faulting PC */
67
"1: j 1b \n"
68
);
69
}
70
71
void
_start(
void
) {
72
/* Reroute mtvec from the silent-spin Trap_Handler to ours. */
73
__asm__
volatile
(
"csrw mtvec, %0"
::
"r"
(my_trap_handler));
74
FLPR_SHARED_COUNTER = FLPR_MARK_BOOT;
75
main();
76
FLPR_SHARED_COUNTER = FLPR_MARK_EXIT;
77
for
(;;);
78
}
79
80
void
watchdog_periodic
(
void
) { }
81
void
watchdog_init
(
void
) { }
82
void
watchdog_start
(
void
) { }
83
void
watchdog_stop
(
void
) { }
84
void
watchdog_reboot
(
void
) {
for
(;;); }
85
86
void
_exit(
int
code) { (void)code;
for
(;;); }
87
88
int
_write(
int
fd,
const
char
*buf,
int
n) { (void)fd; (void)buf;
return
n; }
89
int
_read(
int
fd,
char
*buf,
int
n) { (void)fd; (void)buf; (void)n;
return
0; }
90
int
_close(
int
fd) { (void)fd;
return
0; }
91
int
_lseek(
int
fd,
int
off
,
int
w) { (void)fd; (void)
off
; (void)w;
return
0; }
92
int
_fstat(
int
fd,
void
*st) { (void)fd; (void)st;
return
0; }
93
int
_isatty(
int
fd) { (void)fd;
return
1; }
94
int
_kill(
int
pid,
int
sig) { (void)pid; (void)sig;
return
-1; }
95
int
_getpid(
void
) {
return
1; }
96
void
*_sbrk(
int
incr) { (void)incr;
return
(
void
*)-1; }
off
static int off(void)
Definition
cc2538-rf.c:533
watchdog_reboot
void watchdog_reboot(void)
Keeps control until the WDT throws a reset signal.
Definition
startup-stubs.c:84
watchdog_start
void watchdog_start(void)
Starts the WDT in watchdog mode if enabled by user configuration, maximum interval.
Definition
startup-stubs.c:82
watchdog_periodic
void watchdog_periodic(void)
Writes the WDT clear sequence.
Definition
startup-stubs.c:80
watchdog_init
void watchdog_init(void)
Initialisation function for the WDT.
Definition
startup-stubs.c:81
watchdog_stop
void watchdog_stop(void)
Stops the WDT such that it won't timeout and cause MCU reset.
Definition
startup-stubs.c:83
arch
cpu
nrf-vpr
startup-stubs.c
Generated on
for Contiki-NG by
1.17.0