From 44a400b0270f0f0d160c8440988e17d6ef14a34a Mon Sep 17 00:00:00 2001 From: strawmanbobi Date: Wed, 31 Jan 2018 21:18:12 +0800 Subject: [PATCH] moved tags to data zone to save heap for some scm --- src/ir_decoder/CMakeLists.txt | 2 +- src/ir_decoder/src/ir_ac_binary_parse.c | 12 +++++++++--- src/ir_decoder/src/ir_ac_control.c | 9 ++++++++- src/ir_decoder/src/ir_decode.c | 9 ++++++++- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/ir_decoder/CMakeLists.txt b/src/ir_decoder/CMakeLists.txt index 552a868..3cc941f 100644 --- a/src/ir_decoder/CMakeLists.txt +++ b/src/ir_decoder/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.2) ######################################################## project(irda_decoder) # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") -add_definitions(-DBOARD_PC) +add_definitions(-DBOARD_PC -DDEBUG) # add_definitions(-DBOARD_PC -DBOARD_PC_JNI) IF (CMAKE_SYSTEM_NAME MATCHES "Linux") diff --git a/src/ir_decoder/src/ir_ac_binary_parse.c b/src/ir_decoder/src/ir_ac_binary_parse.c index 3765810..b3360a4 100644 --- a/src/ir_decoder/src/ir_ac_binary_parse.c +++ b/src/ir_decoder/src/ir_ac_binary_parse.c @@ -9,15 +9,18 @@ Revision log: * 2017-01-03: created by strawmanbobi **************************************************************************************/ -#include - #include "../include/ir_ac_binary_parse.h" #include "../include/ir_decode.h" UINT16 tag_head_offset = 0; extern struct ir_bin_buffer *p_ir_buffer; -extern struct tag_head *tags; + +#if defined USE_DYNAMIC_TAG +extern struct tag_head* tags; +#else +extern struct tag_head tags[]; +#endif UINT8 tag_count = 0; const UINT16 tag_index[TAG_COUNT_FOR_PROTOCOL] = @@ -40,11 +43,14 @@ INT8 binary_parse_offset() tag_head_offset = (UINT16) ((tag_count << 1) + 1); +#if defined USE_DYNAMIC_TAG tags = (t_tag_head *) ir_malloc(tag_count * sizeof(t_tag_head)); + if (NULL == tags) { return IR_DECODE_FAILED; } +#endif for (i = 0; i < tag_count; i++) { diff --git a/src/ir_decoder/src/ir_ac_control.c b/src/ir_decoder/src/ir_ac_control.c index aebc888..3d07dc0 100644 --- a/src/ir_decoder/src/ir_ac_control.c +++ b/src/ir_decoder/src/ir_ac_control.c @@ -22,7 +22,12 @@ Revision log: #include "../include/ir_utils.h" +#if defined USE_DYNAMIC_TAG extern struct tag_head *tags; +#else +extern struct tag_head tags[]; +#endif + extern UINT8 tag_count; static INT8 ir_context_init(); @@ -87,8 +92,8 @@ INT8 ir_ac_lib_parse() context->si.type = SWING_TYPE_NORMAL; context->si.mode_count = 2; } - break; context->si.dir_index = 0; + break; } } @@ -360,11 +365,13 @@ INT8 ir_ac_lib_parse() } } +#if defined USE_DYNAMIC_TAG if (NULL != tags) { ir_free(tags); tags = NULL; } +#endif ir_hex_code = (UINT8 *) ir_malloc(context->default_code.len); if (NULL == ir_hex_code) diff --git a/src/ir_decoder/src/ir_decode.c b/src/ir_decoder/src/ir_decode.c index f2b8cdd..5391b2b 100644 --- a/src/ir_decoder/src/ir_decode.c +++ b/src/ir_decoder/src/ir_decode.c @@ -21,8 +21,12 @@ Revision log: struct ir_bin_buffer binary_file; struct ir_bin_buffer *p_ir_buffer = &binary_file; -struct tag_head *tags; +#if defined USE_DYNAMIC_TAG +struct tag_head *tags; +#else +struct tag_head tags[TAG_COUNT_FOR_PROTOCOL]; +#endif UINT8 *ir_hex_code = NULL; UINT8 ir_hex_len = 0; @@ -375,12 +379,15 @@ static UINT16 ir_ac_lib_control(t_remote_ac_status ac_status, UINT16 *user_data, static INT8 ir_ac_lib_close() { +#if defined USE_DYNAMIC_TAG // free context if (NULL != tags) { ir_free(tags); tags = NULL; } +#endif + free_ac_context(); return IR_DECODE_SUCCEEDED;