static void
nrf52_timer_handler(void)
{
    int delta;
    int ticks;
    os_sr_t sr;
    uint32_t counter;

    os_trace_enter_isr();
    OS_ENTER_CRITICAL(sr);

    /* Calculate elapsed ticks and advance OS time. */

    counter = nrf52_os_tick_counter();
    delta = sub24(counter, g_hal_os_tick.lastocmp);
    ticks = delta / g_hal_os_tick.ticks_per_ostick;
    os_time_advance(ticks);

    /* Clear timer interrupt */
    OS_TICK_TIMER->EVENTS_COMPARE[OS_TICK_CMPREG] = 0;

    /* Update the time associated with the most recent tick */
    g_hal_os_tick.lastocmp = (g_hal_os_tick.lastocmp +
        (ticks * g_hal_os_tick.ticks_per_ostick)) & 0xffffff;

    /* Update the output compare to interrupt at the next tick */
    nrf52_os_tick_set_ocmp(g_hal_os_tick.lastocmp + g_hal_os_tick.ticks_per_ostick);

    OS_EXIT_CRITICAL(sr);
    os_trace_exit_isr();
}
Example #2
0
static void
apollo2_uart_irqh_x(int num)
{
    struct apollo2_uart *u;
    uint32_t status;
    int data;
    int rc;

    os_trace_enter_isr();

    u = &uarts[num];

    status = AM_REGn(UART, 0, IES);
    AM_REGn(UART, 0, IEC) &= ~status;

    if (status & (AM_REG_UART_IES_TXRIS_M)) {
        if (u->u_tx_started) {
            while (1) {
                if (AM_BFRn(UART, 0, FR, TXFF)) {
                    break;
                }

                data = u->u_tx_func(u->u_func_arg);
                if (data < 0) {
                    if (u->u_tx_done) {
                        u->u_tx_done(u->u_func_arg);
                    }
                    apollo2_uart_disable_tx_irq();
                    u->u_tx_started = 0;
                    break;
                }

                AM_REGn(UART, 0, DR) = data;
            }
        }
    }

    if (status & (AM_REG_UART_IES_RXRIS_M | AM_REG_UART_IES_RTRIS_M)) {
        /* Service receive buffer */
        while (!AM_BFRn(UART, 0, FR, RXFE)) {
            u->u_rx_buf = AM_REGn(UART, 0, DR);
            rc = u->u_rx_func(u->u_func_arg, u->u_rx_buf);
            if (rc < 0) {
                u->u_rx_stall = 1;
                break;
            }
        }
    }

    os_trace_exit_isr();
}