r_sfma_api.h 35.8 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 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157
/*
****************************************************************************
PROJECT : SFMA driver
FILE    : $Id: r_sfma_api.h 15479 2018-01-11 14:04:31Z florian.zimmermann $
============================================================================
DESCRIPTION
Driver for the SFMA(Serial Flash Memory Interface A) macro
============================================================================
                            C O P Y R I G H T
============================================================================
                           Copyright (c) 2013 - 2014
                                  by
                       Renesas Electronics (Europe) GmbH.
                           Arcadiastrasse 10
                          D-40472 Duesseldorf
                               Germany
                          All rights reserved.
============================================================================

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.

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

/***************************************************************************
  Title: SFMA Driver API

  SFMA (Serial Flash Memory Interface A) driver API.

  SFMA driver controls SFMA H/W macro and accesses only register of SFMA H/W macro.

  An application using SFMA driver should include the following header files.

  * r_typedefs.h
  * r_sfma_api.h
  
*/

#ifndef R_SFMA_API_H
#define R_SFMA_API_H

#ifdef __cplusplus
extern "C" {
#endif


/***************************************************************************
  Section: Global defines
*/
/***************************************************************************
  Group: Constants
*/

/***************************************************************************
  Constants: API Version

  This constant is the value which shows the version information of the SFMA driver.
  It refers at the <R_SFMA_VersionStringGet> function.

  R_SFMA_VERSION_HI - This constant is the high byte of the version information.
                      It is major version information.
  R_SFMA_VERSION_LO - This constant is the low byte of the version information.
                      It is minor version information.
*/
#define R_SFMA_VERSION_HI  3
#define R_SFMA_VERSION_LO  4


/***************************************************************************
  Section: Global Types
*/
/***************************************************************************
  Group: Enumerations and Types
*/
/***************************************************************************
  Define: 

  Description:
  SFMA option for performance enhance mode

  Values:
  R_SFMA_PER_EN_MODE_DISABLE - option is disabled
  R_SFMA_PER_EN_MODE_ENABLE  - option is enabled

*/
          
#define R_SFMA_PER_EN_MODE_DISABLE  (0uL)
#define R_SFMA_PER_EN_MODE_ENABLE   (1uL)

/***************************************************************************
  Enum: r_sfma_Error_t

  Description:
  SFMA driver error code.

  If an error occurs these enumerations give information about the
  reason.

  This list can be extended, it is an example only. 
  The error code is used internally by the driver when 
  calling the central error handler.

  The central error handler will pass the error code to the 
  application call-back function, if it has been set. 

  An API function may also return an error code.

  Values:
  R_SFMA_ERR_OK                   - No error has occurred.
  R_SFMA_ERR_NG                   - An error has occurred, but no specific error code
                                    is defined for it.
  R_SFMA_ERR_PARAM_INCORRECT      - A parameter provided to a function is incorrect.
                                    (It excludes the outside of the range)
  R_SFMA_ERR_RANGE_UNIT           - The unit-number is the outside of the range.
  R_SFMA_ERR_RANGE_PARAM          - A parameter is the outside of the range.
  R_SFMA_ERR_NOT_ACCEPTABLE       - A function was called in an incorrect state.
  R_SFMA_ERR_FATAL_OS             - Fatal error has occurred at OS interface.
  R_SFMA_ERR_FATAL_HW             - Fatal error has occurred at H/W.
  R_SFMA_ERR_NOT_SUPPORT_CLOCK    - The set value of the serial clock isn't supported.
  R_SFMA_ERR_NOT_SUPPORT_TRANSFER - The set transfer mode isn't supported in the 
                                    connected serial flash.
  R_SFMA_ERR_SFLASH_PROTECTED     - The serial flash memory is protected.
  R_SFMA_ERR_NOT_SUPPORTED        - The device isn't supported.
*/
typedef enum
{
    R_SFMA_ERR_OK = 0,
    R_SFMA_ERR_NG,
    R_SFMA_ERR_PARAM_INCORRECT,
    R_SFMA_ERR_RANGE_UNIT,
    R_SFMA_ERR_RANGE_PARAM,
    R_SFMA_ERR_NOT_ACCEPTABLE,
    R_SFMA_ERR_FATAL_OS,
    R_SFMA_ERR_FATAL_HW,
    R_SFMA_ERR_NOT_SUPPORT_CLOCK,
    R_SFMA_ERR_NOT_SUPPORT_TRANSFER,
    R_SFMA_ERR_SFLASH_PROTECTED,
    R_SFMA_ERR_NOT_SUPPORTED
} r_sfma_Error_t;

/***************************************************************************
  Enum: r_sfma_MemoryNum_t

  Description:
  This type describes the number of serial flash memory to connect.

  Values:
  R_SFMA_MEMORY_SINGLE - One serial flash memory is connected.
  R_SFMA_MEMORY_DUAL   - Two serial flash memoryies are connected.

  Supported Device:
  RH850/D1M2(H)     - SINGLE and DUAL are available. 
  RH850/D1M1A Unit0 - SINGLE and DUAL are available. 
  RH850/D1M1A Unit1 - SINGLE and DUAL are available. 
  RH850/D1M1A Unit2 - SINGLE is only available.
  RH850/D1M1(H)     - SINGLE and DUAL are available. 
  RH850/D1L2H       - SINGLE and DUAL are available. 
  RH850/D1L2        - SINGLE is only available.
  RH850/D1L1        - SINGLE is only available.
*/
typedef enum
{
    R_SFMA_MEMORY_SINGLE = 0,
    R_SFMA_MEMORY_DUAL
} r_sfma_MemoryNum_t;


/***************************************************************************
  Enum: r_sfma_Mode_t

  Description:
  This type describes the operating mode.

  Values:
  R_SFMA_MODE_EX_SPACE      - External address space read mode.
  R_SFMA_MODE_SPI_OPERATING - SPI operating mode.
*/
typedef enum
{
    R_SFMA_MODE_EX_SPACE = 0,
    R_SFMA_MODE_SPI_OPERATING
} r_sfma_Mode_t;


/***************************************************************************
  Enum: r_sfma_DataTransferMode_t

  Description:
  This type describes the transfer mode.

  Values:
  R_SFMA_SDR_SINGLE_IO - SDR with Single I/O.
  R_SFMA_SDR_DUAL_IO   - SDR with Dual I/O.
  R_SFMA_SDR_QUAD_IO   - SDR with Quad I/O.
  R_SFMA_DDR_SINGLE_IO - DDR with Single I/O.
  R_SFMA_DDR_DUAL_IO   - DDR with Dual I/O.
  R_SFMA_DDR_QUAD_IO   - DDR with Quad I/O.

  Supported Device:
  RH850/D1M2(H)     - SDR(max:120MHz), DDR(max:80MHz) mode are available.
  RH850/D1M1A Unit0 - SDR(max:120MHz), DDR(max:80MHz) mode are available.
  RH850/D1M1A Unit1 - SDR(max: 40MHz), DDR(max:40MHz) mode are available.
  RH850/D1M1A Unit2 - SDR(max: 80MHz), DDR(max:80MHz) mode are available.
  RH850/D1M1(H)     - SDR(max:120MHz), DDR(max:80MHz) mode are available.
  RH850/D1L2(H)     - SDR(max:120MHz), DDR(max:80MHz) mode are available.
  RH850/D1L1        - SDR(max: 40MHz) mode are available.
*/
typedef enum
{
    R_SFMA_SDR_SINGLE_IO = 0,
    R_SFMA_SDR_DUAL_IO,
    R_SFMA_SDR_QUAD_IO,
    R_SFMA_DDR_SINGLE_IO,
    R_SFMA_DDR_DUAL_IO,
    R_SFMA_DDR_QUAD_IO
} r_sfma_DataTransferMode_t;


/***************************************************************************
  Enum: r_sfma_ProtectionMode_t

  Description:
  This type describes the protection mode of the serial flash memory.

  Values:
  R_SFMA_MODE_PROTECT   - Set to the protection mode.
  R_SFMA_MODE_UNPROTECT - Set to the un-protection mode.
*/
typedef enum
{
    R_SFMA_MODE_PROTECT = 0,
    R_SFMA_MODE_UNPROTECT
} r_sfma_ProtectionMode_t;


/***************************************************************************
  Enum: r_sfma_AddressMode_t

  Description:
  This type describes the format of address output to the serial flash memory.

  Values:
  R_SFMA_ADDRESS_24BIT - 24 bit address output.
  R_SFMA_ADDRESS_32BIT - 32 bit address output.
*/
typedef enum
{
    R_SFMA_ADDRESS_24BIT = 0,
    R_SFMA_ADDRESS_32BIT
} r_sfma_AddressMode_t;

/***************************************************************************
  Enum: r_sfma_AccessRange_t

  Description:
  This type describes the access range of the serial flash memory.

  Values:
  R_SFMA_ACCESS_RANGE_32MB  - Access range is 32 Mbytes.
  R_SFMA_ACCESS_RANGE_64MB  - Access range is 64 Mbytes.
  R_SFMA_ACCESS_RANGE_128MB - Access range is 128 Mbytes.
  R_SFMA_ACCESS_RANGE_256MB - Access range is 256 Mbytes.
  R_SFMA_ACCESS_RANGE_512MB - Access range is 512 Mbytes.
*/
typedef enum
{
    R_SFMA_ACCESS_RANGE_32MB = 0,
    R_SFMA_ACCESS_RANGE_64MB,
    R_SFMA_ACCESS_RANGE_128MB,
    R_SFMA_ACCESS_RANGE_256MB,
    R_SFMA_ACCESS_RANGE_512MB
} r_sfma_AccessRange_t;

/***************************************************************************
  Enum: r_sfma_FlashRegister_t

  Description:
  This type describes the register of the serial flash memory.

  Values:
  R_SFMA_STATUS_REG - Status Register.
  R_SFMA_CONFIG_REG - Configuration Register.
  R_SFMA_NONE_REG   - Un used.
*/
typedef enum
{
    R_SFMA_STATUS_REG = 0,
    R_SFMA_CONFIG_REG,
    R_SFMA_NONE_REG
} r_sfma_FlashRegister_t;

/***************************************************************************
  Enum: r_sfma_DummyCycle_t

  Description:
  This type describes the data read dummy cycles.

  Values:
  R_SFMA_DUMMY_1CYC - 1cycle.
  R_SFMA_DUMMY_2CYC - 2cycles.
  R_SFMA_DUMMY_3CYC - 3cycles.
  R_SFMA_DUMMY_4CYC - 4cycles.
  R_SFMA_DUMMY_5CYC - 5cycles.
  R_SFMA_DUMMY_6CYC - 6cycles.
  R_SFMA_DUMMY_7CYC - 7cycles.
  R_SFMA_DUMMY_8CYC - 8cycles.
  R_SFMA_DUMMY_9CYC - 9cycles.
  R_SFMA_DUMMY_10CYC - 10cycles.
  R_SFMA_DUMMY_11CYC - 11cycles.
  R_SFMA_DUMMY_12CYC - 12cycles.
  R_SFMA_DUMMY_13CYC - 13cycles.
  R_SFMA_DUMMY_14CYC - 14cycles.
  R_SFMA_DUMMY_15CYC - 15cycles.
  R_SFMA_DUMMY_16CYC - 16cycles.
  R_SFMA_DUMMY_0CYC - Dummy cycle insertion disabled.
*/
typedef enum
{
    R_SFMA_DUMMY_1CYC = 0,
    R_SFMA_DUMMY_2CYC,
    R_SFMA_DUMMY_3CYC,
    R_SFMA_DUMMY_4CYC,
    R_SFMA_DUMMY_5CYC,
    R_SFMA_DUMMY_6CYC,
    R_SFMA_DUMMY_7CYC,
    R_SFMA_DUMMY_8CYC,
    R_SFMA_DUMMY_9CYC,
    R_SFMA_DUMMY_10CYC,
    R_SFMA_DUMMY_11CYC,
    R_SFMA_DUMMY_12CYC,
    R_SFMA_DUMMY_13CYC,
    R_SFMA_DUMMY_14CYC,
    R_SFMA_DUMMY_15CYC,
    R_SFMA_DUMMY_16CYC,
    R_SFMA_DUMMY_0CYC,
} r_sfma_DummyCycle_t;

/***************************************************************************
  Enum: r_sfma_AddressBitSize_t

  Description:
  This type describes the address bit size.

  Values:
  R_SFMA_ADDRESS_SIZE_1BIT - 1bit.
  R_SFMA_ADDRESS_SIZE_2BIT - 2bits.
  R_SFMA_ADDRESS_SIZE_4BIT - 4bits.
*/
typedef enum
{
    R_SFMA_ADDRESS_SIZE_1BIT = 0,
    R_SFMA_ADDRESS_SIZE_2BIT,
    R_SFMA_ADDRESS_SIZE_4BIT
} r_sfma_AddressBitSize_t;


/***************************************************************************
  Enum: r_sfma_CacheMode_t

  Description:
  This type describes the cache settings for the SFMA interface.

  Values:
  R_SFMA_CACHE_OFF - SFMA cache off.
  R_SFMA_CACHE_BL1 .. BL16 - SFMA cache on, with set burst length
                             (BL1 = 1 data unit of 64bit, BL16 = 16 data units of 64bit)
*/
typedef enum
{
    R_SFMA_CACHE_OFF  = 0,
    R_SFMA_CACHE_BL1  = 1,
    R_SFMA_CACHE_BL2  = 2,
    R_SFMA_CACHE_BL3  = 3,
    R_SFMA_CACHE_BL4  = 4,
    R_SFMA_CACHE_BL5  = 5,
    R_SFMA_CACHE_BL6  = 6,
    R_SFMA_CACHE_BL7  = 7,
    R_SFMA_CACHE_BL8  = 8,
    R_SFMA_CACHE_BL9  = 9,
    R_SFMA_CACHE_BL10 = 10,
    R_SFMA_CACHE_BL11 = 11,
    R_SFMA_CACHE_BL12 = 12,
    R_SFMA_CACHE_BL13 = 13,
    R_SFMA_CACHE_BL14 = 14,
    R_SFMA_CACHE_BL15 = 15,
    R_SFMA_CACHE_BL16 = 16
} r_sfma_CacheMode_t;

/***************************************************************************
  Enum: r_sfma_WindowMode_t

  Description:
  This type describes the Window for SFMA address map.

  Values:
  R_SFMA_WINDOWMODE_PRIMARY - Primary Data Read Window.
  R_SFMA_WINDOWMODE_PROGRAM - Programming Window.
*/
typedef enum
{
    R_SFMA_WINDOWMODE_PRIMARY = 0,
    R_SFMA_WINDOWMODE_PROGRAM,
} r_sfma_WindowMode_t;

/***************************************************************************
  typedef: r_sfma_FlashRegInfo_t

  Description:
  This type describes register infomation of the serial flash memory.

  Struct members:
  RegAssignment   - See <r_sfma_FlashRegister_t>
  BitPosition     - Bit position of status register or configuration register.
*/
typedef struct
{
    r_sfma_FlashRegister_t Reg;
    uint8_t                BitPosition;
} r_sfma_FlashRegInfo_t;

/***************************************************************************
  typedef: r_sfma_FlashRegSetParam_t

  Description:
  This type describes register infomation and set parameter of the serial flash memory.

  Struct members:
  RegAssignment   - See <r_sfma_FlashRegister_t>
  BitMask         - Bit mask of status register or configuration register.
  BitSet          - Set point to a register.
*/
typedef struct
{
    r_sfma_FlashRegister_t Reg;
    uint8_t                BitMask;
    uint8_t                BitSet;
} r_sfma_FlashRegSetParam_t;

/***************************************************************************
  typedef: r_sfma_FlashCommand_t

  Description:
  This type describes the serial flash commands.

  Struct members:
  QuadIoMode      - Quad I/O operation.
  BlockProtect    - Block Protection.
  WriteInProgress - Write in progress.
  DummyCycle      - Dummy cycle.
  ReadSdrDummyCycle       - Read SDR Dummy cycles.
  ReadSdrIoDualDummyCycle - Read SDR Dual Dummy cycles.
  ReadSdrIoQuadDummyCycle - Read SDR Quad Dummy cycles.
  ReadDdrDummyCycle       - Read DDR Dummy cycles.
  ReadDdrIoDualDummyCycle - Read DDR Dual Dummy cycles.
  ReadDdrIoQuadDummyCycle - Read DDR Quad Dummy cycles.
  WriteAddressBit         - Write address bit width.
  ReadSdr         - SDR read.
  ReadSdrDual     - SDR dual read.
  ReadSdrQuad     - SDR quad read.
  ReadSdrIoDual   - SDR dual I/O read.
  ReadSdrIoQuad   - SDR quad I/O read.
  ReadDdr         - DDR read.
  ReadDdrDual     - DDR dual read.
  ReadDdrQuad     - DDR quad read.
  ReadDdrIoDual   - DDR dual I/O read.
  ReadDdrIoQuad   - DDR quad I/O read.
  WriteSdr        - SDR program page.
  WriteSdrDual    - SDR program page dual.
  WriteSdrQuad    - SDR program page quad.
  WriteDdr        - DDR program page.
  WriteDdrDual    - DDR program page dual.
  WriteDdrQuad    - DDR program page quad.
  WriteEnable     - Write enable.
  Erase           - Erase sector.
  ReadStatus_1    - Read status register.
  ReadStatus_2    - Read config register.
  WriteStatus     - Write status register.
  ExitExtAddrSpc    Exit external address space.
  ResetEnable       Reset enable.
  Reset             Reset device .
  PerfEnhaceInd     Performance enhance indicator.
                    e.g. Sets to "0xA5" in case of connecting MX25L51245G
*/
typedef struct
{
    r_sfma_FlashRegInfo_t      QuadIoMode;
    r_sfma_FlashRegInfo_t      BlockProtect;
    r_sfma_FlashRegInfo_t      WriteInProgress;
    r_sfma_FlashRegSetParam_t  DummyCycle;
    r_sfma_DummyCycle_t        ReadSdrDummyCycle;
    r_sfma_DummyCycle_t        ReadSdrIoDualDummyCycle;
    r_sfma_DummyCycle_t        ReadSdrIoQuadDummyCycle;
    r_sfma_DummyCycle_t        ReadDdrDummyCycle;
    r_sfma_DummyCycle_t        ReadDdrIoDualDummyCycle;
    r_sfma_DummyCycle_t        ReadDdrIoQuadDummyCycle;
    r_sfma_AddressBitSize_t    WriteAddressBit;
    uint8_t                    ReadSdr;
    uint8_t                    ReadSdrDual;
    uint8_t                    ReadSdrQuad;
    uint8_t                    ReadSdrIoDual;
    uint8_t                    ReadSdrIoQuad;
    uint8_t                    ReadDdr;
    uint8_t                    ReadDdrDual;
    uint8_t                    ReadDdrQuad;
    uint8_t                    ReadDdrIoDual;
    uint8_t                    ReadDdrIoQuad;
    uint8_t                    WriteSdr;
    uint8_t                    WriteSdrDual;
    uint8_t                    WriteSdrQuad;
    uint8_t                    WriteDdr;
    uint8_t                    WriteDdrDual;
    uint8_t                    WriteDdrQuad;
    uint8_t                    WriteEnable;
    uint8_t                    Erase;
    uint8_t                    ReadStatus1;
    uint8_t                    ReadStatus2;
    uint8_t                    WriteStatus;
    uint8_t                    ExitExtAddrSpc;
    uint8_t                    ResetEnable;
    uint8_t                    Reset;
    uint8_t                    PerfEnhanceInd;
} r_sfma_FlashCommand_t;


/***************************************************************************
  typedef: r_sfma_Config_t

  Description:
  This type describes the configuration of the unit.

  Struct members:
  Mode                        - See <r_sfma_Mode_t>.
  MemoryNum                   - See <r_sfma_MemoryNum_t>.
  DataTransferMode            - See <r_sfma_DataTransferMode_t>.
  AddressMode                 - See <r_sfma_AddressMode_t>.
  SerialFlashMemoryPageSize   - Page size of connected serial flash memory (Byte).
  SerialFlashMemoryMaxClock   - Specify maximum clock speed of connected serial flash memory (Hz).
                                Bit rate of SFMA is decided by SerialFlashMemoryMaxClock and
                                "B_phi clock" which is input to SFMA H/W macro. and setting of
                                "B_Phi clock" is outside RGL. Refer to chapter 17.4.3.1 of H/W user's
                                manual.
                                For example, in case "B_phi clock" is set to 160 MHz, if
                                SerialFlashMemoryMaxClock is set to 80 MHz, "B_Phi clock" is divided
                                by 2 and bit rate of SFMA is set to 80 MHz. But if SerialFlashMemoryClock
                                is set to 60 MHz, "B_Phi clock" is divided by 4 (because division ratio
                                can be set only to even number) then bit rate of SFMA is set to 40 MHz.
                                See <r_sfma_DataTransferMode_t> about available maximum clock.
  SerialFlashMemorySectorSize - Erase Sector Size of connected serial flash memory (Byte).
                                If the MemoryNum of the <r_sfma_Config_t> structure is
                                <R_SFMA_MEMORY_DUAL>, this size must set double size of
                                sector size of serial flash device. 
                                (e.g. This size is 8 Kbytes when connecting two MX25L51245G.)
  SerialFlashMemorySize       - Size of connected serial flash memory (Byte).
                                This size is total size of connected serial flash device.
                                (e.g. This size is 128 MBytes(128*1024*1024), 
                                when connecting two MX25L51245G)
  Command                     - See <r_sfma_FlashCommand_t>.
  CacheMode                   - See <r_sfma_CacheMode_t>.
  Calibration                 - Calibration setting for the device, clock and phase
  PerformanceEnMode           - option to enable the performance enhance mode  
*/
typedef struct
{
    r_sfma_Mode_t             Mode;
    r_sfma_MemoryNum_t        MemoryNum;
    r_sfma_DataTransferMode_t DataTransferMode;
    r_sfma_AddressMode_t      AddressMode;
    uint32_t                  SerialFlashMemoryPageSize;
    uint32_t                  SerialFlashMemoryMaxClock;
    uint32_t                  SerialFlashMemorySectorSize;
    uint64_t                  SerialFlashMemorySize;
    r_sfma_FlashCommand_t     *Command;
    r_sfma_CacheMode_t        CacheMode;
    uint32_t                  Calibration;
    uint32_t                  PerformanceEnMode;
} r_sfma_Config_t;


/***************************************************************************
  Section: Global API functions
*/

/***************************************************************************
  Function: R_SFMA_Init

  Description:
  This function initializes the SFMA driver.

  If the function successfully execute, the return code will be <R_SFMA_ERR_OK>
  and the state will be in the Initialize state.

  Note that this function can't call from interrupt handler.

  Parameter:
  Unit - The parameter specifies the instance number.

  Return value:
  See <r_sfma_Error_t>.

  Supported Device:
  RH850/D1M2(H) - OK (Unit=0 is available.)
  RH850/D1M1A   - OK (Unit=0, Unit=1 and Unit=2 are available. 
                      Unit=1 and Unit=2 are exclusive.)
  RH850/D1M1(H) - OK (Unit=0 is available.)
  RH850/D1L2(H) - OK (Unit=0 is available.)
  RH850/D1L1    - OK (Unit=0 is available.)
*/
r_sfma_Error_t R_SFMA_Init(const uint32_t Unit);


/***************************************************************************
  Function: R_SFMA_DeInit

  Description:
  This function de-initializes the SFMA driver.

  If the function successfully execute, the return code will be <R_SFMA_ERR_OK>
  and the state will be in the UnInitialize state.

  Note that this function can't call from interrupt handler.

  Parameter:
  Unit - The parameter specifies the instance number.

  Return value:
  See <r_sfma_Error_t>.

  Supported Device:
  RH850/D1M2(H) - OK
  RH850/D1M1A   - OK
  RH850/D1M1(H) - OK
  RH850/D1L2(H) - OK
  RH850/D1L1    - OK
*/
r_sfma_Error_t R_SFMA_DeInit(const uint32_t Unit);


/***************************************************************************
  Function: R_SFMA_Open

  Description:
  This function opens the SFMA driver at an operating mode, number of memories
  that is specified.

  If the function successfully execute, the return code will be <R_SFMA_ERR_OK>
  and the state will be in the Executing state.

  Note that this function can't call from interrupt handler.

  Parameter:
  Unit    - The parameter specifies the instance number.
  Config  - This is a pointer to the <r_sfma_Config_t> structure to the
            configuration of the unit.

  Return value:
  See <r_sfma_Error_t>.

  Supported Device:
  RH850/D1M2(H) - OK
  RH850/D1M1A   - OK
  RH850/D1M1(H) - OK
  RH850/D1L2(H) - OK
  RH850/D1L1    - OK
*/
r_sfma_Error_t R_SFMA_Open(const uint32_t                Unit,
                           const r_sfma_Config_t * const Config);


/***************************************************************************
  Function: R_SFMA_Close

  Description:
  This function closes the SFMA driver.

  If the function successfully execute, the return code will be <R_SFMA_ERR_OK>
  and the state will be in the Initialize state.

  Note that this function can't call from interrupt handler.

  Parameter:
  Unit    - The parameter specifies the instance number.

  Return value:
  See <r_sfma_Error_t>.

  Supported Device:
  RH850/D1M2(H) - OK
  RH850/D1M1A   - OK
  RH850/D1M1(H) - OK
  RH850/D1L2(H) - OK
  RH850/D1L1    - OK
*/
r_sfma_Error_t R_SFMA_Close(const uint32_t Unit);


/***************************************************************************
  Function: R_SFMA_AccessAddressSet

  Description:
  This function sets the address of the serial flash memory.

  In the external address space mode it is possible to access MAX 8 Gbytes space of
  serial flash memory. But accessible space which is mapped to CPU address space is
  MAX 512 Mbytes. This function sets the access address and the access range.

  Note: When the <R_SFMA_Open> function is executed, the access address and
        the access range is automatically set to 0x00000000 and 32 Mbytes.

  Note that this function can't call from interrupt handler.

  Parameter:
  Unit    - The parameter specifies the instance number.
  Addr    - The parameter specifies the access address of the serial flash memory.
            This parameter aligns in the access range of "Range" of the argument.
            (e.g. if "Addr" is "0x2000000" and "Range" is 64MB, the set a will be "0x0".)
  Range   - The parameter specifies the access range of the of the serial flash memory.
            See <r_sfma_AccessRange_t>.

  Return value:
  See <r_sfma_Error_t>.

  Supported Device:
  RH850/D1M2(H) - OK
  RH850/D1M1A   - OK
  RH850/D1M1(H) - OK
  RH850/D1L2(H) - OK
  RH850/D1L1    - OK
*/
r_sfma_Error_t R_SFMA_AccessAddressSet(const uint32_t             Unit,
                                       const uint64_t             Addr,
                                       const r_sfma_AccessRange_t Range);


/***************************************************************************
  Function: R_SFMA_AccessAddressGet

  Description:
  This function gets the address of the serial flash memory.

  Note that this function can't call from interrupt handler.

  Parameter:
  Unit    - The parameter specifies the instance number.
  Addr    - This is a pointer to the access address of the serial flash memory.
  Range   - This is a pointer to the access range of the serial flash memory.
            See <r_sfma_AccessRange_t>.

  Return value:
  See <r_sfma_Error_t>.

  Supported Device:
  RH850/D1M2(H) - OK
  RH850/D1M1A   - OK
  RH850/D1M1(H) - OK
  RH850/D1L2(H) - OK
  RH850/D1L1    - OK
*/
r_sfma_Error_t R_SFMA_AccessAddressGet(const uint32_t                     Unit,
                                             uint64_t             * const Addr,
                                             r_sfma_AccessRange_t * const Range);


/***************************************************************************
  Function: R_SFMA_ProtectionModeSet

  Description:
  This function sets protection mode of the serial flash memory.

  The write and erase access to serial flash memory is prohibited if protection is set.

  Note that this function can't call from interrupt handler.

  Parameter:
  Unit    - The parameter specifies the instance number.
  Mode    - The parameter specifies the protection mode of the serial flash memory.
            See <r_sfma_ProtectionMode_t>.

  Return value:
  See <r_sfma_Error_t>.

  Supported Device:
  RH850/D1M2(H) - OK
  RH850/D1M1A   - OK
  RH850/D1M1(H) - OK
  RH850/D1L2(H) - OK
  RH850/D1L1    - OK
*/
r_sfma_Error_t R_SFMA_ProtectionModeSet(const uint32_t                Unit,
                                        const r_sfma_ProtectionMode_t Mode);


/***************************************************************************
  Function: R_SFMA_DataErase

  Description:
  This function erases the data of designated address in the serial flash memory.

  Note: Erasing of data is performed on the sector unit. Therefore this function
        erases data of the sector including the size from the address.

  Note: Erase sector size become double size when MemoryNum of the <r_sfma_Config_t> structure
        is <R_SFMA_MEMORY_DUAL>.

  Note: This function has the possibility that the processing takes time.
        Therefore, <R_SFMA_Sys_Relax> is sometimes executed.

  Note that this function can't call from interrupt handler.

  Parameter:
  Unit    - The parameter specifies the instance number.
  Addr    - The parameter specifies the erase address of the serial flash memory.
  Size    - The parameter specifies the data size (in bytes) to erase.

  Return value:
  See <r_sfma_Error_t>.

  Supported Device:
  RH850/D1M2(H) - OK
  RH850/D1M1A   - OK
  RH850/D1M1(H) - OK
  RH850/D1L2(H) - OK
  RH850/D1L1    - OK
*/
r_sfma_Error_t R_SFMA_DataErase(const uint32_t Unit, const uint64_t Addr, const int32_t Size);


/***************************************************************************
  Function: R_SFMA_DataWrite

  Description:
  This function writes data to the serial flash memory.

  In order to write data, the data of the sector must have been previously erased.

  Note: This function has the possibility that the processing takes time.
        Therefore, <R_SFMA_Sys_Relax> is sometimes executed.

  Note: This function always executes by the SDR transfer mode.

  Note that this function can't call from interrupt handler.

  Parameter:
  Unit    - The parameter specifies the instance number.
  Addr    - The parameter specifies the write address of the serial flash memory.
            This parameter aligns in the page size of the serial flash memory.
  Buf     - This is a pointer to the address of buffer.
  Size    - The parameter specifies the data size (in bytes) to write.

  Return value:
  See <r_sfma_Error_t>.

  Supported Device:
  RH850/D1M2(H) - OK
  RH850/D1M1A   - OK
  RH850/D1M1(H) - OK
  RH850/D1L2(H) - OK
  RH850/D1L1    - OK
*/
r_sfma_Error_t R_SFMA_DataWrite(const uint32_t Unit,
                                const uint64_t Addr,
                                const uint8_t  *Buf,
                                const int32_t  Size);


/***************************************************************************
  Function: R_SFMA_DataRead

  Description:
  This function reads data from the serial flash memory.

  Note: This function has the possibility that the processing takes time.
        Therefore, <R_SFMA_Sys_Relax> is sometimes executed.

  Note that this function can't call from interrupt handler.

  Parameter:
  Unit    - The parameter specifies the instance number.
  Addr    - The parameter specifies the read address of the serial flash memory.
  Buf     - This is a pointer to the address of buffer.
  Size    - The parameter specifies the data size (in bytes) to read.

  Return value:
  See <r_sfma_Error_t>.

  Supported Device:
  RH850/D1M2(H) - OK
  RH850/D1M1A   - OK
  RH850/D1M1(H) - OK
  RH850/D1L2(H) - OK
  RH850/D1L1    - OK
*/
r_sfma_Error_t R_SFMA_DataRead(const uint32_t Unit,
                               const uint64_t Addr,
                                     uint8_t  *Buf,
                               const int32_t  Size);


/***************************************************************************
  Function: R_SFMA_JEDECRead

  Description:
  This function reads basic JEDEC data.

  Note that this function can't call from interrupt handler.

  Parameter:
  Unit           - The parameter specifies the instance number.
  ManufacturerID - This is a pointer to the manufacturer ID.
  MemoryType     - This is a pointer to the memory type.
  Capacity       - This is a pointer to the memory capacity.

  Return value:
  See <r_sfma_Error_t>.

  Supported Device:
  RH850/D1M2(H) - OK
  RH850/D1M1A   - OK
  RH850/D1M1(H) - OK
  RH850/D1L2(H) - OK
  RH850/D1L1    - OK
*/
r_sfma_Error_t R_SFMA_JEDECRead(const uint32_t        Unit,
                                      uint8_t * const ManufacturerID,
                                      uint8_t * const MemoryType,
                                      uint8_t * const Capacity);

/***************************************************************************
  Function: R_SFMA_VersionStringGet

  Description:
  This function returns the version string of this SFMA driver.

  Parameter:
  None

  Return value:
  Pointer of string.

  Supported Device:
  RH850/D1M2(H) - OK
  RH850/D1M1A   - OK
  RH850/D1M1(H) - OK
  RH850/D1L2(H) - OK
  RH850/D1L1    - OK
*/
const uint8_t* R_SFMA_VersionStringGet(void);

/***************************************************************************
  Function: R_SFMA_MacroVersionGet

  Description:
  This function returns the major and minor version of the H/W macro.

  Parameter:
  Major - This is a pointer to the major version.
  Minor - This is a pointer to the minor version.

  Return value:
  See <r_sfma_Error_t>.

  Supported Device:
  RH850/D1M2(H) - OK
  RH850/D1M1A   - OK
  RH850/D1M1(H) - OK
  RH850/D1L2(H) - OK
  RH850/D1L1    - OK
*/
r_sfma_Error_t R_SFMA_MacroVersionGet(uint32_t * const Major,
                                      uint32_t * const Minor);

/***************************************************************************
  Function: R_SFMA_GetCal

  Description:
  This function retrieves the calibration value.

  Parameter:
  Unit           - The parameter specifies the instance number.
  Cal            - This is a pointer to store the calibration value.

  Return value:
  See <r_sfma_Error_t>.

  Supported Device:
  RH850/D1M2(H) - OK
  RH850/D1M1A   - OK
  RH850/D1M1(H) - OK
  RH850/D1L2(H) - OK
  RH850/D1L1    - OK
*/
r_sfma_Error_t R_SFMA_GetCal(const uint32_t   Unit,
                                   uint32_t * Cal);

/***************************************************************************
  Function: R_SFMA_GetStatus

  Description:
  This function retrieves the status for the device in SPI operating mode.

  Parameter:
  Unit           - The parameter specifies the instance number.
  Status1        - This is a pointer to store the Status1 value.
  Status2        - This is a pointer to store the Status2 value.


  Return value:
  See <r_sfma_Error_t>.

  Supported Device:
  RH850/D1M2(H) - OK
  RH850/D1M1A   - OK
  RH850/D1M1(H) - OK
  RH850/D1L2(H) - OK
  RH850/D1L1    - OK
*/
r_sfma_Error_t R_SFMA_GetStatus(const uint32_t Unit, 
                                      uint8_t * const Status1,
                                      uint8_t * const Status2);

/***************************************************************************
  Function: R_SFMA_GetConfig

  Description:
  This function retrieves the config for the device in SPI operating mode.

  Parameter:
  Unit           - The parameter specifies the instance number.
  Config1        - This is a pointer to store the Config1 value.
  Config2        - This is a pointer to store the Config2 value.


  Return value:
  See <r_sfma_Error_t>.

  Supported Device:
  RH850/D1M2(H) - OK
  RH850/D1M1A   - OK
  RH850/D1M1(H) - OK
  RH850/D1L2(H) - OK
  RH850/D1L1    - OK
*/
r_sfma_Error_t R_SFMA_GetConfig(const uint32_t Unit, 
                                      uint8_t * const Config1,
                                      uint8_t * const Config2);


/***************************************************************************
  Function: R_SFMA_WriteStatusConfig

  Description:
  This function writes the Status and config for the device in SPI operating mode.

  Parameter:
  Unit           - The parameter specifies the instance number.
  Status         - This is the Status value to write.
  Config         - This is the Config value to write.


  Return value:
  See <r_sfma_Error_t>.

  Supported Device:
  RH850/D1M2(H) - OK
  RH850/D1M1A   - OK
  RH850/D1M1(H) - OK
  RH850/D1L2(H) - OK
  RH850/D1L1    - OK
*/
r_sfma_Error_t R_SFMA_WriteStatusConfig(const uint32_t Unit, 
                                              uint8_t Status,
                                              uint8_t Config);


/***************************************************************************
  Function: R_SFMA_WriteReset

  Description:
  This function writes a software reset for the device in SPI operating mode.

  Parameter:
  Unit           - The parameter specifies the instance number.


  Return value:
  See <r_sfma_Error_t>.

  Supported Device:
  RH850/D1M2(H) - OK
  RH850/D1M1A   - OK
  RH850/D1M1(H) - OK
  RH850/D1L2(H) - OK
  RH850/D1L1    - OK
*/
r_sfma_Error_t R_SFMA_WriteReset(const uint32_t Unit);

/***************************************************************************
  Function: R_SFMA_UnitWindowSelect

  Description:
  This function is reserved for future use.

  Parameter:
  Unit           - The parameter specifies the instance number.
  Window         - The parameter specifies the window for SFMA.
                   See r_sfma_WindowMode_t.

  Return value:
  See <r_sfma_Error_t>.

  Supported Device:
  RH850/D1M2(H) - NG
  RH850/D1M1A   - NG
  RH850/D1M1(H) - NG
  RH850/D1L2(H) - NG
  RH850/D1L1    - NG
*/
r_sfma_Error_t R_SFMA_UnitWindowSelect(const uint32_t Unit,
                                       const r_sfma_WindowMode_t Window);



/***************************************************************************
  Function: R_SFMA_UnitNumberGet

  Description:
  This function is reserved for future use.

  Parameter:
  Window         - The parameter specifies the window for SFMA.
                   See <r_sfma_WindowMode_t>
  Unit           - This is a pointer to the instance number.

  Return value:
  See <r_sfma_Error_t>.

  Supported Device:
  RH850/D1M2(H) - NG
  RH850/D1M1A   - NG
  RH850/D1M1(H) - NG
  RH850/D1L2(H) - NG
  RH850/D1L1    - NG
*/
r_sfma_Error_t R_SFMA_UnitNumberGet(const r_sfma_WindowMode_t Window,
                                    uint32_t * const Unit);


#ifdef __cplusplus
}
#endif

#endif /* R_SFMA_API_H */