demos_source/code_TestRendezvous.c

Go to the documentation of this file.
00001 /*
00002  * Femto OS v 0.91 - Copyright (C) 2008-2009 Ruud Vlaming
00003  *
00004  * This file is part of the Femto OS distribution.
00005  *
00006  * This program is free software: you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation, version 3 of the License.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017  *
00018  * Please note that, due to the GPLv3 license, for application of this
00019  * work and/or combined work in embedded systems special obligations apply.
00020  * If these are not to you liking, please know the Femto OS is dual
00021  * licensed. A commercial license and support are available.
00022  * See http://www.femtoos.org/ for details.
00023  */
00024 
00025 
00038 /* This this the only include needed in your code .*/
00039 #include "femtoos_code.h"
00040 
00041 #define delay07   349U
00042 #define delay06   342U
00043 #define delay05   335U
00044 #define delay04   328U
00045 #define delay03   321U
00046 #define delay02   314U
00047 #define delay01   307U
00048 #define delay00   300U
00049 
00050 static Tbool bSync = false;
00051 
00052 /* This is called once at system boot, and before the creating of any of
00053  * the tasks. Use it to initialize the hardware. */
00054 void appBoot(void)
00055 { devLedDRR    = 0xFF;
00056   devLedPORT   = 0xFF;
00057   devSwitchDRR = 0x00; }
00058 
00059 /* Method to set the value of the led. Here you don't need access protection since the devLedPORT operations
00060  * are compiled to sbi/cbi instructions which atomic operations! Only if called with constants. */
00061 #define setLed(lednr,state)  if (state) { devLedPORT |= (1 << lednr); } else { devLedPORT &=  ~(1 << lednr); }
00062 
00063 
00064 /* All indentical tasks just blinking and when the bSync variable is activated, they wait
00065  * for each other. Note you must explicitly tell the wait method the number of tasks
00066  * that must be waited for. */
00067 
00068 #if (preTaskDefined(LEDtask0))
00069 
00070 void appLoop_LEDtask0(void)
00071 { Tuint08 led  = false;
00072   while (true)
00073   { led = !led;
00074     setLed(0,led);
00075     taskDelayFromNow(delay00);
00076     led = !led;
00077     setLed(0,led);
00078     taskDelayFromNow(delay00);
00079     if (bSync)
00080     { taskWaitForTasksOnName(TrefPunt,defNumberOfTasks-1);
00081       bSync = false; } } }
00082 
00083 
00084 #endif
00085 
00086 #if (preTaskDefined(LEDtask1))
00087 
00088 void appLoop_LEDtask1(void)
00089 { Tuint08 led  = false;
00090   while (true)
00091   { led = !led;
00092     setLed(1,led);
00093     taskDelayFromNow(delay01);
00094     led = !led;
00095     setLed(1,led);
00096     taskDelayFromNow(delay01);
00097     if (bSync)
00098     { taskWaitForTasksOnName(TrefPunt,defNumberOfTasks-1);
00099       bSync = false; } } }
00100 
00101 #endif
00102 
00103 #if (preTaskDefined(LEDtask2))
00104 
00105 void appLoop_LEDtask2(void)
00106 { Tuint08 led  = false;
00107   while (true)
00108   { led = !led;
00109     setLed(2,led);
00110     taskDelayFromNow(delay02);
00111     led = !led;
00112     setLed(2,led);
00113     taskDelayFromNow(delay02);
00114     if (bSync)
00115     { taskWaitForTasksOnName(TrefPunt,defNumberOfTasks-1);
00116       bSync = false; } } }
00117 
00118 #endif
00119 
00120 #if (preTaskDefined(LEDtask3))
00121 
00122 void appLoop_LEDtask3(void)
00123 { Tuint08 led  = false;
00124   while (true)
00125   { led = !led;
00126     setLed(3,led);
00127     taskDelayFromNow(delay03);
00128     led = !led;
00129     setLed(3,led);
00130     taskDelayFromNow(delay03);
00131     if (bSync)
00132     { taskWaitForTasksOnName(TrefPunt,defNumberOfTasks-1);
00133       bSync = false; } } }
00134 
00135 #endif
00136 
00137 #if (preTaskDefined(LEDtask4))
00138 
00139 void appLoop_LEDtask4(void)
00140 { Tuint08 led  = false;
00141   while (true)
00142   { led = !led;
00143     setLed(4,led);
00144     taskDelayFromNow(delay04);
00145     led = !led;
00146     setLed(4,led);
00147     taskDelayFromNow(delay04);
00148     if (bSync)
00149     { taskWaitForTasksOnName(TrefPunt,defNumberOfTasks-1);
00150       bSync = false; } } }
00151 
00152 #endif
00153 
00154 #if (preTaskDefined(LEDtask5))
00155 
00156 void appLoop_LEDtask5(void)
00157 { Tuint08 led  = false;
00158   while (true)
00159   { led = !led;
00160     setLed(5,led);
00161     taskDelayFromNow(delay05);
00162     led = !led;
00163     setLed(5,led);
00164     taskDelayFromNow(delay05);
00165     if (bSync)
00166     { taskWaitForTasksOnName(TrefPunt,defNumberOfTasks-1);
00167       bSync = false; } } }
00168 
00169 #endif
00170 
00171 #if (preTaskDefined(LEDtask6))
00172 
00173 void appLoop_LEDtask6(void)
00174 { Tuint08 led  = false;
00175   while (true)
00176   { led = !led;
00177     setLed(6,led);
00178     taskDelayFromNow(delay06);
00179     led = !led;
00180     setLed(6,led);
00181     taskDelayFromNow(delay06);
00182     if (bSync)
00183     { taskWaitForTasksOnName(TrefPunt,defNumberOfTasks-1);
00184       bSync = false; } } }
00185 
00186 #endif
00187 
00188 #if (preTaskDefined(LEDtask7))
00189 
00190 void appLoop_LEDtask7(void)
00191 { Tuint08 led  = false;
00192   while (true)
00193   { led = !led;
00194     setLed(7,led);
00195     taskDelayFromNow(delay07);
00196     led = !led;
00197     setLed(7,led);
00198     taskDelayFromNow(delay07);
00199     if (bSync)
00200     { taskWaitForTasksOnName(TrefPunt,defNumberOfTasks-1);
00201       bSync = false; } } }
00202 
00203 #endif
00204 
00205 
00206 /* This is the task which waits for the synchronizer button to be pushed. If
00207  * so, the bSync will be set and all tasks will start waiting. */
00208 
00209 #if (preTaskDefined(Synchronize))
00210 
00211 void appLoop_Synchronize(void)
00212 { Tuint08 button  = devSwitchPIN & 01;
00213   Tuint08 lastbutton  = button;
00214   while (true)
00215   { button = devSwitchPIN & 01;
00216     if (button != lastbutton) { bSync = true; }
00217     taskDelayFromNow(100); } }
00218 
00219 #endif
00220 

Generated on Fri Oct 16 00:05:21 2009 for FemtoOS by  doxygen 1.5.2