From ad2e19d4fe8331978c947b363d149263e3a3aa27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sun, 24 Dec 2017 16:09:21 +0100 Subject: [PATCH] use bulk typedefs in functions, add monitoring of msg queue usage to stackmon --- comm/msg_bulkread.c | 4 ++-- comm/msg_bulkread.h | 2 +- comm/msg_bulkwrite.c | 4 ++-- comm/msg_bulkwrite.h | 2 +- freertos.c | 6 +++--- tasks/sched_queue.h | 2 +- tasks/task_msg.c | 10 ++++++++-- tasks/task_sched.h | 1 + units/test/unit_test.c | 6 +++--- utils/stacksmon.c | 4 ++++ 10 files changed, 26 insertions(+), 15 deletions(-) diff --git a/comm/msg_bulkread.c b/comm/msg_bulkread.c index 9ee55c3..1151b23 100644 --- a/comm/msg_bulkread.c +++ b/comm/msg_bulkread.c @@ -18,7 +18,7 @@ static uint8_t bulkread_buffer[BULKREAD_MAX_CHUNK]; */ static TF_Result bulkread_lst(TinyFrame *tf, TF_Msg *msg) { - struct bulk_read *bulk = msg->userdata; + BulkRead *bulk = msg->userdata; // this is a final call before timeout, to clean up if (msg->data == NULL) { @@ -69,7 +69,7 @@ close: } /** Start the bulk read flow */ -void bulkread_start(TinyFrame *tf, struct bulk_read *bulk) +void bulkread_start(TinyFrame *tf, BulkRead *bulk) { assert_param(bulk); assert_param(bulk->len); diff --git a/comm/msg_bulkread.h b/comm/msg_bulkread.h index abe49fb..91ad454 100644 --- a/comm/msg_bulkread.h +++ b/comm/msg_bulkread.h @@ -39,7 +39,7 @@ struct bulk_read { * @param tf - tinyframe instance * @param bulk - bulk read config structure (malloc'd or static) */ -void bulkread_start(TinyFrame *tf, struct bulk_read *bulk); +void bulkread_start(TinyFrame *tf, BulkRead *bulk); #endif //GEX_F072_MSG_BULKREAD_H diff --git a/comm/msg_bulkwrite.c b/comm/msg_bulkwrite.c index bd42b27..ef605bb 100644 --- a/comm/msg_bulkwrite.c +++ b/comm/msg_bulkwrite.c @@ -15,7 +15,7 @@ */ static TF_Result bulkwrite_lst(TinyFrame *tf, TF_Msg *msg) { - struct bulk_write *bulk = msg->userdata; + BulkWrite *bulk = msg->userdata; // this is a final call before timeout, to clean up if (msg->data == NULL) { @@ -60,7 +60,7 @@ close: } /** Start the bulk write flow */ -void bulkwrite_start(TinyFrame *tf, struct bulk_write *bulk) +void bulkwrite_start(TinyFrame *tf, BulkWrite *bulk) { assert_param(bulk); assert_param(bulk->len); diff --git a/comm/msg_bulkwrite.h b/comm/msg_bulkwrite.h index 4391dab..b1c2121 100644 --- a/comm/msg_bulkwrite.h +++ b/comm/msg_bulkwrite.h @@ -35,7 +35,7 @@ struct bulk_write { * @param tf - tinyframe instance * @param bulk - bulk write config structure (malloc'd or static) */ -void bulkwrite_start(TinyFrame *tf, struct bulk_write *bulk); +void bulkwrite_start(TinyFrame *tf, BulkWrite *bulk); #endif //GEX_F072_MSG_BULKWRITE_H diff --git a/freertos.c b/freertos.c index 1e0e3fd..ae26eb3 100644 --- a/freertos.c +++ b/freertos.c @@ -58,9 +58,9 @@ /* Variables -----------------------------------------------------------------*/ -#define STACK_MAIN 160 -#define STACK_MSG 230 -#define STACK_JOBRUNNER 150 +#define STACK_MAIN 150 +#define STACK_MSG 150 +#define STACK_JOBRUNNER 128 osThreadId tskMainHandle; uint32_t mainTaskBuffer[ STACK_MAIN ]; diff --git a/tasks/sched_queue.h b/tasks/sched_queue.h index 14662ee..f9a80d8 100644 --- a/tasks/sched_queue.h +++ b/tasks/sched_queue.h @@ -36,6 +36,6 @@ struct rx_que_item { }; #define HP_SCHED_CAPACITY 5 -#define RX_QUE_CAPACITY 16 +#define RX_QUE_CAPACITY 10 #endif //GEX_SCHED_QUEUE_H diff --git a/tasks/task_msg.c b/tasks/task_msg.c index b4bcc35..88d1fb4 100644 --- a/tasks/task_msg.c +++ b/tasks/task_msg.c @@ -4,9 +4,9 @@ #include "platform.h" #include "comm/messages.h" -#include "utils/hexdump.h" #include "task_msg.h" -#include "sched_queue.h" + +volatile uint32_t msgQueHighWaterMark = 0; /** * Process data received from TinyFrame. @@ -27,5 +27,11 @@ void TaskMessaging(const void * argument) assert_param(slot.len>0 && slot.len<=64); // check the len is within bounds TF_Accept(comm, slot.data, slot.len); + +#if USE_STACK_MONITOR + uint32_t count; + count = (uint32_t) uxQueueMessagesWaiting(queRxDataHandle); // this seems to return N+1, hence we don't add the +1 for the one just removed. + msgQueHighWaterMark = MAX(msgQueHighWaterMark, count); +#endif } } \ No newline at end of file diff --git a/tasks/task_sched.h b/tasks/task_sched.h index 0841991..ed9c070 100644 --- a/tasks/task_sched.h +++ b/tasks/task_sched.h @@ -10,6 +10,7 @@ #if USE_STACK_MONITOR extern volatile uint32_t jobQueHighWaterMark; +extern volatile uint32_t msgQueHighWaterMark; #endif extern osThreadId tskJobRunnerHandle; diff --git a/units/test/unit_test.c b/units/test/unit_test.c index 55e5fdb..e7edcac 100644 --- a/units/test/unit_test.c +++ b/units/test/unit_test.c @@ -141,7 +141,7 @@ static bool Tst_handleRequest(Unit *unit, TF_ID frame_id, uint8_t command, Paylo break; case CMD_BULKREAD:; - struct bulk_read *br = malloc(sizeof(struct bulk_read)); + BulkRead *br = malloc(sizeof(struct bulk_read)); assert_param(br); br->len = (uint32_t) strlen(longtext); @@ -152,10 +152,10 @@ static bool Tst_handleRequest(Unit *unit, TF_ID frame_id, uint8_t command, Paylo break; case CMD_BULKWRITE:; - struct bulk_write *bw = malloc(sizeof(struct bulk_write)); + BulkWrite *bw = malloc(sizeof(struct bulk_write)); assert_param(bw); - bw->len = 1024; + bw->len = 10240; bw->frame_id = frame_id; bw->write = bw_dump; diff --git a/utils/stacksmon.c b/utils/stacksmon.c index 12078d8..cc8d753 100644 --- a/utils/stacksmon.c +++ b/utils/stacksmon.c @@ -68,6 +68,10 @@ void stackmon_dump(void) PRINTF(" Used slots: \033[33m%"PRIu32"\033[m\r\n", jobQueHighWaterMark); + PUTS("\033[36m>> MSG QUEUE\033[m\r\n"); + PRINTF(" Used slots: \033[33m%"PRIu32"\033[m\r\n", + msgQueHighWaterMark); + PRINTF("\033[1m---------------------------\033[m\r\n\r\n"); }