1212 */
1313
1414#include " kapi.h"
15+ #include " pros/devices/port.hpp"
1516#include " system/optimizers.h"
1617#include " system/user_functions.h" // IWYU pragma: keep
1718
18- extern void vdml_background_processing ();
19+ extern " C" {
20+ void vexTasksRun ();
21+ void ser_output_flush ();
22+ }
23+
24+ void port_mutex_take_all () {
25+ for (int i = 0 ; i < zest::SmartPort::MAX_SMART_PORTS; i++) {
26+ zest::SmartPort::from_index (i).get_mutex ().take ();
27+ }
28+ }
29+
30+ void port_mutex_give_all () {
31+ for (int i = 0 ; i < zest::SmartPort::MAX_SMART_PORTS; i++) {
32+ zest::SmartPort::from_index (i).get_mutex ().give ();
33+ }
34+ }
1935
20- extern void port_mutex_take_all ();
21- extern void port_mutex_give_all ();
36+ static void _disabled_task (void *);
37+ static void _autonomous_task (void *);
38+ static void _opcontrol_task (void *);
39+ static void _competition_initialize_task (void *);
40+ static void _initialize_task (void *);
41+ static void _system_daemon_task (void *);
2242
2343static task_stack_t competition_task_stack[TASK_STACK_DEPTH_DEFAULT];
2444static static_task_s_t competition_task_buffer;
25- static task_t competition_task ;
45+ static pros:: task_t competition_task;
2646
2747static task_stack_t system_daemon_task_stack[TASK_STACK_DEPTH_DEFAULT];
2848static static_task_s_t system_daemon_task_buffer;
29- static task_t system_daemon_task ;
30-
31- static void _disabled_task (void * ign );
32- static void _autonomous_task (void * ign );
33- static void _opcontrol_task (void * ign );
34- static void _competition_initialize_task (void * ign );
35-
36- static void _initialize_task (void * ign );
37- static void _system_daemon_task (void * ign );
49+ static pros::task_t system_daemon_task;
3850
3951enum state_task {
4052 E_OPCONTROL_TASK = 0 ,
@@ -43,18 +55,15 @@ enum state_task {
4355 E_COMP_INIT_TASK
4456};
4557
46- char task_names [4 ][32 ] = {
58+ static const char task_names[4 ][32 ] = {
4759 " User Operator Control (PROS)" ,
4860 " User Autonomous (PROS)" ,
4961 " User Disabled (PROS)" ,
5062 " User Comp. Init. (PROS)"
5163};
52- task_fn_t task_fns [4 ] =
53- {_opcontrol_task , _autonomous_task , _disabled_task , _competition_initialize_task };
5464
55- extern void ser_output_flush (void );
56-
57- void vexTasksRun ();
65+ static task_fn_t task_fns[4 ] =
66+ {_opcontrol_task, _autonomous_task, _disabled_task, _competition_initialize_task};
5867
5968// does the basic background operations that need to occur every 2ms
6069static inline void do_background_operations () {
@@ -63,12 +72,11 @@ static inline void do_background_operations() {
6372 rtos_suspend_all ();
6473 vexTasksRun ();
6574 rtos_resume_all ();
66- vdml_background_processing ();
6775 port_mutex_give_all ();
6876}
6977
70- static void _system_daemon_task (void * ign ) {
71- uint32_t time = millis ();
78+ static void _system_daemon_task (void *) {
79+ uint32_t time = pros:: millis ();
7280 // Initialize status to an invalid state to force an update the first loop
7381 uint32_t status = (uint32_t )(1 << 8 );
7482 uint32_t task_state;
@@ -78,7 +86,7 @@ static void _system_daemon_task(void* ign) {
7886 // Take all port mutexes to prevent user code from attempting to access VDML during this time.
7987 // User code could be running if a task is created from a global ctor
8088 port_mutex_take_all ();
81- task_delay (2 );
89+ pros::c:: task_delay (2 );
8290 port_mutex_give_all ();
8391
8492 // start up user initialize task. once the user initialize function completes,
@@ -94,18 +102,18 @@ static void _system_daemon_task(void* ign) {
94102 &competition_task_buffer
95103 );
96104
97- time = millis ();
98- while (!task_notify_take (true, 2 )) {
105+ time = pros:: millis ();
106+ while (!pros::c:: task_notify_take (true , 2 )) {
99107 // wait for initialize to finish
100108 do_background_operations ();
101109 }
102110 while (1 ) {
103111 do_background_operations ();
104112
105- if (unlikely (status != competition_get_status ())) {
113+ if (unlikely (status != pros::c:: competition_get_status ())) {
106114 // Have a new competition status, need to clean up whatever's running
107115 uint32_t old_status = status;
108- status = competition_get_status ();
116+ status = pros::c:: competition_get_status ();
109117 enum state_task state = E_OPCONTROL_TASK;
110118 if ((status & COMPETITION_DISABLED) && (old_status & COMPETITION_DISABLED)) {
111119 // Don't restart the disabled task even if other bits have changed (e.g. auton bit)
@@ -124,13 +132,13 @@ static void _system_daemon_task(void* ign) {
124132 state = E_AUTON_TASK;
125133 }
126134
127- task_state = task_get_state (competition_task );
135+ task_state = pros::c:: task_get_state (competition_task);
128136 // delete the task only if it's in normal operation (e.g. not deleted)
129137 // The valid task states AREN'T deleted, invalid, or running (running
130138 // means it's the current task, which will never be the case)
131- if (task_state == E_TASK_STATE_READY || task_state == E_TASK_STATE_BLOCKED
132- || task_state == E_TASK_STATE_SUSPENDED ) {
133- task_delete (competition_task );
139+ if (task_state == pros:: E_TASK_STATE_READY || task_state == pros:: E_TASK_STATE_BLOCKED
140+ || task_state == pros:: E_TASK_STATE_SUSPENDED) {
141+ pros::c:: task_delete (competition_task);
134142 }
135143
136144 competition_task = task_create_static (
@@ -144,7 +152,7 @@ static void _system_daemon_task(void* ign) {
144152 );
145153 }
146154
147- task_delay_until (& time , 2 );
155+ pros::c:: task_delay_until (&time, 2 );
148156 }
149157}
150158
@@ -165,7 +173,7 @@ void system_daemon_initialize() {
165173#define FUNC (NAME ) \
166174 static void _##NAME##_task(void * ign) { \
167175 user_##NAME (); \
168- task_notify(system_daemon_task); \
176+ pros::c:: task_notify (system_daemon_task); \
169177 }
170178#include " system/user_functions/c_list.h"
171179#undef FUNC
0 commit comments