xiaoxiang781216 commented on code in PR #21643:
URL: https://github.com/apache/nuttx/pull/21643#discussion_r4532568865
##########
drivers/misc/Kconfig:
##########
@@ -149,13 +149,76 @@ config ARCH_HAVE_RDWR_MEM_CPU_RUN
default n
config LWL_CONSOLE
-bool "Lightweight Link Console Support"
+ bool "Lightweight Link Console Support"
default n
depends on DEV_CONSOLE && ARCH_HAVE_RDWR_MEM_CPU_RUN
+ select SERIAL
---help---
Use the lightweight link console which provides console over a
debug channel by means of shared memory. A terminal application
- for openocd as the debugger is available in tools/ocdconsole.py.
+ for openocd as the debugger is available in
tools/lwl/ocdconsole.py.
+ See Documentation/guides/drivers/lwl.rst.
+
+if LWL_CONSOLE
+
+config LWL_CONSOLE_RXBUFSIZE
+ int "Receive buffer size"
+ default 64
+ ---help---
+ Size of the buffer that holds the characters received from the
+ host until they are read. While it is full the host is held
off,
+ so no input is lost.
+
+config LWL_CONSOLE_TXBUFSIZE
+ int "Transmit buffer size"
+ default 256
+ ---help---
+ Size of the buffer that holds the characters waiting to be
+ collected by the host. While no host is connected the most
recent
+ output is kept here and shown when the host connects.
+
+config LWL_CONSOLE_RINGSIZE
+ int "Output ring buffer size"
+ default 256
+ ---help---
+ Size of the ring buffer in the control block from which the host
+ collects the output, many bytes per debugger access instead of
+ three per word. This is what makes the output fast. It must be
+ a multiple of 4. 0 disables it: the output then only uses the
+ word protocol, as with old host tools.
+
+config LWL_CONSOLE_DOORBELL
+ bool "Doorbell interrupt"
+ default n
+ depends on ARCH_ARMV6M || ARCH_ARMV7M || ARCH_ARMV8M
Review Comment:
remove. can fake on other arch too
##########
drivers/misc/lwl_console.c:
##########
@@ -296,25 +977,40 @@ static ssize_t lwlconsole_write(FAR struct file *filep,
/****************************************************************************
* Name: up_putc
+ *
+ * Description:
+ * Low-level, unbuffered console output used by syslog and by the assert
+ * logic. It waits for room in the link.
+ *
****************************************************************************/
void up_putc(int ch)
{
- /* If link not initialize just return */
+ irqstate_t flags;
+ uint8_t c = ch;
+
+ flags = enter_critical_section();
- if (!linkactive())
+ do
{
- return;
+ while (!lwl_txready(&g_lwl_dev))
+ {
+ }
}
+ while (lwl_sendbuf(&g_lwl_dev, &c, 1) == 0);
- write8bits(LWL_PORT_CONSOLE, (uint8_t)ch);
+ leave_critical_section(flags);
Review Comment:
let replace the lock with uart driver framework
##########
drivers/misc/Kconfig:
##########
@@ -149,13 +149,76 @@ config ARCH_HAVE_RDWR_MEM_CPU_RUN
default n
config LWL_CONSOLE
-bool "Lightweight Link Console Support"
+ bool "Lightweight Link Console Support"
default n
depends on DEV_CONSOLE && ARCH_HAVE_RDWR_MEM_CPU_RUN
+ select SERIAL
---help---
Use the lightweight link console which provides console over a
debug channel by means of shared memory. A terminal application
- for openocd as the debugger is available in tools/ocdconsole.py.
+ for openocd as the debugger is available in
tools/lwl/ocdconsole.py.
+ See Documentation/guides/drivers/lwl.rst.
+
+if LWL_CONSOLE
+
+config LWL_CONSOLE_RXBUFSIZE
+ int "Receive buffer size"
+ default 64
+ ---help---
+ Size of the buffer that holds the characters received from the
+ host until they are read. While it is full the host is held
off,
+ so no input is lost.
+
+config LWL_CONSOLE_TXBUFSIZE
+ int "Transmit buffer size"
+ default 256
+ ---help---
+ Size of the buffer that holds the characters waiting to be
+ collected by the host. While no host is connected the most
recent
+ output is kept here and shown when the host connects.
+
+config LWL_CONSOLE_RINGSIZE
+ int "Output ring buffer size"
+ default 256
+ ---help---
+ Size of the ring buffer in the control block from which the host
+ collects the output, many bytes per debugger access instead of
+ three per word. This is what makes the output fast. It must be
+ a multiple of 4. 0 disables it: the output then only uses the
+ word protocol, as with old host tools.
+
+config LWL_CONSOLE_DOORBELL
+ bool "Doorbell interrupt"
+ default n
+ depends on ARCH_ARMV6M || ARCH_ARMV7M || ARCH_ARMV8M
+ ---help---
+ Let the host raise an interrupt every time it updates the link,
by
+ setting the pending bit of an unused interrupt in the NVIC. The
+ console is then entirely interrupt driven: the CPU does no work
+ at all while the console is idle. Hosts that don't use the
+ doorbell keep working through polling, see
+ LWL_CONSOLE_POLL_INTERVAL.
+
+config LWL_CONSOLE_DOORBELL_IRQ
+ int "Doorbell IRQ number"
+ depends on LWL_CONSOLE_DOORBELL
+ range 16 511
+ ---help---
+ The NuttX IRQ number (the vector number, so external interrupt
0 is
+ 16) used as the doorbell. It must be implemented by the chip
but
+ not used by any other driver.
+
+config LWL_CONSOLE_POLL_INTERVAL
+ int "Polling interval (usec)"
+ default 10000
Review Comment:
depends on !LWL_CONSOLE_DOORBELL
##########
drivers/misc/lwl_console.c:
##########
@@ -27,267 +27,948 @@
#include <nuttx/config.h>
#include <sys/types.h>
+#include <sys/param.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <string.h>
#include <errno.h>
-#include <nuttx/debug.h>
-#include <nuttx/fs/fs.h>
+#include <nuttx/arch.h>
+#include <nuttx/cache.h>
+#include <nuttx/clock.h>
+#include <nuttx/irq.h>
+#include <nuttx/wdog.h>
#include <nuttx/drivers/drivers.h>
+#include <nuttx/serial/serial.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
-/* Lightweight Link (lwl)
+/* Lightweight Link (LWL)
* ======================
*
* Lightweight bidirectional communication between target and debug host
- * without any need for additional hardware.
- *
- * Works with openOCD and other debuggers that are capable of reading and
- * writing memory while the target is running.
- *
- * Principle of operation is simple; An 'upword' of 32 bits communicates
- * from the target to the host, a 'downword' of the same size runs in the
- * opposite direction. These two words can be in any memory that is
- * read/write access for both the target and the debug host. A simple ping
- * pong handshake protocol over these words allows up/down link
- * communication. On the upside no additional integration is needed. On
- * the downside it may be necessary to feed lwl with cycles to poll for
- * changes in the downword, depending on the use case.
- *
- * Bit configuration
- * -----------------
- *
- * Downword (Host to target);
- *
- * A D U VV XXX
- *
- * A 31 1 - Service Active (Set by host)
- * D 30 1 - Downsense (Toggled when there is data)
- * U 29 1 - Upsense ack (Toggled to acknowledge receipt of uplink data)
- * VV 28-27 2 - Valid Octets (Number of octets valid in the message)
- * XXX 26-24 3 - Port in use (Type of the message)
- * O2 23-16 8 - Octet 2
- * O1 15-08 8 - Octet 1
- * O0 07-00 8 - Octet 0
- *
- * Upword (Target to Host);
- *
- * A 31 1 - Service Active (Set by device)
- * D 30 1 - Downsense ack (Toggled to acknowledge receipt of downlink
- * data)
- * U 29 1 - Upsense (Toggled when there is data)
- * VV 28-27 2 - Valid upword octets
- * XXX 26-24 3 - Port in use (Type of the message)
- * O2 23-16 8 - Octet 2
- * O1 15-08 8 - Octet 1
- * O0 07-00 8 - Octet 0
+ * without any need for additional hardware. It works with OpenOCD and any
+ * other debugger that can read and write target memory while the CPU is
+ * running. See Documentation/guides/drivers/lwl.rst for the full
+ * description.
*
+ * A 'downword' of 32 bits carries data from the host to the target and an
+ * 'upword' of the same size carries data in the opposite direction, with a
+ * ping-pong handshake on two 'sense' bits:
+ *
+ * Bit Downword (host -> target) Upword (target -> host)
+ * 31 A link active (host) A link active (target)
+ * 30 D downsense (new data) D downsense ack
+ * 29 U upsense ack U upsense (new data)
+ * 28-27 VV number of valid octets VV number of valid octets
+ * 26-24 XXX port (1 = console) XXX port (1 = console)
+ * 23-0 O2 O1 O0 data octets O2 O1 O0 data octets
+ *
+ * Hosts that support it can instead collect the output from a ring buffer
+ * in the control block, many bytes per debugger access: the target then
+ * reports the A and D bits in the 'status' word and the upword is unused.
+ *
+ * The driver is a lower half of the generic serial driver, so the console
+ * gets proper RX/TX buffering, termios processing, poll() and signals.
+ * It never busy-waits for the host: the link is serviced either from a
+ * "doorbell" interrupt that the host raises after every update, or from a
+ * low rate watchdog timer when the host does not ring the doorbell.
*/
/* Protocol bits */
-#define LWL_GETACTIVE(x) (((x) & (1 << 31)) != 0)
-#define LWL_ACTIVE(x) (((x)&1) << 31)
+#define LWL_ACTIVEBIT (1u << 31)
+#define LWL_GETACTIVE(x) (((x) & LWL_ACTIVEBIT) != 0)
+
+#define LWL_DNSENSEBIT (1u << 30)
+#define LWL_DNSENSE(x) ((x) & LWL_DNSENSEBIT)
+#define LWL_UPSENSEBIT (1u << 29)
+#define LWL_UPSENSE(x) ((x) & LWL_UPSENSEBIT)
+#define LWL_SENSEMASK (LWL_DNSENSEBIT | LWL_UPSENSEBIT)
+
+#define LWL_GETOCTVAL(x) (((x) >> 27) & 3)
+#define LWL_OCTVAL(x) (((uint32_t)(x) & 3) << 27)
+#define LWL_GETPORT(x) (((x) >> 24) & 7)
+#define LWL_PORT(x) (((uint32_t)(x) & 7) << 24)
+#define LWL_MAXOCTETS 3
+
+#define LWL_PORT_CONSOLE 1
+
+/* Host capabilities, written by the host before it opens the link */
+
+#define LWL_CAP_RING (1u << 0) /* The host reads the ring buffer */
+
+/* Signatures that let the host locate the control block in target RAM.
+ * LWL_EXT_SIG tells the host that the fields that follow the upword are
+ * valid (legacy firmware does not have them).
+ */
+
+#define LWL_ID_SIG 0x7216a318
+#define LWL_EXT_SIG 0x4c574c32 /* "LWL2" */
+
+/* Doorbell: the host writes 'dbval' to 'dbaddr' after an update of the
+ * link. On ARMv6-M/ARMv7-M/ARMv8-M this sets the pending bit of an
+ * otherwise unused interrupt in the NVIC Interrupt Set-Pending Registers
+ * (architecturally at 0xe000e200), which the debugger can write while the
+ * CPU is running.
+ */
+
+#ifdef CONFIG_LWL_CONSOLE_DOORBELL
+# define LWL_DBIRQ CONFIG_LWL_CONSOLE_DOORBELL_IRQ
+# define LWL_NVIC_IRQ_FIRST 16
+# define LWL_NVIC_ISPR 0xe000e200
Review Comment:
why not call irq API to make the code general
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]