Browse Source

修改lvgl。cjson内存管理器

master
sc 6 months ago
parent
commit
541738319d
  1. BIN
      .settings/.rtmenus
  2. 10
      applications/PLC_link.c
  3. 29
      applications/lvgl/lv_port_mem.c
  4. 17
      applications/lvgl/lv_port_mem.h
  5. 3
      applications/sql/DB_SQLite.c
  6. 3
      applications/wdt.c
  7. 8
      packages/LVGL-v8.3.10/env_support/cmsis-pack/lv_conf_cmsis.h
  8. 12
      packages/LVGL-v8.3.10/env_support/rt-thread/lv_rt_thread_conf.h
  9. 6
      packages/LVGL-v8.3.10/lv_conf_template.h
  10. 26
      packages/cJSON-v1.7.17/cJSON.c
  11. 12
      packages/sqlite/sqlite3.c

BIN
.settings/.rtmenus

Binary file not shown.

10
applications/PLC_link.c

@ -29,6 +29,8 @@ static const mb_backend_param_t mb_bkd_prm = {
};
extern unsigned char sys_time[6];
uint8_t r_buffer[16],w_buffer[16];
uint16_t r_regsD[128],w_regsD[128];
static void mb_plc_read_regs(mb_inst_t *hinst)
{
@ -39,7 +41,7 @@ static void mb_plc_read_regs(mb_inst_t *hinst)
}
//输入m0000->rtu2000
uint8_t r_buffer[(DI_TABLE_SIZE + 7) / 8];
//uint8_t r_buffer[(DI_TABLE_SIZE + 7) / 8];
//读取 Modbus bits
int mrx = mb_read_bits(hinst, 2000, DI_TABLE_SIZE, r_buffer);
if (mrx > 0)
@ -53,7 +55,7 @@ static void mb_plc_read_regs(mb_inst_t *hinst)
}
// 输出 m0256 -> RTU 2256
uint8_t w_buffer[(DO_TABLE_SIZE + 7) / 8]; // 关键:初始化为0
//uint8_t w_buffer[(DO_TABLE_SIZE + 7) / 8]; // 关键:初始化为0
// 打包 do_table 到 bit_buffer
for (int i = 0; i < DO_TABLE_SIZE; i++) {
const int byte_idx = i / 8;
@ -73,7 +75,7 @@ static void mb_plc_read_regs(mb_inst_t *hinst)
}
//输入寄存器d0->6000
u16 r_regsD[AI_TABLE_SIZE];
//u16 r_regsD[AI_TABLE_SIZE];
// 读 Modbus
int mrd = mb_read_regs(hinst, 6000, AI_TABLE_SIZE, r_regsD);
if (mrd > 0)
@ -87,7 +89,7 @@ static void mb_plc_read_regs(mb_inst_t *hinst)
}
//输出寄存器d100->6100
u16 w_regsD [AO_TABLE_SIZE];
//u16 w_regsD [AO_TABLE_SIZE];
for (int i = 0; i < AO_TABLE_SIZE; i++)
{
w_regsD [i] = ao_table[i].current_Value;

29
applications/lvgl/lv_port_mem.c

@ -0,0 +1,29 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2026-01-24 Administrator the first version
*/
#include <rtthread.h>
#include "lvgl.h"
#include <stddef.h>
extern struct rt_memheap sdram_heap; //
void *lv_custom_mem_alloc(size_t size)
{
return rt_memheap_alloc(&sdram_heap, size);
}
void lv_custom_mem_free(void *ptr)
{
if (ptr) rt_memheap_free(ptr);
}
void *lv_custom_mem_realloc(void *ptr, size_t new_size)
{
return rt_memheap_realloc(&sdram_heap, ptr, new_size);
}

17
applications/lvgl/lv_port_mem.h

@ -0,0 +1,17 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2026-01-24 Administrator the first version
*/
#ifndef APPLICATIONS_LVGL_LV_PORT_MEM_H_
#define APPLICATIONS_LVGL_LV_PORT_MEM_H_
void *lv_custom_mem_alloc(size_t size);
void lv_custom_mem_free(void *ptr);
void *lv_custom_mem_realloc(void *ptr, size_t new_size);
#endif /* APPLICATIONS_LVGL_LV_PORT_MEM_H_ */

3
applications/sql/DB_SQLite.c

@ -190,8 +190,6 @@ void db_sqlite_init_full(void)
if (g_db)
{
sqlite3_close(g_db);
//限制缓存大小 (100KB)
sqlite3_exec(g_db, "PRAGMA cache_size = 50;", 0, 0, 0);
g_db = RT_NULL;
}
return; //
@ -286,7 +284,6 @@ static void db_sqlite(void *parameter) {
if (first_wait_done)
{
first_wait_done = RT_FALSE;
sqlite3_exec(g_db, "PRAGMA shrink_memory;", 0, 0, 0);
sqlite3_close(g_db);
g_db=RT_NULL;
op_link=0;

3
applications/wdt.c

@ -35,6 +35,9 @@ static void idle_hook(void)
static int wdt_sample()
{
rt_thread_mdelay(5000);
rt_err_t ret = RT_EOK;
rt_uint32_t timeout = 1; /* 溢出时间,单位:秒 */
char device_name[RT_NAME_MAX];

8
packages/LVGL-v8.3.10/env_support/cmsis-pack/lv_conf_cmsis.h

@ -39,7 +39,7 @@
*=========================*/
/*1: use custom malloc/free, 0: use the built-in `lv_mem_alloc()` and `lv_mem_free()`*/
#define LV_MEM_CUSTOM 0
#define LV_MEM_CUSTOM 1
#if LV_MEM_CUSTOM == 0
/*Size of the memory available for `lv_mem_alloc()` in bytes (>= 2kB)*/
#define LV_MEM_SIZE (64U * 1024U) /*[bytes]*/
@ -54,9 +54,9 @@
#else /*LV_MEM_CUSTOM*/
#define LV_MEM_CUSTOM_INCLUDE <stdlib.h> /*Header for the dynamic memory function*/
#define LV_MEM_CUSTOM_ALLOC malloc
#define LV_MEM_CUSTOM_FREE free
#define LV_MEM_CUSTOM_REALLOC realloc
#define LV_MEM_CUSTOM_ALLOC rt_memheap_alloc(&sdram_heap)
#define LV_MEM_CUSTOM_FREE rt_memheap_free()
#define LV_MEM_CUSTOM_REALLOC rt_memheap_realloc(&sdram_heap)
#endif /*LV_MEM_CUSTOM*/
/*Number of the intermediate memory buffer used during rendering and other internal processing mechanisms.

12
packages/LVGL-v8.3.10/env_support/rt-thread/lv_rt_thread_conf.h

@ -23,9 +23,15 @@
#ifdef RT_USING_HEAP
# define LV_MEM_CUSTOM 1
# define LV_MEM_CUSTOM_INCLUDE LV_RTTHREAD_INCLUDE
# define LV_MEM_CUSTOM_ALLOC rt_malloc
# define LV_MEM_CUSTOM_FREE rt_free
# define LV_MEM_CUSTOM_REALLOC rt_realloc
//# define LV_MEM_CUSTOM_ALLOC rt_malloc
//# define LV_MEM_CUSTOM_FREE rt_free
//# define LV_MEM_CUSTOM_REALLOC rt_realloc
extern struct rt_memheap sdram_heap;
#define LV_MEM_CUSTOM_ALLOC(x) rt_memheap_alloc(&sdram_heap,(rt_size_t)x)
#define LV_MEM_CUSTOM_FREE rt_memheap_free
#define LV_MEM_CUSTOM_REALLOC(x,y) rt_memheap_realloc(&sdram_heap,(x),(rt_size_t)(y))
#endif
/*====================

6
packages/LVGL-v8.3.10/lv_conf_template.h

@ -61,9 +61,9 @@
#else /*LV_MEM_CUSTOM*/
#define LV_MEM_CUSTOM_INCLUDE <stdlib.h> /*Header for the dynamic memory function*/
#define LV_MEM_CUSTOM_ALLOC malloc
#define LV_MEM_CUSTOM_FREE free
#define LV_MEM_CUSTOM_REALLOC realloc
#define LV_MEM_CUSTOM_ALLOC rt_memheap_alloc(&sdram_heap)
#define LV_MEM_CUSTOM_FREE rt_memheap_free()
#define LV_MEM_CUSTOM_REALLOC rt_memheap_realloc(&sdram_heap)
#endif /*LV_MEM_CUSTOM*/
/*Number of the intermediate memory buffer used during rendering and other internal processing mechanisms.

26
packages/cJSON-v1.7.17/cJSON.c

@ -176,9 +176,29 @@ static void * CJSON_CDECL internal_realloc(void *pointer, size_t size)
return realloc(pointer, size);
}
#elif defined(__RTTHREAD__)
#define internal_malloc rt_malloc
#define internal_free rt_free
#define internal_realloc rt_realloc
//#define internal_malloc rt_malloc
//#define internal_free rt_free
//#define internal_realloc rt_realloc
extern struct rt_memheap sdram_heap;
void *cjson_malloc(size_t size)
{
return rt_memheap_alloc(&sdram_heap, size);
}
void cjson_free(void *ptr)
{
if (ptr)
rt_memheap_free(ptr);
}
void* cjson_realloc(void *ptr, size_t new_size) {
return rt_memheap_realloc(&sdram_heap, ptr, new_size);
}
#define internal_malloc cjson_malloc
#define internal_free cjson_free
#define internal_realloc cjson_realloc
#else
#define internal_malloc malloc
#define internal_free free

12
packages/sqlite/sqlite3.c

@ -20727,13 +20727,13 @@ static malloc_zone_t* _sqliteZone_;
** Use standard C library malloc and free on non-Apple systems.
** Also used by rt-thread systems if SQLITE_WITHOUT_ZONEMALLOC is defined.
*/
extern struct rt_memheap sram_DTCMRAM;
#define SQLITE_MALLOC(x) rt_memheap_alloc(&sram_DTCMRAM,(rt_size_t)x)
/*extern struct rt_memheap sdram_heap;
#define SQLITE_MALLOC(x) rt_memheap_alloc(&sdram_heap,(rt_size_t)x)
#define SQLITE_FREE(x) rt_memheap_free(x)
#define SQLITE_REALLOC(x,y) rt_memheap_realloc(&sram_DTCMRAM,(x),(rt_size_t)(y))
//#define SQLITE_MALLOC(x) rt_malloc((rt_size_t)x)
//#define SQLITE_FREE(x) rt_free(x)
//#define SQLITE_REALLOC(x,y) rt_realloc((x),(rt_size_t)(y))
#define SQLITE_REALLOC(x,y) rt_memheap_realloc(&sdram_heap,(x),(rt_size_t)(y))*/
#define SQLITE_MALLOC(x) rt_malloc((rt_size_t)x)
#define SQLITE_FREE(x) rt_free(x)
#define SQLITE_REALLOC(x,y) rt_realloc((x),(rt_size_t)(y))
#if (!defined(SQLITE_WITHOUT_MSIZE)) \
&& (defined(HAVE_MALLOC_H) && defined(HAVE_MALLOC_USABLE_SIZE))

Loading…
Cancel
Save