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

Subversion Repositories usb_fpga_1_2

[/] [usb_fpga_1_2/] [trunk/] [include/] [ztex-flash1.h] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ZTEX
/*!
2
   ZTEX Firmware Kit for EZ-USB Microcontrollers
3
   Copyright (C) 2008-2009 ZTEX e.K.
4
   http://www.ztex.de
5
 
6
   This program is free software; you can redistribute it and/or modify
7
   it under the terms of the GNU General Public License version 3 as
8
   published by the Free Software Foundation.
9
 
10
   This program is distributed in the hope that it will be useful, but
11
   WITHOUT ANY WARRANTY; without even the implied warranty of
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
   General Public License for more details.
14
 
15
   You should have received a copy of the GNU General Public License
16
   along with this program; if not, see http://www.gnu.org/licenses/.
17
!*/
18
 
19
/*
20
    supports AT45D* Flash on Port E
21
*/
22
 
23
#ifndef[ZTEX_FLASH_H]
24
#define[ZTEX_FLASH_H]
25
 
26
#define[FLASH_SI_BIT][6]
27
#define[FLASH_SO_BIT][4]
28
#define[FLASH_CLK_BIT][5]
29
#ifeq[PRODUCT_IS][UFM-1_1]
30
#define[FLASH_CS_BIT][3]
31
//#warning[FLASH_CS_BIT=3]
32
#else
33
#define[FLASH_CS_BIT][7]
34
//#warning[FLASH_CS_BIT=7]
35
#endif
36
 
37
xdata BYTE flash_buffer = 1;          // current buffer 1
38
xdata BYTE flash_bufferModified = 0;  // 1 indicates that the current flash page needs to be reprogrammeded
39
xdata WORD flash_page = 0xffff;       // current flash page
40
xdata WORD flash_nextPage = 0xffff;   // next flash page (usually flashPage+1)
41
xdata WORD flash_maxPage = 0;         // next flash page (usually flashPage+1)
42
xdata WORD flash_pageSize = 528;      // page size (512 or 528)
43
xdata BYTE flash_register[4];         // used to store register content 
44
 
45
/* *********************************************************************
46
   ***** flash_setPage *************************************************
47
   ********************************************************************* */
48
/* set the current page, i.e. executes the following steps
49
    1. wait if busy
50
    2. read the desired page from the falsh array into the new buffer
51
    3. write the old buffer to the flash array (if modified)
52
*/
53
static void flash_setPage(WORD page)
54
{
55
    flash_nextPage = page + 1;
56
}
57
 
58
/* *********************************************************************
59
   ***** flash_write ***************************************************
60
   ********************************************************************* */
61
/* writes <bytes> bytes at address <addr> to the current buffer starting at <offs>.
62
   If <setNextPage> = 1 the next page (defined by <flash_nextPage> is set automatically
63
*/
64
static void flash_write(WORD addr, WORD bytes, WORD offs, BYTE setNextPage)
65
{
66
    addr = 0;
67
    bytes = 0;
68
    offs = 0;
69
    setNextPage = 0;
70
}
71
 
72
/* *********************************************************************
73
   ***** flash_write ***************************************************
74
   ********************************************************************* */
75
static void flash_readRegister(BYTE cmd)
76
{
77
    BYTE oe,b,i,j;
78
 
79
    b = OEE & ( ~( (1 << FLASH_SO_BIT) | (1 << FLASH_SI_BIT) | (1 << FLASH_CLK_BIT) | (1 << FLASH_CS_BIT) ) );
80
    oe = IOE & b;
81
    IOE = oe | (1 << FLASH_CS_BIT);   // CS = 1
82
    OEE = b | (1 << FLASH_SI_BIT) | (1 << FLASH_CLK_BIT) | (1 << FLASH_CS_BIT);
83
    IOE = oe;                         // CS = 0
84
 
85
    // CLK=0
86
    for ( i=0; i<8; i++ ) {
87
        IOE = b = oe | ((cmd & 128) >> (7-FLASH_SI_BIT)); // CLK = 0, SI=x
88
        IOE = b | (1 << FLASH_CLK_BIT);                   // CLK = 1, SI=x
89
        cmd <<= 1;
90
    }
91
 
92
    for ( j=0; j<4; j++ ) {
93
        // CLK = 1
94
        b = 0;
95
        for ( i=0; i<8; i++ ) {
96
            IOE = oe;                          // CLK = 0, SO=x
97
            b = (b << 1) | ((IOE >> FLASH_SO_BIT) & 1);
98
            IOE = oe | (1 << FLASH_CLK_BIT);  // CLK = 1
99
        }
100
        flash_register[j]=b;
101
    }
102
 
103
    IOE = oe | (1 << FLASH_CS_BIT);   // CS = 1
104
}
105
 
106
 
107
/* *********************************************************************
108
   ***** EP0 vendor request 0x40 ***************************************
109
   ********************************************************************* */
110
ADD_EP0_VENDOR_REQUEST((0x40,,
111
    flash_readRegister(SETUPDAT[2]);
112
    EP0BUF[0] = flash_register[0];
113
    EP0BUF[1] = flash_register[1];
114
    EP0BUF[2] = flash_register[2];
115
    EP0BUF[3] = flash_register[3];
116
    EP0BCH = 0;
117
    EP0BCL = 4;
118
,,));;
119
 
120
#endif  /*ZTEX_DESCRIPTORS_H*/

powered by: WebSVN 2.1.0

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