Dependencies:   DM_FATFileSystem EthernetInterface HTTPClient mbed-rtos mbed-src

Fork of DMSupport by Embedded Artists

Committer:
embeddedartists
Date:
Fri Nov 21 11:42:51 2014 +0000
Revision:
0:6b68dac0d986
First version

Who changed what in which revision?

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