I've made some progress in writing FLASH access code for the CodeWarrier Development environment:
In the linker file:
PAGED_FLASH INTO PAGE_E0, PAGE_E1, PAGE_E2, PAGE_E3;
I've defined a CODE_BLOCK structure that has both the file information and an array to hold the data image.
typedef union _codecontrolblock {
struct {
WORD CRC; // Block CRC
char FileName[10]; // general format name is xIMn_ssv
char Format; // S (Motorola) or I (Intel) format.
char TargetID; // CANOpen NodeID of destination. (1 == us)
WORD Size; // Size in WORDs.
} f;
unsigned long a[4];
} TCODE_CONTROL_BLOCK;
typedef struct _codeblock {
TCODE_CONTROL_BLOCK CodeInfo;
WORD CodeImage[0x2000-0x10];
} TCODE_BLOCK;
And then defined the variable
#pragma DATA_SEG __GPAGE_SEG PAGED_FLASH
TCODE_BLOCK CodeBlock = {{0x3456, "xIM1_nnv",'I',0x20,0xFFFF},0xFFFF};
#pragma CODE_SEG DEFAULT
Finally a try at a pointer to this data although I haven't been able to make that work yet.
unsigned int far * far destPtr;
I've written a small serial port program along with a general purpose write to flash command.
void
WriteFlashCMD( BYTE cmd ) {
while (FSTAT_CBEIF == 0) // Wait for not busy.
;
if (FSTAT & (FSTAT_PVIOL_MASK | FSTAT_ACCERR_MASK)) // Was there an error?
FSTAT |= (FSTAT_PVIOL_MASK | FSTAT_ACCERR_MASK); // Clear it.
FCMD = cmd; // Issue command.
FSTAT_CBEIF = 1; // Start the cmd. // Start the command.
while (FSTAT_CCIF == 0)
; // Wait for not busy.
}
And I can Display, Erase and Write to the Flash. For example:
| | case 'E' : // FEn -- Erase block at n |
| | pageAddr = GetHexWord(USB_NDX); |
| | CodeBlock.CodeImage[pageAddr] = 0; // Set the Address to erase |
| | WriteFlashCMD(FCMD_SECTOR_ERASE); |
| | break; |
But what doesn't work is setting a point to this structure.
| | destPtr = (unsigned int * __far)&CodeBlock.CodeInfo.CRC; |
| | *destPtr = 0; |
| | WriteFlashCMD(FCMD_SECTOR_ERASE);// Erase the blocks/pages. |
| | CodeBlock.CodeInfo.f.CRC = 0x4142; // Now write the data and address |
| | WriteFlashCMD(FCMD_WORD_PROGRAM); |
Is there even a way to convince the compiler to work with pointers in this manner?
And is there a way to mark the GPAGE section to not be auto-initialized?