Example #1
0
//************************************************************************
void disableTimer(uint8_t _timer)
{
    clearIntEnable(_TIMER_1_IRQ);
    T1CON		=	0;
    tone_pin	=	255;
    clearIntVector(_TIMER_1_VECTOR);
}
Example #2
0
//************************************************************************
void disableTimer(uint8_t _timer)
{
    // Added to prevent compiler warning about unused paraemer
    (void)_timer;
    
    clearIntEnable(_TIMER_1_IRQ);
    T1CON		=	0;
    tone_pin	=	255;
    clearIntVector(_TIMER_1_VECTOR);
}
Example #3
0
//------------------------------------------------------------------------------
void Sd2Card::chipSelectLow(void) {
#if defined(_BOARD_MEGA_) || defined(_BOARD_UNO_) || defined(_BOARD_UC32_)
    if(!fspi_state_saved)
    {
        interrupt_state = clearIntEnable(_EXTERNAL_1_IRQ);
        spi_state = SPI2CON;
        SPI2CONbits.ON = 0; 
        fspi_state_saved = true;
    }
#endif
  digitalWrite(chipSelectPin_, LOW);
}
//------------------------------------------------------------------------------
void altSDchipSelectLow(uint8_t csPin) {
// 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)
    {
        interrupt_state = clearIntEnable(_EXTERNAL_1_IRQ);
        spi_state = SPI2CON;
        SPI2CONbits.ON = 0; 
        fspi_state_saved = true;
    }
  digitalWrite(csPin, LOW);
}
Example #5
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();
}
Example #6
0
void VGA::initializeDevice() {
    _vgaDevice = this;
    if (_hsync_pin == 0 || _vsync_pin == 0) {
        return;
    }

    memset((void *)_buffer0, 0, ((Width/8)+1) * Height);

#if VGA_USE_DOUBLE_BUFFER
    memset((void *)_buffer1, 0, ((Width/8)+1) * Height);
    bufferNumber = 0;
    activeBuffer = _buffer0;
    vgaBuffer = _buffer1;
#else
    bufferNumber = 0;
    activeBuffer = _buffer0;
    vgaBuffer = _buffer0;
#endif

    _hsync_port->tris.clr = _hsync_pin;
    _vsync_port->tris.clr = _vsync_pin;

    // First we need to set up a timer that will trigger at the different times.
    T2CONbits.TCKPS = 0; // No prescaler
    PR2 = 0xFFFF;

    setIntVector(_TIMER_2_VECTOR, vgaProcess);
    setIntPriority(_TIMER_2_VECTOR, 6, 0);
    clearIntFlag(_TIMER_2_IRQ);
    setIntEnable(_TIMER_2_IRQ);

    // Now congfigure SPI4 for display data transmission.
    SPI4CON = 0;
    SPI4CONbits.MSTEN = 1;
    SPI4CONbits.STXISEL = 0b11; // Interrupt when one byte in buffer
#if VGA_USE_HI_RES
    SPI4BRG = 0; // This will set how big each pixel is.
#else
    SPI4BRG = 1; // This will set how big each pixel is.
#endif
    SPI4CONbits.ON = 1;

    // And now a DMA channel for transferring the data
    DCH0SSA = ((unsigned int)vgaBuffer) & 0x1FFFFFFF;
    DCH0DSA = ((unsigned int)&SPI4BUF) & 0x1FFFFFFF;
    DCH0SSIZ = (Width / 8) + 1;
    DCH0DSIZ = 1;
    DCH0CSIZ = 1;
    DCH0ECONbits.SIRQEN = 1;
    DCH0ECONbits.CHSIRQ = _SPI4_TX_IRQ;
    DCH0CONbits.CHAEN = 0;
    DCH0CONbits.CHEN = 0;
    DCH0CONbits.CHPRI = 3;

    vgaVsyncPort = _vsync_port;
    vgaHsyncPort = _hsync_port;
    vgaVsyncMask = _vsync_pin;
    vgaHsyncMask = _hsync_pin;
    vgaWidth = (Width/8) + 1;
    vgaHeight = Height;
    vgaBufSize = vgaWidth * vgaHeight;

    clearIntEnable(_CORE_TIMER_IRQ);
//    setIntPriority(_CORE_TIMER_VECTOR, 5, 0);

    VSYNC_OFF
    HSYNC_OFF

    DMACONbits.ON = 1;
    T2CONbits.ON = 1; // Turn on the timer
}