PDA

View Full Version : How to quit properly a program?


cyril
07-30-2009, 02:23
Hi

I have a simple question but i can't find a answer : how to quit properly a program without shutting down or rebooting.
I just want to quit a a program without doing cwn_driver_sys_pwr_control(CWN_VAL_PWR_REBOOT);
Is "cwn_driver_exit();" the solution to my problem? Why this function is not use in the sample program giver with the SDK?

Cyril

pegahic
07-30-2009, 06:11
It seems COWON intended this to be the "right" way to quit a program, probably because this way you can avoid leaving the O2 in a dirty state (haven't tried to see what exactly can go wrong).

If you really want to get back directly to the UI, you will have to:
1. Make sure you exit from your application with status 1 (either return 1; in main() or exit(1);) and that devices are un-initialized properly (call cwn_driver_exit(), close any open files, free allocated memory, etc. - although linux usually takes care of this stuff, the embedded version used *may* lack some functionality in this regard, it's better to be safe).
2. Add the characters "CWN_EXTERN_WATERMARK_GENERIC" to the end of your app's executable (open the NOTEPAD/CALCULATOR apps in a hex editor to see what I mean). I simply used:
echo -n CWN_EXTERN_WATERMARK_GENERIC >> $YOURAPP.o2

cyril
07-30-2009, 10:41
Thanks it worked well.

When i run my program (compile for linux) with valgrind ( a memory check), it finds a memory leak of about 160 bytes. It is maybe for this, COWON says to exit the program by rebooting or shutting down.