#pragma GCC push_options
#pragma GCC optimize ("Ofast")
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <Arduino.h>
unsigned char DMAMEM DmaMem[480 * 1024];
unsigned char EXTMEM ExtMem[8 * 1024 * 1024];
unsigned char GenMem[300 * 1024];
// each class is only 8 bytes
class cTestData1
{
public: unsigned char A1, A2, A3, A4, A5, A6, A7, A8;
};
class cTestData2
{
public: unsigned short A1, A2, A3, A4;
};
class cTestData3
{
public: unsigned int A1: 24, A2: 20, A3: 13, A4: 7;
};
class cTestData4
{
public: unsigned int A1, A2;
};
void TestDataS(unsigned char *p1, unsigned char *p2) // copy data from one test memory block to other and measure the total amount of CPU tacts for 64K transfer
{ unsigned long begin, end;
cTestData1 *pT1;
cTestData2 *pT2;
cTestData3 *pT3;
cTestData4 *pT4;
cTestData4 *pT41;
unsigned int *pI1, *pI2;
pT1 = (cTestData1*)p1;
pT2 = (cTestData2*)p2;
begin = ARM_DWT_CYCCNT;
for (int i = 0; i < 8192; i++)
{ pT2[i].A1 = pT1[i].A1;
pT2[i].A2 = pT1[i].A2;
pT2[i].A3 = pT1[i].A3;
pT2[i].A4 = pT1[i].A4 + pT1[i].A5 + pT1[i].A6 + pT1[i].A7 + pT1[i].A8;
}
end = ARM_DWT_CYCCNT;
Serial.print(end - begin); Serial.print(" A "); Serial.flush();
pT2 = (cTestData2*)p2;
pT3 = (cTestData3*)p1;
begin = ARM_DWT_CYCCNT;
#if 1
for (int i = 0; i < 8192; i++)
{
// CrashReport.breadcrumb( 1, i );
// CrashReport.breadcrumb( 2, 1 );
pT3[i].A1 = pT2[i].A1;
[B][COLOR="#FF0000"]// >> CrashReport.breadcrumb( 2, 2 ); // Adding this line alone allows completion without error : REQ TD_1.57
if ( i == 0 ) Serial.print("\t A2 \t"); // OR: Adding this line alone allows completion without error[/COLOR][/B]
pT3[i].A2 = pT2[i].A2;
// CrashReport.breadcrumb( 2, 3 );
pT3[i].A3 = pT2[i].A3;
// CrashReport.breadcrumb( 2, 4 );
pT3[i].A4 = pT2[i].A4;
// CrashReport.breadcrumb( 2, 5 );
}
#else
for (int i = 0; i < 8192; i++)
{
pT3[i].A1 = pT2[i].A1;
pT3[i].A2 = pT2[i].A2;
pT3[i].A3 = pT2[i].A3;
pT3[i].A4 = pT2[i].A4;
}
#endif
end = ARM_DWT_CYCCNT;
Serial.print(end - begin); Serial.print(" B "); Serial.flush();
pT3 = (cTestData3*)p1;
pT4 = (cTestData4*)p2;
begin = ARM_DWT_CYCCNT;
for (int i = 0; i < 8192; i++)
{ pT4[i].A1 = pT3[i].A1;
pT4[i].A2 = pT3[i].A2 + pT3[i].A3 + pT3[i].A4;
}
end = ARM_DWT_CYCCNT;
Serial.print(end - begin); Serial.print(" C "); Serial.flush();
pT4 = (cTestData4*)p2;
pT1 = (cTestData1*)p1;
begin = ARM_DWT_CYCCNT;
for (int i = 0; i < 8192; i++)
{ pT1[i].A1 = pT4[i].A1;
pT1[i].A2 = pT4[i].A1;
pT1[i].A3 = pT4[i].A1;
pT1[i].A4 = pT4[i].A1;
pT1[i].A5 = pT4[i].A2;
pT1[i].A6 = pT4[i].A2;
pT1[i].A7 = pT4[i].A2;
pT1[i].A8 = pT4[i].A2;
}
end = ARM_DWT_CYCCNT;
Serial.print(end - begin); Serial.print(" D "); Serial.flush();
pT4 = (cTestData4*)p1;
pT41 = (cTestData4*)p2;
begin = ARM_DWT_CYCCNT;
for (int i = 0; i < 8192; i++)
{ pT41[i].A1 = pT4[i].A1;
pT41[i].A2 = pT4[i].A2;
}
end = ARM_DWT_CYCCNT;
Serial.print(end - begin); Serial.print(" E "); Serial.flush();
pI1 = (unsigned int*)p2;
pI2 = (unsigned int*)p1;
begin = ARM_DWT_CYCCNT;
for (int i = 0; i < 16384; i++)
pI2[i] = pI1[i];
end = ARM_DWT_CYCCNT;
Serial.println(end - begin); Serial.flush();
Serial.println(" DONE! "); Serial.flush();
}
int ShiftList1[] = {0, 4, 8, 12, 16, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3};
int ShiftList2[] = {0, 4, 8, 12, 16, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3};
void TestData(unsigned char *p)
{
Serial.printf("Testing memory of %p\n", p); Serial.flush();
for (uint32_t i = 0; i < sizeof(ShiftList1) / sizeof(ShiftList1[0]); i++)
//for (uint32_t i = 8; i < sizeof(ShiftList1) / sizeof(ShiftList1[0]); i++)
{ Serial.printf("#i=%u %p(%d) to %p(%d) started\n", i, p + ShiftList1[i], ShiftList1[i], p + 65536 + ShiftList1[i], 65536 + ShiftList1[i]);
Serial.flush();
TestDataS(p + ShiftList1[i], p + 65536 + ShiftList1[i]);
}
}
void setup()
{
Serial.begin(115200);
while (!Serial);
Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__); Serial.flush();
if (CrashReport)
{ Serial.print(CrashReport);
delay(10000);
}
else
{
TestData(GenMem);
TestData(DmaMem);
TestData(ExtMem);
}
}
void loop()
{
}
#pragma GCC pop_options