예제 #1
0
bool UartDev::init(unsigned int pclk, unsigned int baudRate,
                   int rxQSize, int txQSize)
{
    mPeripheralClock = pclk;

    // Configure UART Hardware: Baud rate, FIFOs etc.
    if (LPC_UART0_BASE == (unsigned int) mpUARTRegBase)
    {
        lpc_pconp(pconp_uart0, true);
        NVIC_EnableIRQ(UART0_IRQn);
    }
    /*
     else if(LPC_UART1_BASE == (unsigned int)mpUARTRegBase)
     {
     lpc_pconp(pconp_uart1, true);
     NVIC_EnableIRQ(UART1_IRQn);
     }
     */
    else if (LPC_UART2_BASE == (unsigned int) mpUARTRegBase)
    {
        lpc_pconp(pconp_uart2, true);
        NVIC_EnableIRQ(UART2_IRQn);
    }
    else if (LPC_UART3_BASE == (unsigned int) mpUARTRegBase)
    {
        lpc_pconp(pconp_uart3, true);
        NVIC_EnableIRQ(UART3_IRQn);
    }
    else
    {
        return false;
    }

    // Enable & Reset FIFOs and set 4 char timeout for Rx
    mpUARTRegBase->FCR = (1 << 0) | (1 << 6);
    mpUARTRegBase->FCR |= (1 << 1) | (1 << 2);

    setBaudRate(baudRate);

    // Set minimum queue size?
    if (rxQSize < 9) rxQSize = 8;
    if (txQSize < 9) txQSize = 8;

    // Create the receive and transmit queues
    if (!mRxQueue) mRxQueue = xQueueCreate(rxQSize, sizeof(char));
    if (!mTxQueue) mTxQueue = xQueueCreate(txQSize, sizeof(char));

    // Enable Rx/Tx and line status Interrupts:
    mpUARTRegBase->IER = (1 << 0) | (1 << 1) | (1 << 2); // B0:Rx, B1: Tx

    return (0 != mRxQueue && 0 != mTxQueue);
}
예제 #2
0
void ssp1_dma_init()
{
    // Power up and enable GPDMA
    lpc_pconp(pconp_gpdma, true);
    LPC_GPDMA->DMACConfig = 1;
    while (!(LPC_GPDMA->DMACConfig & 1));
}
예제 #3
0
void rit_enable(void_func_t function, uint32_t time_ms)
{
    if (0 == function) {
        return;
    }
    // Divide by zero guard
    if(0 == time_ms) {
        time_ms = 1;
    }

    // Power up first otherwise writing to RIT will give us Hard Fault
    lpc_pconp(pconp_rit, true);

    // Enable CLK/1 to simplify RICOMPVAL calculation below
    lpc_pclk(pclk_rit, clkdiv_1);

    LPC_RIT->RICTRL = 0;
    LPC_RIT->RICOUNTER = 0;
    LPC_RIT->RIMASK = 0;
    LPC_RIT->RICOMPVAL = sys_get_cpu_clock() / (1000 / time_ms);

    // Clear timer upon match, and enable timer
    const uint32_t isr_clear_bitmask = (1 << 0);
    const uint32_t timer_clear_bitmask = (1 << 1);
    const uint32_t timer_enable_bitmask = (1 << 3);
    LPC_RIT->RICTRL = isr_clear_bitmask | timer_clear_bitmask | timer_enable_bitmask;

    // Enable System Interrupt and connect the callback
    g_rit_callback = function;
    vTraceSetISRProperties(RIT_IRQn, "RIT", IP_RIT);
    NVIC_EnableIRQ(RIT_IRQn);
}
예제 #4
0
bool I2C_Base::init(unsigned int pclk, unsigned int busRateInKhz)
{
    // Power on I2C
    switch(mIRQ) {
        case I2C0_IRQn: lpc_pconp(pconp_i2c0, true);  break;
        case I2C1_IRQn: lpc_pconp(pconp_i2c1, true);  break;
        case I2C2_IRQn: lpc_pconp(pconp_i2c2, true);  break;
        default: return false;
    }

    mpI2CRegs->I2CONCLR = 0x6C;           // Clear ALL I2C Flags

    /**
     * Per I2C high speed mode:
     * HS mode master devices generate a serial clock signal with a HIGH to LOW ratio of 1 to 2.
     * So to be able to optimize speed, we use different duty cycle for high/low
     *
     * Compute the I2C clock dividers.
     * The LOW period can be longer than the HIGH period because the rise time
     * of SDA/SCL is an RC curve, whereas the fall time is a sharper curve.
     */
    const uint32_t percent_high = 40;
    const uint32_t percent_low = (100 - percent_high);
    const uint32_t freq_hz = (busRateInKhz > 1000) ? (100 * 1000) : (busRateInKhz * 1000);
    const uint32_t half_clock_divider = (pclk / freq_hz) / 2;
    mpI2CRegs->I2SCLH = (half_clock_divider * percent_high) / 100;
    mpI2CRegs->I2SCLL = (half_clock_divider * percent_low ) / 100;

    // Set I2C slave address and enable I2C
    mpI2CRegs->I2ADR0 = 0;
    mpI2CRegs->I2ADR1 = 0;
    mpI2CRegs->I2ADR2 = 0;
    mpI2CRegs->I2ADR3 = 0;

    // Enable I2C and the interrupt for it
    mpI2CRegs->I2CONSET = 0x40;
    NVIC_EnableIRQ(mIRQ);

    return true;
}
예제 #5
0
/**
 * IR Sensor is attached to P1.18 - CAP1.0, so it needs TIMER1 to capture the times on P1.18
 */
bool IR_Sensor::init()
{
    /* Power up the timer 1 in case it is off */
    lpc_pconp(pconp_timer1, true);

    /* Timer 1 should be initialized by high_level_init.cpp using lpc_sys.c API
     * We will just add on the capture functionality here.
     */
    LPC_TIM1->CCR &= ~(7 << 0);            // Clear Bits 2:1:0
    LPC_TIM1->CCR |=  (1 << 2) | (1 << 1); // Enable Falling Edge capture0 with interrupt

    // Select P1.18 as CAP1.0 by setting bits 5:4 to 0b11
    LPC_PINCON->PINSEL3 |= (3 << 4);

    return true;
}