1 second timer example

Hi Mark,

When the call is over, you will receive the event ADL_CALL_EVENT_HANGUP_OK. From this event, you can print the value of the variable which was incremented from the timer. As you have made the variable, a global variable, hence, you can access the value of this variable from any function or case statement.

I am not sure if this is the exact problem that you are experiencing. Please let me know if this is the problem that you are asking for.

Best Regards,
Open AT Fan.

Hi openAt_Fan,

I never reach this part and there is no hangup. Also, look at the trace after second call. I have tryed different ways to test all of this and those are the results.

case ADL_CALL_EVENT_RING_VOICE:
adl_atSendResponse ( ADL_AT_UNS, "\r\n you are in ring " );}
adl_callAnswer();
break;  

case ADL_CALL_EVENT_HANGUP_OK:
TRACE (( 7, "Hangup OK" )); 
if (myCount <  5){ adl_atSendResponse ( ADL_AT_UNS, "\r\n - under -\r\n" );}
if (myCount == 5){ /* something */ }           
if (myCount >  5){ adl_atSendResponse ( ADL_AT_UNS, "\r\n - over - \r\n" );} 
TRACE((1,"The call was made for %d minutes",myCount)); 
break;

Result:
+WIND: 13
+WIND: 12,0

App init
RING,RING
i hangup, NO CARRIER

If i remove the adl_callAnswer(); then i get this:
+WIND: 13
+WIND: 12,0

App init
RING,RING
i hangup and nothing happens… if i call again, the story is the same.

Basicly, i never get to hangup part and this is not all. Im not sure if the timer is counting becuse i have made call, hangup, call, hangup and look what’s happening in the trace ( subscribe, unsubscribe ).

Trace:
Trace CUS4 30 [ADL PORT] subs (00212661) : 0
Trace CUS4 20 [ADL] tmr subs ; id 0 ; hdlr 00211085 ; val 10 ; cycl 0
Trace CUS4 30 [ADL PORT] event : 0 (port 80 ; state 0)
Trace CUS4 30 [ADL PORT] event : 0 (port 01 ; state 0)
Trace CUS4 22 [ADL] flash subs 1 : -4
Trace CUS4 22 Flh Obj 0000 Len : 4
Trace CUS4 22 Read Flh Obj 0000 (4) : 0
Trace CUS4 30 SIM subs 00211E81
Trace CUS4 30 SIM subs 0021020D
Trace CUS4 27 Call subs 00210225 : 0
Trace CUS4 20 [ADL] tmr subs ; id 1 ; hdlr 00216D75 ; val 5 ; cycl 0
Trace CUS4 20 [ADL] tmr subs ; id 2 ; hdlr 00216D75 ; val 5 ; cycl 0
Trace CUS4 20 [ADL] tmr subs ; id 3 ; hdlr 00216D75 ; val 5 ; cycl 0
Trace CUS4 20 [ADL] tmr subs ; id 4 ; hdlr 00216D75 ; val 5 ; cycl 0
Trace CUS4 30 SIM event 2
Trace CUS4 30 SIM event 5
Trace CUS4 20 [ADL] tmr subs ; id 5 ; hdlr 00213C89 ; val 30 ; cycl 0
Trace CUS4 20 [ADL] tmr unsubs ; id 5 ; hdlr 00213C89 (rem. time : 1)
Trace CUS4 20 [ADL] tmr subs ; id 6 ; hdlr 00213C89 ; val 30 ; cycl 0
Trace CUS4 30 SIM event 3
Trace CUS4 20 [ADL] tmr subs ; id 7 ; hdlr 00213C89 ; val 30 ; cycl 0
Trace CUS4 20 [ADL] tmr unsubs ; id 7 ; hdlr 00213C89 (rem. time : 1)
Trace CUS4 20 [ADL] tmr subs ; id 8 ; hdlr 00213C89 ; val 30 ; cycl 0
Trace CUS4 20 [ADL] tmr unsubs ; id 8 ; hdlr 00213C89 (rem. time : 1)
Trace CUS4 20 [ADL] tmr subs ; id 9 ; hdlr 00213C89 ; val 30 ; cycl 0

Please copy/paste my last posted code and when you have time, try to compile it on your target and let me know if there is some solution on this.

Mark

This is the changed code. The code is working fine, but the error is still the same. Look at the terminal part. Any clue ?

#include "adl_global.h"
const u16 wm_apmCustomStackSize = 1024;
adl_tmr_t *setTimer;
u16 myCount;
//-------------------------------------------------------

void timerHandler (u8 id)               
{  TRACE (( 4, "A second over" ));
    myCount++;
}

void stopTimer()
{
adl_tmrUnSubscribe(setTimer,(adl_tmrHandler_t)timerHandler,ADL_TMR_TYPE_100MS);
setTimer = NULL;
}

s8 Call_Handler(u16 Event, u32 Call_ID)
{
s8 sReturn;
ascii buffer[60];
sReturn = ADL_CALL_FORWARD;                   
TRACE((1,"Event is %d",Event));
switch (Event)
{
  case ADL_CALL_EVENT_ANSWER_OK: 
  break;
  //-------------------------------------------------------------------------
case ADL_CALL_EVENT_HANGUP_OK:
case ADL_CALL_EVENT_HANGUP_OK_FROM_EXT:
case ADL_CALL_EVENT_NO_CARRIER:
case ADL_CALL_EVENT_RELEASE_ID:
stopTimer();
TRACE((1,"Number of seconds for call is %d\r\n",myCount));
wm_sprintf(buffer,"Call duration = %d seconds", myCount);
adl_atSendResponse(ADL_AT_RSP,buffer);
if (myCount <  5)
{
adl_atSendResponse ( ADL_AT_RSP, "\r\n - under -\r\n" );
myCount=0;
}
if (myCount == 5)
{
myCount = 0;
}     
if (myCount >  5)
{ adl_atSendResponse ( ADL_AT_UNS, "\r\n - over - \r\n" );myCount=0;
}
break;
//------------------------------------------------------------------------------------------
case ADL_CALL_EVENT_RING_VOICE:
TRACE (( 7, "Ring OK" ));
TRACE (( 2, "Call OK" ));
if (!setTimer)
{
setTimer=(adl_tmr_t *)adl_tmrSubscribe,(TRUE,10,ADL_TMR_TYPE_100MS,(adl_tmrHandler_t)timerHandler);
break;
}
}
return sReturn;
}

void adl_main ( adl_InitType_e InitType )
{
myCount=0;
adl_callSubscribe(Call_Handler);           
}

Terminal:
OK
RING
RING
RING
RING
RING
RING
Call duration = 0 seconds

  • under -

The reply should be: call duration 6 seconds - over-

Trace:
Trace HWL 1 Unable to find the string of the remote trace in the file (ID = 869673)
Trace HWL 1 Unable to find the string of the remote trace in the file (ID = 869674)
Trace HWL 1 Unable to find the string of the remote trace in the file (ID = 869673)
Trace HWL 1 Unable to find the string of the remote trace in the file (ID = 869674)
Trace ATI 1 Unable to find the string of the remote trace in the file (ID = 866964)
Trace HWL 1 Unable to find the string of the remote trace in the file (ID = 869517)
Trace CUS4 30 [ADL PORT] subs (0021217D) : 0
Trace CUS4 20 [ADL] tmr subs ; id 0 ; hdlr 00210BA1 ; val 10 ; cycl 0
Trace CUS4 30 [ADL PORT] event : 0 (port 80 ; state 0)
Trace CUS4 30 [ADL PORT] event : 0 (port 01 ; state 0)
Trace CUS4 22 [ADL] flash subs 1 : -4
Trace DEV 1 Unable to find the string of the remote trace in the file (ID = 878588)
Trace DEV 1 Unable to find the string of the remote trace in the file (ID = 878588)
Trace DEV 1 Unable to find the string of the remote trace in the file (ID = 878588)
Trace DEV 1 Unable to find the string of the remote trace in the file (ID = 878588)
Trace DEV 1 Unable to find the string of the remote trace in the file (ID = 878588)
Trace CUS4 22 Flh Obj 0000 Len : 4
Trace CUS4 22 Read Flh Obj 0000 (4) : 0
Trace CUS4 30 SIM subs 0021199D
Trace CUS4 27 Call subs 00210075 : 0
Trace CUS4 20 [ADL] tmr subs ; id 1 ; hdlr 00216891 ; val 5 ; cycl 0
Trace CUS4 20 [ADL] tmr subs ; id 2 ; hdlr 00216891 ; val 5 ; cycl 0
Trace CUS4 20 [ADL] tmr subs ; id 3 ; hdlr 00216891 ; val 5 ; cycl 0
Trace CUS4 20 [ADL] tmr subs ; id 4 ; hdlr 00216891 ; val 5 ; cycl 0
Trace CUS4 30 SIM event 2
Trace CUS4 30 SIM event 6
Trace CUS4 30 SIM event 5
Trace L3RR 1 Unable to find the string of the remote trace in the file (ID = 874706)
Trace L3RR 1 Unable to find the string of the remote trace in the file (ID = 875186)
Trace L3RR 1 Unable to find the string of the remote trace in the file (ID = 875186)
Trace CUS4 20 [ADL] tmr subs ; id 5 ; hdlr 002137A5 ; val 30 ; cycl 0
Trace CUS4 1 Event is 0
Trace CUS4 7 Ring OK
Trace CUS4 2 Call OK
Trace CUS4 20 [ADL] tmr unsubs ; id 5 ; hdlr 002137A5 (rem. time : 1)
Trace CUS4 20 [ADL] tmr subs ; id 6 ; hdlr 002137A5 ; val 30 ; cycl 0
Trace CUS4 1 Event is 0
Trace CUS4 7 Ring OK
Trace CUS4 2 Call OK
Trace CUS4 20 [ADL] tmr unsubs ; id 6 ; hdlr 002137A5 (rem. time : -1)
Trace CUS4 20 [ADL] tmr subs ; id 7 ; hdlr 002137A5 ; val 30 ; cycl 0
Trace CUS4 1 Event is 0
Trace CUS4 7 Ring OK
Trace CUS4 2 Call OK
Trace CUS4 20 [ADL] tmr unsubs ; id 7 ; hdlr 002137A5 (rem. time : 1)
Trace CUS4 20 [ADL] tmr subs ; id 8 ; hdlr 002137A5 ; val 30 ; cycl 0
Trace CUS4 1 Event is 0
Trace CUS4 7 Ring OK
Trace CUS4 2 Call OK
Trace CUS4 1 Event is 3
Trace CUS4 20 [ADL] tmr unsubs ; id 181 ; hdlr 0021003D (rem. time : -1)
Trace CUS4 1 Number of seconds for call is 0
Trace CUS4 30 SIM event 3

Hi Mark !

I dont know if you have written everything from your trace, but i don’t see the 1 second timer subscription…

And :

if (!setTimer) 
{ 
setTimer=(adl_tmr_t *)adl_tmrSubscribe,(TRUE,10,ADL_TMR_TYPE_100MS,(adl_tmrHandler_t)timerHandler); 
break; 
}

i dont think that “if(!setTimer)” condition is correct, as setTimer is a pointer to the timer…

Hope it helps

Hi.
Yes i have copy, pasted the whole trace.
I removed the if (!setTimer) part and the result is the same.

It looks like that the timer is subscribed but never started.
I have no idea…

Well, only one thing and it will work :

setTimer=(adl_tmr_t *)adl_tmrSubscribe,(TRUE,10,ADL_TMR_TYPE_100MS,(adl_tmrHandler_t)timerHandler);

As you can see, there is a coma (",") after the “adl_tmrSubscribe”… remove it and it will work better…

Another thing, put a boolean in ur condition to avoid a timer subscritption on every RING.

if (!isTimerRunning) 
{
  isTimerRunning=TRUE;
  setTimer=adl_tmrSubscribe(TRUE,10,ADL_TMR_TYPE_100MS,timerHandler); 
  break; 
}


void stopTimer() 
{ 
  if(isTimerRunning)
  {
     isTimerRunning=FALSE;
     adl_tmrUnSubscribe(setTimer,timerHandler,ADL_TMR_TYPE_100MS); 
     setTimer = NULL;
  }
}

Of course, isTimerRunning must be global

RING
RING
RING
Call duration = 15 seconds

  • over -

I think that there is not much else to say accept
:stuck_out_tongue: :smiley: :wink:

This was the main error in the last posted code. The compiler did not trow any errors and the code was compiled with no warnings.:imp: :angry:

The only problem that im now facing is the ( i guess ) myCount var or timer overflow definition.
Becuse, if you make call for cca 2 seconds, you get : Call duration = 4125 seconds ?

Mark

You said you were an experienced MCU programmer - so you should be used to this kind of thing in ‘C’ ! :wink:

Remember that the Comma can be an operator in ‘C’ - as well as the separator between function arguments… :open_mouth:

awneil, you suprise my always again with your comments :astonished: .
Instead to give some example solution, some tested code you write some comment that has nothing to do with main problem, until this problem is solved. But anyway, i guess that’s just you :smiley: .

Please take this as frendly comment. :stuck_out_tongue::roll:

Regarding to your comment on MCU and emb. I dont know if you are in those waters but when you have time, test some quality c compilers (Hi-tec, ImageCraft, etc. ) and then you will see what im talking about.

Now, your reaction on this should be:
OK, the guy has right, lets see how i can help him in openAT and why is he getting 4125 second instead 2 seconds. :mrgreen:

Hi !

U should start with displaying myCount in the trace on every myCount incrementation :

void timerHandler (u8 id)                
{  
    myCount++; 
    TRACE (( 4, "A second over, nb seconds till now : %u", myCount )); 
}

This will gives you more information on what’s really happening…

Hi !
I have copyed whole trace output and it looks like if the timer is started after hangup…? The counting is continued until i reset the target.

This is the trace output:

1385.536 Trace 1 Unable to find the string of the remote trace in the file (ID = 869673)
1385.536 Trace 1 Unable to find the string of the remote trace in the file (ID = 869674)
1385.536 Trace 1 Unable to find the string of the remote trace in the file (ID = 869673)
1385.536 Trace 1 Unable to find the string of the remote trace in the file (ID = 869674)
1385.536 Trace 1 Unable to find the string of the remote trace in the file (ID = 866964)
1385.536 Trace 1 Unable to find the string of the remote trace in the file (ID = 869517)
1385.536 Trace 30 [ADL PORT] subs (00212769) : 0
1385.536 Trace 20 [ADL] tmr subs ; id 0 ; hdlr 0021118D ; val 10 ; cycl 0
1385.536 Trace 30 [ADL PORT] event : 0 (port 80 ; state 0)
1385.536 Trace 30 [ADL PORT] event : 0 (port 01 ; state 0)
1385.625 Trace 22 [ADL] flash subs 1 : -4
1385.625 Trace 1 Unable to find the string of the remote trace in the file (ID = 878588)
1385.625 Trace 1 Unable to find the string of the remote trace in the file (ID = 878588)
1385.625 Trace 1 Unable to find the string of the remote trace in the file (ID = 878588)
1385.625 Trace 1 Unable to find the string of the remote trace in the file (ID = 878588)
1385.625 Trace 1 Unable to find the string of the remote trace in the file (ID = 878588)
1385.625 Trace 22 Flh Obj 0000 Len : 4
1385.625 Trace 22 Read Flh Obj 0000 (4) : 0
1385.625 Trace 30 SIM subs 00211F89
1385.625 Trace 30 SIM subs 00210231
1385.625 Trace 27 Call subs 002102CD : 0
1385.625 Trace 20 [ADL] tmr subs ; id 1 ; hdlr 00216E7D ; val 5 ; cycl 0
1385.625 Trace 20 [ADL] tmr subs ; id 2 ; hdlr 00216E7D ; val 5 ; cycl 0
1385.626 Trace 20 [ADL] tmr subs ; id 3 ; hdlr 00216E7D ; val 5 ; cycl 0
1385.626 Trace 20 [ADL] tmr subs ; id 4 ; hdlr 00216E7D ; val 5 ; cycl 0
1385.714 Trace 30 SIM event 2
1385.714 Trace 30 SIM event 5
1385.714 Trace 1 Unable to find the string of the remote trace in the file (ID = 875186)
1385.714 Trace 1 Unable to find the string of the remote trace in the file (ID = 875186)
1385.714 Trace 20 [ADL] tmr subs ; id 5 ; hdlr 00213D91 ; val 30 ; cycl 0
1385.714 Trace 1 Event is 0
1385.714 Trace 7 Ring OK
1385.714 Trace 2 Call OK
1385.714 Trace 20 [ADL] tmr subs ; id 6 ; hdlr 00210291 ; val 100 ; cycl 1
1385.714 Trace 20 [ADL] tmr unsubs ; id 5 ; hdlr 00213D91 (rem. time : -1)
1385.714 Trace 20 [ADL] tmr subs ; id 7 ; hdlr 00213D91 ; val 30 ; cycl 0
1385.714 Trace 1 Event is 0
1385.714 Trace 7 Ring OK
1385.714 Trace 2 Call OK
1385.714 Trace 20 [ADL] tmr subs ; id 8 ; hdlr 00210291 ; val 100 ; cycl 1
1385.714 Trace 20 [ADL] tmr unsubs ; id 7 ; hdlr 00213D91 (rem. time : 1)
1385.714 Trace 20 [ADL] tmr subs ; id 9 ; hdlr 00213D91 ; val 30 ; cycl 0
1385.714 Trace 1 Event is 0
1385.730 Trace 7 Ring OK
1385.730 Trace 2 Call OK
1385.730 Trace 20 [ADL] tmr subs ; id 10 ; hdlr 00210291 ; val 100 ; cycl 1
1388.094 Trace 20 [ADL] tmr unsubs ; id 9 ; hdlr 00213D91 (rem. time : 1)
1388.094 Trace 20 [ADL] tmr subs ; id 11 ; hdlr 00213D91 ; val 30 ; cycl 0
1388.094 Trace 1 Event is 0
1388.094 Trace 7 Ring OK
1388.094 Trace 2 Call OK
1388.094 Trace 20 [ADL] tmr subs ; id 12 ; hdlr 00210291 ; val 100 ; cycl 1
1389.393 Trace 4 A second over, nb seconds till now : 0
1390.910 Trace 1 Event is 3
1390.910 Trace 20 [ADL] tmr unsubs ; id 12 ; hdlr 00210291 (rem. time : 71)
1390.910 Trace 1 Number of seconds for call is 1
1392.287 Trace 4 A second over, nb seconds till now : 0
1394.261 Trace 30 SIM event 3
1395.167 Trace 4 A second over, nb seconds till now : 1
1399.393 Trace 4 A second over, nb seconds till now : 2
1402.277 Trace 4 A second over, nb seconds till now : 3
1405.153 Trace 4 A second over, nb seconds till now : 4
1409.373 Trace 4 A second over, nb seconds till now : 5
1412.264 Trace 4 A second over, nb seconds till now : 6
1415.141 Trace 4 A second over, nb seconds till now : 7
1419.362 Trace 4 A second over, nb seconds till now : 8
1422.244 Trace 4 A second over, nb seconds till now : 9
1425.119 Trace 4 A second over, nb seconds till now : 10

Its counting all the time, till the new reset.

Terminal:

+WIND: 12,0
+WIND: 12,1

RING
RING
RING
RING
RING
Call duration = 1 seconds

  • under -

Well, i’m not sure but i think you’re subscribing to the timer on every ring… have you set a boolean in timer subscription/unsubscription ??

1385.714 Trace 1 Event is 0
1385.714 Trace 7 Ring OK
1385.714 Trace 2 Call OK
1385.714 Trace 20 [ADL] tmr subs ; id 6 ; hdlr 00210291 ; val 100 ; cycl 1
1385.714 Trace 20 [ADL] tmr unsubs ; id 5 ; hdlr 00213D91 (rem. time : -1)
1385.714 Trace 20 [ADL] tmr subs ; id 7 ; hdlr 00213D91 ; val 30 ; cycl 0
1385.714 Trace 1 Event is 0
1385.714 Trace 7 Ring OK
1385.714 Trace 2 Call OK
1385.714 Trace 20 [ADL] tmr subs ; id 8 ; hdlr 00210291 ; val 100 ; cycl 1
1385.714 Trace 20 [ADL] tmr unsubs ; id 7 ; hdlr 00213D91 (rem. time : 1)
1385.714 Trace 20 [ADL] tmr subs ; id 9 ; hdlr 00213D91 ; val 30 ; cycl 0
1385.714 Trace 1 Event is 0
1385.730 Trace 7 Ring OK
1385.730 Trace 2 Call OK
1385.730 Trace 20 [ADL] tmr subs ; id 10 ; hdlr 00210291 ; val 100 ; cycl 1
1388.094 Trace 20 [ADL] tmr unsubs ; id 9 ; hdlr 00213D91 (rem. time : 1)
1388.094 Trace 20 [ADL] tmr subs ; id 11 ; hdlr 00213D91 ; val 30 ; cycl 0
1388.094 Trace 1 Event is 0
1388.094 Trace 7 Ring OK
1388.094 Trace 2 Call OK
1388.094 Trace 20 [ADL] tmr subs ; id 12 ; hdlr 00210291 ; val 100 ; cycl 1
1389.393 Trace 4 A second over, nb seconds till now : 0
1390.910 Trace 1 Event is 3
1390.910 Trace 20 [ADL] tmr unsubs ; id 12 ; hdlr 00210291 (rem. time : 71)

I edited this and guess what… :smiley:

The code is running perfect !
THANK YOU ( openAT_Fan, awneil, colin-tfe and others)!