Loop problem

#include "adl_global.h"
u32 wm_apmCustomStack [ 256 ];
const u16 wm_apmCustomStackSize = sizeof ( wm_apmCustomStack );
u8 go=0;
bool Wind4_Handler(adl_atUnsolicited_t *paras)
    adl_atUnSoUnSubscribe("+WIND: 4",(adl_atUnSoHandler_t)Wind4_Handler);
    return FALSE;
void adl_main ( adl_InitType_e InitType )
    adl_atSendResponse ( ADL_AT_UNS, "\r\nMain\r\n" );
    adl_atUnSoSubscribe("+WIND: 4",(adl_atUnSoHandler_t)Wind4_Handler);
    while (!go);
    adl_atSendResponse ( ADL_AT_UNS, "\r\nWIND4\r\n" );

This program with the while loop don’t write the string “Main” and put the module in stale.
Without the while loop the program work fine.
It’s normal?


Your program will loop forever in this loop:

while (!go);

because the “+WIND 4” capture is never subscribed
some APIs are really executed after you have returned, esp. those invloving assinging ‘handlers’

Your adl_main should do :

  • Subscribe “+WIND: 4” to your Wind4_Handler
  • Subscribe a looping timer (e.g. 100ms) to a go_handler, say
  • then retrun

This go_handler should:

  • check if !go, then return
  • check if go , then stop timer and continue…

This is true only for the adl_main or even for the handler functions?



I suggest, forget loops in Open At baceuse the Watchdog Timer will reset the module after a time.
I experienced, that some commands don’t like calling after itself.
Use timers everywhere, the program will benefit it.


No. Not just adl_main

You may do a simple experiment :

void adl_main ( adl_InitType_e InitType )
adl_CmdCreate(“ATI3”,TRUE, (adl_atRspHandler)NULL,NULL;
adl_atSendResponse ( ADL_AT_UNS, “\r\nHELLO ALL\r\n” );

compile it and run, you will see the “HELLO ALL” will come out first. You may try on other functions

I agree with tomalex, do not use ‘while’ or big loop with ‘for’ because of the watchdog timer.

The watchdog timer is set to 4.5 seconds (Open AT Development Guide, chapter about security), so if your Open AT application keeps the hand more than 4.5 seconds in a loop then the module resets.

The best way is to use timers to allow the core software to work properly.