demos_source/code_TestRemember.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 
00038 /* This this the only include needed in your code .*/
00039 #include "femtoos_code.h"
00040 
00041 
00042 /* This is called once at system boot, and before the creating of any of
00043  * the tasks. Use it to initialize the hardware. */
00044 void appBoot(void)
00045 { devLedDRR    |= 0xFF;
00046   devSwitchDRR &= 0x0F;
00047   devLedPORT |= 0xFF; }
00048 
00049 
00064 static void WorkerProcess(void) __attribute__((noreturn));
00065 
00066 static void WorkerProcess(void)
00067 { Tuint08 uiCount;
00068   Tuint08 uiFileOffset;
00069   Tuint08 uiLayer;
00070   Tuint08 uiSet;
00071   Tuint08 uiMemShift;
00072   Tuint08 uiInputA[8];
00073   Tuint08 uiInputB[8];
00074   Tuint08 uiOutput[8];
00075   while (true)
00076   { uiLayer = 0;
00077     uiMemShift = 0;
00078     do
00079     { taskWaitForEvent(1<<uiLayer);
00080       uiSet = 8 >> uiLayer;
00081       do
00082       { taskFileOpen(defReadWrite);
00083         uiFileOffset = taskFileReadByteOnName(LayerInfo,uiLayer);
00084         genTraceByteInfo(uiLayer);
00085         genTraceByteInfo(uiFileOffset);
00086         taskFileWriteByteOnName(LayerInfo,uiLayer,uiFileOffset+1);
00087         taskFileClose();
00088         if (uiFileOffset < uiSet)
00089         { taskFileOpen(defReadOnly);
00090           taskFileReadBuffer(2+uiMemShift+2*uiFileOffset,0,8,(Taddress) uiInputA);
00091           taskFileReadBuffer(3+uiMemShift+2*uiFileOffset,0,8,(Taddress) uiInputB);
00092           taskFileClose();
00093           for (uiCount=0; uiCount<8; uiCount++) { uiOutput[uiCount] = uiInputA[uiCount] ^ uiInputB[uiCount]; }
00094           taskFileOpen(defReadWrite);
00095           taskFileWriteBuffer(2+uiMemShift+2*uiSet+uiFileOffset,0,8,(Taddress) uiOutput);
00096           taskFileClose(); } }
00097       while (uiFileOffset < uiSet);
00098       uiMemShift += 2*uiSet;  }
00099     while (uiLayer++ < 3); } }
00100 
00101 
00102 
00103 /* We can define the number of workers in the configuration. By this construction
00104  * we let the main process know which workers are present to do work. All workers
00105  * make use of the reentrant function  WorkerProcess();
00106  */
00107 
00108 #if (preTaskDefined(Worker0Task))
00109   void appLoop_Worker0Task(void) { WorkerProcess(); }
00110   #define WP0 1
00111 #else
00112   #define WP0 0
00113 #endif
00114 
00115 
00116 #if (preTaskDefined(Worker1Task))
00117   void appLoop_Worker1Task(void) { WorkerProcess(); }
00118   #define WP1 1
00119 #else
00120   #define WP1 0
00121 #endif
00122 
00123 
00124 #if (preTaskDefined(Worker2Task))
00125   void appLoop_Worker2Task(void) { WorkerProcess(); }
00126   #define WP2 1
00127 #else
00128   #define WP2 0
00129 #endif
00130 
00131 #if (preTaskDefined(SleepTask))
00132 void appLoop_SleepTask(void) {}
00133 
00134 #endif
00135 
00136 
00137 #if (preTaskDefined(SupervisorTask))
00138 
00139 void appLoop_SupervisorTask(void)
00140 { taskFileOpen(defReadWrite);
00141   taskFileFormat();
00142   /* define files filled with zero's. */
00143   taskFileSetSizeOnName(LayerInfo,FileSpace_LayerInfo);
00144   taskFileSetSizeOnName(Status,FileSpace_Status);
00145   taskFileClose();
00146   Tuint08 uiStatus[4];
00147   taskDelayFromNow(10);
00148   while (true)
00149   { genTraceMarker();
00150     /* prepare the first stage, fill 16 files with 'random' values. */
00151     taskFileOpen(defReadWrite);
00152     taskFileReadBufferOnName(Status,defFromFileStart,4,(Taddress) uiStatus);
00153     Tuint16 uiSeed = ((Tuint16) uiStatus[2] << 8) + (Tuint16) uiStatus[3];
00154     Tuint16 uiValue = 0;
00155     Tuint08 uiFileCount;
00156     for (uiFileCount=0; uiFileCount<16; uiFileCount++)
00157     { taskFileClear(2+uiFileCount);
00158       Tuint08 uiByteCount;
00159       for (uiByteCount=0; uiByteCount<8; uiByteCount++)
00160       { Tuint08 uiStored = (Tuint08) uiSeed;
00161         uiValue ^= uiStored;
00162         devLedPORT = ~uiValue;
00163         taskFileAppendByte(2+uiFileCount,uiStored);
00164         uiSeed = (uiSeed * 9497U + 129U) >> 1; } }
00165     uiStatus[0] = uiStatus[0] + 1;
00166     uiStatus[1] = uiValue;
00167     uiStatus[2] = (Tuint08) (uiSeed>>8);
00168     uiStatus[3] = (Tuint08) (uiSeed & 0xFF);
00169     taskFileWriteBufferOnName(Status,defFromFileStart,4,(Taddress) uiStatus);
00170     taskFileClose();
00171     devLedPORT = ~uiValue;
00172     taskDelayFromNow(1000);
00173     devLedPORT = ~0x00;
00174     /* Set it loose! */
00175     Tuint08 uiLayer = 0;
00176 
00177     do
00178     { genTraceMarker();
00179       Tuint08 uiLayerInfo = 0;
00180       switch (uiLayer)
00181       { case 0: { genFireEvent(0); } break;
00182         case 1: { genFireEvent(1); } break;
00183         case 2: { genFireEvent(2); } break;
00184         case 3: { genFireEvent(3); } break;
00185         case 4: { genFireEvent(4); } break; }
00186       /* TODO: If we want to add a task for sleeping, the number below is no longer correct. */
00187       while ((genCountEventBlocks(1 << ((uiLayer+1)%4)) < (WP0+WP1+WP2-1)))
00188       { taskFileOpen(defReadOnly);
00189         uiLayerInfo = taskFileReadByteOnName(LayerInfo,uiLayer);
00190         taskFileClose();
00191         genTraceByteInfo(uiLayer);
00192         genTraceByteInfo(uiLayerInfo);
00193         devLedPORT = ~((uiLayer <<4) | uiLayerInfo);
00194         /* We must wait here so that the worker threads have some air to breath. */
00195         taskDelayFromNow(5);
00196         }
00197 
00198       taskDelayFromNow(100); }
00199     while(uiLayer++ < 3);
00200     Tuint08 uiInput[8];
00201     taskFileOpen(defReadOnly);
00202     taskFileReadBuffer(2+16+8+4+2,defFromFileStart,8,(Taddress) uiInput);
00203     taskFileClose();
00204     Tuint08 uiCount;
00205     taskFileOpen(defReadWrite);
00206     for (uiCount=0; uiCount<FileSpace_LayerInfo; uiCount++) { taskFileWriteByteOnName(LayerInfo,uiCount,0); }
00207     taskFileClose();
00208     Tuint08 uiCheckValue = 0;
00209     for (uiCount=0; uiCount<8; uiCount++) { uiCheckValue ^= uiInput[uiCount]; }
00210     if (uiCheckValue == uiStatus[1])
00211     { devLedPORT = ~uiCheckValue;
00212       taskDelayFromNow(5000); }
00213     else
00214     { while (true)
00215       { devLedPORT = uiCheckValue;
00216         taskDelayFromNow(300);
00217         devLedPORT = uiStatus[1];
00218         taskDelayFromNow(300); } } } }
00219 
00220 #endif
00221 

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