@@ -22,6 +22,7 @@ struct alignas(4) TestConfig
22
22
struct alignas (4 ) SpeedResult
23
23
{
24
24
int32_t romTime = 0 ;
25
+ uint32_t bytesPerRomTest = 0 ;
25
26
int32_t readTime = 0 ;
26
27
int32_t writeTime = 0 ;
27
28
int32_t setTime = 0 ;
@@ -30,26 +31,33 @@ struct alignas(4) SpeedResult
30
31
int32_t copyFromTime = 0 ;
31
32
int32_t copyToDMATime = 0 ;
32
33
int32_t copyFromDMATime = 0 ;
33
- uint32_t bytesPerTest = 0 ;
34
+ uint32_t bytesPerRamTest = 0 ;
34
35
};
35
36
36
37
// define all functions here, so we can put them into IWRAM
38
+ #define NOINLINE __attribute__ ((noinline))
39
+
37
40
void printSpeed(int32_t time, uint32_t bytes, uint16_t x, uint16_t y, TUI::Color backColor, TUI::Color textColor) IWRAM_CODE;
38
41
template <typename F>
39
42
void runBlockwise (F func, const TestConfig &config) IWRAM_CODE;
40
- void readBlock (void *source, uint32_t value, uint32_t nrOfWords) IWRAM_CODE;
43
+ void readBlock (const void *source, uint32_t value, uint32_t nrOfWords) IWRAM_CODE;
41
44
void writeBlock (void *destination, uint32_t value, uint32_t nrOfWords) IWRAM_CODE;
42
45
template <typename F>
43
46
int32_t runFunctionBlockwise (F func, const TestConfig &config, uint32_t nrOfCycles) IWRAM_CODE;
44
47
template <typename F>
45
- int32_t runFunction (F func, const TestConfig &config, uint32_t nrOfCycles) IWRAM_CODE;
48
+ int32_t runFunctionOnSrc (F func, const TestConfig &config, uint32_t nrOfCycles) IWRAM_CODE;
49
+ template <typename F>
50
+ int32_t runFunctionOnDest (F func, const TestConfig &config, uint32_t nrOfCycles) IWRAM_CODE;
46
51
SpeedResult runSpeedTest (const TestConfig &config, uint32_t nrOfCycles) IWRAM_CODE;
47
52
uint32_t testPattern (uint32_t index) IWRAM_CODE;
48
53
uint32_t runErrorTest (const TestConfig &config, uint32_t nrOfCycles, uint32_t pattern) IWRAM_CODE;
49
- int32_t getTime () IWRAM_CODE;
50
- void updateTime () IWRAM_CODE;
54
+ int32_t getTime () NOINLINE IWRAM_CODE;
55
+ void updateTime () NOINLINE IWRAM_CODE;
51
56
void updateBlinkState () IWRAM_CODE;
52
57
void updateInput () IWRAM_CODE;
58
+ void printTestState () IWRAM_CODE;
59
+ void printRamTimings () IWRAM_CODE;
60
+ void printRomWaitStates () IWRAM_CODE;
53
61
int main () IWRAM_CODE;
54
62
55
63
// ------------------------------------------------------------------------------------------------
@@ -85,7 +93,7 @@ void runBlockwise(F func, const TestConfig &config)
85
93
}
86
94
}
87
95
88
- void readBlock (void *source, uint32_t value, uint32_t nrOfWords)
96
+ void readBlock (const void *source, uint32_t value, uint32_t nrOfWords)
89
97
{
90
98
uint32_t v = value;
91
99
auto src32 = reinterpret_cast <const uint32_t *>(source);
@@ -121,7 +129,18 @@ int32_t runFunctionBlockwise(F func, const TestConfig &config, uint32_t nrOfCycl
121
129
}
122
130
123
131
template <typename F>
124
- int32_t runFunction (F func, const TestConfig &config, uint32_t nrOfCycles)
132
+ int32_t runFunctionOnSrc (F func, const TestConfig &config, uint32_t nrOfCycles)
133
+ {
134
+ auto startTime = getTime ();
135
+ for (uint32_t cycle = 0 ; cycle < nrOfCycles; cycle++)
136
+ {
137
+ func (config.src , 0x12345678 , config.srcSize >> 2 );
138
+ }
139
+ return getTime () - startTime;
140
+ }
141
+
142
+ template <typename F>
143
+ int32_t runFunctionOnDest (F func, const TestConfig &config, uint32_t nrOfCycles)
125
144
{
126
145
auto startTime = getTime ();
127
146
for (uint32_t cycle = 0 ; cycle < nrOfCycles; cycle++)
@@ -133,16 +152,16 @@ int32_t runFunction(F func, const TestConfig &config, uint32_t nrOfCycles)
133
152
134
153
SpeedResult runSpeedTest (const TestConfig &config, uint32_t nrOfCycles)
135
154
{
136
- SpeedResult result = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , config.destSize * nrOfCycles};
155
+ SpeedResult result = {0 , ROM_DATA_SIZE * 4 * nrOfCycles, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , config.destSize * nrOfCycles};
137
156
auto rom = config;
138
157
rom.src = reinterpret_cast <const uint8_t *>(ROM_DATA);
139
158
rom.srcSize = ROM_DATA_SIZE * 4 ;
140
- result.romTime = runFunction (readBlock, rom, nrOfCycles);
159
+ result.romTime = runFunctionOnSrc (readBlock, rom, nrOfCycles);
141
160
auto to = config;
142
- result.readTime = runFunction (readBlock, to, nrOfCycles);
143
- result.writeTime = runFunction (writeBlock, to, nrOfCycles);
144
- result.setTime = runFunction (Memory::memset32, to, nrOfCycles);
145
- result.setDMATime = runFunction (DMA::dma_fill32, to, nrOfCycles);
161
+ result.readTime = runFunctionOnDest (readBlock, to, nrOfCycles);
162
+ result.writeTime = runFunctionOnDest (writeBlock, to, nrOfCycles);
163
+ result.setTime = runFunctionOnDest (Memory::memset32, to, nrOfCycles);
164
+ result.setDMATime = runFunctionOnDest (DMA::dma_fill32, to, nrOfCycles);
146
165
TestConfig from = {const_cast <uint8_t *>(config.src ), config.srcSize , config.dest , config.destSize };
147
166
result.copyFromTime = runFunctionBlockwise (Memory::memcpy32, from, nrOfCycles);
148
167
result.copyToTime = runFunctionBlockwise (Memory::memcpy32, to, nrOfCycles);
@@ -240,12 +259,6 @@ void updateTime()
240
259
TimerTicks += TimerIncrement;
241
260
}
242
261
243
- void printTestState ()
244
- {
245
- TUI::printString (" Error test" , 4 , 16 , TUI::Color::LightGray, !testSpeed && blinkState ? TUI::Color::Red : TUI::Color::Blue);
246
- TUI::printString (" Speed test" , 20 , 16 , TUI::Color::LightGray, testSpeed && blinkState ? TUI::Color::Red : TUI::Color::Blue);
247
- }
248
-
249
262
void updateBlinkState ()
250
263
{
251
264
// blink UI elements
@@ -254,13 +267,19 @@ void updateBlinkState()
254
267
printTestState ();
255
268
}
256
269
257
- void updateRamTimings ()
270
+ void printTestState ()
271
+ {
272
+ TUI::printString (" Error test" , 4 , 16 , TUI::Color::LightGray, !testSpeed && blinkState ? TUI::Color::Red : TUI::Color::Blue);
273
+ TUI::printString (" Speed test" , 20 , 16 , TUI::Color::LightGray, testSpeed && blinkState ? TUI::Color::Red : TUI::Color::Blue);
274
+ }
275
+
276
+ void printRamTimings ()
258
277
{
259
278
TUI::printString (RamWaitStateStrings[ramWaitStateIndex], 15 , 3 , TUI::Color::Blue, TUI::Color::White);
260
279
TUI::printString (RamWaitStateOptionStrings[ramWaitStateIndex], 0 , 17 , TUI::Color::LightGray, TUI::Color::Blue);
261
280
}
262
281
263
- void updateRomWaitStates ()
282
+ void printRomWaitStates ()
264
283
{
265
284
TUI::printString (RomWaitStateStrings[romWaitStateIndex], 26 , 3 , TUI::Color::Blue, TUI::Color::White);
266
285
TUI::printString (RomWaitStateOptionStrings[romWaitStateIndex], 0 , 18 , TUI::Color::LightGray, TUI::Color::Blue);
@@ -283,7 +302,7 @@ void updateInput()
283
302
if (ramWaitStateIndex != ramWaitStateIndexBefore)
284
303
{
285
304
Memory::RegWaitEwram = RamWaitStates[ramWaitStateIndex];
286
- updateRamTimings ();
305
+ printRamTimings ();
287
306
}
288
307
// check if need to change ROM wait states
289
308
auto romWaitStateIndexBefore = romWaitStateIndex;
@@ -298,7 +317,7 @@ void updateInput()
298
317
if (romWaitStateIndex != romWaitStateIndexBefore)
299
318
{
300
319
Memory::RegWaitCnt = RomWaitStates[romWaitStateIndex];
301
- updateRomWaitStates ();
320
+ printRomWaitStates ();
302
321
}
303
322
// check if we need to change the test mode
304
323
auto testSpeedBefore = testSpeed;
@@ -350,11 +369,11 @@ int main()
350
369
TUI::printString (RamWaitStateOptionStrings[ramWaitStateIndex], 0 , 17 , TUI::Color::LightGray, TUI::Color::Blue);
351
370
TUI::printString (RomWaitStateOptionStrings[romWaitStateIndex], 0 , 18 , TUI::Color::LightGray, TUI::Color::Blue);
352
371
TUI::printString (" (START) Reboot " , 0 , 19 , TUI::Color::LightGray, TUI::Color::Blue);
353
- updateRamTimings ();
354
- updateRomWaitStates ();
372
+ printRamTimings ();
373
+ printRomWaitStates ();
355
374
// start wall clock
356
375
irqInit ();
357
- // set up time to increase time every ~5ms
376
+ // set up time to increase time every ~2. 5ms
358
377
irqSet (irqMASKS::IRQ_TIMER3, updateTime);
359
378
irqEnable (irqMASKS::IRQ_TIMER3);
360
379
REG_TM3CNT_L = 65536 - TimerIncrement;
@@ -378,15 +397,15 @@ int main()
378
397
if (testSpeed)
379
398
{
380
399
auto result = runSpeedTest (testConfig, CyclesSpeed);
381
- printSpeed (result.romTime , result.bytesPerTest , 15 , 5 , TUI::Color::Blue, TUI::Color::White);
382
- printSpeed (result.readTime , result.bytesPerTest , 15 , 6 , TUI::Color::Blue, TUI::Color::White);
383
- printSpeed (result.writeTime , result.bytesPerTest , 15 , 7 , TUI::Color::Blue, TUI::Color::White);
384
- printSpeed (result.setTime , result.bytesPerTest , 15 , 8 , TUI::Color::Blue, TUI::Color::White);
385
- printSpeed (result.setDMATime , result.bytesPerTest , 15 , 9 , TUI::Color::Blue, TUI::Color::White);
386
- printSpeed (result.copyFromTime , result.bytesPerTest , 15 , 10 , TUI::Color::Blue, TUI::Color::White);
387
- printSpeed (result.copyToTime , result.bytesPerTest , 15 , 11 , TUI::Color::Blue, TUI::Color::White);
388
- printSpeed (result.copyFromDMATime , result.bytesPerTest , 18 , 12 , TUI::Color::Blue, TUI::Color::White);
389
- printSpeed (result.copyToDMATime , result.bytesPerTest , 18 , 13 , TUI::Color::Blue, TUI::Color::White);
400
+ printSpeed (result.romTime , result.bytesPerRomTest , 15 , 5 , TUI::Color::Blue, TUI::Color::White);
401
+ printSpeed (result.readTime , result.bytesPerRamTest , 15 , 6 , TUI::Color::Blue, TUI::Color::White);
402
+ printSpeed (result.writeTime , result.bytesPerRamTest , 15 , 7 , TUI::Color::Blue, TUI::Color::White);
403
+ printSpeed (result.setTime , result.bytesPerRamTest , 15 , 8 , TUI::Color::Blue, TUI::Color::White);
404
+ printSpeed (result.setDMATime , result.bytesPerRamTest , 15 , 9 , TUI::Color::Blue, TUI::Color::White);
405
+ printSpeed (result.copyFromTime , result.bytesPerRamTest , 15 , 10 , TUI::Color::Blue, TUI::Color::White);
406
+ printSpeed (result.copyToTime , result.bytesPerRamTest , 15 , 11 , TUI::Color::Blue, TUI::Color::White);
407
+ printSpeed (result.copyFromDMATime , result.bytesPerRamTest , 18 , 12 , TUI::Color::Blue, TUI::Color::White);
408
+ printSpeed (result.copyToDMATime , result.bytesPerRamTest , 18 , 13 , TUI::Color::Blue, TUI::Color::White);
390
409
}
391
410
else
392
411
{
0 commit comments