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

Subversion Repositories usb_fpga_1_15

[/] [usb_fpga_1_15/] [trunk/] [include/] [ztex-fpga6.h] - Diff between revs 3 and 4

Only display areas with differences | Details | Blame | View Log

Rev 3 Rev 4
/*!
/*!
   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.
 
 
   This program is distributed in the hope that it will be useful, but
   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   General Public License for more details.
   General Public License for more details.
 
 
   You should have received a copy of the GNU General Public License
   You should have received a copy of the GNU General Public License
   along with this program; if not, see http://www.gnu.org/licenses/.
   along with this program; if not, see http://www.gnu.org/licenses/.
!*/
!*/
 
 
/*
/*
    FPGA support for ZTEX USB FPGA Modules 2.13 and 2.16
    FPGA support for ZTEX USB FPGA Modules 2.13 and 2.16
*/
*/
 
 
#ifndef[ZTEX_FPGA_H]
#ifndef[ZTEX_FPGA_H]
#define[ZTEX_FPGA_H]
#define[ZTEX_FPGA_H]
 
 
#define[@CAPABILITY_FPGA;]
#define[@CAPABILITY_FPGA;]
 
 
__xdata BYTE fpga_checksum;         // checksum
__xdata BYTE fpga_checksum;         // checksum
__xdata DWORD fpga_bytes;           // transfered bytes
__xdata DWORD fpga_bytes;           // transfered bytes
__xdata BYTE fpga_init_b;           // init_b state (should be 222 after configuration)
__xdata BYTE fpga_init_b;           // init_b state (should be 222 after configuration)
__xdata BYTE fpga_flash_result;     // result of automatic fpga configuarion from Flash
__xdata BYTE fpga_flash_result;     // result of automatic fpga configuarion from Flash
 
 
__xdata BYTE fpga_conf_initialized; // 123 if initialized
__xdata BYTE fpga_conf_initialized; // 123 if initialized
__xdata BYTE OOEC;
__xdata BYTE OOEC;
 
 
/* *********************************************************************
/* *********************************************************************
   ***** reset_fpga ****************************************************
   ***** reset_fpga ****************************************************
   ********************************************************************* */
   ********************************************************************* */
static void reset_fpga () {
static void reset_fpga () {
    OEE = bmBIT7;
    OEE = bmBIT7;
    IOE = 0;
    IOE = 0;
    wait(1);
    wait(1);
    OEE = 0;
    OEE = 0;
    fpga_conf_initialized = 0;
    fpga_conf_initialized = 0;
}
}
 
 
/* *********************************************************************
/* *********************************************************************
   ***** init_fpga *****************************************************
   ***** init_fpga *****************************************************
   ********************************************************************* */
   ********************************************************************* */
static void init_fpga () {
static void init_fpga () {
    if ( (IOE & bmBIT0) == 0 ) {
    if ( (IOE & bmBIT0) == 0 ) {
        // ensure that FPGA is in a proper configuration mode
        // ensure that FPGA is in a proper configuration mode
        OEE = bmBIT7;
        OEE = bmBIT7;
        IOE = 0;
        IOE = 0;
        wait(1);
        wait(1);
    }
    }
    OEE = 0;
    OEE = 0;
    fpga_conf_initialized = 0;
    fpga_conf_initialized = 0;
}
}
 
 
/* *********************************************************************
/* *********************************************************************
   ***** init_fpga_configuration ***************************************
   ***** init_fpga_configuration ***************************************
   ********************************************************************* */
   ********************************************************************* */
static void init_fpga_configuration () {
static void init_fpga_configuration () {
    unsigned short k;
    unsigned short k;
    {
    {
        PRE_FPGA_RESET
        PRE_FPGA_RESET
    }
    }
    IFCONFIG = bmBIT7;
    IFCONFIG = bmBIT7;
    SYNCDELAY;
    SYNCDELAY;
    PORTCCFG = 0;
    PORTCCFG = 0;
    PORTECFG = 0;
    PORTECFG = 0;
 
 
    OOEC = OEC;
    OOEC = OEC;
    fpga_conf_initialized = 123;
    fpga_conf_initialized = 123;
 
 
    OEC &= ~( bmBIT7 | bmBIT4);         // in: MOSI, MISO
    OEC &= ~( bmBIT7 | bmBIT4);         // in: MOSI, MISO
    OEC |= bmBIT6;                      // out: CCLK
    OEC |= bmBIT6;                      // out: CCLK
    IOC6 = 1;
    IOC6 = 1;
//  in:       INIT_B  DONE 
//  in:       INIT_B  DONE 
//  OEE &= ~( bmBIT1 | bmBIT0 );
//  OEE &= ~( bmBIT1 | bmBIT0 );
//  out:     CM0      CM1   RESET_N     CSI     RDWR
//  out:     CM0      CM1   RESET_N     CSI     RDWR
    OEE = bmBIT3 | bmBIT4 | bmBIT7 | bmBIT2 | bmBIT5;
    OEE = bmBIT3 | bmBIT4 | bmBIT7 | bmBIT2 | bmBIT5;
    IOE = bmBIT3;
    IOE = bmBIT3;
 
 
    wait(2);
    wait(2);
    IOE = bmBIT3 | bmBIT7;              // ready for configuration
    IOE = bmBIT3 | bmBIT7;              // ready for configuration
    IOC6 = 0;
    IOC6 = 0;
 
 
    k=0;
    k=0;
    while (!(IOE & bmBIT1) && k<65535)
    while (!(IOE & bmBIT1) && k<65535)
        k++;
        k++;
 
 
    fpga_init_b = (IOE & bmBIT1) ? 200 : 100;
    fpga_init_b = (IOE & bmBIT1) ? 200 : 100;
    fpga_bytes = 0;
    fpga_bytes = 0;
    fpga_checksum = 0;
    fpga_checksum = 0;
}
}
 
 
/* *********************************************************************
/* *********************************************************************
   ***** post_fpga_config **********************************************
   ***** post_fpga_config **********************************************
   ********************************************************************* */
   ********************************************************************* */
static void post_fpga_config () {
static void post_fpga_config () {
    POST_FPGA_CONFIG
    POST_FPGA_CONFIG
}
}
 
 
/* *********************************************************************
/* *********************************************************************
   ***** finish_fpga_configuration *************************************
   ***** finish_fpga_configuration *************************************
   ********************************************************************* */
   ********************************************************************* */
static void finish_fpga_configuration () {
static void finish_fpga_configuration () {
    BYTE w;
    BYTE w;
    fpga_init_b += (IOE & bmBIT1) ? 22 : 11;
    fpga_init_b += (IOE & bmBIT1) ? 22 : 11;
 
 
    for ( w=0; w<64; w++ ) {
    for ( w=0; w<64; w++ ) {
        IOC6 = 1; IOC6 = 0;
        IOC6 = 1; IOC6 = 0;
    }
    }
    IOE |= bmBIT2;              // CSI = 1
    IOE |= bmBIT2;              // CSI = 1
    IOC6 = 1; IOC6 = 0;
    IOC6 = 1; IOC6 = 0;
    IOC6 = 1; IOC6 = 0;
    IOC6 = 1; IOC6 = 0;
    IOC6 = 1; IOC6 = 0;
    IOC6 = 1; IOC6 = 0;
    IOC6 = 1; IOC6 = 0;
    IOC6 = 1; IOC6 = 0;
 
 
    OEE = 0;
    OEE = 0;
    OEC = OOEC;
    OEC = OOEC;
    if ( IOE & bmBIT0 )  {
    if ( IOE & bmBIT0 )  {
        post_fpga_config();
        post_fpga_config();
    }
    }
}
}
 
 
/* *********************************************************************
/* *********************************************************************
   ***** EP0 vendor request 0x30 ***************************************
   ***** EP0 vendor request 0x30 ***************************************
   ********************************************************************* */
   ********************************************************************* */
ADD_EP0_VENDOR_REQUEST((0x30,,          // get FPGA state
ADD_EP0_VENDOR_REQUEST((0x30,,          // get FPGA state
    MEM_COPY1(fpga_checksum,EP0BUF+1,7);
    MEM_COPY1(fpga_checksum,EP0BUF+1,7);
 
 
    if ( IOE & bmBIT0 )  {
    if ( IOE & bmBIT0 )  {
        EP0BUF[0] = 0;                    // FPGA configured 
        EP0BUF[0] = 0;                    // FPGA configured 
    }
    }
    else {
    else {
        EP0BUF[0] = 1;                   // FPGA unconfigured 
        EP0BUF[0] = 1;                   // FPGA unconfigured 
        OEE = 0;
        OEE = 0;
        reset_fpga();                   // prepare FPGA for configuration
        reset_fpga();                   // prepare FPGA for configuration
     }
     }
//    EP0BUF[8] = 0;                    // bit order for bitstream in Flash memory: non-swapped
//    EP0BUF[8] = 0;                    // bit order for bitstream in Flash memory: non-swapped
    EP0BUF[8] = 1;                      // bit order for bitstream in Flash memory: swapped
    EP0BUF[8] = 1;                      // bit order for bitstream in Flash memory: swapped
 
 
    EP0BCH = 0;
    EP0BCH = 0;
    EP0BCL = 9;
    EP0BCL = 9;
,,));;
,,));;
 
 
 
 
/* *********************************************************************
/* *********************************************************************
   ***** EP0 vendor command 0x31 ***************************************
   ***** EP0 vendor command 0x31 ***************************************
   ********************************************************************* */
   ********************************************************************* */
ADD_EP0_VENDOR_COMMAND((0x31,,reset_fpga();,,));;       // reset FPGA
ADD_EP0_VENDOR_COMMAND((0x31,,reset_fpga();,,));;       // reset FPGA
 
 
 
 
/* *********************************************************************
/* *********************************************************************
   ***** EP0 vendor command 0x32 ***************************************
   ***** EP0 vendor command 0x32 ***************************************
   ********************************************************************* */
   ********************************************************************* */
void fpga_send_ep0() {                  // send FPGA configuration data
void fpga_send_ep0() {                  // send FPGA configuration data
    BYTE oOEB;
    BYTE oOEB;
    oOEB = OEB;
    oOEB = OEB;
    OEB = 255;
    OEB = 255;
    fpga_bytes += ep0_payload_transfer;
    fpga_bytes += ep0_payload_transfer;
    __asm
    __asm
        mov     dptr,#_EP0BCL
        mov     dptr,#_EP0BCL
        movx    a,@dptr
        movx    a,@dptr
        jz      010000$
        jz      010000$
        mov     r2,a
        mov     r2,a
        mov     _AUTOPTRL1,#(_EP0BUF)
        mov     _AUTOPTRL1,#(_EP0BUF)
        mov     _AUTOPTRH1,#(_EP0BUF >> 8)
        mov     _AUTOPTRH1,#(_EP0BUF >> 8)
        mov     _AUTOPTRSETUP,#0x07
        mov     _AUTOPTRSETUP,#0x07
        mov     dptr,#_fpga_checksum
        mov     dptr,#_fpga_checksum
        movx    a,@dptr
        movx    a,@dptr
        mov     r1,a
        mov     r1,a
        mov     dptr,#_XAUTODAT1
        mov     dptr,#_XAUTODAT1
010001$:
010001$:
        movx    a,@dptr                 // 2
        movx    a,@dptr                 // 2
        mov     _IOB,a                  // 2
        mov     _IOB,a                  // 2
        setb    _IOC6                   // 2
        setb    _IOC6                   // 2
        add     a,r1                    // 1
        add     a,r1                    // 1
        mov     r1,a                    // 1
        mov     r1,a                    // 1
        clr     _IOC6                   // 2
        clr     _IOC6                   // 2
        djnz    r2, 010001$             // 4
        djnz    r2, 010001$             // 4
 
 
        mov     dptr,#_fpga_checksum
        mov     dptr,#_fpga_checksum
        mov     a,r1
        mov     a,r1
        movx    @dptr,a
        movx    @dptr,a
 
 
010000$:
010000$:
        __endasm;
        __endasm;
    OEB = oOEB;
    OEB = oOEB;
    if ( EP0BCL<64 ) {
    if ( EP0BCL<64 ) {
        finish_fpga_configuration();
        finish_fpga_configuration();
    }
    }
}
}
 
 
ADD_EP0_VENDOR_COMMAND((0x32,,          // send FPGA configuration data
ADD_EP0_VENDOR_COMMAND((0x32,,          // send FPGA configuration data
    if ( fpga_conf_initialized != 123 )
    if ( fpga_conf_initialized != 123 )
        init_fpga_configuration();
        init_fpga_configuration();
,,
,,
    fpga_send_ep0();
    fpga_send_ep0();
));;
));;
 
 
 
 
#ifdef[HS_FPGA_CONF_EP]
#ifdef[HS_FPGA_CONF_EP]
 
 
#ifeq[HS_FPGA_CONF_EP][2]
#ifeq[HS_FPGA_CONF_EP][2]
#elifeq[HS_FPGA_CONF_EP][4]
#elifeq[HS_FPGA_CONF_EP][4]
#elifeq[HS_FPGA_CONF_EP][6]
#elifeq[HS_FPGA_CONF_EP][6]
#elifneq[HS_FPGA_CONF_EP][8]
#elifneq[HS_FPGA_CONF_EP][8]
#error[`HS_FPGA_CONF_EP' is not defined correctly. Valid values are: `2', `4', `6', `8'.]
#error[`HS_FPGA_CONF_EP' is not defined correctly. Valid values are: `2', `4', `6', `8'.]
#endif
#endif
 
 
#define[@CAPABILITY_HS_FPGA;]
#define[@CAPABILITY_HS_FPGA;]
 
 
/* *********************************************************************
/* *********************************************************************
   ***** EP0 vendor request 0x33 ***************************************
   ***** EP0 vendor request 0x33 ***************************************
   ********************************************************************* */
   ********************************************************************* */
ADD_EP0_VENDOR_REQUEST((0x33,,          // get high speed fpga configuration endpoint and interface 
ADD_EP0_VENDOR_REQUEST((0x33,,          // get high speed fpga configuration endpoint and interface 
    EP0BUF[0] = HS_FPGA_CONF_EP; // endpoint
    EP0BUF[0] = HS_FPGA_CONF_EP; // endpoint
    EP0BUF[1] = EPHS_FPGA_CONF_EP_INTERFACE; // interface
    EP0BUF[1] = EPHS_FPGA_CONF_EP_INTERFACE; // interface
    EP0BCH = 0;
    EP0BCH = 0;
    EP0BCL = 2;
    EP0BCL = 2;
,,));;
,,));;
 
 
 
 
/* *********************************************************************
/* *********************************************************************
   ***** EP0 vendor command 0x34 ***************************************
   ***** EP0 vendor command 0x34 ***************************************
   ********************************************************************* */
   ********************************************************************* */
// FIFO write wave form
// FIFO write wave form
const char __xdata GPIF_WAVE_DATA_HSFPGA_24MHZ[32] =
const char __xdata GPIF_WAVE_DATA_HSFPGA_24MHZ[32] =
{
{
/* LenBr */ 0x01,     0x88,     0x01,     0x01,     0x01,     0x01,     0x01,     0x07,
/* LenBr */ 0x01,     0x88,     0x01,     0x01,     0x01,     0x01,     0x01,     0x07,
/* Opcode*/ 0x02,     0x07,     0x02,     0x02,     0x02,     0x02,     0x02,     0x00,
/* Opcode*/ 0x02,     0x07,     0x02,     0x02,     0x02,     0x02,     0x02,     0x00,
/* Output*/ 0x20,     0x00,     0x00,     0x00,     0x00,     0x00,     0x00,     0x20,
/* Output*/ 0x20,     0x00,     0x00,     0x00,     0x00,     0x00,     0x00,     0x20,
/* LFun  */ 0x00,     0x36,     0x00,     0x00,     0x00,     0x00,     0x00,     0x3F,
/* LFun  */ 0x00,     0x36,     0x00,     0x00,     0x00,     0x00,     0x00,     0x3F,
};
};
 
 
const char __xdata GPIF_WAVE_DATA_HSFPGA_12MHZ[32] =
const char __xdata GPIF_WAVE_DATA_HSFPGA_12MHZ[32] =
{
{
/* LenBr */ 0x02,     0x01,     0x90,     0x01,     0x01,     0x01,     0x01,     0x07,
/* LenBr */ 0x02,     0x01,     0x90,     0x01,     0x01,     0x01,     0x01,     0x07,
/* Opcode*/ 0x02,     0x02,     0x07,     0x02,     0x02,     0x02,     0x02,     0x00,
/* Opcode*/ 0x02,     0x02,     0x07,     0x02,     0x02,     0x02,     0x02,     0x00,
/* Output*/ 0x20,     0x00,     0x00,     0x00,     0x00,     0x00,     0x00,     0x20,
/* Output*/ 0x20,     0x00,     0x00,     0x00,     0x00,     0x00,     0x00,     0x20,
/* LFun  */ 0x00,     0x00,     0x36,     0x00,     0x00,     0x00,     0x00,     0x3F,
/* LFun  */ 0x00,     0x00,     0x36,     0x00,     0x00,     0x00,     0x00,     0x3F,
};
};
 
 
 
 
void init_cpld_fpga_configuration() {
void init_cpld_fpga_configuration() {
    IFCONFIG = bmBIT7 | bmBIT6 | 2;     // Internal source, 48MHz, GPIF
    IFCONFIG = bmBIT7 | bmBIT6 | 2;     // Internal source, 48MHz, GPIF
 
 
    GPIFREADYCFG = 0;
    GPIFREADYCFG = 0;
    GPIFCTLCFG = 0x0;
    GPIFCTLCFG = 0x0;
    GPIFIDLECS = 0;
    GPIFIDLECS = 0;
    GPIFIDLECTL = 4;
    GPIFIDLECTL = 4;
    GPIFWFSELECT = 0x4E;
    GPIFWFSELECT = 0x4E;
    GPIFREADYSTAT = 0;
    GPIFREADYSTAT = 0;
 
 
    MEM_COPY1(GPIF_WAVE_DATA_HSFPGA_24MHZ,GPIF_WAVE3_DATA,32);
    MEM_COPY1(GPIF_WAVE_DATA_HSFPGA_24MHZ,GPIF_WAVE3_DATA,32);
 
 
    FLOWSTATE = 0;
    FLOWSTATE = 0;
    FLOWLOGIC = 0x10;
    FLOWLOGIC = 0x10;
    FLOWEQ0CTL = 0;
    FLOWEQ0CTL = 0;
    FLOWEQ1CTL = 0;
    FLOWEQ1CTL = 0;
    FLOWHOLDOFF = 0;
    FLOWHOLDOFF = 0;
    FLOWSTB = 0;
    FLOWSTB = 0;
    FLOWSTBEDGE = 0;
    FLOWSTBEDGE = 0;
    FLOWSTBHPERIOD = 0;
    FLOWSTBHPERIOD = 0;
 
 
    REVCTL = 0x1;                               // reset fifo
    REVCTL = 0x1;                               // reset fifo
    SYNCDELAY;
    SYNCDELAY;
    FIFORESET = 0x80;
    FIFORESET = 0x80;
    SYNCDELAY;
    SYNCDELAY;
    FIFORESET = HS_FPGA_CONF_EP;
    FIFORESET = HS_FPGA_CONF_EP;
    SYNCDELAY;
    SYNCDELAY;
    FIFORESET = 0x0;
    FIFORESET = 0x0;
    SYNCDELAY;
    SYNCDELAY;
 
 
    EPHS_FPGA_CONF_EPFIFOCFG = 0;                // config fifo
    EPHS_FPGA_CONF_EPFIFOCFG = 0;                // config fifo
    SYNCDELAY;
    SYNCDELAY;
    EPHS_FPGA_CONF_EPFIFOCFG = bmBIT4 | 0;
    EPHS_FPGA_CONF_EPFIFOCFG = bmBIT4 | 0;
    SYNCDELAY;
    SYNCDELAY;
    EPHS_FPGA_CONF_EPGPIFFLGSEL = 1;
    EPHS_FPGA_CONF_EPGPIFFLGSEL = 1;
    SYNCDELAY;
    SYNCDELAY;
 
 
    GPIFTCB3 = 1;                               // abort after at least 14*65536 transactions
    GPIFTCB3 = 1;                               // abort after at least 14*65536 transactions
    SYNCDELAY;
    SYNCDELAY;
    GPIFTCB2 = 0;
    GPIFTCB2 = 0;
    SYNCDELAY;
    SYNCDELAY;
    GPIFTCB1 = 0;
    GPIFTCB1 = 0;
    SYNCDELAY;
    SYNCDELAY;
    GPIFTCB0 = 0;
    GPIFTCB0 = 0;
    SYNCDELAY;
    SYNCDELAY;
 
 
    EPHS_FPGA_CONF_EPGPIFTRIG = 0xff;           // arm fifos
    EPHS_FPGA_CONF_EPGPIFTRIG = 0xff;           // arm fifos
    SYNCDELAY;
    SYNCDELAY;
 
 
    OEC &= ~bmBIT6;                             // disable CCLK output
    OEC &= ~bmBIT6;                             // disable CCLK output
    IOE = bmBIT4 | bmBIT7;                      // HS config mode
    IOE = bmBIT4 | bmBIT7;                      // HS config mode
}
}
 
 
 
 
ADD_EP0_VENDOR_COMMAND((0x34,,                  // init fpga configuration
ADD_EP0_VENDOR_COMMAND((0x34,,                  // init fpga configuration
    init_fpga_configuration();
    init_fpga_configuration();
 
 
    EPHS_FPGA_CONF_EPCS &= ~bmBIT0;             // clear stall bit
    EPHS_FPGA_CONF_EPCS &= ~bmBIT0;             // clear stall bit
 
 
    GPIFABORT = 0xFF;                           // abort pendig 
    GPIFABORT = 0xFF;                           // abort pendig 
 
 
    init_cpld_fpga_configuration();
    init_cpld_fpga_configuration();
 
 
,,));;
,,));;
 
 
 
 
/* *********************************************************************
/* *********************************************************************
   ***** EP0 vendor command 0x35 ***************************************
   ***** EP0 vendor command 0x35 ***************************************
   ********************************************************************* */
   ********************************************************************* */
ADD_EP0_VENDOR_COMMAND((0x35,,          // finish fpga configuration
ADD_EP0_VENDOR_COMMAND((0x35,,          // finish fpga configuration
    IOE = bmBIT3 | bmBIT7;
    IOE = bmBIT3 | bmBIT7;
    OEC |= bmBIT6;                      // out: CCLK
    OEC |= bmBIT6;                      // out: CCLK
 
 
    GPIFABORT = 0xFF;
    GPIFABORT = 0xFF;
    SYNCDELAY;
    SYNCDELAY;
    IFCONFIG &= 0xf0;
    IFCONFIG &= 0xf0;
    SYNCDELAY;
    SYNCDELAY;
 
 
    finish_fpga_configuration();
    finish_fpga_configuration();
,,));;
,,));;
 
 
#endif  // HS_FPGA_CONF_EP
#endif  // HS_FPGA_CONF_EP
 
 
#ifeq[FLASH_BITSTREAM_ENABLED][1]
#ifeq[FLASH_BITSTREAM_ENABLED][1]
/* *********************************************************************
/* *********************************************************************
   ***** fpga_configure_from_flash *************************************
   ***** fpga_configure_from_flash *************************************
   ********************************************************************* */
   ********************************************************************* */
/*
/*
    Configure the FPGA using a bitstream from flash.
    Configure the FPGA using a bitstream from flash.
    If force == 0 a already configured FPGA is not re-configured.
    If force == 0 a already configured FPGA is not re-configured.
    Return values:
    Return values:
        0 : Configuration successful
        0 : Configuration successful
        1 : FPGA already configured
        1 : FPGA already configured
        4 : Configuration error
        4 : Configuration error
*/
*/
#define[SPI_CS][IOSPI_PORTSPI_BIT_CS]
#define[SPI_CS][IOSPI_PORTSPI_BIT_CS]
#define[SPI_PORT][C]
#define[SPI_PORT][C]
#define[SPI_BIT_DO][4]
#define[SPI_BIT_DO][4]
#define[SPI_BIT_CS][5]
#define[SPI_BIT_CS][5]
#define[SPI_BIT_CLK][6]
#define[SPI_BIT_CLK][6]
#define[SPI_BIT_DI][7]
#define[SPI_BIT_DI][7]
 
 
BYTE fpga_configure_from_flash( BYTE force) {
BYTE fpga_configure_from_flash( BYTE force) {
    BYTE c;
    BYTE c;
    WORD i;
    WORD i;
 
 
    if ( ( force == 0 ) && ( IOE & bmBIT0 ) ) {
    if ( ( force == 0 ) && ( IOE & bmBIT0 ) ) {
        fpga_flash_result = 1;
        fpga_flash_result = 1;
        return 1;
        return 1;
    }
    }
 
 
    fpga_flash_result = 0;
    fpga_flash_result = 0;
 
 
    c = OESPI_PORT;
    c = OESPI_PORT;
    OESPI_PORT &= ~( bmBITSPI_BIT_CS | bmBITSPI_BIT_DI | bmBITSPI_BIT_CLK );    // disable SPI outputs
    OESPI_PORT &= ~( bmBITSPI_BIT_CS | bmBITSPI_BIT_DI | bmBITSPI_BIT_CLK );    // disable SPI outputs
 
 
    {
    {
        PRE_FPGA_RESET
        PRE_FPGA_RESET
    }
    }
 
 
// reset FPGA and start configuration from flash
// reset FPGA and start configuration from flash
//  out:     CM0      CM1   RESET_N     CSI     RDWR
//  out:     CM0      CM1   RESET_N     CSI     RDWR
    OEE = bmBIT3 | bmBIT4 | bmBIT7;
    OEE = bmBIT3 | bmBIT4 | bmBIT7;
    IOE = 0;
    IOE = 0;
    wait(1);
    wait(1);
    IOE = bmBIT7;
    IOE = bmBIT7;
 
 
// wait up to 10s for CS going high
// wait up to 10s for CS going high
    wait(10);
    wait(10);
    for (i=0; (IOE & bmBIT1) && (SPI_CS==0) && i<10000; i++ ) {
    for (i=0; (IOE & bmBIT1) && (SPI_CS==0) && i<10000; i++ ) {
        wait(1);
        wait(1);
    }
    }
 
 
    wait(1);
    wait(1);
 
 
    if ( IOE & bmBIT0 )  {
    if ( IOE & bmBIT0 )  {
        post_fpga_config();
        post_fpga_config();
    }
    }
    else {
    else {
        IOE =  bmBIT3 | bmBIT4; // leave master SPI config mode
        IOE =  bmBIT3 | bmBIT4; // leave master SPI config mode
        wait(1);
        wait(1);
        fpga_flash_result = 4;
        fpga_flash_result = 4;
    }
    }
    OEE = 0;
    OEE = 0;
 
 
    OESPI_PORT = c;
    OESPI_PORT = c;
    SPI_CS = 1;
    SPI_CS = 1;
 
 
    return fpga_flash_result;
    return fpga_flash_result;
}
}
 
 
#include[ztex-fpga-flash2.h]
#include[ztex-fpga-flash2.h]
 
 
#endif
#endif
 
 
 
 
#endif  /*ZTEX_FPGA_H*/
#endif  /*ZTEX_FPGA_H*/
 
 

powered by: WebSVN 2.1.0

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