00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00038
00039 #include "femtoos_code.h"
00040
00041
00042
00043
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
00104
00105
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
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
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
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
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
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