text mbed async putc

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text mbed async putc相关的知识,希望对你有一定的参考价值。

extern "C" {
int Putc(int c)
{
    static osThreadId threadIds[3] = { 0 };
    static std::vector<char> buffers[3];
    static int countIds = 0;
    static AAsyncSerialOut* aout;

    const osThreadId thisId = Thread::gettid();
    int index = -1;
    for (int i = 0; i < countIds; i++)
    {
        if (threadIds[i] == thisId)
        {
            index = i;
            break;
        }
    }

    if (index == -1)
    {
        X_ASSERT(countIds < X_COUNT_OF(threadIds));
        {
            CriticalSectionLock
            threadIds[countIds] = thisId;
            index = countIds++;
        }
        std::vector<char>* v = &buffers[index];
        v->reserve(AAsyncSerialOut::BLOCK_SZ);
    }

    std::vector<char>* v = &buffers[index];
    v->push_back(c);

    if (c == '\n' || (v->size() == (AAsyncSerialOut::BLOCK_SZ - 1)))
    {
        v->push_back('\0');
        aout->putString(v->data());
        v->clear();
    }

    return c;
}

以上是关于text mbed async putc的主要内容,如果未能解决你的问题,请参考以下文章

mbed的ticker问题

ROS+mbed 订阅者

ST Nucleo mbed套件开发 一 MBED环境使用 以Nucleo-F401为例

调用 get(fgetc) 和 putc(fputc) 函数进行输入输出

使用 Eclipse 调试 MBED

mbed + platformio.org:建议?