TX51/TX53 Release 2011-08-19
authorlothar <lothar>
Fri, 19 Aug 2011 09:10:51 +0000 (09:10 +0000)
committerlothar <lothar>
Fri, 19 Aug 2011 09:10:51 +0000 (09:10 +0000)
27 files changed:
.cvssymlinks
config/TX27-40x0.ecc
config/TX27-40x1.ecc
config/TX37-50x0.ecc
config/TX51-80x0.ecc
packages/devs/eth/arm/tx51karo/v1_0/include/devs_eth_arm_tx51.inl
packages/devs/eth/fec/v2_0/cdl/fec_eth_drivers.cdl
packages/devs/eth/fec/v2_0/include/fec.h
packages/devs/eth/fec/v2_0/src/if_fec.c
packages/devs/eth/phy/v2_0/src/LAN8700.c
packages/devs/flash/arm/mxc/v2_0/cdl/mxc_flash_select.cdl
packages/devs/flash/arm/mxc/v2_0/include/mxc_nfc_v3.h
packages/devs/flash/arm/mxc/v2_0/include/mxcmci_core.h
packages/devs/flash/arm/mxc/v2_0/include/mxcmci_mmc.h
packages/devs/flash/arm/mxc/v2_0/src/mxc_mmc.c
packages/devs/flash/arm/mxc/v2_0/src/mxc_nfc.c
packages/devs/flash/arm/mxc/v2_0/src/mxcmci_core.c
packages/devs/flash/arm/mxc/v2_0/src/mxcmci_mmc.c
packages/devs/flash/arm/mxc/v2_0/src/mxcmci_sd.c
packages/devs/ipu/arm/imx/v1_0/include/ipu_common.h
packages/ecos.db
packages/hal/arm/arch/v2_0/src/redboot_linux_exec.c
packages/infra/v2_0/src/diag.cxx
packages/io/flash/v2_0/include/flash.h
packages/io/flash/v2_0/src/flash.c
packages/redboot/v2_0/src/io.c
packages/redboot/v2_0/src/main.c

index e97979b..7cf7db1 100644 (file)
@@ -2,11 +2,13 @@ v1_0 packages/devs/eth/arm/tx25karo/current
 v1_0 packages/devs/eth/arm/tx27karo/current
 v1_0 packages/devs/eth/arm/tx37karo/current
 v1_0 packages/devs/eth/arm/tx51karo/current
+v1_0 packages/devs/eth/arm/tx53karo/current
 v1_0 packages/devs/ipu/arm/imx/current
 v1_0 packages/hal/arm/mx25/karo/current
 v1_0 packages/hal/arm/mx27/karo/current
 v1_0 packages/hal/arm/mx37/karo/current
 v1_0 packages/hal/arm/mx51/karo/current
+v1_0 packages/hal/arm/mx53/karo/current
 v2_0 packages/compat/linux/current
 v2_0 packages/compat/posix/current
 v2_0 packages/compat/uitron/current
@@ -350,6 +352,7 @@ v2_0 packages/hal/arm/mx51/3stack/current
 v2_0 packages/hal/arm/mx51/babbage/current
 v2_0 packages/hal/arm/mx51/rocky/current
 v2_0 packages/hal/arm/mx51/var/current
+v2_0 packages/hal/arm/mx53/var/current
 v2_0 packages/hal/arm/mxc91131/evb/current
 v2_0 packages/hal/arm/mxc91131/var/current
 v2_0 packages/hal/arm/mxc91221/evb/current
index a9de1f0..9362d5c 100644 (file)
@@ -794,6 +794,24 @@ cdl_option CYGPKG_DEVS_ETH_FEC_CFLAGS_ADD {
 };
 
 # <
+# MXC FEC MII Gasket for RMII mode
+# This option enables the use of the MII Gasket for
+# RMII mode found in i.MX25 and i.MX53 processors.
+#
+cdl_option CYGOPT_HAL_ARM_MXC_FEC_MIIGSK {
+    # This option is not active
+    # ActiveIf constraint: CYGPKG_HAL_ARM_MX25 || CYGPKG_HAL_ARM_MX53
+    #     CYGPKG_HAL_ARM_MX25 (unknown) == 0
+    #     CYGPKG_HAL_ARM_MX53 (unknown) == 0
+    #   --> 0
+
+    # Flavor: bool
+    # No user value, uncomment the following line to provide one.
+    # user_value 1
+    # value_source default
+    # Default value: 1
+};
+
 # <
 # Ethernet transceiver (PHY) support
 # API for ethernet PHY devices
index 7cef0a1..6109d96 100644 (file)
@@ -794,6 +794,24 @@ cdl_option CYGPKG_DEVS_ETH_FEC_CFLAGS_ADD {
 };
 
 # <
+# MXC FEC MII Gasket for RMII mode
+# This option enables the use of the MII Gasket for
+# RMII mode found in i.MX25 and i.MX53 processors.
+#
+cdl_option CYGOPT_HAL_ARM_MXC_FEC_MIIGSK {
+    # This option is not active
+    # ActiveIf constraint: CYGPKG_HAL_ARM_MX25 || CYGPKG_HAL_ARM_MX53
+    #     CYGPKG_HAL_ARM_MX25 (unknown) == 0
+    #     CYGPKG_HAL_ARM_MX53 (unknown) == 0
+    #   --> 0
+
+    # Flavor: bool
+    # No user value, uncomment the following line to provide one.
+    # user_value 1
+    # value_source default
+    # Default value: 1
+};
+
 # <
 # Ethernet transceiver (PHY) support
 # API for ethernet PHY devices
index aa397c8..226da56 100644 (file)
@@ -792,6 +792,24 @@ cdl_option CYGPKG_DEVS_ETH_FEC_CFLAGS_ADD {
 };
 
 # <
+# MXC FEC MII Gasket for RMII mode
+# This option enables the use of the MII Gasket for
+# RMII mode found in i.MX25 and i.MX53 processors.
+#
+cdl_option CYGOPT_HAL_ARM_MXC_FEC_MIIGSK {
+    # This option is not active
+    # ActiveIf constraint: CYGPKG_HAL_ARM_MX25 || CYGPKG_HAL_ARM_MX53
+    #     CYGPKG_HAL_ARM_MX25 (unknown) == 0
+    #     CYGPKG_HAL_ARM_MX53 (unknown) == 0
+    #   --> 0
+
+    # Flavor: bool
+    # No user value, uncomment the following line to provide one.
+    # user_value 1
+    # value_source default
+    # Default value: 1
+};
+
 # <
 # Ethernet transceiver (PHY) support
 # API for ethernet PHY devices
index 8ea46ed..c5f2248 100644 (file)
@@ -794,6 +794,24 @@ cdl_option CYGPKG_DEVS_ETH_FEC_CFLAGS_ADD {
 };
 
 # <
+# MXC FEC MII Gasket for RMII mode
+# This option enables the use of the MII Gasket for
+# RMII mode found in i.MX25 and i.MX53 processors.
+#
+cdl_option CYGOPT_HAL_ARM_MXC_FEC_MIIGSK {
+    # This option is not active
+    # ActiveIf constraint: CYGPKG_HAL_ARM_MX25 || CYGPKG_HAL_ARM_MX53
+    #     CYGPKG_HAL_ARM_MX25 (unknown) == 0
+    #     CYGPKG_HAL_ARM_MX53 (unknown) == 0
+    #   --> 0
+
+    # Flavor: bool
+    # No user value, uncomment the following line to provide one.
+    # user_value 1
+    # value_source default
+    # Default value: 1
+};
+
 # <
 # Ethernet transceiver (PHY) support
 # API for ethernet PHY devices
index 9d31daa..ea9ff11 100644 (file)
@@ -220,6 +220,7 @@ static void tx51_fec_phy_init(void)
        if (!gpio_tst_bit(2, 14)) {
                diag_printf("**Failed to release PHY reset\n");
        }
+       HAL_DELAY_US(400);
 
        /* configure all FEC pins to their required functions */
        for (i = 0; i < NUM_ELEMS(tx51_fec_gpio_data); i++) {
index 683509f..101d8eb 100644 (file)
@@ -85,5 +85,15 @@ cdl_package CYGPKG_DEVS_ETH_FEC {
                 to the set of global flags."
         }
     }
+
+    cdl_option CYGOPT_HAL_ARM_MXC_FEC_MIIGSK {
+        display "MXC FEC MII Gasket for RMII mode"
+       active_if CYGPKG_HAL_ARM_MX25 || CYGPKG_HAL_ARM_MX53
+       flavor bool
+       default_value 1
+        description   "
+            This option enables the use of the MII Gasket for
+           RMII mode found in i.MX25 and i.MX53 processors."
+    }
 }
 
index 2f3f2a9..87a5a56 100644 (file)
@@ -147,7 +147,7 @@ void mxc_fec_phy_write(int reg, int unit, unsigned short data);
 #define FEC_BD_RX_NUM          256
 #define FEC_BD_TX_NUM          2
 
-#ifdef CYGPKG_HAL_ARM_MX25
+#ifdef CYGOPT_HAL_ARM_MXC_FEC_MIIGSK
 /* the defines for MIIGSK */
 
 /* RMII frequency control: 0=50MHz, 1=5MHz */
@@ -199,7 +199,7 @@ typedef     volatile void mxc_fec_reg_t;
 #define erdsr                  0x180   /*Pointer to Receive Descriptor Ring*/
 #define etdsr                  0x184   /*Pointer to Transmit Descriptor Ring*/
 #define emrbr                  0x188   /*Maximum Receive Buffer size*/
-#ifdef CYGPKG_HAL_ARM_MX25
+#ifdef CYGOPT_HAL_ARM_MXC_FEC_MIIGSK
 #define miigsk_cfgr            0x300 /* MIIGSK Configuration Register */
 #define miigsk_enr             0x308  /* MIIGSK Enable Register */
 #endif
index 172588f..8708e63 100644 (file)
@@ -299,7 +299,7 @@ mxc_fec_set_mac_address(volatile mxc_fec_reg_t *hw_reg, unsigned char *enaddr)
        mxc_fec_reg_write(hw_reg, paur, value << 16);
 }
 
-#ifdef CYGPKG_HAL_ARM_MX25
+#ifdef CYGOPT_HAL_ARM_MXC_FEC_MIIGSK
 static int mxc_fec_mii_setup(mxc_fec_priv_t *priv)
 {
        volatile mxc_fec_reg_t *hw_reg = priv->hw_reg;
index 85da4d0..f0dffd6 100644 (file)
@@ -2,7 +2,7 @@
 //
 //      dev/AM79C874.c
 //
-//      Ethernet transceiver (PHY) support 
+//      Ethernet transceiver (PHY) support
 //
 //==========================================================================
 //####ECOSGPLCOPYRIGHTBEGIN####
 //#####DESCRIPTIONBEGIN####
 //
 // Author(s):    LW@KARO-electronics.de
-// Contributors: 
+// Contributors:
 // Date:         2008-01-28
-// Purpose:      
+// Purpose:
 // Description:  Support for ethernet SMSC LAN8700 PHY
-//              
+//
 //
 //####DESCRIPTIONEND####
 //
@@ -105,8 +105,9 @@ static bool lan8700_stat(eth_phy_access_t *f, int *state)
                        return true;
                }
        }
-    return false;
+       return false;
 }
 
 _eth_phy_dev("SMSC LAN8700 Rev. 3", 0x0007c0c3, lan8700_stat)
 _eth_phy_dev("SMSC LAN8700 Rev. 4", 0x0007c0c4, lan8700_stat)
+_eth_phy_dev("SMSC LAN8710 Rev. 1", 0x0007c0f1, lan8700_stat)
index 530e810..2e284c3 100644 (file)
@@ -66,7 +66,8 @@ cdl_package CYGPKG_DEVS_FLASH_ONMXC {
 
         cdl_option CYGHWR_DEVS_FLASH_MMC_ESDHC {
             display       "MXC platform MMC card for newer SDHC controllers"
-            active_if   { CYGPKG_HAL_ARM_MX37_3STACK || CYGPKG_HAL_ARM_MX35_3STACK || CYGPKG_HAL_ARM_MX25_3STACK ||  CYGPKG_HAL_ARM_MX51}
+            active_if   { CYGPKG_HAL_ARM_MX37 || CYGPKG_HAL_ARM_MX35 || 
+                         CYGPKG_HAL_ARM_MX25 ||  CYGPKG_HAL_ARM_MX51 }
             default_value 1
             requires      { CYGSEM_IO_FLASH_READ_INDIRECT == 1 }
             compile       mxcmci_core.c  mxcmci_host.c  mxcmci_mmc.c mxcmci_sd.c mxcmci_sd.c
index 89b31ff..347e813 100644 (file)
@@ -109,17 +109,19 @@ enum nfc_output_mode {
        CYG_MACRO_START                                                                                                         \
        int loops = MAX_LOOPS;                                                                                          \
        static int max_loops = MAX_LOOPS;                                                                       \
+                                                                                                                                               \
        while ((nfc_reg_read(NFC_IPC_REG) & NFC_IPC_AUTO_DONE) == 0) {          \
                HAL_DELAY_US(10);                                                                                               \
                if (loops-- < 0) {                                                                                              \
-                       diag_printf("%s: Timeout waiting for prog done\n", __FUNCTION__); \
+                       diag_printf("%s: Timeout waiting for prog done\n",                      \
+                                               __func__);                                                                              \
                        break;                                                                                                          \
                }                                                                                                                               \
        }                                                                                                                                       \
-       if (loops < max_loops) {                                                                                        \
+       if (MAX_LOOPS - loops < max_loops) {                                                            \
                diag_printf1("%s: auto_prog done after %u loops\n",                             \
                                        __FUNCTION__, MAX_LOOPS - loops);                                       \
-               max_loops = loops;                                                                                              \
+               max_loops = MAX_LOOPS - loops;                                                                  \
        }                                                                                                                                       \
        nfc_reg_write((nfc_reg_read(NFC_IPC_REG) & ~NFC_IPC_AUTO_DONE),         \
                                NFC_IPC_REG);                                                                                   \
@@ -130,23 +132,49 @@ enum nfc_output_mode {
        CYG_MACRO_START                                                                                                         \
        int loops = MAX_LOOPS;                                                                                          \
        static int max_loops = MAX_LOOPS;                                                                       \
+                                                                                                                                               \
        while ((nfc_reg_read(NFC_IPC_REG) & NFC_IPC_INT) == 0) {                        \
                HAL_DELAY_US(10);                                                                                               \
                if (loops-- < 0) {                                                                                              \
-                       diag_printf("%s: Timeout waiting for NFC ready\n", __FUNCTION__); \
+                       diag_printf("%s: Timeout waiting for NFC ready\n",                      \
+                                               __func__);                                                                              \
                        break;                                                                                                          \
                }                                                                                                                               \
        }                                                                                                                                       \
-       if (loops < max_loops) {                                                                                        \
+       if (MAX_LOOPS - loops < max_loops) {                                                            \
                diag_printf1("%s: NFC ready after %u loops\n",                                  \
                                        __FUNCTION__, MAX_LOOPS - loops);                                       \
-               max_loops = loops;                                                                                              \
+               max_loops = MAX_LOOPS - loops;                                                                  \
        }                                                                                                                                       \
        nfc_reg_write(0, NFC_IPC_REG);                                                                          \
        CYG_MACRO_END
 
+#if 0
 #define nfc_reg_read(r)                        readl(r)
 #define nfc_reg_write(v, r)            writel(v, r)
+#else
+#define nfc_reg_read(r)                        __nfc_reg_read(r, #r, __func__, __LINE__)
+#define nfc_reg_write(v, r)            __nfc_reg_write(v, r, #r, __func__, __LINE__)
+
+static inline u32 __nfc_reg_read(unsigned long reg, const char *reg_name,
+                                                               const char *fn, int ln)
+{
+       u32 val;
+
+       val = readl(reg);
+       if (g_nfc_debug_level >= NFC_DEBUG_MAX)
+               diag_printf("%s@%d: Read %08x from %s[%08lx]\n", fn, ln, val, reg_name, reg);
+       return val;
+}
+
+static inline void __nfc_reg_write(u32 val, unsigned long reg,
+                                                               const char *reg_name, const char *fn, int ln)
+{
+       if (g_nfc_debug_level >= NFC_DEBUG_MAX)
+               diag_printf("%s@%d: Writing %08x to %s[%08lx]\n", fn, ln, val, reg_name, reg);
+       writel(val, reg);
+}
+#endif
 
 static void write_nfc_ip_reg(u32 val, u32 reg)
 {
@@ -167,10 +195,10 @@ static void write_nfc_ip_reg(u32 val, u32 reg)
                        return;
                }
        }
-       if (loops < max_loops) {
-               diag_printf("%s: NFC ready after %u loops\n",
+       if (MAX_LOOPS - loops < max_loops) {
+               diag_printf1("%s: NFC ready after %u loops\n",
                                        __FUNCTION__, MAX_LOOPS - loops);
-               max_loops = loops;
+               max_loops = MAX_LOOPS - loops;
        }
        nfc_reg_write(val, reg);
        nfc_reg_write((nfc_reg_read(NFC_IPC_REG) & ~NFC_IPC_CREQ), NFC_IPC_REG);
@@ -225,7 +253,6 @@ static void NFC_SET_NFC_ACTIVE_CS(u32 cs_line)
        nfc_reg_write(v, NAND_CONFIGURATION1_REG);
 }
 
-#ifdef IMX51_TO_2
 static inline u16 NFC_STATUS_READ(void)
 {
        u16 val = nfc_reg_read(NAND_STATUS_SUM_REG);
@@ -235,28 +262,6 @@ static inline u16 NFC_STATUS_READ(void)
        }
        return val;
 }
-#else
-static inline u16 NFC_STATUS_READ(void)
-{
-       u32 status;
-       int i;
-       u16 status_sum = 0;
-
-       /* Cannot rely on STATUS_SUM register due to errata */
-       for (i = 0; i < num_of_nand_chips; i++) {
-               NFC_SET_NFC_ACTIVE_CS(i);
-               do {
-                       nfc_reg_write(NAND_LAUNCH_AUTO_STAT, NAND_LAUNCH_REG);
-                       status = (nfc_reg_read(NAND_CONFIGURATION1_REG) & 0x00FF0000) >> 16;
-               } while ((status & 0x40) == 0); // make sure I/O 6 == 1
-               /* Get Pass/Fail status */
-               status = (nfc_reg_read(NAND_CONFIGURATION1_REG) >> 16) & 0x1;
-               status_sum |= (status << i);
-       }
-       diag_printf("NFC TO2 STATUS: %04x\n", status_sum);
-       return status_sum;
-}
-#endif
 
 /* This function uses a global variable for the page size. It shouldn't be a big
  * problem since we don't expect mixed page size nand flash parts on the same IC.
index 04774da..9042f08 100644 (file)
@@ -30,25 +30,21 @@ Portability: Portable to other compilers or platforms.
 #include "mxcmci_mmc.h"
 #include "mxcmci_host.h"
 
-#define SUCCESS 0
-#define FAIL 1
-#define NO_ARG 0
-#define RCA_SHIFT 16
-#define ONE 1
-#define FOUR 4
-#define EIGHT 8
-#define TWO_K_SIZE 2048
-#define MMCSD_READY_TIMEOUT    3000  /* ~(3s / (2 * 48 * 10us)) */
-#define ESDHC_ACMD41_TIMEOUT 48000 /* 1.5 sec =1500 msec delay for ACMD41 cmd */
+#define SUCCESS                                                0
+#define FAIL                                           1
+#define NO_ARG                                         0
+#define RCA_SHIFT                                      16
+#define MMCSD_READY_TIMEOUT                    3000  /* ~(3s / (2 * 48 * 10us)) */
+#define ESDHC_ACMD41_TIMEOUT           48000 /* 1.5 sec =1500 msec delay for ACMD41 cmd */
 #define MMCSD_SUPPORT
 
 #define CURR_CARD_STATE(r) ((cyg_uint32) ((r) & 0x1E00) >> 9)
 
-/*Defines of CSD data*/
-#define CSD_STRUCT_MSK                       0x00C00000
-#define CSD_STRUCT_SHIFT                    22
-#define MMC_CSD_SPEC_VERS_MASK      0x003C0000
-#define MMC_CSD_SPEC_VERS_SHIFT     18
+/* Defines of CSD data*/
+#define CSD_STRUCT_MSK                                         0x00C00000
+#define CSD_STRUCT_SHIFT                                       22
+#define MMC_CSD_SPEC_VERS_MASK                         0x003C0000
+#define MMC_CSD_SPEC_VERS_SHIFT                                18
 
 extern cyg_uint32 Card_rca;
 extern cyg_uint32 address_mode;
@@ -56,6 +52,7 @@ extern cyg_uint32 MMC_Spec_vers;
 extern card_specific_data csd;  /* Global variable for Card Specific Data */
 extern cyg_uint32 Card_capacity_size; /* Capacity size (C_SIZE) for card*/
 extern cyg_uint32 CCC; /* Card Command Class */
+extern int HighCapacityCard;
 
 
 /* Defines the id for each command */
@@ -119,7 +116,7 @@ typedef enum
        MMC_CSD_1_1,
        MMC_CSD_1_2,
        MMC_UNKNOWN
-}card_type;
+} card_type;
 
 typedef struct
 {
@@ -127,12 +124,12 @@ typedef struct
        cyg_uint32 cid1;
        cyg_uint32 cid2;
        cyg_uint32 cid3;
-}card_ident;
+} card_ident;
 
 
 /* CARD Flash Configuration Parameters Structure */
 typedef struct {
-    cyg_uint32  length;         /* Length of Card data to read */
+       cyg_uint32      length;                 /* Length of Card data to read */
 } CARD_FLASH_CFG_PARMS_T;
 
 /*==================================================================================================
@@ -149,6 +146,8 @@ extern cyg_uint32 mxcmci_get_cid (void);
 extern cyg_uint32 mxcmci_trans_prepare(void);
 extern void   mxcmci_cmd_config (command_t *cmd_config,cyg_uint32 index,cyg_uint32 argument,xfer_type_t transfer,response_format_t format,
                                   data_present_select data,crc_check_enable crc,cmdindex_check_enable cmdindex);
+extern cyg_uint32 mxcmci_trans_status(void);
+extern cyg_uint32 card_get_csd(void);
 
 
 #endif //_MXCMCI_CORE_H_
index 697aa3d..681bdc2 100644 (file)
@@ -1,14 +1,14 @@
 #ifndef _MXCMCI_MMC_H_
 #define _MXCMCI_MMC_H_
 
-// ========================================================================== 
-//                                                                           
+// ==========================================================================
+//
 //    Module Name:  mxcmci_mmc.h
 //
 //    General Description: Limited Bootloader eSDHC Driver.
-//                                 
-//                                                                           
-// ========================================================================== 
+//
+//
+// ==========================================================================
 //####ECOSGPLCOPYRIGHTBEGIN####
 // -------------------------------------------
 // This file is part of eCos, the Embedded Configurable Operating System.
@@ -49,7 +49,7 @@
 // Date:         2008-05-13 Initial version
 // Purpose:
 // Description:
-//     
+//
 //
 //####DESCRIPTIONEND####
 //====================================================================================================
@@ -65,7 +65,7 @@
 #define CARD_BUSY_BIT 0x80000000
 #define CURR_STATE_SHIFT 9
 #define MMC_SPEC_VER 0x003C0000
-#define MMC_SPEC_VER_SHIFT 18  
+#define MMC_SPEC_VER_SHIFT 18
 #define MMC_R1_SWITCH_ERROR_MASK 0x80
 #define SWITCH_ERROR_SHIFT 7
 #define BUS_SIZE_SHIFT 2
@@ -81,14 +81,15 @@ extern cyg_uint32 mmc_get_spec_ver (void);
 extern cyg_uint32 sd_voltage_validation (void);
 extern cyg_uint32 sd_init(cyg_uint32);
 extern cyg_uint32 card_flash_query(void* data);
+extern int sdmmc_set_blklen(int len);
 
-typedef struct 
+typedef struct
 {
        cyg_uint32 csd0;
        cyg_uint32 csd1;
        cyg_uint32 csd2;
        cyg_uint32 csd3;
-}card_specific_data;
+} card_specific_data;
 
 #endif  /* _MXCMCI_MMC_H_ */
 
index 118f6f9..86a7991 100644 (file)
 #include <cyg/io/flash.h>
 #include <cyg/io/mxc_mmc.h>
 
-#if defined(CYGPKG_HAL_ARM_MX31ADS) || defined(CYGPKG_HAL_ARM_MX31_3STACK)
+#ifdef CYGPKG_HAL_ARM_MX31
     #include <cyg/io/card_mx32.h>
 #endif
 
-#if defined(CYGPKG_HAL_ARM_MX25_3STACK) || defined(CYGPKG_HAL_ARM_MX35_3STACK) || defined(CYGPKG_HAL_ARM_MX37_3STACK) || defined(CYGPKG_HAL_ARM_MX51)
+#if defined(CYGPKG_HAL_ARM_MX25) || defined(CYGPKG_HAL_ARM_MX35) || \
+       defined(CYGPKG_HAL_ARM_MX37) || defined(CYGPKG_HAL_ARM_MX51)
     #include <cyg/io/mxcmci_core.h>
 #endif
 
index 683b954..7b19ff0 100644 (file)
@@ -167,7 +167,7 @@ CYG_MACRO_END
 #define NAND_CONFIGURATION1_REG                0xDEADEEEE
 #define NFC_FLASH_CONFIG2_REG          0xDEADEEEE
 #define NFC_FLASH_CONFIG2_ECC_EN       0xDEADEEEE
-#define write_nfc_ip_reg(a, b)
+#define write_nfc_ip_reg(a, b)         CYG_EMPTY_STATEMENT
 #endif
 
 #ifndef MXCFLASH_SELECT_MULTI
@@ -188,7 +188,7 @@ void nandflash_query(void *data)
                                __FUNCTION__, __LINE__, &id[0], data);
                memcpy(data, id, sizeof(id));
        }
-       nfc_printf(NFC_DEBUG_MAX, "%s@%d %p\n", __FUNCTION__, __LINE__,
+       nfc_printf(NFC_DEBUG_MAX, "%s@%d called from %p\n", __FUNCTION__, __LINE__,
                        __builtin_return_address(0));
 }
 
@@ -290,21 +290,21 @@ static const flash_dev_info_t *flash_dev_info;
 static const flash_dev_info_t supported_devices[] = {
 #include <cyg/io/mxc_nand_parts.inl>
 };
-#define NUM_DEVICES NUM_ELEMS(supported_devices)
-
-#define COL_CYCLE                                      flash_dev_info->col_cycle
-#define ROW_CYCLE                                      flash_dev_info->row_cycle
-#define NF_PG_SZ                                       ((flash_dev_info->page_size) * num_of_nand_chips)
-#define NF_SPARE_SZ                                    ((flash_dev_info->spare_size) * num_of_nand_chips)
-#define NF_PG_PER_BLK                          flash_dev_info->pages_per_block
-#define NF_DEV_SZ                                      ((flash_dev_info->device_size) * num_of_nand_chips_for_nandsize)
-#define NF_BLK_SZ                                      ((flash_dev_info->block_size) * num_of_nand_chips)
-#define NF_BLK_CNT                                     ((flash_dev_info->block_count) / scale_block_cnt)
-#define NF_VEND_INFO                           flash_dev_info->vendor_info
-#define NF_OPTIONS                                     flash_dev_info->options
-#define NF_BBT_MAX_NR                          flash_dev_info->bbt_blk_max_nr
-#define NF_OPTIONS                                     flash_dev_info->options
-#define NF_BI_OFF                                      flash_dev_info->bi_off
+#define NUM_DEVICES                                            NUM_ELEMS(supported_devices)
+
+#define COL_CYCLE                                              flash_dev_info->col_cycle
+#define ROW_CYCLE                                              flash_dev_info->row_cycle
+#define NF_PG_SZ                                               (flash_dev_info->page_size * num_of_nand_chips)
+#define NF_SPARE_SZ                                            (flash_dev_info->spare_size * num_of_nand_chips)
+#define NF_PG_PER_BLK                                  flash_dev_info->pages_per_block
+#define NF_DEV_SZ                                              (flash_dev_info->device_size * num_of_nand_chips_for_nandsize)
+#define NF_BLK_SZ                                              (flash_dev_info->block_size * num_of_nand_chips)
+#define NF_BLK_CNT                                             (flash_dev_info->block_count / scale_block_cnt)
+#define NF_VEND_INFO                                   flash_dev_info->vendor_info
+#define NF_OPTIONS                                             flash_dev_info->options
+#define NF_BBT_MAX_NR                                  flash_dev_info->bbt_blk_max_nr
+#define NF_OPTIONS                                             flash_dev_info->options
+#define NF_BI_OFF                                              flash_dev_info->bi_off
 
 #define MXC_NAND_ADDR_MASK                             (NF_DEV_SZ - 1)
 #define BLOCK_TO_OFFSET(blk)                   ((blk) * NF_PG_PER_BLK * NF_PG_SZ)
@@ -315,7 +315,7 @@ static const flash_dev_info_t supported_devices[] = {
 
 static u8 *g_bbt, *g_page_buf;
 static u32 g_bbt_sz;
-static bool mxcnfc_init_ok = false;
+static bool mxcnfc_init_ok;
 static bool mxc_nfc_scan_done;
 
 // this callback allows the platform specific function to be called right
@@ -369,6 +369,8 @@ void mxc_flash_enable(void *start, void *end)
        flash_addr_t s = (unsigned long)start & MXC_NAND_ADDR_MASK;
        flash_addr_t e = ((unsigned long)end - 1) & MXC_NAND_ADDR_MASK;
 
+       if (start == end)
+               return;
        if (flash_enable++ == 0) {
                flash_region_start = s;
                flash_region_end = e;
@@ -389,6 +391,8 @@ void mxc_flash_disable(void *start, void *end)
        flash_addr_t s = (unsigned long)start & MXC_NAND_ADDR_MASK;
        flash_addr_t e = ((unsigned long)end - 1) & MXC_NAND_ADDR_MASK;
 
+       if (start == end)
+               return;
        if (flash_enable) {
                if (--flash_enable == 0) {
                        diag_printf1("Disabling flash region 0x%08llx..0x%08llx\n",
@@ -423,9 +427,7 @@ nandflash_hwr_init(void)
        NFC_CMD_INPUT(FLASH_Reset);
 
        // Look through table for device data
-       nfc_printf(NFC_DEBUG_MAX, "%s@%d %p\n", __FUNCTION__, __LINE__, &id[0]);
        flash_dev_query(&id[0]);
-       nfc_printf(NFC_DEBUG_MAX, "%s@%d\n", __FUNCTION__, __LINE__);
 
        flash_dev_info = supported_devices;
        for (i = 0; i < NUM_DEVICES; i++) {
@@ -435,7 +437,6 @@ nandflash_hwr_init(void)
                        break;
                flash_dev_info++;
        }
-       nfc_printf(NFC_DEBUG_MAX, "%s@%d\n", __FUNCTION__, __LINE__);
 
        // Did we find the device? If not, return error.
        if (NUM_DEVICES == i) {
@@ -458,12 +459,10 @@ nandflash_hwr_init(void)
        nfc_printf(NFC_DEBUG_MED, "%s(): %d out of NUM_DEVICES=%d, id=0x%02x\n",
                           __FUNCTION__, i, NUM_DEVICES, flash_dev_info->device_id);
 
-       if (nfc_setup) {
-               nfc_printf(NFC_DEBUG_MAX, "%s@%d\n", __FUNCTION__, __LINE__);
+       if (nfc_setup)
                g_nfc_version = nfc_setup(NF_PG_SZ / num_of_nand_chips, flash_dev_info->port_size,
-                                                                 flash_dev_info->type, num_of_nand_chips);
-       }
-       nfc_printf(NFC_DEBUG_MAX, "%s@%d\n", __FUNCTION__, __LINE__);
+                                                               flash_dev_info->type, num_of_nand_chips);
+
        diag_printf1("NFC version: %02x\n", g_nfc_version);
        if (g_nfc_version >= MXC_NFC_V3) {
                for (i = 2; i <= NUM_OF_CS_LINES; i++) {
index 43d1fb6..474e363 100644 (file)
@@ -63,13 +63,13 @@ static cyg_uint32 csd_get_value(void *csd, cyg_uint32 start_bit,
 
 #define MMCSD_INIT_DELAY 64
 
-cyg_uint32 Card_rca = 0x1;    /* Relative Card Address */
-card_ident Card_identification;    /* Card Identification Data */
-card_type Card_type;        /* Card Type */
-cyg_uint32 MMC_Spec_vers = 0x1;        /* Spec vers used for MMC */
-card_specific_data csd;        /* Global variable for Card Specific Data */
-cyg_uint32 Card_capacity_size = 0;    /*Card capacity size */
-cyg_uint32 CCC = 0;        /* Card Command Class */
+cyg_uint32 Card_rca = 0x1;                     /* Relative Card Address */
+card_ident Card_identification;                /* Card Identification Data */
+card_type Card_type;                           /* Card Type */
+cyg_uint32 MMC_Spec_vers = 0x1;                /* Spec vers used for MMC */
+card_specific_data csd;                                /* Global variable for Card Specific Data */
+cyg_uint32 Card_capacity_size = 0;     /* Card capacity size */
+cyg_uint32 CCC = 0;                                    /* Card Command Class */
 int Card_Mode = 2;
 int HighCapacityCard = 0;
 
@@ -162,39 +162,37 @@ Detailed Description:
 ==============================================================================*/
 cyg_uint32 card_get_csd(void)
 {
+       command_t cmd;
+       command_response_t response;
+       cyg_uint32 status = FAIL;
+       cyg_uint32 card_address = (Card_rca << RCA_SHIFT);
+
+       /* Configure CMD9 for MMC/SD card */
+       /* 16bit card address is expected as Argument */
+       mxcmci_cmd_config(&cmd, CMD9, card_address, READ, RESPONSE_136,
+                                       DATA_PRESENT_NONE, ENABLE, DISABLE);
+
+       /* Issue Command CMD9 to Extrace CSD register contents     */
+
+       if (host_send_cmd(&cmd) != FAIL) {
+               /* Read Command response */
+               response.format = RESPONSE_136;
+               host_read_response(&response);
+
+               /* Assign Response to CSD Strcuture */
+               csd.csd0 = response.cmd_rsp0;
+               csd.csd1 = response.cmd_rsp1;
+               csd.csd2 = response.cmd_rsp2;
+               csd.csd3 = response.cmd_rsp3;
+
+               flash_dprintf(FLASH_DEBUG_MAX, "CSD:%x:%x:%x:%x\n", csd.csd0,
+                                       csd.csd1, csd.csd2, csd.csd3);
+               status = SUCCESS;
+       } else {
+               diag_printf("Get CSD Failed.\n");
+       }
 
-    command_t cmd;
-    command_response_t response;
-    cyg_uint32 status = FAIL;
-    cyg_uint32 card_address = (Card_rca << RCA_SHIFT);
-
-    /* Configure CMD9 for MMC/SD card */
-    /* 16bit card address is expected as Argument */
-    mxcmci_cmd_config(&cmd, CMD9, card_address, READ, RESPONSE_136,
-              DATA_PRESENT_NONE, ENABLE, DISABLE);
-
-    /* Issue Command CMD9 to Extrace CSD register contents     */
-
-    if (host_send_cmd(&cmd) != FAIL) {
-        /* Read Command response */
-        response.format = RESPONSE_136;
-        host_read_response(&response);
-
-        /* Assign Response to CSD Strcuture */
-        csd.csd0 = response.cmd_rsp0;
-        csd.csd1 = response.cmd_rsp1;
-        csd.csd2 = response.cmd_rsp2;
-        csd.csd3 = response.cmd_rsp3;
-
-        flash_dprintf(FLASH_DEBUG_MAX, "CSD:%x:%x:%x:%x\n", csd.csd0,
-                  csd.csd1, csd.csd2, csd.csd3);
-        status = SUCCESS;
-    } else {
-        diag_printf("Get CSD Failed.\n");
-    }
-
-    return status;
-
+       return status;
 }
 
 static cyg_uint32 csd_get_value(void *csd, cyg_uint32 start_bit,
@@ -236,248 +234,242 @@ static cyg_uint32 csd_get_value(void *csd, cyg_uint32 start_bit,
                                __FUNCTION__, value, *pcsd, *(pcsd + 1), *(pcsd + 2),
                                *(pcsd + 3));
        return value;
-
 }
 
 cyg_uint32 card_get_capacity_size(void)
 {
-    cyg_uint32 capacity = 0;
-    cyg_uint32 c_size, c_size_mult, blk_len;
-
-    if (!csd.csd0 && !csd.csd1 && !csd.csd2 && !csd.csd3)
-        flash_dprintf(FLASH_DEBUG_MAX,
-                  "WARNINGS:mxcmci_init should be done first!\n");
-
-    switch (Card_type) {
-    case SD_CSD_1_0:
-    case MMC_CSD_1_0:
-    case MMC_CSD_1_1:
-    case MMC_CSD_1_2:
+       cyg_uint32 capacity = 0;
+       cyg_uint32 c_size, c_size_mult, blk_len;
+
+       if (!csd.csd0 && !csd.csd1 && !csd.csd2 && !csd.csd3)
+               flash_dprintf(FLASH_DEBUG_MAX,
+                                       "WARNINGS:mxcmci_init should be done first!\n");
+
+       switch (Card_type) {
+       case SD_CSD_1_0:
+       case MMC_CSD_1_0:
+       case MMC_CSD_1_1:
+       case MMC_CSD_1_2:
                c_size = csd_get_value((void*)&csd, 62, 73);
-        c_size_mult = csd_get_value(&csd, 47, 49);
-        blk_len = csd_get_value(&csd, 80, 83);
-        capacity = (c_size + 1) << (c_size_mult + 2 + blk_len - 10);
-        break;
-    case SD_CSD_2_0:
-        //blk_len = csd_get_value(&csd, 80, 83);
-        c_size = csd_get_value(&csd, 48, 69);
-        capacity = (c_size + 1) * 512;    /* block length is fixed to 512B */
-        break;
-    default:
-        capacity = 1;
-        break;
-    }
-
-    /* check whether the card is high capacity card */
-    if(capacity>2*1024*1024)
-       HighCapacityCard = 1;
-    else
-       HighCapacityCard = 0;
-
-    return capacity;
+               c_size_mult = csd_get_value(&csd, 47, 49);
+               blk_len = csd_get_value(&csd, 80, 83);
+               capacity = (c_size + 1) << (c_size_mult + 2 + blk_len - 10);
+               break;
+       case SD_CSD_2_0:
+               //blk_len = csd_get_value(&csd, 80, 83);
+               c_size = csd_get_value(&csd, 48, 69);
+               capacity = (c_size + 1) * 512;    /* block length is fixed to 512B */
+               break;
+       default:
+               capacity = 1;
+               break;
+       }
 
+       /* check whether the card is high capacity card */
+       if(capacity>2*1024*1024)
+               HighCapacityCard = 1;
+       else
+               HighCapacityCard = 0;
+
+       return capacity;
 }
 
-cyg_uint32 mxcmci_data_read(cyg_uint32 * dest_ptr, cyg_uint32 len,
-                cyg_uint32 offset)
+cyg_uint32 mxcmci_data_read(cyg_uint32 *dest_ptr, cyg_uint32 len,
+                                                       cyg_uint32 offset)
 {
-    cyg_uint32 read_status = FAIL;
-
-    read_status = mmc_data_read(dest_ptr, len, offset);
+       cyg_uint32 read_status = FAIL;
 
-    if (read_status) {
-        len = 0;
-    }
-    return len;
+       read_status = mmc_data_read(dest_ptr, len, offset);
 
+       if (read_status) {
+               len = 0;
+       }
+       return len;
 }
 
 cyg_uint32 mxcmci_software_reset(void)
 {
-    command_t cmd;
-    cyg_uint32 response = FAIL;
-
-    /*Configure CMD0 for MMC/SD card */
-    /*CMD0 doesnt expect any response */
-    mxcmci_cmd_config(&cmd, CMD0, NO_ARG, READ, RESPONSE_NONE,
-              DATA_PRESENT_NONE, DISABLE, DISABLE);
-
-    /*Issue CMD0 to MMC/SD card to put in active state */
-    if (host_send_cmd(&cmd) != FAIL) {
-        response = SUCCESS;
-    } else {
-        diag_printf("Card SW Reset Failed.\n");
-    }
-
-    return response;
+       command_t cmd;
+       cyg_uint32 response = FAIL;
+
+       /*Configure CMD0 for MMC/SD card */
+       /*CMD0 doesnt expect any response */
+       mxcmci_cmd_config(&cmd, CMD0, NO_ARG, READ, RESPONSE_NONE,
+                                       DATA_PRESENT_NONE, DISABLE, DISABLE);
+
+       /*Issue CMD0 to MMC/SD card to put in active state */
+       if (host_send_cmd(&cmd) != FAIL) {
+               response = SUCCESS;
+       } else {
+               diag_printf("Card SW Reset Failed.\n");
+       }
+
+       return response;
 }
 
 cyg_uint32 mxcmci_get_cid(void)
 {
 
-    command_t cmd;
-    cyg_uint32 cid_request = FAIL;
-    command_response_t response;
-
-    /* Configure CMD2 for card */
-    /* No Argument is expected for CMD2 */
-    mxcmci_cmd_config(&cmd, CMD2, NO_ARG, READ, RESPONSE_136,
-              DATA_PRESENT_NONE, ENABLE, DISABLE);
-
-    /* Issue CMD2 to card to determine CID contents */
-    if (host_send_cmd(&cmd) == FAIL) {
-        cid_request = FAIL;
-        diag_printf("Send CMD2 Failed.\n");
-    } else {
-        /* Read Command response  */
-        response.format = RESPONSE_136;
-        host_read_response(&response);
-
-        /* Assign CID values to mmc_cid structures */
-        Card_identification.cid0 = response.cmd_rsp0;
-        Card_identification.cid1 = response.cmd_rsp1;
-        Card_identification.cid2 = response.cmd_rsp2;
-        Card_identification.cid3 = response.cmd_rsp3;
-
-        /* Assign cid_request as SUCCESS */
-        cid_request = SUCCESS;
-    }
-
-    flash_dprintf(FLASH_DEBUG_MAX, "%s:CID=%X:%X:%X:%X\n", __FUNCTION__,
-              Card_identification.cid0, Card_identification.cid1,
-              Card_identification.cid2, Card_identification.cid3);
-    return cid_request;
+       command_t cmd;
+       cyg_uint32 cid_request = FAIL;
+       command_response_t response;
+
+       /* Configure CMD2 for card */
+       /* No Argument is expected for CMD2 */
+       mxcmci_cmd_config(&cmd, CMD2, NO_ARG, READ, RESPONSE_136,
+                                       DATA_PRESENT_NONE, ENABLE, DISABLE);
+
+       /* Issue CMD2 to card to determine CID contents */
+       if (host_send_cmd(&cmd) == FAIL) {
+               cid_request = FAIL;
+               diag_printf("Send CMD2 Failed.\n");
+       } else {
+               /* Read Command response  */
+               response.format = RESPONSE_136;
+               host_read_response(&response);
+
+               /* Assign CID values to mmc_cid structures */
+               Card_identification.cid0 = response.cmd_rsp0;
+               Card_identification.cid1 = response.cmd_rsp1;
+               Card_identification.cid2 = response.cmd_rsp2;
+               Card_identification.cid3 = response.cmd_rsp3;
+
+               /* Assign cid_request as SUCCESS */
+               cid_request = SUCCESS;
+       }
+
+       flash_dprintf(FLASH_DEBUG_MAX, "%s:CID=%X:%X:%X:%X\n", __FUNCTION__,
+                               Card_identification.cid0, Card_identification.cid1,
+                               Card_identification.cid2, Card_identification.cid3);
+       return cid_request;
 }
 
 cyg_uint32 mxcmci_trans_prepare(void)
 {
-    command_t cmd;
-    cyg_uint32 card_state = 0;
-    cyg_uint32 transfer_status = 0;
-    command_response_t response;
-    cyg_uint32 card_address = (Card_rca << RCA_SHIFT);
-
-    /* Configure CMD7 for MMC card */
-    /* 16bit card address is expected as Argument */
-    mxcmci_cmd_config(&cmd, CMD7, card_address, READ, RESPONSE_48,
-              DATA_PRESENT_NONE, ENABLE, ENABLE);
-
-    /* Sending the card from stand-by to transfer state    */
-    if (host_send_cmd(&cmd) == FAIL) {
-        transfer_status = FAIL;
-        diag_printf("Send CMD7 Failed.\n");
-    } else {
-
-        /* Configure CMD13 to read status of the card becuase CMD7 has R1b response */
-        mxcmci_cmd_config(&cmd, CMD13, card_address, READ, RESPONSE_48,
-                  DATA_PRESENT_NONE, ENABLE, ENABLE);
-
-        if (host_send_cmd(&cmd) == FAIL) {
-            transfer_status = FAIL;
-            diag_printf("Send CMD13 Failed.\n");
-        } else {
-            /* Read Command response */
-            response.format = RESPONSE_48;
-            host_read_response(&response);
-
-            card_state = CURR_CARD_STATE(response.cmd_rsp0);
-
-            if (card_state == TRAN) {
-                transfer_status = SUCCESS;
-
-            } else {
-                diag_printf("card_state: 0x%x\n", card_state);
-                transfer_status = FAIL;
-            }
-        }
-
-    }
-
-    return transfer_status;
+       command_t cmd;
+       cyg_uint32 card_state = 0;
+       cyg_uint32 transfer_status = 0;
+       command_response_t response;
+       cyg_uint32 card_address = (Card_rca << RCA_SHIFT);
+
+       /* Configure CMD7 for MMC card */
+       /* 16bit card address is expected as Argument */
+       mxcmci_cmd_config(&cmd, CMD7, card_address, READ, RESPONSE_48,
+                                       DATA_PRESENT_NONE, ENABLE, ENABLE);
+
+       /* Sending the card from stand-by to transfer state */
+       if (host_send_cmd(&cmd) == FAIL) {
+               transfer_status = FAIL;
+               diag_printf("Send CMD7 Failed.\n");
+       } else {
+
+               /* Configure CMD13 to read status of the card becuase CMD7 has R1b response */
+               mxcmci_cmd_config(&cmd, CMD13, card_address, READ, RESPONSE_48,
+                                               DATA_PRESENT_NONE, ENABLE, ENABLE);
+
+               if (host_send_cmd(&cmd) == FAIL) {
+                       transfer_status = FAIL;
+                       diag_printf("Send CMD13 Failed.\n");
+               } else {
+                       /* Read Command response */
+                       response.format = RESPONSE_48;
+                       host_read_response(&response);
+
+                       card_state = CURR_CARD_STATE(response.cmd_rsp0);
+
+                       if (card_state == TRAN) {
+                               transfer_status = SUCCESS;
+
+                       } else {
+                               diag_printf("card_state: 0x%x\n", card_state);
+                               transfer_status = FAIL;
+                       }
+               }
+
+       }
 
+       return transfer_status;
 }
 
 cyg_uint32 mxcmci_trans_status(void)
 {
-    command_t cmd;
-    cyg_uint32 card_state = 0;
-    cyg_uint32 transfer_status = 0;
-    command_response_t response;
-    cyg_uint32 card_address = (Card_rca << RCA_SHIFT);
-
-    /* Configure CMD13 to read status of the card becuase CMD7 has R1b response */
-    mxcmci_cmd_config(&cmd, CMD13, card_address, READ, RESPONSE_48,
-              DATA_PRESENT_NONE, ENABLE, ENABLE);
-
-    if (host_send_cmd(&cmd) == FAIL) {
-        diag_printf("Fail, CMD13\n");
-        transfer_status = FAIL;
-    }
-
-    else {
-        /* Read Command response */
-        response.format = RESPONSE_48;
-        host_read_response(&response);
-
-        card_state = CURR_CARD_STATE(response.cmd_rsp0);
-
-        if (card_state == TRAN) {
-            transfer_status = SUCCESS;
-            //diag_printf("card_state: 0x%x\n", card_state);
-        }
-
-        else {
-            //diag_printf("card_state: 0x%x\n", card_state);
-            transfer_status = FAIL;
-        }
-    }
-    return transfer_status;
+       command_t cmd;
+       cyg_uint32 card_state = 0;
+       cyg_uint32 transfer_status = 0;
+       command_response_t response;
+       cyg_uint32 card_address = (Card_rca << RCA_SHIFT);
+
+       /* Configure CMD13 to read status of the card becuase CMD7 has R1b response */
+       mxcmci_cmd_config(&cmd, CMD13, card_address, READ, RESPONSE_48,
+                                       DATA_PRESENT_NONE, ENABLE, ENABLE);
+
+       if (host_send_cmd(&cmd) == FAIL) {
+               diag_printf("Fail, CMD13\n");
+               transfer_status = FAIL;
+       }
+
+       else {
+               /* Read Command response */
+               response.format = RESPONSE_48;
+               host_read_response(&response);
+
+               card_state = CURR_CARD_STATE(response.cmd_rsp0);
+
+               if (card_state == TRAN) {
+                       transfer_status = SUCCESS;
+                       //diag_printf("card_state: 0x%x\n", card_state);
+               }
 
+               else {
+                       //diag_printf("card_state: 0x%x\n", card_state);
+                       transfer_status = FAIL;
+               }
+       }
+       return transfer_status;
 }
 
-void mxcmci_cmd_config(command_t * cmd_config, cyg_uint32 index,
-               cyg_uint32 argument, xfer_type_t transfer,
-               response_format_t format, data_present_select data,
-               crc_check_enable crc, cmdindex_check_enable cmdindex)
+void mxcmci_cmd_config(command_t *cmd_config, cyg_uint32 index,
+                                       cyg_uint32 argument, xfer_type_t transfer,
+                                       response_format_t format, data_present_select data,
+                                       crc_check_enable crc, cmdindex_check_enable cmdindex)
 {
+       command_t *cmd;
 
-    command_t *cmd;
-
-    /* Assign cmd to cmd_config */
-    cmd = cmd_config;
+       /* Assign cmd to cmd_config */
+       cmd = cmd_config;
 
-    /* Configure Command index */
-    cmd->command = index;
+       /* Configure Command index */
+       cmd->command = index;
 
-    /* Configure Command Argument */
-    cmd->arg = argument;
+       /* Configure Command Argument */
+       cmd->arg = argument;
 
-    /* Configure Data transfer type */
-    cmd->data_transfer = transfer;
+       /* Configure Data transfer type */
+       cmd->data_transfer = transfer;
 
-    /* Configure Response Format */
-    cmd->response_format = format;
+       /* Configure Response Format */
+       cmd->response_format = format;
 
-    /* Configure Data Present Select */
-    cmd->data_present = data;
+       /* Configure Data Present Select */
+       cmd->data_present = data;
 
-    /* Configiure CRC check Enable */
-    cmd->crc_check = crc;
+       /* Configiure CRC check Enable */
+       cmd->crc_check = crc;
 
-    /*Configure Command index check enable */
-    cmd->cmdindex_check = cmdindex;
+       /* Configure Command index check enable */
+       cmd->cmdindex_check = cmdindex;
 
-    /* if multi-block is used */
-    if (CMD18 == index || CMD25 == index) {
-        /*Configure Block count enable */
-        cmd->block_count_enable_check = ENABLE;
-        /*Configure Multi single block select */
-        cmd->multi_single_block = MULTIPLE;
-    } else {
-        /*Configure Block count enable */
-        cmd->block_count_enable_check = DISABLE;
+       /* if multi-block is used */
+       if (CMD18 == index || CMD25 == index) {
+               /* Configure Block count enable */
+               cmd->block_count_enable_check = ENABLE;
+               /* Configure Multi single block select */
+               cmd->multi_single_block = MULTIPLE;
+       } else {
+               /* Configure Block count enable */
+               cmd->block_count_enable_check = DISABLE;
 
-        /*Configure Multi single block select */
-        cmd->multi_single_block = SINGLE;
-    }
+               /* Configure Multi single block select */
+               cmd->multi_single_block = SINGLE;
+       }
 }
index cf80b2a..4a8751c 100644 (file)
 //
 //==========================================================================
 
+#include <cyg/infra/diag.h>
 #include <cyg/io/mxcmci_host.h>
 #include <cyg/io/mxcmci_core.h>
 #include <cyg/io/mxcmci_mmc.h>
 #include <cyg/io/mxc_mmc.h>
-
-extern int HighCapacityCard;
+#include <cyg/hal/hal_intr.h>
 
 static cyg_uint32 mmc_set_rca(void);
 static cyg_uint32 mmc_set_bus_width(cyg_uint32 bus_width);
-static cyg_uint32 mmc_set_high_speed_mode(void);
 
 cyg_uint32 address_mode;    /* Global variable for addressing mode */
 
@@ -88,7 +87,6 @@ cyg_uint32 mmc_init(cyg_uint32 bus_width)
                                        return FAIL;
                                }
 #endif
-
                                /* Set block length for transfer */
                                //diag_printf("Send CMD to Set Block Length.\n");
                                if (sdmmc_set_blklen(BLK_LEN))
@@ -113,11 +111,10 @@ cyg_uint32 mmc_init(cyg_uint32 bus_width)
 
 }
 
-cyg_uint32 mmc_data_read(cyg_uint32 * dest_ptr, cyg_uint32 length,
-             cyg_uint32 offset)
+cyg_uint32 mmc_data_read(cyg_uint32 *dest_ptr, cyg_uint32 length,
+                                               cyg_uint32 offset)
 {
        command_t cmd;
-       int len;
        cyg_uint32 read_block_status = 0;
        cyg_uint32 blk_len = BLK_LEN;
        unsigned int SectorNum = 0;
@@ -132,7 +129,7 @@ cyg_uint32 mmc_data_read(cyg_uint32 * dest_ptr, cyg_uint32 length,
 
        /* wait until in transfer mode */
        while (mxcmci_trans_status()) {
-               hal_delay_us(5);
+               HAL_DELAY_US(5);
        }
 
 reread:
@@ -200,12 +197,11 @@ reread:
        return read_block_status;
 }
 
-cyg_uint32 mmc_data_write(cyg_uint32 * src_ptr, cyg_uint32 length,
-              cyg_uint32 offset)
+cyg_uint32 mmc_data_write(cyg_uint32 *src_ptr, cyg_uint32 length,
+                                               cyg_uint32 offset)
 {
 
        command_t cmd;
-       cyg_int32 len;
        cyg_uint32 blk_len = BLK_LEN;
        cyg_uint32 write_block_status = SUCCESS;
        unsigned int SectorNum;
@@ -221,12 +217,12 @@ cyg_uint32 mmc_data_write(cyg_uint32 * src_ptr, cyg_uint32 length,
                offset = offset/512;
 
        //need waiting until CARD out of Prg status, or will cause CMD25 timeout
-       //hal_delay_us(100);
+       //HAL_DELAY_US(100);
 
        //StartCounter();
 
        while (mxcmci_trans_status()) {
-               hal_delay_us(2);
+               HAL_DELAY_US(2);
        }
 
        //counter = StopCounter();
@@ -248,7 +244,7 @@ rewrite:
                        esdhc_softreset(ESDHC_RESET_CMD_MSK | ESDHC_RESET_DAT_MSK);
                        write_block_status = FAIL;
 
-                       //hal_delay_us(1000);
+                       //HAL_DELAY_US(1000);
                        goto rewrite;
 
                } else {
@@ -305,390 +301,378 @@ rewrite:
        }
 
        return write_block_status;
-
 }
 
 cyg_uint32 mmc_data_erase(cyg_uint32 offset, cyg_uint32 size)
 {
-    command_t cmd;
-    extern int Card_Mode;
-    cyg_uint8 startEraseBlockCmd = CMD35;
-    cyg_uint8 endEraseBlockCmd = CMD36;
-
-    cyg_uint32 startBlock = offset / BLK_LEN;
-    cyg_uint32 endBlock = (offset + size - 1) / BLK_LEN;
-    cyg_uint32 ret;
+       command_t cmd;
+       extern int Card_Mode;
+       cyg_uint8 startEraseBlockCmd = CMD35;
+       cyg_uint8 endEraseBlockCmd = CMD36;
+
+       cyg_uint32 startBlock = offset / BLK_LEN;
+       cyg_uint32 endBlock = (offset + size - 1) / BLK_LEN;
+       cyg_uint32 ret;
 //    diag_printf("card_data_erase\n");
-    if (Card_Mode == 0) {
-        startBlock *= BLK_LEN;
-        endBlock *= BLK_LEN;
-        startEraseBlockCmd = CMD35;
-        endEraseBlockCmd = CMD36;
-    }
-
-    else if (Card_Mode == 1) {
-        startBlock *= BLK_LEN;
-        endBlock *= BLK_LEN;
-        startEraseBlockCmd = CMD32;
-        endEraseBlockCmd = CMD33;
-    }
+       if (Card_Mode == 0) {
+               startBlock *= BLK_LEN;
+               endBlock *= BLK_LEN;
+               startEraseBlockCmd = CMD35;
+               endEraseBlockCmd = CMD36;
+       }
+
+       else if (Card_Mode == 1) {
+               startBlock *= BLK_LEN;
+               endBlock *= BLK_LEN;
+               startEraseBlockCmd = CMD32;
+               endEraseBlockCmd = CMD33;
+       }
 #if 1
-    /* hight capacity card uses sector mode */
-    if(HighCapacityCard)
-        startBlock /= BLK_LEN;
-        endBlock /= BLK_LEN;
+       /* hight capacity card uses sector mode */
+       if(HighCapacityCard)
+               startBlock /= BLK_LEN;
+       endBlock /= BLK_LEN;
 #endif
 //     diag_printf("0x%x - 0x%x, size: 0x%x\n", startBlock, endBlock, size);
-    /* Configure start erase command to set first block */
-    mxcmci_cmd_config(&cmd, startEraseBlockCmd, startBlock, READ,
-              RESPONSE_48, DATA_PRESENT_NONE, ENABLE, ENABLE);
-    /* wait response */
-    if ((ret = host_send_cmd(&cmd)) == SUCCESS) {
-        flash_dprintf(FLASH_DEBUG_MAX,
-                  "%s: successful for host_send_cmd\n",
-                  __FUNCTION__);
-        /* Configure end erase command to set end block */
-        mxcmci_cmd_config(&cmd, endEraseBlockCmd, endBlock, READ,
-                  RESPONSE_48, DATA_PRESENT_NONE, ENABLE, ENABLE);
-        if ((ret = host_send_cmd(&cmd)) == SUCCESS) {
-            flash_dprintf(FLASH_DEBUG_MAX,
-                      "%s: successful for host_send_cmd:2\n",
-                      __FUNCTION__);
-            /* Comfigure command to start erase */
-            mxcmci_cmd_config(&cmd, CMD38, 0, READ, RESPONSE_48,
-                      DATA_PRESENT_NONE, ENABLE, ENABLE);
-            if ((ret = host_send_cmd(&cmd)) == SUCCESS) {
-                flash_dprintf(FLASH_DEBUG_MAX,
-                          "%s: successful for host_send_cmd:3\n",
-                          __FUNCTION__);
-                //wait for completion
-                return ret;
-            }
-        }
-    }
-
-    flash_dprintf(FLASH_DEBUG_MAX, "%s: Error return (%d)\n", __FUNCTION__,
-              ret);
-    return ret;
+       /* Configure start erase command to set first block */
+       mxcmci_cmd_config(&cmd, startEraseBlockCmd, startBlock, READ,
+                                       RESPONSE_48, DATA_PRESENT_NONE, ENABLE, ENABLE);
+       /* wait response */
+       if ((ret = host_send_cmd(&cmd)) == SUCCESS) {
+               flash_dprintf(FLASH_DEBUG_MAX,
+                                       "%s: successful for host_send_cmd\n",
+                                       __FUNCTION__);
+               /* Configure end erase command to set end block */
+               mxcmci_cmd_config(&cmd, endEraseBlockCmd, endBlock, READ,
+                                               RESPONSE_48, DATA_PRESENT_NONE, ENABLE, ENABLE);
+               if ((ret = host_send_cmd(&cmd)) == SUCCESS) {
+                       flash_dprintf(FLASH_DEBUG_MAX,
+                                               "%s: successful for host_send_cmd:2\n",
+                                               __FUNCTION__);
+                       /* Comfigure command to start erase */
+                       mxcmci_cmd_config(&cmd, CMD38, 0, READ, RESPONSE_48,
+                                                       DATA_PRESENT_NONE, ENABLE, ENABLE);
+                       if ((ret = host_send_cmd(&cmd)) == SUCCESS) {
+                               flash_dprintf(FLASH_DEBUG_MAX,
+                                                       "%s: successful for host_send_cmd:3\n",
+                                                       __FUNCTION__);
+                               //wait for completion
+                               return ret;
+                       }
+               }
+       }
+
+       flash_dprintf(FLASH_DEBUG_MAX, "%s: Error return (%d)\n", __FUNCTION__,
+                               ret);
+       return ret;
 }
 
 cyg_uint32 mmc_voltage_validation(void)
 {
-    command_t cmd;
-    command_response_t response;
-    cyg_uint32 voltage_validation_command = 0;
-    cyg_uint32 ocr_val = 0;
-    cyg_uint32 voltage_validation = FAIL;
-
-    ocr_val = (cyg_uint32) ((MMC_OCR_VALUE) & 0xFFFFFFFF);
-
-    while ((voltage_validation_command < MMCSD_READY_TIMEOUT)
-           && (voltage_validation != SUCCESS)) {
-        /* Configure CMD1 for MMC card */
-        mxcmci_cmd_config(&cmd, CMD1, ocr_val, READ, RESPONSE_48,
-                  DATA_PRESENT_NONE, DISABLE, DISABLE);
-
-        /* Issue CMD1 to MMC card to determine OCR value */
-        if (host_send_cmd(&cmd) == FAIL) {
-            voltage_validation = FAIL;
-            break;
-        } else {
-            /* Read Response from CMDRSP0 Register */
-            response.format = RESPONSE_48;
-            host_read_response(&response);
-
-            /* Check if card busy bit is cleared or not */
-            if (!(response.cmd_rsp0 & CARD_BUSY_BIT)) {
-                /* Iterate One more time */
-                voltage_validation_command++;
-            } else {
-                if ((response.cmd_rsp0 & MMC_OCR_HC_RES) ==
-                    MMC_OCR_HC_RES) {
-                    address_mode = SECT_MODE;
-                    voltage_validation = SUCCESS;
-                } else if ((response.cmd_rsp0 & MMC_OCR_LC_RES)
-                       == MMC_OCR_LC_RES) {
-                    address_mode = BYTE_MODE;
-                    voltage_validation = SUCCESS;
-                }
-            }
-
-        }
-    }
-
-    return voltage_validation;
+       command_t cmd;
+       command_response_t response;
+       cyg_uint32 voltage_validation_command = 0;
+       cyg_uint32 ocr_val = 0;
+       cyg_uint32 voltage_validation = FAIL;
+
+       ocr_val = (cyg_uint32) ((MMC_OCR_VALUE) & 0xFFFFFFFF);
+
+       while ((voltage_validation_command < MMCSD_READY_TIMEOUT)
+               && (voltage_validation != SUCCESS)) {
+               /* Configure CMD1 for MMC card */
+               mxcmci_cmd_config(&cmd, CMD1, ocr_val, READ, RESPONSE_48,
+                                               DATA_PRESENT_NONE, DISABLE, DISABLE);
+
+               /* Issue CMD1 to MMC card to determine OCR value */
+               if (host_send_cmd(&cmd) == FAIL) {
+                       voltage_validation = FAIL;
+                       break;
+               } else {
+                       /* Read Response from CMDRSP0 Register */
+                       response.format = RESPONSE_48;
+                       host_read_response(&response);
+
+                       /* Check if card busy bit is cleared or not */
+                       if (!(response.cmd_rsp0 & CARD_BUSY_BIT)) {
+                               /* Iterate One more time */
+                               voltage_validation_command++;
+                       } else {
+                               if ((response.cmd_rsp0 & MMC_OCR_HC_RES) ==
+                                       MMC_OCR_HC_RES) {
+                                       address_mode = SECT_MODE;
+                                       voltage_validation = SUCCESS;
+                               } else if ((response.cmd_rsp0 & MMC_OCR_LC_RES)
+                                               == MMC_OCR_LC_RES) {
+                                       address_mode = BYTE_MODE;
+                                       voltage_validation = SUCCESS;
+                               }
+                       }
+
+               }
+       }
+
+       return voltage_validation;
 }
 
 static cyg_uint32 mmc_set_rca(void)
 {
-    command_t cmd;
-    cyg_uint32 card_state = 0;
-    cyg_uint32 rca_request = 0;
-    command_response_t response;
-    cyg_uint32 card_address = (Card_rca << RCA_SHIFT);
-
-    /* Configure CMD3 for MMC card */
-    /* 32bit card address is expected as Argument */
-    mxcmci_cmd_config(&cmd, CMD3, card_address, READ, RESPONSE_48,
-              DATA_PRESENT_NONE, ENABLE, ENABLE);
-
-    /* Assigns relative address to the card
-     */
-
-    if (host_send_cmd(&cmd) == FAIL) {
-        rca_request = FAIL;
-    }
-
-    else {
-        /* Read Command response */
-        response.format = RESPONSE_48;
-        host_read_response(&response);
-        card_state = CURR_CARD_STATE(response.cmd_rsp0);
-        if (card_state == IDENT) {
-            rca_request = SUCCESS;
-
-        } else {
-            rca_request = FAIL;
-        }
-    }
-
-    return rca_request;
+       command_t cmd;
+       cyg_uint32 card_state = 0;
+       cyg_uint32 rca_request = 0;
+       command_response_t response;
+       cyg_uint32 card_address = (Card_rca << RCA_SHIFT);
+
+       /* Configure CMD3 for MMC card */
+       /* 32bit card address is expected as Argument */
+       mxcmci_cmd_config(&cmd, CMD3, card_address, READ, RESPONSE_48,
+                                       DATA_PRESENT_NONE, ENABLE, ENABLE);
+
+       /* Assigns relative address to the card
+        */
+
+       if (host_send_cmd(&cmd) == FAIL) {
+               rca_request = FAIL;
+       }
+
+       else {
+               /* Read Command response */
+               response.format = RESPONSE_48;
+               host_read_response(&response);
+               card_state = CURR_CARD_STATE(response.cmd_rsp0);
+               if (card_state == IDENT) {
+                       rca_request = SUCCESS;
+
+               } else {
+                       rca_request = FAIL;
+               }
+       }
+
+       return rca_request;
 }
 
 cyg_uint32 mmc_get_spec_ver(void)
 {
 
-    cyg_uint32 mmc_spec_version;
-
-    if (card_get_csd() == FAIL) {
-        mmc_spec_version = 0;
-    } else {
-        mmc_spec_version = ((csd.csd3 && MMC_SPEC_VER) >> MMC_SPEC_VER_SHIFT);
-    }
+       cyg_uint32 mmc_spec_version;
 
-    return mmc_spec_version;
+       if (card_get_csd() == FAIL) {
+               mmc_spec_version = 0;
+       } else {
+               mmc_spec_version = ((csd.csd3 && MMC_SPEC_VER) >> MMC_SPEC_VER_SHIFT);
+       }
 
+       return mmc_spec_version;
 }
 
 cyg_uint32 card_flash_query(void *data)
 {
-    command_t cmd;
-    cyg_uint32 cid_request = FAIL;
-    command_response_t response;
-
-    /* Configure CMD2 for card */
-    mxcmci_cmd_config(&cmd, CMD2, NO_ARG, READ, RESPONSE_136,
-              DATA_PRESENT_NONE, ENABLE, DISABLE);
-    /* Issue CMD2 to card to determine CID contents */
-    if (host_send_cmd(&cmd) == FAIL) {
-        cid_request = FAIL;
-        flash_dprintf(FLASH_DEBUG_MAX, "%s: can't send query command\n",
-                  __FUNCTION__);
-    } else {
-        cyg_uint32 *d = (cyg_uint32 *) data;
-        /* Read Command response  */
-        response.format = RESPONSE_136;
-        host_read_response(&response);
-        /* Assign CID values to mmc_cid structures */
-        *d++ = response.cmd_rsp0;
-        *d++ = response.cmd_rsp1;
-        *d++ = response.cmd_rsp2;
-        *d = response.cmd_rsp3;
-
-        /* Assign cid_request as SUCCESS */
-        cid_request = SUCCESS;
-    }
-    flash_dprintf(FLASH_DEBUG_MAX,
-              "%s(Success?=%d):(ID=0x%x: 0x%x, 0x%x, 0x%x)\n",
-              __FUNCTION__, cid_request, *(cyg_uint32 *) (data),
-              *(cyg_uint32 *) ((cyg_uint32) data + 4),
-              *(cyg_uint8 *) ((cyg_uint32) data + 8),
-              *(cyg_uint8 *) ((cyg_uint32) data + 12));
-    return;
+       command_t cmd;
+       cyg_uint32 cid_request = FAIL;
+       command_response_t response;
+
+       /* Configure CMD2 for card */
+       mxcmci_cmd_config(&cmd, CMD2, NO_ARG, READ, RESPONSE_136,
+                                       DATA_PRESENT_NONE, ENABLE, DISABLE);
+       /* Issue CMD2 to card to determine CID contents */
+       if (host_send_cmd(&cmd) == FAIL) {
+               cid_request = FAIL;
+               flash_dprintf(FLASH_DEBUG_MAX, "%s: can't send query command\n",
+                                       __FUNCTION__);
+       } else {
+               cyg_uint32 *d = (cyg_uint32 *) data;
+               /* Read Command response  */
+               response.format = RESPONSE_136;
+               host_read_response(&response);
+               /* Assign CID values to mmc_cid structures */
+               *d++ = response.cmd_rsp0;
+               *d++ = response.cmd_rsp1;
+               *d++ = response.cmd_rsp2;
+               *d = response.cmd_rsp3;
+
+               /* Assign cid_request as SUCCESS */
+               cid_request = SUCCESS;
+       }
+       flash_dprintf(FLASH_DEBUG_MAX,
+                               "%s(Success?=%d):(ID=0x%x: 0x%x, 0x%x, 0x%x)\n",
+                               __FUNCTION__, cid_request, *(cyg_uint32 *) (data),
+                               *(cyg_uint32 *) ((cyg_uint32) data + 4),
+                               *(cyg_uint8 *) ((cyg_uint32) data + 8),
+                               *(cyg_uint8 *) ((cyg_uint32) data + 12));
+       return cid_request;
 }
 
 static cyg_uint32 mmc_set_bus_width(cyg_uint32 bus_width)
 {
-    command_t cmd;
-    cyg_uint32 set_bus_width_status = FAIL;
-    command_response_t response;
-    cyg_uint32 card_address = (Card_rca << RCA_SHIFT);
+       command_t cmd;
+       cyg_uint32 set_bus_width_status = FAIL;
 
-    if ((bus_width == FOUR) || (bus_width == EIGHT) || (bus_width == ONE)) {
+       if ((bus_width == 4) || (bus_width == 8) || (bus_width == 1)) {
 
-        /* Configure CMD6 to write to EXT_CSD register for BUS_WIDTH */
-        mxcmci_cmd_config(&cmd, CMD6, 0x03b70001 | ((bus_width >> 2) << 8), READ,
-                  RESPONSE_48, DATA_PRESENT_NONE, ENABLE, ENABLE);
+               /* Configure CMD6 to write to EXT_CSD register for BUS_WIDTH */
+               mxcmci_cmd_config(&cmd, CMD6, 0x03b70001 | ((bus_width >> 2) << 8), READ,
+                                               RESPONSE_48, DATA_PRESENT_NONE, ENABLE, ENABLE);
 
-        if (host_send_cmd(&cmd) == SUCCESS) {
-            set_bus_width_status = SUCCESS;
-        } else {
-            diag_printf("Setting MMC bus width failed.\n");
-        }
-    }
+               if (host_send_cmd(&cmd) == SUCCESS) {
+                       set_bus_width_status = SUCCESS;
+               } else {
+                       diag_printf("Setting MMC bus width failed.\n");
+               }
+       }
 
-    return set_bus_width_status;
+       return set_bus_width_status;
 }
 
-static cyg_uint32 mmc_set_high_speed_mode(void)
+cyg_uint32 mmc_set_high_speed_mode(void)
 {
-    command_t cmd;
-    command_response_t response;
-    cyg_uint32 status = FAIL;
-
-    //diag_printf("Send CMD6 to Set High Speed Mode.\n");
-    /* Configure CMD6 to write to EXT_CSD register for BUS_WIDTH */
-    mxcmci_cmd_config(&cmd, CMD6, 0x03b90100, READ, RESPONSE_48,
-              DATA_PRESENT_NONE, ENABLE, ENABLE);
-
-    if (host_send_cmd(&cmd) == SUCCESS) {
-        /* wait until in transfer mode */
-        while (mxcmci_trans_status()) {
-            hal_delay_us(5);
-        }
-
-        status = SUCCESS;
-    } else {
-        diag_printf("Setting MMC High Speed Mode FAILED.\n");
-    }
-
-    return status;
+       command_t cmd;
+       cyg_uint32 status;
+
+       //diag_printf("Send CMD6 to Set High Speed Mode.\n");
+       /* Configure CMD6 to write to EXT_CSD register for BUS_WIDTH */
+       mxcmci_cmd_config(&cmd, CMD6, 0x03b90100, READ, RESPONSE_48,
+                                       DATA_PRESENT_NONE, ENABLE, ENABLE);
+
+       status = host_send_cmd(&cmd);
+       if (status == SUCCESS) {
+               /* wait until in transfer mode */
+               while (mxcmci_trans_status()) {
+                       HAL_DELAY_US(5);
+               }
+       } else {
+               diag_printf("Setting MMC High Speed Mode FAILED.\n");
+       }
+
+       return status;
 }
 
 int sdmmc_set_blklen(int len)
 {
-    int status = FAIL;
-    command_t cmd;
-    command_response_t response;
-
-    /* Configure CMD16 to set block length as 512 bytes. */
-    mxcmci_cmd_config(&cmd, CMD16, len, READ, RESPONSE_48,
-              DATA_PRESENT_NONE, ENABLE, ENABLE);
-
-    /* Issue command CMD16 to set block length as 512 bytes */
-    if (host_send_cmd(&cmd) == FAIL) {
-        diag_printf("%s: Can't set block length!(CMD16)\n",
-                __FUNCTION__);
-        esdhc_softreset(ESDHC_RESET_CMD_MSK);
-        status = FAIL;
-    } else {
-        status = SUCCESS;
-    }
-
-    return status;
+       int status;
+       command_t cmd;
+
+       /* Configure CMD16 to set block length as 512 bytes. */
+       mxcmci_cmd_config(&cmd, CMD16, len, READ, RESPONSE_48,
+                                       DATA_PRESENT_NONE, ENABLE, ENABLE);
+
+       /* Issue command CMD16 to set block length as 512 bytes */
+       if (host_send_cmd(&cmd) == FAIL) {
+               diag_printf("%s: Can't set block length!(CMD16)\n",
+                                       __FUNCTION__);
+               esdhc_softreset(ESDHC_RESET_CMD_MSK);
+               status = FAIL;
+       } else {
+               status = SUCCESS;
+       }
+
+       return status;
 }
 
 int sdmmc_stop_transmission(void)
 {
-    int status = FAIL;
-    command_t cmd;
-    command_response_t response;
+       command_t cmd;
 
-    /* Comfigure command CMD12 for read stop */
-    mxcmci_cmd_config(&cmd, CMD12, 0, READ, RESPONSE_48,
-              DATA_PRESENT_NONE, ENABLE, ENABLE);
+       /* Comfigure command CMD12 for read stop */
+       mxcmci_cmd_config(&cmd, CMD12, 0, READ, RESPONSE_48,
+                                       DATA_PRESENT_NONE, ENABLE, ENABLE);
 
-    if (host_send_cmd(&cmd) == FAIL) {
-        //diag_printf("%s: Can't send CMD12!\n", __FUNCTION__);
-        //esdhc_softreset(ESDHC_RESET_CMD_MSK | ESDHC_RESET_DAT_MSK);
-        //read_block_status = FAIL;
-    }
+       if (host_send_cmd(&cmd) == FAIL) {
+               //diag_printf("%s: Can't send CMD12!\n", __FUNCTION__);
+               //esdhc_softreset(ESDHC_RESET_CMD_MSK | ESDHC_RESET_DAT_MSK);
+               //read_block_status = FAIL;
+       }
 
-    return 0;
+       return 0;
 }
 
 static unsigned int mmc_set_extendCSD(unsigned int ECSD_index, unsigned int value, unsigned int access_mode)
 {
-    unsigned int argument = 0;
-    command_t cmd;
-
-    /* access mode: 0b01 set bits/ 0b10 clear bits/ 0b11 write bytes */
-    argument = (access_mode << 24) | (ECSD_index << 16) | (value << 8);
-    //argument = 0x1b30000;
-
-    mxcmci_cmd_config(&cmd, CMD6, argument, READ, RESPONSE_48,
-                      DATA_PRESENT_NONE, ENABLE, ENABLE);
-
-    if(host_send_cmd(&cmd) == SUCCESS) {
-        return 0;
-    } else {
-        //diag_printf("%s: Setting MMC boot Failed.\n", __FUNCTION__);
-        return 1;
-    }
+       unsigned int argument = 0;
+       command_t cmd;
+
+       /* access mode: 0b01 set bits/ 0b10 clear bits/ 0b11 write bytes */
+       argument = (access_mode << 24) | (ECSD_index << 16) | (value << 8);
+       //argument = 0x1b30000;
+
+       mxcmci_cmd_config(&cmd, CMD6, argument, READ, RESPONSE_48,
+                                       DATA_PRESENT_NONE, ENABLE, ENABLE);
+
+       if(host_send_cmd(&cmd) == SUCCESS) {
+               return 0;
+       } else {
+               //diag_printf("%s: Setting MMC boot Failed.\n", __FUNCTION__);
+               return 1;
+       }
 }
 
-static void mmc_set_boot_partition_size(unsigned int value)
+void mmc_set_boot_partition_size(unsigned int value)
 {
-    command_t cmd;
-    command_response_t response;
-    cyg_uint32 card_state = 0;
-    cyg_uint32 card_address = (Card_rca << RCA_SHIFT);
-
-    mxcmci_cmd_config(&cmd, CMD62, 0XEFAC62EC, READ, RESPONSE_48,
-                      DATA_PRESENT_NONE, ENABLE, ENABLE);
-    host_send_cmd(&cmd);
-
-    mxcmci_cmd_config(&cmd, CMD62, 0X00CBAEA7, READ, RESPONSE_48,
-                      DATA_PRESENT_NONE, ENABLE, ENABLE);
-    host_send_cmd(&cmd);
-
-    mxcmci_cmd_config(&cmd, CMD62, value, READ, RESPONSE_48,
-                      DATA_PRESENT, ENABLE, ENABLE);
-    host_send_cmd(&cmd);
+       command_t cmd;
+
+       mxcmci_cmd_config(&cmd, CMD62, 0XEFAC62EC, READ, RESPONSE_48,
+                                       DATA_PRESENT_NONE, ENABLE, ENABLE);
+       host_send_cmd(&cmd);
+
+       mxcmci_cmd_config(&cmd, CMD62, 0X00CBAEA7, READ, RESPONSE_48,
+                                       DATA_PRESENT_NONE, ENABLE, ENABLE);
+       host_send_cmd(&cmd);
+
+       mxcmci_cmd_config(&cmd, CMD62, value, READ, RESPONSE_48,
+                                       DATA_PRESENT, ENABLE, ENABLE);
+       host_send_cmd(&cmd);
 }
 
 cyg_uint32 emmc_set_boot_partition (cyg_uint32 *src_ptr, cyg_uint32 length)
 {
-    cyg_uint32 status=FAIL;
-    unsigned int value;
-    unsigned int eMMCBootDataSize = (length / (128 * 1024)) + 1;
-
-    if (MMC_Spec_vers < 4)
-        return 1;
-
-    /* read back 1KB data as we are programming to user are and want to aviod erasing MBR
-      * will be removed once we program Redboot to boot partition of the card
-      */
-    mmc_data_read(src_ptr, 0x400, 0);
-
-    /* Set boot partition */
-    /* 1. Configure CMD6 to write to EXT_CSD register for eMMC boot partition, Byte 179*/
-    /* boot partition: user area enable and r/w enable */
-    value = (0x7 << 3) | (0x7);
-    //value = (0x1 << 3) | (0x1);
-    status = mmc_set_extendCSD(179, value, 0x3);
-    if(status) {
-        return 1; /* failed */
-    }
-
-    /* 2. Set boot partition size: n*128KB */
-    value = eMMCBootDataSize;
-    //status = mmc_set_extendCSD(226, value, 0x3);
-    //if(status) {
-    //    return 1; /* failed */
-    //}
-    //mmc_set_boot_partition_size(value);
-
-    //diag_printf("Boot partition size: 0x%xKB\n", eMMCBootDataSize * 128);
-
-    /* 3. Program to boot partition, default address is alway 0x0  */
-    status = mmc_data_write (src_ptr, eMMCBootDataSize*128*1024, 0);
-    if(status) {
-        return 1; /* failed */
-    }
-
-    while (mxcmci_trans_status());
-
-    /* 4. Clear boot partition access bits, to protect w/r of boot partition */
-    /* bit 6: send boot ack signal, boot partition: user area enable and r/w access disable */
-    //value = (0x1 << 6) | (0x1 << 3) | (0x0);
-    value = (0x1 << 6) | (0x7 << 3) | (0x0);
-    status = mmc_set_extendCSD(179, value, 0x3);
-    if(status) {
-        return 1; /* failed */
-    }
-
-    return 0;
+       cyg_uint32 status=FAIL;
+       unsigned int value;
+       unsigned int eMMCBootDataSize = (length / (128 * 1024)) + 1;
+
+       if (MMC_Spec_vers < 4)
+               return 1;
+
+       /* read back 1KB data as we are programming to user are and want to aviod erasing MBR
+        * will be removed once we program Redboot to boot partition of the card
+        */
+       mmc_data_read(src_ptr, 0x400, 0);
+
+       /* Set boot partition */
+       /* 1. Configure CMD6 to write to EXT_CSD register for eMMC boot partition, Byte 179*/
+       /* boot partition: user area enable and r/w enable */
+       value = (0x7 << 3) | (0x7);
+       //value = (0x1 << 3) | (0x1);
+       status = mmc_set_extendCSD(179, value, 0x3);
+       if(status) {
+               return 1; /* failed */
+       }
+
+       /* 2. Set boot partition size: n*128KB */
+       value = eMMCBootDataSize;
+       //status = mmc_set_extendCSD(226, value, 0x3);
+       //if(status) {
+       //    return 1; /* failed */
+       //}
+       //mmc_set_boot_partition_size(value);
+
+       //diag_printf("Boot partition size: 0x%xKB\n", eMMCBootDataSize * 128);
+
+       /* 3. Program to boot partition, default address is alway 0x0  */
+       status = mmc_data_write (src_ptr, eMMCBootDataSize*128*1024, 0);
+       if (status) {
+               return 1; /* failed */
+       }
+
+       while (mxcmci_trans_status());
+
+       /* 4. Clear boot partition access bits, to protect w/r of boot partition */
+       /* bit 6: send boot ack signal, boot partition: user area enable and r/w access disable */
+       //value = (0x1 << 6) | (0x1 << 3) | (0x0);
+       value = (0x1 << 6) | (0x7 << 3) | (0x0);
+       status = mmc_set_extendCSD(179, value, 0x3);
+       if(status) {
+               return 1; /* failed */
+       }
+
+       return 0;
 }
 
 /* end of mxcmci_mmc.c */
index e2fa471..cb6199d 100644 (file)
@@ -51,6 +51,7 @@
 //
 //==========================================================================
 
+#include <cyg/infra/diag.h>
 #include <cyg/io/mxcmci_host.h>
 #include <cyg/io/mxcmci_core.h>
 #include <cyg/io/mxcmci_mmc.h>
@@ -83,416 +84,416 @@ static cyg_uint32 sd_set_high_speed_mode(void);
 
 cyg_uint32 sd_init(cyg_uint32 bus_width)
 {
-    cyg_uint32 status = FAIL;
-    cyg_uint32 bus_size = bus_width;
-
-    /* Get CID number of SD Memory Card */
-    if (!mxcmci_get_cid()) {
-        //diag_printf("%s:mxcmci_get_cid OK!\n", __FUNCTION__);
-        /* Set RCA of the SD Card */
-        if (!sd_get_rca()) {
-            //diag_printf("%s:sd_get_rca OK!\n", __FUNCTION__);
-            /*Get CSD from Card */
-            if (card_get_csd())
-                return FAIL;
-
-            /*Enable operating frequency */
-            host_cfg_clock(OPERATING_FREQ);
-
-            //diag_printf("Set SD Card in Transfer State.\n");
-
-            /*Put SD Card in Transfer State */
-            if (!mxcmci_trans_prepare()) {
+       cyg_uint32 status = FAIL;
+       cyg_uint32 bus_size = bus_width;
+
+       /* Get CID number of SD Memory Card */
+       if (!mxcmci_get_cid()) {
+               //diag_printf("%s:mxcmci_get_cid OK!\n", __FUNCTION__);
+               /* Set RCA of the SD Card */
+               if (!sd_get_rca()) {
+                       //diag_printf("%s:sd_get_rca OK!\n", __FUNCTION__);
+                       /*Get CSD from Card */
+                       if (card_get_csd())
+                               return FAIL;
+
+                       /*Enable operating frequency */
+                       host_cfg_clock(OPERATING_FREQ);
+
+                       //diag_printf("Set SD Card in Transfer State.\n");
+
+                       /*Put SD Card in Transfer State */
+                       if (!mxcmci_trans_prepare()) {
 #if 0
-                if (sd_set_high_speed_mode()) {
-                    return FAIL;
-                }
+                               if (sd_set_high_speed_mode()) {
+                                       return FAIL;
+                               }
 #endif
 
-                if (sdmmc_set_blklen(BLK_LEN))
-                    return FAIL;
-
-                /* SD can only support 1/4 bit bitwidth, 8 bit is not supported */
-                if (EIGHT == bus_width) {
-                    bus_width = FOUR;
-                }
-                if (!sd_set_bus_width(bus_width)) {
-                    esdhc_base_pointer->protocol_control &=
-                        ~(0x3 << 1);
-                    esdhc_base_pointer->protocol_control |=
-                        (bus_width / 4) << 1;
-                    diag_printf("Bus Width:    %d\n",
-                            bus_width);
-                    status = SUCCESS;
-                }
-            }
-        }
-
-    } else {
-        diag_printf("Get CID Failed.\n");
-
-    }
-
-    //diag_printf("%s:failed to Init SD card!\n", __FUNCTION__);
-    return status;
+                               if (sdmmc_set_blklen(BLK_LEN))
+                                       return FAIL;
+
+                               /* SD can only support 1/4 bit bitwidth, 8 bit is not supported */
+                               if (8 == bus_width) {
+                                       bus_width = 4;
+                               }
+                               if (!sd_set_bus_width(bus_width)) {
+                                       esdhc_base_pointer->protocol_control &=
+                                               ~(0x3 << 1);
+                                       esdhc_base_pointer->protocol_control |=
+                                               (bus_width / 4) << 1;
+                                       diag_printf("Bus Width:    %d\n",
+                                                               bus_width);
+                                       status = SUCCESS;
+                               }
+                       }
+               }
+
+       } else {
+               diag_printf("Get CID Failed.\n");
+
+       }
+
+       //diag_printf("%s:failed to Init SD card!\n", __FUNCTION__);
+       return status;
 
 }
 
 cyg_uint32 sd_voltage_validation(void)
 {
-    //wait max timeout (unit: ms)
-    cyg_uint32 timeout = 15000;
-
-    command_t cmd;
-    command_response_t response;
-    cyg_uint32 voltage_validation_command = 0;
-    cyg_uint32 default_rca = 0;
-
-    cyg_uint32 ocr_value = SD_OCR_VALUE_HV_LC;    /* nirp_oct07: <- split OCR to 3.3v and 1.8v cases */
-    cyg_uint32 voltage_validation = FAIL;
-    cyg_uint32 interface_value = 0;
-    cyg_uint32 card_usable = SUCCESS;
-
-    /* Configure Command CMD8 to check for High capacity support */
-    /* try 3.3V first */
-    mxcmci_cmd_config(&cmd, CMD8, SD_IF_HV_COND_ARG, READ, RESPONSE_48,
-              DATA_PRESENT_NONE, ENABLE, ENABLE);
-
-    /* Issue Command CMD8  to SD Memory card */
-    if (host_send_cmd(&cmd) == SUCCESS) {    /* nirp_oct07: <- changed order of detection */
-        //diag_printf("%s:CMD8 OK!\n", __FUNCTION__);
-        response.format = RESPONSE_48;
-        host_read_response(&response);
-
-        /* Obtain Interface value from the response buffer */
-        interface_value = response.cmd_rsp0;
-
-        /* Check if volatge lies in range or not */
-        if ((interface_value & SD_IF_HV_COND_ARG) == SD_IF_HV_COND_ARG) {
-            ocr_value = ((cyg_uint32) (SD_OCR_VALUE_HV_HC) & 0xFFFFFFFF);    /* nirp_oct07: <- split OCR to 3.3v and 1.8v cases */
-        }
-
-        /* start timer for a  delay of 1.5sec, for ACMD41 */
-        hal_delay_us(1500);
-
-        while ((voltage_validation_command < 20)
-               && (voltage_validation != SUCCESS)
-               && (card_usable == SUCCESS)) {
-            /* Configure CMD55 for SD card */
-            /* This command expects defualt RCA 0x0000 as argument. */
-            mxcmci_cmd_config(&cmd, CMD55, default_rca, READ,
-                      RESPONSE_48, DATA_PRESENT_NONE,
-                      ENABLE, ENABLE);
-
-            /* Issue CMD55 to SD Memory card */
-            if (host_send_cmd(&cmd) == FAIL) {
-                voltage_validation = FAIL;
-                //diag_printf("Send CMD55 Failed.\n");
-                break;
-            } else {
-                /* Configure ACMD41 for SD card */
-                /* This command expects operating voltage range as argument. */
-                /* CODE REVIEW START: Need to check why BUSY was expected */
-                /* INTERNAL CODE REVIEW: Accepted - to fix original code if needed */
-                /* nirp: changed RESPONSE_48_CHECK_BUSY to RESPONSE_48 */
-                /* nirp_oct03: why with busy again? ACMD41 doesn't hold busy line */
-                mxcmci_cmd_config(&cmd, ACMD41, ocr_value, READ,
-                          RESPONSE_48, DATA_PRESENT_NONE, DISABLE,
-                          DISABLE);
-
-                /* Issue ACMD41 to SD Memory card to determine OCR value */
-                if (host_send_cmd(&cmd) == FAIL) {
-                    voltage_validation = FAIL;
-                    diag_printf("Send CMD41 Failed.\n");
-                    break;
-                } else {
-                    /* Read Response from CMDRSP0 Register */
-                    response.format = RESPONSE_48;
-                    host_read_response(&response);
-
-                    /* Obtain OCR Values from the response */
-                    /* Obtain OCR value from the response buffer */
-                    ocr_value = response.cmd_rsp0;
-
-                    /* Check if card busy bit is cleared or not */
-                    if (!(response.cmd_rsp0 & CARD_BUSY_BIT)) {
-                        /* Iterate One more time */
-                        voltage_validation_command++;
-                    } else {
-
-                        /*CODE REVIEW START: Update code and check only bit 30, HC or LC card type. All voltage bits needs to be masked. */
-                        /* INTERNAL CODE REVIEW: Accepted - need fix the code accordingly */
-                        /* nirp: It may be better to check the actual power supply voltage - requiring the entire range (0xff8000) may fail the sequence even if the device can be supported */
-                        /*CODE REVIEW END: */
-
-                        if ((response.cmd_rsp0 & SD_OCR_HC_RES) == SD_OCR_HC_RES) {
-                            address_mode = SECT_MODE;
-                            voltage_validation = SUCCESS;
-                        }
-                        /* CODE REVIEW 3: (same as above) Check is logically correct, but seems redundent.
-                           Anything that fails the HC check, is assumed Low Capacity */
-                        /* nirp_oct03: this can be just an "else". the LC macro is 0 anyway,
-                           and anything not HC is LC by default */
-                        /* removed else if */
-                        else {
-                            address_mode = BYTE_MODE;
-                            voltage_validation = SUCCESS;
-                        }
-                    }
-                }
-            }
-
-            hal_delay_us(1000);
-        }
-
-        if (voltage_validation == FAIL) {
-            card_usable = FAIL;
-        }
-
-    } else {
-        /*3.3v test failed, try to test 1.8v mode! */
-        mxcmci_cmd_config(&cmd, CMD8, SD_IF_LV_COND_ARG, READ,
-                  RESPONSE_48, DATA_PRESENT_NONE, ENABLE,
-                  ENABLE);
-
-        /* Issue Command CMD8  to SD Memory card */
-        if (host_send_cmd(&cmd) == FAIL) {
-            //diag_printf("%s:CMD8 for 1.8v failed!\n", __FUNCTION__);
-            /* nirp_oct07: CMD8 failed both in 3.3 and in 1.8v, try SD 1.x case - no CMD8, LC, 3.3v only */
-            ocr_value = ((cyg_uint32) (SD_OCR_VALUE_HV_LC) & 0xFFFFFFFF);    /* nirp_oct07: <- changed order of detection */
-        } else {
-            //diag_printf("%s:CMD8 for 1.8v OK!\n", __FUNCTION__);
-            response.format = RESPONSE_48;
-            host_read_response(&response);
-
-            /* Obtain Interface value from the response buffer */
-            interface_value = response.cmd_rsp0;
-
-            /* Check if volatge lies in range or not */
-            if ((interface_value & SD_IF_LV_COND_ARG) == SD_IF_LV_COND_ARG) {
-                ocr_value = ((cyg_uint32) (SD_OCR_VALUE_LV_HC) & 0xFFFFFFFF);    /* nirp_oct07: <- split OCR to 3.3v and 1.8v cases */
-            }
-            /* nirp_oct07: otherwise, try with HV_LC settings (set at function start) */
-        }
-
-    }
-
-    /* start timer for a  delay of 1.5sec, for ACMD41 */
-    hal_delay_us(1500);
-
-    /* nirp_oct03: MMCSD_READY_TIMEOUT too long.
-       ACMD41 also takes longer than CMD1 (twice - ~200 clocks for CMD55+resp+CMD41+resp */
-    /* In any case ,ACMD 41 will loop not more than 1.5 sec */
-    while ((voltage_validation_command < 20)
-           && (voltage_validation != SUCCESS) && (card_usable == SUCCESS)) {
-        /* Configure CMD55 for SD card */
-        /* This command expects defualt RCA 0x0000 as argument. */
-        mxcmci_cmd_config(&cmd, CMD55, default_rca, READ, RESPONSE_48,
-                  DATA_PRESENT_NONE, ENABLE, ENABLE);
-
-        /* Issue CMD55 to SD Memory card */
-        if (host_send_cmd(&cmd) == FAIL) {
-            voltage_validation = FAIL;
-            //diag_printf("Send CMD55 Failed!\n");
-            break;
-        } else {
-            /* Configure ACMD41 for SD card */
-            /* This command expects operating voltage range as argument. */
-            /* CODE REVIEW START: Need to check why BUSY was expected */
-            /* INTERNAL CODE REVIEW: Accepted - to fix original code if needed */
-            /* nirp: changed RESPONSE_48_CHECK_BUSY to RESPONSE_48 */
-            /* nirp_oct03: why with busy again? ACMD41 doesn't hold busy line */
-            mxcmci_cmd_config(&cmd, ACMD41, ocr_value, READ,
-                      RESPONSE_48, DATA_PRESENT_NONE,
-                      DISABLE, DISABLE);
-
-            /* CODE REVIEW END:  */
-
-            /* Issue ACMD41 to SD Memory card to determine OCR value */
-            if (host_send_cmd(&cmd) == FAIL) {
-                voltage_validation = FAIL;
-                diag_printf("Send ACMD41 Failed!\n");
-                break;
-            } else {
-                /* Read Response from CMDRSP0 Register */
-                response.format = RESPONSE_48;
-                host_read_response(&response);
-
-                /* Obtain OCR Values from the response */
-                /* Obtain OCR value from the response buffer
-                 */
-                ocr_value = response.cmd_rsp0;
-
-                /* Check if card busy bit is cleared or not */
-                if (!(response.cmd_rsp0 & CARD_BUSY_BIT)) {
-                    /* Iterate One more time */
-                    voltage_validation_command++;
-                } else {
-                    /*CODE REVIEW START: Update code and check only bit 30, HC or LC card type. All voltage bits needs to be masked. */
-                    /* INTERNAL CODE REVIEW: Accepted - need fix the code accordingly */
-                    /* nirp: It may be better to check the actual power supply voltage - requiring the entire range (0xff8000) may fail the sequence even if the device can be supported */
-                    /*CODE REVIEW END: */
-
-                    if ((response.cmd_rsp0 & SD_OCR_HC_RES) == SD_OCR_HC_RES) {
-                        address_mode = SECT_MODE;
-                        voltage_validation = SUCCESS;
-                    }
-                    /* CODE REVIEW 3: (same as above) Check is logically correct, but seems redundent.
-                       Anything that fails the HC check, is assumed Low Capacity */
-                    /* nirp_oct03: this can be just an "else". the LC macro is 0 anyway,
-                       and anything not HC is LC by default */
-                    else {
-                        address_mode = BYTE_MODE;
-                        voltage_validation = SUCCESS;
-                    }
-                }
-            }
-
-        }
-
-        hal_delay_us(1000);
-
-    }
-
-    return voltage_validation;
+       //wait max timeout (unit: ms)
+       cyg_uint32 timeout = 15000;
+
+       command_t cmd;
+       command_response_t response;
+       cyg_uint32 voltage_validation_command = 0;
+       cyg_uint32 default_rca = 0;
+
+       cyg_uint32 ocr_value = SD_OCR_VALUE_HV_LC;    /* nirp_oct07: <- split OCR to 3.3v and 1.8v cases */
+       cyg_uint32 voltage_validation = FAIL;
+       cyg_uint32 interface_value = 0;
+       cyg_uint32 card_usable = SUCCESS;
+
+       /* Configure Command CMD8 to check for High capacity support */
+       /* try 3.3V first */
+       mxcmci_cmd_config(&cmd, CMD8, SD_IF_HV_COND_ARG, READ, RESPONSE_48,
+                                       DATA_PRESENT_NONE, ENABLE, ENABLE);
+
+       /* Issue Command CMD8  to SD Memory card */
+       if (host_send_cmd(&cmd) == SUCCESS) {    /* nirp_oct07: <- changed order of detection */
+               //diag_printf("%s:CMD8 OK!\n", __FUNCTION__);
+               response.format = RESPONSE_48;
+               host_read_response(&response);
+
+               /* Obtain Interface value from the response buffer */
+               interface_value = response.cmd_rsp0;
+
+               /* Check if volatge lies in range or not */
+               if ((interface_value & SD_IF_HV_COND_ARG) == SD_IF_HV_COND_ARG) {
+                       ocr_value = ((cyg_uint32) (SD_OCR_VALUE_HV_HC) & 0xFFFFFFFF);    /* nirp_oct07: <- split OCR to 3.3v and 1.8v cases */
+               }
+
+               /* start timer for a  delay of 1.5sec, for ACMD41 */
+               hal_delay_us(1500);
+
+               while ((voltage_validation_command < 20)
+                       && (voltage_validation != SUCCESS)
+                       && (card_usable == SUCCESS)) {
+                       /* Configure CMD55 for SD card */
+                       /* This command expects defualt RCA 0x0000 as argument. */
+                       mxcmci_cmd_config(&cmd, CMD55, default_rca, READ,
+                                                       RESPONSE_48, DATA_PRESENT_NONE,
+                                                       ENABLE, ENABLE);
+
+                       /* Issue CMD55 to SD Memory card */
+                       if (host_send_cmd(&cmd) == FAIL) {
+                               voltage_validation = FAIL;
+                               //diag_printf("Send CMD55 Failed.\n");
+                               break;
+                       } else {
+                               /* Configure ACMD41 for SD card */
+                               /* This command expects operating voltage range as argument. */
+                               /* CODE REVIEW START: Need to check why BUSY was expected */
+                               /* INTERNAL CODE REVIEW: Accepted - to fix original code if needed */
+                               /* nirp: changed RESPONSE_48_CHECK_BUSY to RESPONSE_48 */
+                               /* nirp_oct03: why with busy again? ACMD41 doesn't hold busy line */
+                               mxcmci_cmd_config(&cmd, ACMD41, ocr_value, READ,
+                                                               RESPONSE_48, DATA_PRESENT_NONE, DISABLE,
+                                                               DISABLE);
+
+                               /* Issue ACMD41 to SD Memory card to determine OCR value */
+                               if (host_send_cmd(&cmd) == FAIL) {
+                                       voltage_validation = FAIL;
+                                       diag_printf("Send CMD41 Failed.\n");
+                                       break;
+                               } else {
+                                       /* Read Response from CMDRSP0 Register */
+                                       response.format = RESPONSE_48;
+                                       host_read_response(&response);
+
+                                       /* Obtain OCR Values from the response */
+                                       /* Obtain OCR value from the response buffer */
+                                       ocr_value = response.cmd_rsp0;
+
+                                       /* Check if card busy bit is cleared or not */
+                                       if (!(response.cmd_rsp0 & CARD_BUSY_BIT)) {
+                                               /* Iterate One more time */
+                                               voltage_validation_command++;
+                                       } else {
+
+                                               /*CODE REVIEW START: Update code and check only bit 30, HC or LC card type. All voltage bits needs to be masked. */
+                                               /* INTERNAL CODE REVIEW: Accepted - need fix the code accordingly */
+                                               /* nirp: It may be better to check the actual power supply voltage - requiring the entire range (0xff8000) may fail the sequence even if the device can be supported */
+                                               /*CODE REVIEW END: */
+
+                                               if ((response.cmd_rsp0 & SD_OCR_HC_RES) == SD_OCR_HC_RES) {
+                                                       address_mode = SECT_MODE;
+                                                       voltage_validation = SUCCESS;
+                                               }
+                                               /* CODE REVIEW 3: (same as above) Check is logically correct, but seems redundent.
+                                                  Anything that fails the HC check, is assumed Low Capacity */
+                                               /* nirp_oct03: this can be just an "else". the LC macro is 0 anyway,
+                                                  and anything not HC is LC by default */
+                                               /* removed else if */
+                                               else {
+                                                       address_mode = BYTE_MODE;
+                                                       voltage_validation = SUCCESS;
+                                               }
+                                       }
+                               }
+                       }
+
+                       hal_delay_us(1000);
+               }
+
+               if (voltage_validation == FAIL) {
+                       card_usable = FAIL;
+               }
+
+       } else {
+               /*3.3v test failed, try to test 1.8v mode! */
+               mxcmci_cmd_config(&cmd, CMD8, SD_IF_LV_COND_ARG, READ,
+                                               RESPONSE_48, DATA_PRESENT_NONE, ENABLE,
+                                               ENABLE);
+
+               /* Issue Command CMD8  to SD Memory card */
+               if (host_send_cmd(&cmd) == FAIL) {
+                       //diag_printf("%s:CMD8 for 1.8v failed!\n", __FUNCTION__);
+                       /* nirp_oct07: CMD8 failed both in 3.3 and in 1.8v, try SD 1.x case - no CMD8, LC, 3.3v only */
+                       ocr_value = ((cyg_uint32) (SD_OCR_VALUE_HV_LC) & 0xFFFFFFFF);    /* nirp_oct07: <- changed order of detection */
+               } else {
+                       //diag_printf("%s:CMD8 for 1.8v OK!\n", __FUNCTION__);
+                       response.format = RESPONSE_48;
+                       host_read_response(&response);
+
+                       /* Obtain Interface value from the response buffer */
+                       interface_value = response.cmd_rsp0;
+
+                       /* Check if volatge lies in range or not */
+                       if ((interface_value & SD_IF_LV_COND_ARG) == SD_IF_LV_COND_ARG) {
+                               ocr_value = ((cyg_uint32) (SD_OCR_VALUE_LV_HC) & 0xFFFFFFFF);    /* nirp_oct07: <- split OCR to 3.3v and 1.8v cases */
+                       }
+                       /* nirp_oct07: otherwise, try with HV_LC settings (set at function start) */
+               }
+
+       }
+
+       /* start timer for a  delay of 1.5sec, for ACMD41 */
+       hal_delay_us(1500);
+
+       /* nirp_oct03: MMCSD_READY_TIMEOUT too long.
+          ACMD41 also takes longer than CMD1 (twice - ~200 clocks for CMD55+resp+CMD41+resp */
+       /* In any case ,ACMD 41 will loop not more than 1.5 sec */
+       while ((voltage_validation_command < 20)
+               && (voltage_validation != SUCCESS) && (card_usable == SUCCESS)) {
+               /* Configure CMD55 for SD card */
+               /* This command expects defualt RCA 0x0000 as argument. */
+               mxcmci_cmd_config(&cmd, CMD55, default_rca, READ, RESPONSE_48,
+                                               DATA_PRESENT_NONE, ENABLE, ENABLE);
+
+               /* Issue CMD55 to SD Memory card */
+               if (host_send_cmd(&cmd) == FAIL) {
+                       voltage_validation = FAIL;
+                       //diag_printf("Send CMD55 Failed!\n");
+                       break;
+               } else {
+                       /* Configure ACMD41 for SD card */
+                       /* This command expects operating voltage range as argument. */
+                       /* CODE REVIEW START: Need to check why BUSY was expected */
+                       /* INTERNAL CODE REVIEW: Accepted - to fix original code if needed */
+                       /* nirp: changed RESPONSE_48_CHECK_BUSY to RESPONSE_48 */
+                       /* nirp_oct03: why with busy again? ACMD41 doesn't hold busy line */
+                       mxcmci_cmd_config(&cmd, ACMD41, ocr_value, READ,
+                                                       RESPONSE_48, DATA_PRESENT_NONE,
+                                                       DISABLE, DISABLE);
+
+                       /* CODE REVIEW END:  */
+
+                       /* Issue ACMD41 to SD Memory card to determine OCR value */
+                       if (host_send_cmd(&cmd) == FAIL) {
+                               voltage_validation = FAIL;
+                               diag_printf("Send ACMD41 Failed!\n");
+                               break;
+                       } else {
+                               /* Read Response from CMDRSP0 Register */
+                               response.format = RESPONSE_48;
+                               host_read_response(&response);
+
+                               /* Obtain OCR Values from the response */
+                               /* Obtain OCR value from the response buffer
+                                */
+                               ocr_value = response.cmd_rsp0;
+
+                               /* Check if card busy bit is cleared or not */
+                               if (!(response.cmd_rsp0 & CARD_BUSY_BIT)) {
+                                       /* Iterate One more time */
+                                       voltage_validation_command++;
+                               } else {
+                                       /*CODE REVIEW START: Update code and check only bit 30, HC or LC card type. All voltage bits needs to be masked. */
+                                       /* INTERNAL CODE REVIEW: Accepted - need fix the code accordingly */
+                                       /* nirp: It may be better to check the actual power supply voltage - requiring the entire range (0xff8000) may fail the sequence even if the device can be supported */
+                                       /*CODE REVIEW END: */
+
+                                       if ((response.cmd_rsp0 & SD_OCR_HC_RES) == SD_OCR_HC_RES) {
+                                               address_mode = SECT_MODE;
+                                               voltage_validation = SUCCESS;
+                                       }
+                                       /* CODE REVIEW 3: (same as above) Check is logically correct, but seems redundent.
+                                          Anything that fails the HC check, is assumed Low Capacity */
+                                       /* nirp_oct03: this can be just an "else". the LC macro is 0 anyway,
+                                          and anything not HC is LC by default */
+                                       else {
+                                               address_mode = BYTE_MODE;
+                                               voltage_validation = SUCCESS;
+                                       }
+                               }
+                       }
+
+               }
+
+               hal_delay_us(1000);
+
+       }
+
+       return voltage_validation;
 }
 
 static cyg_uint32 sd_get_rca(void)
 {
-    command_t cmd;
-    cyg_uint32 card_state = 0;
-    cyg_uint32 rca_request = 0;
-    command_response_t response;
-
-    /* Configure CMD3 for MMC card */
-    /* 32bit card address is expected as Argument */
-    mxcmci_cmd_config(&cmd, CMD3, NO_ARG, READ, RESPONSE_48,
-              DATA_PRESENT_NONE, ENABLE, ENABLE);
-
-    /* Get relative address of the card     */
-
-    if (host_send_cmd(&cmd) == FAIL) {
-        rca_request = FAIL;
-        diag_printf("Send CMD3 Failed.\n");
-    } else {
-        /* Read Command response */
-        response.format = RESPONSE_48;
-        host_read_response(&response);
-
-        Card_rca = ((cyg_uint32) (response.cmd_rsp0 >> RCA_SHIFT));
-
-        card_state = CURR_CARD_STATE(response.cmd_rsp0);
-
-        if (card_state == IDENT) {
-            rca_request = SUCCESS;
-        } else {
-            rca_request = FAIL;
-            diag_printf("Get RCA Failed.\n");
-        }
-    }
-
-    return rca_request;
+       command_t cmd;
+       cyg_uint32 card_state = 0;
+       cyg_uint32 rca_request = 0;
+       command_response_t response;
+
+       /* Configure CMD3 for MMC card */
+       /* 32bit card address is expected as Argument */
+       mxcmci_cmd_config(&cmd, CMD3, NO_ARG, READ, RESPONSE_48,
+                                       DATA_PRESENT_NONE, ENABLE, ENABLE);
+
+       /* Get relative address of the card     */
+
+       if (host_send_cmd(&cmd) == FAIL) {
+               rca_request = FAIL;
+               diag_printf("Send CMD3 Failed.\n");
+       } else {
+               /* Read Command response */
+               response.format = RESPONSE_48;
+               host_read_response(&response);
+
+               Card_rca = ((cyg_uint32) (response.cmd_rsp0 >> RCA_SHIFT));
+
+               card_state = CURR_CARD_STATE(response.cmd_rsp0);
+
+               if (card_state == IDENT) {
+                       rca_request = SUCCESS;
+               } else {
+                       rca_request = FAIL;
+                       diag_printf("Get RCA Failed.\n");
+               }
+       }
+
+       return rca_request;
 }
 
 static cyg_uint32 sd_get_bit_mode_support(void)
 {
-    command_t cmd;
-    cyg_uint32 rd_data_buff[128];
-    cyg_uint32 bit4_mode_support;
-    command_response_t response;
-    cyg_uint32 card_address = (Card_rca << RCA_SHIFT);
-
-    /* Configure CMD55 for SD card */
-    /* This command expects RCA as argument. */
-    mxcmci_cmd_config(&cmd, CMD55, card_address, READ, RESPONSE_48,
-              DATA_PRESENT_NONE, ENABLE, ENABLE);
-
-    /* Issue CMD55 to SD Memory card */
-    if (host_send_cmd(&cmd) == FAIL) {
-        bit4_mode_support = 0;
-    } else {
-        /* Read Command response */
-        response.format = RESPONSE_48;
-        host_read_response(&response);
-
-        /* Afetr giving ACMD Command, the R1 response should have
-         * STATUS_APP_CMD set
-         */
-        if (response.cmd_rsp0 & SD_R1_STATUS_APP_CMD_MSK) {
-
-            /* Configure ACMD51 for SD card */
-            /* This command expects No argument. */
-
-            mxcmci_cmd_config(&cmd, ACMD51, NO_ARG, READ,
-                      RESPONSE_48, DATA_PRESENT, ENABLE,
-                      ENABLE);
-
-            /* Issue ACMD51 to SD Memory card */
-            if (host_send_cmd(&cmd) == FAIL) {
-                bit4_mode_support = 0;
-            } else {
-                /* Read Response from e-SDHC buffer */
-                host_data_read(rd_data_buff, 512);
-
-                /* Check for bus width supported */
-                bit4_mode_support = (rd_data_buff[SD_BUS_WIDTH_OFFSET] & BIT_MODE_4_SUPPORT);
-
-                if (bit4_mode_support) {
-                    bit4_mode_support = BIT_4_MODE;
-                }
-
-            }
-        }
-    }
-
-    return bit4_mode_support;
+       command_t cmd;
+       cyg_uint32 rd_data_buff[128];
+       cyg_uint32 bit4_mode_support;
+       command_response_t response;
+       cyg_uint32 card_address = (Card_rca << RCA_SHIFT);
+
+       /* Configure CMD55 for SD card */
+       /* This command expects RCA as argument. */
+       mxcmci_cmd_config(&cmd, CMD55, card_address, READ, RESPONSE_48,
+                                       DATA_PRESENT_NONE, ENABLE, ENABLE);
+
+       /* Issue CMD55 to SD Memory card */
+       if (host_send_cmd(&cmd) == FAIL) {
+               bit4_mode_support = 0;
+       } else {
+               /* Read Command response */
+               response.format = RESPONSE_48;
+               host_read_response(&response);
+
+               /* Afetr giving ACMD Command, the R1 response should have
+                * STATUS_APP_CMD set
+                */
+               if (response.cmd_rsp0 & SD_R1_STATUS_APP_CMD_MSK) {
+
+                       /* Configure ACMD51 for SD card */
+                       /* This command expects No argument. */
+
+                       mxcmci_cmd_config(&cmd, ACMD51, NO_ARG, READ,
+                                                       RESPONSE_48, DATA_PRESENT, ENABLE,
+                                                       ENABLE);
+
+                       /* Issue ACMD51 to SD Memory card */
+                       if (host_send_cmd(&cmd) == FAIL) {
+                               bit4_mode_support = 0;
+                       } else {
+                               /* Read Response from e-SDHC buffer */
+                               host_data_read(rd_data_buff, 512);
+
+                               /* Check for bus width supported */
+                               bit4_mode_support = (rd_data_buff[SD_BUS_WIDTH_OFFSET] & BIT_MODE_4_SUPPORT);
+
+                               if (bit4_mode_support) {
+                                       bit4_mode_support = BIT_4_MODE;
+                               }
+
+                       }
+               }
+       }
+
+       return bit4_mode_support;
 }
 
 static cyg_uint32 sd_set_bus_width(cyg_uint32 bus_width)
 {
-    command_t cmd;
-    cyg_uint32 set_bus_width_status = 0;
-    command_response_t response;
-    cyg_uint32 card_address = (Card_rca << RCA_SHIFT);
-
-    if ((bus_width == FOUR) || (bus_width == ONE)) {
-        /* Configure CMD55 for SD card */
-        /* This command expects RCA as argument. */
-
-        mxcmci_cmd_config(&cmd, CMD55, card_address, READ, RESPONSE_48,
-                  DATA_PRESENT_NONE, ENABLE, ENABLE);
-
-        /* Issue CMD55 to SD Memory card */
-        if (host_send_cmd(&cmd) == FAIL) {
-            set_bus_width_status = FAIL;
-        } else {
-            /* Read Command response */
-            response.format = RESPONSE_48;
-            host_read_response(&response);
-
-            /* Afetr giving ACMD Command, the R1 response should have
-             * STATUS_APP_CMD set
-             */
-            if (response.cmd_rsp0 & SD_R1_STATUS_APP_CMD_MSK) {
-                bus_width = (bus_width >> ONE);
-
-                /* Configure ACMD6 for SD card */
-                mxcmci_cmd_config(&cmd, ACMD6, bus_width, READ,
-                          RESPONSE_48,
-                          DATA_PRESENT_NONE, ENABLE,
-                          ENABLE);
-
-                /* Issue ACMD6 to SD Memory card */
-                if (host_send_cmd(&cmd) == FAIL) {
-                    set_bus_width_status = FAIL;
-                } else {
-                    set_bus_width_status = SUCCESS;
-                }
-            }
-        }
-    }
-
-    return set_bus_width_status;
+       command_t cmd;
+       cyg_uint32 set_bus_width_status = 0;
+       command_response_t response;
+       cyg_uint32 card_address = (Card_rca << RCA_SHIFT);
+
+       if ((bus_width == 4) || (bus_width == 1)) {
+               /* Configure CMD55 for SD card */
+               /* This command expects RCA as argument. */
+
+               mxcmci_cmd_config(&cmd, CMD55, card_address, READ, RESPONSE_48,
+                                               DATA_PRESENT_NONE, ENABLE, ENABLE);
+
+               /* Issue CMD55 to SD Memory card */
+               if (host_send_cmd(&cmd) == FAIL) {
+                       set_bus_width_status = FAIL;
+               } else {
+                       /* Read Command response */
+                       response.format = RESPONSE_48;
+                       host_read_response(&response);
+
+                       /* Afetr giving ACMD Command, the R1 response should have
+                        * STATUS_APP_CMD set
+                        */
+                       if (response.cmd_rsp0 & SD_R1_STATUS_APP_CMD_MSK) {
+                               bus_width = (bus_width >> ONE);
+
+                               /* Configure ACMD6 for SD card */
+                               mxcmci_cmd_config(&cmd, ACMD6, bus_width, READ,
+                                                               RESPONSE_48,
+                                                               DATA_PRESENT_NONE, ENABLE,
+                                                               ENABLE);
+
+                               /* Issue ACMD6 to SD Memory card */
+                               if (host_send_cmd(&cmd) == FAIL) {
+                                       set_bus_width_status = FAIL;
+                               } else {
+                                       set_bus_width_status = SUCCESS;
+                               }
+                       }
+               }
+       }
+
+       return set_bus_width_status;
 }
 
 /*==========================================================================
@@ -515,74 +516,74 @@ Detailed Description:
 
 cyg_uint32 esd_set_boot_partition(cyg_uint32 *src_ptr, cyg_uint32 length)
 {
-    command_t cmd;
-    cyg_uint32 set_partition_status = FAIL;
-    command_response_t response;
-    cyg_uint8 response_data[512];
-    cyg_uint32 *response_pointer = (cyg_uint32 *) response_data;
-    cyg_uint32 card_address = (Card_rca << RCA_SHIFT);
-    cyg_uint32 card_state;
-
-   /* Send CMD43 to select partition PARTITION1 active */
-    mxcmci_cmd_config(&cmd, CMD43,
-                              0x1<<24,
-                              READ,
-                              RESPONSE_48,
-                              DATA_PRESENT_NONE,
-                              ENABLE,
-                              ENABLE);
-
-    if(host_send_cmd(&cmd) == FAIL) {
-        //diag_printf("%s: Send CMD43 Failed.\n", __FUNCTION__);
-        return 1;
-    }
-
-    set_partition_status = mmc_data_write (src_ptr, length, 0);
-    if(set_partition_status) {
-        return 1; /* failed */
-    }
-
-    return 0;
+       command_t cmd;
+       cyg_uint32 set_partition_status = FAIL;
+       command_response_t response;
+       cyg_uint8 response_data[512];
+       cyg_uint32 *response_pointer = (cyg_uint32 *) response_data;
+       cyg_uint32 card_address = (Card_rca << RCA_SHIFT);
+       cyg_uint32 card_state;
+
+       /* Send CMD43 to select partition PARTITION1 active */
+       mxcmci_cmd_config(&cmd, CMD43,
+                                       0x1<<24,
+                                       READ,
+                                       RESPONSE_48,
+                                       DATA_PRESENT_NONE,
+                                       ENABLE,
+                                       ENABLE);
+
+       if(host_send_cmd(&cmd) == FAIL) {
+               //diag_printf("%s: Send CMD43 Failed.\n", __FUNCTION__);
+               return 1;
+       }
+
+       set_partition_status = mmc_data_write (src_ptr, length, 0);
+       if(set_partition_status) {
+               return 1; /* failed */
+       }
+
+       return 0;
 }
 
 static cyg_uint32 sd_set_high_speed_mode(void)
 {
-    command_t cmd;
-    cyg_uint32 status = FAIL;
-    command_response_t response;
-
-    /* Configure CMD6 for SD card */
-    mxcmci_cmd_config(&cmd, CMD6, 0xfffff1, READ, RESPONSE_48,
-              DATA_PRESENT_NONE, ENABLE, ENABLE);
-
-    /* Issue CMD6 to SD Memory card */
-    if (host_send_cmd(&cmd) == FAIL) {
-        status = FAIL;
-        diag_printf("Send CMD6 Failed.\n");
-        return FAIL;
-    } else {
-        hal_delay_us(1000);
-        status = SUCCESS;
-
-    }
-
-    mxcmci_cmd_config(&cmd, CMD6, 0x80fffff1, READ, RESPONSE_48,
-              DATA_PRESENT_NONE, ENABLE, ENABLE);
-
-    /* Issue CMD6 to SD Memory card */
-    if (host_send_cmd(&cmd) == FAIL) {
-        status = FAIL;
-        diag_printf("Send CMD6 Failed.\n");
-    } else {
-        /* wait until in transfer mode */
-        while (mxcmci_trans_status()) {
-            hal_delay_us(5);
-        }
-
-        status = SUCCESS;
-    }
-
-    return status;
+       command_t cmd;
+       cyg_uint32 status = FAIL;
+       command_response_t response;
+
+       /* Configure CMD6 for SD card */
+       mxcmci_cmd_config(&cmd, CMD6, 0xfffff1, READ, RESPONSE_48,
+                                       DATA_PRESENT_NONE, ENABLE, ENABLE);
+
+       /* Issue CMD6 to SD Memory card */
+       if (host_send_cmd(&cmd) == FAIL) {
+               status = FAIL;
+               diag_printf("Send CMD6 Failed.\n");
+               return FAIL;
+       } else {
+               hal_delay_us(1000);
+               status = SUCCESS;
+
+       }
+
+       mxcmci_cmd_config(&cmd, CMD6, 0x80fffff1, READ, RESPONSE_48,
+                                       DATA_PRESENT_NONE, ENABLE, ENABLE);
+
+       /* Issue CMD6 to SD Memory card */
+       if (host_send_cmd(&cmd) == FAIL) {
+               status = FAIL;
+               diag_printf("Send CMD6 Failed.\n");
+       } else {
+               /* wait until in transfer mode */
+               while (mxcmci_trans_status()) {
+                       hal_delay_us(5);
+               }
+
+               status = SUCCESS;
+       }
+
+       return status;
 }
 
 /* end of mxcmic_sd.c */
index 8f655ca..2d2c7a3 100644 (file)
@@ -20,6 +20,7 @@
 // System-wide configuration info
 #include <pkgconf/system.h>
 #include <cyg/infra/cyg_type.h>
+#include <cyg/infra/diag.h>
 #ifdef CYGBLD_HAL_PLF_DEFS_H
 #include CYGBLD_HAL_PLF_DEFS_H
 #else
index 533a867..a26d209 100644 (file)
@@ -1817,6 +1817,15 @@ package CYGPKG_DEVS_ETH_ARM_TX51 {
        This package provides Ethernet support for the Ka-Ro electronics TX51 processor module."
 }
 
+package CYGPKG_DEVS_ETH_ARM_TX53 {
+       alias           { "Ethernet driver for Ka-Ro electronics TX53 processor module" devs_eth_arm_tx53 }
+       directory       devs/eth/arm/tx53karo
+       script          tx53_eth_drivers.cdl
+       hardware
+       description "
+       This package provides Ethernet support for the Ka-Ro electronics TX53 processor module."
+}
+
 package CYGPKG_DEVS_ETH_ARM_IMX_3STACK {
        alias           { "Ethernet driver for Freescale 3-Stack board" imx_3stack_eth_driver }
        hardware
@@ -3593,6 +3602,16 @@ package CYGPKG_HAL_ARM_MX51 {
         eCos on Freescale i.MX51 based systems."
 }
 
+package CYGPKG_HAL_ARM_MX53 {
+       alias           { "Freescale i.MX53 Chipset" hal_arm_mx53 }
+       directory       hal/arm/mx53/var
+       script          hal_arm_soc.cdl
+       hardware
+        description "
+        The MX53 HAL package provides the support needed to run
+        eCos on Freescale i.MX53 based systems."
+}
+
 package CYGPKG_HAL_ARM_MXC91321 {
        alias           { "Freescale MXC91321 Chipset" hal_arm_mxc91321 }
        directory       hal/arm/mxc91321/var
@@ -3762,6 +3781,16 @@ package CYGPKG_HAL_ARM_TX51KARO {
         eCos on a Ka-Ro electronics TX51 processor module."
 }
 
+package CYGPKG_HAL_ARM_TX53KARO {
+       alias           { "Ka-Ro electronics TX53 processor module" hal_arm_tx53karo }
+       directory       hal/arm/mx53/karo
+       script          hal_arm_tx53.cdl
+       hardware
+        description "
+        The TX53 HAL package provides the support needed to run
+        eCos on a Ka-Ro electronics TX53 processor module."
+}
+
 # --------------------------------------------------------------------------
 # SH packages
 package CYGPKG_HAL_SH {
@@ -5897,6 +5926,18 @@ target tx51karo {
         Freescale i.MX51 processor."
 }
 
+target tx53karo {
+       alias { "Ka-Ro electronics TX53 processor module" mx53 tx53karo }
+       packages {  CYGPKG_HAL_ARM
+                       CYGPKG_HAL_ARM_MX53
+                       CYGPKG_HAL_ARM_TX53KARO
+        }
+        description "
+        The tx53karo target provides the packages needed to run
+        eCos on a Ka-Ro electronics TX53 module equipped with a
+        Freescale i.MX53 processor."
+}
+
 target mx31ads {
        alias { "Freescale i.MX31 ADS board" mx31 mx31ads }
        packages {  CYGPKG_HAL_ARM
index 81c1bec..9d7a5f9 100644 (file)
@@ -77,7 +77,7 @@
 #include <cyg/hal/hal_io.h>
 
 #ifndef CYGARC_PHYSICAL_ADDRESS
-# error
+# error CYGARC_PHYSICAL_ADDRESS not defined
 # define CYGARC_PHYSICAL_ADDRESS(x) (x)
 #endif
 
index 189303e..5fc75a0 100644 (file)
@@ -42,7 +42,7 @@
 //#####DESCRIPTIONBEGIN####
 //
 // Author(s):    nickg,gthomas,jlarmour
-// Contributors: 
+// Contributors:
 // Date:         1999-02-22
 // Purpose:      Infrastructure diagnostic output
 // Description:  Implementations of infrastructure diagnostic routines.
 #include <pkgconf/hal.h>
 #include <pkgconf/infra.h>
 
-#include <cyg/infra/cyg_type.h>         // base types
-  
-#include <cyg/infra/diag.h>             // HAL polled output
-#include <cyg/hal/hal_arch.h>           // architectural stuff for...
-#include <cyg/hal/hal_intr.h>           // interrupt control
-#include <cyg/hal/hal_diag.h>           // diagnostic output routines
+#include <cyg/infra/cyg_type.h>                // base types
+
+#include <cyg/infra/diag.h>            // HAL polled output
+#include <cyg/hal/hal_arch.h>          // architectural stuff for...
+#include <cyg/hal/hal_intr.h>          // interrupt control
+#include <cyg/hal/hal_diag.h>          // diagnostic output routines
 #include <stdarg.h>
 #include <limits.h>
 #include <ctype.h>
-  
+
 #ifdef CYG_HAL_DIAG_LOCK_DATA_DEFN
 CYG_HAL_DIAG_LOCK_DATA_DEFN;
 #endif
-  
+
 /*----------------------------------------------------------------------*/
 
 externC void diag_write_num(
-    cyg_uint32 n,              /* number to write              */
-    cyg_ucount8 base,          /* radix to write to            */
-    cyg_ucount8 sign,          /* sign, '-' if -ve, '+' if +ve */
-    cyg_bool   pfzero,         /* prefix with zero ?           */
-    cyg_ucount8 width          /* min width of number          */
-    );
+       cyg_uint64      n,                      /* number to write                      */
+       cyg_ucount8 base,               /* radix to write to            */
+       cyg_ucount8 sign,               /* sign, '-' if -ve, '+' if +ve */
+       cyg_bool        pfzero,         /* prefix with zero ?           */
+       cyg_ucount8 width               /* min width of number          */
+       );
 
 class Cyg_dummy_diag_init_class {
 public:
        Cyg_dummy_diag_init_class() {
-           HAL_DIAG_INIT();
-    }
+               HAL_DIAG_INIT();
+       }
 };
 
 // Initialize after HAL.
 static Cyg_dummy_diag_init_class cyg_dummy_diag_init_obj
-                                     CYGBLD_ATTRIB_INIT_AFTER(CYG_INIT_HAL);
+CYGBLD_ATTRIB_INIT_AFTER(CYG_INIT_HAL);
 
 /*----------------------------------------------------------------------*/
 /* Write single char to output                                          */
 
 externC void diag_write_char(char c)
 {
-    /* Translate LF into CRLF */
+       /* Translate LF into CRLF */
 
-    if( c == '\n' )
-    {
-       HAL_DIAG_WRITE_CHAR('\r');
-    }
+       if (c == '\n') {
+               HAL_DIAG_WRITE_CHAR('\r');
+       }
 
-    HAL_DIAG_WRITE_CHAR(c);
+       HAL_DIAG_WRITE_CHAR(c);
 }
 
 // Default wrapper function used by diag_printf
 static void
 _diag_write_char(char c, void *param)
 {
-    diag_write_char(c);
+       diag_write_char(c);
 }
 
 /*----------------------------------------------------------------------*/
@@ -128,7 +127,7 @@ static void (*_putc)(char c, void *param) = _diag_write_char;
 externC void
 diag_init_putc(void (*putc)(char c, void *param))
 {
-    _putc = putc;
+       _putc = putc;
 }
 
 /*----------------------------------------------------------------------*/
@@ -136,29 +135,32 @@ diag_init_putc(void (*putc)(char c, void *param))
 
 externC void diag_write_string(const char *psz)
 {
-    while( *psz ) diag_write_char( *psz++ );
+       while (*psz)
+               diag_write_char(*psz++);
 }
 
 /*----------------------------------------------------------------------*/
 /* Write decimal value                                                  */
 
-externC void diag_write_dec( cyg_int32 n)
+externC void diag_write_dec(cyg_int32 n)
 {
-    cyg_ucount8 sign;
+       cyg_ucount8 sign;
 
-    if( n < 0 ) n = -n, sign = '-';
-    else sign = '+';
-    
-    diag_write_num( n, 10, sign, false, 0);
+       if (n < 0)
+               n = -n, sign = '-';
+       else
+               sign = '+';
+
+       diag_write_num(n, 10, sign, false, 0);
 }
 
 /*----------------------------------------------------------------------*/
 /* Write hexadecimal value                                              */
 
-externC void diag_write_hex( cyg_uint32 n)
+externC void diag_write_hex(cyg_uint32 n)
 {
-    diag_write_num( n, 16, '+', false, 0);
-}    
+       diag_write_num(n, 16, '+', false, 0);
+}
 
 /*----------------------------------------------------------------------*/
 /* Generic number writing function                                      */
@@ -167,94 +169,94 @@ externC void diag_write_hex( cyg_uint32 n)
 /* the left.                                                            */
 
 externC void diag_write_long_num(
-    cyg_uint64  n,              /* number to write              */
-    cyg_ucount8 base,           /* radix to write to            */
-    cyg_ucount8 sign,           /* sign, '-' if -ve, '+' if +ve */
-    cyg_bool    pfzero,         /* prefix with zero ?           */
-    cyg_ucount8 width           /* min width of number          */
-    )
+       cyg_uint64      n,                      /* number to write                      */
+       cyg_ucount8 base,               /* radix to write to            */
+       cyg_ucount8 sign,               /* sign, '-' if -ve, '+' if +ve */
+       cyg_bool        pfzero,         /* prefix with zero ?           */
+       cyg_ucount8 width               /* min width of number          */
+       )
 {
-    char buf[32];
-    cyg_count8 bpos;
-    char bufinit = pfzero?'0':' ';
-    const char *digits = "0123456789ABCDEF";
-
-    /* init buffer to padding char: space or zero */
-    for( bpos = 0; bpos < (cyg_count8)sizeof(buf); bpos++ ) buf[bpos] = bufinit;
-
-    /* Set pos to start */
-    bpos = 0;
-
-    /* construct digits into buffer in reverse order */
-    if( n == 0 ) buf[bpos++] = '0';
-    else while( n != 0 )
-    {
-        cyg_ucount8 d = n % base;
-        buf[bpos++] = digits[d];
-        n /= base;
-    }
-
-    /* set pos to width if less. */
-    if( (cyg_count8)width > bpos ) bpos = width;
-
-    /* set sign if negative. */
-    if( sign == '-' )
-    {
-        if( buf[bpos-1] == bufinit ) bpos--;
-        buf[bpos] = sign;
-    }
-    else bpos--;
-
-    /* Now write it out in correct order. */
-    while( bpos >= 0 )
-        diag_write_char(buf[bpos--]);
+       char buf[32];
+       cyg_count8 bpos;
+       char bufinit = pfzero?'0':' ';
+       const char *digits = "0123456789ABCDEF";
+
+       /* init buffer to padding char: space or zero */
+       for (bpos = 0; bpos < (cyg_count8)sizeof(buf); bpos++)
+               buf[bpos] = bufinit;
+
+       /* Set pos to start */
+       bpos = 0;
+
+       /* construct digits into buffer in reverse order */
+       if (n == 0)
+               buf[bpos++] = '0';
+       else
+               while (n != 0) {
+                       cyg_ucount8 d = n % base;
+                       buf[bpos++] = digits[d];
+                       n /= base;
+               }
+
+       /* set pos to width if less. */
+       if ((cyg_count8)width > bpos)
+               bpos = width;
+
+       /* set sign if negative. */
+       if (sign == '-') {
+               if (buf[bpos-1] == bufinit) bpos--;
+               buf[bpos] = sign;
+       } else {
+               bpos--;
+       }
+
+       /* Now write it out in correct order. */
+       while(bpos >= 0)
+               diag_write_char(buf[bpos--]);
 }
 
 externC void diag_write_num(
-    cyg_uint32  n,              /* number to write              */
-    cyg_ucount8 base,           /* radix to write to            */
-    cyg_ucount8 sign,           /* sign, '-' if -ve, '+' if +ve */
-    cyg_bool    pfzero,         /* prefix with zero ?           */
-    cyg_ucount8 width           /* min width of number          */
-    )
+       cyg_uint64      n,                      /* number to write                      */
+       cyg_ucount8 base,               /* radix to write to            */
+       cyg_ucount8 sign,               /* sign, '-' if -ve, '+' if +ve */
+       cyg_bool        pfzero,         /* prefix with zero ?           */
+       cyg_ucount8 width               /* min width of number          */
+       )
 {
-    diag_write_long_num((long long)n, base, sign, pfzero, width);
+       diag_write_long_num(n, base, sign, pfzero, width);
 }
 
 /*----------------------------------------------------------------------*/
 /* perform some simple sanity checks on a string to ensure that it      */
 /* consists of printable characters and is of reasonable length.        */
 
-static cyg_bool diag_check_string( const char *str )
+static cyg_bool diag_check_string(const char *str)
 {
-    cyg_bool result = true;
-    const char *s;
-
-    if( str == NULL ) return false;
-    
-    for( s = str ; result && *s ; s++ )
-    {
-        char c = *s;
+       cyg_bool result = true;
+       const char *s;
 
-        /* Check for a reasonable length string. */
-        
-        if( s-str > 2048 ) result = false;
+       if (str == NULL)
+               return false;
 
-        /* We only really support CR, NL, tab and backspace at present.
-        * If we want to use other special chars, this test will
-         * have to be expanded.  */
+       for (s = str ; result && *s ; s++) {
+               char c = *s;
 
-        if( c == '\n' || c == '\r' || c == '\b' || c == '\t' )
-            continue;
+               /* Check for a reasonable length string. */
+               if (s - str > 2048)
+                       result = false;
 
-        /* Check for printable chars. This assumes ASCII */
-        
-        if( c < ' ' || c > '~' )
-            result = false;
+               /* We only really support CR, NL, tab and backspace at present.
+                * If we want to use other special chars, this test will
+                * have to be expanded.  */
+               if (c == '\n' || c == '\r' || c == '\b' || c == '\t')
+                       continue;
 
-    }
+               /* Check for printable chars. This assumes ASCII */
+               if (c < ' ' || c > '~')
+                       result = false;
+       }
 
-    return result;
+       return result;
 }
 
 /*----------------------------------------------------------------------*/
@@ -262,25 +264,25 @@ static cyg_bool diag_check_string( const char *str )
 static int
 _cvt(unsigned long long val, char *buf, long radix, const char *digits)
 {
-    char temp[80];
-    char *cp = temp;
-    int length = 0;
-
-    if (val == 0) {
-        /* Special case */
-        *cp++ = '0';
-    } else {
-        while (val) {
-            *cp++ = digits[val % radix];
-            val /= radix;
-        }
-    }
-    while (cp != temp) {
-        *buf++ = *--cp;
-        length++;
-    }
-    *buf = '\0';
-    return (length);
+       char temp[80];
+       char *cp = temp;
+       int length = 0;
+
+       if (val == 0) {
+               /* Special case */
+               *cp++ = '0';
+       } else {
+               while (val) {
+                       *cp++ = digits[val % radix];
+                       val /= radix;
+               }
+       }
+       while (cp != temp) {
+               *buf++ = *--cp;
+               length++;
+       }
+       *buf = '\0';
+       return length;
 }
 
 #define is_digit(c) ((c >= '0') && (c <= '9'))
@@ -288,375 +290,379 @@ _cvt(unsigned long long val, char *buf, long radix, const char *digits)
 static int
 _vprintf(void (*putc)(char c, void *param), void *param, const char *fmt, va_list ap)
 {
-    char buf[sizeof(long long)*8];
-    char c, sign;
-    const char *cp=buf;
-    int left_prec, right_prec, zero_fill, pad, pad_on_right, 
-        i, islong, islonglong;
-    long long val = 0;
-    int res = 0, length = 0;
-
-    if (!diag_check_string(fmt)) {
-        diag_write_string("<Bad format string: ");
-        diag_write_hex((cyg_uint32)fmt);
-        diag_write_string(" :");
-        for( i = 0; i < 8; i++ ) {
-            diag_write_char(' ');
-            val = va_arg(ap, unsigned long);
-            diag_write_hex(val);
-        }
-        diag_write_string(">\n");
-        return 0;
-    }
-    while ((c = *fmt++) != '\0') {
-        if (c == '%') {
-            c = *fmt++;
-            left_prec = right_prec = pad_on_right = islong = islonglong = 0;
-            if (c == '-') {
-                c = *fmt++;
-                pad_on_right++;
-            }
-            if (c == '0') {
-                zero_fill = true;
-                c = *fmt++;
-            } else {
-                zero_fill = false;
-            }
-            while (is_digit(c)) {
-                left_prec = (left_prec * 10) + (c - '0');
-                c = *fmt++;
-            }
-            if (c == '.') {
-                c = *fmt++;
-                zero_fill++;
-                while (is_digit(c)) {
-                    right_prec = (right_prec * 10) + (c - '0');
-                    c = *fmt++;
-                }
-            } else {
-                right_prec = left_prec;
-            }
-            sign = '\0';
-            if (c == 'l') {
-                // 'long' qualifier
-                c = *fmt++;
-               islong = 1;
-                if (c == 'l') {
-                    // long long qualifier
-                    c = *fmt++;
-                    islonglong = 1;
-                }
-            }
-            if (c == 'z') {
-                c = *fmt++;
-               islong = sizeof(size_t) == sizeof(long);
-            }
-            // Fetch value [numeric descriptors only]
-            switch (c) {
-            case 'p':
-               islong = 1;
-            case 'd':
-            case 'D':
-            case 'x':
-            case 'X':
-            case 'u':
-            case 'U':
-            case 'b':
-            case 'B':
-                if (islonglong) {
-                    val = va_arg(ap, long long);
-               } else if (islong) {
-                    val = (long long)va_arg(ap, long);
-               } else{
-                    val = (long long)va_arg(ap, int);
-                }
-                if ((c == 'd') || (c == 'D')) {
-                    if (val < 0) {
-                        sign = '-';
-                        val = -val;
-                    }
-                } else {
-                    // Mask to unsigned, sized quantity
-                    if (islong) {
-                        val &= ((long long)1 << (sizeof(long) * 8)) - 1;
-                    } else if (!islonglong) { // no need to mask longlong
-                        val &= ((long long)1 << (sizeof(int) * 8)) - 1;
-                    }
-                }
-                break;
-            default:
-                break;
-            }
-            // Process output
-            switch (c) {
-            case 'p':  // Pointer
-                (*putc)('0', param);
-                (*putc)('x', param);
-                zero_fill = true;
-                left_prec = sizeof(unsigned long)*2;
-                res += 2;  // Account for "0x" leadin
-            case 'd':
-            case 'D':
-            case 'u':
-            case 'U':
-            case 'x':
-            case 'X':
-                switch (c) {
-                case 'd':
-                case 'D':
-                case 'u':
-                case 'U':
-                    length = _cvt(val, buf, 10, "0123456789");
-                    break;
-                case 'p':
-                case 'x':
-                    length = _cvt(val, buf, 16, "0123456789abcdef");
-                    break;
-                case 'X':
-                    length = _cvt(val, buf, 16, "0123456789ABCDEF");
-                    break;
-                }
-                cp = buf;
-                break;
-            case 's':
-            case 'S':
-                cp = va_arg(ap, char *);
-                if (cp == NULL) 
-                    cp = "<null>";
+       char buf[sizeof(long long) * 8];
+       char c, sign;
+       const char *cp = buf;
+       int left_prec, right_prec, zero_fill, pad, pad_on_right,
+               i, islong, islonglong;
+       long long val = 0;
+       int res = 0, length = 0;
+
+       if (!diag_check_string(fmt)) {
+               diag_write_string("<Bad format string: ");
+               diag_write_hex((cyg_uint32)fmt);
+               diag_write_string(" :");
+               for (i = 0; i < 8; i++) {
+                       diag_write_char(' ');
+                       val = va_arg(ap, unsigned long);
+                       diag_write_hex(val);
+               }
+               diag_write_string(">\n");
+               return 0;
+       }
+       while ((c = *fmt++) != '\0') {
+               if (c == '%') {
+                       c = *fmt++;
+                       left_prec = right_prec = pad_on_right = islong = islonglong = 0;
+                       if (c == '-') {
+                               c = *fmt++;
+                               pad_on_right++;
+                       }
+                       if (c == '0') {
+                               zero_fill = true;
+                               c = *fmt++;
+                       } else {
+                               zero_fill = false;
+                       }
+                       while (is_digit(c)) {
+                               left_prec = (left_prec * 10) + (c - '0');
+                               c = *fmt++;
+                       }
+                       if (c == '.') {
+                               c = *fmt++;
+                               zero_fill++;
+                               while (is_digit(c)) {
+                                       right_prec = (right_prec * 10) + (c - '0');
+                                       c = *fmt++;
+                               }
+                       } else {
+                               right_prec = left_prec;
+                       }
+                       sign = '\0';
+                       if (c == 'l') {
+                               // 'long' qualifier
+                               c = *fmt++;
+                               islong = 1;
+                               if (c == 'l') {
+                                       // long long qualifier
+                                       c = *fmt++;
+                                       islonglong = 1;
+                               }
+                       }
+                       if (c == 'z') {
+                               c = *fmt++;
+                               islong = sizeof(size_t) == sizeof(long);
+                       }
+                       // Fetch value [numeric descriptors only]
+                       switch (c) {
+                       case 'p':
+                               islong = 1;
+                       case 'd':
+                       case 'D':
+                       case 'x':
+                       case 'X':
+                       case 'u':
+                       case 'U':
+                       case 'b':
+                       case 'B':
+                               if (islonglong) {
+                                       val = va_arg(ap, long long);
+                               } else if (islong) {
+                                       val = (long long)va_arg(ap, long);
+                               } else{
+                                       val = (long long)va_arg(ap, int);
+                               }
+                               if ((c == 'd') || (c == 'D')) {
+                                       if (val < 0) {
+                                               sign = '-';
+                                               val = -val;
+                                       }
+                               } else {
+                                       // Mask to unsigned, sized quantity
+                                       if (!islonglong) {
+                                               // no need to mask longlong
+                                               if (islong)
+                                                       val &= ((long long)1 << (sizeof(long) * 8)) - 1;
+                                               else
+                                                       val &= ((long long)1 << (sizeof(int) * 8)) - 1;
+                                       }
+                               }
+                               break;
+                       default:
+                               break;
+                       }
+                       // Process output
+                       switch (c) {
+                       case 'p':  // Pointer
+                               putc('0', param);
+                               putc('x', param);
+                               zero_fill = true;
+                               left_prec = sizeof(unsigned long) * 2;
+                               res += 2;  // Account for "0x" leadin
+                       case 'd':
+                       case 'D':
+                       case 'u':
+                       case 'U':
+                       case 'x':
+                       case 'X':
+                               switch (c) {
+                               case 'd':
+                               case 'D':
+                               case 'u':
+                               case 'U':
+                                       length = _cvt(val, buf, 10, "0123456789");
+                                       break;
+                               case 'p':
+                               case 'x':
+                                       length = _cvt(val, buf, 16, "0123456789abcdef");
+                                       break;
+                               case 'X':
+                                       length = _cvt(val, buf, 16, "0123456789ABCDEF");
+                                       break;
+                               }
+                               cp = buf;
+                               break;
+                       case 's':
+                       case 'S':
+                               cp = va_arg(ap, char *);
+                               if (cp == NULL)
+                                       cp = "<null>";
 #if !CYGINT_ISO_CTYPE
 #warning enable CYGINT_ISO_CTYPE to get sensible string output instead of bogus '<Not a string 0x...>' messages for unprintable characters
-                else if (!diag_check_string(cp)) {
-                    diag_write_string("<Not a string: 0x");
-                    diag_write_hex((cyg_uint32)cp);
-                    cp = ">";
-                }
+                               else if (!diag_check_string(cp)) {
+                                       diag_write_string("<Not a string: 0x");
+                                       diag_write_hex((cyg_uint32)cp);
+                                       cp = ">";
+                               }
 #endif
-                length = 0;
-                while (cp[length] != '\0') length++;
-                break;
-            case 'c':
-            case 'C':
-                c = va_arg(ap, int /*char*/);
-                (*putc)(c, param);
-                res++;
-                continue;
-            case 'b':
-            case 'B':
-                length = left_prec;
-                if (left_prec == 0) {
-                    if (islonglong)
-                        length = sizeof(long long)*8;
-                    else if (islong)
-                        length = sizeof(long)*8;
-                    else
-                        length = sizeof(int)*8;
-                }
-                for (i = 0;  i < length-1;  i++) {
-                    buf[i] = ((val & ((long long)1<<i)) ? '1' : '.');
-                }
-                cp = buf;
-                break;
-            case '%':
-                (*putc)('%', param);
-                res++;
-                continue;
-            default:
-                (*putc)('%', param);
-                (*putc)(c, param);
-                res += 2;
-                continue;
-            }
-            pad = left_prec - length;
-            if (sign != '\0') {
-                pad--;
-            }
-            if (zero_fill) {
-                c = '0';
-                if (sign != '\0') {
-                    (*putc)(sign, param);
-                    res++;
-                    sign = '\0';
-                }
-            } else {
-                c = ' ';
-            }
-            if (!pad_on_right) {
-                while (pad-- > 0) {
-                    (*putc)(c, param);
-                    res++;
-                }
-            }
-            if (sign != '\0') {
-                (*putc)(sign, param);
-                res++;
-            }
-            while (length-- > 0) {
-                c = *cp++;
-#if CYGINT_ISO_CTYPE
-                if (isprint(c) || isspace(c)) {
-                (*putc)(c, param);
-               } else if (iscntrl(c)) {
-                       (*putc)('\\', param);
-                       (*putc)('C', param);
-                       (*putc)('-', param);
-                       (*putc)(c | 0x40, param);
-               } else {
-                       int len = _cvt(c, buf, 16, "0123456789ABCDEF");
-                       (*putc)('\\', param);
-                       (*putc)('0', param);
-                       (*putc)('x', param);
-                       for (int i = 0; i < len; i++) {
-                               (*putc)(buf[i], param);
+                               length = 0;
+                               while (cp[length] != '\0') length++;
+                               break;
+                       case 'c':
+                       case 'C':
+                               c = va_arg(ap, int /*char*/);
+                               putc(c, param);
+                               res++;
+                               continue;
+                       case 'b':
+                       case 'B':
+                               length = left_prec;
+                               if (left_prec == 0) {
+                                       if (islonglong)
+                                               length = sizeof(long long) * 8;
+                                       else if (islong)
+                                               length = sizeof(long) * 8;
+                                       else
+                                               length = sizeof(int) * 8;
+                               }
+                               for (i = 0;  i < length-1;  i++) {
+                                       buf[i] = ((val & ((long long)1<<i)) ? '1' : '.');
+                               }
+                               cp = buf;
+                               break;
+                       case '%':
+                               putc('%', param);
+                               res++;
+                               continue;
+                       default:
+                               putc('%', param);
+                               putc(c, param);
+                               res += 2;
+                               continue;
                        }
-               }
+                       pad = left_prec - length;
+                       if (sign != '\0') {
+                               pad--;
+                       }
+                       if (zero_fill) {
+                               c = '0';
+                               if (sign != '\0') {
+                                       putc(sign, param);
+                                       res++;
+                                       sign = '\0';
+                               }
+                       } else {
+                               c = ' ';
+                       }
+                       if (!pad_on_right) {
+                               while (pad-- > 0) {
+                                       putc(c, param);
+                                       res++;
+                               }
+                       }
+                       if (sign != '\0') {
+                               putc(sign, param);
+                               res++;
+                       }
+                       while (length-- > 0) {
+                               c = *cp++;
+#if CYGINT_ISO_CTYPE
+                               if (isprint(c) || isspace(c)) {
+                                       putc(c, param);
+                               } else if (iscntrl(c)) {
+                                       putc('\\', param);
+                                       putc('C', param);
+                                       putc('-', param);
+                                       putc(c | 0x40, param);
+                               } else {
+                                       int len = _cvt(c, buf, 16, "0123456789ABCDEF");
+                                       putc('\\', param);
+                                       putc('0', param);
+                                       putc('x', param);
+                                       for (int i = 0; i < len; i++) {
+                                               putc(buf[i], param);
+                                       }
+                               }
 #else
-               (*putc)(c, param);
+                               putc(c, param);
 #endif
-                res++;
-            }
-            if (pad_on_right) {
-                while (pad-- > 0) {
-                    (*putc)(' ', param);
-                    res++;
-                }
-            }
-        } else {
-            (*putc)(c, param);
-            res++;
-        }
-    }
-    return (res);
+                               res++;
+                       }
+                       if (pad_on_right) {
+                               while (pad-- > 0) {
+                                       putc(' ', param);
+                                       res++;
+                               }
+                       }
+               } else {
+                       putc(c, param);
+                       res++;
+               }
+       }
+       return res;
 }
 
 struct _sputc_info {
-    char *ptr;
-    int max, len;
+       char *ptr;
+       int max, len;
 };
 
-static void 
+static void
 _sputc(char c, void *param)
 {
-    struct _sputc_info *info = (struct _sputc_info *)param;
+       struct _sputc_info *info = (struct _sputc_info *)param;
 
-    if (info->len < info->max) {
-        *(info->ptr)++ = c;
-        *(info->ptr) = '\0';
-        info->len++;
-    }
+       if (info->len < info->max) {
+               *info->ptr++ = c;
+               *info->ptr = '\0';
+               info->len++;
+       }
 }
 
 int
 diag_sprintf(char *buf, const char *fmt, ...)
-{        
-    int ret;
-    va_list ap;
-    struct _sputc_info info;
-
-    va_start(ap, fmt);
-    info.ptr = buf;
-    info.max = 1024;  // Unlimited
-    info.len = 0;
-    ret = _vprintf(_sputc, (void *)&info, fmt, ap);
-    va_end(ap);
-    return (info.len);
+{
+       int ret;
+       va_list ap;
+       struct _sputc_info info;
+
+       va_start(ap, fmt);
+       info.ptr = buf;
+       info.max = 1024;  // Unlimited
+       info.len = 0;
+       ret = _vprintf(_sputc, &info, fmt, ap);
+       va_end(ap);
+       return info.len;
 }
 
 int
 diag_snprintf(char *buf, size_t len, const char *fmt, ...)
-{        
-    int ret;
-    va_list ap;
-    struct _sputc_info info;
-
-    va_start(ap, fmt);
-    info.ptr = buf;
-    info.len = 0;
-    info.max = len-1;
-    ret = _vprintf(_sputc, (void *)&info, fmt, ap);
-    va_end(ap);
-    return (info.len);
+{
+       int ret;
+       va_list ap;
+       struct _sputc_info info;
+
+       va_start(ap, fmt);
+       info.ptr = buf;
+       info.len = 0;
+       info.max = len-1;
+       ret = _vprintf(_sputc, &info, fmt, ap);
+       va_end(ap);
+       return info.len;
 }
 
-int 
+int
 diag_vsprintf(char *buf, const char *fmt, va_list ap)
 {
-    int ret;
-    struct _sputc_info info;
-
-    info.ptr = buf;
-    info.max = 1024;  // Unlimited
-    info.len = 0;
-    ret = _vprintf(_sputc, (void *)&info, fmt, ap);
-    return (info.len);
+       int ret;
+       struct _sputc_info info;
+
+       info.ptr = buf;
+       info.max = 1024;  // Unlimited
+       info.len = 0;
+       ret = _vprintf(_sputc, &info, fmt, ap);
+       return info.len;
 }
 
 int
 diag_printf(const char *fmt, ...)
 {
-    va_list ap;
-    int ret;
+       va_list ap;
+       int ret;
 
-    va_start(ap, fmt);
-    ret = _vprintf(_putc, (void *)0, fmt, ap);
-    va_end(ap);
-    return (ret);
+       va_start(ap, fmt);
+       ret = _vprintf(_putc, NULL, fmt, ap);
+       va_end(ap);
+       return ret;
 }
 
 int
 diag_vprintf(const char *fmt, va_list ap)
 {
-    int ret;
+       int ret;
 
-    ret = _vprintf(_putc, (void *)0, fmt, ap);
-    return (ret);
+       ret = _vprintf(_putc, NULL, fmt, ap);
+       return ret;
 }
 
 void
 diag_vdump_buf_with_offset(__printf_fun *pf,
-                           cyg_uint8     *p, 
-                           CYG_ADDRWORD   s, 
-                           cyg_uint8     *base)
+                                                  cyg_uint8    *p,
+                                                  CYG_ADDRWORD  s,
+                                                  cyg_uint8    *base)
 {
-    int i, c;
-    if ((CYG_ADDRWORD)s > (CYG_ADDRWORD)p) {
-        s = (CYG_ADDRWORD)s - (CYG_ADDRWORD)p;
-    }
-    while ((int)s > 0) {
-        if (base) {
-            (*pf)("%08X: ", (CYG_ADDRWORD)p - (CYG_ADDRWORD)base);
-        } else {
-            (*pf)("%08X: ", p);
-        }
-        for (i = 0;  i < 16;  i++) {
-            if (i < (int)s) {
-                (*pf)("%02X ", p[i] & 0xFF);
-            } else {
-                (*pf)("   ");
-            }
-           if (i == 7) (*pf)(" ");
-        }
-        (*pf)(" |");
-        for (i = 0;  i < 16;  i++) {
-            if (i < (int)s) {
-                c = p[i] & 0xFF;
-                if ((c < 0x20) || (c >= 0x7F)) c = '.';
-            } else {
-                c = ' ';
-            }
-            (*pf)("%c", c);
-        }
-        (*pf)("|\n");
-        s -= 16;
-        p += 16;
-    }
+       int i, c;
+
+       if ((CYG_ADDRWORD)s > (CYG_ADDRWORD)p) {
+               s = (CYG_ADDRWORD)s - (CYG_ADDRWORD)p;
+       }
+       while ((int)s > 0) {
+               if (base) {
+                       pf("%08X: ", (CYG_ADDRWORD)p - (CYG_ADDRWORD)base);
+               } else {
+                       pf("%08X: ", p);
+               }
+               for (i = 0;  i < 16;  i++) {
+                       if (i < (int)s) {
+                               pf("%02X ", p[i] & 0xFF);
+                       } else {
+                               pf("   ");
+                       }
+                       if (i == 7)
+                               pf(" ");
+               }
+               pf(" |");
+               for (i = 0;  i < 16;  i++) {
+                       if (i < (int)s) {
+                               c = p[i] & 0xFF;
+                               if ((c < 0x20) || (c >= 0x7F)) c = '.';
+                       } else {
+                               c = ' ';
+                       }
+                       pf("%c", c);
+               }
+               pf("|\n");
+               s -= 16;
+               p += 16;
+       }
 }
 
 void
-diag_dump_buf_with_offset(cyg_uint8     *p, 
-                          CYG_ADDRWORD   s, 
-                          cyg_uint8     *base)
+diag_dump_buf_with_offset(cyg_uint8            *p,
+                                                 CYG_ADDRWORD   s,
+                                                 cyg_uint8             *base)
 {
-    diag_vdump_buf_with_offset(diag_printf, p, s, base);
+       diag_vdump_buf_with_offset(diag_printf, p, s, base);
 }
 
 void
@@ -666,31 +672,32 @@ diag_dump_buf(void *p, CYG_ADDRWORD s)
 }
 
 void
-diag_dump_buf_with_offset_32bit(cyg_uint32   *p, 
-                               CYG_ADDRWORD  s, 
-                               cyg_uint32   *base)
+diag_dump_buf_with_offset_32bit(cyg_uint32   *p,
+                                                               CYG_ADDRWORD  s,
+                                                               cyg_uint32   *base)
 {
-    int i;
-    if ((CYG_ADDRWORD)s > (CYG_ADDRWORD)p) {
-        s = (CYG_ADDRWORD)s - (CYG_ADDRWORD)p;
-    }
-    while ((int)s > 0) {
-        if (base) {
-            diag_printf("%08X: ", (CYG_ADDRWORD)p - (CYG_ADDRWORD)base);
-        } else {
-            diag_printf("%08X: ", (CYG_ADDRWORD)p);
-        }
-        for (i = 0;  i < 4;  i++) {
-            if (i < (int)s/4) {
-                diag_printf("%08X ", p[i] );
-            } else {
-                diag_printf("         ");
-            }
-        }
-        diag_printf("\n");
-        s -= 16;
-        p += 4;
-    }
+       int i;
+
+       if ((CYG_ADDRWORD)s > (CYG_ADDRWORD)p) {
+               s = (CYG_ADDRWORD)s - (CYG_ADDRWORD)p;
+       }
+       while ((int)s > 0) {
+               if (base) {
+                       diag_printf("%08X: ", (CYG_ADDRWORD)p - (CYG_ADDRWORD)base);
+               } else {
+                       diag_printf("%08X: ", (CYG_ADDRWORD)p);
+               }
+               for (i = 0;  i < 4;  i++) {
+                       if (i < (int)s / 4) {
+                               diag_printf("%08X ", p[i]);
+                       } else {
+                               diag_printf("         ");
+                       }
+               }
+               diag_printf("\n");
+               s -= 16;
+               p += 4;
+       }
 }
 
 externC void
@@ -700,32 +707,32 @@ diag_dump_buf_32bit(void *p, CYG_ADDRWORD s)
 }
 
 void
-diag_dump_buf_with_offset_16bit(cyg_uint16   *p, 
-                               CYG_ADDRWORD  s, 
-                               cyg_uint16   *base)
+diag_dump_buf_with_offset_16bit(cyg_uint16   *p,
+                                                               CYG_ADDRWORD  s,
+                                                               cyg_uint16   *base)
 {
-    int i;
-    if ((CYG_ADDRWORD)s > (CYG_ADDRWORD)p) {
-        s = (CYG_ADDRWORD)s - (CYG_ADDRWORD)p;
-    }
-    while ((int)s > 0) {
-        if (base) {
-            diag_printf("%08X: ", (CYG_ADDRWORD)p - (CYG_ADDRWORD)base);
-        } else {
-            diag_printf("%08X: ", (CYG_ADDRWORD)p);
-        }
-        for (i = 0;  i < 8;  i++) {
-            if (i < (int)s/2) {
-             diag_printf("%04X ", p[i] );
-             if (i == 3) diag_printf(" ");
-            } else {
-             diag_printf("     ");
-            }
-        }
-        diag_printf("\n");
-        s -= 16;
-        p += 8;
-    }
+       int i;
+       if ((CYG_ADDRWORD)s > (CYG_ADDRWORD)p) {
+               s = (CYG_ADDRWORD)s - (CYG_ADDRWORD)p;
+       }
+       while ((int)s > 0) {
+               if (base) {
+                       diag_printf("%08X: ", (CYG_ADDRWORD)p - (CYG_ADDRWORD)base);
+               } else {
+                       diag_printf("%08X: ", (CYG_ADDRWORD)p);
+               }
+               for (i = 0;  i < 8;  i++) {
+                       if (i < (int)s / 2) {
+                               diag_printf("%04X ", p[i]);
+                               if (i == 3) diag_printf(" ");
+                       } else {
+                               diag_printf("     ");
+                       }
+               }
+               diag_printf("\n");
+               s -= 16;
+               p += 8;
+       }
 }
 
 externC void
index 8becb38..688aba1 100644 (file)
@@ -74,57 +74,57 @@ externC int flash_get_block_info(int *block_size, int *blocks);
 externC bool flash_code_overlaps(void *start, void *end);
 externC char *flash_errmsg(int err);
 
-#define FLASH_ERR_OK              0x00  // No error - operation complete
-#define FLASH_ERR_INVALID         0x01  // Invalid FLASH address
-#define FLASH_ERR_ERASE           0x02  // Error trying to erase
-#define FLASH_ERR_LOCK            0x03  // Error trying to lock/unlock
-#define FLASH_ERR_PROGRAM         0x04  // Error trying to program
-#define FLASH_ERR_PROTOCOL        0x05  // Generic error
-#define FLASH_ERR_PROTECT         0x06  // Device/region is write-protected
-#define FLASH_ERR_NOT_INIT        0x07  // FLASH info not yet initialized
-#define FLASH_ERR_HWR             0x08  // Hardware (configuration?) problem
-#define FLASH_ERR_ERASE_SUSPEND   0x09  // Device is in erase suspend mode
-#define FLASH_ERR_PROGRAM_SUSPEND 0x0a  // Device is in in program suspend mode
-#define FLASH_ERR_DRV_VERIFY      0x0b  // Driver failed to verify data
-#define FLASH_ERR_DRV_TIMEOUT     0x0c  // Driver timed out waiting for device
-#define FLASH_ERR_DRV_WRONG_PART  0x0d  // Driver does not support device
-#define FLASH_ERR_LOW_VOLTAGE     0x0e  // Not enough juice to complete job
+#define FLASH_ERR_OK                     0x00  // No error - operation complete
+#define FLASH_ERR_INVALID                0x01  // Invalid FLASH address
+#define FLASH_ERR_ERASE                          0x02  // Error trying to erase
+#define FLASH_ERR_LOCK                   0x03  // Error trying to lock/unlock
+#define FLASH_ERR_PROGRAM                0x04  // Error trying to program
+#define FLASH_ERR_PROTOCOL               0x05  // Generic error
+#define FLASH_ERR_PROTECT                0x06  // Device/region is write-protected
+#define FLASH_ERR_NOT_INIT               0x07  // FLASH info not yet initialized
+#define FLASH_ERR_HWR                    0x08  // Hardware (configuration?) problem
+#define FLASH_ERR_ERASE_SUSPEND          0x09  // Device is in erase suspend mode
+#define FLASH_ERR_PROGRAM_SUSPEND 0x0a // Device is in in program suspend mode
+#define FLASH_ERR_DRV_VERIFY     0x0b  // Driver failed to verify data
+#define FLASH_ERR_DRV_TIMEOUT    0x0c  // Driver timed out waiting for device
+#define FLASH_ERR_DRV_WRONG_PART  0x0d // Driver does not support device
+#define FLASH_ERR_LOW_VOLTAGE    0x0e  // Not enough juice to complete job
 
 #ifdef CYGPKG_IO_FLASH_BLOCK_DEVICE
 typedef struct {
-    CYG_ADDRESS offset;
-    int len;
-    int flasherr;
-    void **err_address;
+       CYG_ADDRESS offset;
+       int len;
+       int flasherr;
+       void **err_address;
 } cyg_io_flash_getconfig_erase_t;
 
 typedef struct {
-    int dev_size;
+       int dev_size;
 } cyg_io_flash_getconfig_devsize_t;
 
 typedef struct {
-    CYG_ADDRESS offset;
-    int block_size;
+       CYG_ADDRESS offset;
+       int block_size;
 } cyg_io_flash_getconfig_blocksize_t;
 #endif
 
 #ifdef _FLASH_PRIVATE_
 
 struct flash_info {
-    int   block_size;   // Assuming fixed size "blocks"
-    int   blocks;       // Number of blocks
-    int   buffer_size;  // Size of write buffer (only defined for some devices)
-    unsigned long block_mask;
-    void *start, *end;  // Address range
-    int   init;
-    _printf *pf;
+       int   block_size;   // Assuming fixed size "blocks"
+       int   blocks;       // Number of blocks
+       int   buffer_size;  // Size of write buffer (only defined for some devices)
+       unsigned long block_mask;
+       void *start, *end;  // Address range
+       int   init;
+       _printf *pf;
 };
 
 externC struct flash_info flash_info;
 externC int  flash_hwr_init(void);
 externC int  flash_hwr_map_error(int err);
 
-// 
+//
 // Some FLASH devices may require additional support, e.g. to turn on
 // appropriate voltage drivers, before any operation.
 //
index 59725c5..aee6b86 100644 (file)
 // Author(s):    gthomas
 // Contributors: gthomas
 // Date:         2000-07-26
-// Purpose:      
-// Description:  
-//              
+// Purpose:
+// Description:
+//
 //####DESCRIPTIONEND####
 //
 //==========================================================================
-
 #include <pkgconf/system.h>
 #include <pkgconf/io_flash.h>
 
@@ -85,17 +84,17 @@ externC code_fun flash_unlock_block;
 int
 flash_init(_printf *pf)
 {
-    int err;
+       int err;
 
-    flash_info.pf = pf; // Do this before calling into the driver
-    if (flash_info.init) return FLASH_ERR_OK;
+       flash_info.pf = pf; // Do this before calling into the driver
+       if (flash_info.init) return FLASH_ERR_OK;
 
-    if ((err = flash_hwr_init()) != FLASH_ERR_OK) {
-        return err;
-    }
-    flash_info.block_mask = ~(flash_info.block_size-1);
-    flash_info.init = 1;
-    return FLASH_ERR_OK;
+       if ((err = flash_hwr_init()) != FLASH_ERR_OK) {
+               return err;
+       }
+       flash_info.block_mask = ~(flash_info.block_size - 1);
+       flash_info.init = 1;
+       return FLASH_ERR_OK;
 }
 
 // Use this function to make function pointers anonymous - forcing the
@@ -112,286 +111,285 @@ static void *__anonymizer(void *p)
 void
 flash_dev_query(void *data)
 {
-    typedef void code_fun(void *);
-    code_fun *_flash_query;
-    int d_cache, i_cache;
+       typedef void code_fun(void *);
+       code_fun *_flash_query;
+       int d_cache, i_cache;
 
-    _flash_query = (code_fun*)__anonymizer(&flash_query);
+       _flash_query = (code_fun*)__anonymizer(&flash_query);
 
-    HAL_FLASH_CACHES_OFF(d_cache, i_cache);
-    (*_flash_query)(data);
-    HAL_FLASH_CACHES_ON(d_cache, i_cache);
+       HAL_FLASH_CACHES_OFF(d_cache, i_cache);
+       (*_flash_query)(data);
+       HAL_FLASH_CACHES_ON(d_cache, i_cache);
 }
 
 int
 flash_verify_addr(void *target)
 {
-    if (!flash_info.init) {
-        return FLASH_ERR_NOT_INIT;
-    }
-    if (((CYG_ADDRESS)target >= (CYG_ADDRESS)flash_info.start) &&
-        ((CYG_ADDRESS)target <= ((CYG_ADDRESS)flash_info.end - 1))) {
-        return FLASH_ERR_OK;
-    } else {
-        return FLASH_ERR_INVALID;
-    }
+       if (!flash_info.init) {
+               return FLASH_ERR_NOT_INIT;
+       }
+       if (((CYG_ADDRESS)target >= (CYG_ADDRESS)flash_info.start) &&
+               ((CYG_ADDRESS)target <= ((CYG_ADDRESS)flash_info.end - 1))) {
+               return FLASH_ERR_OK;
+       } else {
+               return FLASH_ERR_INVALID;
+       }
 }
 
 int
 flash_get_limits(void *target, void **start, void **end)
 {
-    if (!flash_info.init) {
-        return FLASH_ERR_NOT_INIT;
-    }
-    *start = flash_info.start;
-    *end = flash_info.end;
-    return FLASH_ERR_OK;
+       if (!flash_info.init) {
+               return FLASH_ERR_NOT_INIT;
+       }
+       *start = flash_info.start;
+       *end = flash_info.end;
+       return FLASH_ERR_OK;
 }
 
 int
 flash_get_block_info(int *block_size, int *blocks)
 {
-    if (!flash_info.init) {
-        return FLASH_ERR_NOT_INIT;
-    }
-    *block_size = flash_info.block_size;
-    *blocks = flash_info.blocks;
-    return FLASH_ERR_OK;
+       if (!flash_info.init) {
+               return FLASH_ERR_NOT_INIT;
+       }
+       *block_size = flash_info.block_size;
+       *blocks = flash_info.blocks;
+       return FLASH_ERR_OK;
 }
 
 int
 flash_erase(void *addr, int len, void **err_addr)
 {
-    unsigned short *block, *end_addr;
-    int stat = 0;
-    typedef int code_fun(unsigned short *, unsigned int);
-    code_fun *_flash_erase_block;
-    int d_cache, i_cache;
+       unsigned short *block, *end_addr;
+       int stat = 0;
+       typedef int code_fun(unsigned short *, unsigned int);
+       code_fun *_flash_erase_block;
+       int d_cache, i_cache;
 
-    if (!flash_info.init) {
-        return FLASH_ERR_NOT_INIT;
-    }
+       if (!flash_info.init) {
+               return FLASH_ERR_NOT_INIT;
+       }
 
 #ifdef CYGSEM_IO_FLASH_SOFT_WRITE_PROTECT
-    if (plf_flash_query_soft_wp(addr,len))
-        return FLASH_ERR_PROTECT;
+       if (plf_flash_query_soft_wp(addr,len))
+               return FLASH_ERR_PROTECT;
 #endif
 
-     _flash_erase_block = (code_fun*)__anonymizer(&flash_erase_block);
+       _flash_erase_block = (code_fun*)__anonymizer(&flash_erase_block);
 
-    block = (unsigned short *)((CYG_ADDRESS)addr & flash_info.block_mask);
-    end_addr = (unsigned short *)((CYG_ADDRESS)addr + len);
+       block = (unsigned short *)((CYG_ADDRESS)addr & flash_info.block_mask);
+       end_addr = (unsigned short *)((CYG_ADDRESS)addr + len);
 
-    /* Check to see if end_addr overflowed */
-    if ((end_addr < block) && (len > 0)) {
-        end_addr = (unsigned short *)((CYG_ADDRESS)flash_info.end - 1);
-    }
+       /* Check to see if end_addr overflowed */
+       if ((end_addr < block) && (len > 0)) {
+               end_addr = (unsigned short *)((CYG_ADDRESS)flash_info.end);
+       }
 
 #ifdef CYGSEM_IO_FLASH_CHATTER
-    flash_info.pf("... Erase from %p-%p: ", block, end_addr);
+       flash_info.pf("... Erase from %p-%p: ", block, end_addr);
 #endif
 
-    HAL_FLASH_CACHES_OFF(d_cache, i_cache);
-    FLASH_Enable(block, end_addr);
-    while (block < end_addr) {
-        // Supply the blocksize for a gross check for erase success
-        unsigned short *tmp_block;
+       HAL_FLASH_CACHES_OFF(d_cache, i_cache);
+       FLASH_Enable(block, end_addr);
+       while (block < end_addr) {
+               // Supply the blocksize for a gross check for erase success
+               unsigned short *tmp_block;
 #if !defined(CYGSEM_IO_FLASH_READ_INDIRECT)
-        int i;
-        unsigned char *dp;
-        bool erased = true;
-
-        dp = (unsigned char *)block;
-        for (i = 0;  i < flash_info.block_size;  i++) {
-            if (*dp++ != 0xFF) {
-                erased = false;
-                break;
-            }
-        }
+               int i;
+               unsigned char *dp;
+               bool erased = true;
+
+               dp = (unsigned char *)block;
+               for (i = 0; i < flash_info.block_size; i++) {
+                       if (*dp++ != 0xFF) {
+                               erased = false;
+                               break;
+                       }
+               }
 #else
-        bool erased = false;
+               bool erased = false;
 #endif
 
-        if (!erased) {
-            stat = (*_flash_erase_block)(block, flash_info.block_size);
-            stat = flash_hwr_map_error(stat);
-        }
-        if (stat) {
-            *err_addr = block;
-            break;
-        }
-
-        // Check to see if block will overflow
-        tmp_block = block + flash_info.block_size / sizeof(*block);
-        if (tmp_block < block) {
-            // If block address overflows, set block value to end on this loop
-            block = end_addr;
-        } else {
-            block = tmp_block;
-        }
+               if (!erased) {
+                       stat = (*_flash_erase_block)(block, flash_info.block_size);
+                       stat = flash_hwr_map_error(stat);
+               }
+               if (stat) {
+                       *err_addr = block;
+                       break;
+               }
+
+               // Check to see if block will overflow
+               tmp_block = block + flash_info.block_size / sizeof(*block);
+               if (tmp_block < block) {
+                       // If block address overflows, set block value to end on this loop
+                       block = end_addr;
+               } else {
+                       block = tmp_block;
+               }
 #ifdef CYGSEM_IO_FLASH_CHATTER
-        flash_info.pf(".");
+               flash_info.pf(".");
 #endif
-    }
-    FLASH_Disable((void *)((CYG_ADDRESS)addr & flash_info.block_mask),
-                                 end_addr);
-    HAL_FLASH_CACHES_ON(d_cache, i_cache);
+       }
+       FLASH_Disable((void *)((CYG_ADDRESS)addr & flash_info.block_mask),
+                               end_addr);
+       HAL_FLASH_CACHES_ON(d_cache, i_cache);
 #ifdef CYGSEM_IO_FLASH_CHATTER
-    flash_info.pf("\n");
+       flash_info.pf("\n");
 #endif
-    return stat;
+       return stat;
 }
 
 int
 flash_program(void *_addr, void *_data, int len, void **err_addr)
 {
-    int stat = 0;
-    int size;
-    typedef int code_fun(void *, void *, int, unsigned long, int);
-    code_fun *_flash_program_buf;
-    unsigned char *addr = _addr;
-    unsigned char *data = _data;
-    CYG_ADDRESS tmp;
-    int d_cache, i_cache;
-
-    if (!flash_info.init) {
-        return FLASH_ERR_NOT_INIT;
-    }
+       int stat = 0;
+       int size;
+       typedef int code_fun(void *, void *, int, unsigned long, int);
+       code_fun *_flash_program_buf;
+       unsigned char *addr = _addr;
+       unsigned char *data = _data;
+       CYG_ADDRESS tmp;
+       int d_cache, i_cache;
+
+       if (!flash_info.init) {
+               return FLASH_ERR_NOT_INIT;
+       }
 
 #ifdef CYGSEM_IO_FLASH_SOFT_WRITE_PROTECT
-    if (plf_flash_query_soft_wp(addr,len))
-        return FLASH_ERR_PROTECT;
+       if (plf_flash_query_soft_wp(addr,len))
+               return FLASH_ERR_PROTECT;
 #endif
 
-    _flash_program_buf = (code_fun*)__anonymizer(&flash_program_buf);
+       _flash_program_buf = (code_fun*)__anonymizer(&flash_program_buf);
 
 #ifdef CYGSEM_IO_FLASH_CHATTER
-    flash_info.pf("... Program from %p-%p at %p: ", data, 
-                     (void *)((CYG_ADDRESS)data + len), addr);
+       flash_info.pf("... Program from %p-%p at %p: ", data,
+                               (void *)((CYG_ADDRESS)data + len), addr);
 #endif
 
-    HAL_FLASH_CACHES_OFF(d_cache, i_cache);
-    FLASH_Enable(addr, addr + len);
-    while (len > 0) {
-        size = len;
+       HAL_FLASH_CACHES_OFF(d_cache, i_cache);
+       FLASH_Enable(addr, addr + len);
+       while (len > 0) {
+               size = len;
 #if defined(MXCFLASH_SELECT_NAND) || defined(MXCFLASH_SELECT_MMC)
-        if (flash_info.start != 0)
+               if (flash_info.start != 0)
 #endif
-        if (size > flash_info.block_size) size = flash_info.block_size;
+                       if (size > flash_info.block_size) size = flash_info.block_size;
 
-        tmp = (CYG_ADDRESS)addr & ~flash_info.block_mask;
-        if (tmp) {
-                tmp = flash_info.block_size - tmp;
-                if (size > tmp) size = tmp;
-        }
+               tmp = (CYG_ADDRESS)addr & ~flash_info.block_mask;
+               if (tmp) {
+                       tmp = flash_info.block_size - tmp;
+                       if (size > tmp) size = tmp;
+               }
 
-        stat = (*_flash_program_buf)(addr, data, size, 
-                                     flash_info.block_mask, flash_info.buffer_size);
-        stat = flash_hwr_map_error(stat);
+               stat = (*_flash_program_buf)(addr, data, size,
+                                                                       flash_info.block_mask, flash_info.buffer_size);
+               stat = flash_hwr_map_error(stat);
 #ifdef CYGSEM_IO_FLASH_VERIFY_PROGRAM
-        if (0 == stat) // Claims to be OK
-            if (memcmp(addr, data, size) != 0) {                
-                stat = 0x0BAD;
+               if (0 == stat) // Claims to be OK
+                       if (memcmp(addr, data, size) != 0) {
+                               stat = 0x0BAD;
 #ifdef CYGSEM_IO_FLASH_CHATTER
-                flash_info.pf("V");
+                               flash_info.pf("V");
 #endif
-            }
+                       }
 #endif
-        if (stat) {
-            *err_addr = addr;
-            break;
-        }
+               if (stat) {
+                       *err_addr = addr;
+                       break;
+               }
 #ifdef CYGSEM_IO_FLASH_CHATTER
-        flash_info.pf(".");
+               flash_info.pf(".");
 #endif
-        len -= size;
-        addr += size / sizeof(*addr);
-        data += size / sizeof(*data);
-    }
-    FLASH_Disable(_addr, addr + len);
-    HAL_FLASH_CACHES_ON(d_cache, i_cache);
+               len -= size;
+               addr += size / sizeof(*addr);
+               data += size / sizeof(*data);
+       }
+       FLASH_Disable(_addr, addr + len);
+       HAL_FLASH_CACHES_ON(d_cache, i_cache);
 #ifdef CYGSEM_IO_FLASH_CHATTER
-    flash_info.pf("\n");
+       flash_info.pf("\n");
 #endif
-    return stat;
+       return stat;
 }
 
 int
 flash_read(void *_addr, void *_data, int len, void **err_addr)
 {
 #ifdef CYGSEM_IO_FLASH_READ_INDIRECT
-    int stat = 0;
-    int size;
-    typedef int code_fun(void *, void *, int, unsigned long, int);
-    code_fun *_flash_read_buf;
-    unsigned char *addr = _addr;
-    unsigned char *data = _data;
-    CYG_ADDRESS tmp;
-    int d_cache, i_cache;
+       int stat = 0;
+       int size;
+       typedef int code_fun(void *, void *, int, unsigned long, int);
+       code_fun *_flash_read_buf;
+       unsigned char *addr = _addr;
+       unsigned char *data = _data;
+       CYG_ADDRESS tmp;
+       int d_cache, i_cache;
 
-    if (!flash_info.init) {
-        return FLASH_ERR_NOT_INIT;
-    }
+       if (!flash_info.init) {
+               return FLASH_ERR_NOT_INIT;
+       }
 
-    _flash_read_buf = (code_fun*)__anonymizer(&flash_read_buf);
+       _flash_read_buf = (code_fun*)__anonymizer(&flash_read_buf);
 
 #ifdef CYGSEM_IO_FLASH_CHATTER_VERBOSE
-    flash_info.pf("... Read from %p-%p at %p: ", data, 
-                     (void *)((CYG_ADDRESS)data + len), addr);
+       flash_info.pf("... Read from %p-%p at %p: ", data,
+                               (void *)((CYG_ADDRESS)data + len), addr);
 #endif
 
-    HAL_FLASH_CACHES_OFF(d_cache, i_cache);
-    FLASH_Enable(addr, addr + len);
-    while (len > 0) {
-        size = len;
+       HAL_FLASH_CACHES_OFF(d_cache, i_cache);
+       FLASH_Enable(addr, addr + len);
+       while (len > 0) {
+               size = len;
 #if defined(MXCFLASH_SELECT_NAND) || defined(MXCFLASH_SELECT_MMC)
-        if (flash_info.start !=0)
+               if (flash_info.start != 0)
 #endif
-        if (size > flash_info.block_size) size = flash_info.block_size;
+               if (size > flash_info.block_size) size = flash_info.block_size;
 
-        tmp = (CYG_ADDRESS)addr & ~flash_info.block_mask;
-        if (tmp) {
-                tmp = flash_info.block_size - tmp;
-                if (size>tmp) size = tmp;
-
-        }
+               tmp = (CYG_ADDRESS)addr & ~flash_info.block_mask;
+               if (tmp) {
+                       tmp = flash_info.block_size - tmp;
+                       if (size>tmp) size = tmp;
+               }
 
-        stat = (*_flash_read_buf)(addr, data, size, 
-                                     flash_info.block_mask, flash_info.buffer_size);
-        stat = flash_hwr_map_error(stat);
+               stat = (*_flash_read_buf)(addr, data, size,
+                                                               flash_info.block_mask, flash_info.buffer_size);
+               stat = flash_hwr_map_error(stat);
 #ifdef CYGSEM_IO_FLASH_VERIFY_PROGRAM
-        if (0 == stat) // Claims to be OK
-            if (memcmp(addr, data, size) != 0) {                
-                stat = 0x0BAD;
+               if (0 == stat) // Claims to be OK
+                       if (memcmp(addr, data, size) != 0) {
+                               stat = 0x0BAD;
 #ifdef CYGSEM_IO_FLASH_CHATTER_VERBOSE
-                flash_info.pf("V");
+                               flash_info.pf("V");
 #endif
-            }
+                       }
 #endif
-        if (stat) {
-            *err_addr = addr;
-            break;
-        }
+               if (stat) {
+                       *err_addr = addr;
+                       break;
+               }
 #ifdef CYGSEM_IO_FLASH_CHATTER_VERBOSE
-        flash_info.pf(".");
+               flash_info.pf(".");
 #endif
-        len -= size;
-        addr += size / sizeof(*addr);
-        data += size / sizeof(*data);
-    }
-    FLASH_Disable(_addr, addr + len);
-    HAL_FLASH_CACHES_ON(d_cache, i_cache);
+               len -= size;
+               addr += size / sizeof(*addr);
+               data += size / sizeof(*data);
+       }
+       FLASH_Disable(_addr, addr + len);
+       HAL_FLASH_CACHES_ON(d_cache, i_cache);
 #ifdef CYGSEM_IO_FLASH_CHATTER_VERBOSE
-    flash_info.pf("\n");
+       flash_info.pf("\n");
 #endif
-    return stat;
+       return stat;
 #else // CYGSEM_IO_FLASH_READ_INDIRECT
-    // Direct access to FLASH memory is possible - just move the requested bytes
-    if (!flash_info.init) {
-        return FLASH_ERR_NOT_INIT;
-    }
-    memcpy(_data, _addr, len);
-    return FLASH_ERR_OK;
+       // Direct access to FLASH memory is possible - just move the requested bytes
+       if (!flash_info.init) {
+               return FLASH_ERR_NOT_INIT;
+       }
+       memcpy(_data, _addr, len);
+       return FLASH_ERR_OK;
 #endif
 }
 
@@ -400,65 +398,65 @@ flash_read(void *_addr, void *_data, int len, void **err_addr)
 int
 flash_lock(void *addr, int len, void **err_addr)
 {
-    unsigned short *block, *end_addr;
-    int stat = 0;
-    typedef int code_fun(unsigned short *);
-    code_fun *_flash_lock_block;
-    int d_cache, i_cache;
+       unsigned short *block, *end_addr;
+       int stat = 0;
+       typedef int code_fun(unsigned short *);
+       code_fun *_flash_lock_block;
+       int d_cache, i_cache;
 
-    if (!flash_info.init) {
-        return FLASH_ERR_NOT_INIT;
-    }
+       if (!flash_info.init) {
+               return FLASH_ERR_NOT_INIT;
+       }
 
 #ifdef CYGSEM_IO_FLASH_SOFT_WRITE_PROTECT
-    if (plf_flash_query_soft_wp(addr,len))
-        return FLASH_ERR_PROTECT;
+       if (plf_flash_query_soft_wp(addr,len))
+               return FLASH_ERR_PROTECT;
 #endif
 
-    _flash_lock_block = (code_fun*)__anonymizer(&flash_lock_block);
+       _flash_lock_block = (code_fun*)__anonymizer(&flash_lock_block);
 
-    block = (unsigned short *)((CYG_ADDRESS)addr & flash_info.block_mask);
-    end_addr = (unsigned short *)((CYG_ADDRESS)addr + len);
+       block = (unsigned short *)((CYG_ADDRESS)addr & flash_info.block_mask);
+       end_addr = (unsigned short *)((CYG_ADDRESS)addr + len);
 
-    /* Check to see if end_addr overflowed */
-    if ((end_addr < block) && (len > 0)) {
-        end_addr = (unsigned short *)((CYG_ADDRESS)flash_info.end - 1);
-    }
+       /* Check to see if end_addr overflowed */
+       if ((end_addr < block) && (len > 0)) {
+               end_addr = (unsigned short *)((CYG_ADDRESS)flash_info.end - 1);
+       }
 
 #ifdef CYGSEM_IO_FLASH_CHATTER
-    flash_info.pf("... Lock from %p-%p: ", block, end_addr);
+       flash_info.pf("... Lock from %p-%p: ", block, end_addr);
 #endif
 
-    HAL_FLASH_CACHES_OFF(d_cache, i_cache);
-    FLASH_Enable(block, end_addr);
-    while (block < end_addr) {
-        unsigned short *tmp_block;
-        stat = (*_flash_lock_block)(block);
-        stat = flash_hwr_map_error(stat);
-        if (stat) {
-            *err_addr = block;
-            break;
-        }
-
-        // Check to see if block will overflow
-        tmp_block = block + flash_info.block_size / sizeof(*block);
-        if (tmp_block < block) {
-            // If block address overflows, set block value to end on this loop
-            block = end_addr;
-        } else {
-            block = tmp_block;
-        }
+       HAL_FLASH_CACHES_OFF(d_cache, i_cache);
+       FLASH_Enable(block, end_addr);
+       while (block < end_addr) {
+               unsigned short *tmp_block;
+               stat = (*_flash_lock_block)(block);
+               stat = flash_hwr_map_error(stat);
+               if (stat) {
+                       *err_addr = block;
+                       break;
+               }
+
+               // Check to see if block will overflow
+               tmp_block = block + flash_info.block_size / sizeof(*block);
+               if (tmp_block < block) {
+                       // If block address overflows, set block value to end on this loop
+                       block = end_addr;
+               } else {
+                       block = tmp_block;
+               }
 #ifdef CYGSEM_IO_FLASH_CHATTER
-        flash_info.pf(".");
+               flash_info.pf(".");
 #endif
-    }
-    FLASH_Disable((void *)((CYG_ADDRESS)addr & flash_info.block_mask),
-                                 end_addr);
-    HAL_FLASH_CACHES_ON(d_cache, i_cache);
+       }
+       FLASH_Disable((void *)((CYG_ADDRESS)addr & flash_info.block_mask),
+                               end_addr);
+       HAL_FLASH_CACHES_ON(d_cache, i_cache);
 #ifdef CYGSEM_IO_FLASH_CHATTER
-    flash_info.pf("\n");
+       flash_info.pf("\n");
 #endif
-    return stat;
+       return stat;
 }
 
 int
@@ -528,38 +526,38 @@ flash_unlock(void *addr, int len, void **err_addr)
 char *
 flash_errmsg(int err)
 {
-    switch (err) {
-    case FLASH_ERR_OK:
-        return "No error - operation complete";
-    case FLASH_ERR_ERASE_SUSPEND:
-        return "Device is in erase suspend state";
-    case FLASH_ERR_PROGRAM_SUSPEND:
-        return "Device is in program suspend state";
-    case FLASH_ERR_INVALID:
-        return "Invalid FLASH address";
-    case FLASH_ERR_ERASE:
-        return "Error trying to erase";
-    case FLASH_ERR_LOCK:
-        return "Error trying to lock/unlock";
-    case FLASH_ERR_PROGRAM:
-        return "Error trying to program";
-    case FLASH_ERR_PROTOCOL:
-        return "Generic error";
-    case FLASH_ERR_PROTECT:
-        return "Device/region is write-protected";
-    case FLASH_ERR_NOT_INIT:
-        return "FLASH sub-system not initialized";
-    case FLASH_ERR_DRV_VERIFY:
-        return "Data verify failed after operation";
-    case FLASH_ERR_DRV_TIMEOUT:
-        return "Driver timed out waiting for device";
-    case FLASH_ERR_DRV_WRONG_PART:
-        return "Driver does not support device";
-    case FLASH_ERR_LOW_VOLTAGE:
-        return "Device reports low voltage";
-    default:
-        return "Unknown error";
-    }
+       switch (err) {
+       case FLASH_ERR_OK:
+               return "No error - operation complete";
+       case FLASH_ERR_ERASE_SUSPEND:
+               return "Device is in erase suspend state";
+       case FLASH_ERR_PROGRAM_SUSPEND:
+               return "Device is in program suspend state";
+       case FLASH_ERR_INVALID:
+               return "Invalid FLASH address";
+       case FLASH_ERR_ERASE:
+               return "Error trying to erase";
+       case FLASH_ERR_LOCK:
+               return "Error trying to lock/unlock";
+       case FLASH_ERR_PROGRAM:
+               return "Error trying to program";
+       case FLASH_ERR_PROTOCOL:
+               return "Generic error";
+       case FLASH_ERR_PROTECT:
+               return "Device/region is write-protected";
+       case FLASH_ERR_NOT_INIT:
+               return "FLASH sub-system not initialized";
+       case FLASH_ERR_DRV_VERIFY:
+               return "Data verify failed after operation";
+       case FLASH_ERR_DRV_TIMEOUT:
+               return "Driver timed out waiting for device";
+       case FLASH_ERR_DRV_WRONG_PART:
+               return "Driver does not support device";
+       case FLASH_ERR_LOW_VOLTAGE:
+               return "Device reports low voltage";
+       default:
+               return "Unknown error";
+       }
 }
 
 // EOF io/flash/..../flash.c
index 775710d..c7488a5 100644 (file)
@@ -44,9 +44,9 @@
 // Author(s):    gthomas
 // Contributors: gthomas,hmt,jlarmour
 // Date:         2000-07-14
-// Purpose:      
-// Description:  
-//              
+// Purpose:
+// Description:
+//
 // This code is part of RedBoot (tm).
 //
 //####DESCRIPTIONEND####
@@ -64,100 +64,100 @@ static void
 do_channel(int argc, char *argv[]);
 
 #ifdef CYGPKG_REDBOOT_ANY_CONSOLE
-RedBoot_cmd("channel", 
-            "Display/switch console channel", 
-            "[-1|<channel number>]",
-            do_channel
-    );
+RedBoot_cmd("channel",
+                       "Display/switch console channel",
+                       "[-1|<channel number>]",
+                       do_channel
+       );
 #else
-RedBoot_cmd("channel", 
-            "Display/switch console channel", 
-            "[<channel number>]",
-            do_channel
-    );
+RedBoot_cmd("channel",
+                       "Display/switch console channel",
+                       "[<channel number>]",
+                       do_channel
+       );
 #endif
 
 static void
 do_channel(int argc, char *argv[])
 {
-    int cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
+       int cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
 
-    if (argc == 2) { 
+       if (argc == 2) {
 #ifdef CYGPKG_REDBOOT_ANY_CONSOLE
-        if (strcmp( argv[1], "-1") == 0) {
-            console_selected = false;
-            console_echo = true;
-        } else 
+               if (strcmp( argv[1], "-1") == 0) {
+                       console_selected = false;
+                       console_echo = true;
+               } else
 #endif
-        {
-            unsigned long chan;
-            if ( !parse_num( argv[1], &chan, NULL, NULL) ) {
-                diag_printf("** Error: invalid channel '%s'\n", argv[1]);
-            } else {
-                if (chan < CYGNUM_HAL_VIRTUAL_VECTOR_NUM_CHANNELS) {
-                    CYGACC_CALL_IF_SET_CONSOLE_COMM(chan);
-                    CYGACC_CALL_IF_SET_DEBUG_COMM(chan);
-                    if (chan != cur)
-                        console_echo = true;
-                }
-                else {
-                    diag_printf("**Error: bad channel number '%s'\n", argv[1]);
-                }
-            }
-        }
-    }
-    /* else display */ 
-    else {
-        diag_printf("Current console channel id: ");
+               {
+                       unsigned long chan;
+                       if ( !parse_num( argv[1], &chan, NULL, NULL) ) {
+                               diag_printf("** Error: invalid channel '%s'\n", argv[1]);
+                       } else {
+                               if (chan < CYGNUM_HAL_VIRTUAL_VECTOR_NUM_CHANNELS) {
+                                       CYGACC_CALL_IF_SET_CONSOLE_COMM(chan);
+                                       CYGACC_CALL_IF_SET_DEBUG_COMM(chan);
+                                       if (chan != cur)
+                                               console_echo = true;
+                               }
+                               else {
+                                       diag_printf("**Error: bad channel number '%s'\n", argv[1]);
+                               }
+                       }
+               }
+       }
+       /* else display */
+       else {
+               diag_printf("Current console channel id: ");
 #ifdef CYGPKG_REDBOOT_ANY_CONSOLE
-        if (!console_selected)
-            diag_printf("-1\n");
-        else
+               if (!console_selected)
+                       diag_printf("-1\n");
+               else
 #endif
-            diag_printf("%d\n", cur);
-    }
+                       diag_printf("%d\n", cur);
+       }
 }
 
-void 
+void
 mon_write_char(char c)
 {
-    hal_virtual_comm_table_t *__chan;
+       hal_virtual_comm_table_t *__chan;
 
 #ifdef CYGPKG_REDBOOT_ANY_CONSOLE
-    if (!console_selected) {
-        int cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
-        int i;
-        // Send output to all channels
-        for (i = 0;  i < CYGNUM_HAL_VIRTUAL_VECTOR_COMM_CHANNELS;  i++) {
-            CYGACC_CALL_IF_SET_CONSOLE_COMM(i);
-            __chan = CYGACC_CALL_IF_CONSOLE_PROCS();
-            CYGACC_COMM_IF_PUTC(*__chan, c);
-        }
-        CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
-    } else 
+       if (!console_selected) {
+               int cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
+               int i;
+               // Send output to all channels
+               for (i = 0;  i < CYGNUM_HAL_VIRTUAL_VECTOR_COMM_CHANNELS;  i++) {
+                       CYGACC_CALL_IF_SET_CONSOLE_COMM(i);
+                       __chan = CYGACC_CALL_IF_CONSOLE_PROCS();
+                       CYGACC_COMM_IF_PUTC(*__chan, c);
+               }
+               CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
+       } else
 #endif
-    {
-        __chan = CYGACC_CALL_IF_CONSOLE_PROCS();
-        if (__chan)
-            CYGACC_COMM_IF_PUTC(*__chan, c);
-        else {
-            __chan = CYGACC_CALL_IF_DEBUG_PROCS();
-            CYGACC_COMM_IF_PUTC(*__chan, c);
-        }
-    }
+       {
+               __chan = CYGACC_CALL_IF_CONSOLE_PROCS();
+               if (__chan)
+                       CYGACC_COMM_IF_PUTC(*__chan, c);
+               else {
+                       __chan = CYGACC_CALL_IF_DEBUG_PROCS();
+                       CYGACC_COMM_IF_PUTC(*__chan, c);
+               }
+       }
 }
 
-static void 
+static void
 mon_read_char(char *c)
 {
-    hal_virtual_comm_table_t* __chan = CYGACC_CALL_IF_CONSOLE_PROCS();
-    
-    if (__chan)
-        *c = CYGACC_COMM_IF_GETC(*__chan);
-    else {
-        __chan = CYGACC_CALL_IF_DEBUG_PROCS();
-        *c = CYGACC_COMM_IF_GETC(*__chan);
-    }
+       hal_virtual_comm_table_t *__chan = CYGACC_CALL_IF_CONSOLE_PROCS();
+
+       if (__chan)
+               *c = CYGACC_COMM_IF_GETC(*__chan);
+       else {
+               __chan = CYGACC_CALL_IF_DEBUG_PROCS();
+               *c = CYGACC_COMM_IF_GETC(*__chan);
+       }
 }
 
 #ifdef CYGPKG_REDBOOT_ANY_CONSOLE
@@ -167,84 +167,84 @@ static int _mon_timeout;
 bool
 mon_read_char_with_timeout(char *c)
 {
-    bool res = false;
-    hal_virtual_comm_table_t *__chan;
+       bool res = false;
+       hal_virtual_comm_table_t *__chan;
 
 #ifdef CYGPKG_REDBOOT_ANY_CONSOLE
-    if (!console_selected) {
-        int cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
-        int i, j, tot;
-        // Try input from all channels
-        tot = 0;
-        while (tot < _mon_timeout) {
-            for (i = 0;  i < CYGNUM_HAL_VIRTUAL_VECTOR_COMM_CHANNELS;  i++, tot++) {
-                CYGACC_CALL_IF_SET_CONSOLE_COMM(i);
-                __chan = CYGACC_CALL_IF_CONSOLE_PROCS();
-                res = CYGACC_COMM_IF_GETC_TIMEOUT(*__chan, c);
-                if (res) {
-                    // Input available on this channel, make it be the console
-                    if (*c != '\0') {
-                        // Don't chose this unless real data have arrived
-                        console_selected = true;
-                        CYGACC_CALL_IF_SET_DEBUG_COMM(i);
-                        // Disable interrupts on all channels but this one
-                        for (j = 0;  j < CYGNUM_HAL_VIRTUAL_VECTOR_COMM_CHANNELS;  j++) {
-                            if (i != j) {
-                                CYGACC_CALL_IF_SET_CONSOLE_COMM(j);
-                                __chan = CYGACC_CALL_IF_CONSOLE_PROCS();
-                                CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_IRQ_DISABLE);
-                            }
-                        }
-                        CYGACC_CALL_IF_SET_CONSOLE_COMM(i);
-                        return res;
-                    }
-                }
-            }
-        }
-        CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);        
-    } else 
+       if (!console_selected) {
+               int cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
+               int i, j, tot;
+               // Try input from all channels
+               tot = 0;
+               while (tot < _mon_timeout) {
+                       for (i = 0;  i < CYGNUM_HAL_VIRTUAL_VECTOR_COMM_CHANNELS;  i++, tot++) {
+                               CYGACC_CALL_IF_SET_CONSOLE_COMM(i);
+                               __chan = CYGACC_CALL_IF_CONSOLE_PROCS();
+                               res = CYGACC_COMM_IF_GETC_TIMEOUT(*__chan, c);
+                               if (res) {
+                                       // Input available on this channel, make it be the console
+                                       if (*c != '\0') {
+                                               // Don't chose this unless real data have arrived
+                                               console_selected = true;
+                                               CYGACC_CALL_IF_SET_DEBUG_COMM(i);
+                                               // Disable interrupts on all channels but this one
+                                               for (j = 0;  j < CYGNUM_HAL_VIRTUAL_VECTOR_COMM_CHANNELS;  j++) {
+                                                       if (i != j) {
+                                                               CYGACC_CALL_IF_SET_CONSOLE_COMM(j);
+                                                               __chan = CYGACC_CALL_IF_CONSOLE_PROCS();
+                                                               CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_IRQ_DISABLE);
+                                                       }
+                                               }
+                                               CYGACC_CALL_IF_SET_CONSOLE_COMM(i);
+                                               return res;
+                                       }
+                               }
+                       }
+               }
+               CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
+       } else
 #endif
-    {
-        __chan = CYGACC_CALL_IF_CONSOLE_PROCS();
-        if (__chan)
-            res = CYGACC_COMM_IF_GETC_TIMEOUT(*__chan, c);
-        else {
-            __chan = CYGACC_CALL_IF_DEBUG_PROCS();
-            res = CYGACC_COMM_IF_GETC_TIMEOUT(*__chan, c);
-        }
-    }
-    return res;
+       {
+               __chan = CYGACC_CALL_IF_CONSOLE_PROCS();
+               if (__chan)
+                       res = CYGACC_COMM_IF_GETC_TIMEOUT(*__chan, c);
+               else {
+                       __chan = CYGACC_CALL_IF_DEBUG_PROCS();
+                       res = CYGACC_COMM_IF_GETC_TIMEOUT(*__chan, c);
+               }
+       }
+       return res;
 }
 
 void
 mon_set_read_char_timeout(int ms)
 {
-    hal_virtual_comm_table_t *__chan;
+       hal_virtual_comm_table_t *__chan;
 
 #ifdef CYGPKG_REDBOOT_ANY_CONSOLE
-    if (!console_selected) {
-        int cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
-        int i;
-        // Set timeout to minimum on each channel; total amounts to desired value
-        _mon_timeout = ms;
-        ms = 1;
-        for (i = 0;  i < CYGNUM_HAL_VIRTUAL_VECTOR_COMM_CHANNELS;  i++) {
-            CYGACC_CALL_IF_SET_CONSOLE_COMM(i);
-            if ((__chan = CYGACC_CALL_IF_CONSOLE_PROCS()) != 0) {
-                CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_SET_TIMEOUT, ms);
-            }
-        }
-        CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);        
-    } else 
+       if (!console_selected) {
+               int cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
+               int i;
+               // Set timeout to minimum on each channel; total amounts to desired value
+               _mon_timeout = ms;
+               ms = 1;
+               for (i = 0;  i < CYGNUM_HAL_VIRTUAL_VECTOR_COMM_CHANNELS;  i++) {
+                       CYGACC_CALL_IF_SET_CONSOLE_COMM(i);
+                       if ((__chan = CYGACC_CALL_IF_CONSOLE_PROCS()) != 0) {
+                               CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_SET_TIMEOUT, ms);
+                       }
+               }
+               CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
+       } else
 #endif
-    {
-        if ((__chan = CYGACC_CALL_IF_CONSOLE_PROCS()) != 0) {
-            CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_SET_TIMEOUT, ms);
-        }
-        if ((__chan = CYGACC_CALL_IF_DEBUG_PROCS()) != 0) {
-            CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_SET_TIMEOUT, ms);
-        }
-    }
+       {
+               if ((__chan = CYGACC_CALL_IF_CONSOLE_PROCS()) != 0) {
+                       CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_SET_TIMEOUT, ms);
+               }
+               if ((__chan = CYGACC_CALL_IF_DEBUG_PROCS()) != 0) {
+                       CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_SET_TIMEOUT, ms);
+               }
+       }
 }
 
 //
@@ -253,14 +253,14 @@ mon_set_read_char_timeout(int ms)
 bool
 _rb_break(int timeout)
 {
-    char c;
-    mon_set_read_char_timeout(timeout);
-    if (mon_read_char_with_timeout(&c)) {
-        if (c == 0x03) {  // Test for ^C
-            return true;
-        }
-    }
-    return false;
+       char c;
+       mon_set_read_char_timeout(timeout);
+       if (mon_read_char_with_timeout(&c)) {
+               if (c == 0x03) {  // Test for ^C
+                       return true;
+               }
+       }
+       return false;
 }
 
 #ifdef CYGFUN_REDBOOT_BOOT_SCRIPT
@@ -275,40 +275,40 @@ _rb_break(int timeout)
 static int
 getc_script(char *cp)
 {
-    static bool newline = true;
-    bool skip;
-
-    while (script && *script) {
-       if (newline && *script == '{') {
-           skip = false;
-           ++script;
-
-           // skip if it isn't for this startup type
-           if (strncmp(script, _STARTUP_STR, strlen(_STARTUP_STR)))
-               skip = true;
-
-           // skip past "{...}"
-           while (*script && *script++ != '}')
-               ;
-
-           // skip script line if neccessary
-           if (skip) {
-               while (*script && *script++ != '\n')
-                   ;
-           } else
-               newline = false;
-
-       } else {
-           *cp = *script++;
-           if (*cp == '\n') {
-              newline = true;
-            } else {
-              newline = false;
-            }
-           return true;
+       static bool newline = true;
+       bool skip;
+
+       while (script && *script) {
+               if (newline && *script == '{') {
+                       skip = false;
+                       ++script;
+
+                       // skip if it isn't for this startup type
+                       if (strncmp(script, _STARTUP_STR, strlen(_STARTUP_STR)))
+                               skip = true;
+
+                       // skip past "{...}"
+                       while (*script && *script++ != '}')
+                               ;
+
+                       // skip script line if neccessary
+                       if (skip) {
+                               while (*script && *script++ != '\n')
+                                       ;
+                       } else
+                               newline = false;
+
+               } else {
+                       *cp = *script++;
+                       if (*cp == '\n') {
+                               newline = true;
+                       } else {
+                               newline = false;
+                       }
+                       return true;
+               }
        }
-    }
-    return false;
+       return false;
 }
 #endif
 
@@ -351,422 +351,422 @@ static void expand_history(char *);
 int
 _rb_gets_preloaded(char *buf, int buflen, int timeout)
 {
-    char *ip = buf;   // Insertion point
-    char *eol = buf;  // End of line
-    char c;
-    bool res = false;
-    static char last_ch = '\0';
-    int _timeout;
+       char *ip = buf;   // Insertion point
+       char *eol = buf;  // End of line
+       char c;
+       bool res = false;
+       static char last_ch = '\0';
+       int _timeout;
 #if CYGNUM_REDBOOT_CMD_LINE_EDITING != 0
-    int   _index = _cl_index;  // Last saved line
-    char *xp;
+       int   _index = _cl_index;  // Last saved line
+       char *xp;
 #ifdef CYGSEM_REDBOOT_CMD_LINE_ANSI_SEQUENCES
-    int   ansi_state = 0;      // Used to drive ANSI parser
-    char  ansi_char = '\0';
+       int   ansi_state = 0;      // Used to drive ANSI parser
+       char  ansi_char = '\0';
 #endif
 #endif
 
-    // Display current buffer data
-    while (*eol) {
-        mon_write_char(*eol++);
-    }
-    ip = eol;
+       // Display current buffer data
+       while (*eol) {
+               mon_write_char(*eol++);
+       }
+       ip = eol;
 
-    while (true) {
+       while (true) {
 #ifdef CYGFUN_REDBOOT_BOOT_SCRIPT
-        if (getc_script(&c))
-            do_idle(false);
-        else
+               if (getc_script(&c))
+                       do_idle(false);
+               else
 #endif
-        if ((timeout > 0) && (eol == buf)) {
+                       if ((timeout > 0) && (eol == buf)) {
 #define MIN_TIMEOUT 50
-            _timeout = timeout > MIN_TIMEOUT ? MIN_TIMEOUT : timeout;
-            mon_set_read_char_timeout(_timeout);
-            while (timeout > 0) {
-                res = mon_read_char_with_timeout(&c);
-                if (res) {
-                    // Got a character
-                    do_idle(false);
-                    break;
-                }
-                timeout -= _timeout;
-            }
-            if (res == false) {
-                do_idle(true);
-                return _GETS_TIMEOUT;  // Input timed out
-            }
-        } else {
-            mon_read_char(&c);
-        }
-        *eol = '\0';
+                               _timeout = timeout > MIN_TIMEOUT ? MIN_TIMEOUT : timeout;
+                               mon_set_read_char_timeout(_timeout);
+                               while (timeout > 0) {
+                                       res = mon_read_char_with_timeout(&c);
+                                       if (res) {
+                                               // Got a character
+                                               do_idle(false);
+                                               break;
+                                       }
+                                       timeout -= _timeout;
+                               }
+                               if (res == false) {
+                                       do_idle(true);
+                                       return _GETS_TIMEOUT;  // Input timed out
+                               }
+                       } else {
+                               mon_read_char(&c);
+                       }
+               *eol = '\0';
 #define CTRL(c) ((c)&0x1F)
 #ifdef CYGSEM_REDBOOT_CMD_LINE_ANSI_SEQUENCES
-        // Special handling of ANSI keyboard sequences (arrows, etc)
-        if (c == 0x1B) {
-            // Leadin for ANSI keyboard sequence
-            ansi_state = 1;
-            continue;
-        }
-        switch (ansi_state) {
-        case 0:
-            // No ANSI sequence in progress
-            break;
-        case 1:
-            // ESC seen, look for '['
-            if (c == '[') {
-                ansi_state = 2;
-            } else if (c == 'O') {
-                ansi_state = 4;
-            } else {
-                // Handle bad sequences?
-                ansi_state = 0;
-            }
-            continue;
-        case 2:
-            // ESC+[ seen, process key
-            ansi_state = 0;
-            switch (c) {
-            case 'A':
-                c = CTRL('P');
-                break;
-            case 'B':
-                c = CTRL('N');
-                break;
-            case 'C':
-                c = CTRL('F');
-                break;
-            case 'D':
-                c = CTRL('B');
-                break;
-            case 'F':
-                c = CTRL('E');
-                break;
-            case 'H':
-                c = CTRL('A');
-                break;
-            case '1':
-                ansi_char = CTRL('A');
-                ansi_state = 3;
-                continue;
-            case '3':
-                ansi_char = CTRL('D');
-                ansi_state = 3;
-                continue;
-            default:
-                // Handle bad sequences?
-                continue;
-            }
-            break;
-        case 3:
-            // Sequences like ^[[1~ == ^H
-            ansi_state = 0;
-            if (c == '~') {
-                c = ansi_char;
-            } else {
-                // Handle bad sequences?
-                continue;
-            }
-            break;
-        case 4:
-            // Sequences like ^[OF == ^E
-            ansi_state = 0;
-            if (c == 'F') {
-                c = CTRL('E');
-            } else {
-                // Handle bad sequences?
-                continue;
-            }
-            break;
-        }
+               // Special handling of ANSI keyboard sequences (arrows, etc)
+               if (c == 0x1B) {
+                       // Leadin for ANSI keyboard sequence
+                       ansi_state = 1;
+                       continue;
+               }
+               switch (ansi_state) {
+               case 0:
+                       // No ANSI sequence in progress
+                       break;
+               case 1:
+                       // ESC seen, look for '['
+                       if (c == '[') {
+                               ansi_state = 2;
+                       } else if (c == 'O') {
+                               ansi_state = 4;
+                       } else {
+                               // Handle bad sequences?
+                               ansi_state = 0;
+                       }
+                       continue;
+               case 2:
+                       // ESC+[ seen, process key
+                       ansi_state = 0;
+                       switch (c) {
+                       case 'A':
+                               c = CTRL('P');
+                               break;
+                       case 'B':
+                               c = CTRL('N');
+                               break;
+                       case 'C':
+                               c = CTRL('F');
+                               break;
+                       case 'D':
+                               c = CTRL('B');
+                               break;
+                       case 'F':
+                               c = CTRL('E');
+                               break;
+                       case 'H':
+                               c = CTRL('A');
+                               break;
+                       case '1':
+                               ansi_char = CTRL('A');
+                               ansi_state = 3;
+                               continue;
+                       case '3':
+                               ansi_char = CTRL('D');
+                               ansi_state = 3;
+                               continue;
+                       default:
+                               // Handle bad sequences?
+                               continue;
+                       }
+                       break;
+               case 3:
+                       // Sequences like ^[[1~ == ^H
+                       ansi_state = 0;
+                       if (c == '~') {
+                               c = ansi_char;
+                       } else {
+                               // Handle bad sequences?
+                               continue;
+                       }
+                       break;
+               case 4:
+                       // Sequences like ^[OF == ^E
+                       ansi_state = 0;
+                       if (c == 'F') {
+                               c = CTRL('E');
+                       } else {
+                               // Handle bad sequences?
+                               continue;
+                       }
+                       break;
+               }
 #endif
-        switch (c) {
+               switch (c) {
 #if CYGNUM_REDBOOT_CMD_LINE_EDITING != 0
-        case CTRL('P'):
-            // Fetch the previous line into the buffer
-            if (_index >= 0) {
-                // Erase the previous line [crude]
-                while (ip != buf) {
-                    mon_write_char('\b');
-                    mon_write_char(' ');
-                    mon_write_char('\b');
-                    ip--;
-                }
-                strcpy(buf, _cl_lines[_index]);
-                while (*ip) {
-                    mon_write_char(*ip++);
-                }
-                eol = ip;
-                // Move to previous line
-                _index--;
-                if (_index < 0) {
-                    _index = _cl_max_index;
-                }
-            } else {
-                mon_write_char(0x07);  // Audible bell on most devices
-            }
-            break;
-        case CTRL('N'):
-            // Fetch the next line into the buffer
-            if (_index >= 0) {
-                if (++_index > _cl_max_index) _index = 0;
-                // Erase the previous line [crude]
-                while (ip != buf) {
-                    mon_write_char('\b');
-                    mon_write_char(' ');
-                    mon_write_char('\b');
-                    ip--;
-                }
-                strcpy(buf, _cl_lines[_index]);
-                while (*ip) {
-                    mon_write_char(*ip++);
-                }
-                eol = ip;
-            } else {
-                mon_write_char(0x07);  // Audible bell on most devices
-            }
-            break;
-        case CTRL('B'): 
-            // Move insertion point backwards
-            if (ip != buf) {
-                mon_write_char('\b');
-                ip--;
-            }
-            break;
-        case CTRL('F'):
-            // Move insertion point forwards
-            if (ip != eol) {
-                mon_write_char(*ip++);
-            }
-            break;
-        case CTRL('E'):
-            // Move insertion point to end of line
-            while (ip != eol) {
-                mon_write_char(*ip++);
-            }
-            break;
-        case CTRL('A'):
-            // Move insertion point to beginning of line
-            if (ip != buf) {
-                xp = ip;
-                while (xp-- != buf) {
-                    mon_write_char('\b');
-                }
-            }
-            ip = buf;
-            break;
-        case CTRL('K'):
-            // Kill to the end of line
-            if (ip != eol) {
-                xp = ip;
-                while (xp++ != eol) {
-                    mon_write_char(' ');
-                }
-                while (--xp != ip) {
-                    mon_write_char('\b');
-                }
-                eol = ip;
-            }
-            break;
-        case CTRL('D'):
-            // Erase the character under the cursor
-            if (ip != eol) {
-                xp = ip;
-                eol--;
-                while (xp != eol) {
-                    *xp = *(xp+1);
-                    mon_write_char(*xp++);
-                }
-                mon_write_char(' ');  // Erases last character
-                mon_write_char('\b');
-                while (xp-- != ip) {
-                    mon_write_char('\b');
-                }
-            }
-            break;
+               case CTRL('P'):
+                       // Fetch the previous line into the buffer
+                       if (_index >= 0) {
+                               // Erase the previous line [crude]
+                               while (ip != buf) {
+                                       mon_write_char('\b');
+                                       mon_write_char(' ');
+                                       mon_write_char('\b');
+                                       ip--;
+                               }
+                               strcpy(buf, _cl_lines[_index]);
+                               while (*ip) {
+                                       mon_write_char(*ip++);
+                               }
+                               eol = ip;
+                               // Move to previous line
+                               _index--;
+                               if (_index < 0) {
+                                       _index = _cl_max_index;
+                               }
+                       } else {
+                               mon_write_char(0x07);  // Audible bell on most devices
+                       }
+                       break;
+               case CTRL('N'):
+                       // Fetch the next line into the buffer
+                       if (_index >= 0) {
+                               if (++_index > _cl_max_index) _index = 0;
+                               // Erase the previous line [crude]
+                               while (ip != buf) {
+                                       mon_write_char('\b');
+                                       mon_write_char(' ');
+                                       mon_write_char('\b');
+                                       ip--;
+                               }
+                               strcpy(buf, _cl_lines[_index]);
+                               while (*ip) {
+                                       mon_write_char(*ip++);
+                               }
+                               eol = ip;
+                       } else {
+                               mon_write_char(0x07);  // Audible bell on most devices
+                       }
+                       break;
+               case CTRL('B'):
+                       // Move insertion point backwards
+                       if (ip != buf) {
+                               mon_write_char('\b');
+                               ip--;
+                       }
+                       break;
+               case CTRL('F'):
+                       // Move insertion point forwards
+                       if (ip != eol) {
+                               mon_write_char(*ip++);
+                       }
+                       break;
+               case CTRL('E'):
+                       // Move insertion point to end of line
+                       while (ip != eol) {
+                               mon_write_char(*ip++);
+                       }
+                       break;
+               case CTRL('A'):
+                       // Move insertion point to beginning of line
+                       if (ip != buf) {
+                               xp = ip;
+                               while (xp-- != buf) {
+                                       mon_write_char('\b');
+                               }
+                       }
+                       ip = buf;
+                       break;
+               case CTRL('K'):
+                       // Kill to the end of line
+                       if (ip != eol) {
+                               xp = ip;
+                               while (xp++ != eol) {
+                                       mon_write_char(' ');
+                               }
+                               while (--xp != ip) {
+                                       mon_write_char('\b');
+                               }
+                               eol = ip;
+                       }
+                       break;
+               case CTRL('D'):
+                       // Erase the character under the cursor
+                       if (ip != eol) {
+                               xp = ip;
+                               eol--;
+                               while (xp != eol) {
+                                       *xp = *(xp+1);
+                                       mon_write_char(*xp++);
+                               }
+                               mon_write_char(' ');  // Erases last character
+                               mon_write_char('\b');
+                               while (xp-- != ip) {
+                                       mon_write_char('\b');
+                               }
+                       }
+                       break;
 #endif // CYGNUM_REDBOOT_CMD_LINE_EDITING
-        case CTRL('C'): // ^C
-            // Abort current input
-            diag_printf("^C\n");
-            *buf = '\0';  // Nothing useful in buffer
-            return _GETS_CTRLC;
-        case '\n':
-        case '\r':
-            // If previous character was the "other" end-of-line, ignore this one
-            if (((c == '\n') && (last_ch == '\r')) ||
-                ((c == '\r') && (last_ch == '\n'))) {
-                c = '\0';
-                break;
-            }
-            // End of line
-           if (console_echo) {
-                mon_write_char('\r');
-                mon_write_char('\n');
-           }
-            last_ch = c;
+               case CTRL('C'): // ^C
+                       // Abort current input
+                       diag_printf("^C\n");
+                       *buf = '\0';  // Nothing useful in buffer
+                       return _GETS_CTRLC;
+               case '\n':
+               case '\r':
+                       // If previous character was the "other" end-of-line, ignore this one
+                       if (((c == '\n') && (last_ch == '\r')) ||
+                               ((c == '\r') && (last_ch == '\n'))) {
+                               c = '\0';
+                               break;
+                       }
+                       // End of line
+                       if (console_echo) {
+                               mon_write_char('\r');
+                               mon_write_char('\n');
+                       }
+                       last_ch = c;
 #if CYGNUM_REDBOOT_CMD_LINE_EDITING != 0
-            if (cmd_history) {
-                // History handling - only when enabled
+                       if (cmd_history) {
+                               // History handling - only when enabled
 #ifdef CYGBLD_REDBOOT_CMD_LINE_HISTORY
-               expand_history(buf);
+                               expand_history(buf);
 #endif
-               if (*buf != '\0') {
-                   if (++_cl_index == _CL_NUM_LINES) _cl_index = 0;
-                   if (_cl_index > _cl_max_index) _cl_max_index = _cl_index;
-                   strcpy(_cl_lines[_cl_index], buf);
-               }
-            }
+                               if (*buf != '\0') {
+                                       if (++_cl_index == _CL_NUM_LINES) _cl_index = 0;
+                                       if (_cl_index > _cl_max_index) _cl_max_index = _cl_index;
+                                       strcpy(_cl_lines[_cl_index], buf);
+                               }
+                       }
 #endif
-            return _GETS_OK;
-        case '\b':
-        case 0x7F:  // DEL
-            if (ip != buf) {
+                       return _GETS_OK;
+               case '\b':
+               case 0x7F:  // DEL
+                       if (ip != buf) {
 #if CYGNUM_REDBOOT_CMD_LINE_EDITING != 0
-                if (ip != eol) {
-                    ip--;
-                    mon_write_char('\b');
-                    xp = ip;
-                    while (xp != (eol-1)) {
-                        *xp = *(xp+1);
-                        mon_write_char(*xp++);
-                    }
-                    mon_write_char(' ');  // Erases last character
-                    mon_write_char('\b');
-                    while (xp-- != ip) {
-                        mon_write_char('\b');
-                    }
-                } else {
-                    if (console_echo) {
-                        mon_write_char('\b');
-                        mon_write_char(' ');
-                        mon_write_char('\b');
-                    }
-                    ip--;
-                }
-                eol--;
+                               if (ip != eol) {
+                                       ip--;
+                                       mon_write_char('\b');
+                                       xp = ip;
+                                       while (xp != (eol-1)) {
+                                               *xp = *(xp+1);
+                                               mon_write_char(*xp++);
+                                       }
+                                       mon_write_char(' ');  // Erases last character
+                                       mon_write_char('\b');
+                                       while (xp-- != ip) {
+                                               mon_write_char('\b');
+                                       }
+                               } else {
+                                       if (console_echo) {
+                                               mon_write_char('\b');
+                                               mon_write_char(' ');
+                                               mon_write_char('\b');
+                                       }
+                                       ip--;
+                               }
+                               eol--;
 #else
-                if (console_echo) {
-                    mon_write_char('\b');
-                    mon_write_char(' ');
-                    mon_write_char('\b');
-                }
-                ip--;
-                eol--;
+                               if (console_echo) {
+                                       mon_write_char('\b');
+                                       mon_write_char(' ');
+                                       mon_write_char('\b');
+                               }
+                               ip--;
+                               eol--;
 #endif
-            }
-            break;
+                       }
+                       break;
 #ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
-        case '+': // fall through
-        case '$':
-            if (ip == buf || last_ch != '\\')
-            {
-                // Give up and try GDB protocol
-                ungetDebugChar(c);  // Push back character so stubs will see it
-                return _GETS_GDB;
-            }
-            if (last_ch == '\\') {
+               case '+': // fall through
+               case '$':
+                       if (ip == buf || last_ch != '\\')
+                       {
+                               // Give up and try GDB protocol
+                               ungetDebugChar(c);  // Push back character so stubs will see it
+                               return _GETS_GDB;
+                       }
+                       if (last_ch == '\\') {
 #if CYGNUM_REDBOOT_CMD_LINE_EDITING != 0
-                if (ip == eol) {
-                    // Just save \$ as $
-                    eol = --ip;
-                } else {
-                    mon_write_char('\b');
-                    *--ip = c;
-                    mon_write_char(c);
-                    break;
-                }
+                               if (ip == eol) {
+                                       // Just save \$ as $
+                                       eol = --ip;
+                               } else {
+                                       mon_write_char('\b');
+                                       *--ip = c;
+                                       mon_write_char(c);
+                                       break;
+                               }
 #else
-                ip--;  // Save \$ as $
+                               ip--;  // Save \$ as $
 #endif
-            }
-            // else fall through
+                       }
+                       // else fall through
 #endif
-        default:
+               default:
 #if CYGNUM_REDBOOT_CMD_LINE_EDITING != 0
-            // If the insertion point is not at the end of line, make space for it
-            if (ip != eol) {
-                xp = eol;
-                *++eol = '\0';
-                while (xp != ip) {
-                    *xp = *(xp-1);
-                    xp--;
-                }
-            }
+                       // If the insertion point is not at the end of line, make space for it
+                       if (ip != eol) {
+                               xp = eol;
+                               *++eol = '\0';
+                               while (xp != ip) {
+                                       *xp = *(xp-1);
+                                       xp--;
+                               }
+                       }
 #endif
-            if (console_echo) {
-                mon_write_char(c);
-            }
-            if (ip == eol) {
-                // Advance both pointers
-                *ip++ = c;
-                eol = ip;
+                       if (console_echo) {
+                               mon_write_char(c);
+                       }
+                       if (ip == eol) {
+                               // Advance both pointers
+                               *ip++ = c;
+                               eol = ip;
 #if CYGNUM_REDBOOT_CMD_LINE_EDITING != 0
-            } else {
-                // Just insert the character
-                *ip++ = c;
-                xp = ip;
-                while (xp != eol) {
-                    mon_write_char(*xp++);
-                }
-                while (xp-- != ip) {
-                    mon_write_char('\b');
-                }
+                       } else {
+                               // Just insert the character
+                               *ip++ = c;
+                               xp = ip;
+                               while (xp != eol) {
+                                       mon_write_char(*xp++);
+                               }
+                               while (xp-- != ip) {
+                                       mon_write_char('\b');
+                               }
 #endif
-            }
-        }
-        last_ch = c;
-        if (ip == buf + buflen - 1) { // Buffer full
-            *ip = '\0';
-            return buflen;
-        }
-    }
+                       }
+               }
+               last_ch = c;
+               if (ip == buf + buflen - 1) { // Buffer full
+                       *ip = '\0';
+                       return buflen;
+               }
+       }
 }
 
 int
 _rb_gets(char *buf, int buflen, int timeout)
 {
-    *buf = '\0';  // Empty buffer
-    return _rb_gets_preloaded(buf, buflen, timeout);
+       *buf = '\0';  // Empty buffer
+       return _rb_gets_preloaded(buf, buflen, timeout);
 }
 
 static bool
 _verify_action(int timeout, char *fmt, va_list ap)
 {
-    char ans[8];
-    int ret;
+       char ans[8];
+       int ret;
 #ifdef CYGFUN_REDBOOT_BOOT_SCRIPT
-    // Don't ask if we're executing a script
-    if (script && *script)
-        return 1;
+       // Don't ask if we're executing a script
+       if (script && *script)
+               return 1;
 #endif
 
-    diag_vprintf(fmt, ap);
-    diag_printf(" - continue (y/n)? ");
-    if ((ret = _rb_gets(ans, sizeof(ans), timeout)) > 0) {
-        return ((ans[0] == 'y') || (ans[0] == 'Y'));
-    } else {
-        if (ret == _GETS_TIMEOUT) {
-            diag_printf(" ** Timed out!\n");
-        }
-        return 0;  // Timed out or ^C
-    }
+       diag_vprintf(fmt, ap);
+       diag_printf(" - continue (y/n)? ");
+       if ((ret = _rb_gets(ans, sizeof(ans), timeout)) > 0) {
+               return ((ans[0] == 'y') || (ans[0] == 'Y'));
+       } else {
+               if (ret == _GETS_TIMEOUT) {
+                       diag_printf(" ** Timed out!\n");
+               }
+               return 0;  // Timed out or ^C
+       }
 }
 
 bool
 verify_action(char *fmt, ...)
 {
-    va_list ap;
+       va_list ap;
 
-    va_start(ap, fmt);
-    return _verify_action(0, fmt, ap);
+       va_start(ap, fmt);
+       return _verify_action(0, fmt, ap);
 }
 
 bool
 verify_action_with_timeout(int timeout, char *fmt, ...)
 {
-    va_list ap;
+       va_list ap;
 
-    va_start(ap, fmt);
-    return _verify_action(timeout, fmt, ap);
+       va_start(ap, fmt);
+       return _verify_action(timeout, fmt, ap);
 }
 
 
@@ -776,15 +776,15 @@ verify_action_with_timeout(int timeout, char *fmt, ...)
 static int
 parse_history_index(char *s)
 {
-    int val = 0;
+       int val = 0;
 
-    while ('0' <= *s && *s <= '9')
-       val = (val * 10) + (*s++ - '0');
+       while ('0' <= *s && *s <= '9')
+               val = (val * 10) + (*s++ - '0');
 
-    if (*s)
-       return -1;
+       if (*s)
+               return -1;
 
-    return val;
+       return val;
 }
 
 // Check input line to see if it needs history expansion. If so,
@@ -792,60 +792,60 @@ parse_history_index(char *s)
 static void
 expand_history(char *buf)
 {
-    int ncmds = _cl_max_index + 1;
-    int i, index, len;
-
-    if (buf[0] != '!' || buf[1] == '\0')
-       return;
+       int ncmds = _cl_max_index + 1;
+       int i, index, len;
 
-    if (ncmds > 0) {
-       if (!strcmp(buf, "!!")) {
-           strcpy(buf, _cl_lines[_cl_index]);
-           return;
-       }
-       if ((index = parse_history_index(buf + 1)) >= 0) {
-           if (index <= _cl_max_index) {
-               strcpy(buf, _cl_lines[index]);
+       if (buf[0] != '!' || buf[1] == '\0')
                return;
-           }
-       }
-       len = strlen(buf + 1);
-       for (i = 0, index = _cl_index; i < ncmds; i++) {
-           if (!strncmp(_cl_lines[index], buf+1, len)) {
-               strcpy(buf, _cl_lines[index]);
-               return;
-           }
-           if (--index < 0)
-               index = _cl_max_index;
+
+       if (ncmds > 0) {
+               if (!strcmp(buf, "!!")) {
+                       strcpy(buf, _cl_lines[_cl_index]);
+                       return;
+               }
+               if ((index = parse_history_index(buf + 1)) >= 0) {
+                       if (index <= _cl_max_index) {
+                               strcpy(buf, _cl_lines[index]);
+                               return;
+                       }
+               }
+               len = strlen(buf + 1);
+               for (i = 0, index = _cl_index; i < ncmds; i++) {
+                       if (!strncmp(_cl_lines[index], buf+1, len)) {
+                               strcpy(buf, _cl_lines[index]);
+                               return;
+                       }
+                       if (--index < 0)
+                               index = _cl_max_index;
+               }
        }
-    }
 
-    diag_printf("%s: event not found\n", buf);
-    *buf = '\0';
+       diag_printf("%s: event not found\n", buf);
+       *buf = '\0';
 }
 
 static void
 do_history(int argc, char *argv[])
 {
-    int ncmds = _cl_max_index + 1;
-    int i, index;
-
-    if (_cl_index == _cl_max_index) {
-       // history has not wrapped around
-       for (i = 0; i < ncmds; i++)
-           diag_printf("%3d %s\n", i, _cl_lines[i]);
-    } else {
-       for (i = 0, index = _cl_index + 1; i < ncmds; i++) {
-           diag_printf("%3d %s\n", i, _cl_lines[index++]);
-           if (index > _cl_max_index)
-               index = 0;
+       int ncmds = _cl_max_index + 1;
+       int i, index;
+
+       if (_cl_index == _cl_max_index) {
+               // history has not wrapped around
+               for (i = 0; i < ncmds; i++)
+                       diag_printf("%3d %s\n", i, _cl_lines[i]);
+       } else {
+               for (i = 0, index = _cl_index + 1; i < ncmds; i++) {
+                       diag_printf("%3d %s\n", i, _cl_lines[index++]);
+                       if (index > _cl_max_index)
+                               index = 0;
+               }
        }
-    }
 }
 
-RedBoot_cmd("history", 
-            "Display command history", 
-            "",
-            do_history
-    );
+RedBoot_cmd("history",
+                       "Display command history",
+                       "",
+                       do_history
+       );
 #endif  // CYGBLD_REDBOOT_CMD_LINE_HISTORY
index 04d7cdf..202318b 100644 (file)
@@ -51,6 +51,7 @@
 //
 //==========================================================================
 
+#include <stdlib.h>
 #define  DEFINE_VARS
 #include <redboot.h>
 #include <cyg/hal/hal_arch.h>
@@ -760,3 +761,25 @@ valid_address(unsigned char *addr)
        }
        return false;
 }
+
+static unsigned long random;
+/* provide at least _some_ sort of randomness */
+#define MAX_LOOPS      1000
+
+extern unsigned int hal_timer_count(void);
+
+static void random_init(void)
+{
+       unsigned int timer;
+       int i;
+
+       unsigned int start = hal_timer_count();
+
+       start = hal_timer_count();
+       for (i = 0; i < MAX_LOOPS; i++) {
+               timer = hal_timer_count();
+               srand(random + timer);
+               random = rand();
+       }
+}
+RedBoot_init(random_init, RedBoot_INIT_FIRST);