[Cryptech-Commits] [sw/stm32] 04/05: Show running threads.
git at cryptech.is
git at cryptech.is
Tue Aug 23 16:37:08 UTC 2016
This is an automated email from the git hooks/post-receive script.
paul at psgd.org pushed a commit to branch master
in repository sw/stm32.
commit 1f00be95e861f87b625ed7fe39823dde3230ca98
Author: Paul Selkirk <paul at psgd.org>
AuthorDate: Tue Aug 23 11:29:26 2016 -0400
Show running threads.
---
projects/hsm/Makefile | 5 ++-
projects/hsm/mgmt-cli.c | 3 +-
projects/hsm/mgmt-thread.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++
projects/hsm/mgmt-thread.h | 42 ++++++++++++++++++++
4 files changed, 144 insertions(+), 3 deletions(-)
diff --git a/projects/hsm/Makefile b/projects/hsm/Makefile
index 87679ca..b92390a 100644
--- a/projects/hsm/Makefile
+++ b/projects/hsm/Makefile
@@ -8,7 +8,8 @@ OBJS = crc32.o \
mgmt-fpga.c \
mgmt-keystore.c \
mgmt-masterkey.c \
- mgmt-misc.c
+ mgmt-misc.c \
+ mgmt-thread.c
BOARD_OBJS = \
$(TOPLEVEL)/stm-init.o \
@@ -26,7 +27,7 @@ BOARD_OBJS = \
$(BOARD_DIR)/stm32f4xx_hal_msp.o \
$(BOARD_DIR)/stm32f4xx_it_rtos.o
-CFLAGS += -DNUM_RPC_TASK=6
+CFLAGS += -DNUM_RPC_TASK=4
CFLAGS += -I$(LIBHAL_SRC)
CFLAGS += -I$(LIBCLI_SRC)
diff --git a/projects/hsm/mgmt-cli.c b/projects/hsm/mgmt-cli.c
index 539ba4c..ee1b31b 100644
--- a/projects/hsm/mgmt-cli.c
+++ b/projects/hsm/mgmt-cli.c
@@ -49,6 +49,7 @@
#include "mgmt-misc.h"
#include "mgmt-keystore.h"
#include "mgmt-masterkey.h"
+#include "mgmt-thread.h"
#undef HAL_OK
#define HAL_OK LIBHAL_OK
@@ -106,7 +107,6 @@ void HAL_UART1_RxCpltCallback(UART_HandleTypeDef *huart)
{
ringbuf_write_char(&uart_ringbuf, uart_rx);
osSemaphoreRelease(uart_sem);
- HAL_UART_Receive_DMA(huart, &uart_rx, 1);
}
static void uart_cli_print(struct cli_def *cli __attribute__ ((unused)), const char *buf)
@@ -196,6 +196,7 @@ int cli_main(void)
configure_cli_firmware(cli);
configure_cli_bootloader(cli);
configure_cli_misc(cli);
+ configure_cli_thread(cli);
while (1) {
control_mgmt_uart_dma_rx(DMA_RX_START);
diff --git a/projects/hsm/mgmt-thread.c b/projects/hsm/mgmt-thread.c
new file mode 100644
index 0000000..82b8e72
--- /dev/null
+++ b/projects/hsm/mgmt-thread.c
@@ -0,0 +1,97 @@
+/*
+ * mgmt-thread.c
+ * -----------
+ * CLI 'thread' functions.
+ *
+ * Copyright (c) 2016, NORDUnet A/S All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - Neither the name of the NORDUnet nor the names of its contributors may
+ * be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Show the active threads. This is mostly for debugging, and looks deeply
+ * into OS-level structures, but sometimes you just need to know...
+ */
+
+#include "mgmt-cli.h"
+#include "mgmt-thread.h"
+
+/* rt_TypeDef.h redefines NULL (previously defined in stddef.h, via libcli.h) */
+#undef NULL
+
+#include "rt_TypeDef.h"
+#include "RTX_Conf.h"
+
+static char *task_state[] = {
+ "INACTIVE",
+ "READY",
+ "RUNNING",
+ "WAIT_DLY",
+ "WAIT_ITV",
+ "WAIT_OR",
+ "WAIT_AND",
+ "WAIT_SEM",
+ "WAIT_MBX",
+ "WAIT_MUT",
+};
+
+static int cmd_thread_show(struct cli_def *cli, const char *command, char *argv[], int argc)
+{
+ OS_TID task_id;
+ P_TCB task;
+ char *name;
+ extern void main(void);
+ extern void dispatch_thread(void);
+ extern void osTimerThread(void);
+
+ for (task_id = 1; task_id <= os_maxtaskrun; ++ task_id) {
+ if ((task = os_active_TCB[task_id-1]) != NULL) {
+ if (task->ptask == main)
+ name = "main";
+ else if (task->ptask == dispatch_thread)
+ name = "dispatch_thread";
+ else if (task->ptask == osTimerThread)
+ name = "osTimerThread";
+ else
+ name = "unknown";
+
+ cli_print(cli, "%d:\tptask\t%p\t%s", task_id, task->ptask, name);
+ cli_print(cli, "\tstate\t%d\t\t%s", (int)task->state, task_state[task->state]);
+ cli_print(cli, "\tprio\t%d", (int)task->prio);
+ cli_print(cli, "\tstack\t%p", task->stack);
+ }
+ }
+ return CLI_OK;
+}
+
+void configure_cli_thread(struct cli_def *cli)
+{
+ struct cli_command *c = cli_register_command(cli, NULL, "thread", NULL, 0, 0, NULL);
+
+ /* thread show */
+ cli_register_command(cli, c, "show", cmd_thread_show, 0, 0, "Show the active threads");
+}
diff --git a/projects/hsm/mgmt-thread.h b/projects/hsm/mgmt-thread.h
new file mode 100644
index 0000000..f72695e
--- /dev/null
+++ b/projects/hsm/mgmt-thread.h
@@ -0,0 +1,42 @@
+/*
+ * mgmt-thread.h
+ * -----------
+ * Management CLI 'thread' functions.
+ *
+ * Copyright (c) 2016, NORDUnet A/S All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * - Neither the name of the NORDUnet nor the names of its contributors may
+ * be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __STM32_CLI_MGMT_THREAD_H
+#define __STM32_CLI_MGMT_THREAD_H
+
+#include <libcli.h>
+
+extern void configure_cli_thread(struct cli_def *cli);
+
+#endif /* __STM32_CLI_MGMT_THREAD_H */
More information about the Commits
mailing list