# Events and timers

**URL:** <https://forum.sierrawireless.com/t/events-and-timers/3194>\
**Category:** Open AT\
**Created:** [May 6, 2009, 4:51pm UTC](https://forum.sierrawireless.com/t/events-and-timers/3194 "2009-05-06T16:51:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![BenFT01](https://avatars.discourse-cdn.com/v4/letter/b/73ab20/32.png) [@BenFT01](https://forum.sierrawireless.com/u/BenFT01)\
**Post date:** [May 6, 2009, 4:51pm UTC](https://forum.sierrawireless.com/t/events-and-timers/3194/1 "2009-05-06T16:51:29Z")

</div>

I’ve set up a timer to launch a handler. In the handler I have an adl\_eventWait(). This returns ADL\_RET\_ERR\_BAD\_STATE however.  
The ADL\_User\_Guide says this is because the function was called from Task 0 context. Surely you can generate an event from a timer in this way?  
I have tried searching the docs to find more about task context but the relevent bits have escaped me so far. Is the timer event handler a new task? If not how do you go about launching a new task?  
Any hints or pointers to relevent sections in the docs appreciated. I know it must be in there somewhere.

---

<div class="post-metadata">

**Author:** ![davidc](https://avatars.discourse-cdn.com/v4/letter/d/a183cd/32.png) [@davidc](https://forum.sierrawireless.com/u/davidc)\
**Post date:** [May 7, 2009, 4:46am UTC](https://forum.sierrawireless.com/t/events-and-timers/3194/2 "2009-05-07T04:46:18Z")

</div>

Hiya,

There’s a whole lot of things that you cannot do from within timers and interrupt handlers.

However, you CAN send messages (using adl\_msgSend()) from these contexts. The message handler then runs in the normal execution context

Here’s what to do:

Define the appropriate number of different messages.  
Set up a message handler to listen for messages to yourself, and handle the message types defined above.

From the Interupt or Timer Handler, send a message to yourself requesting that the appropriate action be undertaken.

Have a look at the adl\_sendMsg() function in the ADL users guide.

ciao, Dave

(p.s. I’m working with Open AT 2.20 & OS R7.3).

---

<div class="post-metadata">

**Author:** ![BenFT01](https://avatars.discourse-cdn.com/v4/letter/b/73ab20/32.png) [@BenFT01](https://forum.sierrawireless.com/u/BenFT01)\
**Post date:** [May 7, 2009, 10:28am UTC](https://forum.sierrawireless.com/t/events-and-timers/3194/3 "2009-05-07T10:28:49Z")

</div>

Thanks for the thoughts. I’ve had a look at that. I would need to send a message to the handler, then one back once the processing is done. The event handler should be the way to do this though. If I explain better what I am trying to do, then some one could point to the best way to achieve it.  
I have a input commands coming in from a number of sources, possibly simultaneously, I queue these with the adl queue system which will serialise the input. When a command arrives I want to launch an event to request the command be processed. Another task sits waiting for the event and once received, processes the command. Once the command is processed, the event is cleared and returns to waiting for the next command event.

I’m not entirely clear on how to set up the Wait For Event in a new task. I tried to do it by launching a timer handler, but there is probably a more direct way of doing this. (The Wait For Event handler did launch but I got the error in my openning post).

I’m searching for taskCreate, taskDelete type functions but not finding anything relevent. I’ve read ADL is all event driven but I haven’t got my head round it all yet. Any hints appreciated.

---

<div class="post-metadata">

**Author:** ![BenFT01](https://avatars.discourse-cdn.com/v4/letter/b/73ab20/32.png) [@BenFT01](https://forum.sierrawireless.com/u/BenFT01)\
**Post date:** [May 7, 2009, 2:05pm UTC](https://forum.sierrawireless.com/t/events-and-timers/3194/4 "2009-05-07T14:05:11Z")

</div>

I’ve found the multi-tasking example now and the way of initialising tasks:

```auto
const adl_InitTasks_t adl_InitTasks [] =
{
{ MainTask, 3*1024, "MAIN", 3 }, // Main task
{ SubTask1, 3*1024, "SUB1", 2 }, // Sub task 1
{ SubTask2, 3*1024, "SUB2", 1 }, // Sub task 2
{ NULL, 0, NULL, 0 }
};
```

Trying to debug it now and see if anything is happening but the traces have all disappeared, 😠 it never ends! I’m using M2M, R7.3 . I’ve checked the trace settings, resynced, re-booted but no sign. They we’re there in earlier incarnations. Oh well back to the brick wall ☹ Bang. Bang. Bang. Bang.

---

<div class="post-metadata">

**Author:** ![BenFT01](https://avatars.discourse-cdn.com/v4/letter/b/73ab20/32.png) [@BenFT01](https://forum.sierrawireless.com/u/BenFT01)\
**Post date:** [May 7, 2009, 3:47pm UTC](https://forum.sierrawireless.com/t/events-and-timers/3194/5 "2009-05-07T15:47:09Z")

</div>

In fact the trace filters have disappeared. There are no flows listed so I can’t select them anymore. Where have they gone, how can I get them back ???

---

<div class="post-metadata">

**Author:** ![Madouc](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@Madouc](https://forum.sierrawireless.com/u/Madouc)\
**Post date:** [May 7, 2009, 11:02pm UTC](https://forum.sierrawireless.com/t/events-and-timers/3194/6 "2009-05-07T23:02:13Z")

</div>

are you using m2m studio?

then when you’re connected you need to refresh the target info tree, then you can configure the remote traces.

---

<div class="post-metadata">

**Author:** ![davidc](https://avatars.discourse-cdn.com/v4/letter/d/a183cd/32.png) [@davidc](https://forum.sierrawireless.com/u/davidc)\
**Post date:** [May 7, 2009, 11:49pm UTC](https://forum.sierrawireless.com/t/events-and-timers/3194/7 "2009-05-07T23:49:21Z")

</div>

Hiya,

I’m using the multitasking features of R7.3 to run a data logger. I have a number of device tasks (i.e. collect data from I/O), a event task that takes care of storing the data from the I/O tasks, and a couple of ancillary tasks for things like Data uploads, alarms etc.

All communications between tasks is done using the adl\_msgSend() calls. It’s very asynchronous, but I’ve found it woks extremely well.

The basic layout of all my tasks is as follows:

```auto
MessageHandler(source, id, data)
{
    switch(id):
    {
        case MYMSGA:
            // process message A
            break;
        case MYMSGB:
            // process message B
            break;
         default:
            // ignore other messages
            break;
    }
}

TaskInit()
{
    // Set up task variables and states
    // this is called by the OpenAT multitasker.
    // This is the function that is in the Adl_InitTasks[] array.
}
```

Note that there is NO adl\_main() function when using the multitasking. The first function called is the function with the highest priority in the Adl\_InitTasks[] array.

ciao, Dave

---

<div class="post-metadata">

**Author:** ![BenFT01](https://avatars.discourse-cdn.com/v4/letter/b/73ab20/32.png) [@BenFT01](https://forum.sierrawireless.com/u/BenFT01)\
**Post date:** [May 8, 2009, 4:36pm UTC](https://forum.sierrawireless.com/t/events-and-timers/3194/8 "2009-05-08T16:36:45Z")

</div>

Thanks for the input. I’ll bear messages in mind. The multi-tasking aspects are working now with events. 😃 The init task table was the key. And not using adl\_main().  
My problems with the Trace are down to the serial-usb. I can get TMT to read the usb on an XP machine, but not with M2M on a Vista machine. Anyone else having issues with this?

PS\> davidc you were a life saver on the WIP-bearer events, or lack of them, sorted with a adl\_gprsSubcribe. Cheers!
