summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTC Wan2011-01-04 14:54:50 +0800
committerTC Wan2011-01-04 14:54:50 +0800
commitdcdbc6d3f18fa1c255bc03ce573fed74b754b19c (patch)
tree191b58bc580d33bc18e1d9facef35ddef7675259
parente9cdc8055191a6dea1a471b1b3fe6e2fe0f7070f (diff)
adjusted nxt message to 3 byte header format
Adjusted NXT Message Header to use 3 byte header format to support future expansion of multi-segmented GDB messages. This is not used at this moment.
-rw-r--r--Debugger/debug_comm.S23
-rw-r--r--Debugger/debug_stub.h19
-rwxr-xr-xHost/nxt-gdb-server.py8
3 files changed, 23 insertions, 27 deletions
diff --git a/Debugger/debug_comm.S b/Debugger/debug_comm.S
index 2130aec..11cba1c 100644
--- a/Debugger/debug_comm.S
+++ b/Debugger/debug_comm.S
@@ -281,17 +281,15 @@ _exit_conv_ascii2byte:
* There is a one byte Telegram Type field which identifies the type of telegram, followed by the
* Telegram header and actual message.
*
- * [The GDB Message Format is derived from the MESSAGEWRITE Direct Command format]
* The LEGO Mindstorms Communications Protocol Direct Commands GDB Message format (including all headers)
* is as follows:
*
* GDB Command
* ===========
- * Byte 0: Telegram Type Field (0x00 Direct Command, Response required) | USB Channel Header
- * Byte 1: Command Field (0xF0: GDB command) | NXT Command Header
- * Byte 2: Segment No (1-255, 0: Last Segment; limit is MSG_NUMSEGMENTS) |
- * Byte 3: Telegram Size (Len of USB Buffer - 4, max is MSG_SEGMENTSIZE) |
- * Byte 4-N: Message data | GDB Command
+ * Byte 0: Telegram Type Field (0x8d Direct Command, No response required) | USB Channel Header
+ * Byte 1: Segment No (1-255, 0: Last Segment; limit is MSG_NUMSEGMENTS) |
+ * Byte 2: Telegram Size (Len of USB Buffer - 2, max is MSG_SEGMENTSIZE) |
+ * Byte 3-N: Message data | GDB Command
*
* The GDB Command (of size M) has the following format:
* Offset 0: '$'
@@ -305,11 +303,10 @@ _exit_conv_ascii2byte:
*
* GDB Response
* ============
- * Byte 0: Telegram Type Field (0x02 Response) | USB Channel Header
- * Byte 1: Command Field (0xF1: GDB response) | NXT Command Header
- * Byte 2: Segment No (1-255, 0: Last Segment; limit is MSG_NUMSEGMENTS) |
- * Byte 3: Telegram Size (Len of USB Buffer - 4, max is MSG_SEGMENTSIZE) |
- * Byte 4-N: Message data | GDB Response
+ * Byte 0: Telegram Type Field (0x8d Direct Command, No response required) | USB Channel Header
+ * Byte 1: Segment No (1-255, 0: Last Segment; limit is MSG_NUMSEGMENTS) |
+ * Byte 2: Telegram Size (Len of USB Buffer - 2, max is MSG_SEGMENTSIZE) |
+ * Byte 3-N: Message data | GDB Response
*
* The GDB Response (of size M) has the following format:
* Offset 0: '+' or '-' Command Received Status
@@ -322,7 +319,7 @@ _exit_conv_ascii2byte:
* The maximum size of a GDB Response packet is MSGBUF_SIZE - 6 ('-'/'+', '$', '#', 2 byte checksum, trailing NULL char)
*
* Note: The Telegram Size is the actual size of the Message Data portion
- * (i.e., excludes the four header bytes, includes the GDB Command/Response Packet trailing NULL character
+ * (i.e., excludes the three header bytes, includes the GDB Command/Response Packet trailing NULL character
* in the last segment)
*/
@@ -413,7 +410,7 @@ _copy_msg_from_usbbuf:
ldrb r2, [r1, r0]
cmp r2, #0 /* Check for NULL (in last segment) */
bne _exit_getDebugMsg /* Debugger Message does not have valid terminating NULL char */
- sub r3, r0, #USB_GDBMSG_CHKSUMOFFSET /* Message Length - 4 = '#' offset */
+ sub r3, r0, #USB_GDBMSG_CHKSUMOFFSET /* Message Length - 3 = '#' offset */
ldrb r2, [r1, r3]
mov r4, #0
strb r4, [r1, r3] /* Zero out '#' char for checksum calc later */
diff --git a/Debugger/debug_stub.h b/Debugger/debug_stub.h
index b1815f8..efaed73 100644
--- a/Debugger/debug_stub.h
+++ b/Debugger/debug_stub.h
@@ -39,21 +39,18 @@
#define USB_BUFSIZE 64 /* USB Buffer size for AT91SAM7S */
#define USB_NXT_TELEGRAMTYPE_OFFSET 0 /* NXT Direct Command/Response Header */
-#define USB_NXT_COMMAND_OFFSET 1
-#define USB_NXT_SEGNUM_OFFSET 2
-#define USB_NXT_TELEGRAMSIZE_OFFSET 3
+#define USB_NXT_SEGNUM_OFFSET 1
+#define USB_NXT_TELEGRAMSIZE_OFFSET 2
-#define USB_NXT_TELEGRAM_DC_RESP 0x00
-#define USB_NXT_TELEGRAM_RESP 0x02
-#define USB_NXT_COMMAND_GDB 0xF0
-#define USB_NXT_RESPONSE_GDB 0xF1
+#define USB_NXT_TELEGRAM_DC_RESP 0x8d
+#define USB_NXT_TELEGRAM_RESP 0x8d
-#define USB_GDBMSG_START 4 /* Offset into USB Telegram buffer */
-#define USB_GDBMSG_CHKSUMOFFSET 4 /* to be subtracted from USB_NXT_TELEGRAMSIZE_OFFSET */
+#define USB_GDBMSG_START 3 /* Offset into USB Telegram buffer */
+#define USB_GDBMSG_CHKSUMOFFSET 3 /* to be subtracted from USB_NXT_TELEGRAMSIZE_OFFSET */
#define MSG_NUMSEGMENTS 3 /* For packet transfers */
-#define MSG_SEGMENTSIZE (USB_BUFSIZE - USB_GDBMSG_START) /* 60 bytes per segment */
-#define MSGBUF_SIZE (MSG_SEGMENTSIZE*MSG_NUMSEGMENTS) /* Debug Message Buffer Size, 60 x 3 = 180 chars = ~80 bytes of actual data */
+#define MSG_SEGMENTSIZE (USB_BUFSIZE - USB_GDBMSG_START) /* 61 bytes per segment */
+#define MSGBUF_SIZE (MSG_SEGMENTSIZE*MSG_NUMSEGMENTS) /* Debug Message Buffer Size, 61 x 3 = 183 chars = ~80 bytes of actual data */
#define MSGBUF_STARTCHAR '$'
#define MSGBUF_ACKCHAR '+'
diff --git a/Host/nxt-gdb-server.py b/Host/nxt-gdb-server.py
index fba6073..27cb4a3 100755
--- a/Host/nxt-gdb-server.py
+++ b/Host/nxt-gdb-server.py
@@ -3,6 +3,7 @@
# Copyright (C) 2011 the NxOS developers
#
# Module Developed by: Nicolas Schodet
+# TC Wan
#
# See AUTHORS for a full list of the developers.
#
@@ -32,6 +33,7 @@ class NXTGDBServer:
# Debug command header, no reply.
debug_command = 0x8d
+ segment_no = 0
def __init__ (self, port):
"""Initialise server."""
@@ -41,15 +43,15 @@ class NXTGDBServer:
"""Return packed data to send to NXT."""
# Insert command and length.
assert len (data) <= self.pack_size
- return struct.pack ('BB', self.debug_command, len (data)) + data
+ return struct.pack ('BBB', self.debug_command, self.segment_no, len (data)) + data
def unpack (self, data):
"""Return unpacked data from NXT."""
# May be improved, for now, check command and announced length.
if len (data) < 2:
return ''
- header, body = data[0:2], data[2:]
- command, length = struct.unpack ('BB', header)
+ header, body = data[0:3], data[3:]
+ command, self.segment_no, length = struct.unpack ('BBB', header)
if command != self.debug_command or length != len (body):
return ''
return body