TRC Library for FTC (2011) 2011
TRC Library Code Project

C:/Users/Michael/Ftc/2011/code/trclib/task.h

Go to the documentation of this file.
00001 #if 0
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 #endif
00015 
00016 #ifndef _TASK_H
00017 #define _TASK_H
00018 
00019 #pragma systemFile
00020 
00021 #ifdef MOD_ID
00022     #undef MOD_ID
00023 #endif
00024 #define MOD_ID                  MOD_TASK
00025 
00026 #ifndef MAX_NUM_TASKS
00027     #define MAX_NUM_TASKS       8
00028 #endif
00029 
00030 //
00031 // Macros.
00032 //
00033 #define TaskRegisterHiFreq(m)   (g_HiFreqTasks |= (m))
00034 #define TaskRegisterInput(m)    (g_InputTasks |= (m))
00035 #define TaskRegisterOutput(m)   (g_OutputTask |= (m))
00036 
00037 //
00038 // Type definitions.
00039 //
00040 typedef struct
00041 {
00042     long  module;
00043     void &context;
00044 } ROBOTTASK;
00045 
00046 typedef struct
00047 {
00048     ROBOTTASK hifreqTasks[MAX_NUM_TASKS];
00049     ROBOTTASK inputTasks[MAX_NUM_TASKS];
00050     ROBOTTASK outputTask[MAX_NUM_TASKS];
00051     int numHiFreqTasks;
00052     int numInputTasks;
00053     int numOutputTasks;
00054 } TASKS;
00055 
00056 //
00057 // Global data..
00058 //
00059 TASKS g_RobotTasks;
00060 
00064 void
00065 TaskInit()
00066 {
00067     int i;
00068 
00069     TFuncName("TaskInit");
00070     TLevel(INIT);
00071     TEnter();
00072 
00073     for (i = 0; i < MAX_NUM_TASKS; i++)
00074     {
00075         g_RobotTasks.hifreqTasks[i].module = 0;
00076         g_RobotTasks.hifreqTasks[i].context = 0;
00077         g_RobotTasks.inputTasks[i].module = 0;
00078         g_RobotTasks.inputTasks[i].context = 0;
00079         g_RobotTasks.outputTasks[i].module = 0;
00080         g_RobotTasks.outputTasks[i].context = 0;
00081     }
00082     g_RobotTasks.numHiFreqTasks = 0;
00083     g_RobotTasks.numInputTasks = 0;
00084     g_RobotTasks.numOutputTasks = 0;
00085 
00086     TExit();
00087     return;
00088 }   //TaskInit
00089 
00098 bool
00099 TaskRegHiFreq(
00100     __in long module,
00101     __in void &context
00102     )
00103 {
00104     bool fSuccess = false;
00105 
00106     TFuncName("TaskRegHiFreq");
00107     TEnter();
00108 
00109     if (g_RobotTasks.numHiFreqTasks < MAX_NUM_TASKS)
00110     {
00111         g_RobotTasks.hifreqTasks[g_RobotTasks.numHiFreqTasks].module = module;
00112         g_RobotTasks.hifreqTasks[g_RobotTasks.numHiFreqTasks].context = context;
00113         g_RobotTasks.numHiFreqTasks++;
00114         fSuccess = true;
00115     }
00116 
00117     TExit();
00118     return fSuccess;
00119 }   //TaskRegHiFreq
00120 
00129 bool
00130 TaskRegInput(
00131     __in long module,
00132     __in void &context
00133     )
00134 {
00135     bool fSuccess = false;
00136 
00137     TFuncName("TaskRegInput");
00138     TEnter();
00139 
00140     if (g_RobotTasks.numInputTasks < MAX_NUM_TASKS)
00141     {
00142         g_RobotTasks.inputTasks[g_RobotTasks.numInputTasks].module = module;
00143         g_RobotTasks.inputTasks[g_RobotTasks.numInputTasks].context = context;
00144         g_RobotTasks.numInputTasks++;
00145         fSuccess = true;
00146     }
00147 
00148     TExit();
00149     return fSuccess;
00150 }   //TaskRegInput
00151 
00160 bool
00161 TaskRegOutput(
00162     __in long module,
00163     __in void &context
00164     )
00165 {
00166     bool fSuccess = false;
00167 
00168     TFuncName("TaskRegOutput");
00169     TEnter();
00170 
00171     if (g_RobotTasks.numOutputTasks < MAX_NUM_TASKS)
00172     {
00173         g_RobotTasks.outputTasks[g_RobotTasks.numOutputTasks].module = module;
00174         g_RobotTasks.outputTasks[g_RobotTasks.numOutputTasks].context = context;
00175         g_RobotTasks.numOutputTasks++;
00176         fSuccess = true;
00177     }
00178 
00179     TExit();
00180     return fSuccess;
00181 }   //TaskRegOutput
00182 
00190 void
00191 TaskProcessHiFreq()
00192 {
00193     TFuncName("TaskProcessHiFreq");
00194     TLevel(TASK);
00195     TEnter();
00196 
00197 #ifdef _GYRO_H
00198     if (g_HiFreqTasks & MOD_GYRO)
00199     {
00200         
00201     }
00202 #endif
00203 
00204     TExit();
00205     return;
00206 }   //TaskProcessHiFreq
00207 
00214 void
00215 NxtBtnTask(
00216     __inout NXTBTN &nxtbtn
00217     )
00218 {
00219     int currBtn = nNxtButtonPressed;
00220     bool fPressed;
00221 
00222     TFuncName("NxtBtnTask");
00223     TLevel(TASK);
00224     TEnterMsg(("Prev=%x,Curr=%x", nxtbtn.prevBtn, currBtn));
00225 
00226     if (currBtn != nxtbtn.prevBtn)
00227     {
00228         if (currBtn == kNoButton)
00229         {
00230             currBtn = nxtbtn.prevBtn;
00231             fPressed = false;
00232         }
00233         else
00234         {
00235             fPressed = true;
00236         }
00237 
00238         if (nxtbtn.nxtBtnFlags & NXTBTNF_ENABLE_EVENTS)
00239         {
00240             NxtBtnEvent(nxtbtn, currBtn, fPressed);
00241         }
00242 
00243         nxtbtn.prevBtn = currBtn;
00244     }
00245 
00246     TExit();
00247     return;
00248 }   //NxtBtnTask
00249 
00250 #endif  //ifndef _TASK_H
 All Data Structures Files Functions Variables Defines