예제 #1
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
	}
}
예제 #2
0
파일: hw_digital.c 프로젝트: hlev/firmware
void hw_interrupt_enable(int index, int ulPin, int mode)
{
    assert(index >= 0 && index < 8);

    unsigned portNum = g_APinDescription[ulPin].portNum;
    unsigned bitNum = g_APinDescription[ulPin].bitNum;
    unsigned int_id = PIN_INT0_IRQn + index;

    /* Clear IRQ in case it existed already */
    NVIC_DisableIRQ(int_id);

    hw_digital_input(ulPin);

    /* Configure GPIO interrupt */
    GPIO_IntCmd(index, portNum, bitNum, mode);

    // Clear any pre-existing interrupts requests so it doesn't fire immediately
    GPIO_ClearInt(TM_INTERRUPT_MODE_RISING, index);
    GPIO_ClearInt(TM_INTERRUPT_MODE_FALLING, index);
    GPIO_ClearInt(TM_INTERRUPT_MODE_HIGH, index);
    GPIO_ClearInt(TM_INTERRUPT_MODE_LOW, index);

    /* Enable interrupt for Pin Interrupt */
    NVIC_EnableIRQ(int_id);
}
예제 #3
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();
    }
    
}
예제 #4
0
int _GPIO_IntCmd(uint8_t * args)
{
	uint8_t * arg_ptr;
	uint8_t portNum;
	uint32_t bitValue;
	uint8_t edgeState;

	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;
	bitValue = (uint32_t) strtoul((char *) arg_ptr, NULL, 16);
	if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1;
	edgeState = (uint8_t) strtoul((char *) arg_ptr, NULL, 16);

	GPIO_IntCmd(portNum, bitValue, edgeState);
	return 0;
}
예제 #5
0
/*********************************************************************//**
 * @brief	Initial System Init using Port and Peripheral
 * @param[in]	None
 * @return 		None
 **********************************************************************/
void System_Init(void)
{
	LPC_WDT->WDMOD &= ~WDT_WDMOD_WDEN;  // Disable Watchdog
	SystemInit();						// Initialize system and update core clock
	Port_Init();                        // Port Initialization
	SYSTICK_Config();                   // Systick Initialization
	led_delay = 1000;                   // Heart Beat rate of 1Sec toggle
	NVIC_SetPriority(SysTick_IRQn, 0);  // Set SysTick as Highest Priority

	UART_Config(LPC_UART0, 115200);       // Uart0 Initialize at 9600 Baud Rate
	SSP_Config (LPC_SSP1);              // Initialize SPI
	I2C_Config (LPC_I2C0);              // Initialize I2C0
	GLCD_Init();                        // Initialize GLCD

	GPIO_IntCmd(2,_BIT(7),1);          // Enable GPIO Interrupt at P0.19 Falling Edge
	NVIC_EnableIRQ(EINT3_IRQn);         // NVIC Interrupt EINT3_IRQn for GPIO
	NVIC_SetPriority(EINT3_IRQn, 4);    // Set any lower Priority than SysTick

	TSC2004_Cal_Init(&cmatrix);

}
예제 #6
0
파일: gpio.c 프로젝트: lnls-dig/bpm-ipmi
void gpio_init() {

  SPI_CFG_Type spiInitialization;

  PINSEL_CFG_Type PinSelCfg;

/*-----------------------------------------------------------------
 *--------------------------PORT 0---------------------------------
 *-----------------------------------------------------------------
 */
  GPIO_SetDir(0, 0xFFFFFFFF, OUTPUT);
  PinSelCfg.Portnum = PINSEL_PORT_0;

//  PinSelCfg.Pinnum = PINSEL_PIN_0;
//  PinSelCfg.Funcnum = PINSEL_FUNC_3;
//  PinSelCfg.OpenDrain = 0;
//  PinSelCfg.Pinmode = 0;
//  PINSEL_ConfigPin(&PinSelCfg);
//
//  PinSelCfg.Pinnum = PINSEL_PIN_1;
//  PINSEL_ConfigPin(&PinSelCfg);

  PinSelCfg.Pinnum = PINSEL_PIN_2;
  PinSelCfg.Funcnum = PINSEL_FUNC_1;
  PinSelCfg.OpenDrain = PINSEL_PINMODE_NORMAL;
  PinSelCfg.Pinmode = PINSEL_PINMODE_PULLUP;
  PINSEL_ConfigPin(&PinSelCfg);

  PinSelCfg.Pinnum = PINSEL_PIN_3;
  PINSEL_ConfigPin(&PinSelCfg);


  GPIO_SetDir(0, 0x01<<22, INPUT);


  PinSelCfg.Pinnum = PINSEL_PIN_10;
  PinSelCfg.Funcnum = PINSEL_FUNC_2;
  PinSelCfg.OpenDrain = PINSEL_PINMODE_OPENDRAIN;
  PinSelCfg.Pinmode = PINSEL_PINMODE_TRISTATE;
  PINSEL_ConfigPin(&PinSelCfg);

  PinSelCfg.Pinnum = PINSEL_PIN_11;
  PINSEL_ConfigPin(&PinSelCfg);


  //SET FMC_I2C1 in Hi-Z
  GPIO_SetDir(0, 0x01<<19, INPUT);
  GPIO_SetDir(0, 0x01<<20, INPUT);
//  PinSelCfg.Pinmode = PINSEL_PINMODE_TRISTATE;
//  PinSelCfg.Funcnum = PINSEL_FUNC_3;
//  PinSelCfg.Pinnum = PINSEL_PIN_19;
//  PINSEL_ConfigPin(&PinSelCfg);
//
//  PinSelCfg.Pinnum = PINSEL_PIN_20;
//  PINSEL_ConfigPin(&PinSelCfg);

  PinSelCfg.Funcnum = PINSEL_FUNC_1;
  PinSelCfg.OpenDrain = PINSEL_PINMODE_OPENDRAIN;
  PinSelCfg.Pinnum = PINSEL_PIN_27;
  PINSEL_ConfigPin(&PinSelCfg);

  PinSelCfg.Pinnum = PINSEL_PIN_28;
  PINSEL_ConfigPin(&PinSelCfg);

  PinSelCfg.Pinnum = PINSEL_PIN_29;
  PinSelCfg.Funcnum = PINSEL_FUNC_1;
  PinSelCfg.OpenDrain = PINSEL_PINMODE_NORMAL;
  PinSelCfg.Pinmode = PINSEL_PINMODE_TRISTATE;
  PINSEL_ConfigPin(&PinSelCfg);

  PinSelCfg.Pinnum = PINSEL_PIN_30;
  PINSEL_ConfigPin(&PinSelCfg);

/*-----------------------------------------------------------------
 *---------------------END OF PORT 0-------------------------------
 *-----------------------------------------------------------------
 *-----------------------------------------------------------------
 * ------------------------PORT 1----------------------------------
 * ----------------------------------------------------------------
 */
  GPIO_SetDir(1, 0xFFFFFFFF, OUTPUT);

  GPIO_SetDir(1, ( 0x01<<IPMI_GA0 | 0x01<<IPMI_GA1 | 0x01<<IPMI_GA2 ), INPUT);
  GPIO_SetValue(LED_PORT, (0x01<<_IPMI_BLLED|0x01<<_IPMI_LED1|0x01<<_IPMI_LED2) );

//  PinSelCfg.Portnum = PINSEL_PORT_1;
//  PinSelCfg.Pinnum = PINSEL_PIN_30;
//  PinSelCfg.Funcnum = PINSEL_FUNC_2;
//  PinSelCfg.OpenDrain = PINSEL_PINMODE_NORMAL;
//  PinSelCfg.Pinmode = PINSEL_PINMODE_TRISTATE;
//  PINSEL_ConfigPin(&PinSelCfg);


  GPIO_SetDir(ENA_PORT, 0x001<<ENA_PIN, INPUT);

  GPIO_SetDir(2, 0x0400, INPUT);

  GPIO_SetDir(IPMI_EJTHDL_PORT, 0x001<<IPMI_EJTHDL, INPUT);

  GPIO_SetDir(1, 0x01<<22, INPUT);

  GPIO_SetDir(PGOOD_PORT, 0x01<<PGOOD_PIN, INPUT);



  gpio_clr_gpio_pin(_IPMI_BLLED, LED_PORT);						// turn on blue LED ASAP
  gpio_clr_gpio_pin(UC_PWRENOUT, UC_PWRENOUT_PORT);               // turn off power enable



  PinSelCfg.Pinnum  = PINSEL_PIN_15;
  PinSelCfg.Portnum = PINSEL_PORT_0;
  PinSelCfg.Pinmode = PINSEL_PINMODE_PULLUP;
  PinSelCfg.Funcnum = PINSEL_FUNC_3;
  PinSelCfg.OpenDrain = PINSEL_PINMODE_NORMAL;

  PINSEL_ConfigPin(&PinSelCfg);


  PinSelCfg.Pinnum  = PINSEL_PIN_18;

  PINSEL_ConfigPin(&PinSelCfg);

  GPIO_SetDir(1, 0x01<<26, OUTPUT);

  GPIO_SetValue(1, 0x01<<26);

  GPIO_SetDir(0, 0x01<<21, OUTPUT);
  GPIO_SetDir(0, 0x01<<16, OUTPUT);
  GPIO_SetValue(0, 0x01<<16);
  GPIO_SetValue(0, 0x01<<21);


  GPIO_SetDir(PORT_EN_0, 0x01<<EN_P1V2, OUTPUT);
  GPIO_SetDir(PORT_EN_0, 0x01<<EN_P1V8, OUTPUT);
  GPIO_SetDir(PORT_EN_0, 0x01<<EN_FMC2_P3V3, OUTPUT);
  GPIO_SetDir(PORT_EN_0, 0x01<<EN_FMC1_P3V3, OUTPUT);
  GPIO_SetDir(PORT_EN_0, 0x01<<EM_FMC1_P12V, OUTPUT);
  GPIO_SetDir(PORT_EN_0, 0x01<<EN_FMC2_P12V, OUTPUT);


  GPIO_SetDir(PORT_EN_1, 0x01<<EN_FMC1_PVADJ, OUTPUT);
  GPIO_SetDir(PORT_EN_1, 0x01<<EN_FMC2_PVADJ, OUTPUT);
  GPIO_SetDir(PORT_EN_1, 0x01<<EN_P3V3, OUTPUT);
  GPIO_SetDir(PORT_EN_1, 0x01<<EN_1V5_VTT, OUTPUT);

  GPIO_SetDir(PORT_EN_1, 0x01<<EN_RTM_CONN, OUTPUT);
  GPIO_SetDir(PORT_EN_0, 0x01<<RTM_PRESENCE, INPUT);

  GPIO_SetDir(PORT_EN_3, 0x01<<EN_P1V0, OUTPUT);

  setDC_DC_ConvertersON();

  spiInitialization.CPOL = SPI_CPOL_LO;
  spiInitialization.CPHA = SPI_CPHA_FIRST;
  spiInitialization.Databit = SPI_DATABIT_10;
  spiInitialization.DataOrder = SPI_DATA_MSB_FIRST;
  spiInitialization.ClockRate = 10000000;

  SPI_Init(LPC_SPI, &spiInitialization);

  LPC_SPI->SPCR = 0xA24;



  GPIO_ClearValue(0, 0x01<<16);
  SPI_SendData(LPC_SPI, 0x0125);
  while(! ( SPI_CheckStatus( SPI_GetStatus(LPC_SPI), SPI_STAT_SPIF) ));
  GPIO_SetValue(0, 0x01<<16);

  GPIO_ClearValue(0, 0x01<<16);
  SPI_SendData(LPC_SPI, 0x0025);
  while(! ( SPI_CheckStatus( SPI_GetStatus(LPC_SPI), SPI_STAT_SPIF) ));
  GPIO_SetValue(0, 0x01<<16);


  //SCANSTA JTAG
  GPIO_SetDir(2, 0x0FF, OUTPUT);

  GPIO_SetValue(2, 0x080);

  GPIO_ClearValue(2, 0x07F);

  SPI_ConfigStructInit(&spiInitialization);


  //FPGA_SPI
  GPIO_SetDir(1, 0x01<<20, INPUT);
  GPIO_SetDir(1, 0x01<<21, INPUT);
  GPIO_SetDir(1, 0x01<<23, INPUT);
  GPIO_SetDir(1, 0x01<<24, INPUT);
  // SET PROGRAM_B AS OUTPUT
  // AND SET THIS PIN HIGH
  GPIO_SetDir(0, 0x01<<17, INPUT);
  // SET DONE PIN AS INPUT
  // turn on pull-up
  GPIO_SetDir(0, 0x01<<22, INPUT);
  ////////////////////////////////////////
  // P0_6 - FCS_B - use as FPGA - RST
  ////////////////////////////////////////
  GPIO_SetDir(0, 0x01<<6, INPUT);
  //GPIO_ClearValue(0, 0x01<<6);
  ///////////////////////////////////////
  GPIO_SetDir(0, 0x01<<7, INPUT);
  GPIO_SetDir(0, 0x01<<8, INPUT);
#ifdef AMC_CPU_COM_Express
  GPIO_SetDir(0, 0x01<<9, OUTPUT);
#else
  GPIO_SetDir(0, 0x01<<9, INPUT);
#endif

  ///////////////////////////////////////
  //FMC STATUS PORTS
  ///////////////////////////////////////
  GPIO_SetDir(1, 0x1<<14, INPUT);
  GPIO_SetDir(1, 0x1<<15, INPUT);
  GPIO_SetDir(1, 0x1<<16, INPUT);
  GPIO_SetDir(1, 0x1<<17, INPUT);
  GPIO_SetDir(1, 0x1<<18, INPUT);
  GPIO_SetDir(1, 0x1<<19, INPUT);
  ///////////////////////////////////////

  // FPGA Reset Button
  EXTI_InitTypeDef EXTICfg;

      /* Initialize EXT pin and register */
      /* P2.12 as /EINT2*/
  PinSelCfg.Funcnum   = PINSEL_FUNC_1;
  PinSelCfg.OpenDrain = PINSEL_PINMODE_NORMAL;
  PinSelCfg.Pinmode   = PINSEL_PINMODE_PULLUP;
  PinSelCfg.Pinnum    = FPGA_RST_SW;
  PinSelCfg.Portnum   = FPGA_RST_SW_PORT;
  PINSEL_ConfigPin(&PinSelCfg);

  PinSelCfg.Funcnum   = PINSEL_FUNC_0;
  PinSelCfg.OpenDrain = PINSEL_PINMODE_NORMAL;
  PinSelCfg.Pinmode   = PINSEL_PINMODE_PULLUP;
  PinSelCfg.Pinnum    = FPGA_RESETn;
  PinSelCfg.Portnum   = FPGA_RESETn_PORT;
  PINSEL_ConfigPin(&PinSelCfg);
  GPIO_SetDir(FPGA_RESETn_PORT, 1<<FPGA_RESETn, OUTPUT);

  EXTI_Init();

  EXTICfg.EXTI_Line = EXTI_EINT2;
  EXTICfg.EXTI_Mode = EXTI_MODE_EDGE_SENSITIVE;
  EXTICfg.EXTI_polarity = EXTI_POLARITY_LOW_ACTIVE_OR_FALLING_EDGE;
  EXTI_ClearEXTIFlag(EXTI_EINT2);
  EXTI_Config(&EXTICfg);
  GPIO_IntCmd(0, 0x01 << FPGA_RST_SW, 1);

  NVIC_SetPriorityGrouping(0);
  NVIC_SetPriority(EINT2_IRQn, 4);
  NVIC_EnableIRQ(EINT2_IRQn);

}
예제 #7
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);
}
예제 #8
0
/**
 * @brief The same with GPIO_IntCmd()
 */
void FIO_IntCmd(uint8_t pinInt, uint8_t portNum, uint32_t bitValue, uint8_t intMode)
{
	GPIO_IntCmd(pinInt, portNum, bitValue, intMode);
}