Code Select
uint32_t autodetect_movierecorder()
{
for(uint32_t addr = 0; addr < 0x01000000; addr += 4)
{
uint32_t *ptr = (uint32_t *)addr;
/* first element pointer into flash? */
if((ptr[0] & 0xFF000000) != 0xFF000000)
{
continue;
}
/* second element pointer into ram? */
if((ptr[1] & 0xFF000000) != 0x00000000)
{
continue;
}
/* third element pointer into ram? */
if((ptr[2] & 0xFF000000) != 0x00000000)
{
continue;
}
/* is it a pointer to "MovieRecorder" string? */
if(strcmp("MovieRecorder", (const char *)ptr[0]))
{
continue;
}
/* check for StateObject and TaskClass */
uint32_t *state_ptr = (uint32_t *)ptr[1];
uint32_t *task_ptr = (uint32_t *)ptr[2];
/* StateObject: first element pointer into flash? */
if((state_ptr[0] & 0xFF000000) != 0xFF000000)
{
continue;
}
/* StateObject: is it a pointer to "MovieRecorder" string? */
if(strcmp("StateObject", (const char *)state_ptr[0]))
{
continue;
}
/* TaskClass: first element pointer into flash? */
if((task_ptr[0] & 0xFF000000) != 0xFF000000)
{
continue;
}
/* TaskClass: is it a pointer to "MovieRecorder" string? */
if(strcmp("TaskClass", (const char *)task_ptr[0]))
{
continue;
}
return addr;
}
return 0;
}
uint32_t autodetect_movierecorder_ptr()
{
uint32_t obj = autodetect_movierecorder();
if(obj)
{
for(uint32_t addr = 0x1000; addr < 0x01000000; addr += 4)
{
uint32_t *ptr = (uint32_t *)addr;
if(ptr[0] == obj)
{
return addr;
}
}
}
return 0;
}
uint32_t autodetect_movierecorder_maxsize_pos()
{
uint32_t *obj = (uint32_t *)autodetect_movierecorder();
if(obj)
{
for(uint32_t offset = 0; offset < 100; offset += 2)
{
if((obj[offset] == 0xFFFFFFFF) && (obj[offset+1] == 0))
{
return offset;
}
}
}
return 0;
}
void run_test()
{
uint32_t objPtr = autodetect_movierecorder_ptr();
uint32_t offsetMax = autodetect_movierecorder_maxsize_pos();
if(objPtr && offsetMax)
{
uint32_t *movRec = *((uint32_t**)objPtr);
uint32_t offsetCur = 74;
/* set maximum to 0x3FFFFFFFF bytes (16GiB) */
movRec[offsetMax+1] = 0x00000003;
movRec[offsetMax] = 0xFFFFFFFF;
if(offsetMax != 80)
{
offsetCur = 80;
}
while(1)
{
msleep(100);
bmp_printf(FONT_SMALL, 10,40, "Object: 0x%08X Ptr: 0x%08X Off: %d", movRec, objPtr, offsetMax);
bmp_printf(FONT_SMALL, 10,50, "max: %08X%08X cur:%08X%08X", movRec[offsetMax+1], movRec[offsetMax], movRec[offsetCur+1], movRec[offsetCur]);
}
}
else
{
uint32_t loops = 0;
while(loops++ < 100)
{
msleep(50);
bmp_printf(FONT_SMALL, 10,10, "Object/MaxPos not found");
}
}
return;