1. This forum section is a read-only archive which contains old newsgroup posts. If you wish to post a query, please do so in one of our main forum sections (here). This way you will get a faster, better response from the members on Motherboard Point.

CY7C68013A (Cypres USB 2.0 FX2LP chip). Not the same as the non LP version?

Discussion in 'Embedded' started by Bill Davy, Jun 30, 2005.

  1. Bill Davy

    Bill Davy Guest

    Hi,

    I've downloaded identical software to the FX2 development board (SDK) which
    has the non LP version, and our own FX2LP based board (let's call it SYN).

    The SDK works fine as it has been for months. The SYN board behaves oddly.

    The following behaviour is the same whether I download to the RAM (using the
    Anchor 0xA0 command) or download it into EEPROM as a C2 program and hit
    reset.

    In main(), I set various things up, and then call a routine to print a
    string. On SDK it happily prints "Port 0 12:24:00 on 23 June 2005\n\r". On
    SYN it prints every fifth chracter (starting with P).

    I've used the breakpoint (see BREAKPT in InitialiseUart()) to see how many
    times PutUart() is called and it is called the right number of times. Then
    I used the breakpoint to see how many times UsartISR() is called and it is
    called just seven times as each character has been sent.

    For what it's worth, hitting a key on the keyboard also causes a UART
    interrupt, but the code is not echoing it (done at a higher level than in
    the UART ISR). Again, it works on SDK but not SDK.

    Anybody know of ANY differences bewteen the FX2 and the FX2LP? Although
    it's not relevant now, when I get the LP going, I'd like to know what has
    happened to the REVID register.

    tia,
    Bill

    -------------------
    void main(void)
    {
    // Initialize Global States
    Sleep = FALSE; // Disable sleep mode
    Rwuen = FALSE; // Disable remote wakeup
    Selfpwr = FALSE; // Disable self powered
    GotSUD = FALSE; // Clear "Got setup data" flag

    memset(&CypressStatusPage,0,sizeof(CypressStatusPage));
    CypressStatusPage.Date[0] = __DATE2__ [3]; // dd
    CypressStatusPage.Date[1] = __DATE2__ [4];
    CypressStatusPage.Date[2] = __DATE2__ [0]; // mm
    CypressStatusPage.Date[3] = __DATE2__ [1];
    CypressStatusPage.Date[4] = __DATE2__ [6]; // yy
    CypressStatusPage.Date[5] = __DATE2__ [7];
    CypressStatusPage.Time[0] = __TIME__ [0]; // hh
    CypressStatusPage.Time[1] = __TIME__ [1];
    CypressStatusPage.Time[2] = __TIME__ [3]; // mm
    CypressStatusPage.Time[3] = __TIME__ [4];
    CypressStatusPage.VersionHi = VERSION_HI_NIBBLE;
    CypressStatusPage.VersionLo = VERSION_LO_NIBBLE;
    CypressStatusPage.ChipRevision = REVID; // From hardware register
    CypressStatusPage.EepromId = I2CS>>3;

    memset(&ArmVideoPage,0,sizeof(ArmVideoPage));

    // Initialize user device
    TD_Init();

    if ( EZUSB_HIGHSPEED() )
    {
    pConfigDscr = (WORD)&HighSpeedConfigDscr;
    pOtherConfigDscr = (WORD)&FullSpeedConfigDscr;
    }
    else
    {
    pConfigDscr = (WORD)&FullSpeedConfigDscr;
    pOtherConfigDscr = (WORD)&HighSpeedConfigDscr;
    }

    EZUSB_IRQ_ENABLE(); // Enable USB interrupt (INT2)
    EZUSB_ENABLE_RSMIRQ(); // Wake-up interrupt

    INTSETUP |= (bmAV2EN | bmAV4EN); // Enable INT 2 & 4 autovectoring

    USBIE |= bmSUDAV | bmSUTOK | bmSUSP | bmURES | bmHSGRANT; // Enable
    selected interrupts

    //
    // RWD
    //
    /* setup the timer 0 interrupt */
    TH0 = (unsigned char) TIMER0_PERIOD; /* set timer period
    */
    TL0 = (unsigned char) TIMER0_PERIOD;
    TMOD = TMOD | 0x02; /* select mode 2
    */
    TR0 = 1; /* start timer 0
    */
    ET0 = 1; /* enable timer 0 interrupt
    */

    //
    // RWD, 4 April, 2005
    //
    InitialiseUart();

    PutsUart("Port 0 " __TIME__ " on " __DATE__ "\n");

    ....

    ----------------------------

    //
    // File: Usart.c
    // Author: Bill Davy
    // Copyright: Synectix Limited, 2005. All rights reserved.
    //
    // Interrupt driven serial port code.
    #include "fx2.h"
    #include "fx2regs.h"
    #include "string.h"
    #include "Usart.h"

    #ifdef USE_UART

    void PutUnsignedUart(unsigned int Value)
    {
    char s[sizeof(Value)*2+1];
    char *p = s+sizeof(Value)*2+1;
    *--p = '\0';
    do
    {
    *--p = "0123456789ABCDEF"[Value & 0xF];
    Value >>= 4;
    }
    while (Value);
    PutsUart(p);
    }

    void AssertFail(const char *Condition, const char *File, const int Line)
    {
    PutsUart(Condition);
    PutsUart(" is false, at ");
    PutUnsignedUart(Line);
    PutsUart(" in ");
    PutsUart(File);
    PutsUart("\n");
    }

    typedef unsigned char u8;

    //
    // These are the buffer size and mask (used to make index modulo size)
    //
    #define SizeMask 0x3F
    #define Size 0x40

    //
    // There are problems with calling the same function from ISR and normal
    code
    // (L15 error). It should be OK because serial interrupt was always turned
    off
    // when the function was called from non ISR code, but it did not seem
    happy.
    // So [Put|Get]([Tx|Rx]) became macros
    //
    // We use a null character to indicate a slot in the buffer is free.
    // It terminates strings we send and is used to signal there is
    // nothing from the receiver. Prevent users putting a null in.
    //

    #define GET(Direction,Character) \
    {\
    if ( (Character = Buffer ## Direction [Out ## Direction]) != 0 )\
    {\
    Buffer ## Direction [Out ## Direction ++] = 0;\
    Out ## Direction &= SizeMask;\
    }\
    }

    #define PUT(Direction,Character) \
    {\
    if ( Buffer ## Direction[In ## Direction] == 0 && Character != 0)\
    {\
    Buffer ## Direction[In ## Direction ++] = Character;\
    In ## Direction &= SizeMask;\
    }\
    }

    xdata u8 BufferRx[Size];
    u8 OutRx, InRx;
    xdata u8 BufferTx[Size];
    u8 OutTx, InTx;

    //
    // The state of the tx register in the UART
    // You cannot use TI for this as (I suspect) it just keeps the processor in
    // a tight interrupt loop (certainly it did nothing useful). So, level
    triggered
    // rather than edge triggered.
    //
    bit Tx0RegisterEmpty;


    void PutsUart(const char *s)
    {

    for(;;)
    {
    const char c = *s++;
    if ( ! c )
    return;
    if ( c == '\n' )
    PutUart('\r'); // turn lf into cr/lf
    PutUart(c);
    }
    }

    void PutUart(char c)
    {
    ES0 = 0;
    if ( Tx0RegisterEmpty )
    {
    //
    // Start sending (TI should be zero)
    //
    SBUF0 = c;
    Tx0RegisterEmpty = FALSE;
    }
    else
    PUT(Tx,c); // buffer it
    ES0 = 1;
    }

    char GetUart(void)
    {
    char c;
    ES0 = 0;
    GET(Rx,c);
    ES0 = 1;
    return c;
    }

    void UsartISR(void) interrupt COM0_VECT using 2
    {
    if ( TI )
    {
    char c;

    TI = 0; // clear the interrupt
    Tx0RegisterEmpty = TRUE; // the transmit register is now empty

    GET(Tx,c);
    if ( c )
    {
    SBUF0 = c;
    Tx0RegisterEmpty = FALSE;
    }
    }

    if ( RI )
    {
    const char c = SBUF0;

    RI = 0;
    PUT(Rx,c);
    }
    }

    void InitialiseUart(void)
    {
    {
    char code *pc = (void*)UsartISR;
    BPADDRH = (unsigned int)pc>>8;
    BPADDRL = (unsigned int)pc;
    BREAKPT = 6;
    }

    //
    // RWD, 4 April, 2005
    //
    OutRx = InRx = 0; memset(BufferRx,0,sizeof(BufferRx));
    OutTx = InTx = 0; memset(BufferTx,0,sizeof(BufferTx));

    UART230 |= 1; // High Speed Baud Rate Generator [HSBRG] enabled

    PCON |= 0x80; // Select fast HSBRG [230K]

    SM0 = 0; SM1 = 1; // Mode 1 (start, 8 data, stop)

    SM2 = 0; // Disable mutliprocessor communication

    REN = 1; // Enable receiver

    TI = 0; // Clear transmitter interrupt
    Tx0RegisterEmpty = 1;// Tx buffer is empty

    {
    const char c = SBUF0;// Empty the buffer
    RI = 0; // Clear receiver interrupt
    }

    ES0 = 1; // Enable serial port interrupt
    }
    #endif // defined(USE_UART)
     
    Bill Davy, Jun 30, 2005
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.