Quality RTOS & Embedded Software

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




Loading

Loosing space memory dsPIC33F 16 bits

Posted by Victor Castro on January 7, 2010
Example of diagram of memory

|Byte | Nothing | Int | => As is today, loss memory.
---------------------------------
| B | N | I | I |
---------------------------------
8bits 8bits 8bits 8bits


|Byte | Int | Free | => As should be, gain memory.
------------------------
| B | I | I | F |
------------------------
8bits 8bits 8bits 8bits

Hi, I'm using dsPIC33F 16 bits with MPLab, I'm with problem with loss of memory, I'm mounting structs containing bytes and ints, but when I use sizeof(), the value returned not is the expected, the value is always higher. Has some setup to do on MPLab or have no way? In both examples, I have one byte and one int, but in the first I loss one byte of memory, adding one byte on the final result, and always I make this exact structure, it adds one byte after int.

Thank's a lot!!!

Best regards,

VĂ­ctor Castro

RE: Loosing space memory dsPIC33F 16 bits

Posted by MEdwards on January 7, 2010
I think their compilers are GCC based so you can use __attribute__((packed)) on individual structure variables or -fpack-struct compiler switch to pack all structures.

Not a FreeRTOS question, by the way.

RE: Loosing space memory dsPIC33F 16 bits

Posted by Richard Damon on January 7, 2010
One comment, on the dsPic Processor, like many processors today, multi-byte numbers may not be placed at arbitrary memory locations, but must be aligned to some power of 2 for addresses. 16 bit numbers on the dsPic must be stored on even addresses or the processor will not fetch them correctly. If you try to access a 16 bit word at an odd address, the processor will raise an address error execption.

RE: Loosing space memory dsPIC33F 16 bits

Posted by MEdwards on January 7, 2010
“One comment, on the dsPic Processor, like many processors today, multi-byte numbers may not be placed at arbitrary memory locations, but must be aligned to some power of 2 for addresses. 16 bit numbers on the dsPic must be stored on even addresses or the processor will not fetch them correctly. If you try to access a 16 bit word at an odd address, the processor will raise an address error execption.”


So the order in which you list the members inside the structure will also make a difference. Dont have a char followed by an int followed by a char, but instead a char followed by a char followed by an int.

RE: Loosing space memory dsPIC33F 16 bits

Posted by Richard Damon on January 7, 2010
Int followed by char followed by another char won't lose space. A structure of an int followed by a char, and that is all, will still take 4 bytes as is required to make array work.

RE: Loosing space memory dsPIC33F 16 bits

Posted by Victor Castro on January 8, 2010
Hi edwards3, the tip you said worked very well "__attribute__((packed))".

My structures are in this syntax:
typedef struct
{
char a;
int b;
char c;
} Tes1;

How I put the attribute in this structure above?

Because I got it in this syntax below:
struct Test2
{
char a;
int b;
char c;
} __attribute__((__packed__));

typedef struct Test2 Test_2;

Result:
sizeof(Tes1) = 6
sizeof(Test_2) = 4


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




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

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

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

OpenRTOS and SafeRTOS