1 |
2 |
ZTEX |
/*!
|
2 |
|
|
flashdemo -- demo for Flash memory access from firmware and host software for ZTEX USB-XMEGA Module 1.0
|
3 |
|
|
Copyright (C) 2009-2011 ZTEX GmbH.
|
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 |
|
|
// select ZTEX USB-XMEGA Module 1.0 as target
|
23 |
|
|
IDENTITY_UXM_1_0(10.30.0.0,0);
|
24 |
|
|
|
25 |
|
|
// enable Flash support
|
26 |
|
|
ENABLE_FLASH;
|
27 |
|
|
|
28 |
|
|
// this product string is also used for identification by the host software
|
29 |
|
|
#define[PRODUCT_STRING]["Flash demo for UXM 1.0"]
|
30 |
|
|
|
31 |
|
|
__code char flash_string[] = "Hello World!";
|
32 |
|
|
|
33 |
|
|
// include the main part of the firmware kit, define the descriptors, ...
|
34 |
|
|
#include[ztex.h]
|
35 |
|
|
|
36 |
|
|
void main(void)
|
37 |
|
|
{
|
38 |
|
|
__xdata DWORD sector;
|
39 |
|
|
|
40 |
|
|
init_USB(); // init everything
|
41 |
|
|
|
42 |
|
|
if ( flash_enabled ) {
|
43 |
|
|
flash_read_init( 0 ); // prepare reading sector 0
|
44 |
|
|
flash_read((__xdata BYTE*) §or, 4); // read the number of last sector
|
45 |
|
|
flash_read_finish(flash_sector_size - 4); // dummy-read the rest of the sector + finish read operation
|
46 |
|
|
|
47 |
|
|
sector++;
|
48 |
|
|
if ( sector > flash_sectors || sector == 0 ) {
|
49 |
|
|
sector = 1;
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
flash_write_init( 0 ); // prepare writing sector 0
|
53 |
|
|
flash_write((__xdata BYTE*) §or, 4); // write the current sector number
|
54 |
|
|
flash_write_finish_sector(flash_sector_size - 4); // dummy-write the rest of the sector + CRC
|
55 |
|
|
flash_write_finish(); // finish write operation
|
56 |
|
|
|
57 |
|
|
flash_write_init( sector ); // prepare writing sector sector
|
58 |
|
|
flash_write((__xdata BYTE*) flash_string, sizeof(flash_string)); // write the string
|
59 |
|
|
flash_write_finish_sector(flash_sector_size - sizeof(flash_string)); // dummy-write the rest of the sector + CRC
|
60 |
|
|
flash_write_finish(); // finish write operation
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
while (1) { } // twiddle thumbs
|
64 |
|
|
}
|
65 |
|
|
|