在MSP430上的ISR期间发送UART字节

时间:2016-09-29 15:32:45

标签: c uart msp430 isr

我正在努力找出在我的ISR中处理数据的最佳设计实践。我知道我希望我的ISR快速,所以在我的ISR期间将数据发送到UART是否可以?我做得太多了吗?

static void ParseRxData(const uint8_t rx_byte)
{
    // Only Allow ASCII Characters to be loaded into buffer
    // This will drop CR/LF etc, won't go in gRxBuffer
    if (rx_byte >= 0x20)
        gRxBuffer[gWrIndex++] = tolower(rx_byte); // stuff lowercase only into buffer

    if (rx_byte == 0x08) /* backspace */
    {
        UartSendChar(rx_byte);
        gWrIndex--; /* backup index to ignore previous character */
        UartSendChar(0x20); // space to clear old data
    }

    UartSendChar(rx_byte);

    if (gWrIndex == BUFFER_SIZE)
    {
        gWrIndex = 0;
    }

    if (rx_byte == 0x0A) // End of Command
    {
        gRxBuffer[gWrIndex] = 0;  // Add null pointer to end
        gFlagCmdReady = true;  // Set Global Flag Ready Command
        gWrIndex = 0;
    }
}


//******************************************************************************
//
//This is the USCI_A1 interrupt vector service routine.
//
//******************************************************************************
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_A1_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(USCI_A1_VECTOR)))
#endif
void EUSCI_A1_ISR(void)
{
    uint8_t RXData;
    switch(__even_in_range(UCA1IV,USCI_UART_UCTXCPTIFG))
    {
    case USCI_NONE: break;
    case USCI_UART_UCRXIFG:
        RXData = EUSCI_A_UART_receiveData(EUSCI_A1_BASE);
        ParseRxData(RXData);
        break;
    case USCI_UART_UCTXIFG: break;
    case USCI_UART_UCSTTIFG: break;
    case USCI_UART_UCTXCPTIFG: break;
    }
}

0 个答案:

没有答案