Nut/OS  5.0.5
API Reference
lpc17xx_iap.h
Go to the documentation of this file.
00001 #ifndef _LPC17XX_IAP_H_
00002 #define _LPC17XX_IAP_H_
00003 
00004 /*
00005  * Copyright (C) 2012 by Ole Reinhardt (ole.reinhardt@embedded-it.de)
00006  *
00007  * All rights reserved.
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted provided that the following conditions
00011  * are met:
00012  *
00013  * 1. Redistributions of source code must retain the above copyright
00014  *    notice, this list of conditions and the following disclaimer.
00015  * 2. Redistributions in binary form must reproduce the above copyright
00016  *    notice, this list of conditions and the following disclaimer in the
00017  *    documentation and/or other materials provided with the distribution.
00018  * 3. Neither the name of the copyright holders nor the names of
00019  *    contributors may be used to endorse or promote products derived
00020  *    from this software without specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00029  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00030  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00031  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00032  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00033  * SUCH DAMAGE.
00034  *
00035  * For additional information see http://www.ethernut.de/
00036  *
00037  *
00038  * Parts taken from lpc177x_8x_iap.h        2011-11-21
00039  *
00040  * file     lpc177x_8x_iap.h
00041  * brief    Contains all functions support for IAP
00042  *          on LPC177x_8x
00043  * version  1.0
00044  * date     21. November. 2011
00045  * author   NXP MCU SW Application Team
00046  *
00047  * Copyright(C) 2011, NXP Semiconductor
00048  * All rights reserved.
00049  *
00050  ***********************************************************************
00051  * Software that is described herein is for illustrative purposes only
00052  * which provides customers with programming information regarding the
00053  * products. This software is supplied "AS IS" without any warranties.
00054  * NXP Semiconductors assumes no responsibility or liability for the
00055  * use of the software, conveys no license or title under any patent,
00056  * copyright, or mask work right to the product. NXP Semiconductors
00057  * reserves the right to make changes in the software without
00058  * notification. NXP Semiconductors also make no representation or
00059  * warranty that such application will be suitable for the specified
00060  * use without further testing or modification.
00061  * Permission to use, copy, modify, and distribute this software and its
00062  * documentation is hereby granted, under NXP Semiconductors'
00063  * relevant copyright in the software, without fee, provided that it
00064  * is used in conjunction with NXP Semiconductors microcontrollers.  This
00065  * copyright, permission, and disclaimer notice must appear in all copies of
00066  * this code.
00067  **********************************************************************/
00068 
00069 /*----------------------------------------------------------------------------*
00070   General defines
00071  *----------------------------------------------------------------------------*/
00072 
00073 /* IAP entry location */
00074 #define IAP_LOCATION            (0x1FFF1FF1UL)
00075 
00076 
00080 typedef enum
00081 {
00082     IAP_PREPARE = 50,            /* Prepare sector(s) for write operation     */
00083     IAP_COPY_RAM2FLASH = 51,     /* Copy RAM to Flash                         */
00084     IAP_ERASE = 52,              /* Erase sector(s)                           */
00085     IAP_BLANK_CHECK = 53,        /* Blank check sector(s)                     */
00086     IAP_READ_PART_ID = 54,       /* Read chip part ID                         */
00087     IAP_READ_BOOT_VER = 55,      /* Read chip boot code version               */
00088     IAP_COMPARE = 56,            /* Compare memory areas                      */
00089     IAP_REINVOKE_ISP = 57,       /* Reinvoke ISP                              */
00090     IAP_READ_SERIAL_NUMBER = 58, /* Read serial number                        */
00091 } IAP_COMMAND_CODE;
00092 
00096 typedef enum
00097 {
00098     CMD_SUCCESS,                 /* Command is executed successfully.         */
00099     INVALID_COMMAND,             /* Invalid command.                          */
00100     SRC_ADDR_ERROR,              /* Source address is not on a word boundary. */
00101     DST_ADDR_ERROR,              /* Destination address is not on a correct boundary.    */
00102     SRC_ADDR_NOT_MAPPED,         /* Source address is not mapped in the memory map.      */
00103     DST_ADDR_NOT_MAPPED,         /* Destination address is not mapped in the memory map. */
00104     COUNT_ERROR,                 /* Byte count is not multiple of 4 or is not a permitted value. */
00105     INVALID_SECTOR,              /* Sector number is invalid.                 */
00106     SECTOR_NOT_BLANK,            /* Sector is not blank.                      */
00107     SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION,    /* Command to prepare sector for write operation was not executed. */
00108     COMPARE_ERROR,               /* Source and destination data is not same.  */
00109     BUSY,                        /* Flash programming hardware interface is busy. */
00110 } IAP_STATUS_CODE;
00111 
00115 typedef enum {
00116     IAP_WRITE_256  = 256,
00117     IAP_WRITE_512  = 512,
00118     IAP_WRITE_1024 = 1024,
00119     IAP_WRITE_4096 = 4096,
00120 } IAP_WRITE_SIZE;
00121 
00125 typedef struct {
00126     uint32_t cmd;                 /* Command     */
00127     uint32_t param[4];            /* Parameters  */
00128     uint32_t status;              /* status code */
00129     uint32_t result[4];           /* Result      */
00130 } IAP_COMMAND_Type;
00131 
00136 uint32_t Lpc17xxIapGetSectorNr (uint32_t addr);
00137 IAP_STATUS_CODE Lpc17xxIapSectorRead(uint32_t addr, void *data, size_t len);
00138 IAP_STATUS_CODE Lpc17xxIapSectorWrite(uint32_t dest, void* source, IAP_WRITE_SIZE size);
00139 IAP_STATUS_CODE Lpc17xxIapSectorErase(uint32_t start_sec, uint32_t end_sec);
00140 IAP_STATUS_CODE Lpc17xxIapSectorBlankCheck(uint32_t start_sec, uint32_t end_sec,
00141                                  uint32_t *first_nblank_off, uint32_t *first_nblank_val);
00142 IAP_STATUS_CODE Lpc17xxIapReadBootCodeVersion(uint8_t *major, uint8_t* minor);
00143 IAP_STATUS_CODE Lpc17xxIapReadDeviceSerialNumber(uint32_t *uid);
00144 int Lpc17xxIapParamRead(unsigned int pos, void *data, size_t len);
00145 int Lpc17xxIapParamWrite(unsigned int pos, const void *data, size_t len);
00146 
00147 #endif /* _LPC177X_IAP_H_ */
00148