Exemplo n.º 1
0
/*********************************************************************//**
 * @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
			  }
          }
}
Exemplo n.º 2
0
/*********************************************************************//**
 * @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();
    }
    
}
Exemplo n.º 3
0
// 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();
	}
}
Exemplo n.º 4
0
/*********************************************************************//**
 * @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
	}
}
Exemplo n.º 5
0
/*********************************************************************//**
 * @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++) {
  }
}
Exemplo n.º 6
0
/**
 * @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();
          }
}
Exemplo n.º 7
0
/* Init parallel 16bit Databus to FPGA */
void io_init_fpga_bus(void)
{
    uint32_t i=0;

    PinCfg.Funcnum      = 0;    // GPIO
    PinCfg.OpenDrain    = 0;
    PinCfg.Pinmode      = 0;
    PinCfg.Portnum      = FPGA_BUS_DATA_PORT;
    PinCfg.Pinnum       = FPGA_BUS_DATA_PIN_LOW;

    for(i=FPGA_BUS_DATA_PIN_LOW; i<=FPGA_BUS_DATA_PIN_HIGH; i++) {
        PinCfg.Pinnum       = i;
        //printf("dbg: init fpga bus port %d pin %d\n", PinCfg.Portnum, PinCfg.Pinnum);
        PINSEL_ConfigPin(&PinCfg);
    }

    FIO_ByteSetDir(FPGA_BUS_DATA_PORT, 2, 0xff, POUT);
    FIO_ByteClearValue(FPGA_BUS_DATA_PORT, 2 , 0xff);


    PinCfg.Funcnum      = 0;    // GPIO
    PinCfg.OpenDrain    = 0;
    PinCfg.Pinmode      = 0;
    PinCfg.Portnum      = FPGA_BUS_ADDR_PORT;
    PinCfg.Pinnum       = FPGA_BUS_ADDR_PIN_LOW;

    for(i=FPGA_BUS_ADDR_PIN_LOW; i<=FPGA_BUS_ADDR_PIN_HIGH; i++) {
        PinCfg.Pinnum       = i;
        //printf("dbg: init fpga bus port %d pin %d\n", PinCfg.Portnum, PinCfg.Pinnum);
        PINSEL_ConfigPin(&PinCfg);
    }

    FIO_ByteSetDir(FPGA_BUS_ADDR_PORT, 0, 0xff, POUT);
    FIO_ByteClearValue(FPGA_BUS_ADDR_PORT, 0 , 0xff);

    fpga_bus_dataclock_low();

    return;
}
Exemplo n.º 8
0
/**
 * @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();
			  }
          }
}
Exemplo n.º 9
0
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;
}
Exemplo n.º 10
0
int _FIO_ByteClearValue(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_ByteClearValue(portNum, byteNum, bitValue);
	return 0;
}
Exemplo n.º 11
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();
        }
    }
}
Exemplo n.º 12
0
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
	  }
}
Exemplo n.º 13
0
/*********************************************************************//**
 * @brief		c_entry: Main ADC program body
 * @param[in]	None
 * @return 		int
 **********************************************************************/
int c_entry(void)
{
	PINSEL_CFG_Type PinCfg;
#ifdef MCB_LPC_1768_ADC_BURST_MULTI
	PINSEL_CFG_Type PinCfg1;
#endif
	uint32_t tmp;
	uint32_t adc_value;
	/* Initialize debug via UART0
	 * – 115200bps
	 * – 8 data bit
	 * – No parity
	 * – 1 stop bit
	 * – No flow control
	 */
	debug_frmwrk_init();

	// print welcome screen
	print_menu();

	/* Because the potentiometer on different boards (MCB & IAR) connect
	 * with different ADC channel, so we have to configure correct ADC channel
	 * on each board respectively.
	 * If you want to check other ADC channels, you have to wire this ADC pin directly
	 * to potentiometer pin (please see schematic doc for more reference)
	 */
#ifdef MCB_LPC_1768
	/*
	 * Init ADC pin connect
	 * AD0.2 on P0.25
	 */
	PinCfg.Funcnum = 1;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Pinnum = 25;
	PinCfg.Portnum = 0;
	PINSEL_ConfigPin(&PinCfg);
#ifdef MCB_LPC_1768_ADC_BURST_MULTI
	/*
	 * Init ADC pin connect
	 * AD0.3 on P0.26
	 */
	PinCfg1.Funcnum = 1;
	PinCfg1.OpenDrain = 0;
	PinCfg1.Pinmode = 0;
	PinCfg1.Pinnum = 26;
	PinCfg1.Portnum = 0;
	PINSEL_ConfigPin(&PinCfg1);
#endif
#elif defined (IAR_LPC_1768)
	/* select P1.31 as AD0.5 */
	PinCfg.Funcnum = 3;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Pinnum = 31;
	PinCfg.Portnum = 1;
	PINSEL_ConfigPin(&PinCfg);
#endif


	/* Configuration for ADC:
	 *  select: ADC channel 2 (if using MCB1700 board)
	 *  		ADC channel 5 (if using IAR-LPC1768 board)
	 *  ADC conversion rate = 200KHz
	 */
	ADC_Init(LPC_ADC, 200000);
	ADC_ChannelCmd(LPC_ADC,_ADC_CHANNEL,ENABLE);
#ifdef MCB_LPC_1768_ADC_BURST_MULTI
	ADC_ChannelCmd(LPC_ADC,_ADC_CHANNEL_3,ENABLE);
#endif

#ifdef MCB_LPC17XX_ADC_INJECT_TEST
	FIO_ByteSetDir(1, 3, POLL_LED, 1);
	FIO_ByteClearValue(1, 3, POLL_LED);
	// Enable GPIO interrupt P2.10
	GPIO_IntCmd(2,(1<<10),1);
	NVIC_EnableIRQ(EINT3_IRQn);
#endif

	//Start burst conversion
	ADC_BurstCmd(LPC_ADC,ENABLE);
	while(1)
	{
#ifdef MCB_LPC_1768
		adc_value =  ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_2);
		_DBG("ADC value on channel 2: ");
#elif defined (IAR_LPC_1768)
		adc_value =  ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_5);
		_DBG("ADC value on channel 5: ");
#endif
		_DBD32(adc_value);
		_DBG_("");
#ifdef MCB_LPC_1768_ADC_BURST_MULTI
		adc_value =  ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_3);
		_DBG("ADC value on channel 3: ");
		_DBD32(adc_value);
		_DBG_("");
#endif
		// Wait for a while
		for(tmp = 0; tmp < 1500000; tmp++);
	}
	ADC_DeInit(LPC_ADC);
	return (0);
}
Exemplo n.º 14
0
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);
}
Exemplo n.º 15
0
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);
}