예제 #1
0
파일: main.cpp 프로젝트: 1deus/tmk_keyboard
int main() {
    led1 = 0;
    led2 = 0;
    uint32_t initial_handler, final_handler;
    Counter c;

    // Test chaining inside Serial class
    flipper_1.attach(&flip_1, 1.0); // the address of the function to be attached (flip) and the interval (1 second)
    flipper_2.attach(&flip_2, 2.0); // the address of the function to be attached (flip) and the interval (2 seconds)

    // Test global chaining (InterruptManager)
    printf("Handler initially: %08X\n", initial_handler = NVIC_GetVector(TIMER_IRQ));
    InterruptManager *pManager = InterruptManager::get();
    pFunctionPointer_t ptm = pManager->add_handler(testme, TIMER_IRQ);
    pFunctionPointer_t pinc = pManager->add_handler_front(&c, &Counter::inc, TIMER_IRQ);
    printf("Handler after calling InterruptManager: %08X\n", NVIC_GetVector(TIMER_IRQ));

    wait(4.0);

    if (!pManager->remove_handler(ptm, TIMER_IRQ) || !pManager->remove_handler(pinc, TIMER_IRQ)) {
        printf ("remove handler failed.\n");
        notify_completion(false);
    }
    printf("Interrupt handler calls: %d\n", c.get_count());
    printf("Handler after removing previously added functions: %08X\n", final_handler = NVIC_GetVector(TIMER_IRQ));

    if (initial_handler != final_handler) {
        printf( "InteruptManager test failed.\n");
        notify_completion(false);
    }

    while(1);
}
예제 #2
0
uint32_t vIRQ_GetVector(uint32_t irqn)
{
    if(__uvisor_mode == 0) {
        return NVIC_GetVector((IRQn_Type) irqn);
    }
    else {
        return UVISOR_SVC(UVISOR_SVC_ID_ISR_GET, "", irqn);
    }
}
예제 #3
0
static void
hal_gpio_set_nvic(IRQn_Type irqn)
{
    uint32_t isr;

    switch (irqn) {
    case EXTI0_IRQn:
        isr = (uint32_t)&ext_irq0;
        break;
    case EXTI1_IRQn:
        isr = (uint32_t)&ext_irq1;
        break;
    case EXTI2_TS_IRQn:
        isr = (uint32_t)&ext_irq2;
        break;
    case EXTI3_IRQn:
        isr = (uint32_t)&ext_irq3;
        break;
    case EXTI4_IRQn:
        isr = (uint32_t)&ext_irq4;
        break;
    case EXTI9_5_IRQn:
        isr = (uint32_t)&ext_irq9_5;
        break;
    case EXTI15_10_IRQn:
        isr = (uint32_t)&ext_irq15_10;
        break;
    default:
        assert(0);
        break;
    }

    /* Set isr in vector table if not yet set */
    if (NVIC_GetVector(irqn) != isr) {
        NVIC_SetVector(irqn, isr);
        NVIC_EnableIRQ(irqn);
    }
}
예제 #4
0
void
MODDMA::init(bool isConstructorCalling, int Channels, int Tc, int Err)
{
    if (isConstructorCalling) {    
        if (LPC_SC->PCONP & (1UL << 29)) {
            if (LPC_GPDMA->DMACConfig & 1) {
                error("Only one instance of MODDMA can exist.");
            }
        }
        LPC_SC->PCONP |= (1UL << 29);
        LPC_GPDMA->DMACConfig = 1;
        moddma_p = this;
        for (int i = 0; i < 8; i++) {
            setups[i] = (MODDMA_Config *)NULL;
        }        
    }
    
    // Reset channel configuration register(s)
    if (Channels & 0x01) LPC_GPDMACH0->DMACCConfig = 0;
    if (Channels & 0x02) LPC_GPDMACH1->DMACCConfig = 0;
    if (Channels & 0x04) LPC_GPDMACH2->DMACCConfig = 0;
    if (Channels & 0x08) LPC_GPDMACH3->DMACCConfig = 0;
    if (Channels & 0x10) LPC_GPDMACH4->DMACCConfig = 0;
    if (Channels & 0x20) LPC_GPDMACH5->DMACCConfig = 0;
    if (Channels & 0x40) LPC_GPDMACH6->DMACCConfig = 0;
    if (Channels & 0x80) LPC_GPDMACH7->DMACCConfig = 0;

    /* Clear DMA interrupt and error flag */
    LPC_GPDMA->DMACIntTCClear = Tc;
    LPC_GPDMA->DMACIntErrClr  = Err;
    
    if (isConstructorCalling) {    
        oldDMAHandler = NVIC_GetVector(DMA_IRQn);
        NVIC_SetVector(DMA_IRQn, (uint32_t)MODDMA_IRQHandler);
        NVIC_EnableIRQ(DMA_IRQn);
    }
}
void WakeUp::set_ms(uint32_t ms)
{
    /* Clock the timer */
    SIM->SCGC5 |= 0x1u;
    
    //Check if it is running, in that case, store current values
    remainder_count = 0;
    if (NVIC_GetVector(LPTimer_IRQn) != (uint32_t)WakeUp::irq_handler) {
        oldvector = NVIC_GetVector(LPTimer_IRQn);
        oldPSR = LPTMR0->PSR;
        
        if (LPTMR0->CSR & LPTMR_CSR_TIE_MASK) {
            //Write first to sync value
            LPTMR0->CNR = 0;
            uint16_t countval = LPTMR0->CNR;
            if (countval < LPTMR0->CMR)
                remainder_count = countval - LPTMR0->CMR;
        }
    }
    
    LPTMR0->CSR = 0;

    if (ms != 0) {
        /* Set interrupt handler */
        NVIC_SetVector(LPTimer_IRQn, (uint32_t)WakeUp::irq_handler);
        NVIC_EnableIRQ(LPTimer_IRQn);
        
        uint32_t counts;
        //Set clock
        if (is32kXtal()) {
            SIM->SOPT1 &= ~SIM_SOPT1_OSC32KSEL_MASK;    //Put RTC/LPTMR on 32kHz external. 
            #ifdef OSC0
            OSC0->CR |= OSC_CR_EREFSTEN_MASK;
            #else
            OSC->CR |= OSC_CR_EREFSTEN_MASK;
            #endif
            LPTMR0->PSR = LPTMR_PSR_PCS(2);
            counts = (uint32_t)((float)ms * 32.768f);
        } else {
            //Clock from the 1kHz LPO
            LPTMR0->PSR = LPTMR_PSR_PCS(1);
            counts = (uint32_t)((float)ms * cycles_per_ms);
        }
        
        //If no prescaler is needed
        if (counts <= 0xFFFF) 
            LPTMR0->PSR |= LPTMR_PSR_PBYP_MASK;
        else {        //Otherwise increase prescaler until it fits
            counts >>= 1;
            uint32_t prescaler = 0;
            while (counts > 0xFFFF) {
                counts >>= 1;
                prescaler++;
            }
            LPTMR0->PSR |= LPTMR_PSR_PRESCALE(prescaler);
        }
        LPTMR0->CMR = counts;        

        LPTMR0->CSR = LPTMR_CSR_TIE_MASK;
        LPTMR0->CSR |= LPTMR_CSR_TEN_MASK;
    } else {