![Vlsi VS1063a Скачать руководство пользователя страница 24](http://html.mh-extra.com/html/vlsi/vs1063a/vs1063a_programmers-manual_1042916024.webp)
PRELIMINARY
VS1063a Prog. Guide
8
VS1063A LOAD FILE FORMATS
8.2.2
Example VS1063a Microcontroller Boot Image Decoder
/* This support function that writes one word through SCI is needed. */
void WriteVS10xxRegister(unsigned short addr, unsigned short value);
#define TYPE_I 0
#define TYPE_X 1
#define TYPE_Y 2
#define TYPE_E 3
/* Returns either 0xFFFF for error or image file start address.
For compactness does NOT check if fgetc() fails! */
auto u_int16 SpiLoadImageInto1053(register __i0 FILE *fp) {
s_int16 type;
if (fgetc(fp) != 'P' || fgetc(fp) != '&' || fgetc(fp) != 'H')
return 0xFFFF;
while ((type = fgetc(fp)) >= 0 && type < 4) {
static const u_int16 offsets[3] = {0x8000U, 0x0U, 0x4000U};
u_int16 len, addr;
/* Get length and address of the record */
len = fgetc(fp) << 8;
len |= fgetc(fp);
addr = fgetc(fp) << 8;
addr |= fgetc(fp);
/* If execute record: return with start address */
if (type == TYPE_E)
return addr;
/* Map address to WRAMADDR register space */
if (type != TYPE_Y || addr < 0xE000)
addr += offsets[type];
/* Set write address */
Write1053Sci(SCIR_WRAMADDR, addr + offsets[type]);
/* Convert len from bytes to words, then write data */
len >>= 1;
while (len--) {
u_int16 data = (u_int16)fgetc(fp) << 8;
data |= fgetc(fp);
Write1053Sci(SCIR_WRAM, data);
};
} /* while (type >= 0 && type < 4) */
return 0xFFFF; /* Pass-through indicates error condition */
}
Version: 0.40, 2011-09-02
24