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/] [examples/] [usb-1.0/] [flashdemo/] [flashdemo.c] - Blame information for rev 3

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

Line No. Rev Author Line
1 3 ZTEX
/*!
2
   flashdemo -- Flash memory example
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
#include[ztex-conf.h]   // Loads the configuration macros, see ztex-conf.h for the available macros
20
#include[ztex-utils.h]  // include basic functions and variables
21
 
22
// Cypress vendor ID and product ID may only (!) be used for experimental purposes
23
SET_VPID(0x4b4,0x8613);
24
 
25
// select ZTEX USB Module 1.0 as target (required for FLASH support)
26
IDENTITY_UM_1_0(10.20.0.0,0);
27
// uncomment the following line and comment the line above to run this example on ZTEX USB Module 1.2
28
//IDENTITY_UFM_1_2(10.11.0.0,0);         
29
 
30
// enable Flash support
31
ENABLE_FLASH;
32
 
33
// this product string is also used for identification of the firmware in FlashDemo.java
34
#define[PRODUCT_STRING]["Flash demo"]
35
 
36
code char flash_string[] = "Hello World!";
37
 
38
// include the main part of the firmware kit, define the descriptors, ...
39
#include[ztex.h]
40
 
41
void main(void)
42
{
43
    xdata DWORD sector;
44
 
45
    init_USB();                                         // init everything
46
 
47
    if ( flash_enabled ) {
48
        flash_read_init( 0 );                            // prepare reading sector 0
49
        flash_read(&sector, 4);                         // read the number of last sector 
50
        flash_read_finish(flash_sector_size - 4);       // dummy-read the rest of the sector + finish read operation
51
 
52
        sector++;
53
        if ( sector > flash_sectors || sector == 0 ) {
54
            sector = 1;
55
        }
56
 
57
        flash_write_init( 0 );                           // prepare writing sector 0
58
        flash_write(&sector, 4);                        // write the current sector number
59
        flash_write_finish(flash_sector_size - 4);      // dummy-write the rest of the sector + finish write operation
60
 
61
        flash_write_init( sector );                     // prepare writing sector sector
62
        flash_write((xdata*) flash_string, sizeof(flash_string));       // write the string 
63
        flash_write_finish(flash_sector_size - sizeof(flash_string));   // dummy-write the rest of the sector + finish write operation
64
    }
65
 
66
    while (1) { }                                       //  twiddle thumbs
67
}
68
 

powered by: WebSVN 2.1.0

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