SER_serialWriteString Function
Answer
11/25/15 10:25 AM
Hey :)

At the moment there is no direct possibility to send ASCII strings via UART without writing an own function for this. Often you don't know the length of the strings you want to send or you don't want to count the character count after each length. Therefore I suggest to include a function like this:

SER_errorCode_t SER_serialWriteString(SER_device_t * serialDev_p, void * attr_p, const char * str)
{
    (void) attr_p;

    if ((uint32_t) serialDev_p->txBufDescr.Size - (uint32_t) serialDev_p->txBufDescr.Count)
    {
        return SER_RESOURCE;
    }

    while (*str != 0)
    {
        /* Atomically push a byte into the TX ring buffer */
        INT_Disable();

        if(RingBuf_Push(&serialDev_p->txBufDescr, *str++) != RB_SUCCESS)
        {
        return SER_RESOURCE;
        }

        /* Enable TXBL since we are now in a position to transmit */
        if (serialDev_p->hwType == SER_HWTYPE_LEUART)
        {
#ifdef LEUART_PRESENT
            ((LEUART_TypeDef *) SER_leuartBasePtrTable_ma[serialDev_p->hwDevicePort])->IEN |= LEUART_IEN_TXBL;
#else
            while (1);
#endif
        }
        else if (serialDev_p->hwType == SER_HWTYPE_USART)
        {
#ifdef USART_PRESENT
            ((USART_TypeDef *) SER_usartBasePtrTable_ma[(serialDev_p->hwDevicePort-LEUART_COUNT)])->IEN |= USART_IEN_TXBL;
#else
            while (1);
#endif
        }
        else if (serialDev_p->hwType == SER_HWTYPE_UART)
        {
#ifdef UART_PRESENT
            ((USART_TypeDef *) SER_uartBasePtrTable_ma[(serialDev_p->hwDevicePort-LEUART_COUNT-USART_COUNT)])->IEN |= USART_IEN_TXBL;
#else
            while (1);
#endif
        }
        else
        {
            while (1);
        }

        INT_Enable();
    }

    return SER_SUCCESS;
}

Best regards,

Kai Liebich
0 (0 Votes)
SER_serialWriteString Function
Answer
11/27/15 12:20 PM as a reply to Kai Clemens Liebich.
Hey Kai,

I forwarded your code sample to our devs so hopefully they will include it in the next release.

In addition to that, once this forums gets proper code highlighting (we're working on that), we'll make sure to give it a proper spot so other user can take advantage of that.

Thanks for sharing that,
Florian
0 (0 Votes)