嵌入式中通过可变参数va实现printf

最近在做一个和dsp相关的代码,dsp中通过配置寄存器实现了hifi_puts可以打印字符串,但是还不能像pc上编程一样使用printf打印可变参数,通过下面的方法hifi_printf可以打印可变参数。

int hifi_printf(const char *fmt, ...)
{
        va_list va;
        char str[256];
        int ret;

        va_start(va, fmt);
        ret = vsprintf(str, fmt, va);
        hifi_puts(str);
        va_end(va);

        return ret;
}

猜你喜欢

转载自blog.csdn.net/luckywang1103/article/details/78849714