From 2659305118291c33c4a691d7f1f26a0b1e7c2ebb Mon Sep 17 00:00:00 2001
From: schneider <schneider@blinkenlichts.net>
Date: Mon, 25 Jan 2021 23:33:21 +0100
Subject: [PATCH] chore(serial): Make clear what goes where

---
 epicardium/modules/serial.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/epicardium/modules/serial.c b/epicardium/modules/serial.c
index bbf8c0159..6be231d65 100644
--- a/epicardium/modules/serial.c
+++ b/epicardium/modules/serial.c
@@ -127,11 +127,18 @@ static void write_str_(const char *str, size_t length)
 }
 
 /*
- * API-call to write a string.  Output goes to both CDCACM, UART and BLE
+ * API-call to write a string.  Output goes to CDCACM, UART and BLE
+ *
+ * This is user data from core 1.
  */
 void epic_uart_write_str(const char *str, size_t length)
 {
-	ble_uart_write((uint8_t *)str, length);
+	/* Make sure that we are not in an interrupt when talking to BLE.
+	 * Should not be the case if this is called from core 1
+	 * anyways. */
+	if (!xPortIsInsideInterrupt()) {
+		ble_uart_write((uint8_t *)str, length);
+	}
 	write_str_(str, length);
 }
 
@@ -202,7 +209,6 @@ static void serial_flush_from_thread(void)
 		taskEXIT_CRITICAL();
 
 		cdcacm_write((uint8_t *)&rx_data, received_bytes);
-		//ble_uart_write((uint8_t *)&rx_data, received_bytes);
 	} while (received_bytes > 0);
 }
 
@@ -250,7 +256,9 @@ int epic_uart_read_str(char *buf, size_t cnt)
 }
 
 /*
- * Write a string.  Output goes to both CDCACM and UART
+ * Write a string from epicardium. Output goes to CDCACM and UART
+ *
+ * This mainly log data from epicardium, not user date from core 1.
  */
 long _write_epicardium(int fd, const char *buf, size_t cnt)
 {
-- 
GitLab