]>
git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/tests/mbed/spifi1/spifi_rom_api.h
1 /* definitions for ROM API for SPIFI in NXP MCUs
2 copyright (c) 2010 NXP Semiconductors
3 written by CAM start 4/16/10
5 OK with first SST & Winbond devices 6/8/10
6 OK with Gigadevice, Numonyx, Atmel,
8 consensus with BK, performance optimized 8/24/10
9 this file is largely platform-independent */
11 #ifndef SPIFI_ROM_API_H
12 #define SPIFI_ROM_API_H
15 #define SPIFI_MEM_BASE 0x28000000
16 /* allocated size of the SPIFI memory area on this device */
17 #define MEM_AREA_SIZE 0x00001000
18 #define SPIFI_ROM_PTR 0x1FFF1FF8
20 /* define the symbol TESTING in the environment if test output desired */
22 /* maintain LONGEST_PROT >= the length (in bytes) of the largest
23 protection block of any serial flash that this driver handles */
24 #define LONGEST_PROT 68
26 /* protection/sector descriptors */
39 /* the object that init returns, and other routines use as an operand */
41 unsigned base
, regbase
, devSize
, memSize
;
42 uint8_t mfger
, devType
, devID
, busy
;
45 uint16_t set_prot
, write_prot
;
46 unsigned mem_cmd
, prog_cmd
;
47 uint16_t sectors
, protBytes
;
48 unsigned opts
, errCheck
;
49 uint8_t erase_shifts
[4], erase_ops
[4];
51 char prot
[LONGEST_PROT
];
54 /* operands of program and erase */
56 char *dest
; /* starting address for programming or erasing */
57 unsigned length
; /* number of bytes to be programmed or erased */
58 char *scratch
; /* address of work area or NULL */
59 int protect
; /* protection to apply after programming/erasing is done */
60 unsigned options
; /* see the table below */
64 /* bits in options operands (MODE3, RCVCLK, and FULLCLK
65 have the same relationship as in the Control register) */
70 #define S_FORCE_ERASE 4
71 #define S_ERASE_NOT_REQD 8
72 #define S_CALLER_ERASE 8
73 #define S_ERASE_AS_REQD 0
74 #define S_VERIFY_PROG 0x10
75 #define S_VERIFY_ERASE 0x20
79 #define S_FULLCLK 0x40
82 #define S_CALLER_PROT 0x200
83 #define S_DRIVER_PROT 0
85 /* the length of a standard program command is 256 on all devices */
88 /* interface to ROM API */
90 int (*spifi_init
) (SPIFIobj
*obj
, unsigned csHigh
, unsigned options
,
92 int (*spifi_program
) (SPIFIobj
*obj
, char *source
, SPIFIopers
*opers
);
93 int (*spifi_erase
) (SPIFIobj
*obj
, SPIFIopers
*opers
);
95 void (*cancel_mem_mode
)(SPIFIobj
*obj
);
96 void (*set_mem_mode
) (SPIFIobj
*obj
);
98 /* mid level functions */
99 int (*checkAd
) (SPIFIobj
*obj
, SPIFIopers
*opers
);
100 int (*setProt
) (SPIFIobj
*obj
, SPIFIopers
*opers
, char *change
,
102 int (*check_block
) (SPIFIobj
*obj
, char *source
, SPIFIopers
*opers
,
103 unsigned check_program
);
104 int (*send_erase_cmd
) (SPIFIobj
*obj
, unsigned char op
, unsigned addr
);
105 unsigned (*ck_erase
) (SPIFIobj
*obj
, unsigned *addr
, unsigned length
);
106 int (*prog_block
) (SPIFIobj
*obj
, char *source
, SPIFIopers
*opers
,
107 unsigned *left_in_page
);
108 unsigned (*ck_prog
) (SPIFIobj
*obj
, char *source
, char *dest
, unsigned length
);
110 /* low level functions */
111 void(*setSize
) (SPIFIobj
*obj
, int value
);
112 int (*setDev
) (SPIFIobj
*obj
, unsigned opts
, unsigned mem_cmd
,
114 unsigned (*cmd
) (uint8_t op
, uint8_t addrLen
, uint8_t intLen
, unsigned short len
);
115 unsigned (*readAd
) (SPIFIobj
*obj
, unsigned cmd
, unsigned addr
);
116 void (*send04
) (SPIFIobj
*obj
, uint8_t op
, uint8_t len
, unsigned value
);
117 void (*wren_sendAd
) (SPIFIobj
*obj
, unsigned cmd
, unsigned addr
, unsigned value
);
118 int (*write_stat
) (SPIFIobj
*obj
, uint8_t len
, uint16_t value
);
119 int (*wait_busy
) (SPIFIobj
*obj
, uint8_t prog_or_erase
);
122 //#define define_spifi_romPtr(name) const SPIFI_RTNS *name=*((SPIFI_RTNS **)SPIFI_ROM_PTR)
124 /* example of using this interface:
125 #include "spifi_rom_api.h"
128 #define source_data_ad (char *)1234
133 define_spifi_romPtr(spifi);
134 SPIFIobj *obj = malloc(sizeof(SPIFIobj));
135 if (!obj) { can't allocate memory }
137 rc = spifi->spifi_init (obj, CSHIGH, S_FULLCLK+S_RCVCLK, SPIFI_MHZ);
138 if (rc) { investigate init error rc }
139 printf ("the serial flash contains %d bytes\n", obj->devSize);
141 opers.dest = where_to_program;
142 opers.length = how_many_bytes;
143 opers.scratch = NULL; // unprogrammed data is not saved/restored
144 opers.protect = -1; // save & restore protection
145 opers.options = S_VERIFY_PROG;
147 rc = spifi->spifi_program (obj, source_data_ad, &opers);
148 if (rc) { investigate program error rc }
151 /* these are for normal users, including boot code */
152 int spifi_init (SPIFIobj
*obj
, unsigned csHigh
, unsigned options
, unsigned mhz
);
153 int spifi_program (SPIFIobj
*obj
, char *source
, SPIFIopers
*opers
);
154 int spifi_erase (SPIFIobj
*obj
, SPIFIopers
*opers
);
156 /* these are used by the manufacturer-specific init functions */
157 void setSize (SPIFIobj
*obj
, int value
);
158 int setDev (SPIFIobj
*obj
, unsigned opts
, unsigned mem_cmd
, unsigned prog_cmd
);
159 unsigned read04(SPIFIobj
*obj
, uint8_t op
, uint8_t len
);
160 int write_stat (SPIFIobj
*obj
, uint8_t len
, uint16_t value
);
161 void setProtEnts(SPIFIobj
*obj
, const protEnt
*p
, unsigned protTabLen
);