/*********************************************************************//** * @brief External interrupt 3 handler sub-routine * @param[in] None * @return None **********************************************************************/ void EINT3_IRQHandler(void) { int j; if(GPIO_GetIntStatus(0, 25, 1)) { GPIO_ClearInt(0,(1<<25)); for (j= 0; j<8; j++) { #ifdef MCB_LPC_1768 /* Use MCB1700 board: * blink LED P1.29 when EINT3 occur */ FIO_ByteSetValue(1, 3, INT3_LED); delay(); FIO_ByteClearValue(1, 3, INT3_LED); delay(); #elif defined(IAR_LPC_1768) /* Use IAR LPC1768 KS board: * blink LED2 P0.4 when EINT3 occur */ FIO_ByteSetValue(0, 0, INT3_LED); delay(); FIO_ByteClearValue(0, 0, INT3_LED); delay(); #endif } } }
/*********************************************************************//** * @brief c_entry: Main program body * @param[in] None * @return int **********************************************************************/ int c_entry (void) { /** Use: LEDs for polling when idle and when GPIO interrupt occurs * If using MCB1700 board: Polling led: P1.28; Interrupt led: P1.29 * If using IAR KS board: Polling led: P1.25 (LED1); Interrupt led: P0.4 (LED2) * If using MICROPENDOUS_X board: No polling led; Interrupt led: P1.18 (LED1) */ #ifdef MCB_LPC_1768 FIO_ByteSetDir(1, 3, POLL_LED, 1); FIO_ByteSetDir(1, 3, INT3_LED, 1); // Turn off all LEDs FIO_ByteClearValue(1, 3, POLL_LED); FIO_ByteClearValue(1, 3, INT3_LED); #elif defined(IAR_LPC_1768) FIO_ByteSetDir(1, 3, POLL_LED, 1); FIO_ByteSetDir(0, 0, INT3_LED, 1); // Turn off all LEDs FIO_ByteSetValue(1, 3, POLL_LED); FIO_ByteSetValue(0, 0, INT3_LED); #elif defined(MICROPENDOUS_X) //FIO_ByteSetDir(1, 2, POLL_LED, 1); FIO_ByteSetDir(1, 2, INT3_LED, 1); // Turn off all LEDs //FIO_ByteSetValue(1, 2, POLL_LED); FIO_ByteSetValue(1, 2, INT3_LED); #endif // Enable GPIO interrupt /* Use MCB1700: test GPIO interrupt on P0.25->connects with ADC potentiometer * Use IAR KS : test GPIO interrupt on P0.23->connects with BUT1 button * Use MICROPENDOUS_X : test GPIO interrupt on P2.10->connects with BUT1 button */ #ifdef MICROPENDOUS_X GPIO_IntCmd(2,(1<<10),1); #else GPIO_IntCmd(0,(1<<25),1); #endif NVIC_EnableIRQ(EINT3_IRQn); while (1) { //polling led while idle #ifdef MICROPENDOUS_X #if 0 FIO_ByteSetValue(1, 3, POLL_LED); delay(); FIO_ByteClearValue(1, 3, POLL_LED); delay(); #endif #else FIO_ByteSetValue(1, 3, POLL_LED); delay(); FIO_ByteClearValue(1, 3, POLL_LED); delay(); #endif } }
/*********************************************************************//** * @brief External interrupt 3 handler sub-routine * @param[in] None * @return None **********************************************************************/ void EINT3_IRQHandler(void) { int j; #ifdef MICROPENDOUS_X if (GPIO_GetIntStatus(2,10,1)) { GPIO_ClearInt(2,(1<<10)); #else if(GPIO_GetIntStatus(0, 25, 1)) { GPIO_ClearInt(0,(1<<25)); #endif for (j= 0; j<8; j++) { #ifdef MCB_LPC_1768 /* Use MCB1700 board: * blink LED P1.29 when EINT3 occur */ FIO_ByteSetValue(1, 3, INT3_LED); delay(); FIO_ByteClearValue(1, 3, INT3_LED); delay(); #elif defined(IAR_LPC_1768) /* Use IAR LPC1768 KS board: * blink LED2 P0.4 when EINT3 occur */ FIO_ByteSetValue(0, 0, INT3_LED); delay(); FIO_ByteClearValue(0, 0, INT3_LED); delay(); #elif defined(MICROPENDOUS_X) /* Use MICROPENDOUS_X board: * blink LED1 P1.18 when EINT3 occur */ FIO_ByteClearValue(1, 2, INT3_LED); delay(); FIO_ByteSetValue(1, 2, INT3_LED); delay(); #endif } } } /*-------------------------PRIVATE FUNCTIONS------------------------------*/ /*********************************************************************//** * @brief Delay function * @param[in] None * @return None **********************************************************************/ void delay (void) { unsigned int i; for (i = 0; i < 0x100000; i++) { } }
/*********************************************************************//** * @brief c_entry: Main program body * @param[in] None * @return None **********************************************************************/ void c_entry (void) { GPIO_Init(); FIO_ByteSetDir(LED1_PORT, LED1_BYTE, LED1_BIT, GPIO_DIRECTION_OUTPUT); FIO_ByteSetDir(LED2_PORT, LED2_BYTE, LED2_BIT, GPIO_DIRECTION_OUTPUT); // Turn off all LEDs FIO_ByteClearValue(LED1_PORT, LED1_BYTE, LED1_BIT); FIO_ByteClearValue(LED2_PORT, LED2_BYTE, LED2_BIT); // Enable GPIO interrupt that connects with ADC potentiometer GPIO_IntCmd(BRD_PIO_USED_INTR_PORT, BRD_PIO_USED_INTR_MASK, 1); NVIC_SetPriority(GPIO_IRQn, 1); NVIC_EnableIRQ(GPIO_IRQn); while (1) { FIO_ByteSetValue(LED1_PORT, LED1_BYTE, LED1_BIT); delay(); FIO_ByteClearValue(LED1_PORT, LED1_BYTE, LED1_BIT); delay(); } }
// Main Program int main (void) { PINSEL_CFG_Type PinCfg; // Set Vector table offset value #if (__RAM_MODE__==1) NVIC_SetVTOR(0x10000000); #else NVIC_SetVTOR(0x00000000); #endif //p1.31 , P1.29 and P1.28 are outputs FIO_ByteSetDir(1, 3, LED1_MASK, 1); FIO_ByteSetDir(2, 0, LED2_MASK, 1); // Turn off all LEDs FIO_ByteClearValue(1, 3, LED1_MASK); FIO_ByteClearValue(2, 0, LED2_MASK); //Initialize EXT registers LPC_SC->EXTINT = 0x0; LPC_SC->EXTMODE = 0x0; LPC_SC->EXTPOLAR = 0x0; /* edge sensitive */ LPC_SC->EXTMODE = 0xF; /* falling-edge sensitive */ LPC_SC->EXTPOLAR = 0x0; /* External Interrupt Flag cleared*/ LPC_SC->EXTINT = 0xF; /* P2.10 as /EINT0 */ PinCfg.Funcnum = 1; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Pinnum = 10; PinCfg.Portnum = 2; PINSEL_ConfigPin(&PinCfg); // Enable GPIO interrupt P0.25/AD0.2 LPC_GPIOINT->IO0IntEnF = 0x02000000; NVIC_SetPriorityGrouping(4); //sets PRIGROUP to 3:2 (XXX:YY) NVIC_SetPriority(EINT0_IRQn, 0); //000:00 (bit 7:3) assign eint0 to group 0, sub-priority 0 within group 0 NVIC_SetPriority(EINT3_IRQn, 4); //001:00 (bit 7:3) assign GPIO int to group 1, sub-priority 0 within group 1 NVIC_EnableIRQ(EINT0_IRQn); NVIC_EnableIRQ(EINT3_IRQn); while (1) { FIO_ByteSetValue(1, 3, POLL_LED); delay(); FIO_ByteClearValue(1, 3, POLL_LED); delay(); } }
/** * @brief External Interrupt 0 Handler */ void EINT0_IRQHandler(void) { int i; LPC_SC->EXTINT |= 0x1; //clear the EINT0 flag for (i= 0; i<10; i++) { FIO_ByteSetValue(1, 3, INT0_LED); delay(); FIO_ByteClearValue(1, 3, INT0_LED); delay(); } }
/** * @brief External Interrupt 3 Handler */ void EINT3_IRQHandler(void) { int j; if (LPC_GPIOINT->IO0IntStatF == 0x02000000) { LPC_GPIOINT->IO0IntClr = 0x02000000; for (j= 0; j<10; j++) { FIO_ByteSetValue(1, 3, INT3_LED); delay(); FIO_ByteClearValue(1, 3, INT3_LED); delay(); } } }
int c_entry(void) { // Init LED port LED_Init(); /* * Initialize debug via UART */ debug_frmwrk_init(); // print welcome screen print_menu(); // Read back TimeOut flag to determine previous timeout reset if (WDT_ReadTimeOutFlag()){ _DBG_(info1); // Clear WDT TimeOut WDT_ClrTimeOutFlag(); } else{ _DBG_(info2); } // Initialize WDT, IRC OSC, interrupt mode, timeout = 2000000 microsecond WDT_Init(WDT_CLKSRC_IRC, WDT_MODE_RESET); // Start watchdog with timeout given WDT_Start(WDT_TIMEOUT); // set timer 100 ms Timer_Wait(100); while (1){ // Wait for 100 millisecond while ( !(TIM_GetIntStatus(LPC_TIM0,0))); TIM_ClearIntPending(LPC_TIM0,0); //turn on led FIO_ByteSetValue(2, 0, LED_PIN); // Wait for 100 millisecond while ( !(TIM_GetIntStatus(LPC_TIM0,0))); TIM_ClearIntPending(LPC_TIM0,0); //turn off led FIO_ByteClearValue(2, 0, LED_PIN); } return 0; }
int _FIO_ByteSetValue(uint8_t * args) { uint8_t * arg_ptr; uint8_t portNum; uint8_t byteNum; uint8_t bitValue; if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; portNum = (uint8_t) strtoul((char *) arg_ptr, NULL, 16); if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; byteNum = (uint8_t) strtoul((char *) arg_ptr, NULL, 16); if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; bitValue = (uint8_t) strtoul((char *) arg_ptr, NULL, 16); FIO_ByteSetValue(portNum, byteNum, bitValue); return 0; }
/*********************************************************************//** * @brief External interrupt 3 handler sub-routine * @param[in] None * @return None **********************************************************************/ void GPIO_IRQHandler(void) { int j; if(GPIO_GetIntStatus(BRD_PIO_USED_INTR_PORT, BRD_PIO_USED_INTR_PIN, 1)) { GPIO_ClearInt(BRD_PIO_USED_INTR_PORT, BRD_PIO_USED_INTR_MASK); for (j = 0; j < 10; j++) { FIO_ByteSetValue(LED2_PORT, LED2_BYTE, LED2_BIT); delay(); FIO_ByteClearValue(LED2_PORT, LED2_BYTE, LED2_BIT); delay(); } } }
void EINT3_IRQHandler(void) { if (GPIO_GetIntStatus(1, 10, 1)) { GPIO_ClearInt(2,(1<<10)); toggle=~toggle; #ifdef MCB_LPC_1768_ADC_BURST_MULTI if(toggle) { ADC_ChannelCmd(LPC_ADC,_ADC_CHANNEL_3,ENABLE); FIO_ByteSetValue(1, 3, POLL_LED); } else { ADC_ChannelCmd(LPC_ADC,_ADC_CHANNEL_3,DISABLE); FIO_ByteClearValue(1, 3, POLL_LED); } #endif } }
static inline void io_fpga_register_setdata(uint8_t data) { FIO_ByteClearValue(FPGA_BUS_DATA_PORT, 2, 0xFF); FIO_ByteSetValue(FPGA_BUS_DATA_PORT, 2, data); }
static inline void io_fpga_register_setaddress(uint8_t addr) { FIO_ByteClearValue(FPGA_BUS_ADDR_PORT, 0, 0xFF); FIO_ByteSetValue(FPGA_BUS_ADDR_PORT, 0, addr); }