This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

uart interrupt

Hi everybody,

Could you please help me: i need to use an uart interrupt routine in a RTX code. I've already found some examples for the uart interrupt routine, but i cannot make it work using tasks.
Has anybody an example to show me how to use it.
Thanks

Parents
  • Hello,

    Using tasks should not change things too much.
    Often events are used to signal to a task that an interrupt has occurred.

    For example:

    TASK -

    __task void task_uart(void)
    {
        for (;;)
        {
            os_evt_wait_or(CHAR_READY_EVENT, 0xFFFF);
    
            // handle char...
    
            NVIC_EnableIRQ(UART_IQRn);
    
        }
    
    }
    

    IRQ -

    void UART_IRQHandler (void)
    {
        uint32_t intsrc, tmp;
        /* Determine the interrupt source */
        intsrc = UART_GetIntId(UART_PORT);
        tmp = intsrc & UART_IIR_INTID_MASK;
    
        // Receive Data Available
        if (tmp & UART_IIR_INTID_RDA)
        {
            last_received_char = UART_ReceiveByte(UART_PORT);
            NVIC_DisableIRQ(UART_IQRn);
            isr_evt_set (CHAR_READY_EVENT, t_uart);     // Send Event Flag to task
        }
    
        NVIC_ClearPendingIRQ(TERNIAL_IQRn);   // Clear Interrupt
    }
    

    Hope this helps.

Reply
  • Hello,

    Using tasks should not change things too much.
    Often events are used to signal to a task that an interrupt has occurred.

    For example:

    TASK -

    __task void task_uart(void)
    {
        for (;;)
        {
            os_evt_wait_or(CHAR_READY_EVENT, 0xFFFF);
    
            // handle char...
    
            NVIC_EnableIRQ(UART_IQRn);
    
        }
    
    }
    

    IRQ -

    void UART_IRQHandler (void)
    {
        uint32_t intsrc, tmp;
        /* Determine the interrupt source */
        intsrc = UART_GetIntId(UART_PORT);
        tmp = intsrc & UART_IIR_INTID_MASK;
    
        // Receive Data Available
        if (tmp & UART_IIR_INTID_RDA)
        {
            last_received_char = UART_ReceiveByte(UART_PORT);
            NVIC_DisableIRQ(UART_IQRn);
            isr_evt_set (CHAR_READY_EVENT, t_uart);     // Send Event Flag to task
        }
    
        NVIC_ClearPendingIRQ(TERNIAL_IQRn);   // Clear Interrupt
    }
    

    Hope this helps.

Children