meghs94 / tinyos-main

Automatically exported from code.google.com/p/tinyos-main
1 stars 0 forks source link

ATmega128 const definitions not really const #136

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
avr-gcc 4.7.0 complains that const_uint8_t etc. request data to be placed in a 
read-only segment in memory without that data being actually const.

The specific error message is:
error: variable 'McuSleepC__atm128PowerBits' must be const in order to be put 
into read-only section by means of '__attribute__((progmem))'

The attached patch fixes the problem.

Original issue reported on code.google.com by ondra.hosek@gmail.com on 18 May 2012 at 5:09

Attachments:

GoogleCodeExporter commented 8 years ago
Does this patch work with earlier versions of avr-gcc? The current release 
doesn't support 4.7. What happens when you apply the patch and compile using 
4.1.2?

Original comment by philip.l...@gmail.com on 30 May 2012 at 4:36

GoogleCodeExporter commented 8 years ago

Original comment by philip.l...@gmail.com on 30 May 2012 at 4:36

GoogleCodeExporter commented 8 years ago
I have applied the patch and successfully compiled Blink for micaz using 
avr-gcc 4.1.2.

I have also made sure that such a line is actually included: line 1130 in app.c 
declares McuSleepC__atm128PowerBits an array of const_uint8_t (using the 
patched typedef) and the compiler doesn't complain.

Original comment by ondra.hosek@gmail.com on 30 May 2012 at 12:13

GoogleCodeExporter commented 8 years ago
Adding const to the typedefs results in these these types not being correctly 
stored in program memory with gcc 4.5 (it works correctly with 4.7).

Test results:

gcc 4.5
-------

const uint8_t const_pmem PROGMEM = MAGIC; /**< Stored in PROGMEM. */

typedef const uint8_t const_td_t PROGMEM;
const_td_t const_typedef = MAGIC;         /**< _NOT_ stored in PROGMEM. */

uint8_t nonconst_pmem PROGMEM = MAGIC;    /**< Stored in PROGMEM. */

typedef uint8_t td_t PROGMEM;
td_t nonconst_typedef = MAGIC;            /**< Stored in PROGMEM. */

gcc 4.7
-------

const uint8_t const_pmem PROGMEM = MAGIC; /**< Stored in PROGMEM. */

typedef const uint8_t const_td_t PROGMEM;
const_td_t const_typedef = MAGIC;         /**< Stored in PROGMEM. */

The non-const types fail to compile with the error message mentioned by Ondra.

The test program is attached.
Maybe these typedefs should be removed altogether to guarantee compatibility 
between different gcc versions?

Original comment by Jakob.Gr...@gmail.com on 6 Jun 2012 at 5:50

Attachments:

GoogleCodeExporter commented 8 years ago
Hi to all,

I apply the patch, and the problem persists(same as exposed by ondra) 
I have:
GCC - 4.6.0
AVR-GCC - 4.7.2

I had also apply a patch to $TOS_ROOT/tos/chips/atm128/crc.h but with no 
results.

How can i fix it?

Original comment by teamproj...@gmail.com on 23 Nov 2012 at 1:32