ec521

Dependencies:   mbed

Committer:
gaving
Date:
Sun Apr 22 19:20:10 2018 +0000
Revision:
0:e2f78ce2a5cf
For EC521 only

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gaving 0:e2f78ce2a5cf 1 #ifndef FREESCALEIAP_H
gaving 0:e2f78ce2a5cf 2 #define FREESCALEIAP_H
gaving 0:e2f78ce2a5cf 3
gaving 0:e2f78ce2a5cf 4 #include "mbed.h"
gaving 0:e2f78ce2a5cf 5
gaving 0:e2f78ce2a5cf 6 #if defined(TARGET_KLXX) | defined(TARGET_K20D50M)
gaving 0:e2f78ce2a5cf 7 #define SECTOR_SIZE 1024
gaving 0:e2f78ce2a5cf 8 #elif (TARGET_K22F)
gaving 0:e2f78ce2a5cf 9 #define SECTOR_SIZE 2048
gaving 0:e2f78ce2a5cf 10 #elif defined(TARGET_K64F)
gaving 0:e2f78ce2a5cf 11 #define SECTOR_SIZE 4096
gaving 0:e2f78ce2a5cf 12 #else
gaving 0:e2f78ce2a5cf 13 #warning FreescaleIAP unknown target, using default 1024B
gaving 0:e2f78ce2a5cf 14 #define SECTOR_SIZE 1024
gaving 0:e2f78ce2a5cf 15 #endif
gaving 0:e2f78ce2a5cf 16
gaving 0:e2f78ce2a5cf 17 enum IAPCode {
gaving 0:e2f78ce2a5cf 18 BoundaryError = -99, //Commands may not span several sectors
gaving 0:e2f78ce2a5cf 19 AlignError, //Data must be aligned on longword (two LSBs zero)
gaving 0:e2f78ce2a5cf 20 ProtectionError, //Flash sector is protected
gaving 0:e2f78ce2a5cf 21 AccessError, //Something went wrong
gaving 0:e2f78ce2a5cf 22 CollisionError, //During writing something tried to flash which was written to
gaving 0:e2f78ce2a5cf 23 LengthError, //The length must be multiples of 4
gaving 0:e2f78ce2a5cf 24 RuntimeError,
gaving 0:e2f78ce2a5cf 25 EraseError, //The flash was not erased before writing to it
gaving 0:e2f78ce2a5cf 26 Success = 0
gaving 0:e2f78ce2a5cf 27 };
gaving 0:e2f78ce2a5cf 28
gaving 0:e2f78ce2a5cf 29 /** Erase a flash sector
gaving 0:e2f78ce2a5cf 30 *
gaving 0:e2f78ce2a5cf 31 * The size erased depends on the used device
gaving 0:e2f78ce2a5cf 32 *
gaving 0:e2f78ce2a5cf 33 * @param address address in the sector which needs to be erased
gaving 0:e2f78ce2a5cf 34 * @param return Success if no errors were encountered, otherwise one of the error states
gaving 0:e2f78ce2a5cf 35 */
gaving 0:e2f78ce2a5cf 36 IAPCode erase_sector(int address);
gaving 0:e2f78ce2a5cf 37
gaving 0:e2f78ce2a5cf 38 /** Program flash
gaving 0:e2f78ce2a5cf 39 *
gaving 0:e2f78ce2a5cf 40 * Before programming the used area needs to be erased. The erase state is checked
gaving 0:e2f78ce2a5cf 41 * before programming, and will return an error if not erased.
gaving 0:e2f78ce2a5cf 42 *
gaving 0:e2f78ce2a5cf 43 * @param address starting address where the data needs to be programmed (must be longword alligned: two LSBs must be zero)
gaving 0:e2f78ce2a5cf 44 * @param data pointer to array with the data to program
gaving 0:e2f78ce2a5cf 45 * @param length number of bytes to program (must be a multiple of 4. must be a multiple of 8 when K64F)
gaving 0:e2f78ce2a5cf 46 * @param return Success if no errors were encountered, otherwise one of the error states
gaving 0:e2f78ce2a5cf 47 */
gaving 0:e2f78ce2a5cf 48 IAPCode program_flash(int address, char *data, unsigned int length);
gaving 0:e2f78ce2a5cf 49
gaving 0:e2f78ce2a5cf 50 /**
gaving 0:e2f78ce2a5cf 51 * Returns size of flash memory
gaving 0:e2f78ce2a5cf 52 *
gaving 0:e2f78ce2a5cf 53 * This is the first address which is not flash
gaving 0:e2f78ce2a5cf 54 *
gaving 0:e2f78ce2a5cf 55 * @param return length of flash memory in bytes
gaving 0:e2f78ce2a5cf 56 */
gaving 0:e2f78ce2a5cf 57 uint32_t flash_size(void);
gaving 0:e2f78ce2a5cf 58
gaving 0:e2f78ce2a5cf 59 #endif