forked from arduino/ArduinoCore-zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
98 lines (77 loc) · 2.44 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* Copyright (c) 2022 Dhruva Gole
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "Arduino.h"
#include "zephyr/kernel.h"
#include <cstdint>
#ifdef CONFIG_LLEXT
#include <zephyr/llext/symbol.h>
#endif
#ifdef CONFIG_MULTITHREADING
void start_static_threads();
#endif
// This function will be overwriten by most variants.
void __attribute__((weak))initVariant(void) {
}
int main(void) {
#if (DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm) && CONFIG_USB_CDC_ACM)
Serial.begin(115200);
#endif
initVariant();
#ifdef CONFIG_MULTITHREADING
start_static_threads();
#endif
setup();
for (;;) {
loop();
#if 0 //(DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm) && CONFIG_USB_CDC_ACM) || DT_NODE_HAS_PROP(DT_PATH(zephyr_user), serials)
if (arduino::serialEventRun) arduino::serialEventRun();
#endif
}
return 0;
}
#ifdef CONFIG_LLEXT
LL_EXTENSION_SYMBOL(main);
#endif
/* These magic symbols are provided by the linker. */
extern void (*__preinit_array_start []) (void) __attribute__((weak));
extern void (*__preinit_array_end []) (void) __attribute__((weak));
extern void (*__init_array_start []) (void) __attribute__((weak));
extern void (*__init_array_end []) (void) __attribute__((weak));
static void __libc_init_array (void)
{
size_t count;
size_t i;
count = __preinit_array_end - __preinit_array_start;
for (i = 0; i < count; i++)
__preinit_array_start[i] ();
count = __init_array_end - __init_array_start;
for (i = 0; i < count; i++)
__init_array_start[i] ();
}
extern "C" __attribute__((section(".entry_point"), used)) void entry_point(struct k_heap* stack, size_t stack_size) {
// copy .data in the right place
// .bss should already be in the right place
// call constructors
extern uintptr_t _sidata;
extern uintptr_t _sdata;
extern uintptr_t _edata;
extern uintptr_t _sbss;
extern uintptr_t _ebss;
extern uintptr_t __heap_start;
extern uintptr_t __heap_end;
extern uintptr_t kheap_llext_heap;
extern uintptr_t kheap_llext_heap_size;
//__asm volatile ("cpsie i");
const size_t alignment = 4096;
printk("System Heap end: %p\n", &__heap_end);
printk("System Heap start: %p\n", &__heap_start);
printk("Sketch Heap start: %p, size %p\n", &kheap_llext_heap, &kheap_llext_heap_size);
// __heap_start = (__heap_start + (alignment - 1)) & ~(alignment - 1);
memcpy(&_sdata, &_sidata, (&_edata - &_sdata) * sizeof(uint32_t));
memset(&_sbss, 0, &_ebss - &_sbss);
__libc_init_array();
main();
}