#include "debug.h"
#include "ProfileTimer.h"
#define REFRESH_TIMEOUT_MS 3000
#define FRAME_SIZE 2
#define UNIT_SIZE 2
long refreshTimeout;
long tx1;
float foofoo;
char ftos[16];
const char* const tableA[][UNIT_SIZE] PROGMEM = { {0x41,0x42},
{0x43,0x44} };
const char pair1[] PROGMEM = {35, 36};
const char pair2[] PROGMEM = {37, 38};
const char* const tableB[] = {pair1, pair2};
byte frameInx, unitInx;
char buffer[32];
// =======================================================================
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
refreshTimeout = millis();
frameInx = 0;
unitInx = 0;
foofoo = 3.14;
dumpFF(0x00000UL, 0x100);
}
// =======================================================================
void loop() {
// put your main code here, to run repeatedly:
if (millis()-refreshTimeout > REFRESH_TIMEOUT_MS) {
refreshTimeout = millis();
//dtostrf(foofoo,2,2,ftos);
//SerialPrintf("\n[Loop] millis(): %i ms, foofoo=%s\n", refreshTimeout, ftos);
SerialPrintf("\n[Loop] millis(): %d ms\n", refreshTimeout);
// code;
/*
for(byte ii = 0; ii < FRAME_SIZE; ii++) {
for (byte jj = 0; jj < UNIT_SIZE; jj++) {
//byte val = pgm_read_byte(&(table[ii][jj]));
byte val = pgm_read_dword(&(tableA[ii][jj]));
SerialPrintf("TableA[%d][%d] = %d\r\n", ii, jj, val);
}
}
for(byte ii = 0; ii < FRAME_SIZE; ii++) {
for (byte jj = 0; jj < UNIT_SIZE; jj++) {
//byte val = pgm_read_byte(&(table[ii][jj]));
byte val = pgm_read_dword(&(tableB[ii][jj]));
SerialPrintf("TableB[%d][%d] = %d\r\n", ii, jj, val);
}
}
SerialPrintf(">> %s", "\r\n");
*/
for (int i = 0; i < FRAME_SIZE; i++) {
strcpy_P(buffer, (const char*)pgm_read_byte(&(tableA[i/2])));
SerialPrintf("buffer[%d]: %s, table[][0]=%x, table[][1]=%x\r\n", i, buffer, (i == 0 ? (tableA[0][0], tableA[0][1]) : (tableA[1][0], tableA[1][1])));
}
SerialPrintf(">> %s", "\r\n");
/*
//tx1 = micros();
SerialPrintf("\n[1] Free list: %d ,free RAM: %d\n",freeListSize(),freeMemory());
ProfileTimer t ("foo() timing");
foo();
SerialPrintf("[4] Free list: %d ,free RAM: %d\n",freeListSize(),freeMemory());
//tx1 = micros()-tx1;
//PrintExecTime("foo()",tx1);
*/
}
}
// -------------------------------------------------------------------
void foo (void) {
static byte index =0;
index++;
SerialPrintf("[2] Free list: %d ,free RAM: %d\n",freeListSize(),freeMemory());
PROFILE_FUNCTION;
byte *ptr = (byte*)malloc(128*sizeof(byte));
SerialPrintf("malloc(): @%p\n",ptr);
SerialPrintf("[3] Free list: %d ,free RAM: %d\n",freeListSize(),freeMemory());
long timing = micros() + 1000ul;
while (micros() < timing) {
_NOP();
}
if (index % 3 == 0) {
free(ptr);
}
}