Register

Bfile and system errors

Discuss issues related to the Casio Prizm 3rd party development
Senior Member
User avatar
Posts: 605
Joined: Sat Sep 15, 2012 6:59 am
Location: Krautland ****
Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400

Re: Bfile and system errors

Postby SimonLothar » Sun Jul 14, 2013 9:05 pm

gbl08ma wrote:...I'm using the Timer_* syscalls for managing timers...
Could you give some details? Which timernumbers are used? What do the timer-handlers do? When do timers run?
I'll be back!

Senior Member
Posts: 141
Joined: Wed May 16, 2012 2:50 pm
Location: Portugal
Calculators: Casio fx-CG20

Re: Bfile and system errors

Postby gbl08ma » Sun Jul 14, 2013 9:27 pm

I don't know the timer number, since I provide a 0 to the Timer_Install call so that it automatically chooses a timer number, then I store that number in memory and use it to start the timer. I am using one single timer to check chronometers completion, and this timer starts running right at the beginning of the add-in, before any GUI is even drawn. The timer is never stopped. Its handler checks some values in memory and performs some calculations to check if any of the downwards chronometers has reached zero. It has a period of 25 ms if I remember correctly. The timer handler doesn't touch the storage memory, at most it saves some things in the main memory but only when a chronometer is complete.

Tomorrow you'll be able to check the code in more detail. I can disable the timer by commenting two lines of code, I'll do that and see if it changes anything.

Out of curiosity, in your tests, where is the buffer, with the contents of the file to write, stored? I use the stack for almost all buffers in my add-in because I found malloc and free to be a bit temperamental (plus the heap is smaller than the stack).

Senior Member
User avatar
Posts: 605
Joined: Sat Sep 15, 2012 6:59 am
Location: Krautland ****
Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400

Re: Bfile and system errors

Postby SimonLothar » Mon Jul 15, 2013 5:51 am

gbl08ma wrote:Out of curiosity, in your tests, where is the buffer, with the contents of the file to write, stored?
(void*)0x80000000 is the first address of the flash.
I'll be back!

Senior Member
Posts: 141
Joined: Wed May 16, 2012 2:50 pm
Location: Portugal
Calculators: Casio fx-CG20

Re: Bfile and system errors

Postby gbl08ma » Mon Jul 15, 2013 10:54 am

I know :) I meant the buffer that is in RAM which you use to give WriteFile the contents to write to the test file.

You can download a test version of my refreshed Utilities add-in here: http://tny.im/GH
Inside of the ZIP file there's a folder called src with the source code. Entry point is in main.cpp. Code with lots of Bfile calls that sometimes cause errors is in calendarProvider.cpp and on fileProvider.cpp (on this last one, the problematic functions are
void deleteFiles(File* files, Menu* menu)
and
void filePasteClipboardItems(File* clipboard, char* browserbasepath, int itemsInClipboard)

Tell me if you don't understand something.

Senior Member
User avatar
Posts: 605
Joined: Sat Sep 15, 2012 6:59 am
Location: Krautland ****
Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400

Re: Bfile and system errors

Postby SimonLothar » Mon Jul 15, 2013 11:44 am

gbl08ma wrote:I know :) I meant the buffer that is in RAM which you use to give WriteFile the contents to write to the test file.
No RAM. I use the flash as WriteFile's source-memory. It is the largest consecutive memory area available, so even when writing some MiBs in one call, there is no danger of invalid data address errors.
I'll be back!

Senior Member
Posts: 141
Joined: Wed May 16, 2012 2:50 pm
Location: Portugal
Calculators: Casio fx-CG20

Re: Bfile and system errors

Postby gbl08ma » Mon Jul 15, 2013 11:51 am

Ah OK, understood it now.

I disabled the timer and I am now doing intensive tests on the calendar events functions of my add-in, which usually caused errors when the filesystem is not optimized.
Surprise surprise, I have added/copied/moved/edited/deleted a lot already, and there are no errors so far.
If I really come to the conclusion that having the timer stopped avoids the errors, my explanation for the fact that they do not occur when the filesystem is not optimized changes. It's because when the memory is optimized, things happen faster, without the timer getting to tick. Somehow, timers running can break the Bfile functions - but let me confirm it, as I still need to test the file manager...

EDIT: removing the timers seemed to fix all the errors, except for those in my self-made file copy function, which sometimes works fine and other times errors so bad that causes the storage memory to be unmounted.

EDIT2: after copying the add-in to real hardware and running it there, I already had the calculator reboot (no system error) when moving an event from one day to another. I couldn't reproduce the problem, and that's really annoying.
EDIT3: looks like I reproduced the problem on the emulator, when adding an event. Looks like the calculators (the real and the emulated) have rebooted after calling Bfile_CreateEntry_OS - the file was created but wasn't written. And this time I have no clue what may be causing it...

Senior Member
User avatar
Posts: 605
Joined: Sat Sep 15, 2012 6:59 am
Location: Krautland ****
Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400

Re: Bfile and system errors

Postby SimonLothar » Mon Jul 15, 2013 9:14 pm

gbl08ma wrote:EDIT: removing the timers seemed to fix all the errors, except for those in my self-made file copy function, which sometimes works fine and other times errors so bad that causes the storage memory to be unmounted.
EDIT2: after copying the add-in to real hardware and running it there, I already had the calculator reboot (no system error) when moving an event from one day to another. I couldn't reproduce the problem, and that's really annoying.
EDIT3: looks like I reproduced the problem on the emulator, when adding an event. Looks like the calculators (the real and the emulated) have rebooted after calling Bfile_CreateEntry_OS - the file was created but wasn't written. And this time I have no clue what may be causing it...
Perhaps you could tell me the position (filename, functionname), where the problems occur (the file copy function, event moving, event adding).
I'll be back!

Senior Member
Posts: 141
Joined: Wed May 16, 2012 2:50 pm
Location: Portugal
Calculators: Casio fx-CG20

Re: Bfile and system errors

Postby gbl08ma » Mon Jul 15, 2013 9:37 pm

calendarProvider.cpp, line 188. It's when resuming execution of my code when returning from the Bfile_CreateEntry call that the error happens. The Bfile call itself seems to succeed, as there is an empty file where it should be after the calculator reboots.
It doesn't happen always. I would say it happens 1/6 of the times. It always happens on function AddEvent.

Also, I have pushed the source code of the new add-in to GitHub. You can see the most up-to-date source code here: https://github.com/gbl08ma/utilities

Senior Member
User avatar
Posts: 605
Joined: Sat Sep 15, 2012 6:59 am
Location: Krautland ****
Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400

Re: Bfile and system errors

Postby SimonLothar » Tue Jul 16, 2013 9:15 pm

In calendarProvider.cpp I noticed

int oldsize = Bfile_GetFileSize_OS(hAddFile, Bfile_TellFile_OS( hAddFile ));

In my system Bfile_GetFileSize_OS is syscall 0x1DA6. Syscall 0x1DA6 uses one argument only. Does "GCC with libfxcg" use another syscall for Bfile_GetFileSize_OS? If not, what does Bfile_TellFile_OS( hAddFile ) do?
I'll be back!

Senior Member
Posts: 141
Joined: Wed May 16, 2012 2:50 pm
Location: Portugal
Calculators: Casio fx-CG20

Re: Bfile and system errors

Postby gbl08ma » Tue Jul 16, 2013 9:25 pm

Yes there are some changes with regards to these functions in libfxcg, when compared to miniSDK.

In my system Bfile_GetFileSize_OS is 0x1DA6 too. Bfile_TellFile_OS is 0x1DAB.
Headers for both syscalls:
Code: Select all
int Bfile_GetFileSize_OS( int handle, int pos );
int Bfile_TellFile_OS( int handle );


The reason why that line of code is the way it is, is because at some point someone found out GetFileSize was actually a two parameter call, which allows for getting the remaining file size from the current "cursor" position to the end of the file.
So, if the cursor is at the beginning of the file, GetFileSize will return the remaining length to the end of the file, i.e. the total file size.
If the total filesize of the file is 30 bytes, and you call GetFileSize with the pos parameter as 10, it will return 20 (at least that's how I think it works).


TellFile is used to know where the file "cursor" (the current position of the file handle) is. Since that line is being called right after the file is opened, the cursor will be at the beginning, and Bfile_GetFileSize_OS(handle, Bfile_TellFile_OS( handle)) can be used to retrieve the file size.

PS: I can post a new compiled version of the add-in which has just the reboot-on-AddEvent problem for you to check, if you want.

PreviousNext

Return to Casio Prizm SDK

Who is online

Users browsing this forum: No registered users and 16 guests