• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Low Power RF & Wireless Connectivity » Low Power RF ZigBee® Software & IEEE 802.15.4 Forum » critical section - disable interrupts?
Share
Low Power RF & Wireless Connectivity
  • Forums
  • Announcements
  • Files
  • E2E Wiki
Options
  • Subscribe via RSS

Forums

critical section - disable interrupts?

This question is answered
Jan Bělohoubek
Posted by Jan Bělohoubek
on Mar 20 2012 07:07 AM
Prodigy70 points

Hello,

I'm writing an application for cc2530 and I'm using Z-Stack. Now in my application there is an array of structs.

Any struct in this array can be modified when arrives message from another zigbee device or command from uart. I need to modify hole struct in the same time - atomic operation.

First question: Is good idea to disable interrupts when I operate (replacing data in the structure) with this "big" structure (in the structure there is IEEE address, network address and 1 uint8 flag)? Is there any better option than to disable interrupts while I'm in the critical section in Z-Stack/OSAL?

Second question:  I think that If I would implement simple mutex with "active waiting", it would cause deadlock because of "cooperative round-robin"...like this:

-> incomming uart command:

uart function(){

mutex_lock(x)

.....

->incomming message -> this function interrupted, running incomming_message_function()

....

mutex_unlock(x)

}

incomming message:

incomming_message_function(){

mutex_lock()

waiting for mutex..... -> deadlock

.....

}

...or I'm wrong?

Thank you!

Z-Stack CC2530
Report Abuse
  • Reply
You have posted to a forum that requires a moderator to approve posts before they are publicly available.
All Replies
  • Jan Bělohoubek
    Posted by Jan Bělohoubek
    on Apr 06 2012 08:31 AM
    Prodigy70 points

    Hello, I would like to simplify my question...

    I want to ask you:

    I have an application in Z-Stack. In my application I've data, which can be modified when message from another device arrive or when arrive command thru UART (callback function). This application is fully operational, but I'm not sure with critical sections in Z-Stack.

    Should I handle data modification functions like a "critical section" or functions can't overlap (and every function will finish before another will start)?

    Thank you for reply!

     

    Z-Stack UART Z-Stack 2.3.0 CC2530
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Dirty Harry
    Posted by Dirty Harry
    on Apr 09 2012 17:49 PM
    Verified Answer
    Verified by Dirty Harry
    Mastermind19350 points

     RE: "when message from another device arrive or when arrive command thru UART (callback function)"

    So 2 part answer to your 2 part question:

    1. When data arrives by RF Rx, your Application will eventually receive the data via an OSAL message, namely a 'SYS_EVENT_MSG' with the event as a 'AF_INCOMING_MSG_CMD'. In this case, the memory of the incoming message is completely free from any race or overwrite by any ISR - to be sure, the Application layer owns that memory and must thereby free it as you see in any sample application:

          // Release the memory
          osal_msg_deallocate( (uint8 *)MSGpkt );

     

    2. When data arrives by UART Rx, the Application that opened the UART port gets notified of several important Rx events (like a few bytes of data have been received but are just sitting there with no more coming in,  HAL_UART_RX_TIMEOUT, or so many bytes have been received that the circular receive queue is about to overrun itself if you don't quickly read some out, HAL_UART_RX_ABOUT_FULL). In this case, the Application will read the received bytes out of the circular receive queue via the provided API:

    extern uint16 HalUARTRead ( uint8 port, uint8 *pBuffer, uint16 length );

    The HAL UART driver provided will deconflict any of its local data variables or structures from corruption by an ISR, so the Application does not need to worry about this. Although the data bytes read out could consist of a "message" that may have been corrupted by not reading the bytes out soon enough. Thus, many UART protocols (witness the MT message structure) wrap messages in packtes that have a known start character and a check sequence to ensure message integrity.

     

     

     

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Jan Bělohoubek
    Posted by Jan Bělohoubek
    on Apr 10 2012 04:33 AM
    Prodigy70 points

    Tank you for reply!

    I use my own simple protocol for UART with integrity check, so that's not problem :-)

    I want to ask you, can for example 'HAL_UART_RX_TIMEOUT' event break any 'running function', or the 'running function' will finish before 'HAL_UART_RX_TIMEOUT' will be served?

    I figured from Z-Stack documents, that my 'running function' will finish before another serving function in the app will be executed - is it true? :-)

    Thank you! 

    Z-Stack
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Dirty Harry
    Posted by Dirty Harry
    on Apr 10 2012 10:27 AM
    Verified Answer
    Verified by Dirty Harry
    Mastermind19350 points

    Right - OSAL is just a simple, round-robin, prioritized, loosely cooperative, tasking loop. So you see that you have the opportunity to get a callback on every pass through the loop (the callback would come from within the 'Hal_ProcessPoll()' function):

    void osal_run_system( void )
    {
      uint8 idx = 0;

      osalTimeUpdate();
      Hal_ProcessPoll();

      do {
        if (tasksEvents[idx])  // Task is highest priority that is ready.
        {
          break;
        }
      } while (++idx < tasksCnt);

      if (idx < tasksCnt)
      {

    Thus, a task with a UART callback is essentially "elevated" in priority to be the highest by that callback.

    Your Application task is free to call HalUARTRead() anytime it is running - you may get zero bytes or only the first part of an incoming packet, but no other bad side effects.

     

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Jan Bělohoubek
    Posted by Jan Bělohoubek
    on Apr 15 2012 03:57 AM
    Prodigy70 points

    Thank you!

    I finished before a week, but I wasn't sure that it is 100% OK!

    Thank you for reply! 

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
TI E2E™ Community
  • Support Forums
  • Blogs
  • Videos
  • Groups
  • Site Support & Feedback
  • Settings
TI E2E™ Community Groups
  • TI University Program
  • Make the Switch
  • Microcontroller Projects
  • Motor Drive & Control
Other Communities
  • Deyisupport
  • Designsomething.org
  • beagleboard.org
  • TI on Element 14
  • TI on TechXchangeSM
Other Technical & Support Resources
  • WEBENCH® Design Center
  • Product Information Centers
  • Technical Documents
  • TI Design Network
  • TI Technical Articles
  • TI Training

All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
embedded processors, along with software, tools and the industry’s largest sales/support staff.

© Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy Policy | Terms of Use