当前位置: 移动技术网 > IT编程>开发语言>JavaScript > RTOS移植cJSON

RTOS移植cJSON

2020年09月01日  | 移动技术网IT编程  | 我要评论
简介cJSON需要调用内存管理函数,由于RTOS有其独立的内存管理函数,需对接接口。对接内存管理函数这里以FreeRTOS为例,在GitHub上找最新的cJSON(新版cJSON优化了解析速度等)。注释掉原先的,替换为FreeRTOS的://#define internal_malloc malloc//#define internal_free free//#define internal_realloc realloc#include "cmsis_os.h"#define intern

简介

cJSON需要调用内存管理函数,由于RTOS有其独立的内存管理函数,需对接接口。

对接内存管理函数

这里以FreeRTOS为例,在GitHub上找最新的cJSON(新版cJSON优化了解析速度等)。注释掉原先的,替换为FreeRTOS的:

//#define internal_malloc malloc
//#define internal_free free
//#define internal_realloc realloc
#include "cmsis_os.h"
#define internal_malloc pvPortMalloc
#define internal_free vPortFree
#define internal_realloc NULL

修改浮点打印

一般RTOS或单片机,不支持浮点打印,导致JSON对象转换为字符串格式的时候,如果该对象里包含数字的值时,会出现错误,需注释掉有%f的代码。修改如下所示:

#ifdef FREERTOS_SYSTEM_CALL
        length = sprintf((char*)number_buffer, "%d", item->valueint);
#else
        /* Try 15 decimal places of precision to avoid nonsignificant nonzero digits */
        length = sprintf((char*)number_buffer, "%1.15g", d);

        /* Check whether the original double can be recovered */
        if ((sscanf((char*)number_buffer, "%lg", &test) != 1) || !compare_double((double)test, d))
        {
            /* If not, print with 17 decimal places of precision */
            length = sprintf((char*)number_buffer, "%1.17g", d);
        }
#endif

本文地址:https://blog.csdn.net/u013115811/article/details/108583643

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网