Atmel LightWeight Mesh stack hanging

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

[alexru - I'm creating a topic with the same subject. I don't know what happened, I've tried to delete duplicate post, but entire topic is gone, so whoever asked the last question, please respond here]

The question covered in the topic was - how to prevent device hanging due to repeat calls to NWK_DataReq() without waiting for a confirmation.

Checking application state will help, provided that application changes its state before calling NWK_DataReq() and in the confirmation handler.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

Last Edited: Fri. Oct 16, 2015 - 02:03 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Alex,

I have exactly this mentioned problem, but don´t know how to handle it. Can you explain it in detail with an little example, how to prevent this ?

What can I do here, to check the state?

static void appSendData(void)			
{
.......
nwkDataReq.confirm = appDataConf;		
NWK_DataReq(&nwkDataReq);			
appState = APP_STATE_WAIT_CONF;
}

and here? In which case the confirmation is done?
if (NWK_SUCCESS_STATUS == req->status) ??? What is reg->Status in the case of correct confirmation?

static void appDataConf(NWK_DataReq_t *req)
{
  //HAL_LedOff(LED_DATA);

  if (NWK_SUCCESS_STATUS == req->status)
  {
    if (!appNetworkStatus)
    {
      //HAL_LedOn(LED_NETWORK);
      SYS_TimerStop(&appNetworkStatusTimer);
      appNetworkStatus = true;
    }
  }
  else
  {
    if (appNetworkStatus)
    {
      HAL_LedOff(LED_NETWORK);
      SYS_TimerStart(&appNetworkStatusTimer);
      appNetworkStatus = false;
    }
  }

  appState = APP_STATE_SENDING_DONE;
}

Thank u in advance
Laz

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do something like this:

static void appSendData(void)         
{
  if (APP_STATE_IDLE != appState) // Or whatever your idle state is
    return;
.......
} 

Confirmation is done when appDataConf() is called, no matter what the status is. Note that if you call appSendData() asynchronously and not from a particular state, then you will run into problems with the state machine, because your callbacks change states, which might be not expected by the application. So the best solution is to send though the state change instead of calling appSendData() directly. In that case, when you need to send the data, you check if state machine is in the state, from which it can transition to the sending state (for example, IDLE). If state machine is not in the idle state, you just drop the request. This way state machine itself does the protection and you don't need to worry about it.

Another universal solution, which works even if you don't have any states:

 static bool nwkDataReqBusy = false; // global variable

static void appSendData(void)
{
  if (nwkDataReqBusy)
    return;
  nwkDataReqBusy = true;
.......
}
static void appDataConf(NWK_DataReq_t *req)
{
  nwkDataReqBusy = false;
.......
} 

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey Alex,

thank you very much for the prompt answer.
I will try this and give feedback after testing this solution...
The main idle state in the WSN demo application is APP_STATE_WAIT_SEND_TIMER ???

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, for routers it would be APP_STATE_WAIT_SEND_TIMER.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanx Alex,

I think the problem was solved, after I try something like in the peer2peer demo app (appDataReqBusy). The Application runs stable over hours.
But what happens with the cuurent SendRequest, if the µc is in busystate and we return immediately from appSendData()? Is this request dropped, or would it be send in the next cycle?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There won't be magic, if you don't call NWK_DataReq(), frame won't be sent. The point of waiting for the confirmation is to make sure that you don't call NWK_DataReq() more often than transceiver can handle it.

You will have to adjust your state machine to handle this case (request structure is busy), otherwise it might get stuck in one state.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks, Alex: It solved one of my problems as well. Would you please give some advice on how to use global variable to take data from lwmesh stak to lwip stack so that I can use Tcp to send it to remote server?

Up Hill