The wait in mci_WaitForEvent will delay all card transactions.

Dependencies:   FATFileSystem

Fork of EALib by EmbeddedArtists AB

Committer:
dreschpe
Date:
Sun Dec 15 21:58:56 2013 +0000
Revision:
9:da373a015d07
Parent:
0:0fdadbc3d852
the wait in mci_WaitForEvent will delay all card transactions.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
embeddedartists 0:0fdadbc3d852 1 /* definitions for ROM API for SPIFI in NXP MCUs
embeddedartists 0:0fdadbc3d852 2 copyright (c) 2010 NXP Semiconductors
embeddedartists 0:0fdadbc3d852 3 written by CAM start 4/16/10
embeddedartists 0:0fdadbc3d852 4 first testing 5/12/10
embeddedartists 0:0fdadbc3d852 5 OK with first SST & Winbond devices 6/8/10
embeddedartists 0:0fdadbc3d852 6 OK with Gigadevice, Numonyx, Atmel,
embeddedartists 0:0fdadbc3d852 7 some Macronyx 7/13/10
embeddedartists 0:0fdadbc3d852 8 consensus with BK, performance optimized 8/24/10
embeddedartists 0:0fdadbc3d852 9 this file is largely platform-independent */
embeddedartists 0:0fdadbc3d852 10
embeddedartists 0:0fdadbc3d852 11 #ifndef SPIFI_ROM_API_H
embeddedartists 0:0fdadbc3d852 12 #define SPIFI_ROM_API_H
embeddedartists 0:0fdadbc3d852 13
embeddedartists 0:0fdadbc3d852 14
embeddedartists 0:0fdadbc3d852 15 #define SPIFI_MEM_BASE 0x28000000
embeddedartists 0:0fdadbc3d852 16 /* allocated size of the SPIFI memory area on this device */
embeddedartists 0:0fdadbc3d852 17 #define MEM_AREA_SIZE 0x00001000
embeddedartists 0:0fdadbc3d852 18 #define SPIFI_ROM_PTR 0x1FFF1FF8
embeddedartists 0:0fdadbc3d852 19
embeddedartists 0:0fdadbc3d852 20 /* define the symbol TESTING in the environment if test output desired */
embeddedartists 0:0fdadbc3d852 21
embeddedartists 0:0fdadbc3d852 22 /* maintain LONGEST_PROT >= the length (in bytes) of the largest
embeddedartists 0:0fdadbc3d852 23 protection block of any serial flash that this driver handles */
embeddedartists 0:0fdadbc3d852 24 #define LONGEST_PROT 68
embeddedartists 0:0fdadbc3d852 25
embeddedartists 0:0fdadbc3d852 26 /* protection/sector descriptors */
embeddedartists 0:0fdadbc3d852 27 typedef struct {
embeddedartists 0:0fdadbc3d852 28 unsigned base;
embeddedartists 0:0fdadbc3d852 29 uint8_t flags;
embeddedartists 0:0fdadbc3d852 30 signed char log2;
embeddedartists 0:0fdadbc3d852 31 uint16_t rept;
embeddedartists 0:0fdadbc3d852 32 } protEnt;
embeddedartists 0:0fdadbc3d852 33
embeddedartists 0:0fdadbc3d852 34 typedef union {
embeddedartists 0:0fdadbc3d852 35 uint16_t hw;
embeddedartists 0:0fdadbc3d852 36 uint8_t byte[2];
embeddedartists 0:0fdadbc3d852 37 }stat_t;
embeddedartists 0:0fdadbc3d852 38
embeddedartists 0:0fdadbc3d852 39 /* the object that init returns, and other routines use as an operand */
embeddedartists 0:0fdadbc3d852 40 typedef struct {
embeddedartists 0:0fdadbc3d852 41 unsigned base, regbase, devSize, memSize;
embeddedartists 0:0fdadbc3d852 42 uint8_t mfger, devType, devID, busy;
embeddedartists 0:0fdadbc3d852 43 stat_t stat;
embeddedartists 0:0fdadbc3d852 44 uint16_t reserved;
embeddedartists 0:0fdadbc3d852 45 uint16_t set_prot, write_prot;
embeddedartists 0:0fdadbc3d852 46 unsigned mem_cmd, prog_cmd;
embeddedartists 0:0fdadbc3d852 47 uint16_t sectors, protBytes;
embeddedartists 0:0fdadbc3d852 48 unsigned opts, errCheck;
embeddedartists 0:0fdadbc3d852 49 uint8_t erase_shifts[4], erase_ops[4];
embeddedartists 0:0fdadbc3d852 50 protEnt *protEnts;
embeddedartists 0:0fdadbc3d852 51 char prot[LONGEST_PROT];
embeddedartists 0:0fdadbc3d852 52 } SPIFIobj;
embeddedartists 0:0fdadbc3d852 53
embeddedartists 0:0fdadbc3d852 54 /* operands of program and erase */
embeddedartists 0:0fdadbc3d852 55 typedef struct {
embeddedartists 0:0fdadbc3d852 56 char *dest; /* starting address for programming or erasing */
embeddedartists 0:0fdadbc3d852 57 unsigned length; /* number of bytes to be programmed or erased */
embeddedartists 0:0fdadbc3d852 58 char *scratch; /* address of work area or NULL */
embeddedartists 0:0fdadbc3d852 59 int protect; /* protection to apply after programming/erasing is done */
embeddedartists 0:0fdadbc3d852 60 unsigned options; /* see the table below */
embeddedartists 0:0fdadbc3d852 61 } SPIFIopers;
embeddedartists 0:0fdadbc3d852 62
embeddedartists 0:0fdadbc3d852 63
embeddedartists 0:0fdadbc3d852 64 /* bits in options operands (MODE3, RCVCLK, and FULLCLK
embeddedartists 0:0fdadbc3d852 65 have the same relationship as in the Control register) */
embeddedartists 0:0fdadbc3d852 66 #define S_MODE3 1
embeddedartists 0:0fdadbc3d852 67 #define S_MODE0 0
embeddedartists 0:0fdadbc3d852 68 #define S_MINIMAL 2
embeddedartists 0:0fdadbc3d852 69 #define S_MAXIMAL 0
embeddedartists 0:0fdadbc3d852 70 #define S_FORCE_ERASE 4
embeddedartists 0:0fdadbc3d852 71 #define S_ERASE_NOT_REQD 8
embeddedartists 0:0fdadbc3d852 72 #define S_CALLER_ERASE 8
embeddedartists 0:0fdadbc3d852 73 #define S_ERASE_AS_REQD 0
embeddedartists 0:0fdadbc3d852 74 #define S_VERIFY_PROG 0x10
embeddedartists 0:0fdadbc3d852 75 #define S_VERIFY_ERASE 0x20
embeddedartists 0:0fdadbc3d852 76 #define S_NO_VERIFY 0
embeddedartists 0:0fdadbc3d852 77 #define S_RCVCLK 0x80
embeddedartists 0:0fdadbc3d852 78 #define S_INTCLK 0
embeddedartists 0:0fdadbc3d852 79 #define S_FULLCLK 0x40
embeddedartists 0:0fdadbc3d852 80 #define S_HALFCLK 0
embeddedartists 0:0fdadbc3d852 81 #define S_DUAL 0x100
embeddedartists 0:0fdadbc3d852 82 #define S_CALLER_PROT 0x200
embeddedartists 0:0fdadbc3d852 83 #define S_DRIVER_PROT 0
embeddedartists 0:0fdadbc3d852 84
embeddedartists 0:0fdadbc3d852 85 /* the length of a standard program command is 256 on all devices */
embeddedartists 0:0fdadbc3d852 86 #define PROG_SIZE 256
embeddedartists 0:0fdadbc3d852 87
embeddedartists 0:0fdadbc3d852 88 /* interface to ROM API */
embeddedartists 0:0fdadbc3d852 89 typedef struct {
embeddedartists 0:0fdadbc3d852 90 int (*spifi_init) (SPIFIobj *obj, unsigned csHigh, unsigned options,
embeddedartists 0:0fdadbc3d852 91 unsigned mhz);
embeddedartists 0:0fdadbc3d852 92 int (*spifi_program) (SPIFIobj *obj, char *source, SPIFIopers *opers);
embeddedartists 0:0fdadbc3d852 93 int (*spifi_erase) (SPIFIobj *obj, SPIFIopers *opers);
embeddedartists 0:0fdadbc3d852 94 /* mode switching */
embeddedartists 0:0fdadbc3d852 95 void (*cancel_mem_mode)(SPIFIobj *obj);
embeddedartists 0:0fdadbc3d852 96 void (*set_mem_mode) (SPIFIobj *obj);
embeddedartists 0:0fdadbc3d852 97
embeddedartists 0:0fdadbc3d852 98 /* mid level functions */
embeddedartists 0:0fdadbc3d852 99 int (*checkAd) (SPIFIobj *obj, SPIFIopers *opers);
embeddedartists 0:0fdadbc3d852 100 int (*setProt) (SPIFIobj *obj, SPIFIopers *opers, char *change,
embeddedartists 0:0fdadbc3d852 101 char *saveProt);
embeddedartists 0:0fdadbc3d852 102 int (*check_block) (SPIFIobj *obj, char *source, SPIFIopers *opers,
embeddedartists 0:0fdadbc3d852 103 unsigned check_program);
embeddedartists 0:0fdadbc3d852 104 int (*send_erase_cmd) (SPIFIobj *obj, unsigned char op, unsigned addr);
embeddedartists 0:0fdadbc3d852 105 unsigned (*ck_erase) (SPIFIobj *obj, unsigned *addr, unsigned length);
embeddedartists 0:0fdadbc3d852 106 int (*prog_block) (SPIFIobj *obj, char *source, SPIFIopers *opers,
embeddedartists 0:0fdadbc3d852 107 unsigned *left_in_page);
embeddedartists 0:0fdadbc3d852 108 unsigned (*ck_prog) (SPIFIobj *obj, char *source, char *dest, unsigned length);
embeddedartists 0:0fdadbc3d852 109
embeddedartists 0:0fdadbc3d852 110 /* low level functions */
embeddedartists 0:0fdadbc3d852 111 void(*setSize) (SPIFIobj *obj, int value);
embeddedartists 0:0fdadbc3d852 112 int (*setDev) (SPIFIobj *obj, unsigned opts, unsigned mem_cmd,
embeddedartists 0:0fdadbc3d852 113 unsigned prog_cmd);
embeddedartists 0:0fdadbc3d852 114 unsigned (*cmd) (uint8_t op, uint8_t addrLen, uint8_t intLen, unsigned short len);
embeddedartists 0:0fdadbc3d852 115 unsigned (*readAd) (SPIFIobj *obj, unsigned cmd, unsigned addr);
embeddedartists 0:0fdadbc3d852 116 void (*send04) (SPIFIobj *obj, uint8_t op, uint8_t len, unsigned value);
embeddedartists 0:0fdadbc3d852 117 void (*wren_sendAd) (SPIFIobj *obj, unsigned cmd, unsigned addr, unsigned value);
embeddedartists 0:0fdadbc3d852 118 int (*write_stat) (SPIFIobj *obj, uint8_t len, uint16_t value);
embeddedartists 0:0fdadbc3d852 119 int (*wait_busy) (SPIFIobj *obj, uint8_t prog_or_erase);
embeddedartists 0:0fdadbc3d852 120 } SPIFI_RTNS;
embeddedartists 0:0fdadbc3d852 121
embeddedartists 0:0fdadbc3d852 122 //#define define_spifi_romPtr(name) const SPIFI_RTNS *name=*((SPIFI_RTNS **)SPIFI_ROM_PTR)
embeddedartists 0:0fdadbc3d852 123
embeddedartists 0:0fdadbc3d852 124 /* example of using this interface:
embeddedartists 0:0fdadbc3d852 125 #include "spifi_rom_api.h"
embeddedartists 0:0fdadbc3d852 126 #define CSHIGH 4
embeddedartists 0:0fdadbc3d852 127 #define SPIFI_MHZ 80
embeddedartists 0:0fdadbc3d852 128 #define source_data_ad (char *)1234
embeddedartists 0:0fdadbc3d852 129
embeddedartists 0:0fdadbc3d852 130 int rc;
embeddedartists 0:0fdadbc3d852 131 SPIFIopers opers;
embeddedartists 0:0fdadbc3d852 132
embeddedartists 0:0fdadbc3d852 133 define_spifi_romPtr(spifi);
embeddedartists 0:0fdadbc3d852 134 SPIFIobj *obj = malloc(sizeof(SPIFIobj));
embeddedartists 0:0fdadbc3d852 135 if (!obj) { can't allocate memory }
embeddedartists 0:0fdadbc3d852 136
embeddedartists 0:0fdadbc3d852 137 rc = spifi->spifi_init (obj, CSHIGH, S_FULLCLK+S_RCVCLK, SPIFI_MHZ);
embeddedartists 0:0fdadbc3d852 138 if (rc) { investigate init error rc }
embeddedartists 0:0fdadbc3d852 139 printf ("the serial flash contains %d bytes\n", obj->devSize);
embeddedartists 0:0fdadbc3d852 140
embeddedartists 0:0fdadbc3d852 141 opers.dest = where_to_program;
embeddedartists 0:0fdadbc3d852 142 opers.length = how_many_bytes;
embeddedartists 0:0fdadbc3d852 143 opers.scratch = NULL; // unprogrammed data is not saved/restored
embeddedartists 0:0fdadbc3d852 144 opers.protect = -1; // save & restore protection
embeddedartists 0:0fdadbc3d852 145 opers.options = S_VERIFY_PROG;
embeddedartists 0:0fdadbc3d852 146
embeddedartists 0:0fdadbc3d852 147 rc = spifi->spifi_program (obj, source_data_ad, &opers);
embeddedartists 0:0fdadbc3d852 148 if (rc) { investigate program error rc }
embeddedartists 0:0fdadbc3d852 149 */
embeddedartists 0:0fdadbc3d852 150
embeddedartists 0:0fdadbc3d852 151 /* these are for normal users, including boot code */
embeddedartists 0:0fdadbc3d852 152 int spifi_init (SPIFIobj *obj, unsigned csHigh, unsigned options, unsigned mhz);
embeddedartists 0:0fdadbc3d852 153 int spifi_program (SPIFIobj *obj, char *source, SPIFIopers *opers);
embeddedartists 0:0fdadbc3d852 154 int spifi_erase (SPIFIobj *obj, SPIFIopers *opers);
embeddedartists 0:0fdadbc3d852 155
embeddedartists 0:0fdadbc3d852 156 /* these are used by the manufacturer-specific init functions */
embeddedartists 0:0fdadbc3d852 157 void setSize (SPIFIobj *obj, int value);
embeddedartists 0:0fdadbc3d852 158 int setDev (SPIFIobj *obj, unsigned opts, unsigned mem_cmd, unsigned prog_cmd);
embeddedartists 0:0fdadbc3d852 159 unsigned read04(SPIFIobj *obj, uint8_t op, uint8_t len);
embeddedartists 0:0fdadbc3d852 160 int write_stat (SPIFIobj *obj, uint8_t len, uint16_t value);
embeddedartists 0:0fdadbc3d852 161 void setProtEnts(SPIFIobj *obj, const protEnt *p, unsigned protTabLen);
embeddedartists 0:0fdadbc3d852 162
embeddedartists 0:0fdadbc3d852 163 #endif
embeddedartists 0:0fdadbc3d852 164
embeddedartists 0:0fdadbc3d852 165