void SW3_InterruptCB(void) { bool err = true; uint8_t status = 0x00; // Fetch input edge status err &= R_INTC_GetExtInterruptStatus ( PDL_INTC_IRQ4, &status ); // Check if interrupt was triggered from falling edge if((status & 0x0C) == 0x04) { // Disable switch interrupts and change to rising edge detection err &= R_INTC_ControlExtInterrupt ( PDL_INTC_IRQ4, PDL_INTC_DISABLE|PDL_INTC_RISING ); // Check if switch press callback function is not NULL if(SwitchPressCallbackFunc) { // Execute user callback function SwitchPressCallbackFunc(SWITCH_3); } } else { // Switch to falling edge detection err &= R_INTC_ControlExtInterrupt ( PDL_INTC_IRQ4, PDL_INTC_FALLING ); if(SwitchReleaseCallbackFunc) { SwitchReleaseCallbackFunc(SWITCH_3); } } // Create 10ms one-shot timer interrupt to de-bounce the switch input err &= R_CMT_CreateOneShot ( 1, PDL_NO_DATA, 10E-3, SwitchDebounceCB, 8 ); while(!err) ; }
void ConfigureOperatingFrequency(void) { bool err = true; //Configure the PLL to use the 20.0 MHz crystal as clock input err &= R_CGC_Set ( PDL_CGC_CLK_MAIN, PDL_CGC_BCLK_DIV_1 | PDL_CGC_MAIN_RESONATOR, 20E6, 20E6, 20E6, 20E6, 20E6, PDL_NO_DATA ); /* Configure the clocks as follows - Clock Description Frequency ---------------------------------------- PLL Clock frequency...............100MHz System Clock Frequency.............50MHz Peripheral Module Clock B..........25MHz Peripheral Module Clock D..........50MHz FlashIF Clock......................25MHz External Bus Clock.................25MHz */ err &= R_CGC_Set ( PDL_CGC_CLK_PLL, PDL_CGC_BCLK_DIV_2, 100E6, 50E6, 50E6, 25E6, 25E6, 25E6 ); // Allow 100us for the main clock to stabilize err &= R_CMT_CreateOneShot ( 0, PDL_NO_DATA, 100E-6, PDL_NO_FUNC, 0 ); // Change to high-speed operating mode err &= R_LPC_Control( PDL_LPC_CHANGE_HIGH_SPEED ); // Select the PLL as the clock source err &= R_CGC_Control ( PDL_CGC_CLK_PLL, PDL_CGC_SUB_CLOCK_CL_STANDARD, PDL_CGC_SUB_CLOCK_ENABLE ); while(!err) ; }
/****************************************************************************** * Outline : SW3_InterruptCB * Description : Switch 3 callback ISR function. The function disables switch * interrupts, then uses a oneshot timer to re-enable them after * a 10ms debounce timer period. * Argument : none * Return value : none ******************************************************************************/ void SW3_InterruptCB(void) { /* Declare error flag */ bool err = true; /* Declare status container variable */ uint8_t status = 0x00; /* Fetch input edge status */ err &= R_INTC_GetExtInterruptStatus ( PDL_INTC_IRQ10, &status ); /* Check if interrupt was triggered from falling edge */ if ((status & 0x06) == 0x04) { /* Disable switch interrupts and change to rising edge detection */ err &= R_INTC_ControlExtInterrupt ( PDL_INTC_IRQ10, PDL_INTC_DISABLE | PDL_INTC_RISING ); /* Set global switch flag to indicate SW3 is held down */ gSwitchFlag |= 0x02; /* Check if switch press callback function is not NULL */ if (gSwitchPressCallbackFunc) { /* Execute user callback function */ gSwitchPressCallbackFunc(); } } else { /* Switch to falling edge detection */ err &= R_INTC_ControlExtInterrupt ( PDL_INTC_IRQ10, PDL_INTC_FALLING ); /* Clear SW3 held-down bit in switch flag */ gSwitchFlag &= 0xFD; /* Set global switch flag to indicate SW3 press complete */ gSwitchFlag |= 0x20; /* Check if switch release callback function is not NULL */ if (gSwitchReleaseCallbackFunc) { /* Execute user callback function */ gSwitchReleaseCallbackFunc(); } } /* Set standby ready flag as false */ gSwitchStandbyReady = false; /* Create 10ms one-shot timer interrupt to debounce the switch input */ err &= R_CMT_CreateOneShot ( 1, PDL_NO_DATA, 10E-3, SwitchDebounceCB, 8 ); /* Halt in while loop when RPDL errors detected */ while (!err); }