From 05875a8167970cb69b3bac1ea84114a71b187068 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sun, 14 Jan 2018 00:21:13 +0100 Subject: [PATCH] fixed bogus slotcount use display + moved some stuff to dynalloc to save ram --- USB/usbd_conf.c | 13 +++---------- comm/msg_bulkread.c | 11 ++++++----- comm/msg_bulkread.h | 1 + tasks/task_msg.c | 2 +- utils/stacksmon.c | 2 +- 5 files changed, 12 insertions(+), 17 deletions(-) diff --git a/USB/usbd_conf.c b/USB/usbd_conf.c index 3f9f3ab..4e29378 100644 --- a/USB/usbd_conf.c +++ b/USB/usbd_conf.c @@ -47,6 +47,7 @@ ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ +#include #include "platform.h" #include "usbd_def.h" #include "usbd_core.h" @@ -633,8 +634,6 @@ void USBD_LL_Delay (uint32_t Delay) HAL_Delay(Delay); } -static uint32_t _static_malloc_pos = 0; - /** * @brief static single allocation. * @param size: size of allocated memory @@ -642,11 +641,7 @@ static uint32_t _static_malloc_pos = 0; */ void *USBD_static_malloc(uint32_t size) { - // XXX this was modified to support multiple classes - static uint32_t mem[(sizeof(USBD_MSC_BOT_HandleTypeDef)/4)+1+(sizeof(USBD_CDC_HandleTypeDef)/4)+1];/* On 32-bit boundary */ - uint32_t oldpos = _static_malloc_pos; - _static_malloc_pos += size/4+1; - return &mem[oldpos]; + return malloc_ck(size); } /** @@ -656,9 +651,7 @@ void *USBD_static_malloc(uint32_t size) */ void USBD_static_free(void *p) { - // This is wrong, but will work if both frees and malloc's - // are always called together and not interleaved - _static_malloc_pos = 0; + free_ck(p); } /** diff --git a/comm/msg_bulkread.c b/comm/msg_bulkread.c index 0bc31f8..15dfd0f 100644 --- a/comm/msg_bulkread.c +++ b/comm/msg_bulkread.c @@ -5,14 +5,12 @@ #include "platform.h" #include +#include "utils/malloc_safe.h" #include "messages.h" #include "utils/payload_parser.h" #include "utils/payload_builder.h" -/** Buffer for preparing bulk chunks */ -static uint8_t bulkread_buffer[BULK_READ_BUF_LEN]; - /** * TF listener for the bulk read transaction */ @@ -26,6 +24,7 @@ static TF_Result bulkread_lst(TinyFrame *tf, TF_Msg *msg) } assert_param(NULL != bulk); + assert_param(NULL != bulk->_buffer); if (msg->type == MSG_BULK_ABORT) { goto close; @@ -39,7 +38,7 @@ static TF_Result bulkread_lst(TinyFrame *tf, TF_Msg *msg) chunk = MIN(chunk, BULK_READ_BUF_LEN); // load data into the buffer - bulk->read(bulk, chunk, bulkread_buffer); + bulk->read(bulk, chunk, bulk->_buffer); bool last = (bulk->offset + chunk >= bulk->len); @@ -47,7 +46,7 @@ static TF_Result bulkread_lst(TinyFrame *tf, TF_Msg *msg) TF_ClearMsg(&resp); resp.frame_id = bulk->frame_id; resp.type = (last ? MSG_BULK_END : MSG_BULK_DATA); // the last chunk has the END type - resp.data = bulkread_buffer; + resp.data = bulk->_buffer; resp.len = (TF_LEN) chunk; TF_Respond(tf, &resp); @@ -64,6 +63,7 @@ close: // Ask user to free the bulk and userdata bulk->read(bulk, 0, NULL); msg->userdata = NULL; + free_ck(bulk->_buffer); } return TF_CLOSE; } @@ -76,6 +76,7 @@ void bulkread_start(TinyFrame *tf, BulkRead *bulk) assert_param(bulk->read); bulk->offset = 0; + bulk->_buffer = malloc_ck(BULK_READ_BUF_LEN); { uint8_t buf[8]; diff --git a/comm/msg_bulkread.h b/comm/msg_bulkread.h index 91ad454..eb9fefe 100644 --- a/comm/msg_bulkread.h +++ b/comm/msg_bulkread.h @@ -30,6 +30,7 @@ struct bulk_read { bulkread_data_cb read; //!< Read callback uint32_t len; //!< Total data length void *userdata; //!< A place for arbitrary userdata + uint8_t *_buffer; uint32_t offset; //!< Internal offset counter, will be set to 0 on start. }; diff --git a/tasks/task_msg.c b/tasks/task_msg.c index 4a51a98..510ef9e 100644 --- a/tasks/task_msg.c +++ b/tasks/task_msg.c @@ -80,7 +80,7 @@ void TaskMsgJob(const void *argument) #if USE_STACK_MONITOR uint32_t count; - count = (uint32_t) uxQueueMessagesWaiting(queMsgJobHandle); // this seems to return N+1, hence we don't add the +1 for the one just removed. + count = (uint32_t) uxQueueMessagesWaiting(queMsgJobHandle)+1; msgQueHighWaterMark = MAX(msgQueHighWaterMark, count); #endif } diff --git a/utils/stacksmon.c b/utils/stacksmon.c index a9df241..1fce31c 100644 --- a/utils/stacksmon.c +++ b/utils/stacksmon.c @@ -15,7 +15,7 @@ struct stackhandle { uint32_t len; }; -#define STACK_NUM 8 +#define STACK_NUM 3 static uint32_t nextidx = 0; static struct stackhandle stacks[STACK_NUM];