ec521

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers FreescaleIAP.h Source File

FreescaleIAP.h

00001 #ifndef FREESCALEIAP_H
00002 #define FREESCALEIAP_H
00003 
00004 #include "mbed.h"
00005 
00006 #if defined(TARGET_KLXX) | defined(TARGET_K20D50M)
00007 #define SECTOR_SIZE     1024
00008 #elif (TARGET_K22F)
00009 #define SECTOR_SIZE     2048
00010 #elif defined(TARGET_K64F)
00011 #define SECTOR_SIZE     4096
00012 #else
00013 #warning FreescaleIAP unknown target, using default 1024B
00014 #define SECTOR_SIZE     1024
00015 #endif
00016 
00017 enum IAPCode {
00018     BoundaryError = -99,    //Commands may not span several sectors
00019     AlignError,             //Data must be aligned on longword (two LSBs zero)
00020     ProtectionError,        //Flash sector is protected
00021     AccessError,            //Something went wrong
00022     CollisionError,         //During writing something tried to flash which was written to
00023     LengthError,            //The length must be multiples of 4
00024     RuntimeError,           
00025     EraseError,             //The flash was not erased before writing to it
00026     Success = 0
00027     };
00028 
00029 /** Erase a flash sector
00030  *
00031  * The size erased depends on the used device
00032  *
00033  * @param address address in the sector which needs to be erased
00034  * @param return Success if no errors were encountered, otherwise one of the error states
00035  */
00036 IAPCode erase_sector(int address);
00037 
00038 /** Program flash
00039  *
00040  * Before programming the used area needs to be erased. The erase state is checked
00041  * before programming, and will return an error if not erased.
00042  *
00043  * @param address starting address where the data needs to be programmed (must be longword alligned: two LSBs must be zero)
00044  * @param data pointer to array with the data to program
00045  * @param length number of bytes to program (must be a multiple of 4. must be a multiple of 8 when K64F)
00046  * @param return Success if no errors were encountered, otherwise one of the error states
00047  */
00048 IAPCode program_flash(int address, char *data, unsigned int length);
00049 
00050 /**
00051  * Returns size of flash memory
00052  * 
00053  * This is the first address which is not flash
00054  *
00055  * @param return length of flash memory in bytes
00056  */
00057 uint32_t flash_size(void);
00058 
00059 #endif