Line 1... |
Line 1... |
/*!
|
/*!
|
ZTEX Firmware Kit for EZ-USB FX2 Microcontrollers
|
ZTEX Firmware Kit for EZ-USB FX2 Microcontrollers
|
Copyright (C) 2009-2011 ZTEX GmbH.
|
Copyright (C) 2009-2014 ZTEX GmbH.
|
http://www.ztex.de
|
http://www.ztex.de
|
|
|
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
it under the terms of the GNU General Public License version 3 as
|
it under the terms of the GNU General Public License version 3 as
|
published by the Free Software Foundation.
|
published by the Free Software Foundation.
|
Line 50... |
Line 50... |
|
|
#ifndef[SPI_BIT_CLK]
|
#ifndef[SPI_BIT_CLK]
|
#error[SPI_BIT_CLK not defined]
|
#error[SPI_BIT_CLK not defined]
|
#endif
|
#endif
|
|
|
#ifndef[SPI_DOPORT]
|
#ifndef[SPI_OPORT]
|
#define[SPI_OPORT][SPI_PORT]
|
#define[SPI_OPORT][SPI_PORT]
|
#endif
|
#endif
|
|
|
#define[SPI_IO@][IOSPI_PORT]
|
#define[SPI_IO@][IOSPI_PORT]
|
#define[SPI_OIO@][IOSPI_OPORT]
|
#define[SPI_OIO@][IOSPI_OPORT]
|
Line 391... |
Line 391... |
BYTE flash_read_init(WORD s) {
|
BYTE flash_read_init(WORD s) {
|
if ( (SPI_CS) == 0 ) {
|
if ( (SPI_CS) == 0 ) {
|
flash_ec = FLASH_EC_PENDING;
|
flash_ec = FLASH_EC_PENDING;
|
return FLASH_EC_PENDING; // we interrupted a pending Flash operation
|
return FLASH_EC_PENDING; // we interrupted a pending Flash operation
|
}
|
}
|
|
OESPI_OPORT &= ~bmBITSPI_BIT_DO;
|
|
OESPI_PORT |= bmBITSPI_BIT_CS | bmBITSPI_BIT_DI | bmBITSPI_BIT_CLK;
|
if ( spi_wait() ) {
|
if ( spi_wait() ) {
|
return flash_ec;
|
return flash_ec;
|
}
|
}
|
|
|
s = s << ((BYTE)flash_sector_size - 8);
|
s = s << ((BYTE)flash_sector_size - 8);
|
Line 514... |
Line 516... |
BYTE flash_write_init(WORD s) {
|
BYTE flash_write_init(WORD s) {
|
if ( !SPI_CS ) {
|
if ( !SPI_CS ) {
|
flash_ec = FLASH_EC_PENDING;
|
flash_ec = FLASH_EC_PENDING;
|
return FLASH_EC_PENDING; // we interrupted a pending Flash operation
|
return FLASH_EC_PENDING; // we interrupted a pending Flash operation
|
}
|
}
|
|
OESPI_OPORT &= ~bmBITSPI_BIT_DO;
|
|
OESPI_PORT |= bmBITSPI_BIT_CS | bmBITSPI_BIT_DI | bmBITSPI_BIT_CLK;
|
if ( spi_wait() ) {
|
if ( spi_wait() ) {
|
return flash_ec;
|
return flash_ec;
|
}
|
}
|
spi_write_sector = s;
|
spi_write_sector = s;
|
s = s << ((BYTE)flash_sector_size - 8);
|
s = s << ((BYTE)flash_sector_size - 8);
|