Beispiel #1
0
uint16 _xt_isr_handler(uint16 i)
{
	uint8 index;

	if (i & (1 << ETS_WDT_INUM)) {
//		printf("i %x %u\n", i, REG_READ(0x3ff20c00));
		index = ETS_WDT_INUM;
	} 
	else if (i & (1 << ETS_GPIO_INUM)) {
		index = ETS_GPIO_INUM;
	}else {
		index = __builtin_ffs(i) - 1;

		if (index == ETS_MAX_INUM) {
			i &= ~(1 << ETS_MAX_INUM);
			index = __builtin_ffs(i) - 1;
		}
	}

    _xt_clear_ints(1<<index);

    _xt_isr_status = 1;
    isr[index].handler(isr[index].arg);
    _xt_isr_status = 0;

    return i & ~(1 << index);
}
Beispiel #2
0
uint16_t IRAM _xt_isr_handler(uint16_t i)
{
    uint8_t index;

    /* I think this is implementing some kind of interrupt priority or
       short-circuiting an expensive ffs for most common interrupts - ie
       WDT And GPIO are common or high priority, then remaining flags.
    */
    if (i & (1 << INUM_WDT)) {
	index = INUM_WDT;
    }
    else if (i & (1 << INUM_GPIO)) {
	index = INUM_GPIO;
    }else {
	index = __builtin_ffs(i) - 1;

	if (index == INUM_MAX) {
	    /* I don't understand what happens here. INUM_MAX is not
	       the highest interrupt number listed (and the isr array
	       has 16 entries).

	       Clearing that flag and then setting index to
	       __builtin_ffs(i)-1 may result in index == 255 if no
	       higher flags are set, unless this is guarded against
	       somehow by the caller?

	       I also don't understand why the code is written like
	       this in esp_iot_rtos_sdk instead of just putting the i
	       &= line near the top... Probably no good reason?
	    */
	    i &= ~(1 << INUM_MAX);
	    index = __builtin_ffs(i) - 1;
	}
    }

    _xt_clear_ints(1<<index);

    isr[index]();

    return i & ~(1 << index);
}
IRAM void uart0_rx_handler(void)
{
    // TODO: Handle UART1, see reg 0x3ff20020, bit2, bit0 represents uart1 and uart0 respectively
    if (!UART(UART0).INT_STATUS & UART_INT_STATUS_RXFIFO_FULL) {
        return;
    }
//    printf(" [%08x (%d)]\n", READ_PERI_REG(UART_INT_ST(UART0)), READ_PERI_REG(UART_STATUS(UART0)) & (UART_RXFIFO_CNT << UART_RXFIFO_CNT_S));
    if (UART(UART0).INT_STATUS & UART_INT_STATUS_RXFIFO_FULL) {
        UART(UART0).INT_CLEAR = UART_INT_CLEAR_RXFIFO_FULL;
        if (UART(UART0).STATUS & (UART_STATUS_RXFIFO_COUNT_M << UART_STATUS_RXFIFO_COUNT_S)) {
            long int xHigherPriorityTaskWoken;
            _xt_isr_mask(1 << INUM_UART);
            _xt_clear_ints(1<<INUM_UART);
            xSemaphoreGiveFromISR(uart0_sem, &xHigherPriorityTaskWoken);
            if(xHigherPriorityTaskWoken) {
                portYIELD();
            }
        }
    } else {
        printf("Error: unexpected uart irq, INT_STATUS 0x%02x\n", UART(UART0).INT_STATUS);
    }
}