Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

RTOS+ arm7 typecast problem

Posted by Joel cote on July 29, 2009
Hi,

I use eclipse+yagarto+the exemple RTOS "ARM7_AT91SAM7X256_Eclipse". I have a problem when I do this
char var1[2];
int short var2 = 0x1234;

*(int short*)var1 = var2

When I do the typecast the arm stop working and go in data abort of boot.s. Can someone tell me why the arm his not able to do that and how I can solve my problem, because with the Rabbit I was able to do that. I know I can use memcpy, but with this cast I save some CPU time.

thank

RE: RTOS+ arm7 typecast problem

Posted by Ben on July 29, 2009
sounds like an alignment problem. var1 is probably at an odd address which is fine for byte access but not for 16/32 bit access

Ben

RE: RTOS+ arm7 typecast problem

Posted by Ben on July 29, 2009
have you tried the reverse ?

int short var2 = 0x1234;
char* var1;

var1 = (char*)&var2;

Ben

RE: RTOS+ arm7 typecast problem

Posted by Joel cote on July 29, 2009
yes I have the problem only when the var1 have a odd address, how can I solve that?
No I didn't tried the inverse, because in you exemple var1 is only a ptr, I want the value to be copied and be able to modify var2 without modify the value of var1

Joël

RE: RTOS+ arm7 typecast problem

Posted by Ben on July 29, 2009
You could try using the aligned attribute

http://gcc.gnu.org/onlinedocs/gcc/Variable-Attributes.html

RE: RTOS+ arm7 typecast problem

Posted by Joel cote on July 29, 2009
That doesn't work because in my real projet i'm in a structure (who is packed to be sure no memory space is left between two variable), So if I have this kind of structure
var1[2];
var2;
var3[2];
and I use var3 it is sure that the address of var3 is odd and that doesn't work on the arm, but I don't know why because on the rabbit i'm am able to do that

RE: RTOS+ arm7 typecast problem

Posted by Ben on July 29, 2009
Assuming the structure has to be packed and you can't change the order of the structure elements you will have to copy the short int a byte at a time.

If you can change the order of the elements then delcare var3 after var 1 and both will probably be aligned on an even address, assuming the structure is aligned that way.

This is not really the correct forum for discussing this as it is not a problem with FreeRTOS or related in anyway to it. You would still have your problem even if you used no RTOS.

RE: RTOS+ arm7 typecast problem

Posted by Joel cote on July 29, 2009
Do you know better forum where I can post ? I tried sparfun and atmel

thank

RE: RTOS+ arm7 typecast problem

Posted by Adam Turowski on July 29, 2009
Thisshould work:

char var1[2];
int short var2 = 0x1234;

var1[1] = (char) (var2 & 0xFF);
var1[0] = (char) (var2 >>8);

Maybe not most effective, but it will work? BTW why are you doing such ugly casting anyway?

RE: RTOS+ arm7 typecast problem

Posted by Joel cote on July 29, 2009
I know this work, but it's take more time to the cpu to do it. Why did you find this cast ugly, I find it so beautiful :P. With this cast the cpu copy the value in one shot and this fast when you have to do many.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists