diff --git a/TinyFrame/TF_Config.h b/TinyFrame/TF_Config.h index 992e9b8..42dd408 100644 --- a/TinyFrame/TF_Config.h +++ b/TinyFrame/TF_Config.h @@ -48,26 +48,6 @@ typedef uint8_t TF_COUNT; //----------------------------- PARAMETERS ---------------------------------- -// Maximum received payload size (static buffer) -// Larger payloads will be rejected. -#define TF_MAX_PAYLOAD_RX 640 -// Size of the sending buffer. Larger payloads will be split to pieces and sent -// in multiple calls to the write function. This can be lowered to reduce RAM usage. -#define TF_SENDBUF_LEN 64 - -// --- Listener counts - determine sizes of the static slot tables --- - -// Frame ID listeners (wait for response / multi-part message) -#define TF_MAX_ID_LST 4 -// Frame Type listeners (wait for frame with a specific first payload byte) -#define TF_MAX_TYPE_LST 6 -// Generic listeners (fallback if no other listener catches it) -#define TF_MAX_GEN_LST 1 - -// Timeout for receiving & parsing a frame -// ticks = number of calls to TF_Tick() -#define TF_PARSER_TIMEOUT_TICKS 250 - -//------------------------- End of user config ------------------------------ +// buffers, counts and timeout are defined in plat_compat.h #endif //TF_CONFIG_H diff --git a/USB/usbd_conf.h b/USB/usbd_conf.h index e66b34b..c029a71 100644 --- a/USB/usbd_conf.h +++ b/USB/usbd_conf.h @@ -76,7 +76,7 @@ /*---------- -----------*/ #define USBD_MAX_NUM_CONFIGURATION 1 /*---------- -----------*/ -#define USBD_MAX_STR_DESC_SIZ 128 +//#define USBD_MAX_STR_DESC_SIZ 128 /* Moved to plat_compat.h */ /*---------- -----------*/ #define USBD_SUPPORT_USER_STRING 1 /*---------- -----------*/ @@ -84,7 +84,7 @@ /*---------- -----------*/ #define USBD_SELF_POWERED 1 /*---------- -----------*/ -#define MSC_MEDIA_PACKET 512 +//#define MSC_MEDIA_PACKET 512 /* Moved to plat_compat.h */ /****************************************/ /* #define for FS and HS identification */ #define DEVICE_FS 0 diff --git a/comm/messages.h b/comm/messages.h index 8d113c2..8e0dcdf 100644 --- a/comm/messages.h +++ b/comm/messages.h @@ -5,13 +5,11 @@ #ifndef GEX_MESSAGES_H #define GEX_MESSAGES_H +#include "platform.h" #include "sched_queue.h" #include "task_sched.h" #include "TinyFrame.h" -#define BULK_LST_TIMEOUT_MS 200 -#define BULKREAD_MAX_CHUNK 512 // this is a static buffer - /** * Supported message types (TF_TYPE) */ diff --git a/comm/msg_responses.c b/comm/msg_responses.c index 3562b02..6b5b6a4 100644 --- a/comm/msg_responses.c +++ b/comm/msg_responses.c @@ -2,17 +2,16 @@ // Created by MightyPork on 2017/12/22. // +#include "platform.h" #include "messages.h" #include "msg_responses.h" void com_respond_snprintf(TF_ID frame_id, TF_TYPE type, const char *format, ...) { -#define ERR_STR_LEN 64 - - char buf[ERR_STR_LEN]; + char buf[ERR_MSG_STR_LEN]; va_list args; va_start(args, format); - uint32_t len = (uint32_t) fixup_vsnprintf(&buf[0], ERR_STR_LEN, format, args); + uint32_t len = (uint32_t) fixup_vsnprintf(&buf[0], ERR_MSG_STR_LEN, format, args); va_end(args); com_respond_buf(frame_id, type, (const uint8_t *) buf, len); diff --git a/debug.c b/debug.c index 7075fcb..7ef2342 100644 --- a/debug.c +++ b/debug.c @@ -7,8 +7,6 @@ #if USE_DEBUG_UART -#define DBG_BUF_LEN 80 - // debug printf int PRINTF(const char *format, ...) { diff --git a/framework/settings.c b/framework/settings.c index 62a276d..d15d4c3 100644 --- a/framework/settings.c +++ b/framework/settings.c @@ -2,8 +2,8 @@ // Created by MightyPork on 2017/11/26. // -#include "utils/hexdump.h" #include "platform.h" +#include "utils/hexdump.h" #include "settings.h" #include "unit_registry.h" #include "system_settings.h" @@ -47,8 +47,7 @@ void settings_load(void) } -#define SAVE_BUF_SIZE 256 -static uint8_t save_buffer[SAVE_BUF_SIZE]; +static uint8_t save_buffer[FLASH_SAVE_BUF_LEN]; static uint32_t save_addr; #if DEBUG_FLASH_WRITE @@ -126,7 +125,7 @@ static void savebuf_flush(PayloadBuilder *pb, bool final) */ static bool savebuf_ovhandler(PayloadBuilder *pb, uint32_t more) { - if (more > SAVE_BUF_SIZE) return false; + if (more > FLASH_SAVE_BUF_LEN) return false; savebuf_flush(pb, false); return true; } @@ -135,7 +134,7 @@ static bool savebuf_ovhandler(PayloadBuilder *pb, uint32_t more) void settings_save(void) { HAL_StatusTypeDef hst; - PayloadBuilder pb = pb_start(save_buffer, SAVE_BUF_SIZE, savebuf_ovhandler); + PayloadBuilder pb = pb_start(save_buffer, FLASH_SAVE_BUF_LEN, savebuf_ovhandler); save_addr = SETTINGS_FLASH_ADDR; diff --git a/freertos.c b/freertos.c index eff4d89..af2b0a9 100644 --- a/freertos.c +++ b/freertos.c @@ -48,30 +48,26 @@ /* Includes ------------------------------------------------------------------*/ #include "FreeRTOS.h" -#include "task.h" #include "cmsis_os.h" -/* USER CODE BEGIN Includes */ +/* USER CODE BEGIN Includes */ +#include "platform.h" #include "tasks/sched_queue.h" #include "stacksmon.h" /* USER CODE END Includes */ /* Variables -----------------------------------------------------------------*/ -#define STACK_MAIN 160 -#define STACK_MSG 200 -#define STACK_JOBRUNNER 128 - osThreadId tskMainHandle; -uint32_t mainTaskBuffer[ STACK_MAIN ]; +uint32_t mainTaskBuffer[ TSK_STACK_MAIN ]; osStaticThreadDef_t mainTaskControlBlock; osThreadId tskMsgHandle; -uint32_t msgTaskBuffer[ STACK_MSG ]; +uint32_t msgTaskBuffer[ TSK_STACK_MSG ]; osStaticThreadDef_t msgTaskControlBlock; osThreadId tskJobRunnerHandle; -uint32_t jobRunnerBuffer[ STACK_JOBRUNNER ]; +uint32_t jobRunnerBuffer[ TSK_STACK_JOBRUNNER ]; osStaticThreadDef_t jobRunnerControlBlock; osMessageQId queSchedHandle; @@ -166,15 +162,15 @@ void MX_FREERTOS_Init(void) { /* Create the thread(s) */ /* definition and creation of tskMain */ - osThreadStaticDef(tskMain, TaskMain, osPriorityHigh, 0, STACK_MAIN, mainTaskBuffer, &mainTaskControlBlock); + osThreadStaticDef(tskMain, TaskMain, osPriorityHigh, 0, TSK_STACK_MAIN, mainTaskBuffer, &mainTaskControlBlock); tskMainHandle = osThreadCreate(osThread(tskMain), NULL); /* definition and creation of tskJobRunner */ - osThreadStaticDef(tskJobRunner, TaskJobQueue, osPriorityAboveNormal, 0, STACK_JOBRUNNER, jobRunnerBuffer, &jobRunnerControlBlock); + osThreadStaticDef(tskJobRunner, TaskJobQueue, osPriorityAboveNormal, 0, TSK_STACK_JOBRUNNER, jobRunnerBuffer, &jobRunnerControlBlock); tskJobRunnerHandle = osThreadCreate(osThread(tskJobRunner), NULL); /* definition and creation of TaskMessaging */ - osThreadStaticDef(tskMsg, TaskMessaging, osPriorityNormal, 0, STACK_MSG, msgTaskBuffer, &msgTaskControlBlock); + osThreadStaticDef(tskMsg, TaskMessaging, osPriorityNormal, 0, TSK_STACK_MSG, msgTaskBuffer, &msgTaskControlBlock); tskMsgHandle = osThreadCreate(osThread(tskMsg), NULL); /* USER CODE BEGIN RTOS_THREADS */ diff --git a/platform/plat_compat.h b/platform/plat_compat.h index 7462094..aa4437c 100644 --- a/platform/plat_compat.h +++ b/platform/plat_compat.h @@ -5,6 +5,74 @@ #ifndef GEX_PLAT_COMPAT_H #define GEX_PLAT_COMPAT_H +// -------- Buffers and stack sizes --------- + +// FreeRTOS thread stacks (in 4-byte words) +#define TSK_STACK_MAIN 160 +#define TSK_STACK_MSG 200 +#define TSK_STACK_JOBRUNNER 128 + +// Size of the snprintf buffer for debug messages +// (this is on stack to avoid races) +#define DBG_BUF_LEN 80 + +// Bulk read/write +#define BULK_LST_TIMEOUT_MS 200 // timeout for the bulk transaction to expire +#define BULKREAD_MAX_CHUNK 512 // this is a static buffer + +// Error message buffer size (on stack) +#define ERR_MSG_STR_LEN 32 + +// Static buffer for saving to flash +#define FLASH_SAVE_BUF_LEN 256 + +// Number of job runner slots +#define HP_SCHED_CAPACITY 5 + +// Number of message queue slots (64 bytes each) +#define RX_QUE_CAPACITY 10 + + +// ------ TinyFrame config ------ + +// Maximum received payload size (static buffer) +// Larger payloads will be rejected. +#define TF_MAX_PAYLOAD_RX 640 + +// Size of the sending buffer. Larger payloads will be split to pieces and sent +// in multiple calls to the write function. This can be lowered to reduce RAM usage. +#define TF_SENDBUF_LEN 64 + +// --- Listener counts - determine sizes of the static slot tables --- + +// Frame ID listeners (wait for response / multi-part message) +#define TF_MAX_ID_LST 4 +// Frame Type listeners (wait for frame with a specific first payload byte) +#define TF_MAX_TYPE_LST 6 +// Generic listeners (fallback if no other listener catches it) +#define TF_MAX_GEN_LST 1 + +// Timeout for receiving & parsing a frame +// ticks = number of calls to TF_Tick() +#define TF_PARSER_TIMEOUT_TICKS 250 + + +// --- Mass Storage / USB config --- + +#define USBD_MAX_STR_DESC_SIZ 128 +#define MSC_MEDIA_PACKET 512 + + +// INI buffer sizes +#define INI_KEY_MAX 20 +#define INI_VALUE_MAX 30 +// ini writer +#define IWBUFFER_LEN 128 + + + +// -------- Platform specific includes and defines --------- + #if defined(GEX_PLAT_F103_BLUEPILL) // platform name for the version string diff --git a/tasks/sched_queue.h b/tasks/sched_queue.h index f9a80d8..3dab5d9 100644 --- a/tasks/sched_queue.h +++ b/tasks/sched_queue.h @@ -35,7 +35,4 @@ struct rx_que_item { uint8_t data[64]; }; -#define HP_SCHED_CAPACITY 5 -#define RX_QUE_CAPACITY 10 - #endif //GEX_SCHED_QUEUE_H diff --git a/utils/ini_parser.h b/utils/ini_parser.h index 7b2d2bc..4265965 100644 --- a/utils/ini_parser.h +++ b/utils/ini_parser.h @@ -10,8 +10,8 @@ #endif // buffer sizes -#define INI_KEY_MAX 20 -#define INI_VALUE_MAX 30 +//#define INI_KEY_MAX 20 +//#define INI_VALUE_MAX 30 // moved to plat_compat.h /** * INI parser callback, called for each found key-value pair. diff --git a/utils/ini_writer.c b/utils/ini_writer.c index d97d6bb..05261e3 100644 --- a/utils/ini_writer.c +++ b/utils/ini_writer.c @@ -13,7 +13,7 @@ #define MAX(a,b) ((a)>(b)?(a):(b)) #endif -#define IWBUFFER_LEN 128 +//#define IWBUFFER_LEN 128 // moved to plat_compat.h // sprintf from varargs, allocating buffer on stack. Uses 'format' argument #define IW_VPRINTF() do { \