SingingCat 0
application
init.c
1#include "user_app_info.h"
2
3int start(int MCULIBHANDLE, struct sc_firmware_api *api);
4
5// the linker script provides the ram & flash areas
6extern uint32_t _sidata;
7extern uint32_t _sdata;
8extern uint32_t _edata;
9extern uint32_t _sbss;
10extern uint32_t _ebss;
11extern int MCULIBHANDLE;
12extern struct userapp_info userapp_vector;
13
14struct userapp_info *get_userapp_vector() {
15 return &userapp_vector;
16}
17
18
19/*
20 * called before start(). Since we have no runtime, we'll have to do some
21 * stuff ourselves. For example, initialise the variables in ram from flash to
22 * their default values (_sidata flash region contains the default values, which need to be copied to ram position _sdata)
23 */
24int start_and_init(int MCULIB_HANDLE, struct sc_firmware_api *api) {
25 uint8_t *s;
26 uint8_t *t;
27
28 s = (uint8_t *)&_sidata;
29 t = (uint8_t *)&_sdata;
30
31#ifdef __unix
32 if (_sidata != 0) {
33 for (;;) {
34 *t = *s;
35 t++;
36 s++;
37 if (t >= ((uint8_t *)&_edata)) {
38 break;
39 }
40 }
41 }
42
43 if (_sbss != 0) {
44 s = (uint8_t *)&_sbss;
45 t = (uint8_t *)&_ebss;
46 for (;;) {
47 *s = 0;
48 s++;
49 if (s >= t) {
50 break;
51 }
52 }
53 }
54
55#else
56 for (;;) {
57 *t = *s;
58 t++;
59 s++;
60 if (t >= ((uint8_t *)&_edata)) {
61 break;
62 }
63 }
64
65 s = (uint8_t *)&_sbss;
66 t = (uint8_t *)&_ebss;
67 for (;;) {
68 *s = 0;
69 s++;
70 if (s >= t) {
71 break;
72 }
73 }
74
75#endif
76
77 MCULIBHANDLE = MCULIB_HANDLE;
78 get_userapp_vector();
79 return start(MCULIBHANDLE, api);
80}
int start(int MCULIBHANDLE, struct sc_firmware_api *api)
this is called when the board powers up
Definition: userhooks.c:31
these are the callbacks available. the firmware "api". provided to the app on startup
Definition: user_app_info.h:29
this must be implemented by the userapp, stored in flash at the beginning of the file (offset 0)
user application interface