aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChao Du <124672769+Du-Chao@users.noreply.github.com>2023-03-09 08:24:06 +0800
committerGitHub <noreply@github.com>2023-03-08 16:24:06 -0800
commit59e368e3089fd38ee7d88c3456e1922eaa9ca658 (patch)
tree712756b616a129277ce1a1a17921b12ca17d88d2
parentcd481a97e9ae604880b8239679bf83534e83b381 (diff)
downloadriscv-openocd-59e368e3089fd38ee7d88c3456e1922eaa9ca658.zip
riscv-openocd-59e368e3089fd38ee7d88c3456e1922eaa9ca658.tar.gz
riscv-openocd-59e368e3089fd38ee7d88c3456e1922eaa9ca658.tar.bz2
Calculate the FreeRTOS type sizes and offsets more adaptively. (#806)
* Calculate the FreeRTOS type sizes and offsets more adaptively. The definition of TickType_t varies between different targets. And it is also related to configUSE_16_BIT_TICKS option. Thus introduce a new command to make sure we are using a correct ticktype size. Change-Id: I9e38b331a9f07b96eb9a2c259e32377fca0106ad Signed-off-by: Chao Du <duchao@eswincomputing.com> * redundant semicolon. Change-Id: Ia21f0537e476099d8fe519ef78b3328d14123a38 * Update after review. Change-Id: I1825185ec9b0557d7e01f34a8f366661b3734aa7 * update doc Change-Id: I24b21c88b02ca3d76f1362f2545e86c068fc0ec6 --------- Signed-off-by: Chao Du <duchao@eswincomputing.com>
-rw-r--r--doc/openocd.texi8
-rw-r--r--src/rtos/FreeRTOS.c53
2 files changed, 55 insertions, 6 deletions
diff --git a/doc/openocd.texi b/doc/openocd.texi
index 99cae9a..b66627f 100644
--- a/doc/openocd.texi
+++ b/doc/openocd.texi
@@ -12018,6 +12018,14 @@ contrib/rtos-helpers/FreeRTOS-openocd.c
contrib/rtos-helpers/uCOS-III-openocd.c
@end table
+@section RTOS Commands
+@cindex RTOS Commands
+
+@deffn {Config Command} {freertos_ticktype_size} (2|4|8)
+Pass the size (in bytes) of FreeRTOS TickType_t to OpenOCD. To make sure the
+calculation of offsets and sizes is correct. Defaults to 4.
+@end deffn
+
@anchor{usingopenocdsmpwithgdb}
@section Using OpenOCD SMP with GDB
@cindex SMP
diff --git a/src/rtos/FreeRTOS.c b/src/rtos/FreeRTOS.c
index e017c57..2e468c7 100644
--- a/src/rtos/FreeRTOS.c
+++ b/src/rtos/FreeRTOS.c
@@ -59,6 +59,8 @@ struct FreeRTOS {
unsigned ubasetype_size;
/* sizeof(void *) */
unsigned pointer_size;
+ /* sizeof(TickType_t) */
+ unsigned ticktype_size;
unsigned list_width;
unsigned list_item_width;
unsigned list_elem_next_offset;
@@ -127,6 +129,45 @@ static int nds32_stacking(struct rtos *rtos, const struct rtos_register_stacking
return ERROR_OK;
}
+/* take 4 bytes (32 bits) as the default size,
+ * which is suitable for most 32-bit targets and
+ * configuration of configUSE_16_BIT_TICKS = 0. */
+static unsigned int freertos_ticktype_size = 4;
+COMMAND_HANDLER(handle_freertos_ticktype_size)
+{
+ if (CMD_ARGC != 1) {
+ LOG_ERROR("Command takes exactly 1 parameter");
+ return ERROR_COMMAND_SYNTAX_ERROR;
+ }
+
+ unsigned int size;
+ COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], size);
+ switch (size) {
+ case 2:
+ case 4:
+ case 8:
+ freertos_ticktype_size = size;
+ break;
+ default:
+ LOG_ERROR("Invalid ticktype size. Should be 2, 4 or 8.");
+ return ERROR_COMMAND_SYNTAX_ERROR;
+ }
+
+ return ERROR_OK;
+}
+
+static const struct command_registration freertos_commands[] = {
+ {
+ .name = "freertos_ticktype_size",
+ .handler = handle_freertos_ticktype_size,
+ .mode = COMMAND_ANY,
+ .usage = "(2|4|8)",
+ .help = "Pass the size (in bytes) of TickType_t to OpenOCD. To make sure the "
+ "calculation of offsets and sizes is correct. Defaults to 4."
+ },
+ COMMAND_REGISTRATION_DONE
+};
+
static enum {
STACKING_MAINLINE,
STACKING_METAL
@@ -305,13 +346,12 @@ static unsigned populate_offset_size(struct FreeRTOS *freertos,
align = freertos->pointer_size;
break;
case TYPE_TICKTYPE:
- /* Could be either 16 or 32 bits, depending on configUSE_16_BIT_TICKS. */
- info[i].size = 4;
- align = 4;
+ info[i].size = freertos->ticktype_size;
+ align = freertos->ticktype_size;
break;
case TYPE_LIST_ITEM:
info[i].size = freertos->list_item_width;
- align = MAX(freertos->ubasetype_size, freertos->pointer_size);
+ align = MAX(freertos->ticktype_size, freertos->pointer_size);
break;
case TYPE_CHAR_ARRAY:
/* size is set by the caller. */
@@ -347,11 +387,12 @@ static void freertos_compute_offsets(struct rtos *rtos)
{
struct FreeRTOS *freertos = (struct FreeRTOS *) rtos->rtos_specific_params;
- if (freertos->pointer_size != 0)
+ if (freertos->ticktype_size == freertos_ticktype_size)
return;
freertos->pointer_size = DIV_ROUND_UP(target_address_bits(rtos->target), 8);
freertos->ubasetype_size = DIV_ROUND_UP(target_data_bits(rtos->target), 8);
+ freertos->ticktype_size = freertos_ticktype_size;
/*
* FreeRTOS can be compiled with configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES
@@ -915,5 +956,5 @@ static int freertos_create(struct target *target)
return ERROR_FAIL;
}
- return ERROR_OK;
+ return register_commands(target->rtos->cmd_ctx, NULL, freertos_commands);
}