cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Visitor
Visitor
2,689 Views
Registered: ‎07-22-2009

Data type sizes in XAPP058

Jump to solution

I am about to try and port the code from XAPP058 (program parts via JTAG) to a PIC24EP processor (16 bit CPU), and the way the code is written raises an issue for me with data sizes in the code.

 

The code does not define the type/size of processor it was written for, and uses standard data types of short, int and long. But those are ambiguous sizes based on whatever CPU is actually being used. On a 32 bit CPU those might all have different sizes (ie: short might be 16 bit, int might be 32 bit and long might be 64 bit). However on a 16 bit CPU like mine, short and int are both 16 bit and long is 32 bit. So if the code was written for a 32 bit CPU, things are going to get wonky if I don't re-adjust things in these declarations.

 

If the code had used declarations like UINT16, UINT32, etc... then the sizes would be clearly defined and would be consistent across all porting to different CPUs. But as it is I don't know what the original target CPU was that this was written for. But I am guessing that it wasn't a 16 bit CPU since they mixed the use of short and int, in my CPU those are exactly the same size.

 

Any suggestions??

 

0 Kudos
1 Solution

Accepted Solutions
Highlighted
Visitor
Visitor
4,510 Views
Registered: ‎07-22-2009

Well I compiled the code as it was, for the PIC24EP (16 bit micro) and got it to work without having to change typedefs. So I guess none of the longs were used for 64 bit values. So for anybody else in the future, it does work with 16 bit shorts and ints and 32 bit longs.

View solution in original post

0 Kudos
4 Replies
Highlighted
Visitor
Visitor
2,675 Views
Registered: ‎07-22-2009

In other words, I suspect that I need to go through this whole thing and change all long variables into long long, and change all int variables into long. That way the ones defined in this code as "long" will be 64 bit and the ones defined in this code as "int" will be 32 bit.

 

It looks like the code is packing bytes into some of those variables, and if they're the wrong width, data will be lost.

0 Kudos
Highlighted
Xilinx Employee
Xilinx Employee
2,647 Views
Registered: ‎08-01-2008
you require to download files and utilities associated with this application note are available in a package for downloading from:

https://secure.xilinx.com/webreg/clickthrough.do?cid=11397

Refer the files and check contents
Thanks and Regards
Balkrishan
--------------------------------------------------------------------------------------------
Please mark the post as an answer "Accept as solution" in case it helped resolve your query.
Give kudos in case a post in case it guided to the solution.
0 Kudos
Highlighted
Visitor
Visitor
2,642 Views
Registered: ‎07-22-2009

Your link goes to a link that says the download file is not available.

 

But I did download the files for the app note. Pease re-read my post. The issue is that the variable types are defined ambiguously as long int and short but do not define what scale compiler is used for the microcontroller involved. A "long" does not define a specific size of variable in C. It can be 64 bits or it can be 32 bits depending on the processor. Likewise an "int" can be 16 bits or 32 bits. The micro that I am using has 16 bit ints and 32 bit longs. But it also has 16 bit shorts. Since the downloaded code uses both ints and shorts, that makes me believe that the code was written for a 32 bit or larger CPU, where a short and an int are different sizes. For example a short might be 16 bits, an int might be 32 bits and a long might be 64 bits. But in my compiler and microcontroller they are not those sizes. They are 16, 16 and 32.

 

For many uses within the code that might not be an issue. But if bytes are compressed into a long, the difference is that you can only fit 4 bytes into a long in my compiler while you can fit 8 bytes into a long on a typical 32 bit compiler.

 

I am trying to determine if that is an issue. Code written to be ported for a wide range of different sized microcontrollers should explicitly describe the bit size of it's variables, rather than leave them ambiguously defined. For example using UINT16 and UINT32, which explicitly define the size of the variable type.

0 Kudos
Highlighted
Visitor
Visitor
4,511 Views
Registered: ‎07-22-2009

Well I compiled the code as it was, for the PIC24EP (16 bit micro) and got it to work without having to change typedefs. So I guess none of the longs were used for 64 bit values. So for anybody else in the future, it does work with 16 bit shorts and ints and 32 bit longs.

View solution in original post

0 Kudos