Mercurial > ecos
changeset 2714:615dc33ccc6c
* include/lpc2xxx_iap.h, src/lpc2xxx_iap.c, tests/iap_test.c: New
files: support for IAP (In Application Programming) interface and
small test case for hal_lpc2xxx_iap_call().
* cdl/hal_arm_lpc2xxx.cdl: CYGINT_HAL_ARM_LPC2XXX_IAP_CALL interface
and CYGPKG_HAL_ARM_LPC2XXX_TESTS option added.
| author | jlarmour |
|---|---|
| date | Thu, 15 Jan 2009 03:40:47 +0000 |
| parents | 360689a2c1c5 |
| children | f9ccae0aa179 |
| files | packages/hal/arm/lpc2xxx/var/current/ChangeLog packages/hal/arm/lpc2xxx/var/current/cdl/hal_arm_lpc2xxx.cdl packages/hal/arm/lpc2xxx/var/current/include/lpc2xxx_iap.h packages/hal/arm/lpc2xxx/var/current/src/lpc2xxx_iap.c packages/hal/arm/lpc2xxx/var/current/tests/iap_test.c |
| diffstat | 5 files changed, 486 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/packages/hal/arm/lpc2xxx/var/current/ChangeLog +++ b/packages/hal/arm/lpc2xxx/var/current/ChangeLog @@ -1,3 +1,11 @@ +2009-01-15 Sergei Gavrikov <sergei.gavrikov@gmail.com> + + * include/lpc2xxx_iap.h, src/lpc2xxx_iap.c, tests/iap_test.c: New + files: support for IAP (In Application Programming) interface and + small test case for hal_lpc2xxx_iap_call(). + * cdl/hal_arm_lpc2xxx.cdl: CYGINT_HAL_ARM_LPC2XXX_IAP_CALL interface + and CYGPKG_HAL_ARM_LPC2XXX_TESTS option added. + 2008-12-02 Sergei Gavrikov <sergei.gavrikov@gmail.com> Andrew Lunn <andrew@lunn.ch>
--- a/packages/hal/arm/lpc2xxx/var/current/cdl/hal_arm_lpc2xxx.cdl +++ b/packages/hal/arm/lpc2xxx/var/current/cdl/hal_arm_lpc2xxx.cdl @@ -280,4 +280,76 @@ cdl_package CYGPKG_HAL_ARM_LPC2XXX { this is the highest priority IRQ." } + cdl_interface CYGINT_HAL_ARM_LPC2XXX_IAP_CALL { + display "Interface to manage IAP call" + } + + cdl_component CYGBLD_BUILD_HAL_LPC2XXX_WITH_IAP_CALL { + display "IAP (In Application Programming) interface" + flavor bool + default_value 1 + compile lpc2xxx_iap.c + implements CYGINT_HAL_ARM_LPC2XXX_IAP_CALL + + cdl_option CYGNUM_HAL_ARM_LPC2XXX_IAP_CALL_SAFE { + display "Disable interrupts during IAP call" + flavor bool + default_value 1 + description " + In most cases IAP calls uses itself to manage on-chip + flash memory. LPC2XXX on-chip flash memory is not + accessible during erase and write operations. The + user should either disable interrupts, or ensure that + user interrupt vectors are active in RAM and that + the interrupt handlers reside in RAM, before making a + flash erase/write IAP call. The IAP code does not use + or disable interrupts. This option disable interrupts + by default during IAP call (for safety)." + } + + cdl_option CYGFUN_HAL_ARM_LPC2XXX_IAP_CALL_WRAP { + display "Wrap for IAP call enabled" + flavor bool + active_if { CYGDAT_HAL_ARM_LPC2XXX_IAP_PRE_CALL || \ + CYGDAT_HAL_ARM_LPC2XXX_IAP_POST_CALL } + calculated 1 + description " + This option controls whether IAP call will be wrapped by + custom helpers. E.g., IAP flash programming call takes + ~ 1 ms per 512 byte line. Single sector or full chip + erase takes 400 mS. This can be quite enougth to fire a + hardware watchdog. You still can manage it using own pre- + and (or) post-calls." + } + + # void (*precall)(void) + cdl_option CYGDAT_HAL_ARM_LPC2XXX_IAP_PRE_CALL { + display "Use custom IAP pre-call" + flavor booldata + default_value 0 + description " + If enabled, this option will tell IAP call to use the + value of this option as a custom pre-call." + } + + # void (*postcall)(void) + cdl_option CYGDAT_HAL_ARM_LPC2XXX_IAP_POST_CALL { + display "Use custom IAP post-call" + flavor booldata + default_value 0 + description " + If enabled, this option will tell IAP call to use the + value of this option as a custom post-call." + } + } + + cdl_option CYGPKG_HAL_ARM_LPC2XXX_TESTS { + display "LPC2XXX HAL tests" + flavor data + no_define + calculated { "tests/iap_test" } + description " + This option specifies the set of tests for the LPC2XXX HAL." + } + }
new file mode 100644 --- /dev/null +++ b/packages/hal/arm/lpc2xxx/var/current/include/lpc2xxx_iap.h @@ -0,0 +1,103 @@ +#ifndef CYGONCE_LPC2XXX_IAP_H +#define CYGONCE_LPC2XXX_IAP_H +//========================================================================== +// +// lpc2xxx_iap.h +// +// LPC2XXX IAP (In Application Programming) interface +// +//========================================================================== +//####ECOSGPLCOPYRIGHTBEGIN#### +// ------------------------------------------- +// This file is part of eCos, the Embedded Configurable Operating System. +// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. +// Copyright (C) 2006 eCosCentric Limited +// +// eCos is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 2 or (at your option) any later version. +// +// eCos is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with eCos; if not, write to the Free Software Foundation, Inc., +// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +// +// As a special exception, if other files instantiate templates or use macros +// or inline functions from this file, or you compile this file and link it +// with other works to produce a work based on this file, this file does not +// by itself cause the resulting work to be covered by the GNU General Public +// License. However the source code for this file must still be made available +// in accordance with section (3) of the GNU General Public License. +// +// This exception does not invalidate any other reasons why a work based on +// this file might be covered by the GNU General Public License. +// ------------------------------------------- +//####ECOSGPLCOPYRIGHTEND#### +//========================================================================== +//#####DESCRIPTIONBEGIN#### +// +// Author(s): Sergei Gavrikov +// Contributors: Sergei Gavrikov +// Date: 2007-09-20 +// Purpose: +// Description: +// Usage: #include <cyg/hal/lpc2xxx_iap.h> +// +//####DESCRIPTIONEND#### +// +//========================================================================== + +#include <cyg/infra/cyg_type.h> + +//---------------------------------------------------------------------------- +// The LPC2XXX IAP entry point is at 0x7FFFFFF0 if you wish to call the IAP +// functions from a THUMB function or at 0x7FFFFFF1 if you wish to call from +// an ARM function. + +#define HAL_LPC2XXX_IAP_ENTRY_THUMB 0x7FFFFFF0u +#define HAL_LPC2XXX_IAP_ENTRY_ARM 0x7FFFFFF1u + +#ifndef HAL_LPC2XXX_IAP_ENTRY_DEFAULT +# define HAL_LPC2XXX_IAP_ENTRY_DEFAULT HAL_LPC2XXX_IAP_ENTRY_ARM +#endif + +// LPC2XXX IAP return code +#define HAL_LPC2XXX_IAP_RETURN_CMD_SUCCESS 0 +#define HAL_LPC2XXX_IAP_RETURN_INVALID_COMMAND 1 +#define HAL_LPC2XXX_IAP_RETURN_SRC_ADDR_ERROR 2 +#define HAL_LPC2XXX_IAP_RETURN_DST_ADDR_ERROR 3 +#define HAL_LPC2XXX_IAP_RETURN_SRC_ADDR_NOT_MAPPED 4 +#define HAL_LPC2XXX_IAP_RETURN_DST_ADDR_NOT_MAPPED 5 +#define HAL_LPC2XXX_IAP_RETURN_COUNT_ERROR 6 +#define HAL_LPC2XXX_IAP_RETURN_INVALID_SECTOR 7 +#define HAL_LPC2XXX_IAP_RETURN_SECTOR_NOT_BLANK 8 +#define HAL_LPC2XXX_IAP_RETURN_SECTOR_NOT_PREPARED 9 +#define HAL_LPC2XXX_IAP_RETURN_COMPARE_ERROR 10 +#define HAL_LPC2XXX_IAP_RETURN_BUSY 11 +#define HAL_LPC2XXX_IAP_RETURN_PARAM_ERROR 12 +#define HAL_LPC2XXX_IAP_RETURN_ADDR_ERROR 13 +#define HAL_LPC2XXX_IAP_RETURN_ADDR_NOT_MAPPED 14 +#define HAL_LPC2XXX_IAP_RETURN_CMD_LOCKED 15 +#define HAL_LPC2XXX_IAP_RETURN_INVALID_CODE 16 +#define HAL_LPC2XXX_IAP_RETURN_INVALID_BAUD_RATE 17 +#define HAL_LPC2XXX_IAP_RETURN_INVALID_STOP_BIT 18 + +// LPC2XXX IAP commands +#define HAL_LPC2XXX_IAP_COMMAND_PREPARE_SECTORS 50 +#define HAL_LPC2XXX_IAP_COMMAND_COPY_RAM_TO_FLASH 51 +#define HAL_LPC2XXX_IAP_COMMAND_ERASE_SECTORS 52 +#define HAL_LPC2XXX_IAP_COMMAND_BLANK_CHECK_SECTORS 53 +#define HAL_LPC2XXX_IAP_COMMAND_READ_PART_ID 54 +#define HAL_LPC2XXX_IAP_COMMAND_READ_BOOT_CODE_VERSION 55 +#define HAL_LPC2XXX_IAP_COMMAND_COMPARE 56 + +cyg_uint32 +hal_lpc2xxx_iap_call (cyg_uint32 cmd, cyg_uint32 par0, cyg_uint32 par1, + cyg_uint32 par2, cyg_uint32 par3, cyg_uint32 * ret); + +#endif//CYGONCE_LPC2XXX_IAP_H +// EOF lpc2xxx_iap.h
new file mode 100644 --- /dev/null +++ b/packages/hal/arm/lpc2xxx/var/current/src/lpc2xxx_iap.c @@ -0,0 +1,171 @@ +//========================================================================== +// +// lpc2xxx_iap.c +// +// LPC2XXX IAP (In Application Programming) interface +// +//========================================================================== +//####ECOSGPLCOPYRIGHTBEGIN#### +// ------------------------------------------- +// This file is part of eCos, the Embedded Configurable Operating System. +// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. +// Copyright (C) 2006 eCosCentric Limited +// +// eCos is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 2 or (at your option) any later version. +// +// eCos is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with eCos; if not, write to the Free Software Foundation, Inc., +// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +// +// As a special exception, if other files instantiate templates or use macros +// or inline functions from this file, or you compile this file and link it +// with other works to produce a work based on this file, this file does not +// by itself cause the resulting work to be covered by the GNU General Public +// License. However the source code for this file must still be made available +// in accordance with section (3) of the GNU General Public License. +// +// This exception does not invalidate any other reasons why a work based on +// this file might be covered by the GNU General Public License. +// ------------------------------------------- +//####ECOSGPLCOPYRIGHTEND#### +//========================================================================== +//#####DESCRIPTIONBEGIN#### +// +// Author(s): Sergei Gavrikov +// Contributors: Sergei Gavrikov +// Date: 2007-09-20 +// Purpose: +// Description: +// +//####DESCRIPTIONEND#### +// +//========================================================================== + +#include <pkgconf/hal_arm_lpc2xxx.h> +#include <cyg/hal/hal_intr.h> + +#include <cyg/hal/lpc2xxx_iap.h> + +// ---------------------------------------------------------------------------- +// In most cases NXP IAP (In Appplication Programming) interface uses itself to +// manage on-chip flash memory. Two simple examples are provided the below as +// commented out C code sniplets just to demo how to use the IAP call there. +// ---------------------------------------------------------------------------- +#if 0 +void +iap_call_demo1 (void *data) // Read part id +{ + flash_data_t *id = (flash_data_t *) data; + + hal_lpc2xxx_iap_call (HAL_LPC2XXX_IAP_COMMAND_READ_PART_ID, 0, 0, 0, 0, + (cyg_uint32 *) id); + // ... +} + +void +iap_call_demo2 (void) // Format sectors 7, 8 of on-chip flash +{ + int rc; + + rc = hal_lpc2xxx_iap_call (HAL_LPC2XXX_IAP_COMMAND_PREPARE_SECTORS, + 7, 8, 0, 0, 0); + if (rc != HAL_LPC2XXX_IAP_RETURN_CMD_SUCCESS) { + // ... + } + rc = hal_lpc2xxx_iap_call (HAL_LPC2XXX_IAP_COMMAND_ERASE_SECTORS, 7, + 8, CYGNUM_HAL_ARM_LPC2XXX_CLOCK_SPEED / 1000, + 0, 0); + if (rc != HAL_LPC2XXX_IAP_RETURN_CMD_SUCCESS) { + // ... + } +} +#endif +// ---------------------------------------------------------------------------- + +typedef void (*lpc_iap_entry_t) (cyg_uint32[], cyg_uint32[]); + +static lpc_iap_entry_t lpc_iap_entry = + (lpc_iap_entry_t) HAL_LPC2XXX_IAP_ENTRY_DEFAULT; + + +static void (*precall) (void) = NULL; +static void (*postcall) (void) = NULL; + +static int initialized = 0; + +static void +hal_lpc2xxx_iap_init (void) { +#ifdef CYGFUN_HAL_ARM_LPC2XXX_IAP_CALL_WRAP +# ifdef CYGDAT_HAL_ARM_LPC2XXX_IAP_PRE_CALL + if (!precall) { + precall = CYGDAT_HAL_ARM_LPC2XXX_IAP_PRE_CALL; + } +# endif +# ifdef CYGDAT_HAL_ARM_LPC2XXX_IAP_POST_CALL + if (!postcall) { + postcall = CYGDAT_HAL_ARM_LPC2XXX_IAP_POST_CALL; + } +# endif +#endif + initialized = 1; +} + +// ---------------------------------------------------------------------------- +// hal_lpc2xxx_iap_call -- +// +// Arguments: 'cmd' - code of NXP IAP command, 'par0'...'par3' - parameters, +// and the last argument 'ret' is a pointer on an array of cyg_uint32 values +// (at the least room for two elemets in the array must be reserved) for the +// returned data. +// +// Returns 0 (HAL_LPC2XXX_IAP_RETURN_CMD_SUCCESS) on success, otherwise error +// code (see <cyg/hal/lpc2xxx_iap.h> for details). +// +cyg_uint32 +hal_lpc2xxx_iap_call (cyg_uint32 cmd, cyg_uint32 par0, cyg_uint32 par1, + cyg_uint32 par2, cyg_uint32 par3, cyg_uint32 * ret) +{ + cyg_uint32 command[5] = { cmd, par0, par1, par2, par3 }; + cyg_uint32 results[2]; + +#ifdef CYGNUM_HAL_ARM_LPC2XXX_IAP_CALL_SAFE + cyg_uint32 oldints; +#endif + + if (!initialized) + hal_lpc2xxx_iap_init (); + + if (precall) + precall (); + +#ifdef CYGNUM_HAL_ARM_LPC2XXX_IAP_CALL_SAFE + HAL_DISABLE_INTERRUPTS (oldints); +#endif + + lpc_iap_entry (command, results); + +#ifdef CYGNUM_HAL_ARM_LPC2XXX_IAP_CALL_SAFE + HAL_RESTORE_INTERRUPTS (oldints); +#endif + + if (postcall) + postcall (); + + if (ret != NULL) { + ret[0] = results[0]; // return code + ret[1] = results[1]; // fill in data + } + + return results[0]; +} + +// indent: -i4 -br -nut -di16 -ce; vim: expandtab tabstop=4 shiftwidth=4: +//-------------------------------------------------------------------------- +// EOF lpc2xxx_iap.c
new file mode 100644 --- /dev/null +++ b/packages/hal/arm/lpc2xxx/var/current/tests/iap_test.c @@ -0,0 +1,132 @@ +//========================================================================== +// +// iap_test.c +// +// IAP test for ARM LPC2XXX platforms +// +//========================================================================== +//####ECOSGPLCOPYRIGHTBEGIN#### +// ------------------------------------------- +// This file is part of eCos, the Embedded Configurable Operating System. +// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. +// Copyright (C) 2006 eCosCentric Limited +// +// eCos is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 2 or (at your option) any later version. +// +// eCos is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with eCos; if not, write to the Free Software Foundation, Inc., +// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +// +// As a special exception, if other files instantiate templates or use macros +// or inline functions from this file, or you compile this file and link it +// with other works to produce a work based on this file, this file does not +// by itself cause the resulting work to be covered by the GNU General Public +// License. However the source code for this file must still be made available +// in accordance with section (3) of the GNU General Public License. +// +// This exception does not invalidate any other reasons why a work based on +// this file might be covered by the GNU General Public License. +// ------------------------------------------- +//####ECOSGPLCOPYRIGHTEND#### +//========================================================================== +//#####DESCRIPTIONBEGIN#### +// +// Author(s): Sergei Gavrikov +// Contributors: Sergei Gavrikov +// Date: 2007-09-20 +// Purpose: +// Description: Basic test for IAP (In Application Programming) interface +// +//####DESCRIPTIONEND#### +// +//========================================================================== + +#include <pkgconf/hal_arm_lpc2xxx.h> + +#include <cyg/infra/cyg_type.h> +#include <cyg/infra/testcase.h> +#include <cyg/infra/diag.h> + +#if defined(CYGBLD_BUILD_HAL_LPC2XXX_WITH_IAP_CALL) \ + && (CYGINT_HAL_ARM_LPC2XXX_IAP_CALL == 1) + +#include <cyg/hal/lpc2xxx_iap.h> + +typedef struct { + cyg_uint32 id; + char part[8]; +} lpc_part_id_info_t; + +static lpc_part_id_info_t known_parts[] = { + {0xFFF0FF12, "LPC2104"}, {0xFFF0FF22, "LPC2105"}, {0xFFF0FF32, "LPC2106"}, + {0x0101FF12, "LPC2114"}, {0x0201FF12, "LPC2119"}, {0x0101FF13, "LPC2124"}, + {0x0201FF13, "LPC2129"}, {0x0301FF13, "LPC2194"}, {0x0401FF12, "LPC2212"}, + {0x0601FF13, "LPC2214"}, {0x0401FF13, "LPC2292"}, {0x0501FF13, "LPC2294"}, + {0x0002FF11, "LPC2132"}, {0x0002FF12, "LPC2134"}, {0x0002FF23, "LPC2136"}, + {0x0002FF25, "LPC2138"} +}; + +static cyg_uint32 data[2]; + +static int +read_part_id (void *data) +{ + cyg_uint32 *id = (cyg_uint32 *) data; + return hal_lpc2xxx_iap_call (HAL_LPC2XXX_IAP_COMMAND_READ_PART_ID, 0, 0, + 0, 0, (cyg_uint32 *) id); +} + +void +cyg_start (void) +{ + int i, rc; + cyg_uint32 device_id; + char *part = "unknow"; + + CYG_TEST_INIT (); + CYG_TEST_INFO ("Starting LPC2XXX IAP test"); + + // The simplest way to test IAP call is just to read NXP Device ID with it. + // The Device ID is a unique number for every LPC2XXX chip. So, here we use + // IAP command HAL_LPC2XXX_IAP_COMMAND_READ_PART_ID to get the number. + rc = read_part_id (data); + CYG_TEST_CHECK (rc == HAL_LPC2XXX_IAP_RETURN_CMD_SUCCESS, + "Read of Device ID failed"); + + device_id = data[1]; + + for (i = 0; i < CYG_NELEM (known_parts); i++) { + if (device_id == known_parts[i].id) { + part = known_parts[i].part; + break; + } + } + + diag_printf ("INFO:<LPC2XXX device id 0x%08x>\n", device_id); + diag_printf ("INFO:<LPC2XXX part %s>\n", part); + + CYG_TEST_PASS ("LPC2XXX IAP test OK"); + + CYG_TEST_EXIT ("Done"); +} +#else +void +cyg_start (void) +{ + CYG_TEST_INIT (); + CYG_TEST_INFO ("LPC2XXX IAP test require:\n" + "CYGINT_HAL_ARM_LPC2XXX_IAP_CALL"); + CYG_TEST_NA ("LPC2XXX IAP test requirements"); +} +#endif + +// indent: -i4 -br -nut -di16 -ce; vim: expandtab tabstop=4 shiftwidth=4: +//-------------------------------------------------------------------------- +// EOF iap_test.c
