Basically I have a bunch of 2 byte ints written sequentially in 32bit flash memory. How do I access these as an array of int16's?
I wrote the array irrespective of word boundaries. But I could add padding so that the array starts on a word boundary if necessary.
Here's my code that writes the flash memory (basically it just combines every 4 bytes into a word and then writes that word to the flash):
for(flash_page = 0; flash_page < protocol_pages; flash_page++){ //loop through all the pages
for(flash_address = 0; flash_address < NUMBER_OF_INSTRUCTIONS_IN_PAGE; flash_address++){ //loop through all the words in the page
for (byte_address = 0; byte_address < 4; byte_address++){ //loop through the byte in each word
buffer_check();
flash_word += buffer[buffer_index] << (8*(3-byte_address));
buffer_index++;
bytes_written++;
if(bytes_written >= data_length)
break;
}
///////Write word here
NVMWriteWord((void*) &(proto_data_addr[flash_page][flash_address]), flash_word);
flash_word = 0;
if(bytes_written >= data_length)
break;
}
if(bytes_written >= data_length)
break;
}
Mixed into this block of bytes is sequences of 2 byte ints strung end to end. How can I access them as an array once they're written in the flash memory? Do I have to pad the arrays so that there are 2 int16's in every word?
Thanks!