OpenCores
URL https://opencores.org/ocsvn/usb_fpga_2_14/usb_fpga_2_14/trunk

Subversion Repositories usb_fpga_2_14

[/] [usb_fpga_2_14/] [trunk/] [fx2/] [ztex-flash2.h] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ZTEX
/*%
2
   ZTEX Firmware Kit for EZ-USB FX2 Microcontrollers
3
   Copyright (C) 2009-2017 ZTEX GmbH.
4
   http://www.ztex.de
5
 
6
   This Source Code Form is subject to the terms of the Mozilla Public
7
   License, v. 2.0. If a copy of the MPL was not distributed with this file,
8
   You can obtain one at http://mozilla.org/MPL/2.0/.
9
 
10
   Alternatively, the contents of this file may be used under the terms
11
   of the GNU General Public License Version 3, as described below:
12
 
13
   This program is free software; you can redistribute it and/or modify
14
   it under the terms of the GNU General Public License version 3 as
15
   published by the Free Software Foundation.
16
 
17
   This program is distributed in the hope that it will be useful, but
18
   WITHOUT ANY WARRANTY; without even the implied warranty of
19
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
   General Public License for more details.
21
 
22
   You should have received a copy of the GNU General Public License
23
   along with this program; if not, see http://www.gnu.org/licenses/.
24
%*/
25
 
26
/*
27
    Support for standard SPI flash.
28
*/
29
 
30
#ifeq[SPI_PORT][A]
31
#elifeq[SPI_PORT][B]
32
#elifeq[SPI_PORT][C]
33
#elifneq[SPI_PORT][D]
34
#error[Macro `SPI_PORT' is not defined correctly. Valid values are: `A', `B', `C' and `D'.]
35
#endif
36
 
37
#ifndef[ZTEX_FLASH2_H]
38
#define[ZTEX_FLASH2_H]
39
 
40
#define[@CAPABILITY_FLASH;]
41
 
42
#ifndef[SPI_PORT]
43
#error[SPI_PORT not defined]
44
#endif
45
 
46
#ifndef[SPI_BIT_CS]
47
#error[SPI_BIT_CS not defined]
48
#endif
49
 
50
#ifndef[SPI_BIT_DI]
51
#error[SPI_BIT_DI not defined]
52
#endif
53
 
54
#ifndef[SPI_BIT_DO]
55
#error[SPI_BIT_DO not defined]
56
#endif
57
 
58
#ifndef[SPI_BIT_CLK]
59
#error[SPI_BIT_CLK not defined]
60
#endif
61
 
62
#ifndef[SPI_OPORT]
63
#define[SPI_OPORT][SPI_PORT]
64
#endif
65
 
66
#define[SPI_IO@][IOSPI_PORT]
67
#define[SPI_OIO@][IOSPI_OPORT]
68
 
69
#define[SPI_CS][SPI_IO@SPI_BIT_CS]
70
#define[SPI_CLK][SPI_IO@SPI_BIT_CLK]
71
#define[SPI_DI][SPI_IO@SPI_BIT_DI]
72
#define[SPI_DO][SPI_OIO@SPI_BIT_DO]
73
 
74
__xdata BYTE flash_enabled;     // 0    1: enabled, 0:disabled
75
__xdata WORD flash_sector_size; // 1    sector size <sector size> = MSB==0 : flash_sector_size and 0x7fff ? 1<<(flash_sector_size and 0x7fff)
76
__xdata DWORD flash_sectors;    // 3    number of sectors
77
__xdata BYTE flash_ec;          // 7    error code
78
 
79
__xdata BYTE spi_vendor;        // 0
80
__xdata BYTE spi_device;        // 1
81
__xdata BYTE spi_memtype;       // 2
82
__xdata BYTE spi_erase_cmd;     // 3
83
__xdata BYTE spi_last_cmd;      // 4
84
__xdata BYTE spi_buffer[4];     // 5
85
 
86
__xdata WORD spi_write_addr_hi;
87
__xdata BYTE spi_write_addr_lo;
88
__xdata BYTE spi_need_pp;
89
__xdata WORD spi_write_sector;
90
__xdata BYTE ep0_read_mode;
91
__xdata BYTE ep0_write_mode;
92
 
93
#define[FLASH_EC_TIMEOUT][2]
94
#define[FLASH_EC_BUSY][3]
95
#define[FLASH_EC_PENDING][4]
96
#define[FLASH_EC_NOTSUPPORTED][7]
97
 
98
/* *********************************************************************
99
   ***** spi_clocks ****************************************************
100
   ********************************************************************* */
101
// perform c (256 if c=0) clocks
102
void spi_clocks (BYTE c) {
103
        c;                                      // this avoids stupid warnings
104
__asm
105
        mov     r2,dpl
106
010014$:
107
        setb    _SPI_CLK        // 1
108
        nop                     // 1
109
        nop                     // 1
110
        nop                     // 1
111
        clr     _SPI_CLK        // 1
112
        djnz    r2,010014$      // 3
113
__endasm;
114
}
115
 
116
 
117
/* *********************************************************************
118
   ***** flash_read_byte ***********************************************
119
   ********************************************************************* */
120
// read a single byte from the flash
121
BYTE flash_read_byte() { // uses r2,r3,r4
122
__asm
123
        // 8*7 + 6 = 62 clocks 
124
        mov     c,_SPI_DO       // 7
125
        setb    _SPI_CLK
126
        rlc     a
127
        clr     _SPI_CLK
128
 
129
        mov     c,_SPI_DO       // 6
130
        setb    _SPI_CLK
131
        rlc     a
132
        clr     _SPI_CLK
133
 
134
        mov     c,_SPI_DO       // 5
135
        setb    _SPI_CLK
136
        rlc     a
137
        clr     _SPI_CLK
138
 
139
        mov     c,_SPI_DO       // 4
140
        setb    _SPI_CLK
141
        rlc     a
142
        clr     _SPI_CLK
143
 
144
        mov     c,_SPI_DO       // 3
145
        setb    _SPI_CLK
146
        rlc     a
147
        clr     _SPI_CLK
148
 
149
        mov     c,_SPI_DO       // 2
150
        setb    _SPI_CLK
151
        rlc     a
152
        clr     _SPI_CLK
153
 
154
        mov     c,_SPI_DO       // 1
155
        setb    _SPI_CLK
156
        rlc     a
157
        clr     _SPI_CLK
158
 
159
        mov     c,_SPI_DO       // 0
160
        setb    _SPI_CLK
161
        rlc     a
162
        clr     _SPI_CLK
163
        mov     dpl,a
164
        ret
165
__endasm;
166
        return 0;                // never ever called (just to avoid warnings)
167
}
168
 
169
/* *********************************************************************
170
   ***** flash_read ****************************************************
171
   ********************************************************************* */
172
// read len (256 if len=0) bytes from the flash to the buffer
173
void flash_read(__xdata BYTE *buf, BYTE len) {
174
        *buf;                                   // this avoids stupid warnings
175
        len;                                    // this too
176
__asm                                           // *buf is in dptr, len is in _flash_read_PARM_2
177
        mov     r2,_flash_read_PARM_2
178
010012$:
179
        // 2 + len*(8*7 + 9) + 4 = 6 + len*65 clocks
180
        mov     c,_SPI_DO       // 7
181
        setb    _SPI_CLK
182
        rlc     a
183
        clr     _SPI_CLK
184
 
185
        mov     c,_SPI_DO       // 6
186
        setb    _SPI_CLK
187
        rlc     a
188
        clr     _SPI_CLK
189
 
190
        mov     c,_SPI_DO       // 5
191
        setb    _SPI_CLK
192
        rlc     a
193
        clr     _SPI_CLK
194
 
195
        mov     c,_SPI_DO       // 4
196
        setb    _SPI_CLK
197
        rlc     a
198
        clr     _SPI_CLK
199
 
200
        mov     c,_SPI_DO       // 3
201
        setb    _SPI_CLK
202
        rlc     a
203
        clr     _SPI_CLK
204
 
205
        mov     c,_SPI_DO       // 2
206
        setb    _SPI_CLK
207
        rlc     a
208
        clr     _SPI_CLK
209
 
210
        mov     c,_SPI_DO       // 1
211
        setb    _SPI_CLK
212
        rlc     a
213
        clr     _SPI_CLK
214
 
215
        mov     c,_SPI_DO       // 0
216
        setb    _SPI_CLK
217
        rlc     a
218
        clr     _SPI_CLK
219
 
220
        movx    @dptr,a
221
        inc     dptr
222
        djnz    r2,010012$
223
__endasm;
224
}
225
 
226
/* *********************************************************************
227
   ***** spi_write_byte ************************************************
228
   ********************************************************************* */
229
// send one bytes from buffer buf to the card
230
void spi_write_byte (BYTE b) {  // b is in dpl
231
        b;                              // this avoids stupid warnings
232
__asm
233
        // 3 + 8*7 + 4 = 63 clocks 
234
        mov     a,dpl
235
        rlc     a               // 7
236
 
237
        mov     _SPI_DI,c
238
        setb    _SPI_CLK
239
        rlc     a               // 6
240
        clr     _SPI_CLK
241
 
242
        mov     _SPI_DI,c
243
        setb    _SPI_CLK
244
        rlc     a               // 5
245
        clr     _SPI_CLK
246
 
247
        mov     _SPI_DI,c
248
        setb    _SPI_CLK
249
        rlc     a               // 4
250
        clr     _SPI_CLK
251
 
252
        mov     _SPI_DI,c
253
        setb    _SPI_CLK
254
        rlc     a               // 3
255
        clr     _SPI_CLK
256
 
257
        mov     _SPI_DI,c
258
        setb    _SPI_CLK
259
        rlc     a               // 2
260
        clr     _SPI_CLK
261
 
262
        mov     _SPI_DI,c
263
        setb    _SPI_CLK
264
        rlc     a               // 1
265
        clr     _SPI_CLK
266
 
267
        mov     _SPI_DI,c
268
        setb    _SPI_CLK
269
        rlc     a               // 0
270
        clr     _SPI_CLK
271
 
272
        mov     _SPI_DI,c
273
        setb    _SPI_CLK
274
        nop
275
        clr     _SPI_CLK
276
__endasm;
277
}
278
 
279
/* *********************************************************************
280
   ***** spi_write *****************************************************
281
   ********************************************************************* */
282
// write len (256 if len=0) bytes from the buffer to the flash
283
void spi_write(__xdata BYTE *buf, BYTE len) {
284
        *buf;                                   // this avoids stupid warnings
285
        len;                                    // this too
286
__asm                                           // *buf is in dptr, len is in _flash_read_PARM_2
287
        mov     r2,_flash_read_PARM_2
288
010013$:
289
        // 2 + len*(3 + 8*7 - 1 + 7 ) + 4 = 6 + len*65 clocks
290
        movx    a,@dptr
291
        rlc     a               // 7
292
 
293
        mov     _SPI_DI,c
294
        setb    _SPI_CLK
295
        rlc     a               // 6
296
        clr     _SPI_CLK
297
 
298
        mov     _SPI_DI,c
299
        setb    _SPI_CLK
300
        rlc     a               // 5
301
        clr     _SPI_CLK
302
 
303
        mov     _SPI_DI,c
304
        setb    _SPI_CLK
305
        rlc     a               // 4
306
        clr     _SPI_CLK
307
 
308
        mov     _SPI_DI,c
309
        setb    _SPI_CLK
310
        rlc     a               // 3
311
        clr     _SPI_CLK
312
 
313
        mov     _SPI_DI,c
314
        setb    _SPI_CLK
315
        rlc     a               // 2
316
        clr     _SPI_CLK
317
 
318
        mov     _SPI_DI,c
319
        setb    _SPI_CLK
320
        rlc     a               // 1
321
        clr     _SPI_CLK
322
 
323
        mov     _SPI_DI,c
324
        setb    _SPI_CLK
325
        rlc     a               // 0
326
        clr     _SPI_CLK
327
 
328
        mov     _SPI_DI,c
329
        setb    _SPI_CLK
330
        inc     dptr
331
        clr     _SPI_CLK
332
 
333
        djnz    r2,010013$
334
__endasm;
335
}
336
 
337
/* *********************************************************************
338
   ***** spi_select ****************************************************
339
   ********************************************************************* */
340
/*
341
   select the flash (CS)
342
*/
343
void spi_select() {
344
    SPI_CS = 1;                                 // CS = 1;
345
    spi_clocks(8);                              // 8 dummy clocks to finish a previous command
346
    SPI_CS = 0;
347
}
348
 
349
/* *********************************************************************
350
   ***** spi_deselect **************************************************
351
   ********************************************************************* */
352
// de-select the flash (CS)
353
void spi_deselect() {
354
    SPI_CS = 1;                                 // CS = 1;
355
    spi_clocks(8);                              // 8 dummy clocks to finish a previous command
356
}
357
 
358
/* *********************************************************************
359
   ***** spi_start_cmd *************************************************
360
   ********************************************************************* */
361
// send a command   
362
#define[spi_start_cmd(][);][{                   // send a command, argument=0
363
    spi_last_cmd = $0;
364
    spi_select();                               // select
365
    spi_write_byte($0);                          // CMD 90h
366
}]
367
 
368
/* *********************************************************************
369
   ***** spi_wait ******************************************************
370
   ********************************************************************* */
371
/*
372
   wait if prvious read/write command is still prcessed
373
   result is flash_ec (FLASH_EC_TIMEOUT or 0)
374
*/
375
BYTE spi_wait() {
376
    WORD i;
377
    // wait up to 11s
378
    spi_start_cmd(0x05);
379
    for (i=0; (flash_read_byte() & bmBIT0) && i<65535; i++ ) {
380
        spi_clocks(0);                           // 256 dummy clocks
381
//      uwait(20);
382
    }
383
    flash_ec = flash_read_byte() & bmBIT0 ? FLASH_EC_TIMEOUT : 0;
384
    spi_deselect();
385
    return flash_ec;
386
}
387
 
388
/* *********************************************************************
389
   ***** flash_read_init ***********************************************
390
   ********************************************************************* */
391
/*
392
   Start the initialization sequence for reading sector s.
393
   returns an error code (FLASH_EC_*). 0 means no error.
394
*/
395
BYTE flash_read_init(WORD s) {
396
    if ( (SPI_CS) == 0 ) {
397
        flash_ec = FLASH_EC_PENDING;
398
        return FLASH_EC_PENDING;                // we interrupted a pending Flash operation
399
    }
400
    OESPI_OPORT &= ~bmBITSPI_BIT_DO;
401
    OESPI_PORT |= bmBITSPI_BIT_CS | bmBITSPI_BIT_DI | bmBITSPI_BIT_CLK;
402
    if ( spi_wait() ) {
403
        return flash_ec;
404
    }
405
 
406
    s = s << ((BYTE)flash_sector_size - 8);
407
    spi_start_cmd(0x0b);                        // read command
408
    spi_write_byte(s >> 8);                     // 24 byte address
409
    spi_write_byte(s & 255);
410
    spi_write_byte(0);
411
    spi_clocks(8);                              // 8 dummy clocks
412
    return 0;
413
}
414
 
415
/* *********************************************************************
416
   ***** flash_read_next ***********************************************
417
   ********************************************************************* */
418
/*
419
   dummy function for compatibilty
420
*/
421
BYTE flash_read_next() {
422
    return 0;
423
}
424
 
425
 
426
/* *********************************************************************
427
   ***** flash_read_finish *********************************************
428
   ********************************************************************* */
429
/*
430
    Runs the finalization sequence for the read operation.
431
*/
432
void flash_read_finish(WORD n) {
433
   n;                                   // avoids warnings
434
   spi_deselect();
435
}
436
 
437
 
438
/* *********************************************************************
439
   ***** spi_pp ********************************************************
440
   ********************************************************************* */
441
BYTE spi_pp () {
442
    spi_deselect();                             // finish previous write cmd
443
 
444
    spi_need_pp = 0;
445
 
446
    if ( spi_wait() ) {
447
        return flash_ec;
448
    }
449
    spi_start_cmd(0x06);                        // write enable command
450
    spi_deselect();
451
 
452
    spi_start_cmd(0x02);                        // page write
453
    spi_write_byte(spi_write_addr_hi >> 8);     // 24 byte address
454
    spi_write_byte(spi_write_addr_hi & 255);
455
    spi_write_byte(0);
456
    return 0;
457
}
458
 
459
 
460
/* *********************************************************************
461
   ***** flash_write_byte **********************************************
462
   ********************************************************************* */
463
BYTE flash_write_byte (BYTE b) {
464
    if ( spi_need_pp && spi_pp() ) return flash_ec;
465
    spi_write_byte(b);
466
    spi_write_addr_lo++;
467
    if ( spi_write_addr_lo == 0 ) {
468
        spi_write_addr_hi++;
469
        spi_deselect();                         // finish write cmd
470
        spi_need_pp = 1;
471
    }
472
    return 0;
473
}
474
 
475
 
476
/* *********************************************************************
477
   ***** flash_write ***************************************************
478
   ********************************************************************* */
479
// write len (256 if len=0) bytes from the buffer to the flash
480
BYTE flash_write(__xdata BYTE *buf, BYTE len) {
481
    BYTE b;
482
    if ( spi_need_pp && spi_pp() ) return flash_ec;
483
 
484
    if ( spi_write_addr_lo == 0 ) {
485
        spi_write(buf,len);
486
    }
487
    else {
488
        b = (~spi_write_addr_lo) + 1;
489
        if ( len==0 || len>b ) {
490
            spi_write(buf,b);
491
            len-=b;
492
            spi_write_addr_hi++;
493
            spi_write_addr_lo=0;
494
            buf+=b;
495
            if ( spi_pp() ) return flash_ec;
496
        }
497
        spi_write(buf,len);
498
    }
499
 
500
    spi_write_addr_lo+=len;
501
 
502
    if ( spi_write_addr_lo == 0 ) {
503
        spi_write_addr_hi++;
504
        spi_deselect();                         // finish write cmd
505
        spi_need_pp = 1;
506
    }
507
 
508
    return 0;
509
}
510
 
511
 
512
/* *********************************************************************
513
   ***** flash_write_init **********************************************
514
   ********************************************************************* */
515
/*
516
   Start the initialization sequence for writing sector s
517
   The whole sector will be modified
518
   returns an error code (FLASH_EC_*). 0 means no error.
519
*/
520
BYTE flash_write_init(WORD s) {
521
    if ( !SPI_CS ) {
522
        flash_ec = FLASH_EC_PENDING;
523
        return FLASH_EC_PENDING;                // we interrupted a pending Flash operation
524
    }
525
    OESPI_OPORT &= ~bmBITSPI_BIT_DO;
526
    OESPI_PORT |= bmBITSPI_BIT_CS | bmBITSPI_BIT_DI | bmBITSPI_BIT_CLK;
527
    if ( spi_wait() ) {
528
        return flash_ec;
529
    }
530
    spi_write_sector = s;
531
    s = s << ((BYTE)flash_sector_size - 8);
532
    spi_write_addr_hi = s;
533
    spi_write_addr_lo = 0;
534
 
535
    spi_start_cmd(0x06);                        // write enable command
536
    spi_deselect();
537
 
538
    spi_start_cmd(spi_erase_cmd);               // erase command
539
    spi_write_byte(s >> 8);                     // 24 byte address
540
    spi_write_byte(s & 255);
541
    spi_write_byte(0);
542
    spi_deselect();
543
 
544
    spi_need_pp = 1;
545
    return 0;
546
}
547
 
548
 
549
/* *********************************************************************
550
   ***** flash_write_finish_sector *************************************
551
   ********************************************************************* */
552
/*
553
   Dummy function for compatibilty.
554
*/
555
BYTE flash_write_finish_sector (WORD n) {
556
    n;
557
    spi_deselect();
558
    return 0;
559
}
560
 
561
 
562
/* *********************************************************************
563
   ***** flash_write_finish ********************************************
564
   ********************************************************************* */
565
/*
566
   Dummy function for compatibilty.
567
*/
568
void flash_write_finish () {
569
    spi_deselect();
570
}
571
 
572
 
573
/* *********************************************************************
574
   ***** flash_write_next **********************************************
575
   ********************************************************************* */
576
/*
577
   Prepare the next sector for writing, see flash_write_finish1.
578
*/
579
BYTE flash_write_next () {
580
    spi_deselect();
581
    return flash_write_init(spi_write_sector+1);
582
}
583
 
584
 
585
/* *********************************************************************
586
   ***** flash_init ****************************************************
587
   ********************************************************************* */
588
// init the flash
589
void flash_init() {
590
    BYTE i;
591
 
592
    PORTCCFG = 0;
593
 
594
    flash_enabled = 1;
595
    flash_ec = 0;
596
    flash_sector_size = 0x8010;  // 64 KByte
597
    spi_erase_cmd = 0xd8;
598
 
599
    OESPI_OPORT &= ~bmBITSPI_BIT_DO;
600
    OESPI_PORT |= bmBITSPI_BIT_CS | bmBITSPI_BIT_DI | bmBITSPI_BIT_CLK;
601
    SPI_CS = 1;
602
    spi_clocks(0);                               // 256 clocks
603
 
604
    spi_start_cmd(0x90);                        // CMD 90h, not supported by all chips
605
    spi_clocks(24);                             // ADDR=0
606
    spi_device = flash_read_byte();
607
    spi_deselect();                             // deselect
608
 
609
    spi_start_cmd(0x9F);                        // CMD 9Fh
610
    flash_read(spi_buffer,3);                   // read data
611
    spi_deselect();                             // deselect
612
    if ( spi_buffer[2]<16 || spi_buffer[2]>24 ) {
613
        goto  disable;
614
    }
615
    spi_vendor = spi_buffer[0];
616
    spi_memtype = spi_buffer[1];
617
 
618
#ifeq[USE_4KSECTORS_ENABLED][1]
619
    if ( ( spi_vendor==1 && spi_memtype == 0x40 ) ||
620
         ( spi_vendor==0x20 && spi_memtype == 0xba )
621
       ) {
622
        // support of uniform 4 kbyte (logical) sectors
623
        flash_sector_size = 0x800C;  // 4 KByte
624
        spi_erase_cmd = 0x20;
625
        i=spi_buffer[2]-12;
626
    }
627
    else {
628
        // support of uniform 64 kbyte (logical) sectors
629
        i=spi_buffer[2]-16;
630
    }
631
#else    
632
    i=spi_buffer[2]-16;
633
#endif    
634
    flash_sectors = 1 << i;
635
 
636
    return;
637
 
638
disable:
639
    flash_enabled = 0;
640
    flash_ec = FLASH_EC_NOTSUPPORTED;
641
    OESPI_PORT &= ~( bmBITSPI_BIT_CS | bmBITSPI_BIT_DI | bmBITSPI_BIT_CLK );
642
}
643
 
644
 
645
/* *********************************************************************
646
   ***** EP0 vendor request 0x40 ***************************************
647
   ********************************************************************* */
648
// send flash information structure (card size, error status,  ...) to the host
649
ADD_EP0_VENDOR_REQUEST((0x40,,
650
    if ( flash_ec == 0 && SPI_CS == 0 ) {
651
        flash_ec = FLASH_EC_PENDING;
652
    }
653
    MEM_COPY1(flash_enabled,EP0BUF,8);
654
    EP0BCH = 0;
655
    EP0BCL = 8;
656
,,
657
));;
658
 
659
/* *********************************************************************
660
   ***** EP0 vendor request 0x41 ***************************************
661
   ********************************************************************* */
662
/* read modes (ep0_read_mode)
663
        0: start read
664
        1: continue read
665
        2: finish read
666
*/
667
void spi_read_ep0 () {
668
    flash_read(EP0BUF, ep0_payload_transfer);
669
    if ( ep0_read_mode==2 && ep0_payload_remaining==0 ) {
670
        spi_deselect();
671
    }
672
}
673
 
674
ADD_EP0_VENDOR_REQUEST((0x41,,                  // read data
675
    ep0_read_mode = SETUPDAT[5];
676
    if ( (ep0_read_mode==0) && flash_read_init((SETUPDAT[3] << 8) | SETUPDAT[2]) ) {
677
        EP0_STALL;
678
    }
679
    spi_read_ep0();
680
    EP0BCH = 0;
681
    EP0BCL = ep0_payload_transfer;
682
,,
683
    if ( ep0_payload_transfer != 0 ) {
684
        flash_ec = 0;
685
        spi_read_ep0();
686
    }
687
    EP0BCH = 0;
688
    EP0BCL = ep0_payload_transfer;
689
));;
690
 
691
/* *********************************************************************
692
   ***** EP0 vendor command 0x42 ***************************************
693
   ********************************************************************* */
694
void spi_send_ep0 () {
695
    flash_write(EP0BUF, ep0_payload_transfer);
696
    if ( ep0_write_mode==2 && ep0_payload_remaining==0 ) {
697
        spi_deselect();
698
    }
699
}
700
 
701
ADD_EP0_VENDOR_COMMAND((0x42,,                  // write integer number of sectors
702
    ep0_write_mode = SETUPDAT[5];
703
    if ( (ep0_write_mode == 0) && flash_write_init((SETUPDAT[3] << 8) | SETUPDAT[2]) ) {
704
        EP0_STALL;
705
    }
706
,,
707
    if ( ep0_payload_transfer != 0 ) {
708
        flash_ec = 0;
709
        spi_send_ep0();
710
        if ( flash_ec != 0 ) {
711
            spi_deselect();
712
            EP0_STALL;
713
        }
714
    }
715
));;
716
 
717
/* *********************************************************************
718
   ***** EP0 vendor request 0x43 ***************************************
719
   ********************************************************************* */
720
// send detailed SPI status plus debug information
721
ADD_EP0_VENDOR_REQUEST((0x43,,
722
    MEM_COPY1(flash_ec,EP0BUF,10);
723
    EP0BCH = 0;
724
    EP0BCL = 10;
725
,,
726
));;
727
 
728
#endif  /*ZTEX_FLASH2_H*/

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.