lpc-field

Template project for programming NXP's LPC1768 MCUs
git clone git://git.mdnr.space/lpc-field
Log | Files | Refs | README | LICENSE

lpc17xx_iap.h (5159B)


      1 /**********************************************************************
      2 * $Id$		lpc17xx_iap.h			2012-04-18
      3 *//**
      4 * @file		lpc17xx_iap.h
      5 * @brief	Contains all functions support for IAP
      6 *			on lpc17xx
      7 * @version	1.0
      8 * @date		18. April. 2012
      9 * @author	NXP MCU SW Application Team
     10 * 
     11 * Copyright(C) 2011, NXP Semiconductor
     12 * All rights reserved.
     13 *
     14 ***********************************************************************
     15 * Software that is described herein is for illustrative purposes only
     16 * which provides customers with programming information regarding the
     17 * products. This software is supplied "AS IS" without any warranties.
     18 * NXP Semiconductors assumes no responsibility or liability for the
     19 * use of the software, conveys no license or title under any patent,
     20 * copyright, or mask work right to the product. NXP Semiconductors
     21 * reserves the right to make changes in the software without
     22 * notification. NXP Semiconductors also make no representation or
     23 * warranty that such application will be suitable for the specified
     24 * use without further testing or modification.
     25 * Permission to use, copy, modify, and distribute this software and its
     26 * documentation is hereby granted, under NXP Semiconductors'
     27 * relevant copyright in the software, without fee, provided that it
     28 * is used in conjunction with NXP Semiconductors microcontrollers.  This
     29 * copyright, permission, and disclaimer notice must appear in all copies of
     30 * this code.
     31 **********************************************************************/
     32 
     33 #ifndef _LPC17xx_IAP_H
     34 #define _LPC17xx_IAP_H
     35 #include "lpc_types.h"
     36 
     37 /** @defgroup IAP  	IAP (In Application Programming)
     38  * @ingroup LPC1700CMSIS_FwLib_Drivers
     39  * @{
     40  */
     41 
     42 /** @defgroup IAP_Public_Macros IAP Public Macros
     43  * @{
     44  */
     45 
     46 /** IAP entry location */
     47 #define IAP_LOCATION              (0x1FFF1FF1UL)
     48 
     49 /**
     50  * @}
     51  */
     52 
     53 /** @defgroup IAP_Public_Types IAP Public Types
     54  * @{
     55  */
     56 
     57 /**
     58  * @brief IAP command code definitions
     59  */
     60 typedef enum
     61 {
     62     IAP_PREPARE = 50,       // Prepare sector(s) for write operation
     63     IAP_COPY_RAM2FLASH = 51,     // Copy RAM to Flash
     64     IAP_ERASE = 52,              // Erase sector(s)
     65     IAP_BLANK_CHECK = 53,        // Blank check sector(s)
     66     IAP_READ_PART_ID = 54,       // Read chip part ID
     67     IAP_READ_BOOT_VER = 55,      // Read chip boot code version
     68     IAP_COMPARE = 56,            // Compare memory areas
     69     IAP_REINVOKE_ISP = 57,       // Reinvoke ISP
     70     IAP_READ_SERIAL_NUMBER = 58, // Read serial number
     71 }  IAP_COMMAND_CODE;
     72 
     73 /**
     74  * @brief IAP status code definitions
     75  */
     76 typedef enum
     77 {
     78     CMD_SUCCESS,	             // Command is executed successfully.
     79     INVALID_COMMAND,             // Invalid command.
     80     SRC_ADDR_ERROR,              // Source address is not on a word boundary.
     81     DST_ADDR_ERROR,              // Destination address is not on a correct boundary.
     82     SRC_ADDR_NOT_MAPPED,         // Source address is not mapped in the memory map.
     83     DST_ADDR_NOT_MAPPED,         // Destination address is not mapped in the memory map.
     84     COUNT_ERROR,	               // Byte count is not multiple of 4 or is not a permitted value.
     85     INVALID_SECTOR,	           // Sector number is invalid.
     86     SECTOR_NOT_BLANK,	           // Sector is not blank.
     87     SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION,	// Command to prepare sector for write operation was not executed.
     88     COMPARE_ERROR,               // Source and destination data is not same.
     89     BUSY,		                   // Flash programming hardware interface is busy.
     90 } IAP_STATUS_CODE;
     91 
     92 /**
     93  * @brief IAP write length definitions
     94  */
     95 typedef enum {
     96   IAP_WRITE_256  = 256,
     97   IAP_WRITE_512  = 512,
     98   IAP_WRITE_1024 = 1024,
     99   IAP_WRITE_4096 = 4096,
    100 } IAP_WRITE_SIZE;
    101 
    102 /**
    103  * @brief IAP command structure
    104  */
    105 typedef struct {
    106     uint32_t cmd;   // Command
    107     uint32_t param[4];      // Parameters
    108     uint32_t status;        // status code
    109     uint32_t result[4];     // Result
    110 } IAP_COMMAND_Type;
    111 
    112 /**
    113  * @}
    114  */
    115  
    116 /* Public Functions ----------------------------------------------------------- */
    117 /** @defgroup IAP_Public_Functions IAP Public Functions
    118  * @{
    119  */
    120 
    121 /**  Get sector number of an address */
    122 uint32_t GetSecNum (uint32_t adr);
    123 /**  Prepare sector(s) for write operation */
    124 IAP_STATUS_CODE PrepareSector(uint32_t start_sec, uint32_t end_sec);
    125 /**  Copy RAM to Flash */
    126 IAP_STATUS_CODE CopyRAM2Flash(uint8_t * dest, uint8_t* source, IAP_WRITE_SIZE size);
    127 /**  Prepare sector(s) for write operation */
    128 IAP_STATUS_CODE EraseSector(uint32_t start_sec, uint32_t end_sec);
    129 /**  Blank check sectors */
    130 IAP_STATUS_CODE BlankCheckSector(uint32_t start_sec, uint32_t end_sec,
    131                                  uint32_t *first_nblank_loc, 
    132 								 uint32_t *first_nblank_val);
    133 /**  Read part identification number */
    134 IAP_STATUS_CODE ReadPartID(uint32_t *partID);
    135 /**  Read boot code version */
    136 IAP_STATUS_CODE ReadBootCodeVer(uint8_t *major, uint8_t* minor);
    137 /**  Read Device serial number */
    138 IAP_STATUS_CODE ReadDeviceSerialNum(uint32_t *uid);
    139 /**  Compare memory */
    140 IAP_STATUS_CODE Compare(uint8_t *addr1, uint8_t *addr2, uint32_t size);
    141 /**  Invoke ISP */
    142 void InvokeISP(void);
    143 
    144 /**
    145  * @}
    146  */
    147 
    148 /**
    149  * @}
    150  */
    151 
    152 #endif /*_LPC17xx_IAP_H*/
    153