[ create a new paste ] login | about

Link: http://codepad.org/gOepwaba    [ raw code | fork ]

C, pasted on Mar 17:
#define DBG_TEMPO_H sbi(PORTG, 0) // HIGH
#define DBG_TEMPO_L cbi(PORTG, 0) // LOW

somewhere in a function
{
														// stuff stuff ..
														
                            DBG_TEMPO_H;
                            sq_chain_end_R();
                            DBG_TEMPO_L;
                            
                            // other stuff stuff ..
}

inline void sq_chain_end_R(void)
{
    // this is called at end of chain when RUNNING
    // should happen at the last note-off of the current chain!
    uint8_t need_loadchain = 0;
    if (sellock <= 1)
    {
        if (chainCsect != chainNsect)
        {
            chainCsect = chainNsect;
            need_loadchain |= 0x01;
        }
        if (chain_peek())
        {
            chain_shift();
            need_loadchain |= 0x01;
        }
    }
    if (need_loadchain)
    {
        load_chain(chainCbank, chainCsect, chainCslot, chainClen, patbuf);
    }
    // shift the pitch-shift:
    if (pptN > 12) { pptN = 0; } // err, invalid pitch-shift
    pptC = pptN;
}

inline void load_chain(const uint8_t bank, const uint8_t sect, const uint8_t slot, const uint8_t len, volatile uint8_t *pat)
{
    const uint16_t offs = PATTERN_MEM + bank*BANK_SZ + (slot + NUM_SLOTS * sect) * PAT_SZ;
    spieeprom_read2(offs, len*PAT_SZ, pat);
}

inline void spieeprom_read2(uint16_t addr, uint8_t len, volatile uint8_t *ptr)
{
    // the datasheet says subsequent bytes can be read by just continuing..
    // it increments the address automatically.. so, as far as i understand - just pull CS high
    // after the last byte.. let's see..

    cli();

    // adding this to make it wait if currently writing:
    uint8_t status;
    do
    {
        cbi(SPIEE_CS_PORT, SPIEE_CS_PIN); // pull CS low
        NOP;
        NOP;
        NOP;
        NOP;

        SPDR = SPI_EEPROM_RDSR;
        while (!(SPSR & (1<<SPIF)));
        NOP;
        NOP;
        NOP;
        NOP;
        SPDR = 0;
        while (!(SPSR & (1<<SPIF)));
        status = SPDR;
        sbi(SPIEE_CS_PORT, SPIEE_CS_PIN); // pull CS high

        NOP;
        NOP;
        NOP;
        NOP;

    }
    while ((status & 0x1) != 0);
    // --------------------

    cbi(SPIEE_CS_PORT, SPIEE_CS_PIN); // pull CS low
    NOP;
    NOP;

    SPDR = SPI_EEPROM_READ;           // send command
    while (!(SPSR & (1<<SPIF)));

    SPDR = addr >> 8;                 // send high addr
    while (!(SPSR & (1<<SPIF)));

    SPDR = addr & 0xFF;               // send low addr
    while (!(SPSR & (1<<SPIF)));
    NOP;
    NOP;

    while (len--)
    {
        SPDR = 0;
        while (!(SPSR & (1<<SPIF)));
        *ptr = SPDR;
        ++ptr;
    }

    sbi(SPIEE_CS_PORT, SPIEE_CS_PIN); // pull CS high
    sei();
}


Create a new paste based on this one


Comments: