This is the mail archive of the ecos-patches@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Support for LPC2XXX IAP interface


Hello

The patch provides support for the NXP IAP (In Application Program)
interface. I just want to reserve this support to do not duplicate IAP
code in lpc2xxx on-chip flash drivers. flash_lpc2xxx_v2 comming soon.
Hans's Rosenfeld legacy flash_arm_lp2xxx driver uses IAP. The future V2
driver will use it too. I though that Hans's driver can be cleaned up
then when IAP interface will be included in CVS.

I saw no such a support in other HALs. And I decided to put it under the
lpc2xxx/var tree. 

RFC: Is it a good place for the interface in lpc2xxx/var?

There is a small test case there. The new API was tested on Olimex
LPC2294 header board

(gdb) cont
Continuing.
INFO:<Starting LPC2XXX IAP test>
INFO:<LPC2XXX device id 0x0501ff13>
INFO:<LPC2XXX part LPC2294>
PASS:<LPC2XXX IAP test OK>
EXIT:<Done>

Kind regards,

Sergei
Index: var/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/hal/arm/lpc2xxx/var/current/ChangeLog,v
retrieving revision 1.9
diff -U5 -p -r1.9 ChangeLog
--- var/current/ChangeLog	22 Jul 2008 18:52:16 -0000	1.9
+++ var/current/ChangeLog	27 Nov 2008 12:28:07 -0000
@@ -1,5 +1,13 @@
+2008-11-27  Sergei Gavrikov  <sergei.gavrikov@gmail.com>
+
+	* include/lpc2xxx_iap.h, src/lpc2xxx_iap.c, tests/iap_test.c: New
+	files. It is a support for IAP (In Application Program) interface and
+	small test case for lpc2xxx_iap_call().
+	* cdl/hal_arm_lpc2xxx.cdl: Extended CDL compile set, lpc2xxx_iap.c
+	source added. Added cdl_option CYGPKG_HAL_ARM_LPC2XXX_TESTS.
+
 2008-07-21  Uwe Kindler <uwe_kindler@web.de>
 
 	* cdl/hal_arm_lpc2xxx.cdl: Added option
 	CYGHWR_HAL_ARM_LPC2XXX_VARIANT_VERSION to identify the variant version 
 	because some on-chip peripherals changed slightly in newer veriants.
Index: var/current/cdl/hal_arm_lpc2xxx.cdl
===================================================================
RCS file: /cvs/ecos/ecos/packages/hal/arm/lpc2xxx/var/current/cdl/hal_arm_lpc2xxx.cdl,v
retrieving revision 1.5
diff -U5 -p -r1.5 hal_arm_lpc2xxx.cdl
--- var/current/cdl/hal_arm_lpc2xxx.cdl	22 Jul 2008 18:52:16 -0000	1.5
+++ var/current/cdl/hal_arm_lpc2xxx.cdl	27 Nov 2008 12:28:07 -0000
@@ -55,11 +55,11 @@ cdl_package CYGPKG_HAL_ARM_LPC2XXX {
     hardware
     description   "
         The LPC2XXX HAL package provides the support needed to run
         eCos on Philips LPC2XXX based targets."
 
-    compile       hal_diag.c lpc2xxx_misc.c
+    compile       hal_diag.c lpc2xxx_misc.c lpc2xxx_iap.c
 
     implements    CYGINT_HAL_DEBUG_GDB_STUBS
     implements    CYGINT_HAL_DEBUG_GDB_STUBS_BREAK
     implements    CYGINT_HAL_VIRTUAL_VECTOR_SUPPORT
     implements    CYGINT_HAL_VIRTUAL_VECTOR_COMM_BAUD_SUPPORT
@@ -278,6 +278,15 @@ cdl_package CYGPKG_HAL_ARM_LPC2XXX {
             into one single slot and the ISR need to  find out which interrupt 
             occured. The default value for the system clock interrupts is 0 - 
             this is the highest priority IRQ."
     }
 
+    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."
+    }
+
 }
diff -u5rN /x/iap_test.c var/current/tests/iap_test.c
--- /x/iap_test.c	1970-01-01 03:00:00.000000000 +0300
+++ var/current/tests/iap_test.c	2008-11-27 14:19:48.000000000 +0200
@@ -0,0 +1,122 @@
+//==========================================================================
+//
+//      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 <cyg/infra/cyg_type.h>
+#include <cyg/infra/testcase.h>
+
+#include <cyg/hal/lpc2xxx_iap.h>
+
+extern int      diag_printf (char *, ...);
+
+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 lpc_iap_call (HAL_LPC2XXX_IAP_COMMAND_READ_PART_ID, 0, 0, 0, 0,
+                         (cyg_uint32 *) id);
+}
+
+externC void
+#ifdef CYGPKG_KERNEL
+cyg_user_start (void)
+#else
+cyg_start (void)
+#endif
+{
+    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");
+}
+
+// indent: -i4 -br -nut -di16 -ce; vim: expandtab tabstop=4 shiftwidth=4:
+//--------------------------------------------------------------------------
+// EOF iap_test.c
--- /x	1970-01-01 03:00:00.000000000 +0300
+++ var/current/include/lpc2xxx_iap.h	2008-11-27 14:17:33.000000000 +0200
@@ -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
+lpc_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
--- /x	1970-01-01 03:00:00.000000000 +0300
+++ var/current/src/lpc2xxx_iap.c	2008-11-27 14:17:51.000000000 +0200
@@ -0,0 +1,150 @@
+//==========================================================================
+//
+//      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 <cyg/hal/lpc2xxx_iap.h>
+#include <cyg/hal/hal_intr.h>
+
+// ----------------------------------------------------------------------------
+// In most cases NXP IAP (In Appplication Programming) interface uses itself to
+// manage on-chip flash memory. Before to use this interface read two notes the
+// below, also two examples are provided as commented out C code sniplets just
+// to demo how to use lpc_iap_call().
+
+#if 0
+void
+lpc_iap_demo1 (void *data)      // read part id
+{
+    flash_data_t     *id = (flash_data_t *) data;
+    lpc_iap_call (HAL_LPC2XXX_IAP_COMMAND_READ_PART_ID, 0, 0, 0, 0,
+                  (cyg_uint32 *) id);
+    // ...
+}
+
+void
+lpc_iap_demo2 (void)            // format sectors 7, 8 of on-chip flash
+{
+    int             rc;
+    rc = lpc_iap_call (HAL_LPC2XXX_IAP_COMMAND_PREPARE_SECTORS,
+                       7, 8, 0, 0, 0);
+    if (rc != HAL_LPC2XXX_IAP_RETURN_CMD_SUCCESS) {
+        // ...
+    }
+    rc = lpc_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
+
+// 1) WARNING: lpc on-chip flash memory is not accessible during erase and
+// write operations.  When the user application code starts executing the
+// interrupt vectors from the user flash area are active. 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.
+
+// 2) IAP flash programming takes ~ 1 ms per 512 byte line. Single sector or
+// full chip erase takes 400 mS. This can be quite enougth to fire a watchdog.
+// Two calls: CYGFUN_ARM_LPC2XXX_IAP_PRECALL, CYGFUN_ARM_LPC2XXX_IAP_POSTCALL
+// calls let us be happy with the watchdog.  Certainly, the call can do
+// something another. 
+// ----------------------------------------------------------------------------
+
+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;
+
+// ----------------------------------------------------------------------------
+// lpc_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
+lpc_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];
+
+    cyg_uint32      oldints;
+
+#ifdef CYGFUN_ARM_LPC2XXX_IAP_PRECALL
+    CYGFUN_ARM_LPC2XXX_IAP_PRECALL ();
+#endif
+
+    HAL_DISABLE_INTERRUPTS (oldints);
+
+    lpc_iap_entry (command, results);
+
+    HAL_RESTORE_INTERRUPTS (oldints);
+
+#ifdef CYGFUN_ARM_LPC2XXX_IAP_POSTCALL
+    CYGFUN_ARM_LPC2XXX_IAP_POSTCALL ();
+#endif
+
+    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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]