Esempio n. 1
0
// Initialize the push button
void pb_init(void){
	// Set initial values
	pbState = READY;
	pbTenths = 0;
	pbLongPress = false;
	pbShortPress = false;

	// Set up timer interrupt
	Chip_MRT_IntClear(LPC_MRT_CH(0));
	Chip_MRT_SetEnabled(LPC_MRT_CH(0));

	// Set up pin interrupt
	Chip_PININT_Init(LPC_GPIO_PIN_INT);
	Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_PININT);
	Chip_SYSCTL_PeriphReset(RESET_PININT);
	Chip_INMUX_PinIntSel(0, 0, PWR_PB_SENSE);
	Chip_PININT_ClearIntStatus(LPC_GPIO_PIN_INT, 1 << 0);
	Chip_PININT_SetPinModeLevel(LPC_GPIO_PIN_INT, 1 << 0);

	PININT_EnableLevelInt(LPC_GPIO_PIN_INT, 1 << 0);
	PININT_LowActive(LPC_GPIO_PIN_INT, 1 << 0); // Enable low first so that initial press is not detected

	NVIC_ClearPendingIRQ(PIN_INT0_IRQn);
	NVIC_EnableIRQ(PIN_INT0_IRQn);
	NVIC_SetPriority(PIN_INT0_IRQn, 0x02); // Set higher than systick, but lower than sampling
}
Esempio n. 2
0
static void ADC_PinMuxSetup(void)
{
#if defined(BOARD_NXP_LPCXPRESSO_54102)
	/* Enable PININT1, which will trigger SEQ_B */
	Chip_PININT_Init(LPC_PININT);
	Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 24, IOCON_MODE_INACT | IOCON_FUNC0 | IOCON_DIGITAL_EN | IOCON_GPIO_MODE);
	Chip_GPIO_SetPinDIRInput(LPC_GPIO, 0, 24);
	LPC_INMUX->PINTSEL[PININTSELECT1] = 24;
	Chip_PININT_ClearIntStatus(LPC_PININT, PININTCH(PININTSELECT1));
	Chip_PININT_SetPinModeEdge(LPC_PININT, PININTCH(PININTSELECT1));
	Chip_PININT_EnableIntLow(LPC_PININT, PININTCH(PININTSELECT1));
	NVIC_ClearPendingIRQ(PIN_INT1_IRQn);
	NVIC_EnableIRQ(PIN_INT1_IRQn);

	/* All pins to inactive, neither pull-up nor pull-down. */
	Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 29, IOCON_MODE_INACT | IOCON_FUNC1 | IOCON_ANALOG_EN);
	Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 30, IOCON_MODE_INACT | IOCON_FUNC1 | IOCON_ANALOG_EN);
	Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 31, IOCON_MODE_INACT | IOCON_FUNC1 | IOCON_ANALOG_EN);
	Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 0, IOCON_MODE_INACT | IOCON_FUNC1 | IOCON_ANALOG_EN);
	Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 1, IOCON_MODE_INACT | IOCON_FUNC1 | IOCON_ANALOG_EN);
	Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 2, IOCON_MODE_INACT | IOCON_FUNC1 | IOCON_ANALOG_EN);
	Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 3, IOCON_MODE_INACT | IOCON_FUNC1 | IOCON_ANALOG_EN);
	Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 4, IOCON_MODE_INACT | IOCON_FUNC1 | IOCON_ANALOG_EN);
	Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 5, IOCON_MODE_INACT | IOCON_FUNC1 | IOCON_ANALOG_EN);
	Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 6, IOCON_MODE_INACT | IOCON_FUNC1 | IOCON_ANALOG_EN);
	Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 7, IOCON_MODE_INACT | IOCON_FUNC1 | IOCON_ANALOG_EN);
	Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 8, IOCON_MODE_INACT | IOCON_FUNC1 | IOCON_ANALOG_EN);

#else
#warning "No ADC setup for this example"
#endif
}
Esempio n. 3
0
static void initHardware(void)
{
    SystemCoreClockUpdate();

    Board_Init();

    ciaaIOInit();
    ciaaUARTInit();

    ciaaWriteOutput(0, 0);


    //BOTON 1

    Chip_PININT_Init(LPC_GPIO_PIN_INT);
    //Set GPIO0[4] (SW1) -> GPIO0_IRQHandler
    Chip_SCU_GPIOIntPinSel(0,0,4);
    //falling edge IRQ 
    Chip_PININT_SetPinModeEdge(LPC_GPIO_PIN_INT,PININTCH0);
    Chip_PININT_EnableIntLow(LPC_GPIO_PIN_INT,PININTCH0);

    //habilitar la IRQ
    NVIC_EnableIRQ(PIN_INT0_IRQn);

    //BOTON 2

    //Set GPIO0[4] (SW1) -> GPIO0_IRQHandler
    Chip_SCU_GPIOIntPinSel(1,1,9);
    //falling edge IRQ 
    Chip_PININT_SetPinModeEdge(LPC_GPIO_PIN_INT,PININTCH1);
    Chip_PININT_EnableIntLow(LPC_GPIO_PIN_INT,PININTCH1);

    //habilitar la IRQ
    NVIC_EnableIRQ(PIN_INT1_IRQn);




}
Esempio n. 4
0
/**
 * @brief	Main program body
 * @return	Does not return
 */
int main(void)
{
	/* Generic Initialization */
	SystemCoreClockUpdate();

	/* Board_Init calls Chip_GPIO_Init and enables GPIO clock if needed,
	   Chip_GPIO_Init is not called again */
	Board_Init();
	Board_LED_Set(0, false);

	Chip_PININT_Init(LPC_PININT);

	/* Configure GPIO pin as input */
	Chip_GPIO_SetPinDIRInput(LPC_GPIO, GPIO_PININT_PORT, GPIO_PININT_PIN);

	/* Configure pin as GPIO */
	Chip_IOCON_PinMuxSet(LPC_IOCON, GPIO_PININT_PORT, GPIO_PININT_PIN,
						 (IOCON_FUNC0 | IOCON_DIGITAL_EN  | IOCON_GPIO_MODE));

	/* Configure pin interrupt selection for the GPIO pin in Input Mux Block */
	Chip_INMUX_PinIntSel(GPIO_PININT_INDEX, GPIO_PININT_PORT, GPIO_PININT_PIN);

	/* Configure channel interrupt as edge sensitive and falling edge interrupt */
	Chip_PININT_ClearIntStatus(LPC_PININT, PININTCH(GPIO_PININT_INDEX));
	Chip_PININT_SetPinModeEdge(LPC_PININT, PININTCH(GPIO_PININT_INDEX));
	Chip_PININT_EnableIntLow(LPC_PININT, PININTCH(GPIO_PININT_INDEX));

	/* Enable interrupt in the NVIC */
	NVIC_EnableIRQ(PININT_NVIC_NAME);

	/* Enable wakeup for PININT0 */
	Chip_SYSCON_EnableWakeup(SYSCON_STARTER_PINT0);

	/* save the clock source, power down the PLL */
	saved_clksrc = Chip_Clock_GetMainClockSource();

	/* Go to sleep mode - LED will toggle on each wakeup event */
	while (1) {
		/* Go to sleep state - will wake up automatically on interrupt */
		/* Disable PLL, if previously enabled, prior to sleep */
		if (saved_clksrc == SYSCON_MAINCLKSRC_PLLOUT) {
			Chip_Clock_SetMainClockSource(SYSCON_MAINCLKSRC_IRC);
			Chip_SYSCON_PowerDown(SYSCON_PDRUNCFG_PD_SYS_PLL);
		}

		/* Lower system voltages to current lock (likely IRC) */
		Chip_POWER_SetVoltage(POWER_LOW_POWER_MODE, Chip_Clock_GetMainClockRate());

		/* Go to sleep leaving SRAM powered during sleep. Use lower
		    voltage during sleep. */
		Chip_POWER_EnterPowerMode(PDOWNMODE,
								  (SYSCON_PDRUNCFG_PD_SRAM0A | SYSCON_PDRUNCFG_PD_SRAM0B));

		/* On wakeup, restore PLL power if needed */
		if (saved_clksrc == SYSCON_MAINCLKSRC_PLLOUT) {
			Chip_SYSCON_PowerUp(SYSCON_PDRUNCFG_PD_SYS_PLL);

			/* Wait for PLL lock */
			while (!Chip_Clock_IsSystemPLLLocked()) {}

			Chip_POWER_SetVoltage(POWER_LOW_POWER_MODE, Chip_Clock_GetSystemPLLOutClockRate(false));

			/* Use PLL for system clock */
			Chip_Clock_SetMainClockSource(SYSCON_MAINCLKSRC_PLLOUT);
		}
	}

	return 0;
}
Esempio n. 5
0
 void ciaaIO_ISR_Init(void)
 {
   Chip_PININT_Init(LPC_GPIO_PIN_INT);
 }
int main(void)
{
#if defined (__USE_LPCOPEN)
    // Read clock settings and update SystemCoreClock variable
    SystemCoreClockUpdate();
#if !defined(NO_BOARD_LIB)
#if defined (__MULTICORE_MASTER) || defined (__MULTICORE_NONE)
    // Set up and initialize all required blocks and
    // functions related to the board hardware
    Board_Init();
#endif
    // Set the LED to the state of "On"
    Board_LED_Set(0, true);
#endif
#endif

#if defined (__MULTICORE_MASTER_SLAVE_M0SLAVE) || \
    defined (__MULTICORE_MASTER_SLAVE_M4SLAVE)
    boot_multicore_slave();
#endif

    // Get the address of the PCM value FIFO from the M4 master.
    PCM_FIFO = (PCM_FIFO_T *) Chip_MBOX_GetValue(LPC_MBOX, MAILBOX_CM0PLUS);

    // Map P0.21 as the CLKOUT pin.
    Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 21,
                         (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGITAL_EN));

    // Route the main clock to the CLKOUT pin, for a 1 MHz signal.
    Chip_Clock_SetCLKOUTSource(SYSCON_CLKOUTSRC_MAINCLK, SystemCoreClock / 1000000);

    // Enable the GPIO and pin-interrupt sub-systems.
    Chip_GPIO_Init(LPC_GPIO);
    Chip_PININT_Init(LPC_PININT);

    // Map PIO0_9 as a GPIO input pin.  This is the data signal from the
    // microphone.
    Chip_GPIO_SetPinDIRInput(LPC_GPIO, 0, 9);
    Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 9,
            (IOCON_FUNC0 | IOCON_DIGITAL_EN | IOCON_GPIO_MODE));

    // Map PIO0_11 as a GPIO input pin, triggering pin-interrupt 0.  This will
    // indicate that there is a sample ready from the microphone.
    Chip_GPIO_SetPinDIRInput(LPC_GPIO, 0, 11);
    Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 11,
            (IOCON_FUNC0 | IOCON_DIGITAL_EN | IOCON_GPIO_MODE));
    Chip_INMUX_PinIntSel(PININTSELECT0, 0, 11);

    // Trigger the interrupt on the clock's rising edge.
    Chip_PININT_ClearIntStatus(LPC_PININT, PININTCH(PININTSELECT0));
    Chip_PININT_SetPinModeEdge(LPC_PININT, PININTCH(PININTSELECT0));
    Chip_PININT_EnableIntHigh(LPC_PININT, PININTCH(PININTSELECT0));

    // Enable the interrupt in the NVIC.
    NVIC_EnableIRQ(PIN_INT0_IRQn);

    // Spin while waiting for interrupts from the microphone.
    while (1) {
        __WFI();
    }
    return 0;
}