Example #1
0
CPU_INT08U  BSP_Ser_RdByteUnlocked (void)
{

    CPU_INT08U   rx_byte;


    USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);              /* Enable the Receive not empty interrupt             */

    BSP_OS_SemWait(&BSP_SerRxWait, 0);                          /* Wait until data is received                        */

    USART_ITConfig(USART2, USART_IT_RXNE, DISABLE);             /* Disable the Receive not empty interrupt            */

    rx_byte = BSP_SerRxData;                                    /* Read the data from the temporary register          */

    return (rx_byte);
}
CPU_INT08U  BSP_Ser_RdByteUnlocked (void)
{
    CPU_INT08U   rx_byte;


    IEN(SCI2, RXI2)  = 1;                                       /* Enable the Receive Data Register Full interrupt.     */
    SCI2.SCR.BIT.RIE = 1;                                       /* Enable Receive Interrupts                            */

    BSP_OS_SemWait(&BSP_SerRxWait, 0);                          /* Wait until a data is received                        */

    IEN(SCI2, RXI2)  = 0;                                       /* Disable the Receive Data Register Full interrupt.    */
    SCI2.SCR.BIT.RIE = 0;                                       /* Disable Receive Interrupts                           */

    rx_byte = BSP_SerRxData;                                    /* Read the data form the temporal register.            */

    return (rx_byte);
}
Example #3
0
CPU_INT08U  BSP_Ser_RdByteNB (CPU_INT08U* p_err)
{
    CPU_INT08U  rx_byte = 0;


    *p_err = BSP_SER_ERR_NO_INIT;
    if (BSP_SerialInitilizated == DEF_TRUE)
    {
        BSP_OS_SemWait(&BSP_SerLock, 0);                        /* Obtain access to the serial interface            */
        *p_err = BSP_SER_ERR_RXBUFFER_EMPTY;
        if (BSP_RxBuffer_Head_ndx != BSP_RxBuffer_Tail_ndx)
        {
            rx_byte = BSP_Ser_RdByteUnlocked();                 /* Get a byte from the Rx buffer                    */
            *p_err = BSP_SER_ERR_NONE;
        }
        BSP_OS_SemPost(&BSP_SerLock);                           /* Release access to the serial interface           */
    }
    return (rx_byte);
}
Example #4
0
void  BSP_Ser_WrByteUnlocked (CPU_INT08U uData)
{
    CPU_INT16U  uUpdatedHeadNdx;

    if (BSP_SerialInitilizated == DEF_TRUE)
    {
        do
        {
            BSP_OS_SemWait(&BSP_SerTxWait, 10);
            uUpdatedHeadNdx = BSP_TxBuffer_Head_ndx;
            if (++uUpdatedHeadNdx >= BSP_UART2_TX_BUFFER_SIZE)
            {
                uUpdatedHeadNdx = 0;
            }
        } while (uUpdatedHeadNdx == BSP_TxBuffer_Tail_ndx);

        USART_ITConfig(USART2, USART_IT_TXE, DISABLE);
        BSP_SerialTxBuffer[BSP_TxBuffer_Head_ndx] = uData;
        BSP_TxBuffer_Head_ndx = uUpdatedHeadNdx;
        USART_ITConfig(USART2, USART_IT_TXE, ENABLE);
    }
}
Example #5
0
CPU_INT08U  BSP_Ser_RdByteUnlocked (void)
{

    CPU_INT08U   rx_byte = 0;

    if (BSP_SerialInitilizated == DEF_TRUE)
    {
        do
        {
            BSP_OS_SemWait(&BSP_SerRxWait, 2);                      /* Block until a byte is available                  */
        } while (BSP_RxBuffer_Head_ndx == BSP_RxBuffer_Tail_ndx);

        USART_ITConfig(USART2, USART_IT_RXNE, DISABLE);             /* Disable the "Receive not empty interrupt"        */
        rx_byte = BSP_SerialRxBuffer[BSP_RxBuffer_Tail_ndx++];      /* Read a byte from the Rx buffer                   */
        if (BSP_RxBuffer_Tail_ndx >= BSP_UART2_RX_BUFFER_SIZE)      /* Update Rx buffer Tail index                      */
        {
            BSP_RxBuffer_Tail_ndx = 0;
        }
        USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);              /* Re-enable the "Receive not empty" interrupt      */
    }
    return (rx_byte);
}
Example #6
0
void  BSP_Ser_WrStr (CPU_CHAR  *p_str)
{
    CPU_BOOLEAN  err;


    if (BSP_SerialInitilizated == DEF_TRUE)
    {
        err = BSP_OS_SemWait(&BSP_SerLock, 0);                      /* Obtain access to the serial interface              */
        if (err != DEF_OK ) {
            return;
        }
        while ((*p_str) != (CPU_CHAR )0) {

            if (*p_str == ASCII_CHAR_LINE_FEED) {
                BSP_Ser_WrByteUnlocked(ASCII_CHAR_CARRIAGE_RETURN);
                BSP_Ser_WrByteUnlocked(ASCII_CHAR_LINE_FEED);
                p_str++;
            } else {
                BSP_Ser_WrByteUnlocked(*p_str++);
            }
        }
        BSP_OS_SemPost(&BSP_SerLock);                               /* Release access to the serial interface             */
    }
}
Example #7
0
void  BSP_Ser_RdStr (CPU_CHAR    *p_str,
                     CPU_INT16U   len)
{
    CPU_CHAR     *p_char;
    CPU_BOOLEAN   rxd_history_char0;
    CPU_CHAR      rx_data;
    CPU_BOOLEAN   err;


    rxd_history_char0 = DEF_NO;
    p_str[0]          = (CPU_CHAR)'\0';
    p_char            = p_str;

    err = BSP_OS_SemWait(&BSP_SerLock, 0);                      /* Obtain access to the serial interface                */

    if (err != DEF_OK ) {
        return;
    }

    while (DEF_TRUE)
    {
        rx_data = BSP_Ser_RdByteUnlocked();

        if ((rx_data == ASCII_CHAR_CARRIAGE_RETURN) ||          /* Is it '\r' or '\n' character  ?                      */
            (rx_data == ASCII_CHAR_LINE_FEED      )) {

            BSP_Ser_WrByteUnlocked((CPU_INT08U)ASCII_CHAR_LINE_FEED);
            BSP_Ser_WrByteUnlocked((CPU_INT08U)ASCII_CHAR_CARRIAGE_RETURN);
           *p_char = (CPU_CHAR)'\0';                            /* set the null character at the end of the string      */
#if (BSP_CFG_SER_CMD_HISTORY_LEN > 0u)
            Str_Copy(BSP_SerCmdHistory, p_str);
#endif
            break;                                              /* exit the loop                                        */
        }

        if (rx_data == ASCII_CHAR_BACKSPACE) {                  /* Is backspace character                               */
            if (p_char > p_str) {
                BSP_Ser_WrByteUnlocked((CPU_INT08U)ASCII_CHAR_BACKSPACE);
                p_char--;                                       /* Decrement the index                                  */
            }
        }

        if ((ASCII_IsPrint(rx_data)      ) &&
            (rxd_history_char0 == DEF_NO)) {                    /* Is it a printable character ... ?                    */
            BSP_Ser_WrByteUnlocked((CPU_INT08U)rx_data);        /* Echo-back                                            */
           *p_char = rx_data;                                   /* Save the received character in the buffer            */
            p_char++;                                           /* Increment the buffer index                           */
            if (p_char >= &p_str[len]) {
                p_char  = &p_str[len];
            }

        } else if ((rx_data           == ASCII_CHAR_ESCAPE) &&
                   (rxd_history_char0 == DEF_NO           )) {
            rxd_history_char0 = DEF_YES;

#if (BSP_CFG_SER_CMD_HISTORY_LEN > 0u)
        } else if ((rx_data           == ASCII_CHAR_LEFT_SQUARE_BRACKET) &&
                   (rxd_history_char0 == DEF_YES                       )) {

            while (p_char != p_str) {
                BSP_Ser_WrByteUnlocked((CPU_INT08U)ASCII_CHAR_BACKSPACE);
                p_char--;                                       /* Decrement the index                                  */
            }

            Str_Copy(p_str, BSP_SerCmdHistory);

            while (*p_char != '\0') {
                BSP_Ser_WrByteUnlocked(*p_char++);
            }
#endif
        } else {
            rxd_history_char0 = DEF_NO;
        }
    }

    BSP_OS_SemPost(&BSP_SerLock);                               /* Release access to the serial interface               */
}