changeset 2979:013b321ed7df

ea_lpc2468_nand.c: Fix interrupt-mode brokenness when the debug level was low.
author Ross Younger <wry@ecoscentric.com>
date Tue, 10 Nov 2009 12:04:36 +0000
parents fbb6348661fe
children b54e7bc232f0
files packages/hal/arm/lpc24xx/ea2468/current/ChangeLog packages/hal/arm/lpc24xx/ea2468/current/src/ea_lpc2468_nand.c
diffstat 2 files changed, 38 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/packages/hal/arm/lpc24xx/ea2468/current/ChangeLog
+++ b/packages/hal/arm/lpc24xx/ea2468/current/ChangeLog
@@ -1,3 +1,8 @@
+2009-11-10  Ross Younger <wry@ecoscentric.com>
+
+	* ea_lpc2468_nand.c: Fix interrupt-mode brokenness when the debug
+	  level was low.
+
 2009-11-06  Ross Younger <wry@ecoscentric.com>
 
 	* ea_lpc2468_nand.c: Use mtd_ecc256_fast, not linux_mtd_ecc.
--- a/packages/hal/arm/lpc24xx/ea2468/current/src/ea_lpc2468_nand.c
+++ b/packages/hal/arm/lpc24xx/ea2468/current/src/ea_lpc2468_nand.c
@@ -65,7 +65,7 @@ struct _mypriv {
     cyg_handle_t    inthdl; // interrupt handle
     cyg_interrupt   intr; // interrupt object
 
-    int ready;          // Set when interrupt fires. Protected by DSR lock.
+    volatile int ready;  // Set when interrupt fires. Protected by DSR lock.
 #else
     char dummy; // shush, gcc
 #endif
@@ -151,6 +151,11 @@ static void wait_ready_or_status(cyg_nan
 
 #define POLL_INTERVAL 10 /* us */
 
+#define POLLCOUNT_COUNTING_LEVEL 7
+#if defined(CYGSEM_IO_NAND_DEBUG_LEVEL) && (CYGSEM_IO_NAND_DEBUG_LEVEL >= POLLCOUNT_COUNTING_LEVEL)
+#define REPORT_POLLS
+#endif
+
 /* Case 1: The NAND_RDY line is not connected. ---------------------- */
 #ifndef CYGHWR_HAL_ARM_LPC2XXX_EA_LPC2468_USE_NAND_RDY
 
@@ -163,11 +168,6 @@ static void wait_ready_or_time(cyg_nand_
     HAL_DELAY_US(initial+fallback);
 }
 
-#define POLLCOUNT_COUNTING_LEVEL 7
-#if defined(CYGSEM_IO_NAND_DEBUG_LEVEL) && (CYGSEM_IO_NAND_DEBUG_LEVEL >= POLLCOUNT_COUNTING_LEVEL)
-#define REPORT_POLLS
-#endif
-
 static void wait_ready_or_status(cyg_nand_device *dev, CYG_BYTE mask)
 {
     // The Ready line won't be ready for at least tWB (100ns), so out of 
@@ -207,26 +207,7 @@ static inline int is_chip_ready(cyg_nand
     return rv;
 }
 
-/* Polling loop, does not return until the chip is READY.
- * Callers should themselves wait for tWB or other initial time 
- * to ensure that READY is deasserted. */
-static void wait_ready_polled(cyg_nand_device *ctx)
-{
-#ifdef REPORT_POLLS
-    int polls=0;
-#endif
-    while (0==is_chip_ready(ctx)) {
-        HAL_DELAY_US(POLL_INTERVAL);
-#ifdef REPORT_POLLS
-        ++polls;
-#endif
-    }
-#ifdef REPORT_POLLS
-    NAND_CHATTER(8, ctx, "!BUSY: pollcount %d\n",polls);
-#endif
-}
-
-
+static void wait_ready_polled(cyg_nand_device *ctx);
 
 # ifdef CYGHWR_HAL_ARM_LPC2XXX_EA_LPC2468_NAND_RDY_USE_INTERRUPT
 /* Case 2A: We are using sleep+interrupt wherever possible. */
@@ -377,7 +358,33 @@ static inline int ea_plf_init_nointerrup
 }
 
 # endif
+
+/* Polling loop, does not return until the chip is READY.
+ * Callers should themselves wait for tWB or other initial time 
+ * to ensure that READY is deasserted. */
+static void wait_ready_polled(cyg_nand_device *ctx)
+{
+#ifdef REPORT_POLLS
+    int polls=0;
 #endif
+#ifdef CYGHWR_HAL_ARM_LPC2XXX_EA_LPC2468_NAND_RDY_USE_INTERRUPT
+    cyg_drv_interrupt_unmask(NAND_RDY_VECTOR);
+#endif
+    while (0==is_chip_ready(ctx)) {
+        HAL_DELAY_US(POLL_INTERVAL);
+#ifdef REPORT_POLLS
+        ++polls;
+#endif
+    }
+#ifdef CYGHWR_HAL_ARM_LPC2XXX_EA_LPC2468_NAND_RDY_USE_INTERRUPT
+    cyg_drv_interrupt_mask(NAND_RDY_VECTOR);
+#endif
+#ifdef REPORT_POLLS
+    NAND_CHATTER(8, ctx, "!BUSY: pollcount %d\n",polls);
+#endif
+}
+
+#endif // USE_INTERRUPT ?
 
 static int k9_plf_init(cyg_nand_device *dev)
 {