Ejemplo n.º 1
0
//------------------------------------------------------------------------------
void Sd2Card::chipSelectHigh(void) {
  digitalWrite(chipSelectPin_, HIGH);
#if defined(_BOARD_MEGA_) || defined(_BOARD_UNO_) || defined(_BOARD_UC32_)
  if(fspi_state_saved)
  {
    SPI2CON = spi_state;
    fspi_state_saved = false;
    restoreIntEnable(_EXTERNAL_1_IRQ, interrupt_state);
  }
#endif
}
Ejemplo n.º 2
0
//------------------------------------------------------------------------------
void altSDchipSelectHigh(uint8_t csPin) {
  digitalWrite(csPin, HIGH);

// On the WiFiShield it is possible for the MRF24 to get an interrupt that
// the PIC32 needs to service the MRF24 while the SD card is selected.
// If this happens the PIC32 MRF Universal Driver code provided by MCHP
// will make an SPI call in the interrupt routine, enabling the CS to the MRF which is on the same
// SPI pins as the SD card, thus causing bot the SD card and MRF24 to be enabled and thus
// causing a SDI/SDO data conflict and hosing both the SD and MRF
// The not so great, but working solution is to disable the MRF interrupt while
// the SD card is selected so the Univerdriver will not also select the MRF
  if(fspi_state_saved)
  {
    SPI2CON = spi_state;
    fspi_state_saved = false;
    restoreIntEnable(_EXTERNAL_1_IRQ, interrupt_state);
  }
}
Ejemplo n.º 3
0
void LowPower_::snooze(unsigned long ms) {
    uint32_t f_pb = getPeripheralClock();

    if (switchToLPRC()) {
        f_pb = 31250;
    }

    float baseclock = f_pb;
    uint8_t ps = 0;

    float f = 1.0 / (ms / 1000.0);

    if (baseclock / f > 0xFFFFFFFF) {
        baseclock = f_pb / 2;
        ps = 1;
    }

    if (baseclock / f > 0xFFFFFFFF) {
        baseclock = f_pb / 4;
        ps = 2;
    }

    if (baseclock / f > 0xFFFFFFFF) {
        baseclock = f_pb / 8;
        ps = 3;
    }

    if (baseclock / f > 0xFFFFFFFF) {
        baseclock = f_pb / 8;
        ps = 3;
    }

    if (baseclock / f > 0xFFFFFFFF) {
        baseclock = f_pb / 16;
        ps = 4;
    }

    if (baseclock / f > 0xFFFFFFFF) {
        baseclock = f_pb / 32;
        ps = 5;
    }

    if (baseclock / f > 0xFFFFFFFF) {
        baseclock = f_pb / 64;
        ps = 6;
    }

    if (baseclock / f > 0xFFFFFFFF) {
        baseclock = f_pb / 256;
        ps = 7;
    }

    uint32_t tcon4 = T4CON;
    uint32_t tpr4 = PR4;
    uint32_t tmr4 = TMR4;

    uint32_t tcon5 = T5CON;
    uint32_t tpr5 = PR5;
    uint32_t tmr5 = TMR5;

    int ipl;
    int spl;

    T4CON = 0;
    T5CON = 0;

    T4CONbits.TCKPS = ps;
    T4CONbits.T32 = 1;

    uint32_t pr = baseclock / f;

    PR4 = pr & 0xFFFF;
    PR5 = pr >> 16;

    isrFunc origIsr = setIntVector(_TIMER_5_VECTOR, _timerWakeup);
    getIntPriority(_TIMER_5_VECTOR, &ipl, &spl);
    setIntPriority(_TIMER_5_VECTOR, 5, 0);
    int en = setIntEnable(_TIMER_5_IRQ);
    clearIntFlag(_TIMER_5_IRQ);
    
    TMR4 = 0;
    TMR5 = 0;
    // If we're going to do this we need to ensure the two timers are enabled!
    enableTimer4();
    enableTimer5();

    int cten = clearIntEnable(_CORE_TIMER_IRQ);
    T4CONbits.TON = 1;
    enterIdleMode();
    restoreIntEnable(_CORE_TIMER_IRQ, cten);

    T4CONbits.TON = 0;
    setIntPriority(_TIMER_5_VECTOR, ipl, spl);
    setIntVector(_TIMER_5_VECTOR, origIsr);
    restoreIntEnable(_TIMER_5_IRQ, en);

    T5CON = tcon5;
    PR5 = tpr5;
    TMR5 = tmr5;
    T4CON = tcon4;
    PR4 = tpr4;
    TMR4 = tmr4;
    restoreSystemClock();
}