r_octacdb_macromix.c 17.7 KB
Newer Older
hu's avatar
hu committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
/*
****************************************************************************
PROJECT : OCTA driver
FILE    : $Id: r_octacdb_macromix.c 13935 2017-06-15 10:30:54Z shinya.tomari $
============================================================================
DESCRIPTION
Octa flash command table for MACRONIX flash device
============================================================================
                            C O P Y R I G H T
============================================================================
                           Copyright (c) 2017
                                  by
                       Renesas Electronics (Europe) GmbH.
                           Arcadiastrasse 10
                          D-40472 Duesseldorf
                               Germany
                          All rights reserved.
============================================================================
Purpose: only for testing, not for mass production

DISCLAIMER

LICENSEE has read, understood and accepted the terms and conditions defined in
the license agreement, especially the usage rights. In any case, it is
LICENSEE's responsibility to make sure that any user of the software complies
with the terms and conditions of the signed license agreement.

SAMPLE CODE is not part of the licensed software, as such it must not be used in
mass-production applications. It can only be used for evaluation and
demonstration purposes at customer's premises listed in the signed license
agreement.

****************************************************************************
*/

/***************************************************************************
  Title: Octa flash command table

  Note: This file defines the macro define and the flash command table for
        Macronix MX25LW51245G octa flash device and JSC JSC64SSU8AGDY octa RAM device.
        If you use other octa flash device, change setting
        parameters according to the model number of the target.

*/


/***************************************************************************
  Section: Includes
*/
#include "r_typedefs.h"
#include "r_octa_api.h"

/***************************************************************************
  Section: Local defines for Octa Flash
*/

/***************************************************************************
  Constants: Dummy Length clock of Octa Flash

  Description:
  Dummy Length clock cycles for each frequency.

  Values:
  LOC_OF_DL_066MHZ - Dummy Length clock cycles for 66MHz
  LOC_OF_DL_084MHZ - Dummy Length clock cycles for 84MHz
  LOC_OF_DL_104MHZ - Dummy Length clock cycles for 104MHz
  LOC_OF_DL_133MHZ - Dummy Length clock cycles for 133MHz
*/

#define LOC_OF_DL_066MHZ         ( 6)   /*  6 Clock */
#define LOC_OF_DL_084MHZ         ( 8)   /*  8 Clock */
#define LOC_OF_DL_104MHZ         (10)   /* 10 Clock */
#define LOC_OF_DL_133MHZ         (14)   /* 14 Clock */


/***************************************************************************
  Constants: Clock cycles for Dummy Length of Octa Flash

  Description:
  Dummy Length clock cycles for register / memory access.

  Values:
  LOC_OF_DL_CFG     - Configured clock cycles.
  LOC_OF_DL_REG_R   - Clock cycles of status / configuration / configuration2 register access.
  LOC_OF_DL_MSP_R   - Clock cycles of memory read access on SPI mode.
  LOC_OF_DL_MOP_R   - Clock cycles of memory read access on OPI / DOPI mode.
  
*/

#define LOC_OF_DL_CFG            (LOC_OF_DL_084MHZ)

#define LOC_OF_DL_REG_R          (4)
#define LOC_OF_DL_MSP_R          (8)
#define LOC_OF_DL_MOP_R          (LOC_OF_DL_CFG)

/***************************************************************************
  Constants: Dummy Length code of Octa Flash

  Description:
  Dummy Length code. This value is written to Configuration register.

*/
#define LOC_OF_DL_CODE           (10 - ((LOC_OF_DL_CFG) / 2))

/***************************************************************************
  Section: Local defines for Octa RAM
*/
/***************************************************************************
  Constants: Dummy Length clock of Octa RAM

  Description:
  Dummy Length clock cycles for each frequency.

  Values:
  LOC_OR_DL_083MHZ - Dummy Length clock cycles for 83MHz
  LOC_OR_DL_100MHZ - Dummy Length clock cycles for 100MHz
  LOC_OR_DL_133MHZ - Dummy Length clock cycles for 133MHz
*/

#define LOC_OR_DL_083MHZ         (3)   /* 3 Clock */
#define LOC_OR_DL_100MHZ         (4)   /* 4 Clock */
#define LOC_OR_DL_133MHZ         (5)   /* 5 Clock */

/***************************************************************************
  Constants: Clock cycles for Dummy Length of Octa RAM

  Description:
  Dummy Length clock cycles for each frequency.

  Values:
  LOC_OR_DL_CFG    - Configurable clock cycles.
  
  LOC_OR_DL_REG_R  - Clock cycles for Dummy Length for configuration register access.
  LOC_OR_DL_MEM_R  - Clock cycles for Dummy Length for memory read access.
  LOC_OR_DL_MEM_W  - Clock cycles for Dummy Length for memory write access.
  
*/
#define LOC_OR_DL_CFG            (LOC_OR_DL_100MHZ)

#define LOC_OR_DL_REG_R          (LOC_OR_DL_CFG)
#define LOC_OR_DL_MEM_R          (LOC_OR_DL_CFG)
#define LOC_OR_DL_MEM_W          (LOC_OR_DL_CFG)

/***************************************************************************
  Constants: Dummy Length code of Octa RAM

  Description:
  Dummy Length code. This value is written to Configuration register.

*/
#define LOC_OR_DL_CODE           (LOC_OR_DL_CFG - 3)


/***************************************************************************
  Section: Global Variables for Octa Flash
*/

/*******************************************************************************
  Variable: r_octacdb_FlashCmdTbl

  This value stores the Octa flash command table.
  
*/

const r_octa_Command_t  r_octacdb_FlashCmdTbl = { 

    /* Reg              , Address   , AddressLength, BitPosition */
    { R_OCTA_STATUS_REG , 0         , 0            , 0x003C     }, /* BlockProtect        */
    { R_OCTA_STATUS_REG , 0         , 0            , 0x0002     }, /* WriteEnableLatch    */
    { R_OCTA_STATUS_REG , 0         , 0            , 0x0001     }, /* WriteInProgress     */
    { R_OCTA_CONFIG2_REG, 0x00000200, 4            , 0x0001     }, /* PreCycle            */
    { R_OCTA_CONFIG2_REG, 0x00000000, 4            , 0x0003     }, /* FlashTransferType   */
    { R_OCTA_CONFIG2_REG, 0x00000200, 4            , 0x0002     }, /* DOS                 */
    
    /* Reg              , Address   , AddressLength, BitMask, BitSet */
    { R_OCTA_CONFIG2_REG, 0x00000300, 4            , 0x07   , LOC_OF_DL_CODE }, /* DummyCycle     */
    
    /* Low  , High  , Between */
    { R_OCTA_LOWPERIOD_2 , R_OCTA_HIGHPERIOD_4, R_OCTA_BETWEENPERIOD_5 }, /* ReadTiming          */
    { R_OCTA_LOWPERIOD_2 , R_OCTA_HIGHPERIOD_5, R_OCTA_BETWEENPERIOD_7 }, /* WriteTiming         */
    { R_OCTA_LOWPERIOD_2 , R_OCTA_HIGHPERIOD_5, R_OCTA_BETWEENPERIOD_7 }, /* CfgTiming           */
    
    /* Cmd  , Address   , CmdLength, AddressLength, DummyLength    , DataLength, OpeFlags */
    { 0x000B, 0         , 1        , 3            , LOC_OF_DL_MSP_R, 0         , R_OCTA_CMD_READ8      }, /* ReadSPI3B           */
    { 0x000C, 0         , 1        , 4            , LOC_OF_DL_MSP_R, 0         , R_OCTA_CMD_READ8      }, /* ReadSPI4B           */
    { 0xEC13, 0         , 2        , 4            , LOC_OF_DL_MOP_R, 0         , R_OCTA_CMD_READ8      }, /* ReadOPI             */
    { 0xEE11, 0         , 2        , 4            , LOC_OF_DL_MOP_R, 0         , R_OCTA_CMD_READ16     }, /* ReadDOPI           */
    { 0x0002, 0         , 1        , 3            , 0              , 0         , R_OCTA_CMD_WRITE8     }, /* WriteSPI3B          */
    { 0x0012, 0         , 1        , 4            , 0              , 0         , R_OCTA_CMD_WRITE8     }, /* WriteSPI4B          */
    { 0x12ED, 0         , 2        , 4            , 0              , 0         , R_OCTA_CMD_WRITE8     }, /* WriteOPI            */
    { 0x12ED, 0         , 2        , 4            , 0              , 0         , R_OCTA_CMD_WRITE16    }, /* WriteDOPI          */
    { 0x0022, 0         , 1        , 4            , 0              , 0         , R_OCTA_CMD_WRITE_NONE }, /* WriteBufInitialSPI  */
    { 0x22DD, 0         , 2        , 4            , 0              , 0         , R_OCTA_CMD_WRITE_NONE }, /* WriteBufInitialOPI  */
    { 0x0024, 0         , 1        , 4            , 0              , 0         , R_OCTA_CMD_WRITE8     }, /* WriteBufContinueSPI */
    { 0x24DB, 0         , 2        , 4            , 0              , 0         , R_OCTA_CMD_WRITE8     }, /* WriteBufContinueOPI */
    { 0x0031, 0         , 1        , 0            , 0              , 0         , R_OCTA_CMD_WRITE_NONE }, /* WriteBufConfirmSPI  */
    { 0x31CE, 0         , 2        , 0            , 0              , 0         , R_OCTA_CMD_WRITE_NONE }, /* WriteBufConfirmOPI  */
    { 0x0006, 0         , 1        , 0            , 0              , 0         , R_OCTA_CMD_WRITE_NONE }, /* WriteEnableSPI      */
    { 0x06F9, 0         , 2        , 0            , 0              , 0         , R_OCTA_CMD_WRITE_NONE }, /* WriteEnableOPI      */
    { 0x0020, 0         , 1        , 3            , 0              , 0         , R_OCTA_CMD_WRITE_NONE }, /* EraseSPI3B          */
    { 0x0021, 0         , 1        , 4            , 0              , 0         , R_OCTA_CMD_WRITE_NONE }, /* EraseSPI4B          */
    { 0x21DE, 0         , 2        , 4            , 0              , 0         , R_OCTA_CMD_WRITE_NONE }, /* EraseOPI            */
    { 0x0005, 0         , 1        , 0            , 0              , 1         , R_OCTA_CMD_READ8      }, /* ReadStsSPI          */
    { 0x05FA, 0x00000000, 2        , 4            , LOC_OF_DL_REG_R, 1         , R_OCTA_CMD_READ8      }, /* ReadStsOPI          */
    { 0x0015, 0         , 1        , 0            , 0              , 1         , R_OCTA_CMD_READ8      }, /* ReadCfgSPI          */
    { 0x15EA, 0x00000001, 2        , 4            , LOC_OF_DL_REG_R, 1         , R_OCTA_CMD_READ8      }, /* ReadCfgOPI          */
    { 0x0071, 0         , 1        , 0            , 0              , 1         , R_OCTA_CMD_READ8      }, /* ReadCfg2SPI         */
    { 0x718E, 0         , 2        , 0            , LOC_OF_DL_REG_R, 1         , R_OCTA_CMD_READ8      }, /* ReadCfg2OPI         */
    { 0x0001, 0         , 1        , 0            , 0              , 2         , R_OCTA_CMD_WRITE16    }, /* WriteStsCfgSPI      */
    { 0x01FE, 0x00000000, 2        , 4            , 0              , 1         , R_OCTA_CMD_WRITE8     }, /* WriteStsOPI         */
    { 0x01FE, 0x00000001, 2        , 4            , 0              , 1         , R_OCTA_CMD_WRITE8     }, /* WriteCfgOPI         */
    { 0x0072, 0         , 1        , 0            , 0              , 1         , R_OCTA_CMD_WRITE8     }, /* WriteCfg2SPI        */
    { 0x728D, 0         , 2        , 0            , 0              , 1         , R_OCTA_CMD_WRITE8     }, /* WriteCfg2OPI        */
    { 0x0066, 0         , 1        , 0            , 0              , 0         , R_OCTA_CMD_WRITE_NONE }, /* ResetEnableSPI      */
    { 0x6699, 0         , 2        , 0            , 0              , 0         , R_OCTA_CMD_WRITE_NONE }, /* ResetEnableOPI      */
    { 0x0099, 0         , 1        , 0            , 0              , 0         , R_OCTA_CMD_WRITE_NONE }, /* ResetSPI            */
    { 0x9966, 0         , 2        , 0            , 0              , 0         , R_OCTA_CMD_WRITE_NONE }, /* ResetOPI            */
    { 0x009F, 0         , 1        , 0            , 0              , 3         , R_OCTA_CMD_READ8      }, /* ReadIDSPI           */
    { 0x9F60, 0x00000000, 2        , 4            , LOC_OF_DL_REG_R, 3         , R_OCTA_CMD_READ8      }  /* ReadIDOPI           */
};

/***************************************************************************
  Section: Global Variables for Octa RAM 
*/

/*******************************************************************************
  Variable: r_octacdb_RamCmdTabl

  This value stores the Octa RAM command table.
  
*/

const r_octa_Command_t  r_octacdb_RamCmdTabl = { 

    /* Reg              , Address   , AddressLength, BitPosition */
    { R_OCTA_NONE_REG   , 0         , 0            , 0          }, /* BlockProtect        */
    { R_OCTA_NONE_REG   , 0         , 0            , 0          }, /* WriteEnableLatch    */
    { R_OCTA_NONE_REG   , 0         , 0            , 0          }, /* WriteInProgress     */
    { R_OCTA_CONFIG_REG , 0x00040000, 4            , 0x0100     }, /* PreCycle            */
    { R_OCTA_NONE_REG   , 0         , 0            , 0          }, /* FlashTransferType   */
    { R_OCTA_NONE_REG   , 0         , 0            , 0          }, /* DOS                 */
    
    /* Reg              , Address   , AddressLength, BitMask, BitSet */ 
    { R_OCTA_CONFIG_REG , 0x00040000, 4            , 0x00F0 , ((uint16_t)LOC_OR_DL_CODE << 4) }, /* DummyCycle     */
    
    /* Low  , High  , Between */
    { R_OCTA_LOWPERIOD_2 , R_OCTA_HIGHPERIOD_4, R_OCTA_BETWEENPERIOD_5 }, /* ReadTiming          */
    { R_OCTA_LOWPERIOD_2 , R_OCTA_HIGHPERIOD_5, R_OCTA_BETWEENPERIOD_7 }, /* WriteTiming         */
    { R_OCTA_LOWPERIOD_2 , R_OCTA_HIGHPERIOD_5, R_OCTA_BETWEENPERIOD_7 }, /* CfgTiming           */
    
    /* Cmd  , Address   , CmdLength, AddressLength, DummyLength    , DataLength, OpeFlags */
    { 0xFFFF, 0         , 0        , 0            , 0              , 0         , R_OCTA_CMD_NONE    }, /* ReadSPI3B           */
    { 0xFFFF, 0         , 0        , 0            , 0              , 0         , R_OCTA_CMD_NONE    }, /* ReadSPI4B           */
    { 0xFFFF, 0         , 0        , 0            , 0              , 0         , R_OCTA_CMD_NONE    }, /* ReadOPI             */
    { 0xA000, 0         , 2        , 4            , LOC_OR_DL_MEM_R, 0         , R_OCTA_CMD_READ16  }, /* ReadDOPI           */
    { 0xFFFF, 0         , 0        , 0            , 0              , 0         , R_OCTA_CMD_NONE    }, /* WriteSPI3B          */
    { 0xFFFF, 0         , 0        , 0            , 0              , 0         , R_OCTA_CMD_NONE    }, /* WriteSPI4B          */
    { 0xFFFF, 0         , 0        , 0            , 0              , 0         , R_OCTA_CMD_NONE    }, /* WriteOPI            */
    { 0x2000, 0         , 2        , 4            , LOC_OR_DL_MEM_W, 0         , R_OCTA_CMD_WRITE16 }, /* WriteDOPI          */
    { 0xFFFF, 0         , 0        , 0            , 0              , 0         , R_OCTA_CMD_NONE    }, /* WriteBufInitialSPI  */
    { 0xFFFF, 0         , 0        , 0            , 0              , 0         , R_OCTA_CMD_NONE    }, /* WriteBufInitialOPI  */
    { 0xFFFF, 0         , 0        , 0            , 0              , 0         , R_OCTA_CMD_NONE    }, /* WriteBufContinueSPI */
    { 0xFFFF, 0         , 0        , 0            , 0              , 0         , R_OCTA_CMD_NONE    }, /* WriteBufContinueOPI */
    { 0xFFFF, 0         , 0        , 0            , 0              , 0         , R_OCTA_CMD_NONE    }, /* WriteBufConfirmSPI  */
    { 0xFFFF, 0         , 0        , 0            , 0              , 0         , R_OCTA_CMD_NONE    }, /* WriteBufConfirmOPI  */
    { 0xFFFF, 0         , 0        , 0            , 0              , 0         , R_OCTA_CMD_NONE    }, /* WriteEnableSPI      */
    { 0xFFFF, 0         , 0        , 0            , 0              , 0         , R_OCTA_CMD_NONE    }, /* WriteEnableOPI      */
    { 0xFFFF, 0         , 0        , 0            , 0              , 0         , R_OCTA_CMD_NONE    }, /* EraseSPI3B          */
    { 0xFFFF, 0         , 0        , 0            , 0              , 0         , R_OCTA_CMD_NONE    }, /* EraseSPI4B          */
    { 0xFFFF, 0         , 0        , 0            , 0              , 0         , R_OCTA_CMD_NONE    }, /* EraseOPI            */
    { 0xFFFF, 0         , 0        , 0            , 0              , 0         , R_OCTA_CMD_NONE    }, /* ReadStsSPI          */
    { 0xFFFF, 0         , 0        , 0            , 0              , 0         , R_OCTA_CMD_NONE    }, /* ReadStsOPI          */
    { 0xFFFF, 0         , 0        , 0            , 0              , 0         , R_OCTA_CMD_NONE    }, /* ReadCfgSPI          */
    { 0xC000, 0x00040000, 2        , 4            , LOC_OR_DL_REG_R, 2         , R_OCTA_CMD_READ16  }, /* ReadCfgOPI          */
    { 0xFFFF, 0         , 0        , 0            , 0              , 0         , R_OCTA_CMD_NONE    }, /* ReadCfg2SPI         */
    { 0xFFFF, 0         , 0        , 0            , 0              , 0         , R_OCTA_CMD_NONE    }, /* ReadCfg2OPI         */
    { 0xFFFF, 0         , 0        , 0            , 0              , 0         , R_OCTA_CMD_NONE    }, /* WriteStsCfgSPI      */
    { 0xFFFF, 0         , 0        , 0            , 0              , 0         , R_OCTA_CMD_NONE    }, /* WriteStsOPI         */
    { 0x4000, 0x00040000, 2        , 4            , 0              , 2         , R_OCTA_CMD_WRITE16 }, /* WriteCfgOPI         */
    { 0xFFFF, 0         , 0        , 0            , 0              , 0         , R_OCTA_CMD_NONE    }, /* WriteCfg2SPI        */
    { 0xFFFF, 0         , 0        , 0            , 0              , 0         , R_OCTA_CMD_NONE    }, /* WriteCfg2OPI        */
    { 0xFFFF, 0         , 0        , 0            , 0              , 0         , R_OCTA_CMD_NONE    }, /* ResetEnableSPI      */
    { 0xFFFF, 0         , 0        , 0            , 0              , 0         , R_OCTA_CMD_NONE    }, /* ResetEnableOPI      */
    { 0xFFFF, 0         , 0        , 0            , 0              , 0         , R_OCTA_CMD_NONE    }, /* ResetSPI            */
    { 0xFFFF, 0         , 0        , 0            , 0              , 0         , R_OCTA_CMD_NONE    }, /* ResetOPI            */
    { 0xFFFF, 0         , 0        , 0            , 0              , 0         , R_OCTA_CMD_NONE    }, /* ReadIDSPI           */
    { 0xC000, 0x00000000, 2        , 4            , LOC_OR_DL_REG_R, 2         , R_OCTA_CMD_READ16  }  /* ReadIDOPI           */
};
/* End Of file */