SW0, SW1 button int test.
main.cpp
- Committer:
- mzta
- Date:
- 2015-01-07
- Revision:
- 0:044197641ae8
- Child:
- 1:a88865265000
File content as of revision 0:044197641ae8:
#include "mbed.h" #define BTN0_PIN P6_0 #define BTN1_PIN P6_1 #define BTN0_IRQ IRQ5_IRQn #define BTN1_IRQ IRQ4_IRQn InterruptIn button0(BTN0_PIN); InterruptIn button1(BTN1_PIN); DigitalOut rled(LED_RED); DigitalOut bled(LED_BLUE); #define DELAY_CNT 1000000000 void button0_int_handler() { rled = 0; for (int i = 0; i <= DELAY_CNT; i++) ; rled = 1; } void button1_int_handler() { bled = 0; for (int i = 0; i <= DELAY_CNT; i++) ; bled = 1; } int32_t R_INTC_SetPriority(uint16_t int_id, uint8_t priority); int main() { rled = 1; bled = 1; R_INTC_SetPriority(BTN0_IRQ, 1); button0.fall(&button0_int_handler); button1.fall(&button1_int_handler); while(1) { wait(1); } } /** * http://japan.renesas.com/req/sample_code.do?event=searchProducts&%20expandedProductsId=1&productsId=186374 */ #include "r_typedefs.h" #include "dev_drv.h" /* Device Driver common header */ //#include "devdrv_intc.h" /* INTC Driver Header */ #include "iodefine.h" #define INTC_ID_TOTAL (587) /****************************************************************************** * Function Name: R_INTC_SetPriority * Description : Sets the priority level of the ID specified by the int_id to * : the priority level specified by the priority. * Arguments : uint16_t int_id : Interrupt ID * : uint8_t priority : Interrupt priority level (0 to 31) * Return Value : DEVDRV_SUCCESS : Success of INTC interrupt priority level setting * : DEVDRV_ERROR : Failure of INTC interrupt priority level setting ******************************************************************************/ int32_t R_INTC_SetPriority(uint16_t int_id, uint8_t priority) { uint32_t icdipr; uint32_t mask; volatile uint32_t * addr; /* ==== Argument check ==== */ if ((int_id >= INTC_ID_TOTAL) || priority >= 32) { return DEVDRV_ERROR; /* Argument error */ } priority = priority << 3; /* Priority[7:3] of ICDIPRn is valid bit */ /* ICDIPRn has 4 sources in the 32 bits */ /* The n can be calculated by int_id / 4 */ /* The bit field width is 8 bits */ /* The target bit can be calculated by (int_id % 4) * 8 */ addr = (volatile uint32_t *)&INTC.ICDIPR0; icdipr = *(addr + (int_id / 4)); /* Read ICDIPRn */ mask = (uint32_t)0x000000FFuL; /* ---- Mask ---- */ mask = mask << ((int_id % 4) * 8); /* Shift to target bit */ icdipr &= ~mask; /* Clear priority */ mask = (uint32_t)priority; /* ---- Priority ---- */ mask = mask << ((int_id % 4) * 8); /* Shift to target bit */ icdipr |= mask; /* Set priority */ *(addr + (int_id / 4)) = icdipr; /* Write ICDIPRn */ return DEVDRV_SUCCESS; }