1313 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
1414 */
1515
16+ #include " pros/rtos.hpp"
1617#include " v5_api_patched.h"
1718
1819#include < cstdint>
2122#include < sys/unistd.h>
2223
2324extern " C" {
24-
2525// Initialization routines provided elsewhere
2626void rtos_initialize ();
2727void vfs_initialize ();
28-
29- [[gnu::weak]]
30- void display_initialize () {}
31-
3228void rtos_sched_start ();
33-
34- // libc initialization
3529void __libc_init_array ();
36-
37- // tick vex tasks
38- void vexTasksRun ();
39- } // extern "C"
40-
41- void system_daemon_initialize ();
30+ }
4231
4332// this goes in the first 32-byte chunk of the user program
4433// which is why the entrypoint is offset from 0x3800000 by 0x20
4534// only the first 16 bytes of this chunk is used however
4635// see the vcodesig definition in the SDK for more details
4736[[gnu::section(".boot_data")]]
48- vcodesig vexCodeSig = {V5_SIG_MAGIC , V5_SIG_TYPE_USER , V5_SIG_OWNER_PARTNER , V5_SIG_OPTIONS_NONE };
37+ vcodesig vexCodeSig = {
38+ .magic = V5_SIG_MAGIC ,
39+ .type = V5_SIG_TYPE_USER ,
40+ .owner = V5_SIG_OWNER_PARTNER ,
41+ .options = V5_SIG_OPTIONS_NONE ,
42+ };
4943
5044// The pros_init function is executed early (via constructor attribute)
51- // before most global C++ constructors are run.
52- [[gnu::constructor(102)]]
45+ [[gnu::constructor(101)]]
5346static void pros_init () {
5447 rtos_initialize ();
5548 vfs_initialize ();
56- display_initialize ();
57- // Note: system_daemon_initialize must be called last, per design requirements.
58- system_daemon_initialize ();
5949}
6050
61- // the main function, starts the scheduler and ensures the program exits gracefully if it fails
62- int main () {
63- // Start freeRTOS
64- rtos_sched_start ();
51+ // forward-declare main function
52+ int main ();
6553
66- // If execution reaches here, the scheduler has failed.
67- vexDisplayPrintf (10 , 60 , 1 , " failed to start scheduler\n " );
68- std::printf (" Failed to start Scheduler\n " );
69- _exit (0 ); // exit with code 0 to stop spinlock
70- }
71-
72- // program entrypoint. This is the first function that is run
73- // it sets up memory, calls constructors, and then calls main
54+ // Program entrypoint. This is the first function that is run.
55+ // It sets up memory, calls constructors, and starts the scheduler
7456extern " C" [[gnu::section(".boot")]]
7557void _start () {
7658 // Symbols provided by the linker script
@@ -89,15 +71,23 @@ void _start() {
8971 // call global constructors
9072 __libc_init_array ();
9173
92- // call the main function
93- // This GCC warning is a nuisance.
94- // This is the industry standard
74+ // start main task
75+ // these pragmas are needed to silence the same warning on clang and gcc
76+ // normally you aren't supposed to reference the main function
9577#pragma GCC diagnostic push
9678#pragma GCC diagnostic ignored "-Wpedantic"
9779#pragma GCC diagnostic ignored "-Wunknown-pragmas"
9880#pragma clang diagnostic push
9981#pragma clang diagnostic ignored "-Wmain"
100- main ( );
82+ pros::Task task (main );
10183#pragma clang diagnostic pop
10284#pragma GCC diagnostic pop
85+
86+ // start the scheduler
87+ rtos_sched_start ();
88+
89+ // If execution reaches here, the scheduler has failed.
90+ vexDisplayPrintf (10 , 60 , 1 , " failed to start scheduler\n " );
91+ std::printf (" Failed to start Scheduler\n " );
92+ _exit (0 ); // exit with code 0 to stop spinlock
10393}
0 commit comments