summaryrefslogtreecommitdiff
path: root/zephyr/shim
diff options
context:
space:
mode:
authorDawid Niedzwiecki <dn@semihalf.com>2021-06-28 12:29:37 +0200
committerCommit Bot <commit-bot@chromium.org>2021-07-02 09:42:58 +0000
commit3bb10dd59fa68b2b5a3e0d4e560bda9bef4efcd8 (patch)
tree3a9a14c13b6683e7cf0ab2a574c940ae16124b94 /zephyr/shim
parent5ca2bdaf876c5ee91f4adbc9bb634b9d4f035d2d (diff)
downloadchrome-ec-3bb10dd59fa68b2b5a3e0d4e560bda9bef4efcd8.tar.gz
zephyr: change host console shim interface
Allow passing a whole string to the console buffer, which is sent to host. This should speed up printing because a mutex doesn't have to be locked for every char separately. BUG=b:191724484 BRANCH=none TEST=Make sure buffering of console to host works with the 'ectool console' command Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com> Change-Id: I5b081984bfa4f930ad4729b19975b1c2eb4bbd18 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2988193 Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Diffstat (limited to 'zephyr/shim')
-rw-r--r--zephyr/shim/include/zephyr_console_shim.h9
-rw-r--r--zephyr/shim/src/console.c2
-rw-r--r--zephyr/shim/src/console_buffer.c34
3 files changed, 26 insertions, 19 deletions
diff --git a/zephyr/shim/include/zephyr_console_shim.h b/zephyr/shim/include/zephyr_console_shim.h
index 03e2d115c6..df9f189c9a 100644
--- a/zephyr/shim/include/zephyr_console_shim.h
+++ b/zephyr/shim/include/zephyr_console_shim.h
@@ -56,11 +56,12 @@ int zshim_run_ec_console_command(int (*handler)(int argc, char **argv),
_ZEPHYR_SHELL_COMMAND_SHIM(NAME, ROUTINE, ARGDESC, HELP)
/**
- * console_buf_notify_char() - Notify the console host command buffer
- * of a new character on the console.
+ * console_buf_notify_chars() - Notify the console host command buffer
+ * of bytes on the console.
*
- * @c: The character that appeared on the console.
+ * @s: The pointer to the string.
+ * @len: The size of the string.
*/
-void console_buf_notify_char(char c);
+void console_buf_notify_chars(const char *s, size_t len);
#endif /* __CROS_EC_ZEPHYR_CONSOLE_SHIM_H */
diff --git a/zephyr/shim/src/console.c b/zephyr/shim/src/console.c
index 5d4e2de16f..28f0067249 100644
--- a/zephyr/shim/src/console.c
+++ b/zephyr/shim/src/console.c
@@ -220,7 +220,7 @@ void uart_write_char(char c)
printk("%c", c);
if (IS_ENABLED(CONFIG_PLATFORM_EC_HOSTCMD_CONSOLE))
- console_buf_notify_char(c);
+ console_buf_notify_chars(&c, 1);
}
void uart_flush_output(void)
diff --git a/zephyr/shim/src/console_buffer.c b/zephyr/shim/src/console_buffer.c
index aa3a2300e6..427ae47768 100644
--- a/zephyr/shim/src/console_buffer.c
+++ b/zephyr/shim/src/console_buffer.c
@@ -22,31 +22,37 @@ static inline uint32_t next_idx(uint32_t cur_idx)
K_MUTEX_DEFINE(console_write_lock);
-void console_buf_notify_char(char c)
+void console_buf_notify_chars(const char *s, size_t len)
{
- /* Don't copy null byte into buffer */
- if (!c)
- return;
-
/*
- * This is just notifying of a console character for debugging
+ * This is just notifying of console characters for debugging
* output, so if we are unable to lock the mutex immediately,
- * then just drop the character.
+ * then just drop the string.
*/
- if (!k_mutex_lock(&console_write_lock, K_NO_WAIT)) {
- /* We got the mutex. */
+ if (k_mutex_lock(&console_write_lock, K_NO_WAIT))
+ return;
+ /* We got the mutex. */
+ while (len--) {
+ /* Don't copy null byte into buffer */
+ if (!(*s))
+ continue;
+
uint32_t new_tail = next_idx(tail_idx);
- /* Check if we are starting to overwrite our snapshot heads */
+ /* Check if we are starting to overwrite our snapshot
+ * heads
+ */
if (new_tail == previous_snapshot_idx)
- previous_snapshot_idx = next_idx(previous_snapshot_idx);
+ previous_snapshot_idx =
+ next_idx(previous_snapshot_idx);
if (new_tail == current_snapshot_idx)
- current_snapshot_idx = next_idx(current_snapshot_idx);
+ current_snapshot_idx =
+ next_idx(current_snapshot_idx);
- console_buf[new_tail] = c;
+ console_buf[new_tail] = *s++;
tail_idx = new_tail;
- k_mutex_unlock(&console_write_lock);
}
+ k_mutex_unlock(&console_write_lock);
}
enum ec_status uart_console_read_buffer_init(void)