Ejemplo n.º 1
0
/**
 * @brief	Handle interrupt from mailbox
 * @return	Nothing
 */
void MAILBOX_IRQHandler(void)
{
    /* Slave core uses passed mailbox value as address to shared LED state values */
    uint32_t *psharedLEDStates = (uint32_t *) Chip_MBOX_GetValue(LPC_MBOX, myCoreBox);

    /* Toggle LED bit state for this core usign mutex */
    mutexTake();
    sharedLEDStates = *psharedLEDStates;
    ledToggleBit(1);
    *psharedLEDStates = sharedLEDStates;
    mutexGive();

    /* Clear this MCU's mailbox */
    Chip_MBOX_ClearValueBits(LPC_MBOX, myCoreBox, 0xFFFFFFFF);

    /* Signal master code about the change */
    Chip_MBOX_SetValue(LPC_MBOX, otherCoreBox, 1);
}
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;
}