CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Is this PIC C-18 Compiler Structure Possible in CCS...?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ChrisL



Joined: 16 Apr 2007
Posts: 26
Location: Arizona

View user's profile Send private message Visit poster's website

Is this PIC C-18 Compiler Structure Possible in CCS...?
PostPosted: Sat Sep 15, 2007 8:42 pm     Reply with quote

I am converting the J1939 PIC-18 Complier code. There is a (Structure inside of a Union) in PIC-C;

Code:
union J1939_MESSAGE_UNION {
   struct {
      unsigned int   PDUFormat_Top      : 3;   // This needs pre and post processing.
      unsigned int   DataPage         : 1;
      unsigned int   Res               : 1;
      unsigned int   Priority         : 3;
      unsigned char   PDUFormat;               // CA should use only PDUFormat.
      unsigned char   PDUSpecific;
      unsigned char   SourceAddress;
      unsigned int   DataLength          : 4;
      unsigned int   RTR               : 4;   // RTR bit, value always 0x00
      unsigned char   Data[J1939_DATA_LENGTH];
   };
   unsigned char      Array[J1939_MSG_LENGTH + J1939_DATA_LENGTH];
};
#define GroupExtension       PDUSpecific
#define DestinationAddress    PDUSpecific
typedef union J1939_MESSAGE_UNION J1939_MESSAGE;


That I can't get to work in CCS. Does anybody know how to code this function..???
_________________
Thank you,
Chris
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Sep 15, 2007 10:04 pm     Reply with quote

Quote:
I can't get to work in CCS

Give specific details.

1. Post your compiler version.

2. Post your PIC.

3 Post any compiler error messages.

4 Post a small test program, that shows improper operation.

5. Also, provide #define statements for these two constants:
Quote:
J1939_DATA_LENGTH
J1939_MSG_LENGTH
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Sep 16, 2007 8:06 am     Reply with quote

ChrisL,
The CCS compiler does not support unnamed types in a union, this means you will have to add a name to the first struct in the enum.

It seems like the High-Tech compiler is suffering from the same limitation as I found a ported version which has the required changes: http://www.htsoft.com/forum/all/showflat.php/Cat/0/Number/24552/Main/20677

Code:
#define J1939_MSG_LENGTH   5
#define J1939_DATA_LENGTH   8


union J1939_MESSAGE_UNION {
   struct {
      unsigned int   PDUFormat_Top      : 3;   // This needs pre and post processing.
      unsigned int   DataPage         : 1;
      unsigned int   Res               : 1;
      unsigned int   Priority         : 3;
      unsigned char   PDUFormat;               // CA should use only PDUFormat.
      unsigned char   PDUSpecific;
      unsigned char   SourceAddress;
      unsigned int   DataLength          : 4;
      unsigned int   RTR               : 4;   // RTR bit, value always 0x00
      unsigned char   Data[J1939_DATA_LENGTH];
   } Msg;                 <<-----------------  Add this for CCS as well.
   unsigned char      Array[J1939_MSG_LENGTH + J1939_DATA_LENGTH];
};


A side note:
Unnamed union members are a part of the ANSI/ISO 9899-1999 standard. CCS provides a comparison to the older 1990 version of the standard in http://www.ccsinfo.com/downloads/ansi_compliance.pdf. Too bad I can not find a copy of the 1990 standard on the internet so I can not check the CCS compliance statements.
ChrisL



Joined: 16 Apr 2007
Posts: 26
Location: Arizona

View user's profile Send private message Visit poster's website

PostPosted: Sun Sep 16, 2007 8:14 pm     Reply with quote

FINALLY, I figured out how to do this in CCS... Here is how it works...
Code:
In CCS here is a Structure inside of a Union...

/****************************Messaging*******************************************/
   struct J1939_MESSAGE_STRUCT
   {
      unsigned int   PDUFormat_Top:3;      // This needs pre and post processing.
      unsigned int   DataPage:1;
      unsigned int   Res:1;
      unsigned int   Priority:3;
      unsigned char  PDUFormat;         // CA should use only PDUFormat.
      unsigned char  PDUSpecific;
      unsigned char  SourceAddress;
      unsigned int   DataLength: 4;
      unsigned int   RTR: 4;            // RTR bit, value always 0x00
      unsigned char  Data[J1939_DATA_LENGTH];
   };
   
   union J1939_MESSAGE_UNION
   {
      struct J1939_MESSAGE_STRUCT   Msg;
      unsigned char Array[J1939_MSG_LENGTH + J1939_DATA_LENGTH];
   };
   typedef union J1939_MESSAGE_UNION J1939_MESSAGE;
   
/*******************************************************************************/


It's aliased like this..

J1939_MESSAGE                OneMessage;

It's addressed like this;  OneMessage.Msg.SourceAddress

With a pointer like this; MsgPtr->Msg.PDUFormat_Top


After 5, 20 hour days working on the conversion I have functional J1939 code converted from the Library that Microchip has on their web site.

Sometimes you just need to stop and ask the question to get back on the right track...

ckielstra - I like your solution better. I will give it a try to make my code simpler...

Thanks to all that responded...
_________________
Thank you,
Chris
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Sep 25, 2007 7:58 am     Reply with quote

I asked CCS to add support for unnamed members for struct and unions. This is part of the ANSI/ISO 9899-1999 specification (and maybe in the 1990 version also).

Sept 24 I received an email saying this is implemented in the next release (4.058).

The new feature allows you to write code like:
Code:
union foo
{
  struct
  {
    int a;
    int b;
  };    <-- note: no name here, makes it an anonymous structure.
  char c;
} bar;
char c;
....
bar.a = c; /* 'a' is a member of the anonymous structure
              located inside 'bar' */



A nice example for this new feature is when converting bytes to words and vice versa.
Old situation
Code:
union HL
{
  int16 L;
  struct
  {
    int8 low;
    int8 high;
  } hl;
};

usage:
union HL var1;

var1.L = 50000; // as an INT16

var1.hl.high = 195; // access the high byte
var1.hl.low = 80; // access the low byte


New situation
Code:
union HL
{
  int16 L;
  struct
  {
    int8 low;
    int8 high;
  };           // no name
};

usage:
union HL var1;

var1.L = 50000;

var1.high = 195; // Note the easier notation
var1.low = 80;
ChrisL



Joined: 16 Apr 2007
Posts: 26
Location: Arizona

View user's profile Send private message Visit poster's website

PostPosted: Tue Sep 25, 2007 8:35 am     Reply with quote

ckielstra,

That's great...!
_________________
Thank you,
Chris
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group