Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
alexru
PostPosted: Mar 01, 2012 - 11:53 PM
Raving lunatic


Joined: Apr 15, 2009
Posts: 4861
Location: San Jose, CA

First of all you need to understand if you really need this. In majority of cases you don't. Then you can't just change the state like this, you need to draw a state machine diagram and see how this transition fits into it. For example in this case usartBytesReceived() can be called multiple times before "case APP_HANDLE_BYTES:" is executed, that means that "//receive USART Bytes here" should use some kind of buffer with accumulation (like FIFO) and not just overwrite previous data.

State machine approach looks like this:


Code:

static void usartRxCallback(uint16_t bytes)
{
  uint8_t data;

  for (uint8_t i = 0; i < bytes; i++)
  {
    HAL_ReadUsart(&usartDescriptor, &data, 1);

    switch (smState)
    {
      case INITIAL_STATE:
      {
        if (data == START_SYMBOL)
          smState = NEXT_STATE;
      } break;

      case NEXT_STATE:
      {
        // ....
      } break;
    }
  }
}


Again, in order to take all possible cases into account you need to draw your state machine on the paper, it is impossible to cut corners here.

_________________
The opinions and views expressed by me on this forum are my own and do not represent my employer or anyone else that I’m affiliated with.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
firebee
PostPosted: Mar 05, 2012 - 10:58 AM
Wannabe


Joined: Jun 08, 2011
Posts: 84


Code:
void usartBytesReceived(uint16_t bytesReceived)
{
    //receive USART Bytes here
   
   appState=APP_HANDLE_BYTES;                         
   SYS_PostTask(APL_TASK_ID);   
 }   


switch (appState)
{
    case APP_HANDLE_BYTES:
    handleReceivedUSARTBytes();   
    break;
}


I think in this application, your are just changing the application state and posting the task to handler. You are not reading the data from the buffer within the usartBytesReceived().
Posting the task is deferred execution, so in this case there is chance that your usart buffer might be overwritten before control coming to "case APP_HANDLE_BYTES:"

So I think this will be a better implementation :
Code:

void usartBytesReceived(uint16_t bytesReceived)
{
    //receive USART Bytes here
   
    handleReceivedUSARTBytes();     
 }
 
 View user's profile Send private message  
Reply with quote Back to top
guitero
PostPosted: Mar 09, 2012 - 11:55 AM
Wannabe


Joined: Feb 03, 2012
Posts: 74
Location: Oldenburg

Thanks for your answers. I finally managed the USART communication.
This time a have a general question.

Can a router join a ZigBee network if the coordinator is gone?

Example:
Power on First device: Coordinator.
Then power another device that joins the network as first router. If I a second Router is joined
it applies to the first Router if the distance to the coordinator is long enough. If I switch off
the coordinator I can't add another Router to the network. As far as I have read in the
BitCloud and ZigBee documentation this seems to be the ZigBee Standard.
What is to do corresponding to the ZigBee specification if this happens. In other words:
which workarounds does the BitCloud offer to solve this problem?
I know that the coordinator can rejoin the network if it uses a given PAN ID. But until this happens is there no way to apply routers to the network?

Thanks!
 
 View user's profile Send private message  
Reply with quote Back to top
alexru
PostPosted: Mar 09, 2012 - 04:39 PM
Raving lunatic


Joined: Apr 15, 2009
Posts: 4861
Location: San Jose, CA

If you don't use security and the first router will not leave the network before second one is joining then the second one will join.

In WSNDemo if R detects that C is missing then it will leave the network, for example.

_________________
The opinions and views expressed by me on this forum are my own and do not represent my employer or anyone else that I’m affiliated with.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
guitero
PostPosted: Mar 09, 2012 - 06:06 PM
Wannabe


Joined: Feb 03, 2012
Posts: 74
Location: Oldenburg

Thanks. So ZigBee does not intend that a Router becomes a Coordinator or the Coordinator is reintegrated in the network? If the coordinator is powered off, the whole network should shut-down?
 
 View user's profile Send private message  
Reply with quote Back to top
alexru
PostPosted: Mar 09, 2012 - 06:14 PM
Raving lunatic


Joined: Apr 15, 2009
Posts: 4861
Location: San Jose, CA

What if you have 50 routers, which one should become a coordinator? Coordinator also holds network management information; and there is no way for the router that wants to be a coordinator to get this information, so it is even theoretically impossible.

Basically yes, network can't operate without a coordinator. In some cases it is possible to have network of routers without a coordinator.

_________________
The opinions and views expressed by me on this forum are my own and do not represent my employer or anyone else that I’m affiliated with.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
guitero
PostPosted: Mar 14, 2012 - 04:00 PM
Wannabe


Joined: Feb 03, 2012
Posts: 74
Location: Oldenburg

Hello,
I have another problem with routers, especially with the neighbor-table.
Let's suppose that t a Coord. and two Routers are in the Network. All devices are in each others range.

Settings on every device:
CS_MAX_CHILDREN_AMOUNT 1
CS_MAX_CHILDREN_ROUTER_AMOUNT 1

As far as I have understand every device can now have one Router as a child. I have no enddevices.

Scenario:
I start the Coord. and Router1 and R1 applies to the Coord. If I start Router2 the ZDO_MgmtNwkUpdateNotf() Callback on
Router 1 is invoked. Thus I think that R2 has connected to R1.

If I have a look at the neighbor-table only the address of R1 is listed. I disconnected R1 and no messages from the coordinator were
delivered to R2, as it should be.

If I start again with "Scenario:" and wait for about 20 seconds both addresses (of R2 and R1) are in the neighbor-table of the coordinator.

Which brings me to my questions:

1. Is R1 no longer a child of R2?
2. If not, it must be a child-router of the Coord, but that device can only have 1 child-router.

Hope it's not too confusing.
 
 View user's profile Send private message  
Reply with quote Back to top
alexru
PostPosted: Mar 14, 2012 - 04:06 PM
Raving lunatic


Joined: Apr 15, 2009
Posts: 4861
Location: San Jose, CA

Routers are not children, as soon as they joined through the parent they on their own (after 15 seconds - Link Status interval). CS_MAX_CHILDREN_ROUTER_AMOUNT just sets how many routers can join within this 15 seconds interval.

_________________
The opinions and views expressed by me on this forum are my own and do not represent my employer or anyone else that I’m affiliated with.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
guitero
PostPosted: Mar 14, 2012 - 04:24 PM
Wannabe


Joined: Feb 03, 2012
Posts: 74
Location: Oldenburg

Thanks for your quick answer.
1. But what if I want to control the amount of devices that can apply to a Router or Coordinator.
2.How will a Router decide to which neighbor it logs on. Just the nearest with the best connection?
 
 View user's profile Send private message  
Reply with quote Back to top
alexru
PostPosted: Mar 14, 2012 - 04:25 PM
Raving lunatic


Joined: Apr 15, 2009
Posts: 4861
Location: San Jose, CA

1. What do you mean by "apply"? What do you need this for?
2. Best link quality.

_________________
The opinions and views expressed by me on this forum are my own and do not represent my employer or anyone else that I’m affiliated with.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
guitero
PostPosted: Mar 14, 2012 - 04:39 PM
Wannabe


Joined: Feb 03, 2012
Posts: 74
Location: Oldenburg

I'm sorry for my english.
1) I meant how to control how many Routers can register to another device.

Quote:
What do you need this for?

At the moment nothing special. But I was asking myself how to implement a specific topology in the BitCloud. If I want to build a tree for example it would be useful to allocate a certain number of enddevices to a specific router. Or a specific number of routers to another router.
How can the BitCloud differ between tree and meshed network?
 
 View user's profile Send private message  
Reply with quote Back to top
alexru
PostPosted: Mar 14, 2012 - 04:42 PM
Raving lunatic


Joined: Apr 15, 2009
Posts: 4861
Location: San Jose, CA

BitCloud implements ZigBee PRO specification and ZigBee PRO specification mandates use of mesh, you can't force tree on it.

End Devices, on the other hand, connect to a parent permanently, so you can control the amount of EDs connected to a router.

_________________
The opinions and views expressed by me on this forum are my own and do not represent my employer or anyone else that I’m affiliated with.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
guitero
PostPosted: Mar 14, 2012 - 04:46 PM
Wannabe


Joined: Feb 03, 2012
Posts: 74
Location: Oldenburg

alexru wrote:
BitCloud implements ZigBee PRO specification and ZigBee PRO specification mandates use of mesh, you can't force tree on it.


Okay, didn't know that ZigBee PRO only uses meshed networks. Thanks a lot for your professional answers.
 
 View user's profile Send private message  
Reply with quote Back to top
guitero
PostPosted: Mar 15, 2012 - 03:03 PM
Wannabe


Joined: Feb 03, 2012
Posts: 74
Location: Oldenburg

Hey,

there's a question about the states in the BitCloud.

Let's suppose the Software is in a state called SENDING and sends a message
with APS_DataReq(). After that no Sys_PostTask() is called.
Now the applicaton remains in the state SENDING.
1. Isn't it possible now that another Callback or ISR with higher priority is invoked before the MessageConf() Callback is invoked?
2. Thus when the MessageConf() finally is invoked the application could be in another state than SENDING?
I asked that because some programs have sub-states e.g. TRANSMISSION_BUSY while the main-State is JOINED or something like that.
 
 View user's profile Send private message  
Reply with quote Back to top
alexru
PostPosted: Mar 15, 2012 - 03:04 PM
Raving lunatic


Joined: Apr 15, 2009
Posts: 4861
Location: San Jose, CA

Yes, of course it is possible. The only reason why callbacks exists is to give other tasks time while this one is waiting.

_________________
The opinions and views expressed by me on this forum are my own and do not represent my employer or anyone else that I’m affiliated with.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
guitero
PostPosted: Mar 15, 2012 - 03:13 PM
Wannabe


Joined: Feb 03, 2012
Posts: 74
Location: Oldenburg

The Background of this question is that I have implemented a PCINT for the key button on my board. Within the ISR of the PCINT I activate the Timer-Interrupt (40ms). If it is called four times the button is considered as pressed. In the JOINED state I frequently request if a button is pressed.

Code:
case APP_NETWORK_JOINED_STATE:

   if( get_key_press( 1<<BUTTON ))//if a key push is recognized
   {
      TIMSK5 &= (0<<TOIE5); //...deactivate Timer-Int         
      
      //do something

   }      

   appState=APP_NETWORK_JOINED_STATE;
   SYS_PostTask(APL_TASK_ID);     

break;


But the ISR is not controlled by the BitCloud, so could it be invoked anytime? For example while the stack is busy with another function? Do I have to make some restrictions? So far the application works as expected
 
 View user's profile Send private message  
Reply with quote Back to top
alexru
PostPosted: Mar 15, 2012 - 03:20 PM
Raving lunatic


Joined: Apr 15, 2009
Posts: 4861
Location: San Jose, CA

Correct way of handling this is presented in file buttons.c in BSP (it uses IRQ interrupts, but principle is the same).

In this case I'd do the following: run application timer with short interval (20-40 ms) and in application timer event handler read the state of the pin your button connected to. Now if 4 times in a row there is press detected then check if state is JOINED and post application task. This way you will not be actively polling.

_________________
The opinions and views expressed by me on this forum are my own and do not represent my employer or anyone else that I’m affiliated with.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
guitero
PostPosted: Mar 15, 2012 - 03:29 PM
Wannabe


Joined: Feb 03, 2012
Posts: 74
Location: Oldenburg

Thanks for your advice! Sounds good to me.
But what about the PC-Interrupt itself.As far as I have understand callbacks can't be interrupted if they are within the time-limit. But the PCINT has no restrictions and could interrupt a callback function.
 
 View user's profile Send private message  
Reply with quote Back to top
alexru
PostPosted: Mar 15, 2012 - 03:31 PM
Raving lunatic


Joined: Apr 15, 2009
Posts: 4861
Location: San Jose, CA

Everything can be interrupted by the interrupt. That's why you need to pay attention and don't put heavy code in the interrupt. Generally it means: set some flag and post task and let application code do the rest.

_________________
The opinions and views expressed by me on this forum are my own and do not represent my employer or anyone else that I’m affiliated with.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
guitero
PostPosted: Mar 15, 2012 - 03:39 PM
Wannabe


Joined: Feb 03, 2012
Posts: 74
Location: Oldenburg

alexru wrote:
Everything can be interrupted by the interrupt.


Yes, that was my concern. It's no heavy code in the interrupt. But I wasn't sure how critical this is.
Thanks for your solution.
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits