* Support for LPC2XXX IAP interface
@ 2008-11-27 12:51 Sergei Gavrikov
2008-11-27 17:15 ` Jonathan Larmour
0 siblings, 1 reply; 5+ messages in thread
From: Sergei Gavrikov @ 2008-11-27 12:51 UTC (permalink / raw)
To: eCos patches list
[-- Attachment #1: Type: text/plain, Size: 831 bytes --]
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
[-- Attachment #2: lpc2xxx_iap.patch --]
[-- Type: text/x-diff, Size: 17899 bytes --]
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Support for LPC2XXX IAP interface
2008-11-27 12:51 Support for LPC2XXX IAP interface Sergei Gavrikov
@ 2008-11-27 17:15 ` Jonathan Larmour
2008-11-27 17:43 ` Sergei Gavrikov
0 siblings, 1 reply; 5+ messages in thread
From: Jonathan Larmour @ 2008-11-27 17:15 UTC (permalink / raw)
To: Sergei Gavrikov; +Cc: eCos patches list
Sergei Gavrikov wrote:
>
> 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?
Seems fine.
> +//==========================================================================
> +
> +#include <cyg/infra/cyg_type.h>
> +#include <cyg/infra/testcase.h>
> +
> +#include <cyg/hal/lpc2xxx_iap.h>
> +
> +extern int diag_printf (char *, ...);
include diag.h
> +externC void
> +#ifdef CYGPKG_KERNEL
> +cyg_user_start (void)
> +#else
> +cyg_start (void)
> +#endif
> +{
Why ifdef kernel?
> +cyg_uint32
> +lpc_iap_call (cyg_uint32 cmd, cyg_uint32 par0, cyg_uint32 par1,
> + cyg_uint32 par2, cyg_uint32 par3, cyg_uint32 *ret);
This would be better named something like hal_lpc2xxx_iap_call.
> +// 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.
You say the user, but below, you do disable interrupts.
It sounds like this could be a CDL option, which defaults to what you do
i.e. disabling interrupts (for safety). After all, the flash programming
would severely hamper real-time operation so many people would want to
avoid it..
Otherwise fine.
Jifl
--
eCosCentric Limited http://www.eCosCentric.com/ The eCos experts
Barnwell House, Barnwell Drive, Cambridge, UK. Tel: +44 1223 245571
Registered in England and Wales: Reg No 4422071.
------["Si fractum non sit, noli id reficere"]------ Opinions==mine
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Support for LPC2XXX IAP interface
2008-11-27 17:15 ` Jonathan Larmour
@ 2008-11-27 17:43 ` Sergei Gavrikov
2008-11-28 0:17 ` Sergei Gavrikov
0 siblings, 1 reply; 5+ messages in thread
From: Sergei Gavrikov @ 2008-11-27 17:43 UTC (permalink / raw)
To: Jonathan Larmour; +Cc: Sergei Gavrikov, eCos patches list
Thank you for your feedback and the valuable remarks. Tonight I fix all
and repost a cleaned code.
Thank you, all the best,
Sergei
On Thu, Nov 27, 2008 at 05:14:15PM +0000, Jonathan Larmour wrote:
> Sergei Gavrikov wrote:
> >
> > 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?
>
> Seems fine.
>
> > +//==========================================================================
> > +
> > +#include <cyg/infra/cyg_type.h>
> > +#include <cyg/infra/testcase.h>
> > +
> > +#include <cyg/hal/lpc2xxx_iap.h>
> > +
> > +extern int diag_printf (char *, ...);
>
> include diag.h
>
>
> > +externC void
> > +#ifdef CYGPKG_KERNEL
> > +cyg_user_start (void)
> > +#else
> > +cyg_start (void)
> > +#endif
> > +{
>
> Why ifdef kernel?
>
> > +cyg_uint32
> > +lpc_iap_call (cyg_uint32 cmd, cyg_uint32 par0, cyg_uint32 par1,
> > + cyg_uint32 par2, cyg_uint32 par3, cyg_uint32 *ret);
>
> This would be better named something like hal_lpc2xxx_iap_call.
>
> > +// 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.
>
> You say the user, but below, you do disable interrupts.
>
> It sounds like this could be a CDL option, which defaults to what you do
> i.e. disabling interrupts (for safety). After all, the flash programming
> would severely hamper real-time operation so many people would want to
> avoid it..
>
> Otherwise fine.
>
> Jifl
> --
> eCosCentric Limited http://www.eCosCentric.com/ The eCos experts
> Barnwell House, Barnwell Drive, Cambridge, UK. Tel: +44 1223 245571
> Registered in England and Wales: Reg No 4422071.
> ------["Si fractum non sit, noli id reficere"]------ Opinions==mine
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Support for LPC2XXX IAP interface
2008-11-27 17:43 ` Sergei Gavrikov
@ 2008-11-28 0:17 ` Sergei Gavrikov
2009-01-15 3:42 ` Jonathan Larmour
0 siblings, 1 reply; 5+ messages in thread
From: Sergei Gavrikov @ 2008-11-28 0:17 UTC (permalink / raw)
To: Jonathan Larmour; +Cc: eCos patches list
[-- Attachment #1: Type: text/plain, Size: 675 bytes --]
On Thu, Nov 27, 2008 at 07:42:01PM +0200, Sergei Gavrikov wrote:
> Thank you for your feedback and the valuable remarks. Tonight I fix all
> and repost a cleaned code.
Done. IAP interface is an optional now, include itself by default with
cdl_component CYGBLD_BUILD_HAL_LPC2XXX_WITH_IAP_CALL.
(gdb) cont
Continuing.
INFO:<Starting LPC2XXX IAP test>
INFO:<LPC2XXX device id 0x0501ff13>
INFO:<LPC2XXX part LPC2294>
PASS:<LPC2XXX IAP test OK>
EXIT:<Done>
cdl_component CYGBLD_BUILD_HAL_LPC2XXX_WITH_IAP_CALL {
user_value 0
};
(gdb) cont
Continuing.
INFO:<LPC2XXX IAP test require:
CYGINT_HAL_ARM_LPC2XXX_IAP_CALL>
NOTAPPLICABLE:<LPC2XXX IAP test requirements>
Sergei
[-- Attachment #2: hal_lpc2xxx_var.diff --]
[-- Type: text/x-diff, Size: 20654 bytes --]
Index: hal/arm/lpc2xxx/var/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/hal/arm/lpc2xxx/var/current/ChangeLog,v
retrieving revision 1.9
diff -u -5 -r1.9 ChangeLog
--- hal/arm/lpc2xxx/var/current/ChangeLog 22 Jul 2008 18:52:16 -0000 1.9
+++ hal/arm/lpc2xxx/var/current/ChangeLog 28 Nov 2008 00:00:05 -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: 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-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: hal/arm/lpc2xxx/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 -u -5 -r1.5 hal_arm_lpc2xxx.cdl
--- hal/arm/lpc2xxx/var/current/cdl/hal_arm_lpc2xxx.cdl 22 Jul 2008 18:52:16 -0000 1.5
+++ hal/arm/lpc2xxx/var/current/cdl/hal_arm_lpc2xxx.cdl 28 Nov 2008 00:00:05 -0000
@@ -278,6 +278,78 @@
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_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."
+ }
+
}
--- /dev/null 2008-04-29 00:50:54.000000000 +0300
+++ hal/arm/lpc2xxx/var/current/include/lpc2xxx_iap.h 2008-11-27 22:19:20.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
+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
--- /dev/null 2008-04-29 00:50:54.000000000 +0300
+++ hal/arm/lpc2xxx/var/current/src/lpc2xxx_iap.c 2008-11-28 01:40:37.000000000 +0200
@@ -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
--- /dev/null 2008-04-29 00:50:54.000000000 +0300
+++ hal/arm/lpc2xxx/var/current/tests/iap_test.c 2008-11-28 01:36:07.000000000 +0200
@@ -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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Support for LPC2XXX IAP interface
2008-11-28 0:17 ` Sergei Gavrikov
@ 2009-01-15 3:42 ` Jonathan Larmour
0 siblings, 0 replies; 5+ messages in thread
From: Jonathan Larmour @ 2009-01-15 3:42 UTC (permalink / raw)
To: Sergei Gavrikov; +Cc: eCos patches list
Sergei Gavrikov wrote:
> On Thu, Nov 27, 2008 at 07:42:01PM +0200, Sergei Gavrikov wrote:
>
>>Thank you for your feedback and the valuable remarks. Tonight I fix all
>>and repost a cleaned code.
>
>
> Done. IAP interface is an optional now, include itself by default with
> cdl_component CYGBLD_BUILD_HAL_LPC2XXX_WITH_IAP_CALL.
This got a bit buried in my Inbox, but it looks great and I've committed
it, thanks!
Jifl
--
eCosCentric Limited http://www.eCosCentric.com/ The eCos experts
Barnwell House, Barnwell Drive, Cambridge, UK. Tel: +44 1223 245571
Registered in England and Wales: Reg No 4422071.
------["The best things in life aren't things."]------ Opinions==mine
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-01-15 3:42 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-27 12:51 Support for LPC2XXX IAP interface Sergei Gavrikov
2008-11-27 17:15 ` Jonathan Larmour
2008-11-27 17:43 ` Sergei Gavrikov
2008-11-28 0:17 ` Sergei Gavrikov
2009-01-15 3:42 ` Jonathan Larmour
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).