# Loop problem

**URL:** <https://forum.sierrawireless.com/t/loop-problem/96>\
**Category:** Open AT\
**Created:** [October 24, 2005, 2:42pm UTC](https://forum.sierrawireless.com/t/loop-problem/96 "2005-10-24T14:42:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hoodooman](https://avatars.discourse-cdn.com/v4/letter/h/a9adbd/32.png) [@hoodooman](https://forum.sierrawireless.com/u/hoodooman)\
**Post date:** [October 24, 2005, 2:42pm UTC](https://forum.sierrawireless.com/t/loop-problem/96/1 "2005-10-24T14:42:08Z")

</div>

```auto
#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);
    go=1;
    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?

Thanks.

---

<div class="post-metadata">

**Author:** ![Wallace](https://avatars.discourse-cdn.com/v4/letter/w/b4bc9f/32.png) [@Wallace](https://forum.sierrawireless.com/u/Wallace)\
**Post date:** [October 25, 2005, 4:46am UTC](https://forum.sierrawireless.com/t/loop-problem/96/2 "2005-10-25T04:46:12Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![hoodooman](https://avatars.discourse-cdn.com/v4/letter/h/a9adbd/32.png) [@hoodooman](https://forum.sierrawireless.com/u/hoodooman)\
**Post date:** [October 25, 2005, 9:06am UTC](https://forum.sierrawireless.com/t/loop-problem/96/3 "2005-10-25T09:06:11Z")

</div>

> [@Wallace](#):
>
> some APIs are really executed after you have returned, esp. those invloving assinging ‘handlers’

This is true only for the adl\_main or even for the handler functions?

Thanks

---

<div class="post-metadata">

**Author:** ![tomalex](https://avatars.discourse-cdn.com/v4/letter/t/71e660/32.png) [@tomalex](https://forum.sierrawireless.com/u/tomalex)\
**Post date:** [October 25, 2005, 6:21pm UTC](https://forum.sierrawireless.com/t/loop-problem/96/4 "2005-10-25T18:21:43Z")

</div>

@hoodooman

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.

tom

---

<div class="post-metadata">

**Author:** ![Wallace](https://avatars.discourse-cdn.com/v4/letter/w/b4bc9f/32.png) [@Wallace](https://forum.sierrawireless.com/u/Wallace)\
**Post date:** [October 26, 2005, 9:28am UTC](https://forum.sierrawireless.com/t/loop-problem/96/5 "2005-10-26T09:28:30Z")

</div>

> [@hoodooman](#):
>
> > [@Wallace](#):
> >
> > some APIs are really executed after you have returned, esp. those invloving assinging ‘handlers’
> 
> This is true only for the adl\_main or even for the handler functions?
> 
> Thanks

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

---

<div class="post-metadata">

**Author:** ![Jay](https://avatars.discourse-cdn.com/v4/letter/j/ed8c4c/32.png) [@Jay](https://forum.sierrawireless.com/u/Jay)\
**Post date:** [November 3, 2005, 4:12pm UTC](https://forum.sierrawireless.com/t/loop-problem/96/6 "2005-11-03T16:12:25Z")

</div>

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.
