This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430F2274: Changing the memory address of an array value after using `#pragma LOCATION`

Part Number: MSP430F2274


So in my code I set split up the RAM into two sections, the section I am concerned about holds two 128 byte arrays. To place them in that specific RAM section (referred to ".ram_data") I used the `#pragma LOCATION` and set their contents with `memset`. Next, I wanted to copy the data from one array to the other, which can be done with `memcpy`, but then move the initial data array to a new location in the `.ram_data` section. Can this be done when the LOCATION pragma is already used in the program? Another option I read about was using `#pragma DATA_SECTION`, but then I run into problems where the size of `.bss` section is not big enough, even though I am not place the arrays in the `.bss` section, rather my created `.ram_data` section.

My question can be summarized by asking how I can change the memory address of the the data arrays after they have been set using #pragma directives. A partial listing of my code is below. Thank you!

#include <msp430.h>
#include <string.h>
#include <stdint.h>
#include "ram_data_ccs_mem.h"

#define     INTERRUPT_VALUE         0x0A        // counter for interrupts (see above for calculations)
#define     ARRAY_STEP              0x80        // increase/decrease movement of data (128 bytes)
#define     ARRAY_SIZE              0x80        // size of data (128 bytes)


/* function declarations */
void configWDT(void);                                 // halts the watchdog timer
void configClocks(void);                              // selects ACLK/8 as frequency
void configGPIO(void);                                // disables/enables GPIO pins
void configTimerA(void);                              // configures TimerA for interrupt counter
uint32_t *memory_copy(uint32_t *, uint32_t *, char);  // moves data around RAM and clears previous location


/* global variables */
static volatile unsigned char toggle_LED;       // toggles red LED (used for debugging)
static volatile unsigned short intrp_flg;       // counts number of interrupts of TimerA

/* forces processor to place data arrays in RAM */
//#pragma DATA_SECTION(dest_loc, ".ram_data")
//char cur_loc[128];                              // current location of array in RAM
//char dest_loc[128];                             // next memory location in RAM for array

#pragma LOCATION(cur_loc, 0x220)
char cur_loc[128];

#pragma LOCATION(dest_loc, 0x2A0)
char dest_loc[128];


int main(void)
{
    /* initalize globals */
    toggle_LED = 0;
    intrp_flg = 0;
    //static char reverse_dataflow = 0;

    /* configure watchdog timer, clocks, GPIO pins, and TimerA of processor */
    configWDT();
    configClocks();
    configGPIO();
    configTimerA();

    /* initialize data arrays to be moved throughout RAM */
    int dest = RAM_DATA_START_ADDR + ARRAY_STEP;                                    // starting position is beginning of available RAM
    memset(cur_loc, '#', ARRAY_SIZE);                                               // fill memory with arbitrary data (used for debugging)                                                         
    memset(dest_loc, '\0', RAM_DATA_END_ADDR - RAM_DATA_START_ADDR + ARRAY_STEP);   // clear remaining RAM_DATA sapce
    __no_operation();                                                               // (used for debugging)

    ...
}

  • Sean Kramer said:
    then move the initial data array to a new location in the `.ram_data` section

    That's unusual.  The C language itself has no support for it.

    At this point, I suspect is not helpful to continue to think about this in terms of the low level details of implementation.  With that in mind, please describe the overarching problem you want to solve.  As much as you can, ignore the details of how you might solve it.

    Thanks and regards,

    -George

  • The project requires me to place a data array or "key" into RAM and move around to random locations in RAM once every 24 hours. 

  • This "key" data array cannot, at any time, be allocated to a static address.  That is, it cannot be a global, or even static within a function.  A pointer is required, similar to ...

    int *key_data;

    This pointer will contain the address of the key data array.  As needed, allocate a new array, and memcpy the data from the old one to the new one.

    As an initial implementation, consider using malloc.  A call would look similar to ...

    key_data = malloc(sizeof(int) * NUMBER_OF_ELEMENTS);
    if (key_data == NULL) { /* handle out of memory error */ }

    Since malloc is probably not random enough, it will have to be replaced with a custom solution that, in a similar manner, returns the address of a suitable memory location.

    Thanks and regards,

    -George