demos_source/code_TestFlashLeds.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 
00035 /* This this the only include needed in your code .*/
00036 #include "femtoos_code.h"
00037 
00038 
00039 /* Below we define the times each task has to pause.
00040  *
00041  * If you make use of debugging in the AVR studio, is is handy that you do not
00042  * have to wait for ever for a new task to become active. I haven't used debugging
00043  * in ages anymore, but it still may be handy.*/
00044 #if cfgSysDebug == cfgTrue
00045   #define delay07   9U
00046   #define delay06   9U
00047   #define delay05   8U
00048   #define delay04   7U
00049   #define delay03   6U
00050   #define delay02   5U
00051   #define delay01   4U
00052   #define delay00   3U
00053 #else
00054   #define delay07 25000U
00055   #define delay06 13661U
00056   #define delay05  7465U
00057   #define delay04  4079U
00058   #define delay03  2229U
00059   #define delay02  1218U
00060   #define delay01   666U
00061   #define delay00   364U
00062 #endif
00063 
00064 
00065 /* This is called once at system boot, and before the creating of any of
00066  * the tasks. Use it to initialize the hardware. */
00067 void appBoot(void)
00068 { devLedDRR  |= 0xFF;
00069   devLedPORT |= 0x00;
00070   }
00071 
00072 
00073 /* Here you don't need protection since the devLedPORT operations are sbi/cbi which are atomic operations,
00074  * but only if the method is calls with constants. */
00075 #define setLed(lednr,state)  if (state) { devLedPORT |= (1 << lednr); } else { devLedPORT &=  ~(1 << lednr); }
00076 /* Most easy way to toggle a led is of course via the pins */
00077 #define ledInv(lednr)       do  { devLedPIN |= (1 << lednr); } while(0)
00078 
00079 
00080 /* Below all blinker tasks are defined. Note the preprocessor check for presence of the task.
00081  * The point is, you may want to exclude certain tasks from the system in the configuration
00082  * file, and this construction makes sure it is excluded from the executable as well. */
00083 
00084 #if (preTaskDefined(LEDtask0))
00085 
00086 void appLoop_LEDtask0(void)
00087 {
00088   #if (demoUseShared == cfgTrue)
00089     ledInv(0);
00090     taskRestart(defRestartRunning,delay00);
00091   #else
00092     while (true)
00093     { setLed(0,true);
00094       taskDelayFromNow(delay00);
00095       setLed(0,false);
00096       taskDelayFromNow(delay00); }
00097   #endif
00098 }
00099 
00100 #endif
00101 
00102 
00103 #if (preTaskDefined(LEDtask1))
00104 
00105 void appLoop_LEDtask1(void)
00106 {
00107   #if (demoUseShared == cfgTrue)
00108     ledInv(1);
00109     taskRestart(defRestartRunning,delay01);
00110   #else
00111     while (true)
00112     { setLed(1,true);
00113       taskDelayFromNow(delay01);
00114       setLed(1,false);
00115       taskDelayFromNow(delay01); }
00116   #endif
00117 }
00118 
00119 #endif
00120 
00121 
00122 #if (preTaskDefined(LEDtask2))
00123 
00124 void appLoop_LEDtask2(void)
00125 {
00126   #if (demoUseShared == cfgTrue)
00127     ledInv(2);
00128     taskRestart(defRestartRunning,delay02);
00129   #else
00130     while (true)
00131     { setLed(2,true);
00132       taskDelayFromNow(delay02);
00133       setLed(2,false);
00134       taskDelayFromNow(delay02); }
00135   #endif
00136 }
00137 
00138 #endif
00139 
00140 
00141 #if (preTaskDefined(LEDtask3))
00142 
00143 void appLoop_LEDtask3(void)
00144 {
00145   #if (demoUseShared == cfgTrue)
00146     ledInv(3);
00147     taskRestart(defRestartRunning,delay03);
00148   #else
00149     while (true)
00150     { setLed(3,true);
00151       taskDelayFromNow(delay03);
00152       setLed(3,false);
00153       taskDelayFromNow(delay03); }
00154   #endif
00155 }
00156 
00157 #endif
00158 
00159 
00160 #if (preTaskDefined(LEDtask4))
00161 
00162 void appLoop_LEDtask4(void)
00163 {
00164   #if (demoUseShared == cfgTrue)
00165     ledInv(4);
00166     taskRestart(defRestartRunning,delay04);
00167   #else
00168     while (true)
00169     { setLed(4,true);
00170       taskDelayFromNow(delay04);
00171       setLed(4,false);
00172       taskDelayFromNow(delay04); }
00173   #endif
00174 
00175 }
00176 
00177 #endif
00178 
00179 
00180 #if (preTaskDefined(LEDtask5))
00181 
00182 void appLoop_LEDtask5(void)
00183 {
00184   #if (demoUseShared == cfgTrue)
00185     ledInv(5);
00186     taskRestart(defRestartRunning,delay05);
00187   #else
00188     while (true)
00189     { setLed(5,true);
00190       taskDelayFromNow(delay05);
00191       setLed(5,false);
00192       taskDelayFromNow(delay05); }
00193   #endif
00194 
00195 }
00196 
00197 #endif
00198 
00199 
00200 #if (preTaskDefined(LEDtask6))
00201 
00202 void appLoop_LEDtask6(void)
00203 {
00204   #if (demoUseShared == cfgTrue)
00205     ledInv(6);
00206     taskRestart(defRestartRunning,delay06);
00207   #else
00208     while (true)
00209     { setLed(6,true);
00210       taskDelayFromNow(delay06);
00211       setLed(6,false);
00212       taskDelayFromNow(delay06); }
00213   #endif
00214 
00215 }
00216 
00217 #endif
00218 
00219 
00220 #if (preTaskDefined(LEDtask7))
00221 
00222 void appLoop_LEDtask7(void)
00223 {
00224   #if (demoUseShared == cfgTrue)
00225     ledInv(7);
00226     taskRestart(defRestartRunning,delay07);
00227   #else
00228     while (true)
00229     { setLed(7,true);
00230       taskDelayFromNow(delay07);
00231       setLed(7,false);
00232       taskDelayFromNow(delay07); }
00233   #endif
00234 
00235 }
00236 
00237 #endif
00238 
00239 

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