General CHDK workflow - General Discussion and Assistance - CHDK Forum  

General CHDK workflow

  • 3 Replies
  • 4004 Views
General CHDK workflow
« on: 18 / March / 2014, 10:37:24 »
Advertisements
Hi,

since I want to get into the secrets of CHDK and do own developments I need a kind of overview how CHDK is organized. Is there any flowchart available which shows the overall workflow of CHDK after the cam ist switched on? Or do I heave to read and understand the code line by line?

Doxygen is not really a big help since it shows almost the same like the source code does.
So it does not explain why something is done it shows just that it is done.
In one of my early posts a few years ago I already mentioned the lack of documentation inside the CHDK code.

e.g.:

Code: [Select]
void core_spytask()
{
    int cnt = 1;
    int i=0;

    // Init camera_info bits that can't be done statically
    camera_info_init();

    spytask_can_start=0;

    extern void aram_malloc_init(void);
    aram_malloc_init();

    extern void exmem_malloc_init(void);
    exmem_malloc_init();

#ifdef CAM_CHDK_PTP
    extern void init_chdk_ptp_task();
    init_chdk_ptp_task();
#endif

    while((i++<400) && !spytask_can_start) msleep(10);

    started();
    msleep(50);
    finished();

#if !CAM_DRYOS
    drv_self_unhide();
#endif

    conf_restore();

how a newbee like me should know what is done here?

- what is spytask_can_start=0; for?
- what is aram_malloc_init(); for?
- what is exmem_malloc_init(); for?
- what does this do:     while((i++<400) && !spytask_can_start) msleep(10);
- why msleep(50); is called?

And this is only a small part of many other *.c-files.
As you can see if there is nothing documented inside the code it is very very difficult to understand the rules and functionality behind, but I need it to get a basic understanding what is under the hood of CHDK.
What please is the best way to get familar with that?

I don't want to complain but I really want to know why the developers do not put some small comments into the code that some other developer can get a better understanding. I think code documentation is mandatory especially in OpenSource projects where several developers work together.

At first I would need:

- What is the entry function (is there something like a main() function) which is called after switching on the camera?

- How any writing to the screen is done. What is the basic function to put any drawing or text on the screen.

Thanks a lot guys!
2 x IXUS 860IS 100c
2 x Powershot S110 103a

*

Offline reyalp

  • ******
  • 14118
Re: General CHDK workflow
« Reply #1 on: 18 / March / 2014, 16:26:31 »
since I want to get into the secrets of CHDK and do own developments I need a kind of overview how CHDK is organized.
The assertion CHDK is organized assumes facts not in evidence  :haha
Quote
  Is there any flowchart available which shows the overall workflow of CHDK after the cam ist switched on?
No.
Quote
Or do I heave to read and understand the code line by line?
Not all of it, but if you want to understand the code reading it is a good place to start. My usual approach is to look at some area I'm interested in and grep to figure out what references it. Or if I don't know where the thing I'm interested in, grep for likely terms.

This old thread has some hint about how chdk starts http://chdk.setepontos.com/index.php/topic,1454.0.html though beware it's very old so some of the information is out of date.

The wiki porting page (also sadly out of date) http://chdk.wikia.com/wiki/Adding_support_for_a_new_camera also gives some good information about the overall structure (or lack thereof)
Quote
how a newbee like me should know what is done here?
By reading ;)
Quote
- what is spytask_can_start=0; for?
Spytask needs to wait for some filesystem stuff to be ready (see your platform/<some camera>sub/<some sub>/boot.c )
Quote
- what is aram_malloc_init(); for?
- what is exmem_malloc_init(); for?
Suggest you look at those functions if the name isn't sufficiently self-explanatory.
Quote
- what does this do:     while((i++<400) && !spytask_can_start) msleep(10);
Wait for either spytask_can_start to be set or 4 seconds to pass.

Quote
- why msleep(50); is called?
started() and finished() turn the debug LED on and off, this keeps it on long enough to see.
Quote
As you can see if there is nothing documented inside the code it is very very difficult to understand the rules and functionality behind, but I need it to get a basic understanding what is under the hood of CHDK.
What please is the best way to get familar with that?
The same way the rest of us do... by reading the code and trying to make it do what we want. Cursing and drinking are also recommended but not strictly required.
Quote
I don't want to complain but I really want to know why the developers do not put some small comments into the code that some other developer can get a better understanding. I think code documentation is mandatory especially in OpenSource projects where several developers work together.
I agree that the source is poorly documented.

That said, documentation trivial things  (like the *_malloc_init above) is not really helpful IMO. To really *understand* the code you need to read the *code* not the comments.
Quote
- What is the entry function (is there something like a main() function) which is called after switching on the camera?
Everything starts in loader/<camera>/entry.s
From there after some copying it goes to platform/<camera>/main.c startup() which then goes to sub/<sub>/boot.c boot()

The boot code starts the various tasks (like OS threads or processes). Most CHDK code runs in either spytask or kbd_task.

Quote
- How any writing to the screen is done. What is the basic function to put any drawing or text on the screen.
This is done in the core/gui* files, if you should easily be able to find some functions that draw things by name and see how they are used.
Don't forget what the H stands for.

Re: General CHDK workflow
« Reply #2 on: 18 / March / 2014, 17:10:00 »
it is very very difficult to understand the rules and functionality behind, but I need it to get a basic understanding what is under the hood of CHDK.
What please is the best way to get familar with that?

Extremely simple, spend a LOT of time studying every single part of the code.
That is what I have  done and am still no expert.
I started by learning a little bit of 'C' programming and had to look-up what almost every 'C' command does.


Re: General CHDK workflow
« Reply #3 on: 19 / March / 2014, 03:48:54 »
Hi reyalp and Microfunguy,

thanks for your replies. I hoped you guys will tell me that there is a pretty nice flowchart available and all documentation I needed to understand CHDK.
OK I am joking. It seems I have to face the facts that there is only poor documentation and I have to live with it. I think I will go with what reyalp said, I will take a deeper look into the parts I am interested in and try to understand.
But I warn you be aware this will cause a lot of questions I will post in this forum here!  ;).

Thanks a lot for beeing with me! :)


2 x IXUS 860IS 100c
2 x Powershot S110 103a


 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal