aboutsummaryrefslogtreecommitdiff
path: root/projects
diff options
context:
space:
mode:
Diffstat (limited to 'projects')
-rw-r--r--projects/bootloader/bootloader.c1
-rw-r--r--projects/cli-test/mgmt-keystore.c4
-rw-r--r--projects/hsm/hsm.c52
-rw-r--r--projects/hsm/mgmt-keystore.c4
-rw-r--r--projects/hsm/mgmt-task.c13
5 files changed, 50 insertions, 24 deletions
diff --git a/projects/bootloader/bootloader.c b/projects/bootloader/bootloader.c
index c0f981f..ead87d0 100644
--- a/projects/bootloader/bootloader.c
+++ b/projects/bootloader/bootloader.c
@@ -41,6 +41,7 @@
/* stub these out to avoid linker error */
void fpgacfg_init(void) { }
void sdram_init(void) { }
+void *hal_allocate_static_memory(const size_t size) { return 0; }
/* Linker symbols are strange in C. Make regular pointers for sanity. */
__IO uint32_t *dfu_control = &CRYPTECH_DFU_CONTROL;
diff --git a/projects/cli-test/mgmt-keystore.c b/projects/cli-test/mgmt-keystore.c
index e11ef76..18447c8 100644
--- a/projects/cli-test/mgmt-keystore.c
+++ b/projects/cli-test/mgmt-keystore.c
@@ -340,12 +340,12 @@ static int cmd_keystore_erase(struct cli_def *cli, const char *command, char *ar
return CLI_ERROR;
}
- if ((err = hal_ks_init(hal_ks_token_driver, 0)) != LIBHAL_OK) {
+ if ((err = hal_ks_init(hal_ks_token, 0)) != LIBHAL_OK) {
cli_print(cli, "Failed to reinitialize token keystore: %s", hal_error_string(err));
return CLI_ERROR;
}
- if ((err = hal_ks_init(hal_ks_volatile_driver, 0)) != LIBHAL_OK) {
+ if ((err = hal_ks_init(hal_ks_volatile, 0)) != LIBHAL_OK) {
cli_print(cli, "Failed to reinitialize memory keystore: %s", hal_error_string(err));
return CLI_ERROR;
}
diff --git a/projects/hsm/hsm.c b/projects/hsm/hsm.c
index 33342c0..5ef2ccc 100644
--- a/projects/hsm/hsm.c
+++ b/projects/hsm/hsm.c
@@ -244,25 +244,43 @@ static void RxCallback(uint8_t c)
}
}
-static uint8_t uart_rx[2]; /* current character received from UART */
-static uint32_t uart_rx_idx = 0;
-
-/* UART DMA half-complete and complete callbacks. With a 2-character DMA
- * buffer, one or the other of these will fire on each incoming character.
- * Under heavy load, these will sometimes fire in the wrong order, but the
- * data are in the right order in the DMA buffer, so we have a flip-flop
- * buffer index that doesn't depend on the order of the callbacks.
+/* A ring buffer for the UART DMA receiver. In theory, it should get at most
+ * 92 characters per 1ms tick, but we're going to up-size it for safety.
*/
-void HAL_UART2_RxHalfCpltCallback(UART_HandleTypeDef *huart)
-{
- RxCallback(uart_rx[uart_rx_idx]);
- uart_rx_idx ^= 1;
-}
+#ifndef RPC_UART_RECVBUF_SIZE
+#define RPC_UART_RECVBUF_SIZE 1024 /* must be a power of 2 */
+#endif
+#define RPC_UART_RECVBUF_MASK (RPC_UART_RECVBUF_SIZE - 1)
+
+typedef struct {
+ uint32_t ridx;
+ uint8_t buf[RPC_UART_RECVBUF_SIZE];
+} uart_ringbuf_t;
+
+volatile uart_ringbuf_t uart_ringbuf = {0, {0}};
-void HAL_UART2_RxCpltCallback(UART_HandleTypeDef *huart)
+#define RINGBUF_RIDX(rb) (rb.ridx & RPC_UART_RECVBUF_MASK)
+#define RINGBUF_WIDX(rb) (sizeof(rb.buf) - __HAL_DMA_GET_COUNTER(huart_user.hdmarx))
+#define RINGBUF_COUNT(rb) ((RINGBUF_WIDX(rb) - RINGBUF_RIDX(rb)) & RPC_UART_RECVBUF_MASK)
+#define RINGBUF_READ(rb, dst) {dst = rb.buf[RINGBUF_RIDX(rb)]; rb.ridx++;}
+
+size_t uart_rx_max = 0;
+
+void HAL_SYSTICK_Callback(void)
{
- RxCallback(uart_rx[uart_rx_idx]);
- uart_rx_idx ^= 1;
+#ifdef DO_PROFILING
+ extern void profil_callback(void);
+ profil_callback();
+#endif
+
+ size_t count = RINGBUF_COUNT(uart_ringbuf);
+ if (uart_rx_max < count) uart_rx_max = count;
+
+ while (RINGBUF_COUNT(uart_ringbuf)) {
+ uint8_t c;
+ RINGBUF_READ(uart_ringbuf, c);
+ RxCallback(c);
+ }
}
/* Send one character over the UART. This is called from
@@ -430,7 +448,7 @@ int main(void)
Error_Handler();
/* Start the UART receiver. */
- if (HAL_UART_Receive_DMA(&huart_user, uart_rx, 2) != CMSIS_HAL_OK)
+ if (HAL_UART_Receive_DMA(&huart_user, (uint8_t *) uart_ringbuf.buf, sizeof(uart_ringbuf.buf)) != CMSIS_HAL_OK)
Error_Handler();
/* Launch other tasks (csprng warm-up task?)
diff --git a/projects/hsm/mgmt-keystore.c b/projects/hsm/mgmt-keystore.c
index f24f49b..0104265 100644
--- a/projects/hsm/mgmt-keystore.c
+++ b/projects/hsm/mgmt-keystore.c
@@ -304,12 +304,12 @@ static int cmd_keystore_erase(struct cli_def *cli, const char *command, char *ar
return CLI_ERROR;
}
- if ((err = hal_ks_init(hal_ks_token_driver, 0)) != LIBHAL_OK) {
+ if ((err = hal_ks_init(hal_ks_token, 0)) != LIBHAL_OK) {
cli_print(cli, "Failed to reinitialize token keystore: %s", hal_error_string(err));
return CLI_ERROR;
}
- if ((err = hal_ks_init(hal_ks_volatile_driver, 0)) != LIBHAL_OK) {
+ if ((err = hal_ks_init(hal_ks_volatile, 0)) != LIBHAL_OK) {
cli_print(cli, "Failed to reinitialize memory keystore: %s", hal_error_string(err));
return CLI_ERROR;
}
diff --git a/projects/hsm/mgmt-task.c b/projects/hsm/mgmt-task.c
index 1658a80..4668585 100644
--- a/projects/hsm/mgmt-task.c
+++ b/projects/hsm/mgmt-task.c
@@ -63,8 +63,12 @@ static int cmd_task_show(struct cli_def *cli, const char *command, char *argv[],
}
cli_print(cli, " ");
- cli_print(cli, "request queue current length: %d", request_queue_len());
- cli_print(cli, "request queue maximum length: %d", request_queue_max());
+ cli_print(cli, "RPC request queue current length: %u", request_queue_len());
+ cli_print(cli, "RPC request queue maximum length: %u", request_queue_max());
+
+ extern size_t uart_rx_max;
+ cli_print(cli, " ");
+ cli_print(cli, "UART receive queue maximum length: %u", uart_rx_max);
return CLI_OK;
}
@@ -95,7 +99,10 @@ void configure_cli_task(struct cli_def *cli)
struct cli_command *c = cli_register_command(cli, NULL, "task", NULL, 0, 0, NULL);
/* task show */
- struct cli_command *c_show = cli_register_command(cli, c, "show", cmd_task_show, 0, 0, "Show the active tasks");
+#ifdef DO_TASK_METRICS
+ struct cli_command *c_show =
+#endif
+ cli_register_command(cli, c, "show", cmd_task_show, 0, 0, "Show the active tasks");
#ifdef DO_TASK_METRICS
/* task show metrics */