• 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 » SimpleLink™ Wi-Fi® » Struct Packing
Share
Low Power RF & Wireless Connectivity
  • Forums
  • Announcements
  • Files
  • E2E Wiki
Options
  • Subscribe via RSS

Struct Packing

Struct Packing

This question is answered
Tim Robbins
Posted by Tim Robbins
on Jun 21 2012 08:13 AM
Prodigy100 points

Hello,

I'm having some problems with the generic CC3000 driver.

I am using a processor that has a 16 bit memory access. Because of this, any 16 bit value (like an unsigned short) must be aligned to a 16 bit address.

For instance this struct is 4 bytes, 2 chars, and 1 short. But my compiler must align the short to a 16 bit address. It also pads out a struct to even number of bytes.

So, for me, this struct is sizeof 6.  This really seems to make everything not work. I don't think I can get my compiler to pack the struct do to the HW design.

Has anyone reworked the code to avoid "sizeof"?

typedef struct _hci_cmnd_hdr_t

{

     unsigned char  ucType;

     unsigned short usOpcode;

     unsigned char  ucLength;

 } hci_cmnd_hdr_t;

 

Thanks,

Tim

 

Report Abuse
  • Reply
You have posted to a forum that requires a moderator to approve posts before they are publicly available.
All Replies
  • Norman Wong
    Posted by Norman Wong
    on Jun 21 2012 08:39 AM
    Guru14920 points

    No experience with your platform. Noticed from your other thread that you are using a MSP430. From posts that I have seen, packed structures are supported the IAR and later versions of the TI compiler. IAR uses pragma PACK. TI's uses GNU style pack sttributes on the structure. GNU support must be enabled.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Tim Robbins
    Posted by Tim Robbins
    on Jun 21 2012 09:59 AM
    Prodigy100 points

    I'm using a Freescale 56F8366 Digital Signal Controller.

    Each memory address is 16 bits. They allow for byte addressing to put 2 8 bit values into a 16 bit memory location, but a 16 bit value must be aligned. So any struct that has an odd number of 8 bit values, followed by a 16 bit value will require a padding byte between them to make sure the 16 bit value is aligned.

    The generic driver code attempts to send a struct by casting it to a unsigned char * and assumes that the structure is laid out in memory without any padding. A recieve also attempts to cast a unsigned char * to a pointer to a structure and assumes the bytes will fall into place.

    When I try it, my sizeof call returns a different value because of the padding. This causes extra bytes to be sent and I assume the LS Research board doesn't know what to do with it. Additionally, when I recieve a packet, the cast to a structure doesn't work and therefore the values in the structure don't make sense. And then of course things don't work.

    This could be solved by properly packing and unpacking the unsigned char buffers to and from the structures instead of blindly casting them and hoping the data is in the right place and order.

    Unless someone can tell me otherwise I think I am looking at either rewriting the driver, or looking elsewhere for a simular solution.

     

    Tim

     

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Norman Wong
    Posted by Norman Wong
    on Jun 21 2012 13:53 PM
    Guru14920 points

    Sounds like you're got firm understanding of the problem. I guess you could try asking Freescale about compiler options. It's more than just alignment. There is always the possibility of an endianess problem. Rewriting the driver for manual unpacking and packing would make the driver easier to port to other processors. Avoiding unaligned accesses also makes for faster code. Some justification.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Tim Robbins
    Posted by Tim Robbins
    on Jun 21 2012 13:59 PM
    Prodigy100 points

    Yup, you're exactly right.

    I guess I would have expected something offered up as a "Platform Independent WiFi Driver" to take some of these things into account.

    I'm hoping someone from TI can point me towards something that I missed.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Alon Srednizki
    Posted by Alon Srednizki
    on Jun 24 2012 05:45 AM
    Suggested Answer
    Expert3205 points

    Hi Tim,

    In our upcoming release we've changed the code to use "streaming" macros in each location that transfers data to\ from the CC3000 to the MCU.
    Basically coping the data byte by byte.
    I believe that this change will solve your porting issue. Sorry for the trouble you've been having so far.

    The release is expected any day now.

    Thanks,
    Alon.S

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Tim Robbins
    Posted by Tim Robbins
    on Jun 25 2012 07:27 AM
    Prodigy100 points

    Thanks Alon,

    It sounds like the new code would be helpful.

    Is there an actualy release day? Or is it possible to get a hold of it prior to release. I'm in the process of evaulating this product, so most of the work I am doing will never make it to an end user.

    Tim

     

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Alon Srednizki
    Posted by Alon Srednizki
    on Jun 25 2012 08:07 AM
    Expert3205 points

    Hi Tim,

    No date yet, please ping the forum by e/o the week, I hope to have more information.

    Thanks,
    Alon.S

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • PaulSchoenke
    Posted by PaulSchoenke
    on Jul 02 2012 11:19 AM
    Genius3260 points

    Hi Alon,

    Just checking in on this one to see if the updated code is available yet.

    Thanks again!

    Paul

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Tim Robbins
    Posted by Tim Robbins
    on Jul 10 2012 08:36 AM
    Prodigy100 points

    Hi Alon,

    Any update on the timing of this new software?

     

    Thanks,

    Tim

     

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Alon Srednizki
    Posted by Alon Srednizki
    on Jul 10 2012 10:49 AM
    Expert3205 points

    Not yet, sorry.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Tim Robbins
    Posted by Tim Robbins
    on Jul 10 2012 10:53 AM
    Prodigy100 points

    Any esitmated date?

    Is there someone else I can contact?

    If not, I will look elsewhere for a wifi solution.

    Tim

     

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Alon Srednizki
    Posted by Alon Srednizki
    on Jul 17 2012 05:46 AM
    Expert3205 points

    Hi Tim,

    Sorry for the delayed response.
    We will release a new package by e/o the month.

    Thanks,
    Alon.S

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Tim Robbins
    Posted by Tim Robbins
    on Aug 06 2012 13:13 PM
    Prodigy100 points

    Hi Alon,

    Any update on this?

    Thanks,

    Tim

     

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Gagan Maur
    Posted by Gagan Maur
    on Aug 14 2012 03:24 AM
    Verified Answer
    Verified by Gagan Maur
    Expert4435 points

    Tim, the new releases is available now and is posted here: 

    http://processors.wiki.ti.com/index.php/CC3000_Wi-Fi_Downloads#CC3000_Wi-Fi_Downloads

    ----------------------------------------------------------------------------------------------------------
    Please click the
    Verify Answer button on this post if it answers your question.
    ----------------------------------------------------------------------------------------------------------

    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