Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
20721 Discussions

Integer in NIOS...

Altera_Forum
Honored Contributor II
3,883 Views

Hello as i know integer can hold 2^16 data 

 

but  

typedef struct flash_region { int offset;/* Offset of this region from start of the flash */ int region_size;/* Size of this erase region */ int number_of_blocks;/* Number of blocks in this region */ int block_size;/* Size of each block in this erase region */ }flash_region;the value if offset is larger than 2^16 - 1, how does NIOS II handle this ???? 

 

can someone clarify this for me....
0 Kudos
6 Replies
Altera_Forum
Honored Contributor II
2,284 Views

Hello, 

 

An integer is stored as 32 bits (cf Table 7–1 of the Nios II Processor Reference Handbook). 

And now this is true for all the machine I think, it is not particular to the Nios II. 

 

Jérôme
0 Kudos
Altera_Forum
Honored Contributor II
2,284 Views

You could use 'alt_u32' data type including library '#include <alt_types.h>'. It is of 32 bits and can serve your purpose

0 Kudos
Altera_Forum
Honored Contributor II
2,284 Views

Indeed you can use also these types, but actually there are the same. If you looked at alt_types.h you have : 

 

typedef signed char alt_8; typedef unsigned char alt_u8; typedef signed short alt_16; typedef unsigned short alt_u16; typedef signed long alt_32; typedef unsigned long alt_u32; typedef long long alt_64; typedef unsigned long long alt_u64;
0 Kudos
Altera_Forum
Honored Contributor II
2,284 Views

Actually by using alt_u32 you will be sure that you have a 32-bit integer. 

The C standard doesn't define the size of the int type, and depending on the compiler or architecture, "int" can mean 16, 32 or 64 bits. It has always been a problem with C and that's why each HAL redefines its own integer types.
0 Kudos
Altera_Forum
Honored Contributor II
2,284 Views

But I face a problem of defining a 128bit type< how can I solve this? 

Thanks
0 Kudos
Altera_Forum
Honored Contributor II
2,284 Views

 

--- Quote Start ---  

But I face a problem of defining a 128bit type< how can I solve this? 

Thanks 

--- Quote End ---  

 

 

Probably the best way is to use an array of some defined types. For example: 

 

int32_t My128bitArray[4]; 

int16_t My128bitArray[8]; 

int8_t My128bitArray[16]; 

 

By the way you should choose the type your array on the basis of what you have to do with it. If you have to write 32bit registers BadOmen gives you the answer: 

http://www.alteraforum.com/forum/showthread.php?t=44527 

 

If you have to send 1 byte on a SPI you should go with an 8 bit array etc etc.. 

 

What are you supposed to do with a 128 bit var ? If we can know..
0 Kudos
Reply