make some options configurable and rename some constants

sipo
Ondřej Hruška 7 years ago
parent bef9b83826
commit 89f8c59d40
  1. 38
      debug.c
  2. 5
      debug.h
  3. 4
      freertos.c
  4. 36
      gex.mk
  5. 2
      gex_hooks.c
  6. 78
      platform/plat_compat.h
  7. 4
      stm32_assert.c
  8. 2
      utils/stacksmon.c
  9. 1
      vfs/vfs_manager.c

@ -17,8 +17,15 @@ int PRINTF(const char *format, ...)
va_start(args, format); va_start(args, format);
/*convert into string at buff[0] of length iw*/ /*convert into string at buff[0] of length iw*/
len = (int)fixup_vsnprintf(&dbg_buf[0], DBG_BUF_LEN, format, args); len = (int)fixup_vsnprintf(&dbg_buf[0], DBG_BUF_LEN, format, args);
if (len >= DBG_BUF_LEN) {
dbg_buf[DBG_BUF_LEN-1] = 0;
len = DBG_BUF_LEN-1;
}
_write_r(NULL, 2, dbg_buf, (size_t) len); _write_r(NULL, 2, dbg_buf, (size_t) len);
va_end(args); va_end(args);
return len; return len;
} }
@ -33,6 +40,15 @@ void PUTSN(const char *string, size_t len)
_write_r(NULL, 2, string, (size_t) len); _write_r(NULL, 2, string, (size_t) len);
} }
/**
* Puts a newline
*
*/
void PUTNL(void)
{
_write_r(NULL, 2, "\r\n", 2);
}
/** /**
* Print a string to debug uart * Print a string to debug uart
* @param string - string to print, zero-terminated * @param string - string to print, zero-terminated
@ -56,26 +72,4 @@ int PUTCHAR(int ch)
return ch; // or EOF return ch; // or EOF
} }
/**
* Print string to debug uart, add newline if missing (printf-like)
* @param format
* @param ...
*/
void dbg(const char *format, ...)
{
va_list args;
int len;
char dbg_buf[DBG_BUF_LEN];
va_start(args, format);
len = (int)VSNPRINTF(&dbg_buf[0], DBG_BUF_LEN, format, args);
_write_r(NULL, 2, dbg_buf, (size_t) len);
// add newline if not present
if (dbg_buf[len-1] != '\n')
_write_r(NULL, 2, "\r\n", 2);
va_end(args);
}
#endif #endif

@ -11,13 +11,14 @@
#if USE_DEBUG_UART #if USE_DEBUG_UART
void dbg(const char *format, ...) __attribute__((format(printf,1,2))) ;
int PRINTF(const char *format, ...) __attribute__((format(printf,1,2))) ; int PRINTF(const char *format, ...) __attribute__((format(printf,1,2))) ;
void PUTSN(const char *string, size_t len); void PUTSN(const char *string, size_t len);
int PUTS(const char *string); int PUTS(const char *string);
void PUTNL(void);
int PUTCHAR(int ch); int PUTCHAR(int ch);
#define dbg(format, ...) do { PRINTF(format, ##__VA_ARGS__); PUTNL(); } while (0)
#else #else
#define dbg(format, ...) do {} while (0) #define dbg(format, ...) do {} while (0)
#define PRINTF(format, ...) do {} while (0) #define PRINTF(format, ...) do {} while (0)

@ -71,7 +71,7 @@ uint32_t jobRunnerBuffer[ TSK_STACK_JOBRUNNER ];
osStaticThreadDef_t jobRunnerControlBlock; osStaticThreadDef_t jobRunnerControlBlock;
osMessageQId queSchedHandle; osMessageQId queSchedHandle;
uint8_t myQueue02Buffer[ HP_SCHED_CAPACITY * sizeof( struct sched_que_item ) ]; uint8_t myQueue02Buffer[ JOB_QUEUE_CAPACITY * sizeof( struct sched_que_item ) ];
osStaticMessageQDef_t myQueue02ControlBlock; osStaticMessageQDef_t myQueue02ControlBlock;
osMessageQId queRxDataHandle; osMessageQId queRxDataHandle;
@ -180,7 +180,7 @@ void MX_FREERTOS_Init(void) {
/* Create the queue(s) */ /* Create the queue(s) */
/* definition and creation of queSchedHP */ /* definition and creation of queSchedHP */
osMessageQStaticDef(queSchedHP, HP_SCHED_CAPACITY, struct sched_que_item, myQueue02Buffer, &myQueue02ControlBlock); osMessageQStaticDef(queSchedHP, JOB_QUEUE_CAPACITY, struct sched_que_item, myQueue02Buffer, &myQueue02ControlBlock);
queSchedHandle = osMessageCreate(osMessageQ(queSchedHP), NULL); queSchedHandle = osMessageCreate(osMessageQ(queSchedHP), NULL);
/* definition and creation of queRxData */ /* definition and creation of queRxData */

@ -61,17 +61,10 @@ GEX_CDEFS_BASE = \
-D__packed="__attribute__((__packed__))" \ -D__packed="__attribute__((__packed__))" \
-DUSE_FULL_LL_DRIVER \ -DUSE_FULL_LL_DRIVER \
# TODO implement debug build choice - enable or disable debugging
ifeq '1' '1'
GEX_CDEFS = $(GEX_CDEFS_BASE) \ ifeq '$(DISABLE_DEBUG)' '1'
-DUSE_FULL_ASSERT=1 \
-DVERBOSE_ASSERT=1 \
-DDEBUG_VFS=0 \
-DDEBUG_FLASH_WRITE=0 \
-DVERBOSE_HARDFAULT=1 \
-DUSE_STACK_MONITOR=1 \
-DUSE_DEBUG_UART=1
else
GEX_CDEFS = $(GEX_CDEFS_BASE) \ GEX_CDEFS = $(GEX_CDEFS_BASE) \
-DUSE_FULL_ASSERT=0 \ -DUSE_FULL_ASSERT=0 \
-DVERBOSE_ASSERT=0 \ -DVERBOSE_ASSERT=0 \
@ -80,11 +73,26 @@ GEX_CDEFS = $(GEX_CDEFS_BASE) \
-DVERBOSE_HARDFAULT=0 \ -DVERBOSE_HARDFAULT=0 \
-DUSE_STACK_MONITOR=0 \ -DUSE_STACK_MONITOR=0 \
-DUSE_DEBUG_UART=0 -DUSE_DEBUG_UART=0
else
GEX_CDEFS = $(GEX_CDEFS_BASE) \
-DUSE_FULL_ASSERT=1 \
-DVERBOSE_ASSERT=1 \
-DDEBUG_VFS=0 \
-DDEBUG_FLASH_WRITE=0 \
-DVERBOSE_HARDFAULT=1 \
-DUSE_STACK_MONITOR=1 \
-DUSE_DEBUG_UART=1
endif endif
# TODO implement debug build choice - enable or disable MSC ifeq '$(DISABLE_MSC)' '1'
ifeq '1' '1'
GEX_CDEFS += -DDISABLE_MSC
else
GEX_SOURCES += \ GEX_SOURCES += \
User/USB/usbd_storage_if.c \ User/USB/usbd_storage_if.c \
@ -96,6 +104,4 @@ GEX_SOURCES += \
GEX_SRC_DIR += \ GEX_SRC_DIR += \
User/vfs User/vfs
else
GEX_CDEFS += -DDISABLE_MSC
endif endif

@ -39,7 +39,7 @@ void GEX_PreInit(void)
DebugUart_PreInit(); DebugUart_PreInit();
dbg("\r\n\033[37;1m*** GEX "GEX_VERSION" on "GEX_PLATFORM" ***\033[m"); dbg("\r\n\033[37;1m*** GEX "GEX_VERSION" on "GEX_PLATFORM" ***\033[m");
dbg("Build "__DATE__" "__TIME__"\r\n"); dbg("Build "__DATE__" "__TIME__);
plat_init(); plat_init();

@ -5,69 +5,39 @@
#ifndef GEX_PLAT_COMPAT_H #ifndef GEX_PLAT_COMPAT_H
#define GEX_PLAT_COMPAT_H #define GEX_PLAT_COMPAT_H
// -------- Buffers and stack sizes --------- // -------- Static buffers ---------
#define TSK_STACK_MAIN 150 // USB / VFS task stack size
#define TSK_STACK_MSG 180 // TF message handler task stack size
#define TSK_STACK_JOBRUNNER 100 // Job runner task stack size
// FreeRTOS thread stacks (in 4-byte words) #define BULKREAD_MAX_CHUNK 256 // Bulk read buffer
#define TSK_STACK_MAIN 160
#define TSK_STACK_MSG 200
#define TSK_STACK_JOBRUNNER 128
// Size of the snprintf buffer for debug messages #define FLASH_SAVE_BUF_LEN 256 // Static buffer for saving to flash
// (this is on stack to avoid races)
#define DBG_BUF_LEN 80
// Bulk read/write #define JOB_QUEUE_CAPACITY 4 // Job runner queue size (16 bytes each)
#define BULK_LST_TIMEOUT_MS 200 // timeout for the bulk transaction to expire #define RX_QUE_CAPACITY 10 // TinyFrame rx queue size (64 bytes each)
#define BULKREAD_MAX_CHUNK 512 // this is a static buffer
// Error message buffer size (on stack) #define TF_MAX_PAYLOAD_RX 512 // TF max Rx payload
#define ERR_MSG_STR_LEN 32 #define TF_SENDBUF_LEN 64 // TF transmit buffer (can be less than a full frame)
// Static buffer for saving to flash #define TF_MAX_ID_LST 4 // Frame ID listener count
#define FLASH_SAVE_BUF_LEN 256 #define TF_MAX_TYPE_LST 6 // Frame Type listener count
#define TF_MAX_GEN_LST 1 // Generic listener count
// Number of job runner slots #define USBD_MAX_STR_DESC_SIZ 64 // Descriptor conversion buffer (used for converting ASCII to UTF-16, must be 2x the size of the longest descriptor)
#define HP_SCHED_CAPACITY 5 #define MSC_MEDIA_PACKET 512 // Mass storage sector size (packet)
// Number of message queue slots (64 bytes each) #define INI_KEY_MAX 20 // Ini parser key buffer
#define RX_QUE_CAPACITY 10 #define INI_VALUE_MAX 30 // Ini parser value buffer
// -------- Stack buffers ----------
#define DBG_BUF_LEN 80 // Size of the snprintf buffer for debug messages
#define ERR_MSG_STR_LEN 32 // Error message buffer size
#define IWBUFFER_LEN 80 // Ini writer buffer for sprintf
// ------ TinyFrame config ------ // -------- Timeouts ------------
#define TF_PARSER_TIMEOUT_TICKS 100 // Timeout for receiving & parsing a frame
// Maximum received payload size (static buffer) #define BULK_LST_TIMEOUT_MS 200 // timeout for the bulk transaction to expire
// 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

@ -9,7 +9,7 @@
*/ */
void __attribute__((noreturn)) abort_msg(const char *msg, const char *filename, uint32_t line) void __attribute__((noreturn)) abort_msg(const char *msg, const char *filename, uint32_t line)
{ {
dbg("\r\n\033[31m%s:\033[m %s:%"PRIu32"\r\n", msg, filename, line); dbg("\r\n\033[31m%s:\033[m %s:%"PRIu32, msg, filename, line);
vPortEnterCritical(); vPortEnterCritical();
StatusLed_On(STATUS_FAULT); StatusLed_On(STATUS_FAULT);
while(1); while(1);
@ -23,7 +23,7 @@ void __attribute__((noreturn)) abort_msg(const char *msg, const char *filename,
*/ */
void warn_msg(const char *msg, const char *filename, uint32_t line) void warn_msg(const char *msg, const char *filename, uint32_t line)
{ {
dbg("\r\n\033[33m%s:\033[m %s:%"PRIu32"\r\n", msg, filename, line); dbg("\r\n\033[33m%s:\033[m %s:%"PRIu32, msg, filename, line);
} }
/** /**

@ -81,7 +81,7 @@ void stackmon_check_canaries(void)
for (uint32_t i = 0; i < nextidx; i++) { for (uint32_t i = 0; i < nextidx; i++) {
struct stackhandle *stack = &stacks[i]; struct stackhandle *stack = &stacks[i];
if (stack->buffer[0] != 0xA5) { if (stack->buffer[0] != 0xA5) {
dbg("\r\n\033[31;1m!!!! STACK \"%s\" OVERRUN - CANARY IS DEAD !!!!\033[m\r\n", stack->description); dbg("\r\n\033[31;1m!!!! STACK \"%s\" OVERRUN - CANARY IS DEAD !!!!\033[m", stack->description);
stackmon_dump(); stackmon_dump();
trap("ABORT"); trap("ABORT");
} }

@ -575,6 +575,7 @@ static void file_data_handler(uint32_t sector, const uint8_t *buf, uint32_t num_
file_transfer_state.size_transferred); file_transfer_state.size_transferred);
vfs_printf_nonl("\033[31m", 5); vfs_printf_nonl("\033[31m", 5);
// FIXME this seems wrong
vfs_printf_nonl((const char *) buf, VFS_SECTOR_SIZE * num_of_sectors); vfs_printf_nonl((const char *) buf, VFS_SECTOR_SIZE * num_of_sectors);
vfs_printf_nonl("\033[0m\r\n", 6); vfs_printf_nonl("\033[0m\r\n", 6);

Loading…
Cancel
Save