Book a Demo

Author Topic: How to model bitfields and union  (Read 4219 times)

wink

  • EA User
  • **
  • Posts: 48
  • Karma: +0/-0
  • Montjoie, que jamais ne choit!
    • View Profile
How to model bitfields and union
« on: April 13, 2005, 07:05:49 am »
Hello everybody,

I'm currently evaluating EA and I hope that some of you experienced folks might help me out.

I have to model an embedded real time system using C++.
In order to address all the microcontroller registers I have been using C-type bitfields in the past, which is a convenient way to access to individual bits.

My 1st question is: How can I do this in EA?

I have seen that EA generates attributes with a default value corresponding to the bit length in reverse engeneered code, but when I try to create a new class and I create an attribute ( someAttribute: int = 1 ) and then generate the code, it will generate a normal int attribute without the ':' and the length.

My 2nd question is: How can I model unions?

If I reverse engeneer an existing HPP header file with the following declaration:


struct TER_Bitfield_Access
{
 int  NOP    :       6 ;
 int  Ref     :       1 ;
 int  Cap    :       1 ;    
} ;

union   TER_Access
{
 struct     TER_Bitfield_Access     Bitfield ;
 uchar     Global ;
} ;


EA creates a struct element but it does not create an element for the union. Can this be done somehow?

I'd really appreciate any hints

Thanks in advance for you attention!

best regards,
Manfred

BTW, I'm really impressed by the product! :o
Best regards,
Manfred

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: How to model bitfields and union
« Reply #1 on: April 13, 2005, 04:09:16 pm »
I reverse engineered your example code, it looks like the attributes get the stereotype "bitfield" with the bit length stored in the default value.  It looks like the code generation templates haven't caught up with the parser on that yet though.  :-[
Adding
Code: [Select]
%if attStereotype == "bitfield" and attInitial != ""%
: %attInitial%
%endIf%
to the attribute declaration template just before the semi-colon will make it generate.  (Careful if you copy it that you don't get extra whitespace anywhere)  But then I discover that it doesn't synchronise properly.  :'(

The logical way to model a union would be give the class a union stereotype.  Currently unions aren't reverse engineered, though the templates could be modified to handle unions.

Changing
Code: [Select]
%classStereotype=="struct" ? "struct" : "class"% to
Code: [Select]
%if classStereotype=="struct"%
struct
%elseIf classStereotype=="union"%
union
%else%
class
%endIf%
should do the job.

In the mean time, some extra work needs to be done on the C++ parser, including unions and fixing bitfield synchronisation shouldn't be too much of a problem (and when it is done the templates should also be updated)

Simon

wink

  • EA User
  • **
  • Posts: 48
  • Karma: +0/-0
  • Montjoie, que jamais ne choit!
    • View Profile
Re: How to model bitfields and union
« Reply #2 on: April 14, 2005, 12:50:22 am »
Hi simonm,

Thank you very much for your help, I'll give it a try.
Do you have an idea if and when this feature might get included into an official EA version?

best regards,
Manfred
Best regards,
Manfred

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: How to model bitfields and union
« Reply #3 on: April 14, 2005, 03:00:34 pm »
Quote
In the mean time, some extra work needs to be done on the C++ parser, including unions and fixing bitfield synchronisation shouldn't be too much of a problem (and when it is done the templates should also be updated)


By that I was meaning that I'll include this in the work on the C++ parser.

Simon

wink

  • EA User
  • **
  • Posts: 48
  • Karma: +0/-0
  • Montjoie, que jamais ne choit!
    • View Profile
Re: How to model bitfields and union
« Reply #4 on: April 14, 2005, 11:28:04 pm »
That's great simon!

I'm really looking forward to a new release! :)

Meanwhile I've made the company internal request to buy EA corp edition, so it's just a matter of time untill you will get the order from MGPI-France.

One more question:
Concerning the new releases, once I have my official version, will I be able to upgrade each time there is a new build?

Thanks in advance,

best regards,

Manfred
Best regards,
Manfred

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: How to model bitfields and union
« Reply #5 on: April 17, 2005, 03:10:51 pm »
http://www.sparxsystems.com.au/LicenseInfo.htm
Quote
Purchasing a license makes you a registered user for 12 months, which entitles you to:
  • Download and activate the current, full version of EA.
  • Access free updates and new builds for a period of 12 months.
  • Access Sparx Systems' email support services for 12 months.
  • Access the registered users area and any associated resources for 12 months.

So yes.

Simon