Help about Handlers and Timers



I’m using OpenAt 4.24 and Q2687 processor. Currently I’m implementing a protocol over rs232.

My problem is, when app enters a loop, event handlers and timers are not called by OS. So, I can not block main routine while checking a specific packet received or timeout elapsed.

Is that what expected, or did I make a mistake somewhere ?

I have searched forum and read a few post about issue. Developers say OpenAt is not a multitasking enviroment. If so, both event handlers/timers and user application are running in same context. Is there any way to run event handlers/timers in high level interruption context ? (Because event handlers and timers are supposed to called in another thread by OS…)

Currently, I’m investigating OpenAt OS 2.0 beta, which seems promising about event handlers…

thanks in advance.

  • Gokhan


So don’t put the application into a loop!

Long loops in the application are bad anyhow - you are liable to trigger a watchdog reset!

What are you actually trying to do?
Sounds like you need to change to a state machine that handles individual FCM and Timer events, rather than a loop that tries to wait for a complete packet…?


hi awneil!

thanks for the reply. I’m trying to implement a communication protocol which is based on request-respond messages.

Here is the psuedo code,

static int state = 0;
int offset = 0;
byte[] buffer = new byte[10*1024];

void SerialPort_DataReceived(int len, byte[] data )
    if(len > 3 && data[len-3] = ACK && data[len-2] == CR && data[len-1] == LF)
        state = 1;   //welcome received
    else if(len > 3 && data[len-3] = ETX && data[len-2] == CR && data[len-1] == LF) 
        state = 2;   //synch data complete
    for(int i=0; i< len, i++)
        buffer[offset+i] = data[i];   
    offset += len;

// main function
bool Synchronize()
    int i = 0;
    // wait welcome message for max 3secs
    while(state == 0 && i < 6)
    if(state == 0)
        return false;

    // wait synch data for max 3 secs
    while(state == 1 && i < 6)
    if(state == 1)
        return false;
    return true;

I successfuly implemented protocol before… But this time, Data event handler is not called when while loop running. You may suggest to wrote bussiness functionality in DataHandler, but there are problems like timeout handling, return value of function etc…



It looks like your pseudo-code is c#. There is no thread.sleep() function available with OpenAT. As a matter of fact there is a watchdog reset if your code execution time is above 4 seconds. With OpenAT everything needs to be event based. Check the FCM doc for that.




Of course not.

You need to get rid of this loop and instead have a state, “awaiting welcome”;
The events you expect in this state are either “welcome received” or “timeout”.


yes :slight_smile: code is in c#. by 4 seconds watchdog reset, you mean TOTAL execution of all user codes , or a specific function / loop etc ??

I’ll use state machine approach only if there is no other solution, because

  1. Code will be too complex , there are many states
  2. A client connected via GPRS will wait result of function, so I need to know when whole procedure ends. (I have to use timers for that in state machine approac…)

I have checked multitasking timers example in OpenAt OS 2.0 beta, and it seems Handlers and Timers are running in another thread, which is exaclty what I want… Did you use OpenAt Os 2.0 Beta ?? is it stable to production ?



The watchdog resets the module if the execution time of one loop/function is greater than 4 s. In OS 2 you will be able to increase that delay.
Generally you have to use state machines with OpenAT. It is a little more complicated to conceive but it also has some advantages. If you don’t want that you can always use OpenLua, it allows blocking functions and is sort of multi-threaded.
I don’t have any experience with OS 2 beta, but generally beta releases are not stable. Plus DOTA 2 seems to be impossible from 663b. I hope they will fix that in the final release.




look what wavecom says about “Open AT® OS for Wireless Microprocessors”

“OPEN AT® OS: a Pre-emptive Multitasked Event Based Real-Time OS”, really ? what multitasking they are talking about ? is there any multi tasking related functions in adl api before beta OS 2.0 ? Is it really “real-time” without process-scheduling ?

Itried Beta OS 2.0, a complete failure. Still datahandler are not working in another thread or not as interrupts…

The only breaking difference from 4.x is so called “Pre-emptive” multitasking. (IMHO)

From Multitasking_Timers sample :

// Just sleep some time
    // Shall be preempted there, during the sleep
    adl_ctxSleep ( ADL_TMR_100MS_TO_TICK ( MAIN_TASK_SLEEP ) );

if I have to put a thread to sleep for multitasking, that is called “cooperative” multitasking , not “Pre-emptive”.

It’s also strange that no posts about new beta. It seems “stable” to test new features (9th release ??), and it seems only me using it.

Anyone having problems with “adl_ctxsleep” function, that context does not resume executing after duration exceeds ??