aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_comm.S15
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_macros.h14
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_stub.S121
-rw-r--r--AT91SAM7S256/armdebug/Debugger/undef_handler.S5
-rwxr-xr-xAT91SAM7S256/armdebug/Host/nxt-gdb-server.py13
-rw-r--r--AT91SAM7S256/armdebug/PyFantom/AUTHORS5
-rw-r--r--AT91SAM7S256/armdebug/PyFantom/pyfantom.py359
-rw-r--r--AT91SAM7S256/armdebug/README5
8 files changed, 120 insertions, 417 deletions
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_comm.S b/AT91SAM7S256/armdebug/Debugger/debug_comm.S
index 6635618..740fa3e 100644
--- a/AT91SAM7S256/armdebug/Debugger/debug_comm.S
+++ b/AT91SAM7S256/armdebug/Debugger/debug_comm.S
@@ -765,6 +765,9 @@ _hasMsg2Copy:
/* Need to account for Packet Acknowledgement */
1: ldrb r0, [r5]
+ teq r0, #MSGBUF_CTRLC /* Look for Ctrl-C */
+ moveq r0, r4 /* If found, set R0 to current message length */
+ beq exit_dbg__getDebugMsg /* and return */
teq r0, #MSGBUF_NAKCHAR /* Look for '-' */
beq exit_dbg__getMsgError /* FIXME: We can't handle retransmission, flag message error */
teq r0, #MSGBUF_ACKCHAR /* Look for '+' */
@@ -960,17 +963,19 @@ exit_dbg__putMsgError:
exit_dbg__putDebugMsg:
ldmfd sp!, {r4,r5,pc}
- .global dbg__requestRetransmission
-/* dbg__requestRetransmission
- * Request for Retransmission due to received message Checksum error (Blocking) .
+ .global dbg__sendAckOrNak
+/* dbg__sendAckOrNak
+ * Send Ack (for successful receipt of message)
+ * or Nak (for Retransmission due to received message Checksum error) (Blocking) .
* On entry:
* No parameters (assume pointers were initialized previously using dbg__comm_init)
* On exit:
* r0: status (0: success, -1: error)
* r1: destroyed
- * Note: A Retransmission is indicated by '-', which is prepended with the USB header and sent (without checksum)
+ * Note: An Ack Or Nak is indicated by '+' or '-', which is prepended with the USB header and sent (without checksum)
+ * Sending Ack is only done for Continue and Step commands, where GDB does not expect any replies.
*/
-dbg__requestRetransmission:
+dbg__sendAckOrNak:
stmfd sp!, {lr}
ldr r1, =debug_msgTxBufPtr /* R2: data structure base pointer */
ldr r0, [r1] /* Tx buffer Start Address */
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_macros.h b/AT91SAM7S256/armdebug/Debugger/debug_macros.h
index 89c7035..e71d9ca 100644
--- a/AT91SAM7S256/armdebug/Debugger/debug_macros.h
+++ b/AT91SAM7S256/armdebug/Debugger/debug_macros.h
@@ -121,6 +121,20 @@
bne 1b
.endm
+/* _dbg_outputAckOnlyFlag
+ * Return Flag ('+') for Continue or Step
+ * On exit:
+ * R0: Pointer to Output Buffer ASCIIZ location
+ * R1: destroyed
+ * R2: destroyed
+ */
+ .macro _dbg_outputAckOnlyFlag
+ ldr r0, =debug_OutMsgBuf
+ ldr r1, =debug_AckOnlyFlag /* ASCIIZ terminated */
+ _dbg_stpcpy r0, r1, r2
+ .endm
+
+
/* _dbg_outputRetransmitFlag
* Return Flag ('-') for Checksum Error (retransmission needed)
* On exit:
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_stub.S b/AT91SAM7S256/armdebug/Debugger/debug_stub.S
index 4520c32..3743b98 100644
--- a/AT91SAM7S256/armdebug/Debugger/debug_stub.S
+++ b/AT91SAM7S256/armdebug/Debugger/debug_stub.S
@@ -210,6 +210,9 @@ debug_curr_breakpoint:
debug_RetransmitFlag:
.byte '-',0
+debug_AckOnlyFlag:
+ .byte '+',0
+
debug_ValidResponsePrefix:
.byte '+','$',0
@@ -362,7 +365,7 @@ debug_armComplexCCTable:
.extern dbg__hasDebugMsg /* Check for message from the communications link */
.extern dbg__getDebugMsg /* Read a message from the communications link */
.extern dbg__putDebugMsg /* Write a message to the communications link */
- .extern dbg__requestRetransmission /* Request Retransmission due to Checksum Error */
+ .extern dbg__sendAckOrNak /* Send Ack or Nak to indicate success/failure of message receipt */
.extern dbg__runloopTasks /* Platform specific Run Loop processing */
@@ -482,7 +485,7 @@ dbg__bkpt_init:
bl _dbg__clear_breakpoints
mov r2, #0
ldr r1, =debug_curr_breakpoint
- str r2, [r1]
+ strb r2, [r1]
ldr r0, =debug_InMsgBuf
strb r2, [r0]
ldr r1, =debug_OutMsgBuf
@@ -574,7 +577,9 @@ _process_auto_breakpoint:
* Common internal routine to return execution to user program
*/
_dbg__switch2undefmode:
- bl _dbg__flush_icache
+ bl __dbg__procAckOnly /* send Ack to keep GDB server happy */
+ bl dbg__runloopTasks /* Service run loop tasks */
+ bl _dbg__flush_icache
msr cpsr_c, #(MODE_UND | CPSR_FIQ | CPSR_IRQ) /* Configure Undef Mode */
_dbg_setmode FALSE /* Debug Mode = False */
ldr lr, =resume_execution
@@ -617,10 +622,21 @@ dbg__bkpt_waitCMD_cont:
bl dbg__getDebugMsg /* Read new message from Debugger, buflen in R0, 0 if none, -1 if error, msgbuf pointer in R1 */
cmp r0, #0
beq dbg__bkpt_waitCMD_cont /* No message yet, do housekeeping tasks */
- blt __dbg__procChecksumError /* Message invalid, checksum error? */
-/* Message now has $<packet info>\0 */
+ bgt _proc_command /* valid message, process it */
+ bl __dbg__procChecksumError /* Message invalid, checksum error? */
+ b dbg__bkpt_waitCMD_cont
+
+_proc_command:
+/* Message now has Ctrl-C or $<packet info>\0 */
mov r4, r1 /* Use R4 as buffer pointer */
- ldrb r0, [r4], #1 /* Look for '$' */
+ ldrb r0, [r4], #1 /* Look for Ctrl-C or '$' */
+ teq r0, #MSGBUF_CTRLC
+ bne _dbg_check_gdb_command
+ /* Ctrl-C detected, do nothing (wait for next command from GDB) */
+ bl __dbg__procAckOnly /* send Ack */
+ b dbg__bkpt_waitCMD_cont
+
+_dbg_check_gdb_command:
teq r0, #MSGBUF_STARTCHAR
movne r0, #MSG_ERRFORMAT /* Message Format invalid (not '$') */
bne _dbg__cmdError /* Shouldn't happen */
@@ -644,19 +660,45 @@ _dbg__cmdExists:
_dbg_jumpTableHandler debug_cmdJumpTable, r2, r3 /* Call Command Handler Routine, use R2 as jump address pointer */
b dbg__bkpt_waitCMD_cont
-__dbg__procChecksumError:
- _dbg_outputRetransmitFlag
- bl dbg__requestRetransmission /* Request message retransmission from GDB server */
- cmp r0, #0
- beq dbg__bkpt_waitCMD_cont /* Sending of retransmission request succeeded */
- bl dbg__runloopTasks /* Service run loop tasks */
- b __dbg__procChecksumError /* Retry retransmission */
-
_dbg__cmdError:
_dbg_outputMsgStatusErr
bl dbg__putDebugMsg /* Send error response to the GDB server */
b dbg__bkpt_waitCMD_cont
+
+/* __dbg__procAckOnly
+ * Send Ack to GDB due to Continue or Step
+ * On entry:
+ * None
+ * On exit:
+ * r0-r3: destroyed
+ */
+__dbg__procAckOnly:
+ stmfd sp!, {lr}
+ _dbg_outputAckOnlyFlag
+ b _cont_sendAckOrNak /* Acknowledge Continue or Step command from GDB server */
+
+/* __dbg__procChecksumError
+ * Request Retransmission from GDB due to Checksum error
+ * On entry:
+ * None
+ * On exit:
+ * r0-r3: destroyed
+ */
+__dbg__procChecksumError:
+ stmfd sp!, {lr}
+ _dbg_outputRetransmitFlag
+ /* b _cont_sendAckOrNak */ /* Acknowledge Continue or Step command from GDB server */
+
+_cont_sendAckOrNak:
+ bl dbg__sendAckOrNak /* send Ack or Nak to GDB server */
+ cmp r0, #0
+ beq _cont_sendAckOrNak_exit /* Sending of Ack or Nak succeeded */
+ bl dbg__runloopTasks /* Service run loop tasks */
+ b _cont_sendAckOrNak /* Retry Ack or Nak transmission */
+_cont_sendAckOrNak_exit:
+ ldmfd sp!, {pc}
+
/* _dbg__cmdChar2Index
* Convert Command Character to Jump Table Index
* On entry:
@@ -1130,39 +1172,27 @@ _dbg__cont_check_breakpoint_type:
teq r0, #DBG_MANUAL_BKPT_ARM
beq _dbg__cont_is_manual_bkpt_or_address_specified
teq r0, #DBG_MANUAL_BKPT_THUMB
- bne _dbg__cont_is_normal_breakpoint
-
-_dbg__cont_is_manual_bkpt_or_address_specified:
- bl _dbg__activate_breakpoints /* Restore exisiting breakpoints */
- b _dbg__switch2undefmode
+ beq _dbg__cont_is_manual_bkpt_or_address_specified
_dbg__cont_is_normal_breakpoint:
/* FIXME: _dbg_next_instruction_addr doesn't actually work currently.
This breaks normal breakpoints which need to determine the next instruction to execute
(for placing the autobreakpoint) prior to returning.
*/
- mov r2, #DBGSTACK_USERPC_INDEX /* Retrieve Aborted Instruction PC from the Debug Stack */
+ mov r2, #DBGSTACK_USERPC_INDEX /* Retrieve Aborted Instruction PC from the Debug Stack */
_getdbgregisterfromindex r2, r0 /* Retrieve Register contents into R0 */
- mov r2, #DBGSTACK_NEXTINSTR_INDEX /* The Next Instruction Pointer for Resume is in index 0 of the Debug Stack */
+ mov r2, #DBGSTACK_NEXTINSTR_INDEX /* The Next Instruction Pointer for Resume is in index 0 of the Debug Stack */
_setdbgregisterfromindex r2, r0, r1 /* Set Register contents in R0, using index in R2, and scratch register R1 */
- bl _dbg_next_instruction_addr /* next instruction address returned in r1 */
- bl _dbg__install_singlestep /* Setup Single Step, next instruction address returned in r1 */
+ bl _dbg_next_instruction_addr /* next instruction address returned in r1 */
+ bl _dbg__install_singlestep /* Setup Single Step, next instruction address returned in r1 */
_dbg_getcurrbkpt_index r0 /* load current breakpoint index in memory */
- bl _dbg__activate_autobreakpoint /* pass next instruction address in r1 */
-
-#if 0
-/* Not part of the GDB Remote Protocol spec. Messages are sent only when system halts, not when we resume */
-__dbg__sendOkBeforeResume:
- _dbg_outputMsgStatusOk
- bl dbg__putDebugMsg /* Send Ok response to the GDB server */
- cmp r0, #0
- beq _dbg__switch2undefmode /* Sending of retransmission request succeeded */
- bl dbg__runloopTasks /* Service run loop tasks */
- b __dbg__sendOkBeforeResume /* Retry retransmission */
-#endif
-
+ bl _dbg__activate_autobreakpoint /* pass next instruction address in r1 */
b _dbg__switch2undefmode
+_dbg__cont_is_manual_bkpt_or_address_specified:
+ bl _dbg__activate_breakpoints /* Restore exisiting breakpoints */
+ b _dbg__switch2undefmode
+
/* _dbg__cmd_Step
* Step User Program Execution Command Handler
* Setup breakpoints before resuming execution of program.
@@ -1197,15 +1227,10 @@ _dbg__step_fromAddr:
_dbg__step_check_breakpoint_type:
_dbg_get_bkpt_type r0
- teq r0, #DBG_MANUAL_BKPT_ARM
- beq _dbg__step_is_manual_bkpt
- teq r0, #DBG_MANUAL_BKPT_THUMB
- bne _dbg__step_is_normal_breakpoint
-
-_dbg__step_is_manual_bkpt:
- mov r2, #DBGSTACK_NEXTINSTR_INDEX /* The Next Instruction Pointer for Resume is in index 0 of the Debug Stack */
- _getdbgregisterfromindex r2, r1 /* Retrieve Register contents into R1 */
- b _dbg__step_is_manual_bkpt_or_address_specified
+ teq r0, #DBG_MANUAL_BKPT_ARM
+ beq _dbg__step_is_manual_bkpt
+ teq r0, #DBG_MANUAL_BKPT_THUMB
+ beq _dbg__step_is_manual_bkpt
_dbg__step_is_normal_breakpoint:
/* FIXME: _dbg_next_instruction_addr doesn't actually work currently.
@@ -1216,6 +1241,12 @@ _dbg__step_is_normal_breakpoint:
_getdbgregisterfromindex r2, r0 /* Retrieve Register contents into R0 */
mov r2, #DBGSTACK_NEXTINSTR_INDEX /* The Next Instruction Pointer for Resume is in index 0 of the Debug Stack */
_setdbgregisterfromindex r2, r0, r1 /* Set Register contents in R0, using index in R2, and scratch register R1 */
+ b _dbg__step_is_manual_bkpt_or_address_specified
+
+_dbg__step_is_manual_bkpt:
+ mov r2, #DBGSTACK_NEXTINSTR_INDEX /* The Next Instruction Pointer for Resume is in index 0 of the Debug Stack */
+ _getdbgregisterfromindex r2, r1 /* Retrieve Register contents into R1 */
+ /* b _dbg__step_is_manual_bkpt_or_address_specified */
_dbg__step_is_manual_bkpt_or_address_specified:
/* R1 contains the instruction address to be executed upon return */
diff --git a/AT91SAM7S256/armdebug/Debugger/undef_handler.S b/AT91SAM7S256/armdebug/Debugger/undef_handler.S
index b980a5d..f185fbd 100644
--- a/AT91SAM7S256/armdebug/Debugger/undef_handler.S
+++ b/AT91SAM7S256/armdebug/Debugger/undef_handler.S
@@ -87,6 +87,7 @@ _is_thumb:
teq r2, r1
bne default_undef_handler
ldr r1, =BKPT16_ENUM_MASK /* get Thumb BKPT Enum Mask */
+ ldr r2, =dbg__thumb_bkpt_handler /* handle BKPT, BKPT index in r0 */
b _exit_undef_handler
_is_arm:
ldr r0, [r0] /* load UNDEF instruction into r0 */
@@ -96,11 +97,11 @@ _is_arm:
teq r2, r1
bne default_undef_handler
ldr r1, =BKPT32_ENUM_MASK /* get ARM BKPT Enum Mask */
+ ldr r2, =dbg__arm_bkpt_handler /* handle BKPT, BKPT index in r0 */
_exit_undef_handler:
and r0, r1, r0 /* Keep index value */
msr cpsr_c, #(MODE_ABT) /* Configure Abort Mode */
- ldr lr, =dbg__arm_bkpt_handler /* handle BKPT, BKPT index in r0 */
- mov pc, lr /* Invoke Debugger State (Supervisor Mode) */
+ mov pc, r2 /* Invoke Debugger State (Supervisor Mode) */
.global resume_execution
diff --git a/AT91SAM7S256/armdebug/Host/nxt-gdb-server.py b/AT91SAM7S256/armdebug/Host/nxt-gdb-server.py
index ee03899..47a552d 100755
--- a/AT91SAM7S256/armdebug/Host/nxt-gdb-server.py
+++ b/AT91SAM7S256/armdebug/Host/nxt-gdb-server.py
@@ -22,6 +22,8 @@ import select
import usb
import struct
+CTRLC = chr(3)
+STATUS_QUERY = "$?#3F"
DEFAULT_PORT = 2828
SELECT_TIMEOUT = 0.1
DEBUG = True
@@ -70,6 +72,14 @@ class NXTGDBServer:
"""Split datas in GDB commands and make segments with each command."""
segs = [ ]
self.in_buf += data
+ # Find Ctrl-C (assumed to be by itself and not following a normal command)
+ end = self.in_buf.find (CTRLC)
+ if end >= 0:
+ msg, self.in_buf = self.in_buf[0:end+1], self.in_buf[end+1:]
+ assert len (msg) <= self.pack_size, "Ctrl-C Command Packet too long!"
+ segs.append (self.pack (msg, 0))
+ end = self.in_buf.find (CTRLC)
+
end = self.in_buf.find ('#')
# Is # found and enough place for the checkum?
while end >= 0 and end < len (self.in_buf) - 2:
@@ -142,6 +152,9 @@ class NXTGDBServer:
data = client.recv (self.recv_size)
data = data.strip()
if len (data) > 0:
+ #if len (data) == 1 and data.find(CTRLC) >= 0:
+ # print "CTRL-C Received!"
+ # data = STATUS_QUERY
if DEBUG:
print "[GDB->NXT] %s" % data
segments = self.segment (data)
diff --git a/AT91SAM7S256/armdebug/PyFantom/AUTHORS b/AT91SAM7S256/armdebug/PyFantom/AUTHORS
deleted file mode 100644
index 5c680ea..0000000
--- a/AT91SAM7S256/armdebug/PyFantom/AUTHORS
+++ /dev/null
@@ -1,5 +0,0 @@
-The following people have contributed code, in various quantities, to armdebug.
-A big thanks to all of them, armdebug is what it is in part thanks to each of
-them. In alphabetical order:
-
-Nicolas Schodet <nico (at) ni.fr.eu.org>
diff --git a/AT91SAM7S256/armdebug/PyFantom/pyfantom.py b/AT91SAM7S256/armdebug/PyFantom/pyfantom.py
deleted file mode 100644
index 46367b1..0000000
--- a/AT91SAM7S256/armdebug/PyFantom/pyfantom.py
+++ /dev/null
@@ -1,359 +0,0 @@
-"""NXT Fantom driver wrapper."""
-from ctypes import c_int, c_uint, c_ushort, c_ubyte, c_char_p, byref, POINTER
-import ctypes.util
-import platform
-import collections
-
-# Check platform.
-if platform.system() == 'Darwin':
- import sys
- if sys.maxsize > 2**32:
- raise RuntimeError("fantom drivers not available in 64 bit mode.\n"
- "You can run python in 32 bit mode using:\n"
- "arch -i386 python2.6\n")
- libpath = '/Library/Frameworks/Fantom.framework/Fantom'
- #libpath = ctypes.util.find_library('Fantom')
-else:
- raise RuntimeError('unsupported platform')
-
-# Load library.
-dll = ctypes.cdll.LoadLibrary(libpath)
-dll.nFANTOM100_createNXTIterator.argtypes = [c_ushort, c_uint, POINTER(c_int)]
-dll.nFANTOM100_createNXTIterator.restype = c_uint
-dll.nFANTOM100_destroyNXTIterator.argtypes = [c_int, POINTER(c_int)]
-dll.nFANTOM100_destroyNXTIterator.restype = None
-dll.nFANTOM100_iNXTIterator_advance.argtypes = [c_uint, POINTER(c_int)]
-dll.nFANTOM100_iNXTIterator_advance.restype = None
-dll.nFANTOM100_iNXTIterator_getNXT.argtypes = [c_uint, POINTER(c_int)]
-dll.nFANTOM100_iNXTIterator_getNXT.restype = c_uint
-dll.nFANTOM100_iNXTIterator_getName.argtypes = [c_uint, c_char_p,
- POINTER(c_int)]
-dll.nFANTOM100_iNXTIterator_getName.restype = None
-dll.nFANTOM100_createNXT.argtypes = [c_char_p, POINTER(c_int), c_ushort]
-dll.nFANTOM100_createNXT.restype = c_uint
-dll.nFANTOM100_destroyNXT.argtypes = [c_uint, POINTER(c_int)]
-dll.nFANTOM100_destroyNXT.restype = None
-dll.nFANTOM100_iNXT_getFirmwareVersion.argtypes = [c_uint, POINTER(c_ubyte),
- POINTER(c_ubyte), POINTER(c_ubyte), POINTER(c_ubyte), POINTER(c_int)]
-dll.nFANTOM100_iNXT_getFirmwareVersion.argtypes = None
-dll.nFANTOM100_iNXT_getDeviceInfo.argtypes = [c_uint, c_char_p,
- POINTER(c_ubyte), POINTER(c_ubyte), POINTER(c_uint), POINTER(c_int)]
-dll.nFANTOM100_iNXT_write.argtypes = [c_uint, c_char_p, c_uint,
- POINTER(c_int)]
-dll.nFANTOM100_iNXT_write.restype = c_uint
-dll.nFANTOM100_iNXT_read.argtypes = [c_uint, c_char_p, c_uint,
- POINTER(c_int)]
-dll.nFANTOM100_iNXT_read.restype = c_uint
-dll.nFANTOM100_iNXT_getDeviceInfo.restype = None
-dll.nFANTOM100_iNXT_getResourceString.argtypes = [c_uint, c_char_p,
- POINTER(c_int)]
-dll.nFANTOM100_iNXT_getResourceString.restype = None
-
-class FantomException(RuntimeError):
- """Exception thrown on Fantom library error."""
- pass
-
-class Status:
- """Status codes used by Fantom library."""
-
- # Status codes. {{{
- Success = 0
- Offset = -142000
- PairingFailed = Offset - 5
- BluetoothSearchFailed = Offset - 6
- SystemLibraryNotFound = Offset - 7
- UnpairingFailed = Offset - 8
- InvalidFilename = Offset - 9
- InvalidIteratorDereference = Offset - 10
- LockOperationFailed = Offset - 11
- SizeUnknown = Offset - 12
- DuplicateOpen = Offset - 13
- EmptyFile = Offset - 14
- FirmwareDownloadFailed = Offset - 15
- PortNotFound = Offset - 16
- NoMoreItemsFound = Offset - 17
- TooManyUnconfiguredDevices = Offset - 18
- CommandMismatch = Offset - 19
- IllegalOperation = Offset - 20
- BluetoothCacheUpdateFailed = Offset - 21
- NonNXTDeviceSelected = Offset - 22
- RetryConnection = Offset - 23
- PowerCycleNXT = Offset - 24
- FeatureNotImplemented = Offset - 99
- FWIllegalHandle = Offset - 189
- FWIllegalFileName = Offset - 190
- FWOutOfBounds = Offset - 191
- FWModuleNotFound = Offset - 192
- FWFileExists = Offset - 193
- FWFileIsFull = Offset - 194
- FWAppendNotPossible = Offset - 195
- FWNoWriteBuffers = Offset - 196
- FWFileIsBusy = Offset - 197
- FWUndefinedError = Offset - 198
- FWNoLinearSpace = Offset - 199
- FWHandleAlreadyClosed = Offset - 200
- FWFileNotFound = Offset - 201
- FWNotLinearFile = Offset - 202
- FWEndOfFile = Offset - 203
- FWEndOfFileExpected = Offset - 204
- FWNoMoreFiles = Offset - 205
- FWNoSpace = Offset - 206
- FWNoMoreHandles = Offset - 207
- FWUnknownErrorCode = Offset - 208
- # }}}
-
- # Text description. {{{
- description = {
- Success: "No error",
- PairingFailed: "Bluetooth pairing operation failed.",
- BluetoothSearchFailed: "Bluetooth search failed.",
- SystemLibraryNotFound: "System library not found.",
- UnpairingFailed: "Bluetooth unpairing operation failed.",
- InvalidFilename: "Invalid filename specified.",
- InvalidIteratorDereference: "Invalid iterator dereference.",
- LockOperationFailed: "Resource locking operation failed.",
- SizeUnknown: "Could not determine the requested size.",
- DuplicateOpen: "Cannot open two objects at once.",
- EmptyFile: "File is empty.",
- FirmwareDownloadFailed: "Firmware download failed.",
- PortNotFound: "Could not locate virtual serial port.",
- NoMoreItemsFound: "No more items found.",
- TooManyUnconfiguredDevices: "Too many unconfigured devices.",
- CommandMismatch: "Command mismatch in firmware response.",
- IllegalOperation: "Illegal operation.",
- BluetoothCacheUpdateFailed: "Could not update local Bluetooth"
- " cache with new name.",
- NonNXTDeviceSelected: "Selected device is not an NXT.",
- RetryConnection: "Communication error. Retry the operation.",
- PowerCycleNXT: "Could not connect to NXT. Turn the NXT off and"
- " then back on before continuing.",
- FeatureNotImplemented: "This feature is not yet implemented.",
- FWIllegalHandle: "Firmware reported an illegal handle.",
- FWIllegalFileName: "Firmware reported an illegal file name.",
- FWOutOfBounds: "Firmware reported an out of bounds reference.",
- FWModuleNotFound: "Firmware could not find module.",
- FWFileExists: "Firmware reported that the file already exists.",
- FWFileIsFull: "Firmware reported that the file is full.",
- FWAppendNotPossible: "Firmware reported the append operation is"
- " not possible.",
- FWNoWriteBuffers: "Firmware has no write buffers available.",
- FWFileIsBusy: "Firmware reported that file is busy.",
- FWUndefinedError: "Firmware reported the undefined error.",
- FWNoLinearSpace: "Firmware reported that no linear space is"
- " available.",
- FWHandleAlreadyClosed: "Firmware reported that handle has already"
- " been closed.",
- FWFileNotFound: "Firmware could not find file.",
- FWNotLinearFile: "Firmware reported that the requested file is"
- " not linear.",
- FWEndOfFile: "Firmware reached the end of the file.",
- FWEndOfFileExpected: "Firmware expected an end of file.",
- FWNoMoreFiles: "Firmware cannot handle more files.",
- FWNoSpace: "Firmware reported the NXT is out of space.",
- FWNoMoreHandles: "Firmware could not create a handle.",
- FWUnknownErrorCode: "Firmware reported an unknown error code.",
- }
- # }}}
-
- @staticmethod
- def check(status):
- """Check status, raise on error."""
- if status.value < Status.Success:
- if status.value in Status.description:
- description = Status.description[status.value]
- else:
- description = 'error %d' % status.value
- raise FantomException(description)
-
-class NXTIterator:
- """Interface to an iterator, to find connected NXT."""
-
- def __init__(self, search_bluetooth, bluetooth_search_timeout_s=5):
- """Initialize iterator."""
- self.search_bluetooth = search_bluetooth
- self.bluetooth_search_timeout_s = bluetooth_search_timeout_s
- self.handle = None
- self.stop = False
-
- def __iter__(self):
- """Return the iterator object itself."""
- return self
-
- def next(self):
- """Implement the iterator protocol."""
- if self.stop:
- raise StopIteration()
- # Find first, or find next.
- status = c_int(0)
- if self.handle is None:
- handle = dll.nFANTOM100_createNXTIterator(self.search_bluetooth,
- self.bluetooth_search_timeout_s, byref(status))
- else:
- handle = self.handle
- dll.nFANTOM100_iNXTIterator_advance(handle, byref(status))
- # Check result.
- if status.value == Status.NoMoreItemsFound:
- self.stop = True
- raise StopIteration()
- Status.check(status)
- self.handle = handle
- # Return itself (not part of the protocol, but it has get_nxt and
- # get_name).
- return self
-
- def get_nxt(self):
- """Get the NXT instance."""
- if self.handle is None or self.stop:
- raise FantomException('invalid iterator')
- status = c_int(0)
- handle = dll.nFANTOM100_iNXTIterator_getNXT(self.handle, byref(status))
- Status.check(status)
- return NXT(handle)
-
- def get_name(self):
- """Get the NXT resource name."""
- if self.handle is None or self.stop:
- raise FantomException('invalid iterator')
- status = c_int(0)
- name = ctypes.create_string_buffer(256)
- dll.nFANTOM100_iNXTIterator_getName(self.handle, name, byref(status))
- Status.check(status)
- return name.value
-
- get_resource_string = get_name
-
- def __del__(self):
- """Destroy iterator."""
- if self.handle is not None:
- status = c_int(0)
- dll.nFANTOM100_destroyNXTIterator(self.handle, byref(status))
-
-class NXT:
- """Interface to the NXT brick."""
-
- DeviceInfo = collections.namedtuple('DeviceInfo',
- 'name bluetooth_address signal_strength available_flash')
-
- def __init__(self, name_or_handle):
- """Initialize interface."""
- if isinstance(name_or_handle, basestring):
- status = c_int(0)
- handle = dll.nFANTOM100_createNXT(name_or_handle, byref(status),
- True)
- Status.check(status)
- self.handle = handle
- else:
- self.handle = name_or_handle
-
- def get_firmware_version(self):
- """Get protocol and firmware versions installed on this NXT."""
- status = c_int(0)
- protocol_major = c_ubyte(0)
- protocol_minor = c_ubyte(0)
- firmware_major = c_ubyte(0)
- firmware_minor = c_ubyte(0)
- dll.nFANTOM100_iNXT_getFirmwareVersion(self.handle,
- byref(protocol_major), byref(protocol_minor),
- byref(firmware_major), byref(firmware_minor),
- byref(status))
- Status.check(status)
- return (protocol_major.value, protocol_minor.value,
- firmware_major.value, firmware_minor.value)
-
- def write(self, data):
- """Write, in a generic fashion, to this NXT."""
- status = c_int(0)
- data_buffer = ctypes.create_string_buffer(data)
- ret = dll.nFANTOM100_iNXT_write(self.handle, data_buffer, len(data),
- byref(status))
- Status.check(status)
- return ret
-
- def read(self, length):
- """Read, in a generic fashion, from this NXT."""
- status = c_int(0)
- data_buffer = ctypes.create_string_buffer(length)
- ret = dll.nFANTOM100_iNXT_write(self.handle, data_buffer, length,
- byref(status))
- Status.check(status)
- assert ret <= length
- return data_buffer.raw[0:ret]
-
- def get_device_info(self):
- """Get basic information about this NXT."""
- status = c_int(0)
- name = ctypes.create_string_buffer(16)
- bluetooth_address = (c_ubyte * 7)()
- signal_strength = (c_ubyte * 4)()
- available_flash = c_uint(0)
- dll.nFANTOM100_iNXT_getDeviceInfo(self.handle, name,
- bluetooth_address, signal_strength, byref(available_flash),
- byref(status))
- return self.DeviceInfo(
- name = name.value,
- bluetooth_address = ':'.join('%02x' % c
- for c in bluetooth_address[0:5]),
- signal_strength = tuple(c for c in signal_strength),
- available_flash = available_flash.value,
- )
-
- def get_resource_string(self):
- """Get the NXT resource name."""
- status = c_int(0)
- name = ctypes.create_string_buffer(256)
- dll.nFANTOM100_iNXT_getResourceString(self.handle, name,
- byref(status))
- Status.check(status)
- return name.value
-
- def __del__(self):
- """Destroy interface."""
- if self.handle is not None:
- status = c_int(0)
- dll.nFANTOM100_destroyNXT(self.handle, byref(status))
-
-if __name__ == '__main__':
- get_info = False
- write_read = True
- for i in NXTIterator(False):
- if get_info:
- print "name:", i.get_name()
- print "resource string:", i.get_resource_string()
- print "get_nxt:"
- nxt = i.get_nxt()
- print " firmware version:", nxt.get_firmware_version()
- print " get device info:", nxt.get_device_info()
- rs = nxt.get_resource_string()
- print " resource string:", rs
- del nxt
- print "NXT():"
- nxt = NXT(rs)
- print " resource string:", nxt.get_resource_string()
- del nxt
- if write_read:
- nxt = i.get_nxt()
- import struct
- # Write VERSION SYS_CMD.
- # Query:
- # SYS_CMD: 0x01
- # VERSION: 0x88
- cmd = struct.pack('2B', 0x01, 0x88)
- r = nxt.write(cmd)
- print "wrote", r
- # Response:
- # REPLY_CMD: 0x02
- # VERSION: 0x88
- # SUCCESS: 0x00
- # PROTOCOL_VERSION minor
- # PROTOCOL_VERSION major
- # FIRMWARE_VERSION minor
- # FIRMWARE_VERSION major
- rep = nxt.read(7)
- print "read", struct.unpack('%dB' % len(rep), rep)
- # Same thing, without response.
- cmd = struct.pack('2B', 0x81, 0x88)
- r = nxt.write(cmd)
- print "wrote", r
- rep = nxt.read(7)
- print struct.unpack('%dB' % len(rep), rep)
- del nxt
diff --git a/AT91SAM7S256/armdebug/README b/AT91SAM7S256/armdebug/README
index 9b6bca3..0e5ca38 100644
--- a/AT91SAM7S256/armdebug/README
+++ b/AT91SAM7S256/armdebug/README
@@ -9,9 +9,12 @@ Contents
The various folders contents are as follows:
Debugger: GDB client driver for NXT (need to be embedded in firmware code)
Host: GDB Server for PC Host
-FantomModule: pyFantom - Python Wrapper for Fantom Driver on Mac OSX (used by nxt-python)
nxt-python-fantom: Local fork of nxt-python to support pyFantom
+Obsolete
+========
+FantomModule: pyFantom - Python Wrapper for Fantom Driver on Mac OSX (used by nxt-python) [abandoned for now, use pyfantom instead]
+
LICENCES
========