A simple task ? - General Discussion and Assistance - CHDK Forum

A simple task ?

  • 4 Replies
  • 3184 Views
A simple task ?
« on: 10 / July / 2011, 18:32:21 »
Advertisements
Just playing around with a simple background task on the A460 that sounds a beep at an interval determined by a global variable.

In boot.c, _taskCreateHookAdd(createHook) adds the 'hook' createHook(), which is implemented in \generic\main.c.

That executes task_start_hook() which   _CreateTask("Beeper", 0x19, 0x2000, beeper, 0);

beeper() simply calls bgndBeeper() :-

Code: [Select]
void bgndBeeper()
{
 static int BeepCnt;
while(!spytask_can_start) msleep(10);
// debug_led(1);
 if(gBeepRepeat)
  {
   if(++BeepCnt>=(gBeepInterval*100))
    {
     BeepCnt = 0;
     play_sound(4);
    }
  }
 msleep(10);
}

The task pauses until file initialisation task finished and deleted.

So, not only does it not beep the led cannot even be unconditionally turned on (when not commented out).


Any ideas ?

When you have msleep() in a task, does that means the task scheduler ignores it for that amount of time ?

*

Online reyalp

  • ******
  • 14111
Re: A simple task ?
« Reply #1 on: 10 / July / 2011, 19:03:42 »
As written, your task will wait until spytaks_can_start, do at most 1 beep, sleep 10, and then exit. I'm not exactly clear what the logic of gBeepRepeat and BeepCnt are supposed to be.

If you want your task to run indefinitely waiting for gBeepRepeat, it needs to be in a loop with a msleep (or better, a wait on some kind of synchronization object that can be signaled by other tasks) in it.

It seems like the LED should be turned on, but perhaps it is turned off again by some of the other startup code ?

edit:
FWIW, the "blinker" task in #if 0 at the bottom of platform/d10/sub/100a/boot.c works just fine, alternately blinking the different colored LEDs in the background. All you have to change to enable it is turn the #if 0 to #if 1 and add a call to CreateTask_blinker after CreateTask_spytask.
« Last Edit: 10 / July / 2011, 19:15:06 by reyalp »
Don't forget what the H stands for.

Re: A simple task ?
« Reply #2 on: 10 / July / 2011, 19:22:18 »
Thanks, a while(1) {.....  msleep(10);} fixed it.

So, how often does the task scheduler service this task, is it related to the msleep(10) time ?

As the beep interval is measured in seconds, could I use msleep(500), for example ?

EDIT
That is exactly the value you have used in the D10 blinker !


A stack size of 0x2000 is obviously not needed, is there a lower limit ?

Also, why is task priority 0x19 ?

Can the movie task be paused and restarted using the appropriate firmware commands ?

I ask because of the fruitless efforts of trying to achieve  better movie synch of two cameras.
« Last Edit: 10 / July / 2011, 19:35:08 by Microfunguy »

*

Online reyalp

  • ******
  • 14111
Re: A simple task ?
« Reply #3 on: 10 / July / 2011, 20:23:49 »
Thanks, a while(1) {.....  msleep(10);} fixed it.

So, how often does the task scheduler service this task, is it related to the msleep(10) time ?
Yes. What exactly happens depends on the details of the scheduler, task priority and what other tasks are doing.

msleep yields the task so the next one in the schedulers list will be run. Your task shouldn't be scheduled again for at least 10ms, but the delay could be longer.

msleep isn't the only thing that could cause your task to yield.
- Preemptive schedulers (which the cameras have) will interrupt running tasks to let others run, subject to priority and the details of the implementation. However, this probably won't happen if interrupts are disabled, which may be relevant when you are modifying canon tasks.
- Other system calls can implicitly yield. For example, on many systems IO will cause a task to yield, so something else can run while the hardware is busy. Tasks will also yield waiting for a synchronized resource.
Quote
As the beep interval is measured in seconds, could I use msleep(500), for example ?
If you want whole seconds, you might as well use 1000 .

Quote
A stack size of 0x2000 is obviously not needed, is there a lower limit ?
I'm not sure if there's a lower limit, but you need enough for whatever functions your task calls. A good rule of thumb would be to use what the simpler canon tasks use. I came up with 0x200 for init_chdk_ptp_task using this approach.

It should be divisible by 4. It looks like dryos will refuse to create a stack that's less than about 32 bytes.

Quote
Also, why is task priority 0x19 ?
Because I blindly copy pasted/from something else and it worked ;) Note that in vxworks (and presumably dryos) lower numbers are higher priority. What exactly priority means depends a lot on the scheduler implementation.
Quote
Can the movie task be paused and restarted using the appropriate firmware commands ?
You can wait on synchronization objects like semaphores or message queues. If you look at the canon tasks, you can see that most of them sit in a loop waiting on a message queue. How long the canon task could be stalled like this before causing problems is open to question. There are also functions to suspend and resume tasks externally (taskSuspend and taskResume in vxworks)

FWIW, you can find the vxworks documentation online with a little googling. This will give you a lot of information on the task and task synchronization functions.
Don't forget what the H stands for.


Re: A simple task ?
« Reply #4 on: 10 / July / 2011, 20:42:26 »
Time for bed, but first ...


If you want whole seconds, you might as well use 1000 .

It was insurance in case it misses one.
Quote
Because I blindly copy pasted/from something else and it worked

You actually set a priority of 1, and so have I.

Quote
If you look at the canon tasks, you can see that most of them sit in a loop waiting on a message queue.
Yes, I gave up long ago trying to pause various branches of the queue.
Quote
There are also functions to suspend and resume tasks externally (taskSuspend and taskResume in vxworks)


That is what I was really referring to.

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal