Skip to content
This repository was archived by the owner on May 3, 2026. It is now read-only.

Commit 7518dbe

Browse files
committed
re-add system daemon
1 parent 3fd4a54 commit 7518dbe

3 files changed

Lines changed: 40 additions & 6 deletions

File tree

src/competition.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void initialize() {
5757

5858
// if the competition state changed, or the control task has been notified,
5959
// the competition task should be changed
60-
if (mode != prev_mode || pros::Task::notify_take(true, 0)) {
60+
if (mode != prev_mode) {
6161
prev_mode = mode;
6262

6363
switch (mode) {

src/system/startup.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void __libc_init_array();
3535
// only the first 16 bytes of this chunk is used however
3636
// see the vcodesig definition in the SDK for more details
3737
[[gnu::section(".boot_data")]]
38-
vcodesig vexCodeSig = {
38+
vcodesig boot_data = {
3939
.magic = V5_SIG_MAGIC,
4040
.type = V5_SIG_TYPE_USER,
4141
.owner = V5_SIG_OWNER_PARTNER,
@@ -72,15 +72,15 @@ void _start() {
7272
// call global constructors
7373
__libc_init_array();
7474

75-
// start main task
76-
// these pragmas are needed to silence the same warning on clang and gcc
77-
// normally you aren't supposed to reference the main function
75+
// start main task
76+
// these pragmas are needed to silence the same warning on clang and gcc
77+
// normally you aren't supposed to reference the main function
7878
#pragma GCC diagnostic push
7979
#pragma GCC diagnostic ignored "-Wpedantic"
8080
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
8181
#pragma clang diagnostic push
8282
#pragma clang diagnostic ignored "-Wmain"
83-
pros::Task task([]() {
83+
pros::Task main_task([]() {
8484
// run the main function
8585
main();
8686
// initialize the competition control task

src/system/system_daemon.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "kapi.h"
2+
#include "pros/devices/brain.hpp"
3+
#include "pros/rtos.hpp"
4+
5+
extern "C" {
6+
void vexTasksRun();
7+
void ser_output_flush();
8+
}
9+
10+
namespace zest {
11+
12+
// This task runs for the lifetime of the program.
13+
// It periodically calls vexTasksRun, which copies shared memory to/from vexOS.
14+
static pros::Task system_daemon([]() {
15+
while (true) {
16+
// lock all smart port mutexes
17+
Brain::smart_port_mutex_lock_all();
18+
// flush serial output
19+
ser_output_flush();
20+
// suspend all tasks
21+
rtos_suspend_all();
22+
// copy shared memory
23+
vexTasksRun();
24+
// resume all tasks
25+
rtos_resume_all();
26+
// unlock all smart port mutexes
27+
zest::Brain::smart_port_mutex_unlock_all();
28+
29+
// delay to save resources
30+
pros::delay(2);
31+
}
32+
}, TASK_PRIORITY_MAX);
33+
34+
} // namespace zest

0 commit comments

Comments
 (0)