| Up to 19 additional tasks can execute concurrently with task main within a VEX Cortex user program (and up to 4 additional tasks within a VEX PIC user program). The ‘main’ or ‘primary’ task is automatically started when a user program is run. Execution of other tasks can be started and stopped with the StartTask and StopTask functions. The VEX will share CPU execution time among various tasks by giving each task a “time slice” where it will execute a group of instructions.
Each task can be assigned a priority from 0 to 255. The VEX scheduler gives execution time to the highest priority task that is waiting to run. A round robin scheduling scheme is used when there are multiple tasks ready to run all with the highest priority. Lower priority tasks will not execute until there are no tasks of higher priority that are ready to run.
A task that is waiting for a time period to expire is not ready to run. Once the time period has expired it will again become ready to run. Waiting tasks do not consume any CPU cycles.
|
abortTimeslice
| void abortTimeslice()
|
| (void) Immediately ends the current task time slice and allows another task to be immediately scheduled and executed. Tasks are given CPU execution time so that highest priority tasks get all the CPU time. If there are multiple tasks with the same highest priority then they are given "slices" of CPU time in a round robin fashion. This function will immediately end the current timeslice.
|
abortTimeslice(); // aborts the current time slice of the task
|
|
hogCPU
| void hogCPU()
|
| (void) This special function is used to temporarily suspend the normal task scheduler and give all the CPU time to the current task. As long as this task can run, then it will get all of the CPU time until a releaseCPU() function call is made. You can execute the hogCPU() command inside of task main to hog the CPU away from ROBOTC's background driver task.
|
hogCPU(); // suspend every other task and focus 100% on the current task
|
|
kDefaultTaskPriority
| const int kDefaultTaskPriority = 7
|
| (int) Constant. The default priority assigned to a task. Equivalent to setting a priority of 7.
|
int myPriority = 0; // creates a variable to hold the task priority value
myPriority = kDefaultTaskPriority; // sets 'myPriority' to 7 (default)
|
|
kLowPriority
| const int kLowPriority = 0
|
| (int) Constant. Lowest priority that can be assigned to a task. Equivalent to setting a priority of 0.
|
int myPriority = 0; // creates a variable to hold the task priority value
nSchedulePriority = kLowPriority; // assigns the Priority of the Task to the Lowest Priority
myPriority = nSchedulePriority; // sets the current priority to a variable to view in the debugger
|
|
kHighPriority
| const int kLowPriority = 255
|
| (int) Constant. Highest priority that can be assigned to a task. Equivalent to setting a priority of 255.
|
int myPriority = 0; // creates a variable to hold the task priority value
nSchedulePriority = kHighPriority; // assigns the Priority of the Task to the Highest Priority
myPriority = nSchedulePriority; // sets the current priority to a variable to view in the debugger
|
|
nSchedulePriority
| word nSchedulePriority
|
| (word) The CPU scheduler priority for the current task. ROBOTC shares CPU execution time among various tasks by giving each task a “time slice” where it will execute a group of instructions. Each task can be assigned a priority from 0 to 255. The scheduler gives execution time to the highest priority task that is waiting to run. A round robin scheduling scheme is used when there are multiple tasks ready to run all with the highest priority. Lower priority tasks will not execute until there are no tasks of higher priority that are ready to run. By default, tasks are assigned a priority value of "7".
|
nSchedulePriority = 100; // assigns the current task with a priority of 100
|
|
releaseCPU
| void releaseCPU()
|
| (void) This special function is used to resume the normal task schedule. It cancels the effect of a previous releaseCPU() function call.
|
releaseCPU(); // resume other tasks and return control to the task scheduler
|
|
StartTask
| void StartTask(void TaskID, const short nTaskPriority)
|
| (void) A functional call to start or restart the execution of a specific task. The nPriority command is optional, and can be used to assign a priority to a task at the time the task is told to start executing. If the nPriority command is not specified, the task will start with a default priority of "7".
|
| Parameter
|
Explanation
|
Data Type
|
| TaskID
|
The ID of the task to start.
|
void
|
| nTaskPriority
|
The priority to start the task with (optional).
|
short
|
|
StartTask(MoveArm, 10); // starts the task named "MoveArm" with a priorty of 10
|
|
StopAllTasks
| void StopAllTasks()
|
| (void) A function call to stop every task running, including the main program task.
|
StopAllTasks(); // stops all tasks currently running and exits the current program
|
|
StopTask
| void StopTask(void TaskID)
|
| (void) A functional call to start or restart the execution of a specific task. The nPriority command is optional, and can be used to assign a priority to a task at the time the task is told to start executing. If the nPriority command is not specified, the task will start with a default priority of "7".
|
| Parameter
|
Explanation
|
Data Type
|
| TaskID
|
The ID of the task to stop.
|
void
|
|
StopTask(MoveArm); // stops the task named "MoveArm"
|
|