aboutsummaryrefslogtreecommitdiff
path: root/AT91SAM7S256/armdebug
diff options
context:
space:
mode:
Diffstat (limited to 'AT91SAM7S256/armdebug')
-rw-r--r--AT91SAM7S256/armdebug/.gitignore41
-rw-r--r--AT91SAM7S256/armdebug/.project11
-rw-r--r--AT91SAM7S256/armdebug/AUTHORS6
-rw-r--r--AT91SAM7S256/armdebug/COPYING9
-rw-r--r--AT91SAM7S256/armdebug/Debugger/_c_arm_macros.h88
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_comm.S1025
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_comm.h53
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_internals.h300
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_macros.h386
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_runlooptasks.S87
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_stack.ld15
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_stub.S2925
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_stub.h132
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_test.S53
-rw-r--r--AT91SAM7S256/armdebug/Debugger/debug_test.h35
-rw-r--r--AT91SAM7S256/armdebug/Debugger/undef_handler.S147
-rw-r--r--AT91SAM7S256/armdebug/Doxyfile243
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/FantomModule.cpp305
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/FantomModule.h60
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/FantomModule.xcodeproj/project.pbxproj295
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/FantomModulePriv.h19
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/FantomModuleProj.xcconfig6
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/FantomModuleTarget.xcconfig11
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/FantomModule_Prefix.pch6
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/fantom/iFile.h280
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/fantom/iFileIterator.h133
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/fantom/iModule.h154
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/fantom/iModuleIterator.h123
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/fantom/iNXT.h666
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/fantom/iNXTIterator.h120
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/fantom/platform.h94
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/fantom/tStatus.h458
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/advanceFileIterator.vibin0 -> 52507 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/advanceModuleIterator.vibin0 -> 49641 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/advanceNXTIterator.vibin0 -> 49658 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/bluetoothFactoryReset.vibin0 -> 44169 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/bootSamba.vibin0 -> 30013 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/closeFile.vibin0 -> 42973 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/createFile.vibin0 -> 53398 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/createFileIterator.vibin0 -> 59566 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/createModule.vibin0 -> 60580 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/createModuleIterator.vibin0 -> 59588 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/createNXT.vibin0 -> 77937 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/createNXTIterator.vibin0 -> 61697 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/destroyFile.vibin0 -> 44491 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/destroyFileIterator.vibin0 -> 44715 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/destroyModule.vibin0 -> 44733 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/destroyModuleIterator.vibin0 -> 44657 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/destroyNXT.vibin0 -> 54226 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/destroyNXTIterator.vibin0 -> 44090 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/downloadFirmware.vibin0 -> 51788 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/eraseUserFlash.vibin0 -> 53218 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/findDeviceInFirmwareDownloadMode.vibin0 -> 33424 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/findNXT.vibin0 -> 57487 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getAvailableSize.vibin0 -> 46052 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getDeviceInfo.vibin0 -> 77397 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getFile.vibin0 -> 46879 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getFileName.vibin0 -> 57503 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getFileSize.vibin0 -> 49827 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getFileSizeFromIterator.vibin0 -> 46119 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getFilenameFromIterator.vibin0 -> 50359 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getFirmwareVersion.vibin0 -> 54438 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getIOMapSize.vibin0 -> 47320 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getModule.vibin0 -> 45677 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getModuleID.vibin0 -> 47455 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getModuleName.vibin0 -> 51125 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getModuleNameFromIterator.vibin0 -> 50373 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getModuleSize.vibin0 -> 47365 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getNXTFromIterator.vibin0 -> 45554 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getResourceString.vibin0 -> 50629 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getStringFromNXTIterator.vibin0 -> 50832 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/isPaired.vibin0 -> 33180 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/nakedRead.vibin0 -> 56833 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/nakedWrite.vibin0 -> 53942 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/nxt.ctlbin0 -> 12924 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/openForRead.vibin0 -> 46847 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/openForWrite.vibin0 -> 61344 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/pairBluetooth.vibin0 -> 37997 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/pollAvailableLength.vibin0 -> 48927 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/read.vibin0 -> 57324 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/readBufferData.vibin0 -> 60250 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/readIOMap.vibin0 -> 56653 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/remove.vibin0 -> 46762 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/sendDirectCommand.vibin0 -> 62289 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/setNXTName.vibin0 -> 46126 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/unpairBluetooth.vibin0 -> 28927 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/write.vibin0 -> 53525 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/writeIOMap.vibin0 -> 54282 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/advanceFileIterator.vibin0 -> 50807 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/advanceModuleIterator.vibin0 -> 47697 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/advanceNXTIterator.vibin0 -> 47430 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/bluetoothFactoryReset.vibin0 -> 42289 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/bootSamba.vibin0 -> 28245 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/closeFile.vibin0 -> 41293 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/createFile.vibin0 -> 51566 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/createFileIterator.vibin0 -> 57766 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/createModule.vibin0 -> 58556 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/createModuleIterator.vibin0 -> 57524 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/createNXT.vibin0 -> 75773 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/createNXTIterator.vibin0 -> 59605 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/destroyFile.vibin0 -> 42775 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/destroyFileIterator.vibin0 -> 43063 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/destroyModule.vibin0 -> 43017 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/destroyModuleIterator.vibin0 -> 42989 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/destroyNXT.vibin0 -> 52394 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/destroyNXTIterator.vibin0 -> 42110 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/downloadFirmware.vibin0 -> 49704 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/eraseUserFlash.vibin0 -> 50750 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/findDeviceInFirmwareDownloadMode.vibin0 -> 31524 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/findNXT.vibin0 -> 55779 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getAvailableSize.vibin0 -> 43996 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getDeviceInfo.vibin0 -> 73869 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getFile.vibin0 -> 45059 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getFileName.vibin0 -> 55387 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getFileSize.vibin0 -> 47899 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getFileSizeFromIterator.vibin0 -> 44047 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getFilenameFromIterator.vibin0 -> 48447 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getFirmwareVersion.vibin0 -> 52298 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getIOMapSize.vibin0 -> 45256 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getModule.vibin0 -> 43873 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getModuleID.vibin0 -> 45675 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getModuleName.vibin0 -> 49113 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getModuleNameFromIterator.vibin0 -> 48477 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getModuleSize.vibin0 -> 45533 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getNXTFromIterator.vibin0 -> 43762 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getResourceString.vibin0 -> 48689 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getStringFromNXTIterator.vibin0 -> 48664 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/isPaired.vibin0 -> 31428 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/nakedRead.vibin0 -> 55097 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/nakedWrite.vibin0 -> 51866 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/nxt.ctlbin0 -> 12692 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/openForRead.vibin0 -> 44755 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/openForWrite.vibin0 -> 58108 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/pairBluetooth.vibin0 -> 35997 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/pollAvailableLength.vibin0 -> 46951 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/read.vibin0 -> 55444 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/readBufferData.vibin0 -> 58354 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/readIOMap.vibin0 -> 54409 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/remove.vibin0 -> 45010 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/sendDirectCommand.vibin0 -> 60249 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/setNXTName.vibin0 -> 44182 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/unpairBluetooth.vibin0 -> 27139 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/write.vibin0 -> 51589 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/include/labview/win32/writeIOMap.vibin0 -> 52014 bytes
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/pyfantom/__init__.py0
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/setup.py40
-rw-r--r--AT91SAM7S256/armdebug/FantomModule/visatype.h155
-rw-r--r--AT91SAM7S256/armdebug/GNU-GPLv2.txt340
-rw-r--r--AT91SAM7S256/armdebug/Host/README21
-rw-r--r--AT91SAM7S256/armdebug/Host/gdb-commands.txt43
-rwxr-xr-xAT91SAM7S256/armdebug/Host/nxt-gdb-server.py202
-rw-r--r--AT91SAM7S256/armdebug/LEGO_Open_Source_License.docbin0 -> 40960 bytes
-rw-r--r--AT91SAM7S256/armdebug/README22
-rw-r--r--AT91SAM7S256/armdebug/SConscript13
-rw-r--r--AT91SAM7S256/armdebug/SConstruct182
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-2.1.0.tar.gzbin0 -> 49769 bytes
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/.project11
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/LICENSE674
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/MANIFEST.in4
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/PKG-INFO168
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/README169
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/examples/alpharex.py151
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/examples/cnc.py53
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/examples/latency.py23
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/examples/mary.py45
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/examples/message_test.py15
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/examples/spin.py14
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/examples/test_sensors.py11
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/install.bat11
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/nxt/__init__.py17
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/nxt/bluesock.py82
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/nxt/brick.py226
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/nxt/direct.py216
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/nxt/error.py87
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/nxt/fantomglue.py211
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/nxt/lightblueglue.py53
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/nxt/locator.py57
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/nxt/motor.py431
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/nxt/pyusbglue.py82
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/nxt/sensor/__init__.py50
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/nxt/sensor/analog.py41
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/nxt/sensor/common.py67
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/nxt/sensor/digital.py227
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/nxt/sensor/generic.py154
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/nxt/sensor/hitechnic.py611
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/nxt/sensor/mindsensors.py815
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/nxt/system.py297
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/nxt/telegram.py118
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/nxt/usbsock.py133
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/nxt/utils.py33
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/scripts/nxt_filer142
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/scripts/nxt_push47
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/scripts/nxt_test33
-rwxr-xr-xAT91SAM7S256/armdebug/nxt-python-fantom/scripts/pyenv-nxt_test3
-rwxr-xr-xAT91SAM7S256/armdebug/nxt-python-fantom/scripts/pyenv-syspython3
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/setup.py23
196 files changed, 14912 insertions, 0 deletions
diff --git a/AT91SAM7S256/armdebug/.gitignore b/AT91SAM7S256/armdebug/.gitignore
new file mode 100644
index 0000000..46f8223
--- /dev/null
+++ b/AT91SAM7S256/armdebug/.gitignore
@@ -0,0 +1,41 @@
+# Ignore tag
+MASTER-REPO_DO-NOT-DELETE
+*.lst
+*.objdump
+.DS_Store
+
+# Generally annoying things.
+*.[oa]
+*.pyc
+*.bin
+*.elf
+*.rxe
+*.map
+*.orig
+*.log
+*~
+*.swp
+\#*\#
+.\#*
+
+# Python distutils creates this when building.
+pynxt/build/
+
+# XCode build stuff
+FantomModule/build/
+*mode1v3
+*pbxuser
+
+# SCons cruft
+.sconsign.dblite
+.sconf_temp
+build_flags.py
+
+# Precommit hooks drop a commit.msg file if they fail.
+commit.msg
+
+# The option-cache
+scons.options
+
+# pyfantom related
+pyfantom.py
diff --git a/AT91SAM7S256/armdebug/.project b/AT91SAM7S256/armdebug/.project
new file mode 100644
index 0000000..15b12fc
--- /dev/null
+++ b/AT91SAM7S256/armdebug/.project
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>armdebug</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ </buildSpec>
+ <natures>
+ </natures>
+</projectDescription>
diff --git a/AT91SAM7S256/armdebug/AUTHORS b/AT91SAM7S256/armdebug/AUTHORS
new file mode 100644
index 0000000..169c2b6
--- /dev/null
+++ b/AT91SAM7S256/armdebug/AUTHORS
@@ -0,0 +1,6 @@
+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>
+Tat Chee Wan <tcwan (at) cs.usm.my>
diff --git a/AT91SAM7S256/armdebug/COPYING b/AT91SAM7S256/armdebug/COPYING
new file mode 100644
index 0000000..86fae60
--- /dev/null
+++ b/AT91SAM7S256/armdebug/COPYING
@@ -0,0 +1,9 @@
+The armdebug project is dual licensed.
+
+You can either use the GNU GPLv2 license in GNU-GPLv2.txt,
+or else the "LEGO Open Source License" in LEGO_Open_Source_License.doc
+to redistribute the code.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
diff --git a/AT91SAM7S256/armdebug/Debugger/_c_arm_macros.h b/AT91SAM7S256/armdebug/Debugger/_c_arm_macros.h
new file mode 100644
index 0000000..025542e
--- /dev/null
+++ b/AT91SAM7S256/armdebug/Debugger/_c_arm_macros.h
@@ -0,0 +1,88 @@
+/** @file _c_arm_macros.h
+ * @brief Define macros to support shared C and ASM headers
+ *
+ */
+
+/* Copyright (C) 2010 the NxOS developers
+ *
+ * Module Developed by: TC Wan <tcwan@cs.usm.my>
+ *
+ * Thanks to Bartli (forum post @ embdev.net ARM programming with GCC/GNU tools forum)
+ *
+ * See AUTHORS for a full list of the developers.
+ *
+ * See COPYING for redistribution license
+ *
+ */
+
+#ifndef __C_ARM_MACROS__
+#define __C_ARM_MACROS__
+
+
+#ifdef __ASSEMBLY__
+
+#define NULL 0x0
+#define FALSE 0
+#define TRUE ~FALSE
+
+#define TYPEDEF @
+#define FUNCDEF @
+
+ .set last_enum_value, 0
+ .macro enum_val name
+ .equiv \name, last_enum_value
+ .set last_enum_value, last_enum_value + 1
+ .endm
+
+#define ENUM_BEGIN .set last_enum_value, 0
+
+#define ENUM_VAL(name) enum_val name
+#define ENUM_VALASSIGN(name, value) \
+ .set last_enum_value, value ;\
+ enum_val name
+#define ENUM_END(enum_name)
+
+#else /* C Defines */
+/** Macro to control typedef generation
+ *
+ */
+#define TYPEDEF typedef
+
+/** Macro to control extern generation
+ *
+ */
+#ifndef FUNCDEF
+#define FUNCDEF extern
+#endif
+
+/** Macro to control typedef enum generation
+ *
+ */
+#define ENUM_BEGIN typedef enum {
+
+/** Macro to specify enum instance (auto value assignment)
+ *
+ */
+#define ENUM_VAL(name) name,
+
+/** Macro to control enum specification and value assignment
+*
+*/
+#define ENUM_VALASSIGN(name, value) name = value,
+
+/** Macro to control enum named type generation
+ *
+ */
+#define ENUM_END(enum_name) } enum_name;
+
+#endif
+
+/* Example of how to use the ENUM definition macros
+ENUM_BEGIN
+ENUM_VAL(INIT)
+ENUM_VAL(RESET)
+ENUM_VAL(CONFIGURED)
+ENUM_END(enum_label)
+*/
+
+#endif /* __C_ARM_MACROS__ */
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_comm.S b/AT91SAM7S256/armdebug/Debugger/debug_comm.S
new file mode 100644
index 0000000..b743f72
--- /dev/null
+++ b/AT91SAM7S256/armdebug/Debugger/debug_comm.S
@@ -0,0 +1,1025 @@
+/** @file debug_comm.S
+ * @brief GDB Server communications support routines
+ *
+ */
+
+/* Copyright (C) 2007-2011 the NxOS developers
+ *
+ * Module Developed by: TC Wan <tcwan@cs.usm.my>
+ *
+ * See AUTHORS for a full list of the developers.
+ *
+ * See COPYING for redistribution license
+ *
+ */
+
+
+/* #define __NXOS__ */ /* Defined externally in SConstruct */
+
+#define __ASSEMBLY__
+#include "debug_macros.h"
+#include "debug_stub.h"
+#include "debug_internals.h"
+#include "debug_comm.h"
+
+.bss
+.align 4
+
+debug_InCommBuf:
+ .space USB_BUFSIZE,0
+debug_OutCommBuf:
+ .space USB_BUFSIZE,0
+
+debug_msgRxBufPtr:
+ .word 0x0
+debug_msgTxBufPtr:
+ .word 0x0
+
+debug_msgRxBuf_AppendPtr:
+ .word 0x0
+debug_msgTxBuf_AppendPtr:
+ .word 0x0
+
+ .equ RXAPPENDPTR_OFFSET, (debug_msgRxBuf_AppendPtr - debug_msgRxBufPtr)
+ .equ TXAPPENDPTR_OFFSET, (debug_msgTxBuf_AppendPtr - debug_msgTxBufPtr)
+
+debug_segmentRxNum: /* Current Rx Segment Number */
+ .word 0x0
+
+#ifndef __NXOS__
+debug_nxtMsgLength: /* NXT Firmware Received Message Length */
+ .word 0x0
+
+debug_nxtCommChannel:
+ .word 0x0
+
+ .equ NXTCOMMCHANNEL_OFFSET, (debug_nxtCommChannel - debug_nxtMsgLength)
+
+#endif
+
+.data
+.align 4
+
+nxt_commcmd_header:
+ .byte NXT_GDBMSG_TELEGRAMTYPE, 0x00, 0x00 /* padded to 3 bytes */
+
+hex2char_lut:
+ .ascii "0123456789ABCDEF"
+
+/* Macros
+ */
+
+
+/* _hex2char_lut
+ * Internal routine to intialize the LUT address pointer
+ */
+ .macro _hex2char_lut addrptr
+ ldr \addrptr, =hex2char_lut
+ .endm
+
+/* _hex2char_cont
+ * Internal routine that assumes that the LUT has been loaded.
+ * This macro accepts a byte sized hex value as a parameter register(7:0) and returns the
+ * ASCII equivalent in in the same register(7:0)
+ * The second parameter is the LUT address pointer register to use (assumed to be initialized)
+ * WARNING: Assumes that the value in register is sanity checked before invoking macro
+ */
+ .macro _hex2char_cont reg, addrptr
+ ldrb \reg, [\addrptr, \reg]
+ .endm
+
+/* _hex2char
+ * This macro accepts a byte sized hex value as a parameter register(7:0) and returns the
+ * ASCII equivalent in in the same register(7:0)
+ * The second parameter is the LUT address pointer register to use (register content is destroyed)
+ * WARNING: Assumes that the value in register is sanity checked before invoking macro
+ */
+ .macro _hex2char reg, addrptr
+ _hex2char_lut \addrptr
+ _hex2char_cont \reg, \addrptr
+ .endm
+
+/* _char2hex
+ * This macro accepts an ASCII char as a parameter register(7:0) and returns the
+ * equivalent byte sized hex value in in the same register(7:0)
+ * WARNING: Assumes that the char in register is a valid hex char before invoking macro
+ */
+ .macro _char2hex reg
+ cmp \reg, #'A' /* If Alpha */
+ bichs \reg, \reg, #ASCII_LOWER2UPPER_MASK /* Convert to Uppercase */
+ subhs \reg, \reg, #7 /* Adjustment to allow for subtraction with 0x30 */
+ sub \reg, \reg, #0x30 /* get final hex value */
+ .endm
+
+
+.code 32
+.text
+.align 4
+
+
+/* Utility Routines
+ * GDB requires command parameters to be specified as Big Endian values.
+ * However, the read/write register command expect the register contents to be specified in target byte order.
+ * Hence we need both versions of multibyte conversion routines for word sized values.
+ */
+
+/* hex2char
+ * This routine accepts a byte sized hex value in R0(7:0) and returns the
+ * ASCII equivalent in R0(7:0)
+ */
+ .global hex2char
+
+hex2char:
+ stmfd sp!, {r1,lr}
+ and r0, #NIBBLE0 /* make sure that input is sane */
+ _hex2char r0, r1
+ ldmfd sp!, {r1,pc}
+
+/* char2hex
+ * This routine accepts an ASCII character in R0(7:0) and returns the
+ * equivalent byte sized hex value in R0(7:0).
+ * It accepts lowercase and uppercase ASCII Hex char inputs.
+ * Invalid inputs return -1 as the value
+* On entry:
+ * R0: ASCII character
+ * On exit:
+ * R0: Hex value
+ */
+ .global char2hex
+
+char2hex:
+ and r0, r0, #BYTE0 /* make sure that input is sane */
+ cmp r0, #'0'
+ blo char2hex_error
+ cmp r0, #'9'
+ bls perform_char2hex
+ cmp r0, #'A'
+ blo char2hex_error
+ cmp r0, #'F'
+ bls perform_char2hex
+ cmp r0, #'a'
+ blo char2hex_error
+ cmp r0, #'f'
+ bhi char2hex_error
+ /* Validated Hex Char */
+perform_char2hex:
+ _char2hex r0 /* Return hex value in R0 */
+ bx lr
+
+char2hex_error:
+ mov r0, #-1 /* Set Return value to Error value */
+ bx lr
+
+/* byte2ascii_cont
+ * (Shared routine, does not perform sanity checks)
+ * On entry:
+ * R0: ASCII buffer pointer
+ * R1[7:0]: byte value
+ * On exit:
+ * R0: Address of next empty char slot in buffer
+ * R1: Destroyed
+ *
+ * This routine accepts an ASCII buffer pointer in R0 and a byte value in R1,
+ * and stores the ASCII equivalent byte value in the buffer pointed to by R0.
+ * Note: On return, R0 points to next empty char slot in buffer
+ */
+byte2ascii_cont:
+ stmfd sp!, {r2,r3,r4, lr}
+ lsl r2, r1, #24 /* Keep copy of input byte value R1[7:0], shifted to MSB R2[31:24] */
+ mov r4, #2 /* Loop counter */
+ _hex2char_lut r3 /* initialize LUT pointer */
+1: ror r2, r2, #28 /* Rotate MSNibble R2[31:28] into LSNibble position R2[3:0] */
+ and r1, r2, #NIBBLE0 /* Mask out everything else, store Nibble in R1 */
+ _hex2char_cont r1, r3 /* Convert nibble to ASCII char */
+ strb r1, [r0], #1
+ subs r4, r4, #1 /* decrement loop counter */
+ bne 1b
+ ldmfd sp!, {r2,r3,r4, pc}
+
+/* byte2ascii
+ * On entry:
+ * R0: ASCII buffer pointer
+ * R1[7:0]: Byte value
+ * On exit:
+ * R0: Address of next empty char slot in buffer
+ * R1: Original Address of Buffer
+ *
+ * This routine accepts an ASCII buffer pointer in R0 and a byte value in R1,
+ * and stores the ASCII equivalent byte value in the buffer pointed to by R0.
+ * Note: On return, R0 points to the next empty char slot in buffer
+ */
+ .global byte2ascii
+
+byte2ascii:
+ stmfd sp!, {r0, lr} /* Keep ASCII buffer pointer */
+ and r1, #BYTE0 /* sanitize input */
+ bl byte2ascii_cont
+ ldmfd sp!, {r1, pc} /* return original string pointer in R1 */
+
+/* halfword2ascii_be
+ * Big Endian version of halfword2ascii conversion routine
+ * On entry:
+ * R0: ASCII buffer pointer
+ * R1[15:0]: Halfword value
+ * On exit:
+ * R0: Address of next empty char slot in buffer
+ * R1: Original Address of Buffer
+ *
+ * This routine accepts an ASCII buffer pointer in R0 and a halfword value in R1,
+ * and stores the ASCII equivalent halfword value in the buffer pointed to by R0.
+ * Note: On return, R0 points to the next empty char slot in buffer
+ */
+ .global halfword2ascii_be
+halfword2ascii_be:
+ stmfd sp!, {r0,r2,r3, lr} /* Keep ASCII buffer pointer */
+ mov r3, #2 /* Loop Counter */
+ mov r2, r1, lsl #16 /* copy of input halfword value R1[15:0], shifted to MSH R2[31:16] */
+ b _conv_byte2ascii_be /* goto Byte conversion loop */
+
+/* halfword2ascii_le
+ * Little Endian version of halfword2ascii conversion routine
+ * On entry:
+ * R0: ASCII buffer pointer
+ * R1[15:0]: Halfword value
+ * On exit:
+ * R0: Address of next empty char slot in buffer
+ * R1: Original Address of Buffer
+ *
+ * This routine accepts an ASCII buffer pointer in R0 and a halfword value in R1,
+ * and stores the ASCII equivalent halfword value in the buffer pointed to by R0.
+ * Note: On return, R0 points to the next empty char slot in buffer
+ */
+ .global halfword2ascii_le
+halfword2ascii_le:
+ stmfd sp!, {r0,r2,r3, lr} /* Keep ASCII buffer pointer */
+ mov r3, #2 /* Loop Counter */
+ b _conv_byte2ascii_le /* goto Byte conversion loop */
+
+
+/* word2ascii_be
+ * Big Endian version of word2ascii conversion routine
+ * On entry:
+ * R0: ASCII buffer pointer
+ * R1[31:0]: Word value
+ * On exit:
+ * R0: Address of next empty char slot in buffer
+ * R1: Original Address of Buffer
+ *
+ * This routine accepts an ASCII buffer pointer in R0 and a word value in R1,
+ * and stores the ASCII equivalent word value in the buffer pointed to by R0.
+ * Note: On return, R0 points to the next empty char slot in buffer
+ */
+ .global word2ascii_be
+word2ascii_be:
+ stmfd sp!, {r0,r2,r3, lr} /* Keep ASCII buffer pointer */
+ mov r2, r1 /* copy of input word value R1[31:0] */
+ mov r3, #4 /* Loop Counter */
+
+ /* Fall through to byte coversion loop */
+
+
+/* Big Endian Multibyte Convert: Rotate then convert */
+_conv_byte2ascii_be:
+ ror r2, r2, #24 /* Rotate MSB R2[31:24] into LSB position R2[7:0] */
+ and r1, r2, #BYTE0 /* Copy byte value in R2[7:0] into R1 */
+ bl byte2ascii_cont /* R0: next ASCII buffer location pointer, R1: destroyed */
+ subs r3, r3, #1
+ bne _conv_byte2ascii_be
+ ldmfd sp!, {r1,r2,r3, pc}
+
+/* word2ascii_le
+ * Little Endian version of word2ascii conversion routine
+ * On entry:
+ * R0: ASCII buffer pointer
+ * R1[31:0]: Word value
+ * On exit:
+ * R0: Address of next empty char slot in buffer
+ * R1: Original Address of Buffer
+ *
+ * This routine accepts an ASCII buffer pointer in R0 and a word value in R1,
+ * and stores the ASCII equivalent word value in the buffer pointed to by R0.
+ * Note: On return, R0 points to the next empty char slot in buffer
+ */
+ .global word2ascii_le
+word2ascii_le:
+ stmfd sp!, {r0,r2,r3, lr} /* Keep ASCII buffer pointer */
+ mov r2, r1 /* copy of input word value R1[31:0] */
+ mov r3, #4 /* Loop Counter */
+
+ /* Fall through to byte coversion loop */
+
+/* Little Endian Multibyte Convert: Convert then rotate */
+_conv_byte2ascii_le:
+ and r1, r2, #BYTE0 /* Copy byte value in R2[7:0] into R1 */
+ bl byte2ascii_cont /* R0: next ASCII buffer location pointer, R1: destroyed */
+ ror r2, r2, #8 /* Rotate LSB+1 R2[15:8] into LSB position R2[7:0] */
+ subs r3, r3, #1
+ bne _conv_byte2ascii_le
+ ldmfd sp!, {r1,r2,r3, pc}
+
+
+/* ascii2hex_varlen_be
+ * Big Endian version of ascii2hex_varlen conversion routine
+ * (There is no Little Endian Version)
+ * On entry:
+ * R0: ASCII buffer pointer
+ * On exit:
+ * R0: Hex value
+ * R1: Address of next char slot in buffer
+ *
+ * This routine accepts an ASCII buffer pointer in R0,
+ * and returns the hex value in R0 for up to 8 Hex characters.
+ * Note: On return, R1 points to the ASCII buffer location after the hex value chars.
+ */
+ .global ascii2hex_varlen_be
+
+ascii2hex_varlen_be:
+ stmfd sp!, {r2,r3, lr}
+ mov r3, #CMD_REG_REGPARAMLEN /* Set max count to 8 (Max Register size) */
+ mov r1, r0 /* Use R1 as ASCII buffer pointer */
+ mov r2, #0 /* Initialize Cummulative Results */
+2: ldrb r0, [r1] /* Load ASCII char for Hex Value */
+ bl char2hex /* on return, hex value in R0, -1 for error */
+ cmp r0, #-1
+ beq _exit_ascii2hex_varlen
+ orr r2, r0, r2, lsl #4 /* combined byte value */
+ subs r3, r3, #1 /* Decrement Counter */
+ add r1, r1, #1 /* Go to next char slot */
+ bne 2b
+_exit_ascii2hex_varlen:
+ mov r0, r2 /* Return results in R0 */
+ ldmfd sp!, {r2,r3, pc}
+
+
+/* ascii2byte
+ * On entry:
+ * R0: ASCII buffer pointer
+ * On exit:
+ * R0[7:0]: Byte value
+ * R1: Address of next char slot in buffer
+ *
+ * This routine accepts an ASCII buffer pointer in R0,
+ * and returns the byte value in R0[7:0].
+ * Note: On return, R1 points to the ASCII buffer location after the current 2 chars.
+ * WARNING: This routine assumes that the input buffer was sanitized and contains valid Hex chars,
+ * otherwise it will return invalid results.
+ */
+ .global ascii2byte
+
+ascii2byte:
+ stmfd sp!, {r2, lr}
+ mov r1, r0 /* Use R1 as ASCII buffer pointer */
+ ldrb r0, [r1], #1 /* Load ASCII char for MSN */
+ bl char2hex /* on return, hex value in R0, -1 for error (ignored) */
+ mov r2, r0, lsl #4 /* Intermediate Results register */
+ ldrb r0, [r1], #1 /* Load ASCII char for LSN */
+ bl char2hex /* on return, hex value in R0, -1 for error (ignored) */
+ orr r0, r2, r0 /* combined byte value */
+ ldmfd sp!, {r2, pc}
+
+/* ascii2halfword_be
+ * Big Endian version of ascii2halfword conversion routine
+ * On entry:
+ * R0: ASCII buffer pointer
+ * On exit:
+ * R0[15:0]: Halfword value
+ * R1: Address of next char slot in buffer
+ *
+ * This routine accepts an ASCII buffer pointer in R0,
+ * and returns the Halfword value in R0[15:0].
+ * Note: On return, R1 points to the ASCII buffer location after the current 4 chars.
+ * WARNING: This routine assumes that the input buffer was sanitized and contains valid Hex chars,
+ * otherwise it will return invalid results.
+ */
+ .global ascii2halfword_be
+
+ascii2halfword_be:
+ stmfd sp!, {r2,r3, lr}
+ mov r3, #2 /* Loop counter */
+ b _conv_ascii2byte_be
+
+/* ascii2halfword_le
+ * Little Endian version of ascii2halfword conversion routine
+ * On entry:
+ * R0: ASCII buffer pointer
+ * On exit:
+ * R0[15:0]: Halfword value
+ * R1: Address of next char slot in buffer
+ *
+ * This routine accepts an ASCII buffer pointer in R0,
+ * and returns the Halfword value in R0[15:0].
+ * Note: On return, R1 points to the ASCII buffer location after the current 4 chars.
+ * WARNING: This routine assumes that the input buffer was sanitized and contains valid Hex chars,
+ * otherwise it will return invalid results.
+ */
+ .global ascii2halfword_le
+
+ascii2halfword_le:
+ stmfd sp!, {r2,r3, lr}
+ mov r3, #2 /* Loop counter */
+ b _conv_ascii2byte_le
+
+
+/* ascii2word_be
+ * Big Endian version of ascii2word conversion routine
+ * On entry:
+ * R0: ASCII buffer pointer
+ * On exit:
+ * R0[31:0]: Word value
+ * R1: Address of next char slot in buffer
+ *
+ * This routine accepts an ASCII buffer pointer in R0,
+ * and returns the word value in R0[31:0].
+ * Note: On return, R1 points to the ASCII buffer location after the current 8 chars.
+ * WARNING: This routine assumes that the input buffer was sanitized and contains valid Hex chars,
+ * otherwise it will return invalid results.
+ */
+ .global ascii2word_be
+
+ascii2word_be:
+ stmfd sp!, {r2,r3, lr}
+ mov r3, #4 /* Loop counter */
+
+ /* Fall through to byte coversion loop */
+
+_conv_ascii2byte_be:
+ teq r0, #0
+ beq _exit_conv_ascii2byte_be /* exit if NULL pointer in R0 */
+ mov r2, #0 /* Initialize Cummulative value */
+2: bl ascii2byte
+ orr r2, r0, r2, lsl #8 /* Merge current byte with cummulative value */
+ mov r0, r1 /* Copy next char pointer to R0 for next byte */
+ subs r3, r3, #1
+ bne 2b
+ mov r0, r2 /* Copy it to R0 as return value */
+
+_exit_conv_ascii2byte_be:
+ ldmfd sp!, {r2,r3, pc} /* return hex value in R0 */
+
+/* ascii2word_le
+ * Litle Endian version of ascii2word conversion routine
+ * On entry:
+ * R0: ASCII buffer pointer
+ * On exit:
+ * R0[31:0]: Word value
+ * R1: Address of next char slot in buffer
+ *
+ * This routine accepts an ASCII buffer pointer in R0,
+ * and returns the word value in R0[31:0].
+ * Note: On return, R1 points to the ASCII buffer location after the current 8 chars.
+ * WARNING: This routine assumes that the input buffer was sanitized and contains valid Hex chars,
+ * otherwise it will return invalid results.
+ */
+ .global ascii2word_le
+
+ascii2word_le:
+ stmfd sp!, {r2,r3, lr}
+ mov r3, #4 /* Loop counter */
+
+ /* Fall through to byte coversion loop */
+
+_conv_ascii2byte_le:
+ teq r0, #0
+ beq _exit_conv_ascii2byte_le /* exit if NULL pointer in R0 */
+ push {r3} /* Need to keep couter for final value adjustment */
+ mov r2, #0 /* Initialize Cummulative value */
+2: bl ascii2byte
+ orr r2, r0, r2, ror #8 /* Merge current byte with cummulative value */
+ mov r0, r1 /* Copy next char pointer to R0 for next byte */
+ subs r3, r3, #1
+ bne 2b
+ /* Cummulative value done, need to rotate it into the correct position for return value */
+ pop {r3} /* retrieve counter */
+ rsb r3, r3, #5 /* 5 - count */
+ lsl r3, r3, #3 /* [(5-count) x 8] bits to rotate */
+ mov r0, r2, ror r3 /* Copy it to R0 as return value */
+
+_exit_conv_ascii2byte_le:
+ ldmfd sp!, {r2,r3, pc} /* return hex value in R0 */
+
+
+
+
+/* Debugger Communications Routines
+ * It does not make sense to pass information from the Debugger Module to the Comm. link one character
+ * at a time, especially if we're not using a native serial interface (e.g., EIA-232). Consequently
+ * a Message interface has been defined. This can still call getChar() and putChar() subroutines
+ * if so desired, but it'll be a purely internal matter.
+ *
+ * Message Format
+ * Since we need to use EP1&2 (Bulk channels) to communicate with the PC Host, the messages should
+ * follow the NXT Direct Commands message structure (this will allow for interoperability with NXT Firmware
+ * in addition to NxOS). The maximum length of any USB communications via the Bulk channel is 64 bytes.
+ * There is a one byte Telegram Type field which identifies the type of telegram, followed by the
+ * Telegram header and actual message.
+ *
+ * The LEGO Mindstorms Communications Protocol Direct Commands GDB Message format (including all headers)
+ * is as follows:
+ *
+ * GDB Command
+ * ===========
+ * Byte 0: Telegram Type Field (0x8d Direct Command, No response required) | NXT Msg Header
+ * Byte 1: Segment No (1-255, 0: Last Segment; limit is MSG_NUMSEGMENTS) |
+ * Byte 2: Telegram Size (Len of USB Buffer - 3, max is MSG_SEGMENTSIZE) |
+ * Byte 3-N: Message data | GDB Command
+ *
+ * The GDB Command (of size M) has the following format:
+ * Offset 0: '+'/'-' Command Received Status (Optional)
+ * Offset 1/0: '$'
+ * Offset 2/1: GDB Command char
+ * Offset 3 - (M-4): Command packet info
+ * Offset M-3: '#'
+ * Offset M-2: MSB of Checksum
+ * Offset M-1: LSB of Checksum
+ *
+ * To be safe, we assume that the Command Received Status is always sent by the GDB server. Therefore,
+ * The maximum size of a GDB Command packet is MSGBUF_SIZE - 5 ('+'/'-', '$', '#', 2 byte checksum)
+ *
+ * GDB Response
+ * ============
+ * Byte 0: Telegram Type Field (0x8d Direct Command, No response required) | NXT Msg Header
+ * Byte 1: Segment No (1-255, 0: Last Segment; limit is MSG_NUMSEGMENTS) |
+ * Byte 2: Telegram Size (Len of USB Buffer - 3, max is MSG_SEGMENTSIZE) |
+ * Byte 3-N: Message data | GDB Response
+ *
+ * The GDB Retransmission Request has the following format:
+ * Offset 0: '-' Command Received Status
+ *
+ * The GDB Response (of size M) has the following format:
+ * Offset 0: '+' Command Received Status
+ * Offset 1: '$'
+ * Offset 2 - (M-4): Response packet info
+ * Offset M-3: '#'
+ * Offset M-2: MSB of Checksum
+ * Offset M-1: LSB of Checksum
+ *
+ * The maximum size of a GDB Response packet is MSGBUF_SIZE - 5 ('+', '$', '#', 2 byte checksum)
+ *
+ * Note: The Telegram Size is the actual size of the Message Data portion
+ * (i.e., excludes the three header bytes, includes the GDB Command/Response Packet checksum bytes
+ * in the last segment)
+ */
+
+ .global dbg__comm_init
+/* dbg__comm_init
+ * Initialize communications channel.
+ * On Entry:
+ * R0: MSG Rx Buf Pointer
+ * R1: MSG Tx Buf Pointer
+ */
+
+dbg__comm_init:
+ stmfd sp!, {lr}
+ ldr r2, =debug_msgRxBufPtr
+ stmia r2!, {r0, r1} /* debug_msgRxBufPtr and debug_msgTxBufPtr */
+ stmia r2!, {r0, r1} /* debug_msgRxBuf_AppendPtr and debug_msgTxBuf_AppendPtr */
+ bl _dbg__comm_readbuf_reset
+#ifndef __NXOS__
+ ldr r1, =debug_nxtMsgLength
+ mov r0, #0
+ str r0, [r1, #NXTCOMMCHANNEL_OFFSET] /* Clear NXT Channel on INIT */
+#endif
+ ldmfd sp!, {pc}
+
+_dbg__comm_readbuf_reset:
+#ifdef __NXOS__
+ stmfd sp!, {lr}
+ ldr r0, =debug_InCommBuf
+ mov r1, #USB_BUFSIZE
+ ldr r2, =nx_usb_read
+ mov lr, pc
+ bx r2
+ ldmfd sp!, {pc}
+#else
+ ldr r1, =debug_nxtMsgLength
+ mov r0, #0
+ str r0, [r1] /* Clear NXT Received Message Length */
+ bx lr
+
+ .global dbg__copyNxtDebugMsg
+/* dbg__copyNxtDebugMsg
+ * Copy NXT Firmware Debug Message to our own Buffers, indicate Msg Received status.
+ * On Entry:
+ * R0: NXT Input Buf Pointer
+ * R1: NXT Communications Channel Enum (CmdBit)
+ * R2: NXT Raw Message Length
+ * On Exit:
+ * R0-R3: Destroyed
+ */
+dbg__copyNxtDebugMsg:
+ ldr r3, =debug_nxtMsgLength
+ str r1, [r3, #NXTCOMMCHANNEL_OFFSET]
+ str r2, [r3]
+ ldr r1, =debug_InCommBuf
+/* FIXME: We can probably save some cycles and buffer space by using the
+ * NXT comms buffer specified in R0 directly without copying to internal buffers
+ */
+ _dbg_memcpy r1, r0, r2, r3 /* r3: scratch register */
+ bx lr
+#endif
+
+/* _dbg_reset_msgTxBuf_AppendPtr
+ * Internal variable to reset pointers.
+ * On Exit:
+ * R0: debug_msgTxBuf_AppendPtr
+ * R1: destroyed
+ */
+_dbg_reset_msgTxBuf_AppendPtr:
+ ldr r1, =debug_msgTxBufPtr /* Should not be modified */
+ ldr r0, [r1]
+ str r0, [r1, #TXAPPENDPTR_OFFSET]
+ mov pc, lr
+
+/* _dbg__commHasMsg
+ * Internal Segment Reassembly Routine.
+ * On exit:
+ * r0: !0: (Availale Telegram Message Size), 0: no incoming message/segment
+ * r1: message segment number
+ */
+_dbg__commHasMsg:
+ stmfd sp!, {lr}
+#ifdef __NXOS__
+ ldr r2, =nx_usb_data_read
+ mov lr,pc
+ bx r2 /* Number of bytes read in R0 */
+ /* Note: The return value in R0 is the Comm Buffer Size, includes NXT Direct Command Header */
+#else
+ ldr r0, =debug_nxtMsgLength
+ ldr r0, [r0] /* R0 contains the Comm Buffer Size, including the NXT Direct Command Header */
+#endif
+
+ ldr r2, =debug_InCommBuf
+ ldrb r1, [r2, #NXT_MSG_TELEGRAMTYPE_OFFSET]
+ cmp r1, #NXT_GDBMSG_TELEGRAMTYPE
+ bne invalid_CommMsg /* Invalid telegram type, ignore */
+
+ ldrb r1, [r2, #NXT_MSG_TELEGRAMSIZE_OFFSET]
+ sub r0, r0, r1 /* Comm Buffer Size - Telegram Size = 3 (header size) */
+ cmp r0, #NXT_GDBMSG_START /* Start offset is equal to header size */
+ bne invalid_CommMsg /* Invalid Message Length, ignore */
+
+ mov r0, r1 /* Telegram Message Size */
+ ldrb r1, [r2, #NXT_MSG_SEGNUM_OFFSET]
+ b _exit_dbg__commHasMsg
+
+invalid_CommMsg:
+ mov r0, #0
+_exit_dbg__commHasMsg:
+ ldmfd sp!, {pc}
+
+/* _copy_msg_from_commbuf
+ * Internal Comm buffer copy routine, handles segment reassembly.
+ * On entry:
+ * r0: number of bytes to copy
+ * r1: segment number
+ * On exit:
+ * r0: cummulative message length
+ * r1: segment number
+ * r2, r3: Destroyed
+ */
+_copy_msg_from_commbuf:
+ stmfd sp!, {r1,r4,r5,r6,lr}
+ movs r4, r0
+ beq _exit_copy_msg_from_commbuf
+
+ ldr r6, =debug_msgRxBufPtr /* Address of Pointers */
+ ldr r5, [r6] /* Rx buffer Start Address */
+ ldr r2, [r6, #RXAPPENDPTR_OFFSET] /* Append Pointer */
+
+ sub r3, r2, r5 /* r3: current length of message */
+ add r3, r3, r4 /* new cummulative length of message */
+ cmp r3, #MSGBUF_SIZE
+ movhi r4, #0 /* Buffer overflow! */
+ strhi r5, [r6, #RXAPPENDPTR_OFFSET] /* Reset AppendPtr to beginning of Rx Buffer */
+ bhi _exit_copy_msg_from_commbuf
+
+ ldr r3, =debug_InCommBuf
+ add r3, r3, #NXT_GDBMSG_START
+ _dbg_memcpy r2, r3, r4, r0 /* r2 updated to point to next empty char slot in Rx buffer */
+ sub r4, r2, r5 /* r4: cummulative length of message */
+
+ /* Update debug_msgRxBuf_AppendPtr */
+ teq r1, #0 /* Check if this is last segment (segment 0) */
+ streq r5, [r6, #RXAPPENDPTR_OFFSET] /* Reset AppendPtr to beginning of Rx Buffer if so */
+ strne r2, [r6, #RXAPPENDPTR_OFFSET] /* Otherwise, update Append Pointer to receive next segment */
+
+_exit_copy_msg_from_commbuf:
+ bl _dbg__comm_readbuf_reset /* Next Comm telegram transaction */
+ mov r0, r4 /* Return cummulative message length in R0 */
+ ldmfd sp!, {r1,r4,r5,r6,pc} /* Return segment number in R1 */
+
+
+/* _msgbuf_checksum
+ * Internal routine to calculate checksum character buffer.
+ * On entry:
+ * r0: pointer to character buffer to checksum (assume ASCIIZ terminated)
+ * On exit:
+ * r0: pointer to character buffer after ASCIIZ
+ * r1: checksum (8-bit binary)
+ * r2: message length
+ * r3: destroyed
+ */
+_msgbuf_checksum:
+ mov r1, #0 /* clear checksum */
+ mov r2, #0 /* clear length */
+1: ldrb r3, [r0], #1 /* Iterate through buffer */
+ add r1, r1, r3 /* cummulative sum of char */
+ teq r3, #0
+ addne r2, r2, #1 /* increment message length */
+ bne 1b /* until ASCIIZ found */
+ and r1, #BYTE0 /* Modulo 256 */
+ mov pc, lr
+
+ .global dbg__getDebugMsg
+/* dbg__getDebugMsg
+ * Retrieve pending Debugger Message if available (Non-Blocking).
+ * On entry:
+ * No parameters (assume pointers were initialized previously using dbg__comm_init)
+ * On exit:
+ * r0: >0 = Valid GDB Message Length (incl '$', excluding '#' and checksum),
+ * 0 = no valid message (yet), -1 = error
+ * r1: GDB Message Buffer Pointer (incl '$', excluding '#' and checksum)
+ * r2, r3: Destroyed
+ * Note: If GDB Message were returned, it is ASCIIZ terminated, does not include '#' and checksum
+ */
+dbg__getDebugMsg:
+ stmfd sp!, {r4,r5,lr}
+ bl _dbg__commHasMsg /* r0: message length, r1: segment number */
+ teq r0, #0
+ beq exit_dbg__getDebugMsg /* no new message, exit with R0 = 0 */
+
+ ldr r4, =debug_segmentRxNum
+ ldr r2, [r4] /* Get current Segment Number */
+ add r2, r2, #1 /* Expected Segment Number for comparison */
+ teq r1, #0
+ streq r1, [r4] /* Update current Segment Number with 0 since it is the last segment */
+ beq _hasMsg2Copy
+ cmp r1, #MSG_NUMSEGMENTS /* Segment Number < MSG_NUMSEGMENTS? */
+ bhs _invalid_segment
+ teq r1, r2 /* Valid Segment Number, check against Expected Segment Number */
+ beq _hasMsg2Copy /* Segment Number matches Expected Segment Number, update buffers */
+
+_invalid_segment:
+ bl _dbg__comm_readbuf_reset /* Invalid, Next Comm telegram transaction */
+ mov r0, #0 /* Reset Segment Number */
+ str r0, [r4] /* Update current Segment Number with 0 to prepare for new message */
+ b exit_dbg__getMsgError /* Exit with error */
+
+_hasMsg2Copy:
+ str r1, [r4] /* Update current Segment Number */
+ bl _copy_msg_from_commbuf /* r0: cummulative message length, r1: segment number */
+ teq r1, #0
+ movne r0, #0 /* Incomplete message, ignore for now */
+ bne exit_dbg__getDebugMsg /* Message not complete yet, exit */
+
+ /* Check for valid GDB message */
+ mov r4, r0 /* keep message length in R4, assume to be within MSGBUF_SIZE */
+ ldr r5, =debug_msgRxBufPtr
+ ldr r5, [r5] /* Rx buffer Start Address */
+
+/* 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 '+' */
+ addeq r5, r5, #1 /* Adjust Buffer Start Pointer (excl '+') */
+ subeq r4, r4, #1 /* Adjust Message Length */
+ beq 1b /* Skip all Packet Acknowledgements */
+
+ /* Note: Here we assume that we won't get a single ACK '+' or NAK '-' character message.
+ * If we do, it'll be flagged as an error
+ */
+ subs r2, r4, #MSGBUF_CHKSUMOFFSET /* Look for '#': Message Length - 3 = '#' offset */
+ blt exit_dbg__getMsgError /* Message Length is too short, exit with error */
+ ldrb r0, [r5, r2]
+ teq r0, #MSGBUF_CHKSUMCHAR
+ bne exit_dbg__getMsgError /* No checksum char '#', exit with error */
+
+ mov r1, #0
+ strb r1, [r5, r2] /* Zero out '#' char for checksum calc later */
+
+#ifdef CHECK_GDBSTARTCHAR
+ /* Checked in dbg__bkpt_waitCMD */
+ ldrb r0, [r5]
+ teq r0, #MSGBUF_STARTCHAR /* Look for '$' */
+ bne exit_dbg__getMsgError /* No start char '$', exit with error */
+#endif
+
+ add r0, r5, #1 /* Checksum packet data (excl '$') */
+ bl _msgbuf_checksum /* R2: length (excl '$'), R1: calculated checksum, R0: pointer to checksum in receive buffer */
+ mov r3, r1 /* Keep calculated checksum in R3 (R1 destroyed by ascii2byte) */
+ bl ascii2byte /* R0: received checksum, R1: address of next buffer location */
+ teq r0, r3 /* Compare calculated checksum in R3 against received checksum in R0 */
+ bne exit_dbg__getMsgError /* Checksums do not match, exit with error */
+
+ subeq r0, r4, #MSGBUF_CHKSUMOFFSET /* Update message length (incl '$') as return parameter */
+ add r2, r2, #1 /* expected message length (from _msgbuf_checksum) */
+ teq r0, r2
+ beq exit_dbg__getDebugMsg /* Valid length, return */
+
+exit_dbg__getMsgError:
+ mov r0, #MSGBUF_MSGERROR
+exit_dbg__getDebugMsg:
+ mov r1, r5 /* Return GDB Message Buffer Pointer in R1 */
+ ldmfd sp!, {r4,r5,pc}
+
+/* _dbg__sendCommMsg
+ * Internal send routine (interfaces with drivers).
+ * On entry:
+ * R0: Total Message Buffer length
+ * On exit:
+ R0: Tx Status (TRUE if data sent)
+ */
+_dbg__sendCommMsg:
+ stmfd sp!, {r4, lr}
+ mov r4, r0 /* Keep Comm Buffer length in R4 */
+#ifdef __NXOS__
+ /* Check USB bus status, transmit message if possible */
+ bl nx_usb_is_connected /* R0 = True if USB is ready */
+ cmp r0, #TRUE
+ bne _exit_dbg__sendCommMsg
+
+ /* Actual transmission (blocking) */
+ ldr r0, =debug_OutCommBuf /* data pointer parameter */
+ mov r1, r4 /* Comm buffer length */
+ bl nx_usb_write
+
+1: bl nx_usb_data_written /* R0 = True if data has been sent */
+ cmp r0, #TRUE
+ /* FIXME: implement timeout */
+ bne 1b /* Busy Wait Loop */
+#else
+ ldr r0, =debug_nxtCommChannel
+ ldr r0, [r0] /* Get Channel Enum */
+ teq r0, #BT_CMD_READY
+ beq _dbg__sendBTMsg
+ teq r0, #USB_CMD_READY
+ beq _dbg__sendUSBMsg
+ b _dbg__sendCommMsgFailed /* Channel Enum Doesn't Match, shouldn't happen? */
+
+_dbg__sendBTMsg:
+ /* NXT BT routines do not have any configuration checks */
+ ldr r0, =debug_OutCommBuf /* data pointer parameter */
+ mov r1, r4 /* BT Bytes to Send */
+ mov r2, r4 /* BT Message Size */
+ bl dBtSendMsg /* Send it via Bluetooth (complete message) */
+ mov r0, #TRUE /* Always flag Success */
+ b _exit_dbg__sendCommMsg
+
+_dbg__sendUSBMsg:
+ /* Check USB bus status, transmit message if possible */
+ bl dUsbIsConfigured /* R0: UByte status, TRUE / FALSE */
+ teq r0, #nxt_UBYTE_TRUE
+ bne _dbg__sendCommMsgFailed
+
+ /* Actual transmission (blocking) */
+ ldr r0, =debug_OutCommBuf /* data pointer parameter */
+ mov r1, r4 /* Comm buffer length */
+ bl dUsbWrite /* call NXT Firmware USB driver, return 0: done, !0: remaining chars */
+ teq r0, #0 /* Tx done if returned length is 0 */
+ moveq r0, #TRUE /* Convert NXT firmware return value to our Status (TRUE/FALSE) */
+ beq _exit_dbg__sendCommMsg
+#endif
+
+_dbg__sendCommMsgFailed:
+ mov r0, #FALSE
+
+_exit_dbg__sendCommMsg:
+ ldmfd sp!, {r4, pc}
+
+
+/* _copy_msg_to_commbuf
+ * Internal Comm buffer copy routine, handles segment fragmentation.
+ * On entry:
+ * r0: number of bytes to copy
+ * r1: segment number
+ * On exit:
+ * r0: cummulative message length
+ * r1: segment number
+ * r2, r3: Destroyed
+ */
+_copy_msg_to_commbuf:
+ stmfd sp!, {r1,r4,r5,r6,lr}
+ ldr r6, =debug_msgTxBufPtr /* Address of Pointers */
+ ldr r5, [r6, #TXAPPENDPTR_OFFSET] /* Retrieve Tx Append Pointer */
+
+ movs r4, r0
+ beq _exit_copy_msg_to_commbuf
+
+#ifdef CHECK_TXLEN
+ add r0, r4, #NXT_GDBMSG_START /* offset = header size */
+ cmp r0, #USB_BUFSIZE
+ bhi _exit_copy_msg_to_commbuf /* We let calling routine detect problem (segment number will increment) */
+#endif
+
+ /* Fill in Comm Message Header */
+ ldr r3, =debug_OutCommBuf
+ mov r2, #NXT_GDBMSG_TELEGRAMTYPE
+ strb r2, [r3], #1 /* Telegram type */
+ strb r1, [r3], #1 /* Segment Number */
+ strb r0, [r3], #1 /* Message Length */
+
+ mov r2, r5 /* Copy to R2 for updating */
+ mov r1, r4 /* actual GDB message fragment length (exclude Comm header) */
+ _dbg_memcpy r3, r2, r1, r0 /* This copies over the message fragment, r3, r2 updated */
+ mov r5, r2 /* Updated Tx Append Pointer, keep in R5 for now */
+
+ add r0, r4, #NXT_GDBMSG_START /* Total Comm Buffer Size for Tx (NXT_GDBMSG_START offset = header size) */
+ bl _dbg__sendCommMsg /* Common interface routine to commnuncations drivers */
+ cmp r0, #TRUE
+ ldrne r5, [r6, #TXAPPENDPTR_OFFSET] /* Tx failed, Retrieve Original Tx Append Pointer */
+ streq r5, [r6, #TXAPPENDPTR_OFFSET] /* Tx succeeded, Update Tx Append Pointer to new position */
+
+_exit_copy_msg_to_commbuf:
+ ldr r6, [r6] /* Retrieve Tx Buffer Start Address */
+ sub r0, r5, r6 /* Return calculated cummulative message length (R0) */
+ ldmfd sp!, {r1,r4,r5,r6,pc} /* Return segment number in R1 */
+
+ .global dbg__putDebugMsg
+/* dbg__putDebugMsg
+ * Sends Debugger Message from calling routine after appending checksum (Blocking) .
+ * On entry:
+ * No parameters (assume pointers were initialized previously using dbg__comm_init)
+ * On exit:
+ * r0: status (0: success, -1: error)
+ * Note: GDB Message to be sent must be ASCIIZ terminated, does not include '#' and checksum
+ * Response packets start with '+' followed by '$' (2 bytes prefix)
+ */
+dbg__putDebugMsg:
+ stmfd sp!, {r4,r5,lr}
+ /* Perform Checksum Calculation */
+ ldr r5, =debug_msgTxBufPtr /* R5: data structure base pointer */
+ ldr r4, [r5] /* Tx buffer Start Address */
+ str r4, [r5, #TXAPPENDPTR_OFFSET] /* Reset Tx buffer Append Pointer */
+ add r0, r4, #2 /* skip '+' and '$' */
+ bl _msgbuf_checksum /* R2: length (excl '+' and '$'), R1: calculated checksum, R0: pointer to checksum in tx buffer */
+
+#ifdef CHECK_TXLEN
+ add r2, r2, #2 /* r2: returned length from _msgbuf_checksum, added with prefix length */
+ sub r3, r0, r4 /* r3: calculated length from pointers (incl. prefix length) */
+ teq r2, r3
+ bne exit_dbg__putMsgError
+#endif
+
+ mov r3, #MSGBUF_CHKSUMCHAR
+ strb r3, [r0, #-1] /* Insert '#' */
+ bl byte2ascii /* On return, R0 points to location after checksum bytes, R1 is original pointer to checksum */
+ sub r4, r0, r4 /* R4 = Calculated total message length (incl '+' and '$', '#' and checksum bytes */
+ cmp r4, #MSG_SEGMENTSIZE /* If total message length > MSG_SEGMENTSIZE */
+ mov r1, #0 /* Initialize Segment Number = 0 (last segment) first */
+ mov r0, #0 /* Initial cummulative message length */
+ mov r5, #0 /* Previous cummulative message length */
+
+ /* We assume unsigned message lengths, so the arithmetic MUST NOT result in negative values */
+_cont_putMsg:
+ cmp r4, r0
+ movls r0, #0 /* R0: Exit status (success) */
+ bls exit_dbg__putDebugMsg /* If Total message length (r4) <= Cummulative message length (r0), we're done */
+ add r2, r0, #MSG_SEGMENTSIZE /* R2: calculate new Max cummulative message length */
+ cmp r4, r2 /* Check total message length (R4) against new Max cummulative message length (R2) */
+ subls r0, r4, r0 /* if total message length (R4) <= new Max cummulative message length (R2), send remainder */
+ movls r1, #0 /* Flag as last segment (Segment Number = 0) */
+ movhi r0, #MSG_SEGMENTSIZE /* else send MSG_SEGMENTSIZE bytes */
+ addhi r1, r1, #1 /* Increment Segment Number */
+ cmp r1, #MSG_NUMSEGMENTS
+ bhs exit_dbg__putMsgError /* If Segment Number >= MSG_NUMSEGMENTS, flag error */
+ bl _copy_msg_to_commbuf /* R0: cummulative message length, R1: segment number */
+ teq r5, r0 /* Check if we managed to transmit the previous message */
+ beq exit_dbg__putMsgError /* No, flag error */
+ movne r5, r0 /* Update previous cummulative message length */
+ b _cont_putMsg
+
+exit_dbg__putMsgError:
+ mov r0, #MSGBUF_MSGERROR
+exit_dbg__putDebugMsg:
+ ldmfd sp!, {r4,r5,pc}
+
+ .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: An Ack Or Nak is indicated by '+' or '-', which is prepended with the Comm header and sent (without checksum)
+ * Sending Ack is only done for Continue and Step commands, where GDB does not expect any replies.
+ */
+dbg__sendAckOrNak:
+ stmfd sp!, {lr}
+ ldr r1, =debug_msgTxBufPtr /* R2: data structure base pointer */
+ ldr r0, [r1] /* Tx buffer Start Address */
+ str r0, [r1, #TXAPPENDPTR_OFFSET] /* Reset Tx buffer Append Pointer */
+
+ mov r1, #0 /* Initialize Segment Number = 0 (last segment) */
+ mov r0, #1 /* Retransmission message length = 1 */
+ bl _copy_msg_to_commbuf /* R0: cummulative message length, R1: segment number */
+ cmp r0, #1 /* Check if we managed to transmit the previous message */
+ moveq r0, #0 /* R0: Exit status (success) */
+ movne r0, #MSGBUF_MSGERROR /* R0: Exit status (error) */
+ ldmfd sp!, {pc}
+
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_comm.h b/AT91SAM7S256/armdebug/Debugger/debug_comm.h
new file mode 100644
index 0000000..7553240
--- /dev/null
+++ b/AT91SAM7S256/armdebug/Debugger/debug_comm.h
@@ -0,0 +1,53 @@
+/** @file debug_comm.h
+ * @brief Shared C/ASM header file for debugger communications
+ *
+ */
+
+/* Copyright (C) 2007-2010 the NxOS developers
+ *
+ * Module Developed by: TC Wan <tcwan@cs.usm.my>
+ *
+ * See AUTHORS for a full list of the developers.
+ *
+ * See COPYING for redistribution license
+ *
+ */
+
+#ifndef __DEBUG_COMM_H__
+#define __DEBUG_COMM_H__
+
+#include "_c_arm_macros.h"
+
+/* This is a place holder header file to allow for interfacing with C Routines in either
+ * NxOS or NXT Firmware.
+ *
+ * Since the header files from the original source trees were meant for C programs, we can't
+ * include them directly. Here we just use .extern to reference the routines.
+ */
+
+#ifdef __NXOS__
+
+ .extern nx_usb_is_connected
+ .extern nx_usb_can_write
+ .extern nx_usb_write
+ .extern nx_usb_data_written
+ .extern nx_usb_read
+ .extern nx_usb_data_read
+
+#else /* NXT Firmware */
+
+ .extern cCommInit
+ .extern cCommCtrl
+ .extern cCommExit
+ .extern dUsbWrite
+ .extern dUsbRead
+ .extern dUsbIsConfigured
+ .extern dBtSendMsg
+ .equ nxt_UBYTE_TRUE, 1
+ .equ nxt_UBYTE_FALSE, 0
+ .equ USB_CMD_READY, 0x01 /* From c_comm.iom */
+ .equ BT_CMD_READY, 0x02 /* From c_comm.iom */
+
+#endif
+
+#endif
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_internals.h b/AT91SAM7S256/armdebug/Debugger/debug_internals.h
new file mode 100644
index 0000000..82c0e38
--- /dev/null
+++ b/AT91SAM7S256/armdebug/Debugger/debug_internals.h
@@ -0,0 +1,300 @@
+/** @file debug_internals.h
+ * @brief Shared C/ASM header file for debugger internal constants
+ *
+ */
+
+/* Copyright (C) 2007-2011 the NxOS developers
+ *
+ * Module Developed by: TC Wan <tcwan@cs.usm.my>
+ *
+ * See AUTHORS for a full list of the developers.
+ *
+ * See COPYING for redistribution license
+ *
+ */
+
+#ifndef __DEBUG_INTERNALS_H__
+#define __DEBUG_INTERNALS_H__
+
+#include "_c_arm_macros.h"
+
+
+/** @addtogroup debugger */
+/*@{*/
+
+
+/* Declarations go here. */
+/** @name Debug Message Constants.
+ *
+ * Debug Message Values
+ */
+/*@{*/
+
+/*
+ * USB Buffer Sizes: Ctrl Intr Iso Bulk
+ * Full Speed Device 64 64 1023 64
+ * High Speed Device 64 1024 1024 512
+ */
+
+#define USB_BUFSIZE 64 /* USB Buffer size for AT91SAM7S */
+
+#define NXT_MSG_TELEGRAMTYPE_OFFSET 0 /* NXT Direct Command/Response Header */
+#define NXT_MSG_SEGNUM_OFFSET 1
+#define NXT_MSG_TELEGRAMSIZE_OFFSET 2
+
+#define NXT_GDBMSG_TELEGRAMTYPE 0x8d /* GDB debugger specific, no Response required */
+
+#define NXT_GDBMSG_START 3 /* Offset into USB Telegram buffer */
+
+#define MSG_NUMSEGMENTS 3 /* For packet transfers */
+#define MSG_SEGMENTSIZE (USB_BUFSIZE - NXT_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_CHKSUMOFFSET 3 /* to be subtracted from message length */
+#define MSGBUF_IN_OVERHEADLEN 5 /* For calculating max message data length (exclude ASCIIZ char) */
+#define MSGBUF_OUT_OVERHEADLEN 5 /* For calculating max message data length (exclude ASCIIZ char) */
+
+#define MSGBUF_CTRLC 0x03 /* For Out of Band Signaling: not implemented yet */
+#define MSGBUF_STARTCHAR '$'
+#define MSGBUF_ACKCHAR '+'
+#define MSGBUF_NAKCHAR '-'
+#define MSGBUF_ERRCHAR 'E'
+#define MSGBUF_SIGCHAR 'S'
+#define MSGBUF_SETCHAR '='
+#define MSGBUF_CHKSUMCHAR '#'
+#define MSGBUF_SEPCHAR ','
+#define MSGBUF_ARGCHAR ':'
+#define MSGBUF_MSGERROR -1
+/*@}*/
+
+/** @name Debug Command Lookup Constants.
+ *
+ * Debug Command Lookup
+ */
+/*@{*/
+
+#define CMDINDEX_OUTOFRANGE -1
+/*@}*/
+
+/** @name Debug Register Command Constants.
+ *
+ * Debug Register Command
+ */
+/*@{*/
+#define CMD_REG_NUMREGS 17
+#define CMD_REG_GETONE_MINPARAMLEN 1
+#define CMD_REG_GETONE_MAXPARAMLEN 2
+#define CMD_REG_GETALL_PARAMLEN 0
+#define CMD_REG_REGPARAMLEN 8 /* 32-bit ASCII Hex Value */
+#define CMD_REG_SETONE_MINPARAMLEN (2 + CMD_REG_REGPARAMLEN)
+#define CMD_REG_SETONE_MAXPARAMLEN (3 + CMD_REG_REGPARAMLEN)
+#define CMD_REG_SETALL_PARAMLEN (CMD_REG_NUMREGS*CMD_REG_REGPARAMLEN)
+/*@}*/
+
+/** @name Debug Memory Command Constants.
+ *
+ * Debug Memory Command
+ * FIXME: These limits are not enforced by the GDB client, it truncates addresses and lengths to remove leading '0's
+ * The PARAMLEN constants would probably be removed
+ */
+/*@{*/
+#define CMD_NUMITEMS_PARAMLEN 4 /* 16-bit ASCII Hex Value */
+#define CMD_MEM_READ_PARAMLEN (CMD_REG_REGPARAMLEN + CMD_NUMITEMS_PARAMLEN + 1) /* Address length is equivalent to reg param len */
+#define CMD_MEM_WRITE_MINPARAMLEN (CMD_REG_REGPARAMLEN + CMD_NUMITEMS_PARAMLEN + 2) /* Address length is equivalent to reg param len */
+#define CMD_MEM_SEPCHAR_OFFSET CMD_REG_REGPARAMLEN /* Address length is equivalent to reg param len */
+#define CMD_MEM_MAXOUTBUFLEN (MSGBUF_SIZE - MSGBUF_OUT_OVERHEADLEN)
+#define CMD_MEM_MAXREADBYTES (CMD_MEM_MAXOUTBUFLEN/2)
+#define CMD_MEM_MAXINBUFLEN (MSGBUF_SIZE - MSGBUF_IN_OVERHEADLEN)
+#define CMD_MEM_MAXWRITEBYTES ((CMD_MEM_MAXINBUFLEN - CMD_MEM_WRITE_MINPARAMLEN)/2)
+/*@}*/
+
+/** @name Debug Continue and Step Command Constants.
+ *
+ * Debug Continue and Step Command
+ */
+/*@{*/
+#define CMD_CONTINUE_MINPARAMLEN 0
+#define CMD_STEP_MINPARAMLEN 0
+/*@}*/
+
+
+
+/** @name Debug Breakpoint Command Constants.
+ *
+ * Debug Breakpoint Command
+ */
+/*@{*/
+
+#define CMD_BKPT_INSERT_MINPARAMLEN 5
+#define CMD_BKPT_REMOVE_MINPARAMLEN 5
+
+
+#define CMD_BKPT_TYPE_BREAK_MEMORY 0
+#define CMD_BKPT_TYPE_BREAK_HARD 1 /* Not supported */
+#define CMD_BKPT_TYPE_WATCH_WRITE 2 /* Not supported (yet) */
+#define CMD_BKPT_TYPE_WATCH_READ 3 /* Not supported (yet) */
+#define CMD_BKPT_TYPE_WATCH_ACCESS 4 /* Not supported (yet) */
+
+#define CMD_BKPT_KIND_THUMB 2
+#define CMD_BKPT_KIND_THUMB2 3 /* Not supported */
+#define CMD_BKPT_KIND_ARM 4
+
+#define CMD_BKPT_NOTFOUND -1
+
+/*@}*/
+
+/** @name Debug Stack Constants.
+ *
+ * Debug Stack Manipulation Values
+ */
+/*@{*/
+#define DBGSTACK_NEXTINSTR_INDEX 0 /* Next Instruction Address is at index 0 from bottom of Debug Stack */
+#define DBGSTACK_USERCPSR_INDEX 1 /* User CPSR (SPSR_UNDEF) is at index 1 from bottom of Debug Stack */
+#define DBGSTACK_USERREG_INDEX 2 /* R0 starts at index 2 from bottom of Debug Stack */
+#define DBGSTACK_USERSP_INDEX (DBGSTACK_USERREG_INDEX + REG_SP) /* SP is R13 */
+#define DBGSTACK_USERLR_INDEX (DBGSTACK_USERREG_INDEX + REG_LR) /* LR is R14 */
+#define DBGSTACK_USERPC_INDEX (DBGSTACK_USERREG_INDEX + REG_PC) /* PC is R15 */
+/*@}*/
+
+
+/** @name Exception Handler Vector Definitions.
+ *
+ * Exception Handler Vectors.
+ */
+/*@{*/
+
+#define RESET_VECTOR 0x00000000
+#define UNDEF_VECTOR 0x00000004
+#define SVC_VECTOR 0x00000008
+#define PABRT_VECTOR 0x0000000C
+#define DABRT_VECTOR 0x00000010
+#define RESERVED_VECTOR 0x00000014
+#define IRQ_VECTOR 0x00000018
+#define FIQ_VECTOR 0x0000001C
+
+
+/*@}*/
+
+
+/** @name Bitmask Definitions.
+ *
+ * Various Bitmasks used for data manipulation.
+ */
+/*@{*/
+#define BKPT_STATE_THUMB_FLAG 0x01 /* Flag Thumb Breakpoint */
+#define ASCII_LOWER2UPPER_MASK 0x20 /* ASCII Conversion bitmask */
+#define NIBBLE0 0x0000000F /* Nibble 0 word(3:0) */
+#define NIBBLE1 0x000000F0 /* Nibble 1 word(7:4) */
+#define NIBBLE2 0x00000F00 /* Nibble 2 word(11:8) */
+#define NIBBLE3 0x0000F000 /* Nibble 3 word(15:12) */
+#define NIBBLE4 0x000F0000 /* Nibble 4 word(19:16) */
+#define NIBBLE5 0x00F00000 /* Nibble 5 word(23:20) */
+#define NIBBLE6 0x0F000000 /* Nibble 6 word(27:24) */
+#define NIBBLE7 0xF0000000 /* Nibble 7 word(31:28) */
+#define BYTE0 0x000000FF /* Byte 0 word(7:0) */
+#define BYTE1 0x0000FF00 /* Byte 1 word(15:8) */
+#define BYTE2 0x00FF0000 /* Byte 2 word(23:16) */
+#define BYTE3 0xFF000000 /* Byte 3 word(31:24) */
+#define HLFWRD0 0x0000FFFF /* Halfword 0 word(15:0) */
+#define HLFWRD1 0xFFFF0000 /* Halfword 0 word(31:16) */
+/*@}*/
+
+/** @name CPSR Bit Definitions.
+ *
+ * Various Bit definitions for accessing the CPSR register.
+ */
+/*@{*/
+#define CPSR_THUMB 0x00000020
+#define CPSR_FIQ 0x00000040
+#define CPSR_IRQ 0x00000080
+#define CPSR_MODE 0x0000001F
+#define CPSR_COND 0xF0000000
+
+/* ARM Exception Modes */
+#define MODE_USR 0x10 /* User mode */
+#define MODE_FIQ 0x11 /* FIQ mode */
+#define MODE_IRQ 0x12 /* IRQ mode */
+#define MODE_SVC 0x13 /* Supervisor mode */
+#define MODE_ABT 0x17 /* Abort mode */
+#define MODE_UND 0x1B /* Undefined mode */
+#define MODE_SYS 0x1F /* System mode */
+
+/* Condition Flags
+ * b31 b30 b29 b28
+ * N Z C V
+ */
+#define CPSR_NFLAG 0x80000000
+#define CPSR_ZFLAG 0x40000000
+#define CPSR_CFLAG 0x20000000
+#define CPSR_VFLAG 0x10000000
+
+/*@}*/
+
+/** Debugger State Enums
+ *
+ * Debugger State.
+ * The enums must be consecutive, starting from 0
+ */
+ENUM_BEGIN
+ENUM_VALASSIGN(DBG_RESET, 0) /**< Initial State. */
+ENUM_VAL(DBG_INIT) /**< Debugger Initialized. */
+ENUM_VAL(DBG_CONFIGURED) /**< Debugger has been configured by GDB Server */
+ENUM_END(dbg_state_t)
+
+/** Breakpoint Type Enums
+ *
+ * Breakpoint Type.
+ * The enums must be consecutive, starting from 0
+ */
+ENUM_BEGIN
+ENUM_VALASSIGN(DBG_AUTO_BKPT,0) /**< Auto Breakpoint (Instruction resume after breakpoint). */
+ENUM_VAL(DBG_MANUAL_BKPT_ARM) /**< Manual ARM Breakpoint. */
+ENUM_VAL(DBG_NORMAL_BKPT_ARM) /**< Normal ARM Breakpoint (Single Step, Normal). */
+ENUM_VAL(DBG_MANUAL_BKPT_THUMB) /**< Manual Thumb Breakpoint. */
+ENUM_VAL(DBG_NORMAL_BKPT_THUMB) /**< Normal Thumb Breakpoint (Single Step, Normal). */
+ENUM_END(bkpt_type_t)
+
+/** Debugger Message Error Enums
+ *
+ * Debugger Error Message Enums.
+ * The enums must be consecutive, starting from 1
+ */
+/* FIXME: Need to validate against the ecos-generic-stub.c Error enums */
+ENUM_BEGIN
+ENUM_VALASSIGN(MSG_ERRIMPL, 0) /**< Stub (not implemented) Error. */
+ENUM_VAL(MSG_ERRINLENGTH) /**< Message Write Length Error. */
+ENUM_VAL(MSG_ERROUTLENGTH) /**< Message Read Length Error. */
+ENUM_VAL(MSG_ERRFORMAT) /**< Message Format Error. */
+ENUM_VAL(MSG_UNKNOWNCMD) /**< Unrecognized Command Error. */
+ENUM_VAL(MSG_UNKNOWNPARAM) /**< Unrecognized Parameter Error. */
+ENUM_VAL(MSG_UNKNOWNBRKPT) /**< Unrecognized Breakpoint Error. */
+ENUM_END(dbg_msg_errno)
+
+/** Register Enums
+ *
+ * Register Enums.
+ * Refer to eCOS's arm_stub.h for enum values
+ */
+ENUM_BEGIN
+ENUM_VALASSIGN(REG_R0, 0) /**< User Reg R0 */
+ENUM_VAL(REG_R1) /**< User Reg R1 */
+ENUM_VAL(REG_R2) /**< User Reg R2 */
+ENUM_VAL(REG_R3) /**< User Reg R3 */
+ENUM_VAL(REG_R4) /**< User Reg R4 */
+ENUM_VAL(REG_R5) /**< User Reg R5 */
+ENUM_VAL(REG_R6) /**< User Reg R6 */
+ENUM_VAL(REG_R7) /**< User Reg R7 */
+ENUM_VAL(REG_R8) /**< User Reg R8 */
+ENUM_VAL(REG_R9) /**< User Reg R9 */
+ENUM_VAL(REG_R10) /**< User Reg R10 */
+ENUM_VAL(REG_R11) /**< User Reg R11 */
+ENUM_VAL(REG_R12) /**< User Reg R12 */
+ENUM_VAL(REG_SP) /**< Previous Mode SP (R13) */
+ENUM_VAL(REG_LR) /**< Previous Mode LR (R14) */
+ENUM_VAL(REG_PC) /**< Program Counter (R15) */
+ENUM_VALASSIGN(REG_FPSCR, 24) /**< Previous Mode FPSCR (dummy) */
+ENUM_VAL(REG_CPSR) /**< Previous Mode CPSR */
+
+ENUM_END(register_enum_t)
+
+
+#endif /* __DEBUG_INTERNALS_H__ */
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_macros.h b/AT91SAM7S256/armdebug/Debugger/debug_macros.h
new file mode 100644
index 0000000..75d6299
--- /dev/null
+++ b/AT91SAM7S256/armdebug/Debugger/debug_macros.h
@@ -0,0 +1,386 @@
+/** @file debug_macros.h
+ * @brief internal macros used by debug_stub routines
+ *
+ */
+
+/* Copyright (C) 2007-2010 the NxOS developers
+ *
+ * Module Developed by: TC Wan <tcwan@cs.usm.my>
+ *
+ * See AUTHORS for a full list of the developers.
+ *
+ * See COPYING for redistribution license
+ *
+ */
+
+#ifndef __DEBUG_MACROS_H__
+#define __DEBUG_MACROS_H__
+
+
+
+/** @addtogroup debug_macros */
+/*@{*/
+
+/* _dbg_jumpTableHandler
+ * Call Jump Table Routine based on Index
+ * On entry:
+ * jumptableaddr is the address (constant) of the Jump Table
+ * jumpreg is the register used to perform the indirect jump
+ * indexreg contains jump table index value
+ */
+ .macro _dbg_jumpTableHandler jumptableaddr, jumpreg, indexreg
+
+ ldr \jumpreg, =\jumptableaddr
+ ldr \jumpreg, [\jumpreg, \indexreg, lsl #2]
+ mov lr, pc
+ bx \jumpreg /* Call Command Handler Routine */
+ .endm
+
+
+/* _dbg_thumbDecodeEntry
+ * Load Thumb Instruction Decoder Entry
+ * On entry:
+ * instrreg is the register to load the instruction into
+ * instrmask is the register to load the instruction mask into
+ * codehandler is the register to load the code handling routine into
+ * indexreg contains decode table index value
+ * NOTE: instrreg, instrmask, codehandler must be in increasing register number order
+ */
+ .macro _dbg_thumbDecodeEntry instrreg, instrmask, codehandler, indexreg
+
+ ldr \instrmask, =debug_thumbDecodeTable /* Temporary register */
+ add \instrmask, \instrmask, \indexreg, lsl #3
+ ldm \instrmask, {\instrreg, \codehandler} /* LSHW: IID, MSHW: IBM */
+ mov \instrmask, \instrreg, lsr #16
+ mov \instrreg, \instrreg, lsl #16
+ mov \instrreg, \instrreg, lsr #16 /* Keep HLFWORD0 containing instruction */
+ .endm
+
+/* _dbg_armDecodeEntry
+ * Load ARM Instruction Decoder Entry
+ * On entry:
+ * instrreg is the register to load the instruction into
+ * instrmask is the register to load the instruction mask into
+ * codehandler is the register to load the code handling routine into
+ * indexreg contains decode table index value
+ * NOTE: instrreg, instrmask, codehandler must be in increasing register number order
+ */
+ .macro _dbg_armDecodeEntry instrreg, instrmask, codehandler, indexreg
+
+ ldr \instrmask, =debug_thumbDecodeTable /* Temporary register */
+ add \instrmask, \instrmask, \indexreg, lsl #3
+ add \instrmask, \instrmask, \indexreg, lsl #2 /* 12 byte entries */
+ ldm \instrmask, {\instrreg, \instrmask, \codehandler}
+ .endm
+
+/* _asciiz
+ * Terminate string given string buffer pointer in \strptr
+ * scratchreg is used as a scratch register (destroyed)
+ *
+ */
+ .macro _asciiz strptr, scratchreg
+ mov \scratchreg, #0 /* ASCIIZ character */
+ strb \scratchreg, [\strptr] /* Terminate ASCII string */
+ .endm
+
+
+/* _dbg_stpcpy
+ * _dbg_stpcpy macro
+ * On entry:
+ * deststrptr: Destination string
+ * sourcestrptr: Source string
+ * scratchreg: scratch register for copying
+ * On exit:
+ * deststrptr: Pointer to ASCIIZ character in destination string
+ * sourcestrptr: Pointer to next character slot in source string (after ASCIIZ)
+ * scratchreg: destroyed
+ */
+ .macro _dbg_stpcpy deststrptr, sourcestrptr, scratchreg
+1: ldrb \scratchreg, [\sourcestrptr], #1
+ strb \scratchreg, [\deststrptr], #1
+ teq \scratchreg, #0
+ bne 1b
+ sub \deststrptr, \deststrptr, #1 /* Adjust Destination string pointer to point at ASCIIZ character */
+ .endm
+
+/* _dbg_memcpy
+ * _dbg_stpcpy macro
+ * On entry:
+ * deststrptr: Destination string
+ * sourcestrptr: Source string
+ * sizereg: Number of bytes to copy
+ * scratchreg: scratch register for copying
+ * On exit:
+ * deststrptr: Pointer to next character slot in destination string
+ * sourcestrptr: Pointer to next character slot in source string
+ * sizereg, scratchreg: destroyed
+ */
+ .macro _dbg_memcpy deststrptr, sourcestrptr, sizereg, scratchreg
+1: ldrb \scratchreg, [\sourcestrptr], #1
+ strb \scratchreg, [\deststrptr], #1
+ subs \sizereg, \sizereg, #1
+ 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:
+ * R0: Pointer to Output Buffer ASCIIZ location
+ * R1: destroyed
+ * R2: destroyed
+ */
+ .macro _dbg_outputRetransmitFlag
+ ldr r0, =debug_OutMsgBuf
+ ldr r1, =debug_RetransmitFlag /* ASCIIZ terminated */
+ _dbg_stpcpy r0, r1, r2
+ .endm
+
+/* _dbg_outputMsgValidResponse
+ * Return Message with valid response ('+$')
+ * On exit:
+ * R0: Pointer to Output Buffer next character slot location
+ * R1: destroyed
+ * R2: destroyed
+ */
+ .macro _dbg_outputMsgValidResponse
+ ldr r0, =debug_OutMsgBuf
+ ldr r1, =debug_ValidResponsePrefix
+ _dbg_stpcpy r0, r1, r2
+ .endm
+
+
+/* _dbg_outputMsgStatusOk
+ * Return Message with Ok ('+$OK') status
+ * On exit:
+ * R0: Pointer to Output Buffer ASCIIZ location
+ * R1: destroyed
+ * R2: destroyed
+ */
+ .macro _dbg_outputMsgStatusOk
+ ldr r0, =debug_OutMsgBuf
+ ldr r1, =debug_OkResponse /* ASCIIZ terminated */
+ _dbg_stpcpy r0, r1, r2
+ .endm
+
+/* __dbg_outputErrMsg
+ * Internal Routine called to generate error messages
+ * Return Message with Error ('+$ENN') status
+ * On entry:
+ * R1: error code
+ * On exit:
+ * R0: Pointer to Output Buffer ASCIIZ location
+ * R1: destroyed
+ * R2: destroyed
+ * R3: destroyed
+ */
+ .macro __dbg_outputErrMsg
+ ldr r0, =debug_OutMsgBuf
+ ldr r2, =debug_ErrorResponsePrefix
+ _dbg_stpcpy r0, r2, r3
+ bl byte2ascii /* R0 points to buffer position after byte value */
+ _asciiz r0, r1
+ .endm
+
+/* _dbg_outputMsgStatusErr
+ * Return Message with Error ('+$ENN') status
+ * On entry:
+ * R0: error code
+ * On exit:
+ * R0: Pointer to Output Buffer ASCIIZ location
+ * R1: destroyed
+ * R2: destroyed
+ * R3: destroyed
+ */
+ .macro _dbg_outputMsgStatusErr
+ mov r1, r0
+ __dbg_outputErrMsg
+ .endm
+
+/* _dbg_outputMsgStatusErrCode
+ * Return Message with Error ('+$ENN') status
+ * On exit:
+ * R0: Pointer to Output Buffer ASCIIZ location
+ * R1: destroyed
+ * R2: destroyed
+ */
+ .macro _dbg_outputMsgStatusErrCode errcode
+ mov r1, #\errcode
+ __dbg_outputErrMsg
+ .endm
+
+/* _dbg_outputMsgStatusSig
+ * Return Message with Signal ('+$SNN') status
+ * On exit:
+ * R0: Pointer to Output Buffer ASCIIZ location
+ * R1: destroyed
+ * R2: destroyed
+ */
+ .macro _dbg_outputMsgStatusSig statuscode
+ ldr r0, =debug_OutMsgBuf
+ ldr r1, =debug_SignalResponsePrefix
+ _dbg_stpcpy r0, r1, r2
+ mov r1, #\statuscode
+ bl byte2ascii /* R0 points to buffer position after byte value */
+ _asciiz r0, r1
+ .endm
+
+/* _regenum2index
+ * Convert register enum to debugger stack index
+ *
+ * On entry:
+ * indexenum: enum representing Register to access
+ * indexreg: register to be used to store the debugger stack index value (0-max index)
+ * On exit:
+ * indexreg contains debugger stack index value (0-max index)
+ */
+ .macro _regenum2index indexenum, indexreg
+ add \indexreg, \indexenum, #DBGSTACK_USERREG_INDEX /* Convert register index to Debug Stack index */
+ .endm
+
+/* _getdbgregisterfromindex
+ * Retrieve register contents from debugger stack given index
+ *
+ * On entry:
+ * indexreg contains debugger stack index value (0-max index)
+ * On exit:
+ * indexreg: Breakpoint index (preserved)
+ * contentsreg: Register Contents for given index
+ */
+ .macro _getdbgregisterfromindex indexreg, contentsreg
+ ldr \contentsreg, =__debugger_stack_bottom__
+ ldr \contentsreg, [\contentsreg, \indexreg, lsl #2]
+ .endm
+
+/* _setdbgregisterfromindex
+ * Store register contents to debugger stack given index
+ *
+ * On entry:
+ * indexreg contains debugger stack index value (0-max index)
+ * contentsreg: Register Contents for given index
+ * addressreg: Scratch register for address pointer
+ * On exit:
+ * indexreg: Breakpoint index (preserved)
+ * contentsreg: Register Contents for given index
+ */
+ .macro _setdbgregisterfromindex indexreg, contentsreg, addressreg
+ ldr \addressreg, =__debugger_stack_bottom__
+ str \contentsreg, [\addressreg, \indexreg, lsl #2]
+ .endm
+
+
+/* _index2bkptindex_addr
+ * Convert Breakpoint index to breakpoing entry address
+ *
+ * On entry:
+ * indexreg contains breakpoint index value
+ * On exit:
+ * indexreg: Breakpoint index (preserved)
+ * addrreg: Breakpoint Entry Address
+ */
+ .macro _index2bkptindex_addr indexreg, addrreg
+ ldr \addrreg, =__breakpoints_start__
+ add \addrreg, \addrreg, \indexreg, lsl #3 /* Calculate Breakpoint Entry Address */
+ .endm
+
+/* _dbg_getstate
+ * Get Debugger State
+ * On exit:
+ * reg: Debugger State enum
+ */
+ .macro _dbg_getstate reg
+ ldr \reg, =debug_state
+ ldrb \reg, [\reg]
+ .endm
+
+/* _dbg_setstate
+ * Set Debugger State to given value
+ * On exit:
+ * r0, r1: destroyed
+ */
+ .macro _dbg_setstate state
+ mov r0, #\state
+ ldr r1, =debug_state
+ strb r0, [r1]
+ .endm
+
+/* _dbg_getmode
+ * Get Debugger Mode
+ * On exit:
+ * reg: Debugger Mode (Boolean)
+ */
+ .macro _dbg_getmode reg
+ ldr \reg, =debug_mode
+ ldrb \reg, [\reg]
+ .endm
+
+/* _dbg_setmode
+ * Set Debugger Mode to given value
+ * On exit:
+ * r0, r1: destroyed
+ */
+ .macro _dbg_setmode mode
+ mov r0, #\mode
+ ldr r1, =debug_mode
+ strb r0, [r1]
+ .endm
+
+/* _dbg_get_bkpt_type
+ * Get Breakpoint Type
+ * On exit:
+ * reg: Breakpoint Type
+ */
+ .macro _dbg_get_bkpt_type reg
+ ldr \reg, =debug_bkpt_type
+ ldrb \reg, [\reg]
+ .endm
+
+/* _dbg_set_bkpt_type
+ * Set Breakpoint Type to given value
+ * On exit:
+ * r0, r1: destroyed
+ */
+ .macro _dbg_set_bkpt_type bkpt_type
+ mov r0, #\bkpt_type
+ ldr r1, =debug_bkpt_type
+ strb r0, [r1]
+ .endm
+
+
+
+/* _dbg_getcurrbkpt_index
+ * Get current breakpoint index
+ * On exit:
+ * reg: Breakpoint index
+ */
+ .macro _dbg_getcurrbkpt_index reg
+ ldr \reg, =debug_curr_breakpoint
+ ldrb \reg, [\reg]
+ .endm
+
+/* _dbg_setcurrbkpt_index
+ * Set current breakpoint index
+ * On exit:
+ * r1: destroyed
+ */
+ .macro _dbg_setcurrbkpt_index reg
+ ldr r1, =debug_curr_breakpoint
+ strb \reg, [r1]
+ .endm
+
+ /*@}*/
+
+#endif /* __DEBUG_MACROS_H__ */
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_runlooptasks.S b/AT91SAM7S256/armdebug/Debugger/debug_runlooptasks.S
new file mode 100644
index 0000000..fd17412
--- /dev/null
+++ b/AT91SAM7S256/armdebug/Debugger/debug_runlooptasks.S
@@ -0,0 +1,87 @@
+/** @file debug_runloop.S
+ * @brief GDB Server platform Run Loop
+ *
+ */
+
+/* Copyright (C) 2007-2011 the NxOS developers
+ *
+ * Module Developed by: TC Wan <tcwan@cs.usm.my>
+ *
+ * See AUTHORS for a full list of the developers.
+ *
+ * See COPYING for redistribution license
+ *
+ */
+
+
+/*
+ * The Debugger has to implement a Run Loop in ABORT mode
+ * since the hardware is still running. Consequently,
+ * the communications subsystems such as USB (and Bluetooth?)
+ * which is used to communicate with the Host needs to be
+ * serviced in order for actual data transmission and reception
+ * to take place. Currently we're reusing the platform's
+ * communication routines to do the actual tx/rx, so it means
+ * that it is not possible to set breakpoints in those modules.
+ * In addition, since the platform communication modules may
+ * handle other tasks, it is currently possible to enter an
+ * indeterminate state where certain communication messages trigger
+ * a platform response which cannot be handled by the Debugger Run Loop.
+ * The alternative is to implement our own communications routines, but
+ * that will take even more code.
+ *
+ * FIXME: It may become necessary to hack the platform communications
+ * routines to detect that we're in the Debugger Run Loop and not the
+ * normal run loop to avoid system crashes, but the current goal is to
+ * have as minimal changes to the platform code as possible.
+ *
+ * Since there are two Run Loops for the platform, the way in which
+ * they interact is as follows:
+ *
+ * [Platform Run Loop] - DBG_INIT/ GDB Cmd/ BKPT -> [Debugger Run Loop]
+ * \ <------ GO/ STEP/ CONT ----- /
+ * ... ...
+ * ... Handle GDB Cmd/Resp
+ * ... ...
+ * {normal runloop {communications /
+ * processing} watchdog routines}
+ * ^-------v v-------^
+ *
+ * The Platform will invoke dbg__bkpt_init() after hardware and system initialization,
+ * before entering the Platform Run Loop. This switches processing over to the
+ * Debugger Run Loop which will wait for the GDB command to Go/Step/Cont before
+ * returning control to the Platform Run Loop.
+ *
+ * Subsequently, Debugger Run Loop will be triggered by Breakpoints, or
+ * when the communications subsystem receives a GDB Command.
+ *
+ * The Debugger Run Loop is actually dbg__bkpt_waitCMD(), this file contains
+ * the Run Loop Tasks which needs to be invoked periodically by the Run Loop,
+ * to minimize the coupling between the ARMDEBUG modules and the Platform.
+ *
+ * Note: The Debugger Run Loop does not handle Hardware Shutdown, it is
+ * assumed that we wouldn't need to do so in Debug Mode.
+ *
+ */
+#define __ASSEMBLY__
+
+ .global dbg__runloopTasks
+
+
+#ifdef __NXOS__
+/* NxOS Run Loop */
+dbg__runloopTasks:
+/* Currently, there's nothing that needs to be done in the NxOS Run Loop */
+ bx lr
+
+#else
+/* NXT Firmware Run Loop */
+ .extern cCommCtrl
+
+dbg__runloopTasks:
+ push {lr}
+ /* FIXME: Add necessary cXXXCtrl calls here */
+ bl cCommCtrl
+ /* OSWatchdogWrite is a NULL function in the NXT Firmware?! */
+ pop {pc}
+#endif
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_stack.ld b/AT91SAM7S256/armdebug/Debugger/debug_stack.ld
new file mode 100644
index 0000000..8fc4cb7
--- /dev/null
+++ b/AT91SAM7S256/armdebug/Debugger/debug_stack.ld
@@ -0,0 +1,15 @@
+/* The following linker definitions should be placed in the stack section */
+
+ /* debugger state */
+ __debugger_stack_bottom__ = . ;
+ . += 0x48; /* 16 previous mode registers + SPSR + UNDEF Next Instruction Address */
+ __debugger_stack__ = .;
+ __debugger_stack_top__ = . ;
+
+ /* breakpoints */
+ __breakpoints_start__ = . ;
+ . += 0x40; /* Single Stepping Breakpoint + 7 Breakpoints */
+ __breakpoints_end__ = . ;
+
+/* Symbols */
+ __breakpoints_num__ = (__breakpoints_end__ - __breakpoints_start__) / 8;
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_stub.S b/AT91SAM7S256/armdebug/Debugger/debug_stub.S
new file mode 100644
index 0000000..a58fa8f
--- /dev/null
+++ b/AT91SAM7S256/armdebug/Debugger/debug_stub.S
@@ -0,0 +1,2925 @@
+/** @file debug_stub.S
+ * @brief ARM Breakpoint Debugger support routines
+ *
+ */
+
+/* Copyright (C) 2007-2011 the NxOS developers
+ *
+ * Module Developed by: TC Wan <tcwan@cs.usm.my>
+ *
+ * See AUTHORS for a full list of the developers.
+ *
+ * See COPYING for redistribution license
+ *
+ */
+
+ /* GDB sparc-stub.c comments header included below to document GDB Server Remote protocol */
+ /* This header has been modified to include additional commands not documented in the header stub */
+
+ /****************************************************************************
+
+ THIS SOFTWARE IS NOT COPYRIGHTED
+
+ HP offers the following for use in the public domain. HP makes no
+ warranty with regard to the software or it's performance and the
+ user accepts the software "AS IS" with all faults.
+
+ HP DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD
+ TO THIS SOFTWARE INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+
+****************************************************************************/
+
+/****************************************************************************
+ * Header: remcom.c,v 1.34 91/03/09 12:29:49 glenne Exp $
+ *
+ * Module name: remcom.c $
+ * Revision: 1.34 $
+ * Date: 91/03/09 12:29:49 $
+ * Contributor: Lake Stevens Instrument Division$
+ *
+ * Description: low level support for gdb debugger. $
+ *
+ * Considerations: only works on target hardware $
+ *
+ * Written by: Glenn Engel $
+ * ModuleState: Experimental $
+ *
+ * NOTES: See Below $
+ *
+ * Modified for SPARC by Stu Grossman, Cygnus Support.
+ *
+ * This code has been extensively tested on the Fujitsu SPARClite demo board.
+ *
+ * To enable debugger support, two things need to happen. One, a
+ * call to set_debug_traps() is necessary in order to allow any breakpoints
+ * or error conditions to be properly intercepted and reported to gdb.
+ * Two, a breakpoint needs to be generated to begin communication. This
+ * is most easily accomplished by a call to breakpoint(). Breakpoint()
+ * simulates a breakpoint by executing a trap #1.
+ *
+ *************
+ *
+ * The following gdb commands are supported:
+ *
+ * command function Return value
+ *
+ * g return the value of the CPU registers hex data or ENN
+ * GrrrrRRRR.. set the value of the CPU registers OK or ENN
+ * where register values are given as
+ * 32-bit hex values in the sequence:
+ * User R0, R1, ..., R15, CPSR
+ * px get the value of one register (x) hex data or ENN
+ * Px=rrrr set the value of one register (x) to OK or ENN
+ * 32-bit hex value rrrr.
+ * x = ['0','F'] for R0-R15,
+ * '18' for FPSCR (dummy), '19' for User CPSR
+ *
+ * mAA..AA,LLLL Read LLLL bytes at address AA..AA hex data or ENN
+ * MAA..AA,LLLL:bb..bb
+ * Write LLLL bytes at address AA.AA OK or ENN
+ *
+ * c Resume at current address SNN ( signal NN)
+ * cAA..AA Continue at address AA..AA SNN
+ *
+ * s Step one instruction SNN
+ * sAA..AA Step one instruction from AA..AA SNN
+ *
+ * k kill
+ *
+ * ? What was the last sigval ? SNN (signal NN)
+ *
+ * zt,AA..AA,k Remove a Breakpoint of type t at addr OK or ENN
+ * AA..AA of kind k
+ * Zt,AA..AA,k Insert a Breakpoint of type t at addr OK or ENN
+ * AA..AA of kind k
+ * t 0: memory breakpoint
+ * 1: hardware breakpoint
+ * 2: write watchpoint
+ * 3: read watchpoint
+ * 4: access watchpoint
+ * k: 2 (16-bit Thumb), 3 (32-bit Thumb2)
+ * or 4 (32-bit ARM) for t=[0,1]
+ * Num. bytes to watch for t=[2,4]
+ *
+ * All commands and responses are sent with a packet which includes a
+ * checksum. A packet consists of
+ *
+ * $<packet info>#<checksum>.
+ *
+ * where
+ * <packet info> :: <characters representing the command or response>
+ * <checksum> :: < two hex digits computed as modulo 256 sum of <packetinfo>>
+ *
+ * When a packet is received, it is first acknowledged with either '+' or '-'.
+ * '+' indicates a successful transfer. '-' indicates a failed transfer.
+ *
+ * Example:
+ *
+ * Host: Reply:
+ * $m0,10#2a +$00010203040506070809101112131415#42
+ *
+ ****************************************************************************/
+ /* Modified GDB Server Remote Protocol definition from GDB's sparc-stub.c Comment Header included above
+ * Additional commands from GDB Reference Appendix D.2
+ *
+ * Note: ARMDEBUG can only implement Memory Breakpoints t=0. Hardware breakpoints requires a JTAG debugger.
+ * Currently, watchpoints are not implemented as they require hardware support as well (need verification).
+ *
+ * GDB requires command parameters to be specified as Big Endian values.
+ * However, the read/write register command expect the register contents to be specified in target byte order.
+ * The default target byte order is Little Endian for the AT91SAM7xxx processor in the NXT.
+ * If Big Endian target byte order is required, the __BIG_ENDIAN__ preprocessor label should be defined.
+ */
+
+/* FIXME: The Hex value arguments passed by GDB does not have fixed lengths! Although the standard says
+ * there should be x digits, it does not follow this requirement. e.g., register index.
+ */
+
+
+#define __ASSEMBLY__
+#include "debug_stub.h"
+#include "debug_internals.h"
+#include "debug_macros.h"
+
+/* Macro definitions */
+
+/* _check_msgseparator
+ * Look for separator ','
+ * On entry:
+ * bufferptr: points to the parameter buffer [can't be R0]
+ * On exit:
+ * R0: destroyed
+ * bufferptr: points to the next character location in the parameter buffer
+ * Flags: Updated
+ */
+
+ .macro _check_msgseparator bufferptr
+ ldrb r0, [\bufferptr], #1 /* get separator */
+ cmp r0, #MSGBUF_SEPCHAR
+ .endm
+
+/* _check_msgargument
+ * Look for argument ':'
+ * On entry:
+ * bufferptr: points to the parameter buffer [can't be R0]
+ * On exit:
+ * R0: destroyed
+ * bufferptr: points to the next character location in the parameter buffer
+ * Flags: Updated
+ */
+
+ .macro _check_msgargument bufferptr
+ ldrb r0, [\bufferptr], #1 /* get separator */
+ cmp r0, #MSGBUF_ARGCHAR
+ .endm
+
+/* _check_msgassignment
+ * Look for assignment '='
+ * On entry:
+ * bufferptr: points to the parameter buffer [can't be R0]
+ * On exit:
+ * R0: destroyed
+ * bufferptr: points to the next character location in the parameter buffer
+ * Flags: Updated
+ */
+
+ .macro _check_msgassignment bufferptr
+ ldrb r0, [\bufferptr], #1 /* get separator */
+ cmp r0, #MSGBUF_SETCHAR
+ .endm
+
+.bss
+.align 4
+debug_InMsgBuf:
+ .space MSGBUF_SIZE,0
+debug_OutMsgBuf:
+ .space MSGBUF_SIZE,0
+
+debug_state:
+ .byte 0x0 /* dbg_state_t variable */
+debug_mode:
+ .byte 0x0 /* Boolean variable */
+debug_bkpt_type:
+ .byte 0x0 /* bkpt_type_t variable */
+debug_curr_breakpoint:
+ .byte 0x0
+
+.data
+.align 4
+debug_RetransmitFlag:
+ .byte '-',0
+
+debug_AckOnlyFlag:
+ .byte '+',0
+
+debug_ValidResponsePrefix:
+ .byte '+','$',0
+
+debug_ErrorResponsePrefix:
+ .byte '+','$','E',0
+
+debug_SignalResponsePrefix:
+ .byte '+','$','S',0
+
+debug_OkResponse:
+ .byte '+','$','O','K',0
+
+/* The CmdIndexTable and CmdJumpTable must be kept in sync */
+debug_cmdIndexTable:
+ .byte 'g','G','p','P','m','M','c','s','k','z','Z','?','q','Q',0
+
+/* Command Handlers
+ * On entry:
+ * R0: Input Message Parameter Buffer address pointer (points to contents after '$' and '<cmdchar>')
+ */
+.align 4
+debug_cmdJumpTable:
+ .word _dbg__cmd_GetAllRegs /* 'g' */
+ .word _dbg__cmd_SetAllRegs /* 'G' */
+ .word _dbg__cmd_GetOneReg /* 'p' */
+ .word _dbg__cmd_SetOneReg /* 'P' */
+ .word _dbg__cmd_ReadMem /* 'm' */
+ .word _dbg__cmd_WriteMem /* 'M' */
+ .word _dbg__cmd_Continue /* 'c' */
+ .word _dbg__nop /* 's' */
+ .word _dbg__nop /* 'k' */
+ .word _dbg__cmd_RemoveBreakpoint /* 'z' */
+ .word _dbg__cmd_InsertBreakpoint /* 'Z' */
+ .word _dbg__cmd_Status /* '?' */
+ .word _dbg__cmd_Query /* 'q' */
+ .word _dbg__nop /* 'Q' */
+ .word 0
+
+/* Rm Shifted Shift Type Jump Table
+ * On entry:
+ * R0: Register Rm
+ * R1: Shift/Rotate Amount
+ * On exit:
+ * R0: RmShifted result
+ *
+ */
+debug_regShiftJumpTable:
+ .word _reg_lsl /* 00 */
+ .word _reg_lsr /* 01 */
+ .word _reg_asr /* 02 */
+ .word _reg_ror /* 03 */
+ .word _reg_rrx /* 04 */
+
+/* Data Processing Instruction Jump Table
+ * On entry:
+ * R0: Register Rn (Operand 1) value
+ * R1: Operand 2 value
+ * R2: Default Next Instruction Address
+ * R5[3:0]: CPSR condition codes
+ * On exit:
+ * R0: Calculated result
+ * R1, R2, R3: Destroyed
+ *
+ */
+debug_dataInstrJumpTable:
+ .word _opcode_and /* 00 */
+ .word _opcode_eor /* 01 */
+ .word _opcode_sub /* 02 */
+ .word _opcode_rsb /* 03 */
+ .word _opcode_add /* 04 */
+ .word _opcode_adc /* 05 */
+ .word _opcode_sbc /* 06 */
+ .word _opcode_rsc /* 07 */
+ .word _opcode_tst /* 08 */
+ .word _opcode_teq /* 09 */
+ .word _opcode_cmp /* 0A */
+ .word _opcode_cmn /* 0B */
+ .word _opcode_orr /* 0C */
+ .word _opcode_mov /* 0D */
+ .word _opcode_bic /* 0E */
+ .word _opcode_mvn /* 0F */
+
+
+/*
+ * To determine the next instruction to execute, we need to check current (breakpointed) instruction
+ * and determine whether it will be executed or not. This necessitates a mini instruction decoder
+ * that can check the type of instruction, as well as if it'll affect the PC.
+ * The instruction decoder used here is table based. Each entry in the table consists of:
+ * Instruction Identifier (IID), Instruction Bitmask (IBM), Instruction Handler Address (IHA)
+ * Null entries are placed at the end of the table.
+ *
+ * This allows for a flexible approach to handling instructions that we're interested in, at the expense
+ * of memory usage.
+ *
+ * For ARM, the IID & IBM are both 4 bytes, whereas the Thumb IID & IBM are 2 bytes.
+ * The IHA is always 4 bytes.
+ */
+
+/* ARM Instruction Decode Table
+ * .word IID, IBM, IHA (12 bytes)
+ */
+
+debug_armDecodeTable:
+ .word 0x0000f000, 0x0c00f000, _arm_data_instr_handler /* Data Processing instr with Rd = R15 */
+ .word 0x012fff10, 0x0ffffff0, _arm_bx_blx_handler /* BX or BLX. Note v4t does not have BLX instr */
+ .word 0x0410f000, 0x0410f000, _arm_ldr_pc_handler /* LDR with Rd = PC */
+/* .word 0x06000010, 0x0e000010, _arm_undef_handler */ /* Undefined instr: shouldn't occur, as it would've been trapped already. See _dbg_following_instruction_addr */
+ .word 0x08108000, 0x0e108000, _arm_ldm_pc_handler /* LDM {pc} */
+ .word 0x0a000000, 0x0e000000, _arm_b_bl_blx_handler /* B, BL or BLX. Note v4t does not have BLX instr */
+ .word 0x0c000000, 0x0c000000, _arm_coproc_swi_handler /* Coprocessor instr or SWI */
+ .word 0x0,0x0,0x0 /* Null Entry */
+
+/* Thumb Instruction Decode Table
+ * .hword IID, IBM
+ * .word IHA (8 bytes)
+ */
+
+debug_thumbDecodeTable:
+ .hword 0x4700, 0xff07
+ .word _thumb_bx_blx_handler /* BX or BLX. Note: b7 (H1) is not matched in the mask */
+ .hword 0xbd00, 0xff00
+ .word _thumb_poppc_handler /* PUSH/POP, specifically POP {Rlist,PC} */
+ .hword 0xd000, 0xf000
+ .word _thumb_bcond_swi_handler /* B<cond> or SWI */
+ .hword 0xe000, 0xf800
+ .word _thumb_b_handler /* B */
+ .hword 0xf000, 0xf000
+ .word _thumb_long_bl_blx_handler /* Long BL or BLX (4 bytes) Note: b11 (H) indicates 1st or 2nd instr */
+ .hword 0x0,0x0
+ .word 0x0 /* Null Entry */
+
+/* ARM Condition Code Mapping Table
+ * Converts Instruction encoding to SPSR Flags.
+ * b31 b30 b29 b28
+ * N Z C V
+ * Indexed according to Instruction Encoding order (pg 30, Table 6, ATMEL ARM7TDMI Data Sheet)
+ * Condition Code stored in MSN(set), LSN(clr) order
+ * Note1: 0x00 = AL. NV is deprecated, treat as AL
+ * Note2: 0xFF indicates that the condition checks needs to be handled separately (complex checks)
+ *
+ * EQ: Z set
+ * NE: Z clr
+ * HS/CS: C set
+ * LO/CC: C clr
+ * MI: N set
+ * PL: N clr
+ * VS: V set
+ * VC: V clr
+ * HI: C set AND Z clr
+ * LS: C clr AND Z set
+ */
+
+
+debug_armCondCodeTable:
+ /* EQ, NE, HS/CS, LO/CC, MI, PL, VS, VC, HI, LS, GE, LT, GT, LE, AL, NV */
+ .byte 0x40, 0x04, 0x20, 0x02, 0x80, 0x08, 0x10, 0x01, 0x24, 0x42, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00
+
+/* ARM Complex Condition Code Mapping Table
+ * Converts Instruction encoding to SPSR Flags.
+ * b31 b30 b29 b28
+ * N Z C V
+ * Indexed according to Instruction Encoding order (pg 30, Table 6, ATMEL ARM7TDMI Data Sheet)
+ * for GE, LT, GT and LE instructions only
+ * Condition Code stored in the following order:
+ * b7 b6 b5 b4 b3 b2 b1 b0
+ * - - - ANDOR - Z set AND N==V (bit set = 1)
+ * - - - ANDOR - Z clr OR N!=V (bit clr = 0)
+ *
+ * GE: N == V
+ * LT: N != V
+ * GT: Z clr AND (N == V)
+ * LE: Z set OR (N != V)
+ */
+
+#define COMPLEX_CONDCODE_START 0x0A
+#define COMPLEX_CONDCODE_NEQV_MASK 0x01
+#define COMPLEX_CONDCODE_AND_MASK 0x02
+#define COMPLEX_CONDCODE_ZSET_MASK 0x04
+#define COMPLEX_CONDCODE_ANDOR_MASK 0x10
+
+#define COMPLEX_CONDCODE_NFLAG 0x08
+#define COMPLEX_CONDCODE_ZFLAG 0x04
+#define COMPLEX_CONDCODE_CFLAG 0x02
+#define COMPLEX_CONDCODE_VFLAG 0x01
+
+
+debug_armComplexCCTable:
+ /* GE, LT, GT, LE */
+ .byte 0x01, 0x00, 0x15, 0x12
+
+.code 32
+.text
+.align 4
+ .extern __breakpoints_num__
+ .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__sendAckOrNak /* Send Ack or Nak to indicate success/failure of message receipt */
+ .extern dbg__runloopTasks /* Platform specific Run Loop processing */
+
+
+/* The Debugger Interface can handle a total of (n-1) Breakpoint States and 1 Single Stepping State,
+ * where n is a power of 2. The value of n is given by __breakpoints_num__ defined in the linker file.
+ *
+ * In addition, a Debugger Stack contains the User Mode Register Stack Frame + SPSR + Bkpt Instr Addr.
+ * These are currently stored in the .stack area in RAM, so there is no fixed address
+ * location that is used for this purpose.
+ *
+ * The Breakpoint feature assumes that the program is executed in RAM. It is not possible
+ * to set dynamic breakpoints for programs executed from Flash in the AT91SAM7S which lacks
+ * instruction breakpointing support in hardware without using JTAG. The only type of breakpoints
+ * that can be supported in Flash based programs are Static (predefined) breakpoints inserted into
+ * the code.
+ *
+ * Each Breakpoint State i is a struct comprising the Breakpoint Address + Memory Contents
+ * stored in 8 bytes as:
+ * [High Memory Address]
+ * ADDR [i*8+4]: Memory Contents (32 bits)
+ * ADDR [i*8]: Breakpoint Address (31 bits, b0 = THUMB flag [not implemented yet])
+ * [Low Memory Address]
+ *
+ * A Non-zero Breakpoint Address means that the breakpoint is active, whereas the memory contents
+ * contains the instruction which resided at that address initially (now replaced by a BKPT <index>
+ * instruction).
+ * Note: Currently it is not possible to resume execution of a program with breakpoints enabled
+ * after a RESET, since the RESET will clear all contents of the stack, destroying the instruction
+ * contained in a given breakpoint.
+ * Fortunately the NXT will also need to reload the program into RAM so this is not expected to be
+ * an issue.
+ *
+ * The Memory Map for the Debugger State is as follows:
+ *
+ * [High Memory Address] __breakpoints_end__
+ * Breakpoint 07 State
+ * Breakpoint 06 State
+ * ...
+ * Breakpoint 02 State
+ * Breakpoint 01 State
+ * Single Step State __debugger_stack__ / __breakpoints_start__
+ * Previous Mode R15
+ * Previous Mode R14
+ * Previous Mode R13
+ * ...
+ * User Mode R02
+ * User Mode R01
+ * User Mode R00
+ * Previous Mode CPSR (UNDEF SPSR)
+ * UNDEF Next Instr Addr __debugger_stack_bottom__
+ * [Low Memory Address]
+ *
+ * Each Breakpoint State will initially be zeroed.
+ *
+ */
+ /* FIXME: The Debugger Stack Frame is probably not 100% consistent with the order that
+ GDB expects in the g/G messages. CSPR is probably located above R15 */
+
+#ifndef __NXOS__
+/****************************************************************************
+ *
+ * GDB Debugger Invocation Routine for NXT Firmware
+ *
+ ****************************************************************************/
+ .code 16
+ .align 2
+ .global cCommHandleDebug
+ .thumb_func
+/* cCommHandleDebug
+ * Switch Mode to Debugger.
+ * Used by NXT Firmware only
+ *
+ * UWORD cCommHandleDebug(UBYTE *pInBuf, UBYTE CmdBit, UWORD MsgLength);
+ *
+ * This routine is called from cCommInterprete either in normal operation mode (SVC)
+ * or else when we're in debug mode (ABORT) which uses the cCommCtrl() routine to handle
+ * I/O with the Host.
+ *
+ * On entry, the message is copied from the NXT buffer into our own buffers.
+ *
+ * If this is accessed from normal operation mode, we need to switch mode to
+ * ABORT mode to handle the incoming message using a Manual Breakpoint instruction.
+ * When DEBUG is exited, the execution resumes from the instruction following the Breakpoint.
+ */
+cCommHandleDebug:
+/* Arg Registers are not preserved since this is invoked explicitly */
+ push {lr} /* store arg registers */
+ bl dbg__copyNxtDebugMsg /* setup Debugger Message Buffers, validate input, CPSR returned in R0 */
+ _dbg_getmode r0 /* Get Debug Mode */
+ cmp r0, #(TRUE & BYTE0) /* Confine it to Byte size */
+
+ /* If Debug Mode is TRUE, this means that we're already running the Debugger */
+ beq _cCommHandleDebug_cont
+ /* Else, we're in normal operation mode (SVC), or other mode (??!) and need to force a switch to Debug mode */
+ dbg__bkpt_thumb
+_cCommHandleDebug_cont:
+ mov r0, #0 /* FIXME: Return Status */
+ pop {r1} /* Can't Pop LR directly */
+ bx r1 /* Safe code: actually we should be able to Pop PC since the caller is Thumb Mode */
+
+ .ltorg
+#endif
+
+/****************************************************************************
+ *
+ * GDB Debugger Init and Breakpoint Handler Routines
+ *
+ ****************************************************************************/
+ .code 32
+ .align 4
+ .global dbg__bkpt_init
+/* dbg__bkpt_init
+ * GDB set_debug_traps() routine
+ */
+dbg__bkpt_init:
+ push {lr}
+ bl _dbg__clear_breakpoints
+ mov r2, #0
+ ldr r1, =debug_curr_breakpoint
+ strb r2, [r1]
+ ldr r0, =debug_InMsgBuf
+ strb r2, [r0]
+ ldr r1, =debug_OutMsgBuf
+ strb r2, [r1]
+ bl dbg__comm_init /* Pass R0: Rx Buffer, R1: Tx Buffer to comm submodule */
+
+/* FIXME: Initialize other stuff here */
+ _dbg_setstate DBG_INIT
+ _dbg_setmode FALSE /* Debug Mode = False */
+ pop {lr}
+ bx lr /* Must return via BX; may have been called from Thumb mode (NXT Firmware) */
+
+
+/* _dbg__flush_icache
+ * Flush the Instruction cache
+ * Defined by GDB Stub, but not needed for ARMv4T architecture
+ */
+_dbg__flush_icache:
+ /* nop */
+ bx lr
+
+
+ .global dbg__thumb_bkpt_handler
+/* dbg__thumb_bkpt_handler
+ * GDB handle_exception() routine (Thumb Mode)
+ */
+dbg__thumb_bkpt_handler:
+/* On entry, r0 contains breakpoint index value */
+ mov r4, #BKPT16_AUTO_BKPT
+ and r4, r0, #BKPT16_AUTO_BKPT /* keep AUTO flag value in r4 */
+ bic r0, r0, #BKPT16_AUTO_BKPT /* mask out AUTO flag */
+ _dbg_setcurrbkpt_index r0 /* keep current breakpoint index in memory */
+ ldr r1, =BKPT16_MANUAL_BKPT
+ teq r0, r1
+ beq _process_manual_breakpoint_thumb
+ ldr r1, =__breakpoints_num__
+ cmp r0, r1 /* Sanity check that index is in range */
+ bhs dbg__bkpt_offset_outofrange
+/* Valid index value found */
+ teq r4, #0 /* Check if AUTO flag set */
+ bne _process_auto_breakpoint
+/* else */
+ _dbg_set_bkpt_type DBG_NORMAL_BKPT_THUMB
+ b _process_normal_breakpoint
+
+ .global dbg__arm_bkpt_handler
+/* dbg__arm_bkpt_handler
+ * GDB handle_exception() routine (ARM Mode)
+ */
+dbg__arm_bkpt_handler:
+/* On entry, r0 contains breakpoint index value */
+ mov r4, #BKPT32_AUTO_BKPT
+ and r4, r0, #BKPT32_AUTO_BKPT /* keep AUTO flag value in r4 */
+ bic r0, r0, #BKPT32_AUTO_BKPT /* mask out AUTO flag */
+ _dbg_setcurrbkpt_index r0 /* keep current breakpoint index in memory */
+ ldr r1, =BKPT32_MANUAL_BKPT
+ teq r0, r1
+ beq _process_manual_breakpoint_arm
+ ldr r1, =__breakpoints_num__
+ cmp r0, r1 /* Sanity check that index is in range */
+ bhs dbg__bkpt_offset_outofrange
+/* Valid index value found */
+ teq r4, #0 /* Check if AUTO flag set */
+ bne _process_auto_breakpoint
+/* else */
+ _dbg_set_bkpt_type DBG_NORMAL_BKPT_ARM
+/* b _process_normal_breakpoint */
+
+_process_normal_breakpoint:
+ bl _dbg__restore_breakpoints
+ bl _dbg__restore_singlestep
+ bl _dbg__clear_singlestep
+ bl _dbg__flush_icache
+ b dbg__bkpt_waitCMD
+
+_process_auto_breakpoint:
+/* Load Auto BKPT for Breakpoint index given in r0 */
+ _index2bkptindex_addr r0, r1 /* Calculate Breakpoint Entry Address */
+ ldm r1, {r1, r2} /* r1: Breakpoint Address, r2: Breakpoint Instruction */
+ teq r1, #0 /* Check that Breakpoint is active */
+ beq dbg__bkpt_inactive
+ bl _dbg__activate_one_breakpoint
+ bl _dbg__restore_singlestep
+ bl _dbg__clear_singlestep
+ _dbg_set_bkpt_type DBG_AUTO_BKPT
+ b _dbg__switch2undefmode
+
+/* _dbg__switch2undefmode
+ * Common internal routine to return execution to user program
+ */
+_dbg__switch2undefmode_withAck:
+ bl __dbg__procAckOnly /* send Ack to keep GDB server happy */
+ bl dbg__runloopTasks /* Service run loop tasks */
+_dbg__switch2undefmode:
+ 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
+ mov pc, lr /* Exit via UNDEF mode */
+
+_process_manual_breakpoint_thumb:
+ _dbg_set_bkpt_type DBG_MANUAL_BKPT_THUMB
+ b dbg__bkpt_waitCMD
+
+_process_manual_breakpoint_arm:
+ _dbg_set_bkpt_type DBG_MANUAL_BKPT_ARM
+/* b dbg__bkpt_waitCMD */
+
+dbg__bkpt_inactive:
+/* b dbg__bkpt_waitCMD */
+
+dbg__bkpt_offset_outofrange:
+/* b dbg__bkpt_waitCMD */
+
+ .global dbg__bkpt_waitCMD
+/* dbg__bkpt_waitCMD
+ * GDB Stub Remote Command Handler
+ */
+
+/****************************************************************************
+ *
+ * GDB Server Command Processing Routines
+ *
+ ****************************************************************************/
+dbg__bkpt_waitCMD:
+ /* We enter this code section when a Breakpoint Triggers */
+ _dbg_setmode TRUE /* Debug Mode = True */
+ _dbg_getstate r0
+ cmp r0, #DBG_CONFIGURED
+ blo dbg__bkpt_waitCMD_cont /* Not configured yet, don't send Breakpoint Signal Response */
+ bl _dbg__cmd_Status /* Send signal response to the GDB server */
+
+dbg__bkpt_waitCMD_cont:
+ bl dbg__runloopTasks /* Execute housekeeping tasks while in ABRT mode */
+ 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 */
+ 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 Ctrl-C or '$' */
+ teq r0, #MSGBUF_CTRLC
+ bne _dbg_check_gdb_command
+ /* Ctrl-C detected, do nothing (wait for next command from GDB) */
+#if 0
+ /* On entering the Debugger via Ctrl-C, _dbg__cmd_Status has already sent a reply, so just keep quiet */
+ bl __dbg__procAckOnly /* send Ack */
+#endif
+ 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 */
+ ldrb r0, [r4], #1 /* Look for command char */
+ bl _dbg__cmdChar2Index /* Index in R0 */
+ mov r1, #CMDINDEX_OUTOFRANGE
+ teq r0, r1
+ bne _dbg__cmdExists /* Found valid command, execute it */
+_dbg_unknown_command:
+ bl _dbg__nop /* Command character not recognized, send empty response to GDB server */
+ b dbg__bkpt_waitCMD_cont
+
+#if 0
+ moveq r0, #MSG_UNKNOWNCMD /* Out of range, Command character not recognized */
+ beq _dbg__cmdError /* Send response to GDB server */
+#endif
+
+_dbg__cmdExists:
+ mov r3, r0 /* put Command Handler Index in R3 */
+ mov r0, r4 /* R0 now contains Input Message Buffer Parameter Pointer (previously in R4) */
+ _dbg_jumpTableHandler debug_cmdJumpTable, r2, r3 /* Call Command Handler Routine, use R2 as jump address pointer */
+ b dbg__bkpt_waitCMD_cont
+
+_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:
+ * r0: command character
+ * On exit:
+ * r0: jump table index (-1 for command not found)
+ * R1: destroyed
+ * R2: destroyed
+ * R3: destroyed
+ */
+_dbg__cmdChar2Index:
+ mov r1, r0 /* Copy command character to r1 */
+ mov r0, #0 /* Clear return value */
+ ldr r3, =debug_cmdIndexTable /* Convert command to index using r3 as Index Lookup Address Pointer */
+1: ldrb r2, [r3, r0] /* Get table entry */
+ teq r2, #0
+ moveq r0, #CMDINDEX_OUTOFRANGE /* End of Index Table, Not found */
+ beq _exit_cmdIndexTable
+ teq r1, r2
+ addne r0, #1 /* Increment Index */
+ bne 1b /* No match, skip to next command char */
+_exit_cmdIndexTable:
+ bx lr
+
+/* __dbg__cmdParamLen
+ * Determines the length of the parameter buffer for a given command
+ * On entry:
+ * R0: parameter buffer pointer (contents after '$' and '<cmdchar>')
+ * On exit:
+ * R0: Address of parameter buffer (preserved)
+ * R1: length
+ */
+__dbg__cmdParamLen:
+ stmfd sp!, {r0,r2,lr} /* R2: scratch register */
+ mov r1, #0
+1: ldrb r2, [r0], #1
+ teq r2, #0
+ addne r1, r1, #1
+ bne 1b
+ ldmfd sp!, {r0,r2,pc}
+
+/* __dbg__procCmdOk
+ * Common subroutine exit stub to return Command Ok Status for Command Handlers
+ * DO NOT CALL THIS STUB DIRECTLY! It Assumes that the return address is in the stack.
+ *
+ */
+__dbg__procCmdOk:
+ _dbg_outputMsgStatusOk
+ b __dbg__sendDebugMsgExit
+
+/* __dbg__procUnimplementedError
+ * Common subroutine exit stub to handle Unimplemented GDB Command Error
+ * DO NOT CALL THIS STUB DIRECTLY! It Assumes that the return address is in the stack.
+ * Note: GDB Remote Protocol specifies returning blank message ('+$')
+ *
+ */
+__dbg__procUnimplementedError:
+ _dbg_outputMsgValidResponse
+ b __dbg__sendDebugMsgExit
+
+/* __dbg__procCmdParamError
+ * Common subroutine exit stub to handle Command Parameter Error for Command Handlers
+ * DO NOT CALL THIS STUB DIRECTLY! It Assumes that the return address is in the stack.
+ *
+ */
+__dbg__procCmdParamError:
+ mov r1, #MSG_UNKNOWNPARAM
+ b __dbg__procErrorMsg
+
+/* __dbg__procCmdReturnInputLengthError
+ * Common subroutine exit stub to handle Command Input Length Error for Command Handlers
+ * DO NOT CALL THIS STUB DIRECTLY! It Assumes that the return address is in the stack.
+ *
+ */
+__dbg__procCmdReturnInputLengthError:
+ mov r1, #MSG_ERRINLENGTH
+ b __dbg__procErrorMsg
+
+/* __dbg__procCmdReturnOutputLengthError
+ * Common subroutine exit stub to handle Command Return Output Error for Command Handlers
+ * DO NOT CALL THIS STUB DIRECTLY! It Assumes that the return address is in the stack.
+ *
+ */
+__dbg__procCmdReturnOutputLengthError:
+ mov r1, #MSG_ERROUTLENGTH
+ b __dbg__procErrorMsg
+
+/* __dbg__procBreakpointAddrError
+ * Common subroutine exit stub to handle Breakpoint Address Error for Breakpoint Insert/Remove Handlers
+ * DO NOT CALL THIS STUB DIRECTLY! It Assumes that the return address is in the stack.
+ *
+ */
+__dbg__procBreakpointAddrError:
+ mov r1, #MSG_UNKNOWNBRKPT
+ b __dbg__procErrorMsg
+
+
+__dbg__procErrorMsg:
+ __dbg_outputErrMsg
+ /* b __dbg__sendDebugMsgExit */
+
+__dbg__sendDebugMsgExit:
+ bl dbg__putDebugMsg /* Send error response to the GDB server */
+ ldmfd sp!, {pc}
+
+/* _dbg__cmd_Status
+ * Status Command Handler
+ * On entry:
+ * r0: parameter buffer (contents after '$' and '<cmdchar>')
+ * On exit:
+ * r0, r1, r2, r3: destroyed
+ */
+_dbg__cmd_Status:
+ stmfd sp!, {lr}
+ _dbg_outputMsgStatusSig 0x0 /* FIXME: Dummy Signal number */
+ b __dbg__sendDebugMsgExit
+
+/* _dbg__cmd_Query
+ * Query Command Handler
+ * On entry:
+ * r0: parameter buffer (contents after '$' and '<cmdchar>')
+ * [varied, see GDB General Packets query docs]
+ * http://sourceware.org/gdb/current/onlinedocs/gdb/General-Query-Packets.html
+ * On exit:
+ * r0, r1, r2, r3: destroyed
+ */
+_dbg__cmd_Query:
+ stmfd sp!, {lr}
+ _dbg_setstate DBG_CONFIGURED /* We have exchanged query messages with the GDB server */
+ b __dbg__procUnimplementedError /* FIXME: return an empty message to GDB (no modifiable settings) */
+
+
+/* _dbg__cmd_GetOneReg
+ * Get One Register Value Command Handler
+ * Valid command parameter x is from '0' to 'F' for User Mode Registers R0-R15,
+ * '18' for FPSCR (dummy), and '19' for CPSR
+ * On entry:
+ * r0: parameter buffer pointer (contents after '$' and '<cmdchar>')
+ * x
+ * On exit:
+ * r0, r1, r2, r3: destroyed
+ *
+ */
+_dbg__cmd_GetOneReg:
+ stmfd sp!, {lr}
+ bl __dbg__cmdParamLen
+ cmp r1, #CMD_REG_GETONE_MINPARAMLEN /* Check for correct length */
+ blo __dbg__procCmdParamError /* Unexpected input, report error */
+ cmp r1, #CMD_REG_GETONE_MAXPARAMLEN /* Check for correct length */
+ bhi __dbg__procCmdParamError /* Unexpected input, report error */
+ bl ascii2hex_varlen_be /* convert ASCII reg enum to Hex (in R0), R1 has address of next buffer char */
+
+_dbg__proc_getRegister:
+ mov r3, r0 /* Keep register index safe */
+ _dbg_outputMsgValidResponse /* R0: address of output message buffer data pointer (after response prefix) */
+ mov r1, r3 /* Move register index value to R1 */
+ bl _dbg_outputOneRegValue /* update output buffer */
+ _asciiz r0, r1
+ bl dbg__putDebugMsg /* Send response to the GDB server */
+ ldmfd sp!, {pc}
+
+/* _dbg_outputOneRegValue
+ * Given Register Enum (0-F: R0-R15, 0x19: CPSR, OtherVal: dummy), output hex char to buffer
+ * On entry:
+ * r0: output message buffer pointer
+ * r1: register enum (0-F, 0x19)
+ * On exit:
+ * r0: updated (points to next character slot at end of Output Buffer)
+ * r1: original output message buffer pointer
+ * r2: destroyed
+ */
+_dbg_outputOneRegValue:
+ stmfd sp!, {lr}
+ cmp r1, #REG_PC
+ addls r2, r1, #DBGSTACK_USERREG_INDEX /* Convert register enum to Debug Stack index */
+ bls _retrieve_RegVal
+
+ cmp r1, #REG_CPSR
+ moveq r2, #DBGSTACK_USERCPSR_INDEX /* convert register enum to Debug Stack index */
+ beq _retrieve_RegVal
+
+ cmp r1, #REG_FPSCR
+ bne _exit_dbg_outputOneRegValue /* No match, skip */
+
+_output_dummy_fpscr:
+ /* Output Dummy FPSCR value */
+ mov r1, #0
+ b _output2buffer /* Output all zeros for FPSCR */
+
+_retrieve_RegVal:
+ _getdbgregisterfromindex r2, r1 /* Retrieve Register contents into R1 */
+
+_output2buffer:
+
+#ifdef __BIG_ENDIAN__
+ bl word2ascii_be /* Convert and put hex chars into Output Message Buffer */
+#else
+ bl word2ascii_le /* Convert and put hex chars into Output Message Buffer */
+#endif
+
+_exit_dbg_outputOneRegValue:
+ ldmfd sp!, {pc}
+
+/* _dbg__cmd_GetAllRegs
+ * Get All Register Values Command Handler
+ * Output Buffer returns register values in the order: User R0, R1, R2, ..., R15, CPSR
+ * On entry:
+ * r0: parameter buffer pointer (contents after '$' and '<cmdchar>')
+ * <NULL> (no parameters)
+ * On exit:
+ * r0, r1, r2, r3: destroyed
+ */
+_dbg__cmd_GetAllRegs:
+ stmfd sp!, {lr}
+ bl __dbg__cmdParamLen
+ teq r1, #CMD_REG_GETALL_PARAMLEN /* Check for correct length */
+ bne __dbg__procCmdParamError /* Unexpected input, report error */
+
+ _dbg_outputMsgValidResponse /* R0: address of output message buffer data pointer (after response prefix) */
+
+ /* We must return R0-R15, then CPSR */
+ mov r3, #REG_R0 /* Output User Register Values first */
+1: mov r1, r3
+ bl _dbg_outputOneRegValue /* update output buffer */
+ add r3, r3, #1 /* increment index */
+ cmp r3, #REG_PC
+ bls 1b /* process all the registers */
+_get_cpsr:
+ mov r1, #REG_CPSR /* Output User CPSR Value last */
+ bl _dbg_outputOneRegValue /* update output buffer */
+
+ _asciiz r0, r1
+ bl dbg__putDebugMsg /* Send response to the GDB server */
+ ldmfd sp!, {pc}
+
+/* _dbg_setOneRegValue
+ * Given Register Enum (0-F: R0-R15, 0x19: CPSR, OtherVal: dummy), output hex char to buffer
+ * On entry:
+ * r0: parameter buffer pointer
+ * r1: register enum (0-F, 0x19)
+ * On exit:
+ * r0: (Updated) Address of parameter in buffer
+ * r1, r2, r3: destroyed
+ */
+_dbg_setOneRegValue:
+ stmfd sp!, {lr}
+ cmp r1, #REG_PC
+ addls r2, r1, #DBGSTACK_USERREG_INDEX /* Convert register enum to Debug Stack index */
+ bls _store_RegVal
+
+ cmp r1, #REG_CPSR
+ moveq r2, #DBGSTACK_USERCPSR_INDEX /* convert register enum to Debug Stack index */
+ beq _store_RegVal
+
+ cmp r1, #REG_FPSCR
+ bne _exit_dbg_setOneRegValue /* No match, skip */
+ /* FIXME: If we get SetAllRegs with FP reg values, this will not skip pass the FP regs! */
+
+_set_dummy_fpscr:
+ /* Set dummy FPSCR value (ignored) */
+ add r1, r0, #CMD_REG_REGPARAMLEN /* Just increment the pointer */
+ b _done_store_RegVal
+
+_store_RegVal:
+#ifdef __BIG_ENDIAN__
+ bl ascii2word_be
+#else
+ bl ascii2word_le
+#endif
+ /* R0: value, R1: pointer to next char in buffer */
+ _setdbgregisterfromindex r2, r0, r3 /* Set Register contents in R0, using index in R2, and scratch register R3 */
+_done_store_RegVal:
+ mov r0, r1 /* Copy buffer pointer to next parameter to R0 for return value */
+_exit_dbg_setOneRegValue:
+ ldmfd sp!, {pc}
+
+
+/* _dbg__cmd_SetOneReg
+ * Set One Register Value Command Handler
+ * Valid command parameter x is from '0' to 'F' for User Mode Registers R0-R15,
+ * '18' for FPSCR (dummy), and '19' for CPSR
+ * On entry:
+ * r0: parameter buffer pointer (contents after '$' and '<cmdchar>')
+ * x=rrrr
+ * On exit:
+ * r0, r1, r2, r3, r4: destroyed
+ *
+ */
+_dbg__cmd_SetOneReg:
+ stmfd sp!, {lr}
+ bl __dbg__cmdParamLen
+ cmp r1, #CMD_REG_SETONE_MINPARAMLEN /* Check for correct length */
+ blo __dbg__procCmdParamError /* Unexpected input, report error */
+ cmp r1, #CMD_REG_SETONE_MAXPARAMLEN /* Check for correct length */
+ bhi __dbg__procCmdParamError /* Unexpected input, report error */
+
+ bl ascii2hex_varlen_be /* convert ASCII reg enum to Hex (in R0), R1 has address of next buffer char */
+ mov r4, r0 /* Keep enum in R4 */
+ _check_msgassignment r1 /* R1 points to next char in buffer */
+ bne __dbg__procCmdParamError /* Can't find '=' */
+
+_dbg__proc_setRegister:
+ mov r0, r1 /* move parameter buffer pointer to R0 */
+ mov r1, r4 /* and retrieve enum to R1 to call _dbg_setOneRegValue */
+ bl _dbg_setOneRegValue
+ b __dbg__procCmdOk
+
+/* _dbg__cmd_SetAllReg
+ * Set All Register Values Command Handler
+ * On entry:
+ * r0: parameter buffer pointer (contents after '$' and '<cmdchar>')
+ * rrrrRRRRrrrr... (17 registers)
+ * On exit:
+ * r0, r1, r2, r3, r4: destroyed
+ *
+ */
+_dbg__cmd_SetAllRegs:
+ /* Assumes that the registers are in the sequence R0, R1, ... R15, CPSR */
+ stmfd sp!, {lr}
+ bl __dbg__cmdParamLen /* R0: pointer to parameters in buffer */
+ teq r1, #CMD_REG_SETALL_PARAMLEN /* Check for correct length */
+ bne __dbg__procCmdParamError /* Unexpected input, report error */
+ mov r4, #REG_R0 /* R4: register enum, starting with enum for R0 */
+1: mov r1, r4 /* Copy enum to R1; R0 already points to current parameter */
+ bl _dbg_setOneRegValue /* R0: next parameter address pointer */
+ add r4, r4, #1 /* increment index */
+ cmp r4, #REG_PC
+ bls 1b
+
+_set_cpsr:
+#if 0
+ /* GDB was not happy when this was added */
+ /* Read dummy FPSCR value (ignored) */
+#ifdef __BIG_ENDIAN__
+ bl ascii2word_be
+#else
+ bl ascii2word_le
+#endif
+ mov r0, r1 /* Copy buffer pointer to next parameter to R0 for return value */
+#endif
+
+ mov r1, #REG_CPSR /* Use CPSR enum */
+ bl _dbg_setOneRegValue /* R0: next parameter address pointer */
+ ldrb r0, [r0]
+ teq r0, #0 /* Look for ASCIIZ character to terminate loop */
+ beq __dbg__procCmdOk
+ bne __dbg__procCmdParamError /* Unexpected input, report error */
+
+/* _dbg__nop
+ * NOP Command Handler (placeholder)
+ * On entry:
+ * r0: parameter buffer (contents after '$' and '<cmdchar>')
+ * On exit:
+ * r0, r1, r2, r3: destroyed
+ */
+_dbg__nop:
+ stmfd sp!, {lr}
+ b __dbg__procUnimplementedError
+
+/* _dbg__cmd_ReadMem
+ * Read Memory Contents Command Handler
+ * Output Buffer returns memory contents
+ * On entry:
+ * r0: parameter buffer pointer (contents after '$' and '<cmdchar>')
+ * AA..AA,LLLL
+ * On exit:
+ * r0, r1, r2, r3, r4: destroyed
+ */
+_dbg__cmd_ReadMem:
+ stmfd sp!, {lr}
+ bl __dbg__cmdParamLen
+#if 0
+ teq r1, #CMD_MEM_READ_PARAMLEN /* Check for correct length */
+ bne __dbg__procCmdParamError /* Unexpected input, report error */
+ bl ascii2word_be /* convert ASCII address location to Hex (in R0), R1 has address of next buffer char */
+#endif
+ bl ascii2hex_varlen_be /* convert ASCII address to Hex (in R0), R1 has address of next buffer char */
+ mov r3, r0 /* Keep Address location in R3 */
+ _check_msgseparator r1
+ bne __dbg__procCmdParamError /* Can't find ',' */
+ mov r0, r1 /* move buffer pointer to R0 for subsequent processing */
+ bl ascii2hex_varlen_be /* convert ASCII length to Hex (in R0), R1 has address of next buffer char */
+ cmp r0, #CMD_MEM_MAXREADBYTES /* Don't overflow our buffer (2 x CMD_MEM_MAXREADBYTES) */
+ bhi __dbg__procCmdReturnOutputLengthError /* Requested Length greater than buffer size, return error */
+ mov r4, r0 /* Keep numbytes in R4 */
+ /* FIXME: Should validate the address? */
+
+ _dbg_outputMsgValidResponse /* R0: address of output message buffer data pointer (after response prefix) */
+1: ldrb r1, [r3], #1
+ bl byte2ascii /* update output buffer */
+ subs r4, r4, #1
+ bne 1b
+
+ _asciiz r0, r1
+ bl dbg__putDebugMsg /* Send response to the GDB server */
+ ldmfd sp!, {pc}
+
+
+/* _dbg__cmd_WriteMem
+ * Write Memory Contents Command Handler
+ * On entry:
+ * r0: parameter buffer pointer (contents after '$' and '<cmdchar>')
+ * AA..AA,LLLL::bb..bb
+ * On exit:
+ * r0, r1, r2, r3, r4: destroyed
+ */
+_dbg__cmd_WriteMem:
+ stmfd sp!, {lr}
+ bl __dbg__cmdParamLen
+#if 0
+ cmp r1, #CMD_MEM_WRITE_MINPARAMLEN /* Check for correct (minimum) length */
+ blo __dbg__procCmdParamError /* Unexpected input, report error */
+ sub r4, r1, #CMD_MEM_WRITE_MINPARAMLEN /* R4: Number of ASCII Hex chars for byte writes */
+ bl ascii2word_be /* convert ASCII address location to Hex (in R0), R1 has address of next buffer char */
+#endif
+ bl ascii2hex_varlen_be /* convert ASCII address to Hex (in R0), R1 has address of next buffer char */
+ mov r3, r0 /* Keep Address location in R3 */
+ _check_msgseparator r1
+ bne __dbg__procCmdParamError /* Can't find ',' */
+ mov r0, r1 /* move buffer pointer to R0 for subsequent processing */
+ bl ascii2hex_varlen_be /* convert ASCII length to Hex (in R0), R1 has address of next buffer char */
+ cmp r0, r4, asr #1 /* is Number of bytes to write == (number of ASCII Hex Chars / 2)? */
+ bne __dbg__procCmdParamError /* Number of bytes does not match argument length */
+ cmp r0, #CMD_MEM_MAXWRITEBYTES /* Don't overflow our buffer (2 x CMD_MEM_MAXWRITEBYTES) */
+ bhi __dbg__procCmdReturnInputLengthError /* Requested Length greater than buffer size, return error */
+ mov r4, r0 /* Keep numbytes in R4 */
+ /* FIXME: Should validate the address? */
+ _check_msgargument r1
+ bne __dbg__procCmdParamError /* Can't find ':' */
+
+1: mov r0, r1
+ bl ascii2byte /* convert ASCII Hex value into byte value */
+ strb r0, [r3], #1 /* Store into memory location */
+ subs r4, r4, #1
+ bne 1b
+ b __dbg__procCmdOk
+
+/* _dbg__cmd_Continue
+ * Continue User Program Execution Command Handler
+ * Setup breakpoints before resuming execution of program.
+ *
+ * If Address is specified, update the next instruction address to specified address
+ *
+ * If this is a Normal Breakpoint, then we need to install an Autobreakpoint at next instruction address
+ * and resume from current (Breakpoint) exception address
+ * Else (it is a Manual Breakpoint or Address Specified)
+ * We need to resume from the next instruction address
+ * On entry:
+ * r0: parameter buffer pointer (contents after '$' and '<cmdchar>')
+ * Optional: AA..AA
+ * On exit:
+ * r0-r7: destroyed
+ * Note: This routine does not return to caller. Instead it switches
+ * operating mode to UNDEF and returns to previously active program
+ */
+_dbg__cmd_Continue:
+ /* Don't put anything on the stack, we won't return to the Debugger Run Loop */
+ bl __dbg__cmdParamLen
+ cmp r1, #CMD_CONTINUE_MINPARAMLEN /* Check for correct parameter length */
+ beq _dbg__cont_check_breakpoint_type /* Continue from current PC */
+
+_dbg__cont_fromAddr:
+ bl ascii2hex_varlen_be /* convert ASCII address to Hex (in R0), R1 has address of next buffer char */
+ /* Continue from Specified Address */
+ 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__cont_is_manual_bkpt_or_address_specified
+
+_dbg__cont_check_breakpoint_type:
+ _dbg_get_bkpt_type r0
+ teq r0, #DBG_MANUAL_BKPT_ARM
+ beq _dbg__cont_is_manual_bkpt_or_address_specified
+ teq r0, #DBG_MANUAL_BKPT_THUMB
+ beq _dbg__cont_is_manual_bkpt_or_address_specified
+
+_dbg__cont_is_normal_breakpoint:
+/* FIXME: _dbg_following_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 */
+ _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 */
+ bl _dbg_following_instruction_addr /* following 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 */
+ b _dbg__switch2undefmode_withAck
+
+_dbg__cont_is_manual_bkpt_or_address_specified:
+ bl _dbg__activate_breakpoints /* Restore exisiting breakpoints */
+ b _dbg__switch2undefmode_withAck
+
+/* _dbg__cmd_Step
+ * Step User Program Execution Command Handler
+ * Setup breakpoints before resuming execution of program.
+ *
+ * If Address is specified, update the next instruction address to specified address
+ *
+ * If this is a Normal Breakpoint, then we need to install a Step Breakpoint at next instruction address
+ * and resume from current (Breakpoint) exception address
+ * Else (it is a Manual Breakpoint or Address specified)
+ * We need to install a Step Breakpoint at the following instruction address (after the next instruction address)
+ * and resume from the next instruction address
+ * On entry:
+ * r0: parameter buffer pointer (contents after '$' and '<cmdchar>')
+ * Optional: AA..AA
+ * On exit:
+ * r0-r7: destroyed
+ * Note: This routine does not return to caller. Instead it switches
+ * operating mode to UNDEF and returns to previously active program
+ */
+_dbg__cmd_Step:
+ /* Don't put anything on the stack, we won't return to the Debugger Run Loop */
+ bl __dbg__cmdParamLen
+ cmp r1, #CMD_STEP_MINPARAMLEN /* Check for correct parameter length */
+ beq _dbg__step_check_breakpoint_type /* Step from current PC */
+
+_dbg__step_fromAddr:
+ bl ascii2hex_varlen_be /* convert ASCII address to Hex (in R0), R1 has address of next buffer char */
+ /* Step from Specified Address */
+ 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_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
+ beq _dbg__step_is_manual_bkpt
+
+_dbg__step_is_normal_breakpoint:
+/* FIXME: _dbg_following_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 */
+ _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, r0 /* Retrieve Register contents into R1 */
+ /* b _dbg__step_is_manual_bkpt_or_address_specified */
+
+_dbg__step_is_manual_bkpt_or_address_specified:
+ bl _dbg_following_instruction_addr /* following instruction address returned in r1 */
+ bl _dbg__install_singlestep /* Setup Single Step, next instruction address returned in r1 */
+ bl _dbg__activate_singlestep
+ b _dbg__switch2undefmode_withAck
+
+
+/* _dbg__proc_brkpt_params
+ * Process Breakpoint Parameters
+ * On entry:
+ * r0: parameter buffer pointer (contents after '$' and '<cmdchar>')
+ * t,AA..AA,k
+ * On exit:
+ * r0: non-zero = breakpoint address; 0 = parameter error
+ * r1: destroyed
+ * r2: destroyed
+ * r3: destroyed
+ */
+_dbg__proc_brkpt_params:
+ /* FIXME: Add support for watchpoints */
+ stmfd sp!, {lr}
+ mov r3, r0 /* Keep parameter buffer address in R3 */
+ ldrb r0, [r3], #1 /* get breakpoint type t */
+ bl char2hex
+ cmp r0, #CMD_BKPT_TYPE_BREAK_MEMORY
+ bne _dbg__proc_brkpt_params_error /* We only support memory breakpoints for now */
+ _check_msgseparator r3
+ bne _dbg__proc_brkpt_params_error /* Something wrong with the parameters */
+ mov r0, r3 /* Check Address */
+ bl ascii2hex_varlen_be /* convert ASCII address to Hex (in R0), R1 has address of next buffer char */
+ mov r3, r0 /* Keep breakpoint address in R3 */
+ _check_msgseparator r1
+ bne _dbg__proc_brkpt_params_error /* Something wrong with the parameters */
+ ldrb r0, [r1], #1 /* get breakpoint kind k */
+ bl char2hex
+ cmp r0, #CMD_BKPT_KIND_THUMB
+ orreq r3, r3, #1 /* Mark Thumb breakpoints */
+ beq _exit_dbg__proc_brkpt_params
+ cmp r0, #CMD_BKPT_KIND_ARM
+ beq _exit_dbg__proc_brkpt_params /* ARM breakpoint */
+
+_dbg__proc_brkpt_params_error:
+ mov r3, #0 /* Unrecognized breakpoint type */
+_exit_dbg__proc_brkpt_params:
+ mov r0, r3 /* return breakpoint address */
+ ldmfd sp!, {pc}
+
+/* _dbg__cmd_InsertBreakpoint
+ * Add Breakpoint
+ * On entry:
+ * r0: parameter buffer pointer (contents after '$' and '<cmdchar>')
+ * t,AA..AA,k
+ * On exit:
+ * r0, r1, r2, r3: destroyed
+ */
+_dbg__cmd_InsertBreakpoint:
+ stmfd sp!, {lr}
+ bl __dbg__cmdParamLen
+ teq r1, #CMD_BKPT_INSERT_MINPARAMLEN /* Check for correct length */
+ blo __dbg__procCmdParamError /* Unexpected input, report error */
+ bl _dbg__proc_brkpt_params /* R0: Breakpoint Address */
+ teq r0, #0
+ beq __dbg__procBreakpointAddrError /* Thumb2 instructions, or unknown kind */
+ mov r3, r0 /* Keep breakpoint address in R3 */
+ mov r0, #0 /* Empty Breakpoint entry */
+ bl _dbg_find_breakpoint_slot /* Look for an available breakpoint slot, return index in R0 */
+ cmp r0, #CMD_BKPT_NOTFOUND
+ beq __dbg__procBreakpointAddrError /* No empty slot! */
+ mov r1, r3 /* Move breakpoint address to R1 */
+ bl _dbg__install_one_breakpoint /* r0: index, r1: instruction address */
+ b __dbg__procCmdOk
+
+/* _dbg__cmd_RemoveBreakpoint
+ * Remove Breakpoint
+ * On entry:
+ * r0: parameter buffer pointer (contents after '$' and '<cmdchar>')
+ * t,AA..AA,k
+ * On exit:
+ * r0, r1, r2, r3: destroyed
+ */
+_dbg__cmd_RemoveBreakpoint:
+ stmfd sp!, {lr}
+ bl __dbg__cmdParamLen
+ teq r1, #CMD_BKPT_REMOVE_MINPARAMLEN /* Check for correct length */
+ blo __dbg__procCmdParamError /* Unexpected input, report error */
+ bl _dbg__proc_brkpt_params /* R0: Breakpoint Address */
+ teq r0, #0
+ beq __dbg__procBreakpointAddrError /* Thumb2 instructions, or unknown kind */
+ bl _dbg_find_breakpoint_slot /* Look for matching breakpoint slot, return index in R0 */
+ cmp r0, #CMD_BKPT_NOTFOUND
+ beq __dbg__procBreakpointAddrError /* Specified Breakpoint not found! */
+ _index2bkptindex_addr r0, r1 /* Calculate Breakpoint Entry Address */
+ mov r0, r1 /* Move it to R0 for subroutine call */
+ bl _dbg__clear_one_breakpoint /* R0: address of breakpoint to clear */
+ b __dbg__procCmdOk
+
+
+
+
+/****************************************************************************
+// Selected Routines from the eCos arm_stub.c related to next instruction address
+// determination in ARM processors.
+
+//========================================================================
+//
+// arm_stub.c
+//
+// Helper functions for stub, generic to all ARM processors
+//
+//========================================================================
+// ####ECOSGPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+//
+// eCos is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 or (at your option) any later
+// version.
+//
+// eCos is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with eCos; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// As a special exception, if other files instantiate templates or use
+// macros or inline functions from this file, or you compile this file
+// and link it with other works to produce a work based on this file,
+// this file does not by itself cause the resulting work to be covered by
+// the GNU General Public License. However the source code for this file
+// must still be made available in accordance with section (3) of the GNU
+// General Public License v2.
+//
+// This exception does not invalidate any other reasons why a work based
+// on this file might be covered by the GNU General Public License.
+// -------------------------------------------
+// ####ECOSGPLCOPYRIGHTEND####
+//========================================================================
+//#####DESCRIPTIONBEGIN####
+//
+// Author(s): Red Hat, gthomas
+// Contributors: Red Hat, gthomas, jskov
+// Date: 1998-11-26
+// Purpose:
+// Description: Helper functions for stub, generic to all ARM processors
+// Usage:
+//
+//####DESCRIPTIONEND####
+//
+//========================================================================
+
+
+static int
+ins_will_execute(unsigned long ins)
+{
+ unsigned long psr = get_register(PS); // condition codes
+ int res = 0;
+ switch ((ins & 0xF0000000) >> 28) {
+ case 0x0: // EQ
+ res = (psr & PS_Z) != 0;
+ break;
+ case 0x1: // NE
+ res = (psr & PS_Z) == 0;
+ break;
+ case 0x2: // CS
+ res = (psr & PS_C) != 0;
+ break;
+ case 0x3: // CC
+ res = (psr & PS_C) == 0;
+ break;
+ case 0x4: // MI
+ res = (psr & PS_N) != 0;
+ break;
+ case 0x5: // PL
+ res = (psr & PS_N) == 0;
+ break;
+ case 0x6: // VS
+ res = (psr & PS_V) != 0;
+ break;
+ case 0x7: // VC
+ res = (psr & PS_V) == 0;
+ break;
+ case 0x8: // HI
+ res = ((psr & PS_C) != 0) && ((psr & PS_Z) == 0);
+ break;
+ case 0x9: // LS
+ res = ((psr & PS_C) == 0) || ((psr & PS_Z) != 0);
+ break;
+ case 0xA: // GE
+ res = ((psr & (PS_N|PS_V)) == (PS_N|PS_V)) ||
+ ((psr & (PS_N|PS_V)) == 0);
+ break;
+ case 0xB: // LT
+ res = ((psr & (PS_N|PS_V)) == PS_N) ||
+ ((psr & (PS_N|PS_V)) == PS_V);
+ break;
+ case 0xC: // GT
+ res = ((psr & (PS_N|PS_V)) == (PS_N|PS_V)) ||
+ ((psr & (PS_N|PS_V)) == 0);
+ res = ((psr & PS_Z) == 0) && res;
+ break;
+ case 0xD: // LE
+ res = ((psr & (PS_N|PS_V)) == PS_N) ||
+ ((psr & (PS_N|PS_V)) == PS_V);
+ res = ((psr & PS_Z) == PS_Z) || res;
+ break;
+ case 0xE: // AL
+ res = TRUE;
+ break;
+ case 0xF: // NV
+ if (((ins & 0x0E000000) >> 24) == 0xA)
+ res = TRUE;
+ else
+ res = FALSE;
+ break;
+ }
+ return res;
+}
+
+static unsigned long
+RmShifted(int shift)
+{
+ unsigned long Rm = get_register(shift & 0x00F);
+ int shift_count;
+ if ((shift & 0x010) == 0) {
+ shift_count = (shift & 0xF80) >> 7;
+ } else {
+ shift_count = get_register((shift & 0xF00) >> 8);
+ }
+ switch ((shift & 0x060) >> 5) {
+ case 0x0: // Logical left
+ Rm <<= shift_count;
+ break;
+ case 0x1: // Logical right
+ Rm >>= shift_count;
+ break;
+ case 0x2: // Arithmetic right
+ Rm = (unsigned long)((long)Rm >> shift_count);
+ break;
+ case 0x3: // Rotate right
+ if (shift_count == 0) {
+ // Special case, RORx
+ Rm >>= 1;
+ if (get_register(PS) & PS_C) Rm |= 0x80000000;
+ } else {
+ Rm = (Rm >> shift_count) | (Rm << (32-shift_count));
+ }
+ break;
+ }
+ return Rm;
+}
+
+// Decide the next instruction to be executed for a given instruction
+static unsigned long *
+target_ins(unsigned long *pc, unsigned long ins)
+{
+ unsigned long new_pc, offset, op2;
+ unsigned long Rn;
+ int i, reg_count, c;
+
+ switch ((ins & 0x0C000000) >> 26) {
+ case 0x0:
+ // BX or BLX
+ if ((ins & 0x0FFFFFD0) == 0x012FFF10) {
+ new_pc = (unsigned long)get_register(ins & 0x0000000F);
+ return ((unsigned long *)new_pc);
+ }
+ // Data processing
+ new_pc = (unsigned long)(pc+1);
+ if ((ins & 0x0000F000) == 0x0000F000) {
+ // Destination register is PC
+ if ((ins & 0x0FBF0000) != 0x010F0000) {
+ Rn = (unsigned long)get_register((ins & 0x000F0000) >> 16);
+ if ((ins & 0x000F0000) == 0x000F0000) Rn += 8; // PC prefetch!
+ if ((ins & 0x02000000) == 0) {
+ op2 = RmShifted(ins & 0x00000FFF);
+ } else {
+ op2 = ins & 0x000000FF;
+ i = (ins & 0x00000F00) >> 8; // Rotate count
+ op2 = (op2 >> (i*2)) | (op2 << (32-(i*2)));
+ }
+ switch ((ins & 0x01E00000) >> 21) {
+ case 0x0: // AND
+ new_pc = Rn & op2;
+ break;
+ case 0x1: // EOR
+ new_pc = Rn ^ op2;
+ break;
+ case 0x2: // SUB
+ new_pc = Rn - op2;
+ break;
+ case 0x3: // RSB
+ new_pc = op2 - Rn;
+ break;
+ case 0x4: // ADD
+ new_pc = Rn + op2;
+ break;
+ case 0x5: // ADC
+ c = (get_register(PS) & PS_C) != 0;
+ new_pc = Rn + op2 + c;
+ break;
+ case 0x6: // SBC
+ c = (get_register(PS) & PS_C) != 0;
+ new_pc = Rn - op2 + c - 1;
+ break;
+ case 0x7: // RSC
+ c = (get_register(PS) & PS_C) != 0;
+ new_pc = op2 - Rn +c - 1;
+ break;
+ case 0x8: // TST
+ case 0x9: // TEQ
+ case 0xA: // CMP
+ case 0xB: // CMN
+ break; // PC doesn't change
+ case 0xC: // ORR
+ new_pc = Rn | op2;
+ break;
+ case 0xD: // MOV
+ new_pc = op2;
+ break;
+ case 0xE: // BIC
+ new_pc = Rn & ~op2;
+ break;
+ case 0xF: // MVN
+ new_pc = ~op2;
+ break;
+ }
+ }
+ }
+ return ((unsigned long *)new_pc);
+ case 0x1:
+ if ((ins & 0x02000010) == 0x02000010) {
+ // Undefined!
+ return (pc+1);
+ } else {
+ if ((ins & 0x00100000) == 0) {
+ // STR
+ return (pc+1);
+ } else {
+ // LDR
+ if ((ins & 0x0000F000) != 0x0000F000) {
+ // Rd not PC
+ return (pc+1);
+ } else {
+ Rn = (unsigned long)get_register((ins & 0x000F0000) >> 16);
+ if ((ins & 0x000F0000) == 0x000F0000) Rn += 8; // PC prefetch!
+ if (ins & 0x01000000) {
+ // Add/subtract offset before
+ if ((ins & 0x02000000) == 0) {
+ // Immediate offset
+ if (ins & 0x00800000) {
+ // Add offset
+ Rn += (ins & 0x00000FFF);
+ } else {
+ // Subtract offset
+ Rn -= (ins & 0x00000FFF);
+ }
+ } else {
+ // Offset is in a register
+ if (ins & 0x00800000) {
+ // Add offset
+ Rn += RmShifted(ins & 0x00000FFF);
+ } else {
+ // Subtract offset
+ Rn -= RmShifted(ins & 0x00000FFF);
+ }
+ }
+ }
+ return ((unsigned long *)*(unsigned long *)Rn);
+ }
+ }
+ }
+ return (pc+1);
+ case 0x2: // Branch, LDM/STM
+ if ((ins & 0x02000000) == 0) {
+ // LDM/STM
+ if ((ins & 0x00100000) == 0) {
+ // STM
+ return (pc+1);
+ } else {
+ // LDM
+ if ((ins & 0x00008000) == 0) {
+ // PC not in list
+ return (pc+1);
+ } else {
+ Rn = (unsigned long)get_register((ins & 0x000F0000) >> 16);
+ if ((ins & 0x000F0000) == 0x000F0000) Rn += 8; // PC prefetch!
+ offset = ins & 0x0000FFFF;
+ reg_count = 0;
+ for (i = 0; i < 15; i++) {
+ if (offset & (1<<i)) reg_count++;
+ }
+ if (ins & 0x00800000) {
+ // Add offset
+ Rn += reg_count*4;
+ } else {
+ // Subtract offset
+ Rn -= 4;
+ }
+ return ((unsigned long *)*(unsigned long *)Rn);
+ }
+ }
+ } else {
+ // Branch
+ if (ins_will_execute(ins)) {
+ offset = (ins & 0x00FFFFFF) << 2;
+ if (ins & 0x00800000) offset |= 0xFC000000; // sign extend
+ new_pc = (unsigned long)(pc+2) + offset;
+ // If its BLX, make new_pc a thumb address.
+ if ((ins & 0xFE000000) == 0xFA000000) {
+ if ((ins & 0x01000000) == 0x01000000)
+ new_pc |= 2;
+ new_pc = MAKE_THUMB_ADDR(new_pc);
+ }
+ return ((unsigned long *)new_pc);
+ } else {
+ // Falls through
+ return (pc+1);
+ }
+ }
+ case 0x3: // Coprocessor & SWI
+ if (((ins & 0x03000000) == 0x03000000) && ins_will_execute(ins)) {
+ // SWI
+ return (unsigned long *)(CYGNUM_HAL_VECTOR_SOFTWARE_INTERRUPT * 4);
+ } else {
+ return (pc+1);
+ }
+ default:
+ // Never reached - but fixes compiler warning.
+ return 0;
+ }
+}
+
+// FIXME: target_ins also needs to check for CPSR/THUMB being set and
+// set the thumb bit accordingly.
+
+static unsigned long
+target_thumb_ins(unsigned long pc, unsigned short ins)
+{
+ unsigned long new_pc = MAKE_THUMB_ADDR(pc+2); // default is fall-through
+ // to next thumb instruction
+ unsigned long offset, arm_ins, sp;
+ int i;
+
+ switch ((ins & 0xf000) >> 12) {
+ case 0x4:
+ // Check for BX or BLX
+ if ((ins & 0xff07) == 0x4700)
+ new_pc = (unsigned long)get_register((ins & 0x00078) >> 3);
+ break;
+ case 0xb:
+ // push/pop
+ // Look for "pop {...,pc}"
+ if ((ins & 0xf00) == 0xd00) {
+ // find PC
+ sp = (unsigned long)get_register(SP);
+
+ for (offset = i = 0; i < 8; i++)
+ if (ins & (1 << i))
+ offset += 4;
+
+ new_pc = *(cyg_uint32 *)(sp + offset);
+
+ if (!v5T_semantics())
+ new_pc = MAKE_THUMB_ADDR(new_pc);
+ }
+ break;
+ case 0xd:
+ // Bcc | SWI
+ // Use ARM function to check condition
+ arm_ins = ((unsigned long)(ins & 0x0f00)) << 20;
+ if ((arm_ins & 0xF0000000) == 0xF0000000) {
+ // SWI
+ new_pc = CYGNUM_HAL_VECTOR_SOFTWARE_INTERRUPT * 4;
+ } else if (ins_will_execute(arm_ins)) {
+ offset = (ins & 0x00FF) << 1;
+ if (ins & 0x0080) offset |= 0xFFFFFE00; // sign extend
+ new_pc = MAKE_THUMB_ADDR((unsigned long)(pc+4) + offset);
+ }
+ break;
+ case 0xe:
+ // check for B
+ if ((ins & 0x0800) == 0) {
+ offset = (ins & 0x07FF) << 1;
+ if (ins & 0x0400) offset |= 0xFFFFF800; // sign extend
+ new_pc = MAKE_THUMB_ADDR((unsigned long)(pc+4) + offset);
+ }
+ break;
+ case 0xf:
+ // BL/BLX (4byte instruction!)
+ // First instruction (bit 11 == 0) holds top-part of offset
+ if ((ins & 0x0800) == 0) {
+ offset = (ins & 0x07FF) << 12;
+ if (ins & 0x0400) offset |= 0xFF800000; // sign extend
+ // Get second instruction
+ // Second instruction (bit 11 == 1) holds bottom-part of offset
+ ins = *(unsigned short*)(pc+2);
+ // Check for BL/BLX
+ if ((ins & 0xE800) == 0xE800) {
+ offset |= (ins & 0x07ff) << 1;
+ new_pc = (unsigned long)(pc+4) + offset;
+ // If its BLX, force a full word alignment
+ // Otherwise, its a thumb address.
+ if (!(ins & 0x1000))
+ new_pc &= ~3;
+ else
+ new_pc = MAKE_THUMB_ADDR(new_pc);
+ }
+ }
+ break;
+ }
+
+ return new_pc;
+}
+
+void __single_step (void)
+{
+ unsigned long pc = get_register(PC);
+ unsigned long cpsr = get_register(PS);
+
+ // Calculate address of next instruction to be executed
+ if (cpsr & CPSR_THUMB_ENABLE) {
+ // thumb
+ ss_saved_pc = target_thumb_ins(pc, *(unsigned short*)pc);
+ } else {
+ // ARM
+ unsigned long curins = *(unsigned long*)pc;
+ if (ins_will_execute(curins)) {
+ // Decode instruction to decide what the next PC will be
+ ss_saved_pc = (unsigned long) target_ins((unsigned long*)pc,
+ curins);
+ } else {
+ // The current instruction will not execute (the conditions
+ // don't hold)
+ ss_saved_pc = pc+4;
+ }
+ }
+
+ // Set breakpoint according to type
+ if (IS_THUMB_ADDR(ss_saved_pc)) {
+ // Thumb instruction
+ unsigned long t_pc = UNMAKE_THUMB_ADDR(ss_saved_pc);
+ ss_saved_thumb_instr = *(unsigned short*)t_pc;
+ *(unsigned short*)t_pc = HAL_BREAKINST_THUMB;
+ } else {
+ // ARM instruction
+ ss_saved_instr = *(unsigned long*)ss_saved_pc;
+ *(unsigned long*)ss_saved_pc = HAL_BREAKINST_ARM;
+ }
+}
+
+ ****************************************************************************/
+
+/* _dbg_following_instruction_addr
+ * Determine the address of the following instruction to execute.
+ * On entry:
+ * R0: Address of the instruction to be (re)executed
+ * On exit:
+ * R0: Destroyed
+ * R1: Following Instruction Address (31 bits, b0 = THUMB flag)
+ * R2-R7: Destroyed
+ *
+ * Here we make use of the Debugger Stack which contains the address of the aborted instruction that will be reexecuted
+ * when we resume the program.
+ *
+ * If it is a Manual Breakpoint inserted into the code, then we will need to update the aborted instruction
+ * address to skip the current aborted instruction and resume execution at the next instruction address,
+ * and the next instruction address to be returned to the calling routine is the following instruction
+ * address instead.
+ *
+ * We need to check the aborted instruction type, to see if it is a branch instruction, before we can determine
+ * the next instruction address (for inserting a Breakpoint).
+ */
+_dbg_following_instruction_addr:
+ stmfd sp!, {lr}
+/* We assume that any BKPT instructions in the code will be Manual Breakpoints,
+ * i.e., the Debugger does not leave stray Single Step / Auto / Normal breakpoints in memory
+ */
+ mov r6, r0 /* Keep instruction address in R6 */
+ mov r2, #DBGSTACK_USERCPSR_INDEX /* Retrieve User CPSR */
+ _getdbgregisterfromindex r2, r1 /* Retrieve Register contents into R1 */
+ and r4, r1, #CPSR_THUMB /* store Thumb Mode status in R4 */
+ mov r5, r1, lsr #28 /* store CPSR condition flags in R5[3:0] */
+
+_dbg_get_aborted_instr:
+1: teq r4, #0 /* Check if it is ARM or Thumb instruction */
+ ldrneh r0, [r6] /* Load Thumb instruction opcode using Addr in R6 into R0 */
+ ldrne r2, =(BKPT16_INSTR | BKPT16_MANUAL_BKPT) /* check for Thumb Manual Breakpoint Instruction */
+ ldreq r0, [r6] /* Load ARM instruction opcode using Addr in R6 into R0 */
+ ldreq r2, =(BKPT32_INSTR | BKPT32_MANUAL_BKPT) /* check for ARM Manual Breakpoint Instruction */
+ teq r0, r2 /* Is instruction opcode (R0) == Manual Breakpoint opcode (R2)? */
+ bne 2f /* Not Manual breakpoint */
+ teq r4, #0 /* Check if it is ARM or Thumb Manual Breakpoint */
+ addne r6, r6, #2 /* Is Manual Breakpoint, Skip to next Thumb instruction */
+ addeq r6, r6, #4 /* Is Manual Breakpoint, Skip to next ARM instruction */
+ b 1b /* To protect against a sequence of Manual Breakpoint Instructions */
+
+/* Here, R0 contains the instruction opcode which will be (re)executed when program resumes.
+ * We need to dissect it to see if it is a branch instruction.
+ * For ARM instructions, we also need to evaluate the current (breakpointed) instruction to see if it'll execute.
+ * If not, then the following instruction is at the address following the address of the opcode in R0 (Default Following Instruction Address).
+ */
+2:
+ teq r4, #0 /* Check if it is ARM or Thumb instruction */
+ beq _following_instr_is_arm
+_following_instr_is_thumb:
+ add r6, r6, #2 /* Store following Thumb instruction address to R1 */
+ orr r6, r6, #BKPT_STATE_THUMB_FLAG /* Set b0 to indicate Thumb instruction */
+ /* R0: Candidate Instruction Opcode
+ * R5[3:0]: CPSR condition codes
+ * R6: Default Following Instruction Address (PC+2)
+ */
+ bl _eval_thumb_instruction /* following address is either ARM or Thumb */
+ /* We must set this the Thumb bit only within the instruction handler since BX would switch modes */
+ b _exit_dbg_following_instruction_addr
+
+_following_instr_is_arm:
+ add r6, r6, #4 /* Store following ARM instruction address to R1 */
+ /* R0: Candidate Instruction Opcode
+ * R5[3:0]: CPSR condition codes
+ * R6: Default Following Instruction Address (PC+4)
+ */
+ bl _eval_arm_instruction
+
+_exit_dbg_following_instruction_addr:
+ mov r1, r0 /* Return Actual Following Instruction Address in R1 (B0 set to indicate Thumb mode) */
+ ldmfd sp!, {pc}
+
+
+/* _eval_arm_instruction
+ * Evaluate ARM instruction to determine following instruction address
+ * On entry:
+ * R0: instruction to be executed
+ * R5[3:0]: CPSR condition codes
+ * R6: Default Following Instruction Address (PC+4)
+ * On exit:
+ * R0: following instruction address (B0 set to indicate Thumb mode)
+ * R1-R7: destroyed
+ */
+_eval_arm_instruction:
+ stmfd sp!, {lr}
+ mov r4, r0 /* Keep Instruction Opcode in R4 */
+ bl _dbg_check_arm_condcode
+ teq r0, #FALSE
+ moveq r0, r6 /* False (don't execute), so use Default Following Instruction Address */
+ bne _exit_eval_arm_instruction
+
+_will_execute_arm_instr:
+ mov r0, r4 /* Copy instruction opcode to R0 as Code Handler parameter */
+ mov r1, #0 /* initialize ARM Decode Entry Table index register */
+1:
+ _dbg_armDecodeEntry r2, r3, r4, r1 /* instrreg (R2), instrmask (R3), codehandler (R4), indexreg (R1) */
+ teq r2, #0 /* Check for Null Entry (End of Table marker) */
+ moveq r0, r6 /* End of Table, no match found, so use Default Following Instruction Address */
+ beq _exit_eval_arm_instruction
+ and r7, r0, r3 /* Use R7 to check masked instruction opcode (from R0) to see if it matches template (in R2) */
+ teq r7, r2
+ addne r1, r1, #1 /* No match, so keep looking */
+ bne 1b
+
+_call_arm_code_handler:
+ mov r1, r6 /* Copy Default Following Instruction Address to R1 as Code Handler Parameter */
+ mov lr, pc
+ bx r4 /* Call Code Handler with R0: Instruction Opcode, R1: Default Following Instruction Address */
+_exit_eval_arm_instruction:
+ /* Returned Following Address Instruction in R0 (B0 set to indicate Thumb mode) */
+ ldmfd sp!, {pc}
+
+/* _eval_thumb_instruction
+ * Evaluate Thumb instruction to determine following instruction address
+ * On entry:
+ * R0: instruction to be executed
+ * R5[3:0]: CPSR condition codes
+ * R6: Default Following Instruction Address (PC+2)
+ * On exit:
+ * R0: following instruction address (B0 set to indicate Thumb mode)
+ * R1-R7: destroyed
+ */
+_eval_thumb_instruction:
+ stmfd sp!, {lr}
+#if 0
+ mov r4, r0 /* Keep Instruction Opcode in R4 */
+ /* Only B<cond> instructions are conditionally executed, deal with it in that Code Handler */
+ bl _dbg_check_thumb_condcode
+ teq r0, #FALSE
+ moveq r0, r6 /* False (don't execute), so use Default Following Instruction Address */
+ bne _exit_eval_thumb_instruction
+
+_will_execute_thumb_instr:
+ mov r0, r4 /* Copy instruction opcode to R0 as Code Handler parameter */
+#endif
+ mov r1, #0 /* initialize Thumb Decode Entry Table index register */
+1:
+ _dbg_thumbDecodeEntry r2, r3, r4, r1 /* instrreg (R2), instrmask (R3), codehandler (R4), indexreg (R1) */
+ teq r2, #0 /* Check for Null Entry (End of Table marker) */
+ moveq r0, r6 /* End of Table, no match found, so use Default Following Instruction Address */
+ beq _exit_eval_thumb_instruction
+
+ and r7, r0, r3 /* Use R5 to check masked instruction opcode (from R0) to see if it matches template (in R2) */
+ teq r7, r2
+ addne r1, r1, #1 /* No match, so keep looking */
+ bne 1b
+
+_call_thumb_code_handler:
+ mov r1, r6 /* Copy Default Following Instruction Address to R1 as Code Handler Parameter */
+ mov lr, pc
+ bx r4 /* Call Code Handler with R0: Instruction Opcode, R1: Default Following Instruction Address */
+_exit_eval_thumb_instruction:
+ /* Returned Following Address Instruction in R0 */
+ ldmfd sp!, {pc}
+
+
+/****************************************************************************
+ *
+ * Instruction Decode Routines
+ *
+ ****************************************************************************/
+
+/* _dbg_check_arm_condcode
+ * Check ARM conditional execution code
+ * On entry:
+ * R0: instruction to be executed
+ * R5[3:0]: CPSR condition codes
+ * On exit:
+ * R0: will_execute (boolean)
+ * R1-R3: Destroyed
+ */
+
+_dbg_check_arm_condcode:
+ stmfd sp!, {r6,lr} /* Use R6 as temporary will_execute variable */
+ mov r6, #TRUE
+ mov r0, r0, lsr #28 /* convert condition code to index (0-F) */
+ ldr r2, =debug_armCondCodeTable
+ ldrb r1, [r2, r0] /* Get condition code mask */
+/*
+ * The following check is unnecessary as it is covered by the set/clear checking algorithm
+ teq r1, #0
+ beq _dbg_check_arm_condcode_exit
+*/
+ teq r1, #0xFF
+ bne _dbg_check_bits_set
+
+
+/*
+ * Complex Checks:
+ *
+ * will_execute = TRUE [default condition]
+ * If (N == V) bit set
+ * will_execute = (N == V)
+ * else
+ * will_execute = (N != V)
+ *
+ * If (ANDOR bit) set
+ * z_cond = ((Z XOR Z set) == 0)
+ * If (AND bit set)
+ * will_execute = will_execute && z_cond
+ * else
+ * will_execute = will_execute || z_cond
+ */
+_dbg_cond_complex_check:
+ sub r1, r0, #COMPLEX_CONDCODE_START /* Convert complex condition code to new index (0-3) */
+ ldr r2, =debug_armComplexCCTable
+ ldrb r1, [r2, r1] /* Get complex condition code bitmap */
+
+ /* Use r2 to store N, r3 to store V */
+ tst r5, #COMPLEX_CONDCODE_NFLAG
+ moveq r2, #FALSE
+ movne r2, #TRUE /* r2 = N flag */
+ tst r5, #COMPLEX_CONDCODE_VFLAG
+ moveq r3, #FALSE
+ movne r3, #TRUE /* r3 = V flag */
+ eor r2, r2, r3 /* r2 = (N xor V): 0 if equal, 0xFF if not equal */
+ tst r1, #COMPLEX_CONDCODE_NEQV_MASK
+ mvnne r6, r1 /* If (N == V) bit set, will_execute (r6) = TRUE if (N == V) [r2 == 0] -> invert r2 */
+ moveq r6, r1 /* else (N == V) bit clr, will_execute (r6) = TRUE if (N != V) [r2 == 0xFF] */
+
+ tst r1, #COMPLEX_CONDCODE_ANDOR_MASK
+ beq _dbg_check_arm_condcode_exit /* No additional checks needed, exit */
+
+ /* Use r2 to store Z, r3 to store Z set */
+ and r2, r5, #COMPLEX_CONDCODE_ZFLAG /* r2 = Z flag */
+ and r3, r1, #COMPLEX_CONDCODE_ZSET_MASK /* r3 = Z set */
+ eors r2, r2, r3 /* r2 = (Z xor Z set): 0 if matched, non-zero if not matched */
+ moveq r2, #TRUE
+ movne r2, #FALSE /* r2 (z_cond): TRUE if matched, FALSE if not matched */
+
+ tst r1, #COMPLEX_CONDCODE_AND_MASK
+ andne r6, r6, r2 /* If AND bit set, will_execute = will_execute && z_cond */
+ orreq r6, r6, r2 /* else, will_execute = will_execute || z_cond */
+ b _dbg_check_arm_condcode_exit
+
+
+/*
+ * Simple Checks:
+ *
+ * will_execute = TRUE [default condition, equivalent to 0x00 (AL) ]
+ * If (SetBitMask is Non-Zero)
+ * will_execute = ((cond_code & SetBitMask) == SetBitMask)
+ * If will_execute && (ClearBitMask is Non-Zero)
+ * will_execute = will_execute && ((cond_code | ~ClearBitMask) == ~ClearBitMask)
+ */
+
+_dbg_check_bits_set:
+ movs r0, r1, lsr #4 /* R0: bits set */
+ beq _dbg_check_bits_clear
+ and r2, r5, r0 /* Check bits set IF bitmask non-zero */
+ teq r2, r0 /* ((cond_code & SetBitMask) == SetBitMask)? */
+ movne r6, #FALSE /* No, so will_execute = FALSE */
+ bne _dbg_check_arm_condcode_exit
+
+_dbg_check_bits_clear:
+ ands r1, r1, #NIBBLE0 /* R1: bits clear */
+ beq _dbg_check_arm_condcode_exit
+ mvn r1, r1 /* Invert Bitmask */
+ orr r2, r5, r1 /* Check bits clear IF bitmask non-zero */
+ teq r2, r1 /* ((cond_code | ~ClearBitMask) == ~ClearBitMask)? */
+ movne r6, #FALSE /* No, so will_execute = FALSE */
+ bne _dbg_check_arm_condcode_exit
+
+
+_dbg_check_arm_condcode_exit:
+ mov r0, r6 /* Update return value */
+ ldmfd sp!, {r6, pc}
+
+
+/* _arm_rmshifted_val
+ * Calculate value of Shifted Rm (operand)
+ * On entry:
+ * R0[11:0]: Shifted Rm operand
+ * On exit:
+ * R0: value of Shifted Rm
+ * R1, R2, R3: destroyed
+ */
+_arm_rmshifted_val:
+ stmfd sp!, {lr}
+ ldr r3, =(NIBBLE2|BYTE0)
+ and r3, r0, r3 /* 12 bit Shifted Register operand, copied to R3 */
+ and r2, r3, #NIBBLE0 /* Register Rn Enum in R2 */
+ _regenum2index r2, r2 /* Convert Enum into Index in R2 */
+ _getdbgregisterfromindex r2, r0 /* Retrieve Register Rn contents from Index (R2) into R0 */
+
+ tst r3, #0x10 /* B4: Immediate (0) or Register (1) shift count */
+ /* check bitshift op */
+ and r3, r3, #0x60 /* shift type */
+ mov r3, r3, lsr #5 /* convert into shift type jumptable index */
+ bne _arm_get_reg_shift /* Flags set previously via TST r3 (B4) */
+_arm_calc_const_shift:
+ movs r1, r3, lsr #7 /* Immediate shift count, 5 bit unsigned value in R1 */
+ bne _arm_calc_shifted_rm_val /* Non-zero shift count, process normally */
+ /* Must check for RRX == ROR #0 */
+ teq r3, #0x3 /* ROR == 0x3 */
+ addeq r3, r3, #1
+ b _arm_calc_shifted_rm_val
+
+_arm_get_reg_shift:
+ mov r2, r3, lsr #8 /* Register-based shift count, 4 bit register enum in R2 */
+ _regenum2index r2, r2 /* Convert Enum into Index in R2 */
+ _getdbgregisterfromindex r2, r1 /* Retrieve Register value (shift count) from Index (R2) into R1 */
+
+_arm_calc_shifted_rm_val:
+ _dbg_jumpTableHandler debug_regShiftJumpTable, r2, r3 /* Calculate RmShifted value from R0: Rn Register val, R1: Shift/Rotate val */
+ ldmfd sp!, {pc}
+
+/* Rm Shifted Shift Type Jump Table Routines
+ * On entry:
+ * R0: Register Rm
+ * R1: Shift/Rotate Amount
+ * On exit:
+ * R0: RmShifted result
+ * R1, R2: destroyed
+ *
+ */
+_reg_lsl:
+ lsl r0, r0, r1
+ bx lr
+
+_reg_lsr:
+ lsr r0, r0, r1
+ bx lr
+
+_reg_asr:
+ asr r0, r0, r1
+ bx lr
+
+_reg_ror:
+ ror r0, r0, r1
+ bx lr
+
+_reg_rrx:
+ moveq r2, #DBGSTACK_USERCPSR_INDEX /* convert register enum to Debug Stack index */
+ _getdbgregisterfromindex r2, r1 /* Retrieve CPSR contents from Index (R2) into R1 */
+ ands r1, r1, #CPSR_CFLAG /* Keep C Flag */
+ movne r1, #0x80000000 /* Set B31 if C Flag set */
+ lsr r0, r0, #1 /* Rm >> 1 */
+ orr r0, r0, r1 /* Put C flag into B31 */
+ bx lr
+
+
+/* _arm_data_instr_handler
+ * ARM Data Processing Instruction with Rd == R15
+ * On entry:
+ * R0: instruction to be executed
+ * R1: Default Following Instruction Address (PC+4)
+ * R5[3:0]: CPSR condition codes
+ * On exit:
+ * R0: following instruction address
+ * R1-R7: Destroyed
+ */
+_arm_data_instr_handler:
+ stmfd sp!, {lr}
+ mov r6, r1 /* save Following Instruction Address in R6 */
+ ldr r1, =0x0FBF0000
+ and r4, r0, r1 /* Keep instruction Opcode in R4 */
+ ldr r1, =0x010F0000
+ cmp r4, r1 /* Check for MSR / MRS instruction */
+
+_arm_is_msr_mrs_instr:
+ moveq r0, r6 /* Copy default next instruciton address to R0 */
+ beq _exit_arm_data_instr_handler /* Return default next instruction address */
+
+ /* Not MSR / MRS, so process normally */
+_arm_normal_data_instr:
+ and r4, r0, #0x01E00000 /* Mask Instruction Opcode into R4[24:21] */
+ lsr r4, r4, #21 /* Shift Data Processing Opcode into R4[3:0] */
+ and r7, r0, #0x000F0000 /* Store Rn (Operand 1) Register Enum into R7[19:16] */
+ lsr r7, r7, #16 /* Shift into R7[3:0] */
+
+_arm_check_operand2_type:
+ tst r0, #0x02000000 /* Check for Immediate (1) or Register (0) Operand 2 */
+ beq _arm_op2_is_reg
+
+_arm_op2_is_imm:
+ and r1, r0, #BYTE0 /* 8 bit unsigned constant in R1 */
+ and r2, r0, #NIBBLE2 /* (rotate count / 2) in R2[11:8] */
+ lsr r2, r2, #7 /* actual rotate count in R2[4:0] */
+ ror r1, r1, r2 /* Rotated constant in R1 */
+ b _arm_get_operand1_val
+
+_arm_op2_is_reg:
+ ldr r1, =(NIBBLE2|BYTE0)
+ and r0, r0, r1 /* 12 bit register operand in R1 */
+ bl _arm_rmshifted_val /* R0 contains the Rm shifted val */
+ mov r1, r0 /* move to R1 for later processing */
+
+_arm_get_operand1_val:
+ _regenum2index r7, r1 /* Convert Enum into Index in R1 */
+ _getdbgregisterfromindex r1, r0 /* Retrieve Register contents from Index (R1) into R4 */
+ teq r7, #REG_PC /* Check if it is PC relative */
+ addeq r0, r0, #8 /* adjust for PC relative (+8) */
+
+_arm_calc_data_instr_val:
+ mov r2, r6 /* Retrieve Following Instruction Address in R6 to R2 */
+ /* Calculate data instruction value from R0: Rn Register (Op1) val, R1: Operand 2 val, R2: Default Next Instr Addr */
+ _dbg_jumpTableHandler debug_dataInstrJumpTable, r6, r4 /* Next Instruction Address in R0 */
+_exit_arm_data_instr_handler:
+ ldmfd sp!, {pc}
+
+
+/* Data Processing Instruction Jump Table Routines
+ * On entry:
+ * R0: Register Rn (Operand 1) value
+ * R1: Operand 2 value
+ * R2: Default Next Instruction Address (PC+4)
+ * R5[3:0]: CPSR condition codes
+ * On exit:
+ * R0: Calculated result
+ * R1, R2, R3: Destroyed
+ *
+ */
+_opcode_and:
+ and r0, r0, r1
+ bx lr
+
+_opcode_eor:
+ eor r0, r0, r1
+ bx lr
+
+_opcode_sub:
+ sub r0, r0, r1
+ bx lr
+
+_opcode_rsb:
+ rsb r0, r0, r1
+ bx lr
+
+_opcode_add:
+ add r0, r0, r1
+ bx lr
+
+_opcode_adc:
+ /* Op1 + Op2 + C */
+#if 0
+ moveq r2, #DBGSTACK_USERCPSR_INDEX /* convert register enum to Debug Stack index */
+ _getdbgregisterfromindex r2, r3 /* Retrieve CPSR contents from Index (R2) into R3 */
+ ands r3, r3, #CPSR_CFLAG /* Keep C Flag, NE if C set */
+#endif
+ tst r5, #0x02 /* R5[3:0] is shifted CPSR value */
+ add r0, r0, r1
+ addne r0, r0, #1 /* Add C if set */
+ bx lr
+
+_opcode_sbc:
+ /* Op1 - Op2 + C - 1 */
+#if 0
+ moveq r2, #DBGSTACK_USERCPSR_INDEX /* convert register enum to Debug Stack index */
+ _getdbgregisterfromindex r2, r3 /* Retrieve CPSR contents from Index (R2) into R3 */
+ ands r3, r3, #CPSR_CFLAG /* Keep C Flag, NE if C set */
+#endif
+ tst r5, #0x02 /* R5[3:0] is shifted CPSR value */
+ sub r0, r0, r1
+ subeq r0, r0, #1 /* If C clear, subtract 1, else (C - 1) = 0 */
+ bx lr
+
+_opcode_rsc:
+ /* Op2 - Op1 + C - 1 */
+#if 0
+ moveq r2, #DBGSTACK_USERCPSR_INDEX /* convert register enum to Debug Stack index */
+ _getdbgregisterfromindex r2, r3 /* Retrieve CPSR contents from Index (R2) into R3 */
+ ands r3, r3, #CPSR_CFLAG /* Keep C Flag, NE if C set */
+#endif
+ tst r5, #0x02 /* R5[3:0] is shifted CPSR value */
+ rsb r0, r0, r1
+ subeq r0, r0, #1 /* If C clear, subtract 1, else (C - 1) = 0 */
+ bx lr
+
+_opcode_tst:
+_opcode_teq:
+_opcode_cmp:
+_opcode_cmn:
+ mov r0, r2 /* Next Instruction Address is not modified */
+ bx lr
+
+_opcode_orr:
+ orr r0, r0, r1
+ bx lr
+
+_opcode_mov:
+ mov r0, r1 /* Operand 1 is ignored */
+ bx lr
+
+_opcode_bic:
+ bic r0, r0, r1
+ bx lr
+
+_opcode_mvn:
+ mvn r0, r1 /* Operand 1 is ignored */
+ bx lr
+
+
+/* _arm_bx_blx_handler
+ * BX or BLX Rm Handler. Note v4t does not have BLX instr
+ * On entry:
+ * R0: instruction to be executed
+ * R1: Default Following Instruction Address (PC+4)
+ * R5[3:0]: CPSR condition codes
+ * On exit:
+ * R0: following instruction address (B0 set to indicate Thumb mode)
+ * R1, R2: destroyed
+ */
+_arm_bx_blx_handler:
+ stmfd sp!, {lr}
+ and r0, r0, #NIBBLE0 /* Register Rn Enum in R0 */
+ _regenum2index r0, r1 /* Convert Enum into Index in R1 */
+ _getdbgregisterfromindex r1, r0 /* Retrieve Register contents from Index (R1) into R0 */
+ /* Here, the register value would have B0 set to indicate switch to Thumb mode */
+#if 0
+ bic r0, #0x01 /* Clear R0[0] since it is used to indicates Thumb mode */
+#endif
+ ldmfd sp!, {pc}
+
+/* _arm_ldr_pc_handler
+ * LDR with Rd = PC
+ * On entry:
+ * R0: instruction to be executed
+ * R1: Default Following Instruction Address (PC+4)
+ * R5[3:0]: CPSR condition codes
+ * On exit:
+ * R0: following instruction address
+ * R1, R2, R3, R4, R5: destroyed
+ */
+
+_arm_ldr_pc_handler:
+ stmfd sp!, {lr}
+ mov r5, r0 /* Keep a copy of the instruction in R5 */
+ and r0, r0, #NIBBLE4 /* Register Rn Enum in R0[19:16] */
+ lsr r0, r0, #16 /* Move Rn Enum to R0[3:0] */
+ _regenum2index r0, r1 /* Convert Enum into Index in R1 */
+ _getdbgregisterfromindex r1, r4 /* Retrieve Register contents from Index (R1) into R4 */
+ teq r0, #REG_PC /* Check if it is PC relative */
+ addeq r4, r4, #8 /* adjust for PC relative (+8) */
+ tst r5, #0x01000000 /* Pre (1) or Post (0) Indexed */
+ beq _exit_arm_ldr_pc_handler /* If Post-Indexed, just return value of Rn */
+ /* Pre-Indexed */
+ ldr r0, =(NIBBLE2|BYTE0)
+ and r0, r5, r0 /* 12 bit Immediate value or Shifted Reg operand */
+ tst r5, #0x02000000 /* Immediate (0) or Register (1) */
+ beq _calc_ldr_pc_offset /* Immediate value is already in R0 */
+
+_get_shiftedreg_val:
+ bl _arm_rmshifted_val /* Convert Rm shifted operand into value in R0 */
+
+_calc_ldr_pc_offset:
+ tst r5, #0x00800000 /* Add (1) or Subtract (0) */
+ addne r4, r4, r0 /* If Add, R2 = Rn + value */
+ subeq r4, r4, r0 /* If Sub, R2 = Rn - value */
+
+_exit_arm_ldr_pc_handler:
+ mov r0, r4 /* Return next instruction address in R0 */
+ ldmfd sp!, {pc}
+
+
+/* _arm_ldm_pc_handler
+ * LDM {pc}
+ * On entry:
+ * R0: instruction to be executed
+ * R1: Default Following Instruction Address (PC+4)
+ * R5[3:0]: CPSR condition codes
+ * On exit:
+ * R0: following instruction address
+ * R1, R2, R3: destroyed
+ *
+ * FIXME: The algorithm from eCos arm_stub.c does not deal with the Pre/Post-Indexed addressing (P) bit.
+ */
+_arm_ldm_pc_handler:
+ stmfd sp!, {lr}
+ and r3, r0, #0x000F0000 /* Store Rn (Operand 1) Register Enum into R3[19:16] */
+ lsr r3, r3, #16 /* Shift into R3[3:0] */
+
+_arm_get_Rn_val:
+ _regenum2index r3, r2 /* Convert Enum into Index in R2 */
+ _getdbgregisterfromindex r2, r1 /* Retrieve Register contents from Index (R2) into R1 */
+ teq r3, #REG_PC /* Check if it is PC relative */
+ addeq r1, r1, #8 /* adjust Rn (R1) for PC relative (+8) */
+
+_arm_get_regcount:
+ mov r2, #0 /* Initialize reg_count (R2) to 0 */
+ mov r3, r0, lsl #16 /* Keep HLFWORD0 containing vector bits in R3[31:16] */
+ /* This shortens the checking to a max of 16 iterations, since the PC bit should be set */
+1: movs r3, r3, lsl #1 /* count number of '1' bits */
+ addcs r2, r2, #1 /* increment reg_count (R2) if C Flag set */
+ bne 1b /* continue until vector is empty */
+
+_arm_check_updown_offset:
+ tst r0, #0x00800000 /* Check Up (1) or Down (0) */
+ addne r1, r1, r2, lsl #2 /* Ascending: Rn (R1) += reg_count (R2) x 4 */
+ subeq r1, r1, #4 /* Descending: Rn (R1) -= 4 */
+ ldr r0, [r1] /* Retrieve stack content for new PC value */
+ ldmfd sp!, {pc}
+
+
+
+/* _arm_b_bl_blx_handler
+ * B, BL or BLX <offset>. Note v4t does not have BLX instr
+ * On entry:
+ * R0: instruction to be executed
+ * R1: Default Following Instruction Address (PC+4)
+ * R5[3:0]: CPSR condition codes
+ * On exit:
+ * R0: following instruction address
+ * R1, R2, R3: destroyed
+ */
+
+_arm_b_bl_blx_handler:
+ stmfd sp!, {lr}
+#ifndef __ARM6OR7__
+ /* armv5t or later, has BLX support */
+ mov r3, r0 /* Copy instruction to R3 */
+#endif
+
+_arm_b_bl_blx_get_offset:
+ and r0, r0, #(BYTE2|BYTE1|BYTE0) /* Encoded Branch offset in R0[23:0] */
+ lsl r0, r0, #(32-24) /* Shift to R0[31:8] */
+ asr r0, r0, #(32-25) /* Actual Signed offset = Encode Offset x 2 in R0[25:0] */
+ add r1, r1, #4 /* R1: (PC+4) + 4 */
+ add r0, r0, r1 /* Calculate Branch Target Address R0: (PC+8) + signed offset */
+
+#ifndef __ARM6OR7__
+ /* armv5t or later, has BLX support */
+ and r2, r3, #0xFE000000 /* Mask out Condition Code and Opcode */
+ teq r2, #0xFA000000 /* Look for BLX */
+ bne _exit_arm_b_bl_blx_handler /* No, it is a B/BL instruction */
+ tst r3, #0x01000000 /* H bit for Thumb Halfword Address */
+ orrne r0, r0, #0x02 /* Set Halfword Address R0[1] */
+ orr r0, r0, #0x01 /* Set R0[0] since it is used to indicates Thumb mode */
+#endif
+
+_exit_arm_b_bl_blx_handler:
+ ldmfd sp!, {pc}
+
+/* _arm_coproc_swi_handler
+ * SVC (SWI) or Coprocessor instruction
+ * On entry:
+ * R0: instruction to be executed
+ * R1: Default Following Instruction Address (PC+4)
+ * R5[3:0]: CPSR condition codes
+ * On exit:
+ * R0: following instruction address
+ * R1, R2: destroyed
+ */
+
+_arm_coproc_swi_handler:
+ and r2, r0, #0x0F000000
+ teq r2, #0x0F000000 /* SVC (SWI) instruction */
+
+_arm_swi_instr:
+ ldreq r0, =SVC_VECTOR /* Return SVC Vector Address */
+ beq _exit_arm_coproc_swi_handler
+
+_arm_coproc_instr:
+ mov r0, r1 /* Use default Following Instruction Address */
+_exit_arm_coproc_swi_handler:
+ bx lr
+
+
+/* _thumb_bx_blx_handler
+ * BX or BLX Handler. Note: b7 (H1) is not matched in the mask (should be 0); armv4t does not support BLX.
+ * On entry:
+ * R0: instruction to be executed
+ * R1: Default Following Instruction Address (PC+2)
+ * R5[3:0]: CPSR condition codes
+ * On exit:
+ * R0: following instruction address (B0 set to indicate Thumb mode)
+ * R1: destroyed
+ */
+_thumb_bx_blx_handler:
+ stmfd sp!, {lr}
+ and r0, r0, #0x78 /* Register Rn Enum in R0[6:3] (Hi-Reg indicated by B6) */
+ mov r0, r0, lsr #3 /* Shift Rn Enum to R0[3:0] */
+ _regenum2index r0, r1 /* Convert Enum into Index in R1 */
+ _getdbgregisterfromindex r1, r0 /* Retrieve Register contents from Index (R1) into R0 */
+ /* Here, the register value would have R0[0] set to indicate switch to Thumb mode */
+ ldmfd sp!, {pc}
+
+/* _thumb_poppc_handler
+ * PUSH/POP, specifically POP {Rlist,PC}
+ * On entry:
+ * R0: instruction to be executed
+ * R1: Default Following Instruction Address (PC+2)
+ * R5[3:0]: CPSR condition codes
+ * On exit:
+ * R0: following instruction address (B0 set to indicate Thumb mode)
+ * R1: destroyed
+ */
+_thumb_poppc_handler:
+ stmfd sp!, {lr}
+
+_thumb_get_SP_val:
+ mov r2, #DBGSTACK_USERSP_INDEX /* Set Register Index (R2) to SP Index */
+ _getdbgregisterfromindex r2, r1 /* Retrieve SP contents from Index (R2) into R1 */
+
+_thumb_get_regcount:
+ mov r2, #0 /* Initialize reg_count (R2) to 0 */
+ mov r3, r0, lsl #24 /* Keep BYTE0 containing vector bits in R3[31:24] */
+ /* This shortens the checking to a max of 8 iterations */
+1: movs r3, r3, lsl #1 /* count number of '1' bits */
+ addcs r2, r2, #1 /* increment reg_count (R2) if C Flag set */
+ add r1, r1, #4 /* Walk the stack to locate the PUSHed LR (POP PC) value */
+ bne 1b /* continue until vector is empty */
+ ldr r0, [r1] /* Retrieve new PC value */
+#if 0
+ /* PC Value should have B0 set */
+ orr r0, r0, #0x01 /* Force R0[0] since it is used to indicates Thumb mode */
+#endif
+ ldmfd sp!, {pc}
+
+
+/* _thumb_bcond_swi_handler
+ * B<cond> or SWI (SVC)
+ * On entry:
+ * R0: instruction to be executed
+ * R1: Default Following Instruction Address (PC+2)
+ * R5[3:0]: CPSR condition codes
+ * On exit:
+ * R0: following instruction address (B0 set to indicate Thumb mode)
+ * R1-R6: destroyed
+ */
+_thumb_bcond_swi_handler:
+ mov r4, r0 /* Keep instruction in R4 */
+ and r2, r0, #0x0F00 /* Keep Condition Code R2[11:8] */
+ teq r2, #0x0F00 /* SVC (SWI) instruction */
+_thumb_swi_instr:
+ ldreq r0, =SVC_VECTOR /* Return SVC Vector Address */
+ beq _exit_thumb_bcond_swi_handler /* Switch to ARM mode for SVC */
+_thum_bcond_unused_instr:
+ teq r2, #0x0E00
+ moveq r0, r6 /* False (don't execute), so use Default Following Instruction Address */
+ beq _exit_thumb_bcond_instr
+
+_thumb_bcond_instr:
+ mov r6, r1 /* Store Default Following Instruction Address in R6 */
+ lsl r0, r2, #(32-12) /* Shift condition code in R2[11:8] to R0[31:28] to match ARM cond-code format */
+ bl _dbg_check_arm_condcode /* Use ARM condition code checking routine to test (R4, R6 unchanged) */
+ teq r0, #FALSE
+ moveq r0, r6 /* False (don't execute), so use Default Following Instruction Address */
+ beq _exit_thumb_bcond_instr
+
+_thumb_calc_bcond_offset:
+ lsl r0, r4, #(32-8) /* Shift 8-bit offset in R4[7:0] to R0[31:24] */
+ asr r0, r0, #(32-9) /* Convert into 9-bit signed offset in R0[8:0] */
+ add r0, r6, r0 /* PC+2 + signed offset */
+ add r0, r0, #2 /* PC+4 + signed offset */
+_exit_thumb_bcond_instr:
+ orr r0, r0, #0x01 /* Set R0[0] since it is used to indicates Thumb mode */
+_exit_thumb_bcond_swi_handler:
+ bx lr
+
+/* _thumb_b_handler
+ * B
+ * On entry:
+ * R0: instruction to be executed
+ * R1: Default Following Instruction Address (PC+2)
+ * R5[3:0]: CPSR condition codes
+ * On exit:
+ * R0: following instruction address (B0 set to indicate Thumb mode)
+ * R1: destroyed
+ * Note: The signed offset is 12-bits (encoded value x 2)
+ */
+_thumb_b_handler:
+ stmfd sp!, {lr}
+ lsl r0, r0, #(32-11) /* Shift 11-bit offset in R0[10:0] to R0[31:21] */
+ asr r0, r0, #(32-12) /* Convert into 12-bit signed offset in R0[11:0] */
+ add r0, r1, r0 /* PC+2 + signed offset */
+ add r0, r0, #2 /* PC+4 + signed offset */
+ orr r0, r0, #0x01 /* Set R0[0] since it is used to indicates Thumb mode */
+ ldmfd sp!, {pc}
+
+
+/* _thumb_long_bl_blx_handler
+ * Long BL or BLX (4 bytes) Note: b11 (H) indicates 1st or 2nd instr; armv4t does not support BLX.
+ * On entry:
+ * R0: instruction to be executed
+ * R1: Default Following Instruction Address (PC+2)
+ * R5[3:0]: CPSR condition codes
+ * On exit:
+ * R0: following instruction address (B0 set to indicate Thumb mode)
+ * R1, R2, R3: destroyed
+ * Note: The BL instruction (0xFxxx) should be in pairs (Dual 16-bit instructions).
+ * The first instruction should have (H=0) to indicate the upper 11 bits of the encoded offset
+ * The second instruction should have (H=1) to indicate the lower 11 bits of the encoded offset
+ * The signed offset is 23 bits (encoded value x 2)
+ *
+ * Note2: The BLX instruction (0xExxx) encodes the first instruciton using BL (0xFxxx) with H=0,
+ * while the second instruction has a different opcode value (0xExxx), with H=1.
+ * BLX is only used to switch to an ARM target.
+ */
+_thumb_long_bl_blx_handler:
+ stmfd sp!, {lr}
+ tst r0, #0x0800 /* Check H bit */
+ bne _return_default_thumb_following_instr /* H=1 as first instruction shouldn't happen */
+
+_thumb_is_1st_bl_blx_instruction:
+ lsl r0, r0, #(32-11) /* Shift 11-bit offset in R0[10:0] to R0[31:21] */
+ asr r0, r0, #(32-23) /* Convert into 12-bit signed offset in R0[22:12] */
+ ldrh r3, [r1] /* Get second instruction in pair into R3 */
+ tst r3, #0x0800 /* Check H bit */
+ beq _exit_thumb_long_bl_blx_handler /* H=0 as second instruction shouldn't happen */
+
+ lsl r2, r3, #(32-11) /* Shift 11-bit offset in R3[10:0] to R2[31:21] */
+ lsr r2, r2, #(32-12) /* Convert into 12-bit unsigned offset in R2[11:0] */
+ orr r0, r0, r2 /* Combine offsets */
+ add r0, r1, r0 /* PC+2 + signed offset */
+ add r0, r0, #2 /* PC+4 + signed offset */
+
+_thumb_is_2nd_bl_blx_instruction:
+ and r3, r3, #0x0F000 /* Keep instruction opcode in R3 */
+
+ cmp r3, #0x0F000 /* Look for BL */
+ orreq r0, r0, #0x01 /* Match, set R0[0] since it is used to indicates Thumb mode */
+ beq _exit_thumb_long_bl_blx_handler
+
+#ifndef __ARM6OR7__
+ /* v5t or higher architecture */
+ cmp r3, #0x0E000 /* Look for BLX */
+ biceq r0, r0, #0x03 /* Match, Force ARM address */
+ beq _exit_thumb_long_bl_blx_handler
+#endif
+
+_return_default_thumb_following_instr:
+ mov r0, r1 /* Return default Following Instruction Address */
+
+_exit_thumb_long_bl_blx_handler:
+ ldmfd sp!, {pc}
+
+
+/****************************************************************************
+ *
+ * Breakpoint Manipulation Routines
+ *
+ ****************************************************************************/
+/* _dbg_find_breakpoint_slot
+ * Find the matching Breakpoint Slot.
+ * This is both used to find empty slots (pass R0=0x0000) or
+ * occupied slots (pass R0=<brkpt addr>)
+ *
+ * On Entry:
+ * R0: Breakpoint Address
+ * On Exit:
+ * R0: Matching Index (-1: not found)
+ *
+ * NOTE: This routine performs exact match, i.e., breakpoint address MUST be configured
+ * for ARM or Thumb (bit 0 clear/set) as appropriate
+ */
+
+_dbg_find_breakpoint_slot:
+ stmfd sp!, {r1,r2,r3, lr}
+ mov r1, #1 /* Only consider Breakpoints 1-7 */
+ ldr r3, =__breakpoints_num__
+1:
+ _index2bkptindex_addr r1, r2 /* Calculate Breakpoint Entry Address */
+ ldr r2, [r2] /* Get actual breakpoint entry (instruction address) */
+ cmp r0, r2
+ beq _found_breakpoint_slot
+ add r1, r1, #1 /* no match, check next */
+ cmp r1, r3
+ blo 1b /* continue checking only if we don't exceed __breakpoints_num__ */
+
+_notfound_breakpoint_slot:
+ mov r1, #CMD_BKPT_NOTFOUND
+_found_breakpoint_slot:
+ mov r0, r1 /* Return value in R0 */
+ ldmfd sp!, {r1,r2,r3, pc}
+
+/* _dbg__clear_singlestep
+ * Clear the Single Step Breakpoint
+ */
+_dbg__clear_singlestep:
+ ldr r0, =__breakpoints_start__ /* Single Step Breakpoint is at the beginning of the Breakpoint State Struct */
+/* b _dbg__clear_one_breakpoint */
+
+/* _dbg__clear_one_breakpoint
+ * On entry, R0 contains the Breakpoint State slot address to be cleared
+ *
+ */
+_dbg__clear_one_breakpoint:
+ mov r1, #0
+ mov r2, #0
+ stmea r0!, {r1, r2} /* clear Breakpoint state */
+ bx lr
+
+/* _dbg__clear_breakpoints
+ * Routine iterates through the array of breakpoints (incl single step breakpoint) and clears the breakpoint
+ */
+_dbg__clear_breakpoints:
+ stmfd sp!, {lr}
+ ldr r0, =__breakpoints_start__ /* Single Step Breakpoint is at the beginning of the Breakpoint State Struct */
+ ldr r3, =__breakpoints_end__ /* start from top of the table */
+3: bl _dbg__clear_one_breakpoint
+ cmp r0, r3
+ blo 3b
+ ldmfd sp!, {pc}
+
+/* _dbg__install_singlestep
+ * Install the Single Step Breakpoint
+ * On entry:
+ * R1: Instruction Address (31 bits, b0 = THUMB flag)
+ */
+_dbg__install_singlestep:
+ mov r0, #0
+/* b _dbg__install_one_breakpoint */
+
+/* _dbg__install_one_breakpoint
+ * Install breakpoint entry into Breakpoint State Table
+ * On entry:
+ * R0: Breakpoint index (assumed valid)
+ * R1: Instruction Address (31 bits, b0 = THUMB flag)
+ *
+ * On exit:
+ * R2: Breakpoint Instruction
+ * R3: Breakpoint Entry address
+ */
+_dbg__install_one_breakpoint:
+/* Check for Thumb bit */
+ tst r1, #BKPT_STATE_THUMB_FLAG /* 1: Thumb instruction */
+/* Assume that the address entry is valid, otherwise we should sanitize it (mask out b1) */
+ ldreq r2, [r1] /* if 0: load ARM instruction from address location */
+ ldrneh r2, [r1] /* else load Thumb instruction */
+ _index2bkptindex_addr r0, r3 /* Calculate Breakpoint Entry Address */
+ stm r3, {r1, r2}
+ bx lr
+
+
+/* _dbg__restore_singlestep
+ * Restores the contents of the single step breakpoint to memory
+ */
+_dbg__restore_singlestep:
+ mov r0, #0 /* single step breakpoint index */
+ _index2bkptindex_addr r0, r1 /* Calculate Single Step Breakpoint Entry Address */
+ ldm r1, {r1, r2} /* r1: Breakpoint Address, r2: Breakpoint Instruction */
+ teq r1, #0
+ bxeq lr /* Exit if not active */
+/* b _dbg__restore_one_breakpoint */
+
+/* _dbg__restore_one_breakpoint
+ * Restores the contents to memory for one breakpoint
+ * On entry:
+ * R0: Breakpoint index (assumed valid) [not used -- can be used for validating BKPT]
+ * R1: Breakpoint Address (assumed valid)
+ * R2: Breakpoint Instruction (assumed valid)
+ */
+_dbg__restore_one_breakpoint:
+/* Check for Thumb bit */
+ tst r1, #BKPT_STATE_THUMB_FLAG /* 1: Thumb instruction */
+/* Assume that the address entry is valid, otherwise we should sanitize it (mask out b1) */
+ streq r2, [r1] /* if 0: restore ARM instruction to address location */
+ bicne r1, #BKPT_STATE_THUMB_FLAG /* else, clear Thumb Flag */
+ strneh r2, [r1] /* store Thumb instruction */
+ bx lr
+
+/* _dbg__restore_breakpoints
+ * Routine iterates through the array of breakpoints (incl single step breakpoint) and restores the contents to memory
+ * Only Active breakpoints (i.e., Non-zero Address) are processed.
+ */
+_dbg__restore_breakpoints:
+ stmfd sp!, {lr}
+ ldr r5, =_dbg__restore_one_breakpoint
+ b __dbg__iterate_breakpoint_array
+
+/* _dbg__activate_singlestep
+ * Activate the single step breakpoint to memory
+ */
+_dbg__activate_singlestep:
+ mov r0, #0 /* single step breakpoint index */
+ _index2bkptindex_addr r0, r1 /* Calculate Single Step Breakpoint Entry Address */
+ ldm r1, {r1, r2} /* r1: Breakpoint Address, r2: Breakpoint Instruction */
+ teq r1, #0
+ bxeq lr /* Exit if not active */
+/* b _dbg__activate_one_breakpoint */
+
+/* _dbg__activate_one_breakpoint
+ * Activate one breakpoint to memory
+ * On entry:
+ * R0: Breakpoint index (assumed valid)
+ * R1: Breakpoint Address (assumed valid)
+ * R2: Breakpoint Instruction (assumed valid)
+ */
+_dbg__activate_one_breakpoint:
+/* Check for Thumb bit */
+ tst r1, #BKPT_STATE_THUMB_FLAG /* 1: Thumb instruction */
+ bne _nx_is_thumb_bp
+_nx_is_arm_bp:
+/* Assume that the address entry is valid, otherwise we should sanitize it (mask out b1) */
+ ldr r3, [r1] /* if 0: load ARM instruction from address location */
+ teq r2, r3 /* check that the two instructions are identical */
+ bne _dbg__breakpoint_invalid_arm
+ ldr r2, =BKPT32_INSTR /* ARM BKPT instruction */
+ and r2, r2, r0 /* Merge Breakpoint index */
+ str r2, [r1] /* Store it into memory location */
+_dbg__breakpoint_invalid_arm:
+ bx lr
+_nx_is_thumb_bp:
+ bic r1, #BKPT_STATE_THUMB_FLAG /* else, clear Thumb Flag */
+ ldrh r3, [r1] /* load Thumb instruction from address location */
+ teq r2, r3 /* check that the two instructions are identical */
+ bne _dbg__breakpoint_invalid_thumb
+ ldr r2, =BKPT16_INSTR /* Thumb BKPT instruction */
+ and r2, r2, r0 /* Merge Breakpoint index */
+ strh r2, [r1] /* Store it into memory location */
+_dbg__breakpoint_invalid_thumb:
+ bx lr
+
+/* _dbg__activate_breakpoints
+ * Routine iterates through the array of breakpoints (incl single step breakpoint) and activates them
+ * Only Active breakpoints (i.e., Non-zero Address) are processed.
+ */
+_dbg__activate_breakpoints:
+ stmfd sp!, {lr}
+ ldr r5, =_dbg__activate_one_breakpoint
+ b __dbg__iterate_breakpoint_array
+
+
+/* __dbg__iterate_breakpoint_array
+ * Common routine iterates through the array of breakpoints (incl single step breakpoint)
+ * and executes routine given in R5, passing:
+ * R0: Breakpoint index
+ * R1: Breakpoint Address
+ * R2: Breakpoint Instruction
+ *
+ * On Entry:
+ * Assumes that lr has been push to stack (routine can't be called directly)
+ *
+ * Only Active breakpoints (i.e., Non-zero Address entries) are processed.
+ */
+__dbg__iterate_breakpoint_array:
+ ldr r4, =__breakpoints_end__ /* start from top of the table (Assume __breakpoints_end__ > __breakpoints_start__) */
+ ldr r3, =__breakpoints_start__ /* end address check */
+ ldr r0, =__breakpoints_num__ /* Number of Breakpoints (incl Single Step) (Assume Non-Zero) */
+4: sub r0, r0, #1 /* Decrement breakpoint index in r0 */
+ ldmea r4!, {r1, r2} /* r1: Breakpoint Address, r2: Breakpoint Instruction */
+ teq r1, #0 /* Is it active? */
+ movne lr, pc
+ bxne r5 /* active entry */
+ cmp r4, r3
+ bhi 4b /* if (pointer > start of Breakpoint Table address), get next slot */
+ ldmfd sp!, {pc}
+
+/* _dbg__activate_autobreakpoint
+ * Activate all other breakpoints except current breakpoint, activate auto breakpoint in next instr slot
+ * On entry:
+ * R0: Current Breakpoint index (assumed valid)
+ * R1: Next Instruction address (for AUTO Breakpoint) [Not used, assume Single Step Breakpoint already has correct info]
+ */
+_dbg__activate_autobreakpoint:
+ stmfd sp!, {lr}
+ mov r5, r0 /* Keep Current Breakpoint Index in r5 */
+ ldr r4, =__breakpoints_end__ /* start from top of the table */
+ ldr r0, =__breakpoints_num__ /* Number of Breakpoints (incl Single Step) (Assume Non-Zero) */
+4: subs r0, r0, #1 /* Decrement breakpoint index in r0 */
+ ldmea r4!, {r1, r2} /* r1: Breakpoint Address, r2: Breakpoint Instruction */
+ bls 5f /* Flag set by subs instruction previously. Reached Single Step, go activate AUTO Breakpoint */
+ teq r0, r5 /* Is it the Current Breakpoint? */
+ beq 4b /* Yes, so skip */
+ teq r1, #0 /* Is it active? */
+ blne _dbg__activate_one_breakpoint /* active entry */
+ b 4b /* Next iteration */
+5:
+/* Here, r1: Breakpoint Address, r2: Breakpoint Instruction */
+ tst r1, #BKPT_STATE_THUMB_FLAG /* Check for Thumb bit -- 1: Thumb instruction */
+ orreq r0, r5, #BKPT32_AUTO_BKPT /* Is ARM Instruction, merge AUTO flag with Current Breakpoint Index */
+ orrne r0, r5, #BKPT16_AUTO_BKPT /* Is Thumb Instruction, merge AUTO flag with Current Breakpoint Index */
+ bl _dbg__activate_one_breakpoint /* Activate AUTO Breakpoint */
+ ldmfd sp!, {pc}
+
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_stub.h b/AT91SAM7S256/armdebug/Debugger/debug_stub.h
new file mode 100644
index 0000000..931aa68
--- /dev/null
+++ b/AT91SAM7S256/armdebug/Debugger/debug_stub.h
@@ -0,0 +1,132 @@
+/** @file debug_stub.h
+ * @brief Shared C/ASM header file for debugger stub
+ *
+ */
+
+/* Copyright (C) 2007-2010 the NxOS developers
+ *
+ * Module Developed by: TC Wan <tcwan@cs.usm.my>
+ *
+ * See AUTHORS for a full list of the developers.
+ *
+ * See COPYING for redistribution license
+ *
+ */
+
+#ifndef __DEBUG_STUB_H__
+#define __DEBUG_STUB_H__
+
+#include "_c_arm_macros.h"
+
+/** @name BKPT suppport constants
+ *
+ * ARM and Thumb Breakpoint Instructions.
+ */
+/*@{*/
+
+#define __ARM6OR7__
+
+#ifdef __ARM6OR7__
+#define BKPT32_INSTR 0xE7200070 /* ARM6 and ARM7 does not trap unused opcodes (BKPT overlap with control instructions), \
+ CPU has unpredictable behavior. Ref: Steve Furber, ARM SoC Architecture 2nd Ed, pg. 143 */
+#else
+#define BKPT32_INSTR 0xE1200070 /* ARM BKPT instruction, will work in ARMv5T and above */
+#endif
+
+#define BKPT32_ENUM_MASK 0x000FFF0F /* ARM BKPT Enum Mask */
+#define BKPT32_AUTO_BKPT 0x00080000 /* ARM BKPT Auto-Step Flag (for CONT support) */
+#define BKPT32_MANUAL_BKPT 0x0007FF0F /* Manually inserted ARM Breakpoint */
+
+#define BKPT16_INSTR 0xBE00 /* Thumb BKPT instruction */
+#define BKPT16_ENUM_MASK 0x00FF /* Thumb BKPT Enum Mask */
+#define BKPT16_AUTO_BKPT 0x0080 /* Thumb BKPT Auto-Step Flag (for CONT support) */
+#define BKPT16_MANUAL_BKPT 0x007F /* Manually inserted Thumb Breakpoint */
+/*@}*/
+
+#ifndef __ASSEMBLY__
+
+/* Define C stuff */
+/** @defgroup debug_public */
+/*@{*/
+
+
+/** Initialize Debugger.
+ * Equivalent to GDB set_debug_traps() routine
+ */
+FUNCDEF void dbg__bkpt_init(void);
+
+#ifndef __NXOS__
+/** Switch Mode to Debugger.
+ * Used by NXT Firmware only
+ */
+FUNCDEF UWORD cCommHandleDebug(UBYTE *pInBuf, UBYTE CmdBit, UWORD MsgLength);
+#endif
+
+/** Debugger Handler Routine (called by Exception Handler Trap).
+ * Equivalent to GDB handle_exception() routine
+ */
+FUNCDEF void dbg__bkpt_handler(void);
+
+/** dbg_breakpoint_arm.
+ * Equivalent to GDB breakpoint() routine for ARM code
+ */
+/* FUNCDEF void dbg_breakpoint_arm(void); */
+static inline void dbg_breakpoint_arm(void)
+{
+ asm volatile (".word %a0"
+ : /* Output (empty) */
+ : "X" (BKPT32_INSTR | BKPT32_MANUAL_BKPT)
+ );
+}
+
+#if 0 /* Old asm definitions, in case gas does not recognize %a0 operand */
+
+#ifdef __ARM6OR7__
+static inline void dbg_breakpoint_arm(void) { asm volatile (".word 0xE727FF7F" /* (BKPT32_INSTR | BKPT32_MANUAL_BKPT) */ ); }
+#else
+static inline void dbg_breakpoint_arm(void) { asm volatile (".word 0xE127FF7F" /* (BKPT32_INSTR | BKPT32_MANUAL_BKPT) */ ); }
+#endif
+
+#endif
+
+/** dbg_breakpoint_thumb.
+ * Equivalent to GDB breakpoint() routine for Thumb code
+ */
+/* FUNCDEF void dbg_breakpoint_thumb(void); */
+static inline void dbg_breakpoint_thumb(void)
+{
+ asm volatile (".hword %a0"
+ : /* Output (empty) */
+ : "X" (BKPT16_INSTR | BKPT16_MANUAL_BKPT)
+ );
+}
+
+#if 0 /* Old asm definitions, in case gas does not recognize %a0 operand */
+
+static inline void dbg_breakpoint_thumb(void) { asm volatile (".hword 0xBE7F" /* (BKPT16_INSTR | BKPT16_MANUAL_BKPT) */); }
+
+#endif
+
+/*@}*/
+
+#else
+/* Define Assembly stuff */
+
+/* dbg__bkpt_arm
+ * GDB breakpoint() for ARM mode
+ */
+ .macro dbg__bkpt_arm
+ .word (BKPT32_INSTR | BKPT32_MANUAL_BKPT)
+ .endm
+
+/* dbg__bkpt_arm
+ * GDB breakpoint() for Thumb mode
+ */
+ .macro dbg__bkpt_thumb
+ .hword (BKPT16_INSTR | BKPT16_MANUAL_BKPT)
+ .endm
+
+#endif
+ /*@}*/
+
+#endif /* __DEBUG_STUB_H__ */
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_test.S b/AT91SAM7S256/armdebug/Debugger/debug_test.S
new file mode 100644
index 0000000..91e19d2
--- /dev/null
+++ b/AT91SAM7S256/armdebug/Debugger/debug_test.S
@@ -0,0 +1,53 @@
+/** @file debug_test.S
+ * @brief Test Routines to trigger ARM and Thumb Manual Breakpoints
+ *
+ */
+
+/* Copyright (C) 2007-2011 the NxOS developers
+ *
+ * Module Developed by: TC Wan <tcwan@cs.usm.my>
+ *
+ * See AUTHORS for a full list of the developers.
+ *
+ * See COPYING for redistribution license
+ *
+ */
+#define __ASSEMBLY__
+#include "debug_stub.h"
+
+.text
+.align 4
+.code 32
+
+/**********************************************
+ * dbg__test_arm_bkpt Test Routine
+ *
+ */
+ .global dbg__test_arm_bkpt
+dbg__test_arm_bkpt:
+ stmfd sp!,{lr}
+ dbg__bkpt_arm /* Trigger ARM Manual Breakpoint */
+ ldmfd sp!,{pc}
+
+/**********************************************
+ * dbg__test_thumb_bkpt Test Routine
+ *
+ */
+ .global dbg__test_thumb_bkpt
+dbg__test_thumb_bkpt:
+ stmfd sp!,{lr}
+/* ldr r0, =_thumb_entry
+ orr r0, r0, #1 @ Set Thumb mode
+ mov lr, pc
+ bx r0
+*/
+ bl _thumb_entry
+ ldmfd sp!,{pc}
+
+.code 16
+.thumb_func
+_thumb_entry:
+ dbg__bkpt_thumb
+ bx lr
+
+.end
diff --git a/AT91SAM7S256/armdebug/Debugger/debug_test.h b/AT91SAM7S256/armdebug/Debugger/debug_test.h
new file mode 100644
index 0000000..6680f58
--- /dev/null
+++ b/AT91SAM7S256/armdebug/Debugger/debug_test.h
@@ -0,0 +1,35 @@
+/** @file debug_test.h
+ * @brief C header file for debugger test routines
+ *
+ */
+
+/* Copyright (C) 2007-2010 the NxOS developers
+ *
+ * Module Developed by: TC Wan <tcwan@cs.usm.my>
+ *
+ * See AUTHORS for a full list of the developers.
+ *
+ * See COPYING for redistribution license
+ *
+ */
+
+#ifndef __DEBUG_TEST_H__
+#define __DEBUG_TEST_H__
+
+#include "_c_arm_macros.h"
+
+#ifndef __ASSEMBLY__
+
+/* Define C stuff */
+/** @defgroup debug_public */
+/*@{*/
+
+FUNCDEF void dbg__test_arm_bkpt(void);
+FUNCDEF void dbg__test_thumb_bkpt(void);
+
+ /*@}*/
+
+#endif
+
+
+#endif /* __DEBUG_TEST_H__ */
diff --git a/AT91SAM7S256/armdebug/Debugger/undef_handler.S b/AT91SAM7S256/armdebug/Debugger/undef_handler.S
new file mode 100644
index 0000000..f185fbd
--- /dev/null
+++ b/AT91SAM7S256/armdebug/Debugger/undef_handler.S
@@ -0,0 +1,147 @@
+
+/* Copyright (C) 2007-2010 the NxOS developers
+ *
+ * Module Developed by: TC Wan <tcwan@cs.usm.my>
+ *
+ * See AUTHORS for a full list of the developers.
+ *
+ * Redistribution of this file is permitted under
+ * the terms of the GNU Public License (GPL) version 2.
+ */
+#define __ASSEMBLY__
+#include "debug_stub.h"
+#include "debug_internals.h"
+
+
+.text
+.code 32
+.align 0
+
+ .extern dbg__thumb_bkpt_handler
+ .extern dbg__arm_bkpt_handler
+ .extern default_undef_handler
+
+ .global undef_handler
+
+undef_handler:
+/* Remote GDB Debugger relies on BKPT instruction being trapped here
+ * In ARMv4t, it is an Illegal (Undefined) Instruction.
+ * On triggering, lr (R14) contains the previous mode's pc (R15).
+ * Based on example in Hohl, "ARM Assembly Language: Fundamentals and Techniques"
+ * Chapter 11, Example 11.1.
+ * Note: The handler is not AAPCS compliant (8 byte-alignment and stack, etc.)
+ */
+ /* We assume that the UNDEF stack holds only one stack frame and we will overwrite it.
+ * On entry, LR_undef points to one instruction past the UNDEF instruction.
+ *
+ * For the purpose of Debugging, the stack frame should present the PC (R15) as the address
+ * of the instruction that triggered the Breakpoint. Hence we need to adjust R15
+ * to point to the address of the UNDEF instruction. This is what the JTAG debugger
+ * does. (In the ARM hardware, the PC would point to UNDEF+2 instruction address
+ * since it has a three stage pipeline).
+ *
+ * We will also store UNDEF LR (next instruction pointer) and UNDEF SPSR to the stack.
+ *
+ * For the handler, once the user registers have been stored in the debug stack, the
+ * registers will be used as follows:
+ *
+ * R0: UNDEF LR, then UNDEF instruction address, finally UNDEF instruction word / BKPT index
+ * R1: SPSR
+ * R2: Mode
+ * R3: Debug Stack Pointer (for Banked R13-R14 update)
+ */
+ ldr sp, =__debugger_stack__
+ stmfd sp, {r0-r15}^ /* Save workspace, previous mode's pc via 'S' flag, R13-R15: placeholders */
+ mov r3, sp /* Use R3 to write Banked R13-R14, and actual PC of UNDEF instruction */
+ sub sp, sp, #(4*16) /* Need to manually update SP(undef) */
+
+ mov r0, lr /* Keep Next Instruction address after UNDEF instruction in R0 */
+ mrs r1, spsr /* Copy SPSR to r1 */
+ stmfd sp!, {r0,r1} /* Save User's Next Instr Pointer (in UNDEF LR) and previous mode's CPSR to stack */
+
+ tst r1, #CPSR_THUMB /* Check for Thumb Mode */
+ subne r0, r0, #2 /* Is Thumb instruction, adjust PC for UNDEF instruction address */
+ subeq r0, r0, #4 /* Is ARM instruction, adjust PC for UNDEF instruction address */
+ str r0, [r3, #-4]! /* Save PC to stack (R15 slot) */
+
+ and r2, r1, #CPSR_MODE /* Get previous mode */
+ teq r2, #MODE_USR
+ beq _skip_banked_registers /* Can't switch back if we're in User mode! */
+
+_store_prev_mode_banked_regs:
+ /* FIXME: We don't handle FIQ properly! */
+
+ orr r2, #(CPSR_FIQ | CPSR_IRQ) /* Disable Interrupts */
+ msr cpsr_c, r2 /* Switch to previous mode */
+ stmfd r3!, {sp, lr} /* Store Previous Mode's LR (R14), SP (R13) via R3 */
+ msr cpsr_c, #(MODE_UND | CPSR_FIQ | CPSR_IRQ) /* Revert to Undef Mode */
+
+_skip_banked_registers:
+ tst r1, #CPSR_THUMB /* Check for Thumb Mode */
+ beq _is_arm /* Clear, so it's ARM mode */
+_is_thumb:
+ ldrh r0, [r0] /* load UNDEF instruction into r0 */
+ ldr r1, =BKPT16_ENUM_MASK /* Thumb BKPT enum mask */
+ bic r2, r0, r1 /* leave only opcode */
+ ldr r1, =BKPT16_INSTR /* check for Thumb Breakpoint Instruction */
+ 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 */
+ ldr r1, =BKPT32_ENUM_MASK /* ARM BKPT enum mask */
+ bic r2, r0, r1 /* leave only opcode */
+ ldr r1, =BKPT32_INSTR /* check for ARM Breakpoint Instruction */
+ 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 */
+ mov pc, r2 /* Invoke Debugger State (Supervisor Mode) */
+
+ .global resume_execution
+
+resume_execution:
+/*
+ * This routine is called by the Debugger prior to returning control to
+ * the executing program.
+ * It updates the SPSR_UNDEF with the Debug Stack value, and
+ * restores all registers R0-R14 to the previously active mode.
+ * Then, it uses the Next Instruction Address Pointer to return
+ * execution control to the previously executing program.
+ */
+/* On Entry, SP(undef) points to the Next Instruction Address.
+ * If the instruction which triggered the Breakpoint need to be
+ * reexecuted, it should be placed in the Next Instruction Address slot
+ * by ABORT mode before coming here
+ */
+ ldr lr, =__debugger_stack_bottom__ /* Use LR(undef) for Debug Stack Access */
+ add r1, lr, #(DBGSTACK_USERSP_INDEX*4) /* Use R1 for Previous Mode SP (R13) and LR (R14) access */
+ ldr r0, [lr, #(DBGSTACK_USERCPSR_INDEX*4)]! /* LR updated, Retrieve SPSR into R0 */
+ msr spsr, r0 /* Update SPSR for return to program being debugged */
+ and r0, r0, #CPSR_MODE /* Get previous mode */
+ teq r0, #MODE_USR
+ bne _restore_prev_mode_banked_regs /* Can't switch back if we're in User mode! */
+
+ /* Previous mode was User Mode */
+ ldmed lr, {r0-r14}^ /* We use LDMED since LR is pointing to USERCPSR not R0 */
+ b _really_resume_execution
+
+_restore_prev_mode_banked_regs:
+ /* FIXME: We don't handle FIQ properly! */
+ orr r0, #(CPSR_FIQ | CPSR_IRQ) /* Disable Interrupts */
+ msr cpsr_c, r0 /* Switch to previous mode */
+ ldmfd r1, {sp, lr} /* Restore Previous Mode's LR (R14), SP (R13) via R1 */
+ msr cpsr_c, #(MODE_UND | CPSR_FIQ | CPSR_IRQ) /* Revert to Undef Mode */
+ ldmed lr, {r0-r12} /* We use LDMED since LR is pointing to USERCPSR not R0 */
+
+_really_resume_execution:
+ ldmfd sp, {pc}^ /* Exit to Previous Mode using Next Instruction Address */
+
+
+
+
diff --git a/AT91SAM7S256/armdebug/Doxyfile b/AT91SAM7S256/armdebug/Doxyfile
new file mode 100644
index 0000000..6266354
--- /dev/null
+++ b/AT91SAM7S256/armdebug/Doxyfile
@@ -0,0 +1,243 @@
+# Doxyfile 1.5.3-20071008
+
+#---------------------------------------------------------------------------
+# Project related configuration options
+#---------------------------------------------------------------------------
+DOXYFILE_ENCODING = UTF-8
+PROJECT_NAME = "NxOS Debugger"
+PROJECT_NUMBER =
+OUTPUT_DIRECTORY = ../doc/debug
+CREATE_SUBDIRS = NO
+OUTPUT_LANGUAGE = English
+BRIEF_MEMBER_DESC = YES
+REPEAT_BRIEF = YES
+ABBREVIATE_BRIEF = "The $name class" \
+ "The $name widget" \
+ "The $name file" \
+ is \
+ provides \
+ specifies \
+ contains \
+ represents \
+ a \
+ an \
+ the
+ALWAYS_DETAILED_SEC = NO
+INLINE_INHERITED_MEMB = NO
+FULL_PATH_NAMES = YES
+STRIP_FROM_PATH =
+STRIP_FROM_INC_PATH =
+SHORT_NAMES = NO
+JAVADOC_AUTOBRIEF = NO
+QT_AUTOBRIEF = NO
+MULTILINE_CPP_IS_BRIEF = NO
+#DETAILS_AT_TOP = NO
+INHERIT_DOCS = YES
+SEPARATE_MEMBER_PAGES = NO
+TAB_SIZE = 8
+ALIASES =
+OPTIMIZE_OUTPUT_FOR_C = YES
+OPTIMIZE_OUTPUT_JAVA = NO
+BUILTIN_STL_SUPPORT = NO
+CPP_CLI_SUPPORT = NO
+SIP_SUPPORT = NO
+DISTRIBUTE_GROUP_DOC = NO
+SUBGROUPING = YES
+#---------------------------------------------------------------------------
+# Build related configuration options
+#---------------------------------------------------------------------------
+EXTRACT_ALL = NO
+EXTRACT_PRIVATE = YES
+EXTRACT_STATIC = YES
+EXTRACT_LOCAL_CLASSES = YES
+EXTRACT_LOCAL_METHODS = NO
+EXTRACT_ANON_NSPACES = NO
+HIDE_UNDOC_MEMBERS = NO
+HIDE_UNDOC_CLASSES = NO
+HIDE_FRIEND_COMPOUNDS = NO
+HIDE_IN_BODY_DOCS = NO
+INTERNAL_DOCS = YES
+CASE_SENSE_NAMES = YES
+HIDE_SCOPE_NAMES = NO
+SHOW_INCLUDE_FILES = YES
+INLINE_INFO = YES
+SORT_MEMBER_DOCS = YES
+SORT_BRIEF_DOCS = NO
+SORT_BY_SCOPE_NAME = NO
+GENERATE_TODOLIST = YES
+GENERATE_TESTLIST = YES
+GENERATE_BUGLIST = YES
+GENERATE_DEPRECATEDLIST= YES
+ENABLED_SECTIONS =
+MAX_INITIALIZER_LINES = 30
+SHOW_USED_FILES = YES
+SHOW_DIRECTORIES = NO
+FILE_VERSION_FILTER =
+#---------------------------------------------------------------------------
+# configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+QUIET = NO
+WARNINGS = YES
+WARN_IF_UNDOCUMENTED = YES
+WARN_IF_DOC_ERROR = YES
+WARN_NO_PARAMDOC = NO
+WARN_FORMAT = "$file:$line: $text"
+WARN_LOGFILE =
+#---------------------------------------------------------------------------
+# configuration options related to the input files
+#---------------------------------------------------------------------------
+INPUT = .
+INPUT_ENCODING = UTF-8
+FILE_PATTERNS = *.h
+RECURSIVE = YES
+EXCLUDE = at91sam7s256.h
+EXCLUDE_SYMLINKS = NO
+EXCLUDE_PATTERNS =
+EXCLUDE_SYMBOLS =
+EXAMPLE_PATH =
+EXAMPLE_PATTERNS = *
+EXAMPLE_RECURSIVE = NO
+IMAGE_PATH =
+INPUT_FILTER =
+FILTER_PATTERNS =
+FILTER_SOURCE_FILES = NO
+#---------------------------------------------------------------------------
+# configuration options related to source browsing
+#---------------------------------------------------------------------------
+SOURCE_BROWSER = NO
+INLINE_SOURCES = NO
+STRIP_CODE_COMMENTS = YES
+REFERENCED_BY_RELATION = NO
+REFERENCES_RELATION = NO
+REFERENCES_LINK_SOURCE = YES
+USE_HTAGS = NO
+VERBATIM_HEADERS = NO
+#---------------------------------------------------------------------------
+# configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+ALPHABETICAL_INDEX = NO
+COLS_IN_ALPHA_INDEX = 5
+IGNORE_PREFIX =
+#---------------------------------------------------------------------------
+# configuration options related to the HTML output
+#---------------------------------------------------------------------------
+GENERATE_HTML = YES
+HTML_OUTPUT = html
+HTML_FILE_EXTENSION = .html
+HTML_HEADER =
+HTML_FOOTER =
+HTML_STYLESHEET =
+HTML_ALIGN_MEMBERS = YES
+GENERATE_HTMLHELP = NO
+HTML_DYNAMIC_SECTIONS = NO
+CHM_FILE =
+HHC_LOCATION =
+GENERATE_CHI = NO
+BINARY_TOC = NO
+TOC_EXPAND = NO
+DISABLE_INDEX = NO
+ENUM_VALUES_PER_LINE = 1
+GENERATE_TREEVIEW = YES
+TREEVIEW_WIDTH = 280
+#---------------------------------------------------------------------------
+# configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+GENERATE_LATEX = NO
+LATEX_OUTPUT = latex
+LATEX_CMD_NAME = latex
+MAKEINDEX_CMD_NAME = makeindex
+COMPACT_LATEX = NO
+PAPER_TYPE = a4wide
+EXTRA_PACKAGES =
+LATEX_HEADER =
+PDF_HYPERLINKS = YES
+USE_PDFLATEX = YES
+LATEX_BATCHMODE = NO
+LATEX_HIDE_INDICES = NO
+#---------------------------------------------------------------------------
+# configuration options related to the RTF output
+#---------------------------------------------------------------------------
+GENERATE_RTF = NO
+RTF_OUTPUT = rtf
+COMPACT_RTF = NO
+RTF_HYPERLINKS = NO
+RTF_STYLESHEET_FILE =
+RTF_EXTENSIONS_FILE =
+#---------------------------------------------------------------------------
+# configuration options related to the man page output
+#---------------------------------------------------------------------------
+GENERATE_MAN = NO
+MAN_OUTPUT = man
+MAN_EXTENSION = .3
+MAN_LINKS = NO
+#---------------------------------------------------------------------------
+# configuration options related to the XML output
+#---------------------------------------------------------------------------
+GENERATE_XML = NO
+XML_OUTPUT = xml
+XML_SCHEMA =
+XML_DTD =
+XML_PROGRAMLISTING = YES
+#---------------------------------------------------------------------------
+# configuration options for the AutoGen Definitions output
+#---------------------------------------------------------------------------
+GENERATE_AUTOGEN_DEF = NO
+#---------------------------------------------------------------------------
+# configuration options related to the Perl module output
+#---------------------------------------------------------------------------
+GENERATE_PERLMOD = NO
+PERLMOD_LATEX = NO
+PERLMOD_PRETTY = YES
+PERLMOD_MAKEVAR_PREFIX =
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor
+#---------------------------------------------------------------------------
+ENABLE_PREPROCESSING = YES
+#MACRO_EXPANSION = NO
+MACRO_EXPANSION = YES
+EXPAND_ONLY_PREDEF = NO
+SEARCH_INCLUDES = YES
+INCLUDE_PATH =
+INCLUDE_FILE_PATTERNS =
+PREDEFINED =
+EXPAND_AS_DEFINED =
+SKIP_FUNCTION_MACROS = YES
+#---------------------------------------------------------------------------
+# Configuration::additions related to external references
+#---------------------------------------------------------------------------
+TAGFILES =
+GENERATE_TAGFILE =
+ALLEXTERNALS = NO
+EXTERNAL_GROUPS = YES
+PERL_PATH = /usr/bin/perl
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool
+#---------------------------------------------------------------------------
+CLASS_DIAGRAMS = NO
+MSCGEN_PATH =
+HIDE_UNDOC_RELATIONS = YES
+HAVE_DOT = NO
+CLASS_GRAPH = YES
+COLLABORATION_GRAPH = YES
+GROUP_GRAPHS = YES
+UML_LOOK = NO
+TEMPLATE_RELATIONS = NO
+INCLUDE_GRAPH = YES
+INCLUDED_BY_GRAPH = YES
+CALL_GRAPH = NO
+CALLER_GRAPH = NO
+GRAPHICAL_HIERARCHY = YES
+DIRECTORY_GRAPH = YES
+DOT_IMAGE_FORMAT = png
+DOT_PATH =
+DOTFILE_DIRS =
+DOT_GRAPH_MAX_NODES = 50
+MAX_DOT_GRAPH_DEPTH = 1000
+DOT_TRANSPARENT = YES
+DOT_MULTI_TARGETS = NO
+GENERATE_LEGEND = YES
+DOT_CLEANUP = YES
+#---------------------------------------------------------------------------
+# Configuration::additions related to the search engine
+#---------------------------------------------------------------------------
+SEARCHENGINE = NO
diff --git a/AT91SAM7S256/armdebug/FantomModule/FantomModule.cpp b/AT91SAM7S256/armdebug/FantomModule/FantomModule.cpp
new file mode 100644
index 0000000..b3380f1
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/FantomModule.cpp
@@ -0,0 +1,305 @@
+/*
+ * FantomModule.cp
+ * FantomModule
+ *
+ * Created by tcmac on 01/03/2011.
+ * Copyright 2011 TC Wan. All rights reserved.
+ *
+ * Based on code from Fantom Driver 1.0.2f0 Example
+ * © Copyright 2006, National Instruments Corporation.
+ * All rights reserved. Originated: 10 March 2006
+ *
+ */
+
+#include <iostream>
+#include <string.h>
+#include "FantomModule.h"
+#include "FantomModulePriv.h"
+
+static PyMethodDef FantomMethods[] = {
+ {"finddevices", fantom_finddevices, METH_VARARGS,
+ "Discover NXT Devices (BT Discovery)"},
+ {"find_bricks", fantom_find_bricks, METH_VARARGS,
+ "Find and Create NXT Devices (USB)"},
+ {"socket", fantom_socket, METH_VARARGS,
+ "Create a Socket for a NXT Brick"},
+ {"connect", fantom_connect, METH_VARARGS,
+ "Connect the Socket to a NXT Brick"},
+ {"send", fantom_send, METH_VARARGS,
+ "Send Data via the Socket to a NXT Brick"},
+ {"recv", fantom_recv, METH_VARARGS,
+ "Receive Data via the Socket from a NXT Brick"},
+ {"close", fantom_close, METH_VARARGS,
+ "Close the Socket to a NXT Brick"},
+ {NULL, NULL, 0, NULL} /* Sentinel */
+};
+
+extern "C" PyMODINIT_FUNC
+initfantom(void)
+{
+ (void) Py_InitModule("fantom", FantomMethods);
+}
+
+extern "C" PyObject *fantom_finddevices(PyObject *py_self, PyObject *py_args)
+{
+
+ PyObject *list = FantomModule::finddevices(py_self,py_args);
+
+ return list; // of resource names
+}
+
+extern "C" PyObject *fantom_find_bricks(PyObject *py_self, PyObject *py_args)
+{
+
+ PyObject *list = FantomModule::find_bricks(py_self,py_args);
+
+ return list; // of FantomModule objects
+}
+
+extern "C" PyObject *fantom_socket(PyObject *py_self, PyObject *py_args)
+{
+
+ ViChar newPasskey[FANTOM_PASSKEY_LEN] = FANTOM_NXT_PASSKEY; // Default Passkey
+
+ // FIXME: Retrieve PyObject's proto setting
+ const char *proto;
+ if (!PyArg_ParseTuple(py_args, "s", &proto))
+ return NULL;
+ ViBoolean enableBT = strcmp(proto, FANTOM_BT) ? true : false;
+
+ // Get new passkey from Python args if specified
+
+ // Create a FantomModule object, which has not been connected to an actual NXT yet
+ FantomModule *fantomObject;
+ fantomObject = new FantomModule;
+
+ fantomObject->socket(enableBT, newPasskey); // Internal object setup
+
+ // FIXME: Convert fantomObject to PyObject and return.
+
+}
+
+extern "C" PyObject *fantom_connect(PyObject *py_self, PyObject *py_args)
+{
+ FantomModule *fantomObject;
+ // FIXME: Retrieve FantomObject from PyObject variable
+ ViChar resourceName[FANTOM_NXTNAME_LEN];
+ ViBoolean success;
+
+ success = fantomObject->connect(resourceName);
+}
+
+extern "C" PyObject *fantom_send(PyObject *py_self, PyObject *py_args)
+{
+ FantomModule *fantomObject;
+ // FIXME: Retrieve FantomObject from PyObject variable
+
+ ViByte bufferPtr[FANTOM_DATA_BUFLEN];
+ ViUInt32 numberOfBytes;
+ ViUInt32 bytesSent;
+
+ bytesSent = fantomObject->send(bufferPtr,numberOfBytes);
+}
+
+extern "C" PyObject *fantom_recv(PyObject *py_self, PyObject *py_args)
+{
+ FantomModule *fantomObject;
+ // FIXME: Retrieve FantomObject from PyObject variable
+
+ ViByte bufferPtr[FANTOM_DATA_BUFLEN];
+ ViUInt32 numberOfBytes;
+ ViUInt32 bytesReceived;
+
+ bytesReceived = fantomObject->recv(bufferPtr,numberOfBytes);
+}
+
+extern "C" PyObject *fantom_close(PyObject *py_self, PyObject *py_args)
+{
+ FantomModule *fantomObject;
+ // FIXME: Retrieve FantomObject from PyObject variable
+
+ ViBoolean success = fantomObject->close();
+ delete fantomObject;
+
+ // Return success/failure
+}
+
+
+// Static method called directly from C
+PyObject *FantomModule::finddevices(PyObject *py_self, PyObject *py_args)
+{
+ const char *proto;
+ if (!PyArg_ParseTuple(py_args, "s", &proto))
+ return NULL;
+
+ ViBoolean useBT = strcmp(proto, FANTOM_BT) ? true : false;
+
+ PyObject *list = NULL;
+
+ nFANTOM100::iNXTIterator* nxtIteratorPtr;
+ nFANTOM100::tStatus status;
+
+ // Create an NXT iterator object which is used to find all accessible NXT devices.
+ nxtIteratorPtr = nFANTOM100::iNXT::createNXTIterator(useBT, (useBT ? FANTOM_BT_TIMEOUTSEC : 0), status);
+
+ // Creating the NXT iterator object could fail, better check status before dereferencing a
+ // potentially NULL pointer.
+ while (status.isNotFatal())
+ {
+ ViChar nxtName[FANTOM_NXTNAME_LEN];
+ nxtIteratorPtr->getName(nxtName, status);
+
+ std::cout << "Found: " << nxtName << std::endl;
+
+ if (status.isNotFatal())
+ {
+ // Split nxtName into NXT ID (h) and NXT Name (n)
+ // return as [(h,n),...]
+ // FIXME: Append to Python list
+ /*
+ return Py_BuildValue("i", sts);
+ */
+ }
+ nxtIteratorPtr->advance(status);
+
+ }
+ // Destroy the NXT iterator object which we no longer need
+ nFANTOM100::iNXT::destroyNXTIterator( nxtIteratorPtr );
+ return list;
+
+}
+
+// Static method called directly from C
+PyObject *FantomModule::find_bricks(PyObject *py_self, PyObject *py_args)
+{
+ const char *host, *name;
+ if (!PyArg_ParseTuple(py_args, "ss", &host, &name))
+ return NULL;
+
+ ViBoolean useBT = false;
+
+ PyObject *list = NULL;
+
+
+ nFANTOM100::iNXTIterator* nxtIteratorPtr;
+ nFANTOM100::tStatus status;
+
+ // Create an NXT iterator object which is used to find all accessible NXT devices.
+ nxtIteratorPtr = nFANTOM100::iNXT::createNXTIterator(useBT, (useBT ? FANTOM_BT_TIMEOUTSEC : 0), status);
+
+ // Creating the NXT iterator object could fail, better check status before dereferencing a
+ // potentially NULL pointer.
+ while (status.isNotFatal())
+ {
+ ViChar nxtName[FANTOM_NXTNAME_LEN];
+ nFANTOM100::iNXT* aNXT = NULL;
+
+ nxtIteratorPtr->getName(nxtName, status);
+ std::cout << "Found: " << nxtName << std::endl;
+ aNXT = nxtIteratorPtr->getNXT(status);
+ if (status.isNotFatal())
+ {
+ FantomModule *aFantomObject = new FantomModule;
+ aFantomObject->nxtPtr = aNXT;
+ aFantomObject->status.assign(status);
+ if (strlcpy(aFantomObject->pairedResourceName, nxtName, FANTOM_NXTNAME_LEN) >= FANTOM_NXTNAME_LEN)
+ {
+ // Exceeded Name Length
+ std::cout << "NXTName Length Exceeded: " << nxtName << std::endl;
+ delete aFantomObject;
+ }
+ else
+ {
+ // FIXME: Append to Python list
+ /*
+ return Py_BuildValue("i", sts);
+ */
+ }
+
+ }
+ nxtIteratorPtr->advance(status);
+
+ }
+ // Destroy the NXT iterator object which we no longer need
+ nFANTOM100::iNXT::destroyNXTIterator( nxtIteratorPtr );
+ return list;
+
+}
+
+ViBoolean FantomModule::socket(ViBoolean enableBT, ViConstString BTkey)
+{
+ // Internal class object setup
+ nxtPtr = NULL;
+ useBT = enableBT;
+ if (strlcpy(passkey, BTkey, FANTOM_PASSKEY_LEN) >= FANTOM_PASSKEY_LEN)
+ return false;
+ return true;
+
+}
+
+ViBoolean FantomModule::connect(ViConstString resourceName)
+{
+ // If a NXT is found over BT, the computer and the NXT must be paired before an NXT object can be
+ // created. This can be done programatically using the iNXT::pairBluetooth method.
+ // FIXME: Retrieve resource String
+
+
+ if (useBT and !nFANTOM100::iNXT::isPaired((ViConstString)resourceName,status))
+ nFANTOM100::iNXT::pairBluetooth((ViConstString) resourceName, (ViConstString) passkey, (ViChar *) pairedResourceName, status);
+
+ if (status.isNotFatal())
+ {
+ nxtPtr = nFANTOM100::iNXT::createNXT((ViConstString) resourceName, status, false);
+ }
+}
+
+ViUInt32 FantomModule::send(const ViByte *bufferPtr, ViUInt32 numberOfBytes)
+{
+ nFANTOM100::tStatus status;
+
+ return nxtPtr->write(bufferPtr, numberOfBytes, status);
+}
+
+ViUInt32 FantomModule::recv(ViByte *bufferPtr, ViUInt32 numberOfBytes)
+{
+ nFANTOM100::tStatus status;
+
+ return nxtPtr->read(bufferPtr, numberOfBytes, status);
+}
+
+ViBoolean FantomModule::close()
+{
+
+ const char *proto;
+ useBT = strcmp(proto, FANTOM_BT) ? true : false;
+ if (useBT and nFANTOM100::iNXT::isPaired((ViConstString)pairedResourceName,status))
+ nFANTOM100::iNXT::unpairBluetooth((ViConstString) pairedResourceName, status); // No Effect on Mac OSX
+
+ if (nxtPtr)
+ nFANTOM100::iNXT::destroyNXT(nxtPtr);
+ nxtPtr = NULL;
+
+ return true;
+}
+
+FantomModule::~FantomModule()
+{
+ if (nxtPtr)
+ nFANTOM100::iNXT::destroyNXT(nxtPtr);
+ nxtPtr = NULL;
+
+}
+
+// Skeleton functions from Xcode
+void FantomModule::HelloWorld(const char * s)
+{
+ FantomModulePriv *theObj = new FantomModulePriv;
+ theObj->HelloWorldPriv(s);
+ delete theObj;
+};
+
+void FantomModulePriv::HelloWorldPriv(const char * s)
+{
+ std::cout << s << std::endl;
+};
+
diff --git a/AT91SAM7S256/armdebug/FantomModule/FantomModule.h b/AT91SAM7S256/armdebug/FantomModule/FantomModule.h
new file mode 100644
index 0000000..e2d99cb
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/FantomModule.h
@@ -0,0 +1,60 @@
+/*
+ * FantomModule.h
+ * FantomModule
+ *
+ * Created by tcmac on 01/03/2011.
+ * Copyright 2011 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#ifndef FantomModule_
+#define FantomModule_
+
+#include "Python.h"
+#include "fantom/iNXT.h"
+#include "fantom/iNXTIterator.h"
+#include "fantom/tStatus.h"
+
+#define FANTOM_BT "BT"
+#define FANTOM_USB "USB"
+#define FANTOM_BT_TIMEOUTSEC 5
+#define FANTOM_NXTNAME_LEN 256
+#define FANTOM_PASSKEY_LEN 256
+#define FANTOM_DATA_BUFLEN 256
+#define FANTOM_NXT_PASSKEY "1234"
+
+/* The classes below are exported */
+#pragma GCC visibility push(default)
+
+extern "C" PyMODINIT_FUNC initfantom(void);
+
+extern "C" PyObject *fantom_finddevices(PyObject *py_self, PyObject *py_args); // BT Discovery function
+extern "C" PyObject *fantom_find_bricks(PyObject *py_self, PyObject *py_args); // USB function
+extern "C" PyObject *fantom_socket(PyObject *py_self, PyObject *py_args);
+extern "C" PyObject *fantom_connect(PyObject *py_self, PyObject *py_args);
+extern "C" PyObject *fantom_send(PyObject *py_self, PyObject *py_args);
+extern "C" PyObject *fantom_recv(PyObject *py_self, PyObject *py_args);
+extern "C" PyObject *fantom_close(PyObject *py_self, PyObject *py_args);
+
+class FantomModule
+{
+ nFANTOM100::iNXT* nxtPtr;
+ nFANTOM100::tStatus status;
+ ViBoolean useBT;
+ ViChar passkey[FANTOM_PASSKEY_LEN];
+ ViChar pairedResourceName[FANTOM_NXTNAME_LEN];
+
+ public:
+ static PyObject *finddevices(PyObject *py_self, PyObject *py_args);
+ static PyObject *find_bricks(PyObject *py_self, PyObject *py_args);
+ ViBoolean socket(ViBoolean enableBT, ViConstString BTkey);
+ ViBoolean connect(ViConstString resourceName);
+ ViUInt32 send(const ViByte *bufferPtr, ViUInt32 numberOfBytes);
+ ViUInt32 recv(ViByte *bufferPtr, ViUInt32 numberOfBytes);
+ ViBoolean close();
+ ~FantomModule();
+ void HelloWorld(const char *);
+};
+
+#pragma GCC visibility pop
+#endif
diff --git a/AT91SAM7S256/armdebug/FantomModule/FantomModule.xcodeproj/project.pbxproj b/AT91SAM7S256/armdebug/FantomModule/FantomModule.xcodeproj/project.pbxproj
new file mode 100644
index 0000000..f4a5ec8
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/FantomModule.xcodeproj/project.pbxproj
@@ -0,0 +1,295 @@
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 45;
+ objects = {
+
+/* Begin PBXBuildFile section */
+ 43B531D2131C92690016BF14 /* Python in Frameworks */ = {isa = PBXBuildFile; fileRef = 43B531D1131C92690016BF14 /* Python */; };
+ 43B531F2131C962E0016BF14 /* iFile.h in Headers */ = {isa = PBXBuildFile; fileRef = 43B531EA131C962E0016BF14 /* iFile.h */; };
+ 43B531F3131C962E0016BF14 /* iFileIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = 43B531EB131C962E0016BF14 /* iFileIterator.h */; };
+ 43B531F4131C962E0016BF14 /* iModule.h in Headers */ = {isa = PBXBuildFile; fileRef = 43B531EC131C962E0016BF14 /* iModule.h */; };
+ 43B531F5131C962E0016BF14 /* iModuleIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = 43B531ED131C962E0016BF14 /* iModuleIterator.h */; };
+ 43B531F6131C962E0016BF14 /* iNXT.h in Headers */ = {isa = PBXBuildFile; fileRef = 43B531EE131C962E0016BF14 /* iNXT.h */; };
+ 43B531F7131C962E0016BF14 /* iNXTIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = 43B531EF131C962E0016BF14 /* iNXTIterator.h */; };
+ 43B531F8131C962E0016BF14 /* platform.h in Headers */ = {isa = PBXBuildFile; fileRef = 43B531F0131C962E0016BF14 /* platform.h */; };
+ 43B531F9131C962E0016BF14 /* tStatus.h in Headers */ = {isa = PBXBuildFile; fileRef = 43B531F1131C962E0016BF14 /* tStatus.h */; };
+ 43B531FB131C963A0016BF14 /* visatype.h in Headers */ = {isa = PBXBuildFile; fileRef = 43B531FA131C963A0016BF14 /* visatype.h */; };
+ 43B5320A131C975B0016BF14 /* Fantom in Frameworks */ = {isa = PBXBuildFile; fileRef = 43B53209131C975B0016BF14 /* Fantom */; };
+ 50149BDA09E781A5002DEE6A /* FantomModule.h in Headers */ = {isa = PBXBuildFile; fileRef = 50149BD909E781A5002DEE6A /* FantomModule.h */; };
+ 5073E0CB09E734E500EC74B6 /* FantomModule.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5073E0C409E734A800EC74B6 /* FantomModule.cpp */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXFileReference section */
+ 32BAE0B70371A74B00C91783 /* FantomModule_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FantomModule_Prefix.pch; sourceTree = "<group>"; };
+ 43B531D1131C92690016BF14 /* Python */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = Python; path = /System/Library/Frameworks/Python.framework/Python; sourceTree = "<absolute>"; };
+ 43B531EA131C962E0016BF14 /* iFile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = iFile.h; sourceTree = "<group>"; };
+ 43B531EB131C962E0016BF14 /* iFileIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = iFileIterator.h; sourceTree = "<group>"; };
+ 43B531EC131C962E0016BF14 /* iModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = iModule.h; sourceTree = "<group>"; };
+ 43B531ED131C962E0016BF14 /* iModuleIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = iModuleIterator.h; sourceTree = "<group>"; };
+ 43B531EE131C962E0016BF14 /* iNXT.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = iNXT.h; sourceTree = "<group>"; };
+ 43B531EF131C962E0016BF14 /* iNXTIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = iNXTIterator.h; sourceTree = "<group>"; };
+ 43B531F0131C962E0016BF14 /* platform.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = platform.h; sourceTree = "<group>"; };
+ 43B531F1131C962E0016BF14 /* tStatus.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tStatus.h; sourceTree = "<group>"; };
+ 43B531FA131C963A0016BF14 /* visatype.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = visatype.h; sourceTree = "<group>"; };
+ 43B53209131C975B0016BF14 /* Fantom */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = Fantom; path = /Library/Frameworks/Fantom.framework/Fantom; sourceTree = "<absolute>"; };
+ 43DB2163131CBF18001443AF /* setup.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = setup.py; sourceTree = "<group>"; };
+ 50149BD909E781A5002DEE6A /* FantomModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FantomModule.h; sourceTree = "<group>"; };
+ 5073E0C409E734A800EC74B6 /* FantomModule.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = FantomModule.cpp; sourceTree = "<group>"; };
+ 5073E0C609E734A800EC74B6 /* FantomModuleProj.xcconfig */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.xcconfig; path = FantomModuleProj.xcconfig; sourceTree = "<group>"; };
+ 5073E0C709E734A800EC74B6 /* FantomModuleTarget.xcconfig */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.xcconfig; path = FantomModuleTarget.xcconfig; sourceTree = "<group>"; };
+ 50B2938909F016FC00694E55 /* FantomModulePriv.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FantomModulePriv.h; sourceTree = "<group>"; };
+ D2AAC09D05546B4700DB518D /* libFantomModule.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = libFantomModule.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+ D2AAC09B05546B4700DB518D /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 43B531D2131C92690016BF14 /* Python in Frameworks */,
+ 43B5320A131C975B0016BF14 /* Fantom in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+ 034768DDFF38A45A11DB9C8B /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ D2AAC09D05546B4700DB518D /* libFantomModule.dylib */,
+ );
+ name = Products;
+ sourceTree = "<group>";
+ };
+ 0867D691FE84028FC02AAC07 /* FantomModule */ = {
+ isa = PBXGroup;
+ children = (
+ 43B531FA131C963A0016BF14 /* visatype.h */,
+ 43B531E9131C962E0016BF14 /* fantom */,
+ 5073E0CA09E734BC00EC74B6 /* Configuration Files */,
+ 08FB77ACFE841707C02AAC07 /* Source */,
+ 0867D69AFE84028FC02AAC07 /* External Frameworks and Libraries */,
+ 034768DDFF38A45A11DB9C8B /* Products */,
+ 43DB2163131CBF18001443AF /* setup.py */,
+ );
+ name = FantomModule;
+ sourceTree = "<group>";
+ };
+ 0867D69AFE84028FC02AAC07 /* External Frameworks and Libraries */ = {
+ isa = PBXGroup;
+ children = (
+ 43B53209131C975B0016BF14 /* Fantom */,
+ 43B531D1131C92690016BF14 /* Python */,
+ );
+ name = "External Frameworks and Libraries";
+ sourceTree = "<group>";
+ };
+ 08FB77ACFE841707C02AAC07 /* Source */ = {
+ isa = PBXGroup;
+ children = (
+ 32BAE0B70371A74B00C91783 /* FantomModule_Prefix.pch */,
+ 50149BD909E781A5002DEE6A /* FantomModule.h */,
+ 50B2938909F016FC00694E55 /* FantomModulePriv.h */,
+ 5073E0C409E734A800EC74B6 /* FantomModule.cpp */,
+ );
+ name = Source;
+ sourceTree = "<group>";
+ };
+ 43B531E9131C962E0016BF14 /* fantom */ = {
+ isa = PBXGroup;
+ children = (
+ 43B531EA131C962E0016BF14 /* iFile.h */,
+ 43B531EB131C962E0016BF14 /* iFileIterator.h */,
+ 43B531EC131C962E0016BF14 /* iModule.h */,
+ 43B531ED131C962E0016BF14 /* iModuleIterator.h */,
+ 43B531EE131C962E0016BF14 /* iNXT.h */,
+ 43B531EF131C962E0016BF14 /* iNXTIterator.h */,
+ 43B531F0131C962E0016BF14 /* platform.h */,
+ 43B531F1131C962E0016BF14 /* tStatus.h */,
+ );
+ path = fantom;
+ sourceTree = "<group>";
+ };
+ 5073E0CA09E734BC00EC74B6 /* Configuration Files */ = {
+ isa = PBXGroup;
+ children = (
+ 5073E0C609E734A800EC74B6 /* FantomModuleProj.xcconfig */,
+ 5073E0C709E734A800EC74B6 /* FantomModuleTarget.xcconfig */,
+ );
+ name = "Configuration Files";
+ sourceTree = "<group>";
+ };
+/* End PBXGroup section */
+
+/* Begin PBXHeadersBuildPhase section */
+ D2AAC09905546B4700DB518D /* Headers */ = {
+ isa = PBXHeadersBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 50149BDA09E781A5002DEE6A /* FantomModule.h in Headers */,
+ 43B531F2131C962E0016BF14 /* iFile.h in Headers */,
+ 43B531F3131C962E0016BF14 /* iFileIterator.h in Headers */,
+ 43B531F4131C962E0016BF14 /* iModule.h in Headers */,
+ 43B531F5131C962E0016BF14 /* iModuleIterator.h in Headers */,
+ 43B531F6131C962E0016BF14 /* iNXT.h in Headers */,
+ 43B531F7131C962E0016BF14 /* iNXTIterator.h in Headers */,
+ 43B531F8131C962E0016BF14 /* platform.h in Headers */,
+ 43B531F9131C962E0016BF14 /* tStatus.h in Headers */,
+ 43B531FB131C963A0016BF14 /* visatype.h in Headers */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXHeadersBuildPhase section */
+
+/* Begin PBXNativeTarget section */
+ D2AAC09C05546B4700DB518D /* FantomModule */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 1DEB916008733D950010E9CD /* Build configuration list for PBXNativeTarget "FantomModule" */;
+ buildPhases = (
+ D2AAC09905546B4700DB518D /* Headers */,
+ D2AAC09B05546B4700DB518D /* Frameworks */,
+ D2AAC09A05546B4700DB518D /* Sources */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = FantomModule;
+ productName = libFantomModule;
+ productReference = D2AAC09D05546B4700DB518D /* libFantomModule.dylib */;
+ productType = "com.apple.product-type.library.dynamic";
+ };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+ 0867D690FE84028FC02AAC07 /* Project object */ = {
+ isa = PBXProject;
+ buildConfigurationList = 1DEB916408733D950010E9CD /* Build configuration list for PBXProject "FantomModule" */;
+ compatibilityVersion = "Xcode 3.1";
+ developmentRegion = English;
+ hasScannedForEncodings = 1;
+ knownRegions = (
+ English,
+ Japanese,
+ French,
+ German,
+ );
+ mainGroup = 0867D691FE84028FC02AAC07 /* FantomModule */;
+ productRefGroup = 034768DDFF38A45A11DB9C8B /* Products */;
+ projectDirPath = "";
+ projectRoot = "";
+ targets = (
+ D2AAC09C05546B4700DB518D /* FantomModule */,
+ );
+ };
+/* End PBXProject section */
+
+/* Begin PBXSourcesBuildPhase section */
+ D2AAC09A05546B4700DB518D /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 5073E0CB09E734E500EC74B6 /* FantomModule.cpp in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin XCBuildConfiguration section */
+ 1DEB916108733D950010E9CD /* Debug */ = {
+ isa = XCBuildConfiguration;
+ baseConfigurationReference = 5073E0C709E734A800EC74B6 /* FantomModuleTarget.xcconfig */;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ COPY_PHASE_STRIP = NO;
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_ENABLE_FIX_AND_CONTINUE = YES;
+ GCC_MODEL_TUNING = G5;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = FantomModule_Prefix.pch;
+ LIBRARY_SEARCH_PATHS = (
+ "$(inherited)",
+ "\"$(SYSTEM_LIBRARY_DIR)/Frameworks/Python.framework\"",
+ "\"$(LOCAL_LIBRARY_DIR)/Frameworks/Fantom.framework\"",
+ );
+ };
+ name = Debug;
+ };
+ 1DEB916208733D950010E9CD /* Release */ = {
+ isa = XCBuildConfiguration;
+ baseConfigurationReference = 5073E0C709E734A800EC74B6 /* FantomModuleTarget.xcconfig */;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+ GCC_MODEL_TUNING = G5;
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = FantomModule_Prefix.pch;
+ LIBRARY_SEARCH_PATHS = (
+ "$(inherited)",
+ "\"$(SYSTEM_LIBRARY_DIR)/Frameworks/Python.framework\"",
+ "\"$(LOCAL_LIBRARY_DIR)/Frameworks/Fantom.framework\"",
+ );
+ STRIP_INSTALLED_PRODUCT = YES;
+ STRIP_STYLE = "non-global";
+ };
+ name = Release;
+ };
+ 1DEB916508733D950010E9CD /* Debug */ = {
+ isa = XCBuildConfiguration;
+ baseConfigurationReference = 5073E0C609E734A800EC74B6 /* FantomModuleProj.xcconfig */;
+ buildSettings = {
+ ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ HEADER_SEARCH_PATHS = /usr/include/python2.6/;
+ ONLY_ACTIVE_ARCH = YES;
+ PREBINDING = NO;
+ SDKROOT = macosx10.6;
+ };
+ name = Debug;
+ };
+ 1DEB916608733D950010E9CD /* Release */ = {
+ isa = XCBuildConfiguration;
+ baseConfigurationReference = 5073E0C609E734A800EC74B6 /* FantomModuleProj.xcconfig */;
+ buildSettings = {
+ ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ PREBINDING = NO;
+ SDKROOT = macosx10.6;
+ };
+ name = Release;
+ };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+ 1DEB916008733D950010E9CD /* Build configuration list for PBXNativeTarget "FantomModule" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 1DEB916108733D950010E9CD /* Debug */,
+ 1DEB916208733D950010E9CD /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ 1DEB916408733D950010E9CD /* Build configuration list for PBXProject "FantomModule" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 1DEB916508733D950010E9CD /* Debug */,
+ 1DEB916608733D950010E9CD /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+/* End XCConfigurationList section */
+ };
+ rootObject = 0867D690FE84028FC02AAC07 /* Project object */;
+}
diff --git a/AT91SAM7S256/armdebug/FantomModule/FantomModulePriv.h b/AT91SAM7S256/armdebug/FantomModule/FantomModulePriv.h
new file mode 100644
index 0000000..54e0775
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/FantomModulePriv.h
@@ -0,0 +1,19 @@
+/*
+ * FantomModulePriv.h
+ * FantomModule
+ *
+ * Created by tcmac on 01/03/2011.
+ * Copyright 2011 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+/* The classes below are not exported */
+#pragma GCC visibility push(hidden)
+
+class FantomModulePriv
+{
+ public:
+ void HelloWorldPriv(const char *);
+};
+
+#pragma GCC visibility pop
diff --git a/AT91SAM7S256/armdebug/FantomModule/FantomModuleProj.xcconfig b/AT91SAM7S256/armdebug/FantomModule/FantomModuleProj.xcconfig
new file mode 100644
index 0000000..363b2d1
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/FantomModuleProj.xcconfig
@@ -0,0 +1,6 @@
+ PREBINDING = NO;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ GCC_MODEL_TUNING = G5;
+ GCC_INCREASE_PRECOMPILED_HEADER_SHARING = YES;
+ GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
diff --git a/AT91SAM7S256/armdebug/FantomModule/FantomModuleTarget.xcconfig b/AT91SAM7S256/armdebug/FantomModule/FantomModuleTarget.xcconfig
new file mode 100644
index 0000000..63f1a7e
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/FantomModuleTarget.xcconfig
@@ -0,0 +1,11 @@
+ PRODUCT_NAME = libFantomModule;
+ INSTALL_PATH = /usr/local/lib;
+ MACH_O_TYPE = mh_dylib;
+ DYLIB_COMPATIBILITY_VERSION = 1;
+ DYLIB_CURRENT_VERSION = 1;
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = FantomModule_Prefix.pch;
+ GCC_ENABLE_CPP_EXCEPTIONS = YES;
+ GCC_ENABLE_CPP_RTTI = YES;
+ STANDARD_C_PLUS_PLUS_LIBRARY_TYPE = Dynamic;
+ GCC_SYMBOLS_PRIVATE_EXTERN = YES;
diff --git a/AT91SAM7S256/armdebug/FantomModule/FantomModule_Prefix.pch b/AT91SAM7S256/armdebug/FantomModule/FantomModule_Prefix.pch
new file mode 100644
index 0000000..031204e
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/FantomModule_Prefix.pch
@@ -0,0 +1,6 @@
+//
+// Prefix header for all source files of the 'FantomModule' target in the 'FantomModule' project.
+//
+
+
+#include <iostream>
diff --git a/AT91SAM7S256/armdebug/FantomModule/fantom/iFile.h b/AT91SAM7S256/armdebug/FantomModule/fantom/iFile.h
new file mode 100644
index 0000000..d9884f9
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/fantom/iFile.h
@@ -0,0 +1,280 @@
+/*!
+ \file iFile.h
+ \brief Interface for a file on a LEGO MINDSTORMS NXT.
+*/
+/*
+ © Copyright 2005-2006,
+ National Instruments Corporation.
+ All rights reserved.
+
+ File: iFile.h
+ Originated: 12 May 2005
+*/
+
+#ifndef ___fantom_iFile_h___
+#define ___fantom_iFile_h___
+
+// includes...
+
+#ifndef ___fantom_platform_h___
+ #include "platform.h"
+#endif
+
+#ifndef ___fantom_tStatus_h___
+ #include "tStatus.h"
+#endif
+
+
+// defines...
+
+
+namespace nFANTOM100
+{
+ // forward declarations...
+
+ // typedefs...
+
+ // classes...
+
+ /*!
+ \class iFile
+ \brief Interface to a file on a LEGO MINDSTORMS NXT.
+ */
+ class iFile
+ {
+ friend class tNXT;
+
+ // methods
+ protected:
+
+ //! Destructor
+ virtual ~iFile() = 0;
+
+ public:
+
+ //! Retrieves the name of this file.
+ /*!
+ \param fileName Populated with the name of this file. The file name character array
+ must be able to accomodate a NULL-terminated, 15.3 formatted module name. That
+ is, it must have a capacity of 20 bytes.
+ */
+ virtual void getName( ViChar fileName[] ) const = 0;
+
+ //! Retrieves the total size of this file in bytes.
+ /*!
+ The returned size is undefined if the specified status is fatal.
+
+ \param status Status chaining object.
+ \return The total size of this file in bytes.
+ */
+ virtual ViUInt32 getSize( tStatus& status ) = 0;
+
+ //! Retrieves the remaining available size, in bytes, in this file.
+ /*!
+ This number is only helpful for data logging files, which can contain variable
+ amounts of data.
+ The returned size is undefined if the specified status is fatal.
+
+ \param status Status chaining object.
+ \return The remaining available size, in bytes, in this file.
+ */
+ virtual ViUInt32 getAvailableSize( tStatus& status ) = 0;
+
+
+ //! Opens this file for reading.
+ /*!
+ Opens, for reading, the file that corresponds to this object on the associated NXT.
+ The file is not opened if the specified status is fatal.
+
+ \param status Status chaining object.
+ */
+ virtual void openForRead( tStatus& status ) = 0;
+
+
+ //! Open this file for writing.
+ /*!
+ Opens, for writing, the file that corresponds to this object on the associated NXT.
+ If this file doesn't exist on the NXT, it is created. If this file does exist on
+ the NXT, an error is generated.
+ The file is not opened if the specified status is fatal.
+
+ \param sizeInBytes Size of the data, in bytes, that will be written to this file.
+ \param status Status chaining object.
+ */
+ virtual void openForWrite( ViUInt32 sizeInBytes, tStatus& status ) = 0;
+
+
+ //! Open this file for linear (contiguous) writing.
+ /*!
+ Opens, for linear (contiguous) writing, the file that corresponds to this object on
+ the associated NXT. If this file doesn't exist on the NXT, it is created. If this
+ file does exist on the NXT, an error is generated.
+ The file is not opened if the specified status is fatal.
+
+ \param sizeInBytes Size of the data, in bytes, that will be written to the file.
+ \param status Status chaining object.
+ */
+ virtual void openForLinearWrite( ViUInt32 sizeInBytes, tStatus& status ) = 0;
+
+
+ //! Open this data file for writing.
+ /*!
+ Opens, for writing, the data file that corresponds to this object on the associated
+ NXT. This data file differs from normal files in that a data file can be closed
+ before the entire file has been written. If this file doesn't exist on the NXT,
+ it is created. If this file does exist on the NXT, an error is generated.
+ The file is not opened if the specified status is fatal.
+
+ \param sizeInBytes Size of the data, in bytes, that may be written to the file.
+ \param status Status chaining object.
+ */
+ virtual void openForDataWrite( ViUInt32 sizeInBytes, tStatus& status ) = 0;
+
+
+ //! Open this data file for appending additional data.
+ /*!
+ Opens, for appending additional data, the data file that corresponds to this object
+ on the associated NXT. If this file doesn't exist on the NXT, the behavior is
+ undefined. If this file does exist on the NXT, the data that is written is
+ appended to the end of the exiting data.
+ The file is not opened if the specified status is fatal.
+
+ \param status Status chaining object.
+ */
+ virtual void openForDataAppend( tStatus& status ) = 0;
+
+
+ //! Closes this file.
+ /*!
+ Closes the file that corresponds to this object on the associated NXT.
+ The file is not closed if the specified status is fatal.
+
+ \param status Status chaining object.
+ */
+ virtual void close( tStatus& status ) = 0;
+
+
+ //! Reads from this file
+ /*!
+ Reads the specified number of bytes from this file into the specified buffer. No data
+ is read if the specified status is fatal. The ownership of the buffer is not
+ transferred to this file object.
+
+ \param bufferPtr A pointer to the buffer that will be populated with the data that is
+ read. The capacity of the specified buffer must be at least the specified number
+ of bytes.
+ \param numberOfBytes Number of bytes to read.
+ \param status Status chaining object.
+ \return The number of bytes actually read from this file.
+
+ \pre This file must have been opened for reading with the iFile::openForRead method.
+ \post The specified buffer may be deallocated.
+ */
+ virtual ViUInt32 read( ViPBuf bufferPtr, ViUInt32 numberOfBytes, tStatus& status ) = 0;
+
+
+ //! Writes to this file
+ /*!
+ Writes the specified number of bytes from the specified buffer to this file. No data
+ is written if the specified status is fatal. The ownership of the buffer is not
+ transferred to this file object.
+
+ \param bufferPtr A pointer to the buffer that contains the data that will be written.
+ The capacity of the specified buffer must be at least the specified number of
+ bytes.
+ \param numberOfBytes Number of bytes to write to this file.
+ \param status Status chaining object.
+ \return The number of bytes actually written to this file.
+
+ \pre This file must have previously been opened for writing.
+ \post The specified buffer may be deallocated.
+ */
+ virtual ViUInt32 write( const ViByte bufferPtr[], ViUInt32 numberOfBytes,
+ tStatus& status ) = 0;
+
+
+ //! Removes this file
+ /*!
+ Removes the file that corresponds to this object on the associated NXT.
+ The file is not removed if the specified status is fatal.
+
+ \param status Status chaining object.
+ */
+ virtual void remove( tStatus& status ) = 0;
+
+ };
+
+
+ // constants...
+ const ViUInt8 kProtocolFilenameLength = 19; // 15 basename + 1 dot + 3 extension = 19
+
+} // namespace nFANTOM100
+
+
+ // declarations for globally-scoped globals...
+
+ // typedefs...
+ typedef ViObject nFANTOM100_iFile;
+
+ // prototypes...
+ extern "C"
+ {
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_iFile_getName(
+ nFANTOM100_iFile filePtr,
+ ViChar fileName[],
+ ViStatus* status );
+
+ nFANTOM100_kExport ViUInt32 _VI_FUNCC nFANTOM100_iFile_getSize(
+ nFANTOM100_iFile filePtr,
+ ViStatus* status );
+
+ nFANTOM100_kExport ViUInt32 _VI_FUNCC nFANTOM100_iFile_getAvailableSize(
+ nFANTOM100_iFile filePtr,
+ ViStatus* status );
+
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_iFile_openForRead(
+ nFANTOM100_iFile filePtr,
+ ViStatus* status );
+
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_iFile_openForWrite(
+ nFANTOM100_iFile filePtr,
+ ViUInt32 sizeInBytes,
+ ViStatus* status );
+
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_iFile_openForLinearWrite(
+ nFANTOM100_iFile filePtr,
+ ViUInt32 sizeInBytes,
+ ViStatus* status );
+
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_iFile_openForDataWrite(
+ nFANTOM100_iFile filePtr,
+ ViUInt32 sizeInBytes,
+ ViStatus* status );
+
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_iFile_openForDataAppend(
+ nFANTOM100_iFile filePtr,
+ ViStatus* status );
+
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_iFile_close(
+ nFANTOM100_iFile filePtr,
+ ViStatus* status );
+
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_iFile_read(
+ nFANTOM100_iFile filePtr,
+ ViPBuf bufferPtr,
+ ViUInt32 numberOfBytes,
+ ViStatus* status );
+
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_iFile_write(
+ nFANTOM100_iFile filePtr,
+ const ViByte bufferPtr[],
+ ViUInt32 numberOfBytes,
+ ViStatus* status );
+
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_iFile_remove(
+ nFANTOM100_iFile filePtr,
+ ViStatus* status );
+
+ }
+
+#endif // ___fantom_iFile_h___
diff --git a/AT91SAM7S256/armdebug/FantomModule/fantom/iFileIterator.h b/AT91SAM7S256/armdebug/FantomModule/fantom/iFileIterator.h
new file mode 100644
index 0000000..5803be8
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/fantom/iFileIterator.h
@@ -0,0 +1,133 @@
+/*!
+ \file iFileIterator.h
+ \brief Interface for an iterator for files on a LEGO MINDSTORMS NXT.
+*/
+/*
+ © Copyright 2005-2006,
+ National Instruments Corporation.
+ All rights reserved.
+
+ File: iFileIterator.h
+ Originated: 12 May 2005
+*/
+
+#ifndef ___fantom_iFileIterator_h___
+#define ___fantom_iFileIterator_h___
+
+
+// includes...
+
+#ifndef ___fantom_platform_h___
+ #include "platform.h"
+#endif
+
+#ifndef ___fantom_iFile_h___
+ #include "iFile.h"
+#endif
+
+#ifndef ___fantom_tStatus_h___
+ #include "tStatus.h"
+#endif
+
+
+// defines...
+
+
+namespace nFANTOM100
+{
+ // forward declarations...
+
+ // typedefs...
+
+ // classes...
+
+ /*!
+ \class iFileIterator
+ \brief Interface to an iterator for files on a LEGO MINDSTORMS NXT.
+ */
+ class iFileIterator
+ {
+ friend class tNXT;
+
+ // methods
+ protected:
+
+ //! Destructor
+ virtual ~iFileIterator() = 0;
+
+ public:
+
+ //! Creates a file object for the file referenced by this iterator.
+ /*!
+ Creates file object for the file referenced by this iterator. An object is not
+ created if the specified status is fatal or if this iterator refers to the end of
+ the list. The returned file object should be destroyed using the
+ iNXT::destroyFile method.
+
+ \param status Status chaining object.
+ \return A pointer to the iFile object that was created.
+ */
+ virtual iFile* getFile( tStatus& status ) = 0;
+
+ //! Advances this iterator.
+ /*!
+ Advances this iterator to the next file that matches the previously specified file
+ name pattern. If no more files match, this iterator is advanced to the end of the
+ list.
+ The iterator is not advanced if the specified status is fatal.
+ If this iterator is already at the end of the list, a fatal status will be generated.
+
+ \param status Status chaining object.
+ */
+ virtual void advance( tStatus& status ) = 0;
+
+ //! Retrieves the name of the file to which this iterator refers.
+ /*!
+ \param fileName Populated with the name of the file to which this iterator refers.
+ The file name character array must be able to accomodate a NULL-terminated, 15.3
+ formatted file name. This is, it must have a capacity of 20 bytes.
+ \param status Status chaining object.
+ */
+ virtual void getName( ViChar fileName[], tStatus& status ) = 0;
+
+ //! Retrieves the total size, in bytes, of the file to which this iterator refers.
+ /*!
+ \param status Status chaining object.
+ \return The total size of the file in bytes.
+ */
+ virtual ViUInt32 getSize( tStatus& status ) = 0;
+
+ };
+
+
+ // constants...
+
+} // namespace nFANTOM100
+
+
+ // declarations for globally-scoped globals...
+
+ // typedefs
+ typedef ViObject nFANTOM100_iFileIterator;
+
+ extern "C"
+ {
+ nFANTOM100_kExport nFANTOM100_iFile _VI_FUNCC nFANTOM100_iFileIterator_getFile(
+ nFANTOM100_iFileIterator iteratorPtr,
+ ViStatus* status );
+
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_iFileIterator_advance(
+ nFANTOM100_iFileIterator iteratorPtr,
+ ViStatus* status );
+
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_iFileIterator_getName(
+ nFANTOM100_iFileIterator iteratorPtr,
+ ViChar filename[],
+ ViStatus* status );
+
+ nFANTOM100_kExport ViUInt32 _VI_FUNCC nFANTOM100_iFileIterator_getSize(
+ nFANTOM100_iFileIterator iteratorPtr,
+ ViStatus* status );
+ }
+
+#endif // ___fantom_iFileIterator_h___
diff --git a/AT91SAM7S256/armdebug/FantomModule/fantom/iModule.h b/AT91SAM7S256/armdebug/FantomModule/fantom/iModule.h
new file mode 100644
index 0000000..1f03849
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/fantom/iModule.h
@@ -0,0 +1,154 @@
+/*!
+ \file iModule.h
+ \brief Interface for a firmware module on a LEGO MINDSTORMS NXT.
+*/
+/*
+ © Copyright 2005-2006,
+ National Instruments Corporation.
+ All rights reserved.
+
+ File: iModule.h
+ Originated: 8 Aug 2005
+*/
+
+#ifndef ___fantom_iModule_h___
+#define ___fantom_iModule_h___
+
+#ifndef ___fantom_platform_h___
+ #include "platform.h"
+#endif
+
+#ifndef ___fantom_tStatus_h___
+ #include "tStatus.h"
+#endif
+
+
+// defines...
+
+
+namespace nFANTOM100
+{
+
+ /*!
+ \class iModule
+ \brief Interface to a firmware module on a LEGO MINDSTORMS NXT.
+ */
+ class iModule
+ {
+ friend class tNXT;
+
+ // methods
+ protected:
+
+ //! Destructor
+ virtual ~iModule() = 0;
+
+ public:
+
+ //! Retrieves the name of this module.
+ /*!
+ \param moduleName Populated with the name of this module. The module name character
+ array must be able to accomodate a NULL-terminated, 15.3 formatted module name.
+ That is, it must have a capacity of 20 bytes.
+ */
+ virtual void getName( ViChar moduleName[] ) const = 0;
+
+ //! Retrieves the internal module ID of this module.
+ /*!
+ \return The internal module ID of this module.
+ */
+ virtual ViUInt32 getModuleID( void ) const = 0;
+
+ //! Retrieves the size in bytes of this module.
+ /*!
+ \return The size in bytes of this module.
+ */
+ virtual ViUInt32 getModuleSize( void ) const = 0;
+
+ //! Retrieves the size in bytes of the I/O map associated with this module.
+ /*!
+ \return The size in bytes of the I/O map associated with this module.
+ */
+ virtual ViUInt32 getModuleIOMapSize( void ) const = 0;
+
+ //! Reads a portion of this module's I/O map.
+ /*!
+ Reads the data located at [I/O map address] + [specified offset in bytes] into the
+ specified data buffer. The read will attempt to copy the specified number of
+ bytes. No read occurs if the specified status is fatal. The ownership of data
+ buffer is not transferred to this module object.
+
+ \param offsetInBytes The index of the byte in the I/O map at which to start the read.
+ \param numberOfBytes The number of bytes that should be read from the I/O map.
+ \param dataBufferPtr A pointer to the data buffer that will be populated with the
+ data that is read. The capacity of the specified data buffer must be at least the
+ specified number of bytes.
+ \param status Status chaining object.
+ \return The number of bytes actually read from the I/O map.
+
+ \post The specified data buffer may be deallocated.
+ */
+ virtual ViUInt32 readIOMap( ViUInt32 offsetInBytes, ViUInt32 numberOfBytes,
+ ViPBuf dataBufferPtr, tStatus& status ) = 0;
+
+ //! Writes a portion of this module's I/O map.
+ /*!
+ Writes the specified data into this module's I/O map. The write starts at [I/O map
+ address] + [specified offset in bytes] and stops after the specified number of
+ bytes have been written. No write occurs if the specified status is fatal. The
+ ownership of data buffer is not transferred to this module object.
+
+ \param offsetInBytes The index of the byte in the I/O map at which to start the write.
+ \param numberOfBytes The number of bytes to write into the I/O map.
+ \param dataBufferPtr A pointer to the data buffer that contains the data that will be
+ written. The capacity of the specified data buffer must be at least the specified
+ number of bytes.
+ \param status Status chaining object.
+ \return The number of bytes actually written into the I/O map.
+
+ \post The specified data buffer may be deallocated.
+ */
+ virtual ViUInt32 writeIOMap( ViUInt32 offsetInBytes, ViUInt32 numberOfBytes,
+ const ViByte dataBufferPtr[], tStatus& status ) = 0;
+
+ };
+
+}; // nFANTOM100
+
+typedef ViObject nFANTOM100_iModule;
+
+extern "C"
+{
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_iModule_getName(
+ nFANTOM100_iModule modulePtr,
+ ViChar moduleName[],
+ ViStatus* status );
+
+ nFANTOM100_kExport ViUInt32 _VI_FUNCC nFANTOM100_iModule_getModuleID(
+ nFANTOM100_iModule modulePtr,
+ ViStatus* status );
+
+ nFANTOM100_kExport ViUInt32 _VI_FUNCC nFANTOM100_iModule_getModuleSize(
+ nFANTOM100_iModule modulePtr,
+ ViStatus* status );
+
+ nFANTOM100_kExport ViUInt32 _VI_FUNCC nFANTOM100_iModule_getIOMapSize(
+ nFANTOM100_iModule modulePtr,
+ ViStatus* status );
+
+ nFANTOM100_kExport ViUInt32 _VI_FUNCC nFANTOM100_iModule_readIOMap(
+ nFANTOM100_iModule modulePtr,
+ ViUInt32 offset,
+ ViUInt32 numberBytesToRead,
+ ViPBuf dataBuffer,
+ ViStatus* status );
+
+ nFANTOM100_kExport ViUInt32 _VI_FUNCC nFANTOM100_iModule_writeIOMap(
+ nFANTOM100_iModule modulePtr,
+ ViUInt32 offset,
+ ViUInt32 numberBytesToWrite,
+ const ViByte dataBuffer[],
+ ViStatus* status );
+}
+
+#endif // ___fantom_iModule_h___
diff --git a/AT91SAM7S256/armdebug/FantomModule/fantom/iModuleIterator.h b/AT91SAM7S256/armdebug/FantomModule/fantom/iModuleIterator.h
new file mode 100644
index 0000000..402bf1a
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/fantom/iModuleIterator.h
@@ -0,0 +1,123 @@
+/*!
+ \file iModuleIterator.h
+ \brief Interface for an iterator for firmware modules on a LEGO MINDSTORMS NXT.
+*/
+/*
+ © Copyright 2005-2006,
+ National Instruments Corporation.
+ All rights reserved.
+
+ File: iModuleIterator.h
+ Originated: 8 Aug 2005
+*/
+
+#ifndef ___fantom_iModuleIterator_h___
+#define ___fantom_iModuleIterator_h___
+
+
+// includes...
+
+#ifndef ___fantom_platform_h___
+ #include "platform.h"
+#endif
+
+#ifndef ___fantom_iModule_h___
+ #include "iModule.h"
+#endif
+
+#ifndef ___fantom_tStatus_h___
+ #include "tStatus.h"
+#endif
+
+
+// defines...
+
+
+namespace nFANTOM100
+{
+ // forward declarations...
+
+ // typedefs...
+
+ // classes...
+
+ /*!
+ \class iModuleIterator
+ \brief Interface to an iterator for firmware modules on a LEGO MINDSTORMS NXT.
+ */
+ class iModuleIterator
+ {
+ friend class tNXT;
+
+ // methods
+ protected:
+
+ //! Destructor
+ virtual ~iModuleIterator() = 0;
+
+ public:
+
+ //! Creates a module object for the module referenced by this iterator.
+ /*!
+ Creates a module object for the module referenced by this iterator. An object is not
+ created if the specified status is fatal or if this iterator refers to the end of
+ the list. The returned module object should be destroyed using the
+ iNXT::destroyModule method.
+
+ \param status Status chaining object.
+ \return A pointer to the iModule object that was created.
+ */
+ virtual iModule* getModule( tStatus& status ) = 0;
+
+ //! Advances this iterator.
+ /*!
+ Advances this iterator to the next module that matches the previously specified
+ module name pattern. If no more modules match, this iterator is advanced to the
+ end of the list.
+ The iterator is not advanced if the specified status is fatal.
+ If this iterator is already at the end of the list, a fatal status will be generated.
+
+ \param status Status chaining object.
+ */
+ virtual void advance( tStatus& status ) = 0;
+
+ //! Retrieves the name of the module to which this iterator refers.
+ /*!
+ \param moduleName Populated with the name of the module to which this iterator
+ refers. The module name character array must be able to accomodate a
+ NULL-terminated, 15.3 formatted module name. This is, it must have a capacity of
+ 20 bytes.
+ \param status Status chaining object.
+ */
+ virtual void getName( ViChar moduleName[], tStatus& status ) = 0;
+
+ };
+
+
+ // constants...
+
+} // namespace nFANTOM100
+
+
+ // declarations for globally-scoped globals...
+
+ // typedefs
+ typedef ViObject nFANTOM100_iModuleIterator;
+
+ extern "C"
+ {
+ nFANTOM100_kExport nFANTOM100_iModule _VI_FUNCC nFANTOM100_iModuleIterator_getModule(
+ nFANTOM100_iModuleIterator iteratorPtr,
+ ViStatus* status );
+
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_iModuleIterator_advance(
+ nFANTOM100_iModuleIterator iteratorPtr,
+ ViStatus* status );
+
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_iModuleIterator_getName(
+ nFANTOM100_iModuleIterator iteratorPtr,
+ ViChar moduleName[],
+ ViStatus* status );
+ }
+
+#endif // ___fantom_iModuleIterator_h___
diff --git a/AT91SAM7S256/armdebug/FantomModule/fantom/iNXT.h b/AT91SAM7S256/armdebug/FantomModule/fantom/iNXT.h
new file mode 100644
index 0000000..ba61db8
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/fantom/iNXT.h
@@ -0,0 +1,666 @@
+/*!
+ \file iNXT.h
+ \brief Interface for a LEGO MINDSTORMS NXT and declaration of its factory.
+*/
+/*
+ © Copyright 2005-2006,
+ National Instruments Corporation.
+ All rights reserved.
+
+ File: iNXT.h
+ Originated: 12 May 2005
+*/
+
+#ifndef ___fantom_iNXT_h___
+#define ___fantom_iNXT_h___
+
+
+// includes...
+
+#ifndef ___fantom_platform_h___
+ #include "platform.h"
+#endif
+
+#ifndef ___fantom_iFile_h___
+ #include "iFile.h"
+#endif
+
+#ifndef ___fantom_iFileIterator_h___
+ #include "iFileIterator.h"
+#endif
+
+#ifndef ___fantom_iModule_h___
+ #include "iModule.h"
+#endif
+
+#ifndef ___fantom_iModuleIterator_h___
+ #include "iModuleIterator.h"
+#endif
+
+#ifndef ___fantom_iNXTIterator_h___
+ #include "iNXTIterator.h"
+#endif
+
+#ifndef ___fantom_tStatus_h___
+ #include "tStatus.h"
+#endif
+
+// defines...
+
+
+namespace nFANTOM100
+{
+ // forward declarations...
+
+ // typedefs...
+
+ // classes...
+
+ /*!
+ \class iNXT
+ \brief Interface to a LEGO MINDSTORMS NXT.
+ */
+ class iNXT
+ {
+ // methods
+ protected:
+
+ //! Destructor
+ virtual ~iNXT() = 0;
+
+ public:
+
+ //! Enumeration of buffer types on the NXT
+ enum tBuffer
+ {
+ // The buffer associated with the standard port.
+ kBufferStandard,
+
+ // The buffer associated with the high-speed port.
+ kBufferHighSpeed
+ };
+
+ //! Creates a file object for the file with the specified name on this NXT.
+ /*!
+ Invoking this method does not actually create a file on the NXT. Rather, this method
+ creates a file object which may be used to open a file on this NXT, for reading or
+ writing, or may be used to delete a file on the NXT.
+ A file is not created if the specified status is fatal.
+ The returned file object should be destroyed using the iNXT::destroyFile method.
+
+ \param fileName Name of the file. The file name must conform to the 15.3 naming
+ convention and be NULL-terminated.
+ \param status Status chaining object.
+ \return A pointer to the iFile object that was created.
+ */
+ virtual iFile* createFile( ViConstString fileName, tStatus& status ) = 0;
+
+
+ //! Destroys the specified file object.
+ /*!
+ Invoking this method does not actually delete a file on the NXT. Rather, this method
+ destroys a file object which may have been used to open a file on this NXT for
+ reading or writing, or may have been used to delete a file on the NXT.
+
+ \param filePtr Pointer to the file object to destroy.
+ */
+ virtual void destroyFile( iFile* filePtr ) = 0;
+
+
+ //! Creates an iterator to the files on this NXT.
+ /*!
+ The iterator traverses those files on this NXT that match the specified file name
+ pattern.
+ The iterator is not created if the specified status is fatal.
+ The returned file iterator object should be destroyed using the
+ iNXT::destroyFileIterator method.
+
+ \param fileNamePattern The file name pattern against which to match when iterating
+ over the files on this NXT. The file name pattern may contain wildcards. The
+ wildcards may be used in the following manner: *.* (all files on this NXT);
+ fileBaseName.* (all files on this NXT with the specified base name regardless of
+ extension); *.fileExtension (all files on this NXT with the specified extension,
+ regardless of basename); fileBaseName.fileExtension (the file on this NXT with the
+ specified base name and extension).
+ \param status Status chaining object.
+ \return A pointer to the iFileIterator object that was created.
+ */
+ virtual iFileIterator* createFileIterator( ViConstString fileNamePattern,
+ tStatus& status ) = 0;
+
+
+ //! Destroys the specified file iterator.
+ /*!
+ \param fileIteratorPtr A pointer to the file iterator to destroy.
+ */
+ virtual void destroyFileIterator( iFileIterator* fileIteratorPtr ) = 0;
+
+ //! Creates a module object for the module with the specified name on this NXT.
+ /*!
+ Invoking this method does not actually create a module on the NXT. Rather, this
+ method creates a module object which may be used to access an I/O map on this NXT.
+ A module is not created if the specified status is fatal.
+ The returned module object should be destroyed using the iNXT::destroyModule method.
+
+ \param moduleName The name of the module. The module name must conform to the 15.3
+ naming convention and be NULL-terminated.
+ \param moduleID The NXT-internal ID of the module.
+ \param moduleSizeInBytes The number of bytes the module occupies.
+ \param ioMapSizeInBytes The number of bytes the module's I/O map occupies.
+ \param status Status chaining object.
+ \return A pointer to the iModule object that was created.
+ */
+ virtual iModule* createModule( ViConstString moduleName, ViUInt32 moduleID,
+ ViUInt32 moduleSizeInBytes, ViUInt32 ioMapSizeInBytes, tStatus& status ) = 0;
+
+ //! Destroys the specified module object.
+ /*!
+ Invoking this method does not actually delete a module on this NXT. Rather, this
+ method destroys a module object which may have been used to access an I/O map on
+ this NXT.
+
+ \param modulePtr Pointer to the module object to destroy.
+ */
+ virtual void destroyModule( iModule* modulePtr ) = 0;
+
+
+ //! Creates an iterator to the modules on this NXT.
+ /*!
+ The iterator traverses those modules on this NXT that match the specified module name
+ pattern.
+ The iterator is not created if the specified status is fatal.
+ The returned module iterator object should be destroyed using the
+ iNXT::destroyModuleIterator method.
+
+ \param moduleNamePattern The module name pattern against which to match. The module
+ name pattern may contain wildcards. Since extensions are implicit in the case of
+ modules, a wildcard may only be used for the module name, as in "*.mod".
+ \param status Status chaining object.
+ \return A pointer to an iModuleIterator object that was created.
+ */
+ virtual iModuleIterator* createModuleIterator( ViConstString moduleNamePattern,
+ tStatus& status ) = 0;
+
+
+ //! Destroys the specified module iterator.
+ /*!
+ \param moduleIteratorPtr A pointer to the module iterator object to destroy.
+ */
+ virtual void destroyModuleIterator( iModuleIterator* moduleIteratorPtr ) = 0;
+
+ //! Retrieves the firmware version of this NXT.
+ /*!
+ Returns the protocol and firmware versions installed on this NXT.
+ The current version of this driver supports a protocol major version number of 1 and a
+ firmware major version number of 1. If either of these major version numbers is a
+ value other than 1, the driver will not attempt to communicate to the NXT.
+ The returned versions are undefined if the specified status is fatal.
+
+ \param protocolVersionMajorRef Reference to parameter that will be populated with the
+ major protocol version.
+ \param protocolVersionMinorRef Reference to parameter that will be populated with the
+ minor protocol version.
+ \param firmwareVersionMajorRef Reference to parameter that will be populated with the
+ major firmware verison.
+ \param firmwareVersionMinorRef Reference to parameter that will be populated with the
+ minor firmware verison.
+ \param status Status chaining object.
+ */
+ virtual void getFirmwareVersion( ViUInt8& protocolVersionMajorRef,
+ ViUInt8& protocolVersionMinorRef, ViUInt8& firmwareVersionMajorRef,
+ ViUInt8& firmwareVersionMinorRef, tStatus& status ) = 0;
+
+
+ //! Sends the specified direct command to this NXT.
+ /*!
+ For more information on direct commands, refer to the LEGO MINDSTORMS NXT Direct
+ commands document.
+ The command is not sent if the specified status is fatal.
+ The command buffer must be non-NULL and the command buffer size in bytes must be
+ non-zero.
+ If require response is set to true, the response buffer must be non-NULL and the
+ response buffer size in bytes must be non-zero.
+ If require response is set to false, the response buffer must be NULL and the
+ response buffer size in bytes must be zero.
+ Both of the buffer size parameters must be small enough to fit in one packet for
+ whichever bus the NXT is connected over (USB or Bluetooth). This means the
+ maximum length for a direct command over USB is 63 bytes; over Bluetooth, 65,533
+ bytes.
+ If any of these requirements are violated, VI_ERROR_USER_BUF will be returned.
+
+ \param requireResponse Boolean flag indicating if a response is required.
+ \param commandBufferPtr Buffer containing the direct command to send to the NXT.
+ \param commandBufferSizeInBytes Number of bytes in the command buffer.
+ \param responseBufferPtr Buffer that will be populated with the response to the direct
+ command.
+ \param responseBufferSizeInBytes Capacity of the response buffer in bytes.
+ \param status Status chaining object.
+ \return Number of bytes written to the response buffer.
+ */
+ virtual ViUInt32 sendDirectCommand( ViBoolean requireResponse, const ViByte commandBufferPtr[],
+ ViUInt32 commandBufferSizeInBytes, ViPBuf responseBufferPtr,
+ ViUInt32 responseBufferSizeInBytes, tStatus& status ) = 0;
+
+ //! Downloads firmware to this NXT.
+ /*!
+ The NXT must already be in firmware-download mode.
+
+ \param firmwareBufferPtr The buffer containing the new firmware binary image.
+ \param firmwareBufferSizeInBytes The number of bytes in the new firmware image.
+ \param status Status chaining object.
+ */
+ virtual void downloadFirmware( const ViByte firmwareBufferPtr[],
+ ViUInt32 firmwareBufferSizeInBytes, tStatus& status ) = 0;
+
+
+ //! Writes, in a generic fashion, to this NXT.
+ /*!
+ Writes a command directly to this NXT. In general, this method isn't used and,
+ instead, the sendDirectCommand and other more specific methods are invoked when
+ communication to the NXT.
+ The write doesn not occur if the specified status is fatal.
+
+ \param bufferPtr A pointer to the buffer that contains the command that will be
+ written.
+ \param numberOfBytes Size of the buffer.
+ \param status Status chaining object.
+ \return The number of bytes actually written to the NXT.
+ */
+ virtual ViUInt32 write( const ViByte bufferPtr[], ViUInt32 numberOfBytes,
+ tStatus& status ) = 0;
+
+ //! Reads, in a generic fashion, from this NXT.
+ /*!
+ Reads a response directly from this NXT. In general, this method isn't used and,
+ instead, the sendDirectCommand and other more specific methods are invoked when
+ communication to the NXT.
+ The command is not sent if the specified status is fatal.
+
+ \param bufferPtr A pointer to the buffer that will be populated with the response.
+ \param numberOfBytes Number of bytes expected to be read from this NXT.
+ \param status Status chaining object.
+ \return The number of bytes actually read from this NXT.
+ */
+ virtual ViUInt32 read ( ViPBuf bufferPtr, ViUInt32 numberOfBytes, tStatus& status ) = 0;
+
+ //! Reboots this NXT into firmware-download mode.
+ /*!
+ This is required before invoking the downloadFirmware method.
+ The reboot does not occur is the specified status is fatal.
+
+ \param status Status chaining object.
+ */
+ virtual void bootIntoFirmwareDownloadMode( tStatus& status ) = 0;
+
+ //! Sets the name of this NXT.
+ /*!
+ The specified name will be displayed on the NXT, show up during Bluetooth scans, and
+ returned when the getDeviceInfo method is called.
+
+ \param newName The name for the NXT. The name can be at most 15 characters. However,
+ the NXT can only display 8 characters. The string must be NULL terminated.
+ \param status Status chaining object.
+ */
+ virtual void setName( ViConstString newName, tStatus& status ) = 0;
+
+ //! Retrieves basic information about this NXT.
+ /*!
+ Retrieves the name of this NXT, its Bluetooth address, the Bluetooth signal strength,
+ and the number of bytes available.
+ Information retrieval is not done if specified status is fatal.
+
+ \param name Populated with the name of this NXT. The name character array must be
+ able to accomodate a NULL-terminated 15 character name. That is, it must have a
+ capacity of 16 bytes.
+ \param bluetoothAddress Populated with this NXT's Bluetooth address. The bluetooth
+ address array must have a capacity of six bytes.
+ \param signalStrength Populated with strength of the signal for this NXT's four
+ Bluetooth conenctions. The signal strength array must have a capacity of four
+ bytes.
+ \param availableFlash Populated with the amount of memory in bytes that is not
+ occupied by firmware or user files.
+ \param status Status chaining object.
+ */
+ virtual void getDeviceInfo( ViChar name[], ViByte bluetoothAddress[],
+ ViUInt8 signalStrength[], ViUInt32 &availableFlash, tStatus& status ) = 0;
+
+ //! Erases all files from this NXT, leaving only the firmware.
+ /*!
+ All programs, sounds, and data logs are erased.
+ The erasure does not occur if specified status is fatal.
+
+ \param status Status chaining object.
+ */
+ virtual void eraseUserFlash( tStatus& status ) = 0;
+
+ //! Polls the data buffer on this NXT for the number of bytes available to be read.
+ /*
+ The data buffer is not polled if the specified status is fatal.
+
+ \param bufferSelector The buffer from which to read.
+ \param status Status chaining object.
+ \return The number of bytes in the buffer available to be read.
+ */
+ virtual ViUInt32 pollAvailableLength( tBuffer bufferSelector, tStatus& status ) = 0;
+
+ //! Reads data from the data buffer on this NXT.
+ /*!
+ Data is not read if the specified status is fatal.
+
+ \param dataBuffer Populated with the data that is read from the specified buffer.
+ \param bufferSelector The buffer from which to read.
+ \param numberOfBytesToRead The number of bytes to read from the data buffer.
+ \param status Status chaining object.
+ \return The number of bytes actually read from the data buffer.
+ */
+ virtual ViUInt32 readBufferData( ViPBuf dataBuffer, tBuffer bufferSelector,
+ ViUInt32 numberOfBytesToRead, tStatus& status ) = 0;
+
+ //! Retrieves the resource string for this NXT's session.
+ /*
+ An example resource string could look like the one of the following:
+ BTH::LEGOBrick::00:16:53:04:05:06::5
+ BTH::LEGOBrick::00:16:53:04:05:06::1
+ BTH::Brick2::00:16:53:44:FF:66
+ USB0::0x0694::0x0002::0016535127BA::RAW
+
+ \param resourceString Populated with the resource string. The resource string must
+ have a capacity of 256 bytes.
+ \param status Status chaining object.
+ */
+ virtual void getResourceString( ViChar resourceString[], tStatus& status ) = 0;
+
+ //! Resets the Bluetooth module on this NXT to its factory settings.
+ /*
+ \param status Status chaining object.
+ */
+ virtual void bluetoothFactoryReset( tStatus& status ) = 0;
+
+ //! Creates an NXT object
+ /*!
+ Creates an NXT object representing the specified NXT.
+ The NXT object is not created if the specified status is fatal.
+ The returned NXT object should be destroyed using the iNXT::destroyNXT method.
+
+ \param resourceString A string identifying which resource should be opened. A list
+ of possible strings can be obtained using an iNXTIterator (refer to the
+ createNXTIterator method).
+ \param status Status chaining object.
+ \param checkFirmwareVersion A boolean flag that specifies whether version validation
+ should occur (defaults to true).
+ \return A pointer to the iNXT object that was created.
+ */
+ nFANTOM100_kExport static iNXT* _VI_FUNCC createNXT( ViConstString resourceString,
+ tStatus& status, ViBoolean checkFirmwareVersion = true );
+
+ //! Destroys an NXT object
+ /*!
+ \param nxtPtr A pointer to the NXT object to destroy; may be NULL
+ */
+ nFANTOM100_kExport static void _VI_FUNCC destroyNXT( iNXT* nxtPtr );
+
+ //! Creates an NXT iterator.
+ /*!
+ The NXT iterator can be used to find all NXTs that are connected (USB) or in range
+ (Bluetooth).
+ The NXT iterator is not created if the specified status is fatal.
+ The returned NXT iterator object should be destroyed using the
+ iNXT::destroyNXTIterator method.
+
+ \param searchBluetooth A boolean flag that specifies if the iterator should traverse
+ NXTs via Bluetooth.
+ \param bluetoothSearchTimeoutInSeconds The minimum number of seconds that should be
+ spent waiting for Bluetooth devices to respond.
+ \param status Status chaining object.
+ \return A pointer to the iNXTIterator object that was created.
+ */
+ nFANTOM100_kExport static iNXTIterator* _VI_FUNCC createNXTIterator(
+ ViBoolean searchBluetooth, ViUInt32 bluetoothSearchTimeoutInSeconds,
+ tStatus& status );
+
+ //! Destroys an NXT iterator object.
+ /*
+ \param iterPtr A pointer to the iNXTIterator object to destroy.
+ */
+ nFANTOM100_kExport static void _VI_FUNCC destroyNXTIterator( iNXTIterator* iterPtr );
+
+ //! Pairs with an NXT via Bluetooth.
+ /*!
+ Programmatically pairs the specified NXT to this computer and, on Windows, creates a
+ virtual serial port to use for communication with that NXT. However, clients
+ should not depend on the creation of this virtual serial port.
+ The pairing is not done if the specified status is fatal.
+
+ \param resourceName The resource string that specifies the NXT with which to pair.
+ \param passkey A string containing the passkey the computer should exchange with the
+ device. The passkey cannot be longer than 15 characters and must be
+ NULL-terminated.
+ \param pairedResourceName A Bluetooth resource string representing the paired device.
+ On Windows, the specified resourceName is suffixed with the COM port; On Mac OS X,
+ the RFCOMM channel identifier. The resource string must have a capacity of 256
+ bytes.
+ \param status Status chaining object.
+ */
+ nFANTOM100_kExport static void _VI_FUNCC pairBluetooth( ViConstString resourceName,
+ ViConstString passkey, ViChar pairedResourceName[], tStatus& status );
+
+ //! Unpairs with an NXT via Bluetooth.
+ /*!
+ Programmatically destroys the Bluetooth pairing that was previously established
+ between this computer and the specified NXT. On Mac OS X, this method has no
+ effect and doesn't generate a fatal status.
+ The unpairing is not done if the specified status is fatal.
+
+ \param resourceName The resource string that specifies the NXT with which to unpair.
+ \param status Status chaining object.
+ */
+ nFANTOM100_kExport static void _VI_FUNCC unpairBluetooth( ViConstString resourceName,
+ tStatus& status );
+
+ //! Determines if the NXT associated with the specified resource string is paired.
+ /*!
+ The determination is not done if the specified status is fatal.
+
+ \param resourceName A resource string that specifies the NXT for which to check its
+ pairing status.
+ \param status Status chaining object.
+ \return VI_TRUE if the NXT is paired with this computer (or if it is connected via
+ USB); VI_FALSE otherwise.
+ */
+ nFANTOM100_kExport static ViBoolean _VI_FUNCC isPaired( ViConstString resourceName,
+ tStatus& status );
+
+ //! Finds the NXT that is currently in firmware-download mode.
+ /*!
+ Note that only a single NXT may be in firmware-download mode at a time.
+
+ \param resourceName Populated with the resource string. The resource string must
+ have a capacity of 256 bytes.
+ \param status Status chaining object.
+ */
+ nFANTOM100_kExport static void findDeviceInFirmwareDownloadMode( ViChar resourceName[],
+ tStatus& status );
+
+
+ private:
+
+ };
+
+ // constants...
+
+} // namespace nFANTOM100
+
+
+ // declarations for globally-scoped globals...
+
+ // typedefs...
+ typedef ViObject nFANTOM100_iNXT;
+
+ // prototypes...
+ extern "C"
+ {
+
+ nFANTOM100_kExport nFANTOM100_iNXTIterator _VI_FUNCC nFANTOM100_createNXTIterator(
+ ViBoolean searchBluetooth,
+ ViUInt32 bluetoothSearchTimeoutInSeconds,
+ ViStatus* status );
+
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_destroyNXTIterator(
+ nFANTOM100_iNXTIterator iterPtr,
+ ViStatus* status );
+
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_pairBluetooth(
+ ViConstString resourceName,
+ ViConstString passkey,
+ ViChar pairedResourceName[],
+ ViStatus* status );
+
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_unpairBluetooth(
+ ViConstString resourceName,
+ ViStatus* status );
+
+ nFANTOM100_kExport ViBoolean _VI_FUNCC nFANTOM100_isPaired(
+ ViConstString resourceName,
+ ViStatus* status );
+
+ nFANTOM100_kExport nFANTOM100_iNXT _VI_FUNCC nFANTOM100_createNXT(
+ ViConstString resourceString,
+ ViStatus* status,
+ ViBoolean checkFirmwareVersion );
+
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_destroyNXT(
+ nFANTOM100_iNXT nxtPtr,
+ ViStatus* status );
+
+ nFANTOM100_kExport nFANTOM100_iFile _VI_FUNCC nFANTOM100_iNXT_createFile(
+ nFANTOM100_iNXT nxtPtr,
+ ViConstString fileName,
+ ViStatus* status );
+
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_iNXT_destroyFile(
+ nFANTOM100_iNXT nxtPtr,
+ nFANTOM100_iFile filePtr,
+ ViStatus* status );
+
+ nFANTOM100_kExport nFANTOM100_iFileIterator _VI_FUNCC nFANTOM100_iNXT_createFileIterator(
+ nFANTOM100_iNXT nxtPtr,
+ ViConstString fileNamePattern,
+ ViStatus* status );
+
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_iNXT_destroyFileIterator(
+ nFANTOM100_iNXT nxtPtr,
+ nFANTOM100_iFileIterator fileIteratorPtr,
+ ViStatus* status );
+
+ nFANTOM100_kExport nFANTOM100_iModule _VI_FUNCC nFANTOM100_iNXT_createModule(
+ nFANTOM100_iNXT nxtPtr,
+ ViConstString moduleName,
+ ViUInt32 moduleID,
+ ViUInt32 moduleSize,
+ ViUInt32 ioMapSizeInBytes,
+ ViStatus* status );
+
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_iNXT_destroyModule(
+ nFANTOM100_iNXT nxtPtr,
+ nFANTOM100_iModule modulePtr,
+ ViStatus* status );
+
+ nFANTOM100_kExport nFANTOM100_iModuleIterator _VI_FUNCC nFANTOM100_iNXT_createModuleIterator(
+ nFANTOM100_iNXT nxtPtr,
+ ViConstString moduleNamePattern,
+ ViStatus* status );
+
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_iNXT_destroyModuleIterator(
+ nFANTOM100_iNXT nxtPtr,
+ nFANTOM100_iModuleIterator moduleIteratorPtr,
+ ViStatus* status );
+
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_iNXT_getFirmwareVersion(
+ nFANTOM100_iNXT nxtPtr,
+ ViUInt8* protocolVersionMajorPtr,
+ ViUInt8* protocolVersionMinorPtr,
+ ViUInt8* firmwareVersionMajorPtr,
+ ViUInt8* firmwareVersionMinorPtr,
+ ViStatus* status );
+
+ nFANTOM100_kExport ViUInt32 _VI_FUNCC nFANTOM100_iNXT_sendDirectCommand(
+ nFANTOM100_iNXT nxtPtr,
+ ViBoolean requireResponse,
+ const ViByte commandBufferPtr[],
+ ViUInt32 commandBufferSizeInBytes,
+ ViPBuf responseBufferPtr,
+ ViUInt32 responseBufferSizeInBytes,
+ ViStatus* status );
+
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_iNXT_findDeviceInFirmwareDownloadMode(
+ ViChar resourceString[],
+ ViStatus* status );
+
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_iNXT_downloadFirmware(
+ nFANTOM100_iNXT nxtPtr,
+ const ViByte firmwareBufferPtr[],
+ ViUInt32 firmwareBufferSize,
+ ViStatus* status );
+
+ nFANTOM100_kExport ViUInt32 _VI_FUNCC nFANTOM100_iNXT_write(
+ nFANTOM100_iNXT nxtPtr,
+ const ViByte bufferPtr[],
+ ViUInt32 numberOfBytes,
+ ViStatus* status );
+
+ nFANTOM100_kExport ViUInt32 _VI_FUNCC nFANTOM100_iNXT_read(
+ nFANTOM100_iNXT nxtPtr,
+ ViPBuf bufferPtr,
+ ViUInt32 numberOfBytes,
+ ViStatus* status );
+
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_iNXT_bootIntoFirmwareDownloadMode(
+ ViConstString resouceName,
+ ViStatus* status );
+
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_iNXT_setName(
+ nFANTOM100_iNXT nxtPtr,
+ ViConstString newName,
+ ViStatus* status );
+
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_iNXT_getDeviceInfo(
+ nFANTOM100_iNXT nxtPtr,
+ ViChar name[],
+ ViByte bluetoothAddress[],
+ ViUInt8 signalStrength[],
+ ViUInt32* availableFlash,
+ ViStatus* status );
+
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_iNXT_eraseUserFlash(
+ nFANTOM100_iNXT nxtPtr,
+ ViStatus* status );
+
+ nFANTOM100_kExport ViUInt32 _VI_FUNCC nFANTOM100_iNXT_pollAvailableLength(
+ nFANTOM100_iNXT nxtPtr,
+ ViUInt32 bufferIndex,
+ ViStatus* status );
+
+ nFANTOM100_kExport ViUInt32 _VI_FUNCC nFANTOM100_iNXT_readBufferData(
+ nFANTOM100_iNXT nxtPtr,
+ ViPBuf dataBuffer,
+ ViUInt32 bufferIndex,
+ ViUInt32 numberOfBytesToRead,
+ ViStatus* status );
+
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_iNXT_getResourceString(
+ nFANTOM100_iNXT nxtPtr,
+ ViChar resourceString[],
+ ViStatus* status );
+
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_iNXT_bluetoothFactoryReset(
+ nFANTOM100_iNXT nxtPtr,
+ ViStatus* status );
+
+
+ } // extern "C"
+
+
+// inline functions and function macros...
+
+
+#endif // ___fantom_iNXT_h___
diff --git a/AT91SAM7S256/armdebug/FantomModule/fantom/iNXTIterator.h b/AT91SAM7S256/armdebug/FantomModule/fantom/iNXTIterator.h
new file mode 100644
index 0000000..6f43537
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/fantom/iNXTIterator.h
@@ -0,0 +1,120 @@
+/*!
+ \file iNXTIterator.h
+ \brief Interface used for searching for LEGO MINDSTORMS NXTs.
+*/
+/*
+ © Copyright 2005-2006,
+ National Instruments Corporation.
+ All rights reserved.
+
+ File: iNXTIterator.h
+ Originated: 17 Oct 2005
+*/
+
+#ifndef ___fantom_iNXTIterator_h___
+#define ___fantom_iNXTIterator_h___
+
+
+// includes...
+
+#ifndef ___fantom_platform_h___
+ #include "platform.h"
+#endif
+
+#ifndef ___fantom_tStatus_h___
+ #include "tStatus.h"
+#endif
+
+
+// defines...
+
+
+namespace nFANTOM100
+{
+ // forward declarations...
+ class iNXT;
+
+ // typedefs...
+
+ // classes...
+
+ /*!
+ \class iNXTIterator
+ \brief Interface to an iterator for LEGO MINDSTORMS NXTs.
+ */
+ class iNXTIterator
+ {
+ friend class iNXT;
+
+ // methods
+ protected:
+
+ //! Destructor
+ virtual ~iNXTIterator() = 0;
+
+ public:
+
+ //! Retrieves the name of the NXT to which this iterator refers.
+ /*
+ \param resourceName Populated with the name of the NXT to which this iterator
+ currently refers. The resource name character array must have a capacity of 256
+ bytes.
+ \param status Status chaining object.
+ */
+ virtual void getName( ViChar resourceName[], tStatus& status ) const = 0;
+
+ //! Advances this iterator.
+ /*!
+ Advances this iterator to the next NXT that was found. If no more NXTs are found,
+ this iterator is advanced to the end of the list.
+ The iterator is not advanced if the specified status is fatal.
+ If this iterator is already at the end of the list, a fatal status will be generated.
+
+ \param status Status chaining object.
+ */
+ virtual void advance( tStatus& status ) = 0;
+
+ //! Creates an NXT object for the NXT referenced by this iterator.
+ /*
+ Creates an NXT object for the NXT referenced by this iterator. An object is not
+ created if the specified status is fatal or if this iterator refers to the end of
+ the list. The returned iNXT object should be destroyed using the iNXT::destroyNXT
+ method.
+
+ \param status Status chaining object.
+ \return A pointer to the iNXT object that was created.
+ */
+ virtual iNXT* getNXT( tStatus& status ) = 0;
+ };
+
+
+ // constants...
+
+} // namespace nFANTOM100
+
+
+ // declarations for globally-scoped globals...
+
+ // typedefs
+ typedef ViObject nFANTOM100_iNXTIterator;
+
+ // we must duplicate this typedef for the getNXT C wrapper
+ typedef ViObject nFANTOM100_iNXT;
+
+ extern "C"
+ {
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_iNXTIterator_getName(
+ nFANTOM100_iNXTIterator iteratorPtr,
+ ViChar resourceName[],
+ ViStatus* status );
+
+ nFANTOM100_kExport void _VI_FUNCC nFANTOM100_iNXTIterator_advance(
+ nFANTOM100_iNXTIterator iteratorPtr,
+ ViStatus* status );
+
+ nFANTOM100_kExport nFANTOM100_iNXT _VI_FUNCC nFANTOM100_iNXTIterator_getNXT(
+ nFANTOM100_iNXTIterator iteratorPtr,
+ ViStatus* status );
+ }
+
+#endif // ___fantom_iNXTIterator_h___
diff --git a/AT91SAM7S256/armdebug/FantomModule/fantom/platform.h b/AT91SAM7S256/armdebug/FantomModule/fantom/platform.h
new file mode 100644
index 0000000..7455796
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/fantom/platform.h
@@ -0,0 +1,94 @@
+/*!
+ \file platform.h
+ \brief This file contains platform-related defines.
+*/
+/*
+ © Copyright 2005,
+ National Instruments Corporation.
+ All rights reserved.
+
+ File: platform.h
+ Originated: 23 June 2005
+*/
+
+
+#ifndef ___fantom_platform_h___
+#define ___fantom_platform_h___
+
+#ifndef __VISATYPE_HEADER__
+ #include "visatype.h"
+#endif
+
+
+#define nFANTOM100_kOSMacOSX 0
+#define nFANTOM100_kOSWin32 0
+
+#define nFANTOM100_kProcessorI386 0
+#define nFANTOM100_kProcessorPPC 0
+
+#define nFANTOM100_kCompilerMSVC 0
+#define nFANTOM100_kCompilerApple 0
+
+
+#if (( defined( __GNUG__ ) || defined( __GNUC__ )) && defined( __APPLE__ ))
+
+ #undef nFANTOM100_kOSMacOSX
+ #define nFANTOM100_kOSMacOSX 1
+
+ #undef nFANTOM100_kCompilerApple
+ #define nFANTOM100_kCompilerApple ( __GNUC__ * 10000 \
+ + __GNUC_MINOR__ * 100 \
+ + __GNUC_PATCHLEVEL__ )
+
+ #if ( defined( __ppc__ ))
+ #undef nFANTOM100_kProcessorPPC
+ #define nFANTOM100_kProcessorPPC 1
+
+ #define nFANTOM100_kBigEndian 1
+ #define nFANTOM100_kLittleEndian 0
+ #elif ( defined( __i386__ ))
+ #undef nFANTOM100_kProcessorI386
+ #define nFANTOM100_kProcessorI386 1
+
+ #define nFANTOM100_kBigEndian 0
+ #define nFANTOM100_kLittleEndian 1
+ #else
+ #error Unknown processor.
+ #endif
+
+ #ifdef nFANTOM100_kExportSymbols
+ #define nFANTOM100_kExport __attribute__ ((section ("__TEXT,__export")))
+ #else
+ #define nFANTOM100_kExport
+ #endif
+
+
+#elif ( defined( _MSC_VER ) && ( defined( _M_IX86 ) || defined( _M_I86 )))
+
+ #undef nFANTOM100_kOSWin32
+ #define nFANTOM100_kOSWin32 1
+
+ #undef nFANTOM100_kCompilerMSVC
+ #define nFANTOM100_kCompilerMSVC _MSC_VER
+
+ #undef nFANTOM100_kProcessorI386
+ #define nFANTOM100_kProcessorI386 1
+
+ #ifdef nFANTOM100_kExportSymbols
+ #define nFANTOM100_kExport __declspec(dllexport)
+ #else
+ #define nFANTOM100_kExport __declspec(dllimport)
+ #endif
+
+ #define nFANTOM100_kBigEndian 0
+ #define nFANTOM100_kLittleEndian 1
+
+#else
+
+ #error Unknown platform.
+
+#endif
+
+
+#endif // ___fantom_platform_h___
+
diff --git a/AT91SAM7S256/armdebug/FantomModule/fantom/tStatus.h b/AT91SAM7S256/armdebug/FantomModule/fantom/tStatus.h
new file mode 100644
index 0000000..7622c63
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/fantom/tStatus.h
@@ -0,0 +1,458 @@
+/*!
+ \file tStatus.h
+ \brief Status code class
+*/
+/*
+ © Copyright 2005-2006,
+ National Instruments Corporation.
+ All rights reserved.
+
+ File: tStatus.h
+ Originated: 10 March 2005
+*/
+
+#ifndef ___fantom_tStatus_h___
+#define ___fantom_tStatus_h___
+
+// includes ...
+
+#ifndef ___fantom_platform_h___
+ #include "platform.h"
+#endif
+
+#include <string.h>
+
+
+// defines...
+
+#define nFANTOM_mLocation __FILE__, __LINE__
+
+#define nFANTOM_ForceToWarning(s) (((s) >= 0 ) ? (s) : -(s))
+#define nFANTOM_ForceToFatal(s) (((s) <= 0 ) ? (s) : -(s))
+
+/*!
+ \brief The namespace for Fantom 1.0.
+*/
+namespace nFANTOM100
+{
+ // forward declarations...
+
+ // typedefs...
+
+ // classes...
+ const ViInt32 kStatusOffset = -142000; // 0xFFFDD550
+ const ViStatus kStatusSuccess = VI_SUCCESS;
+
+ /*!
+ \brief Enumeration of Fantom-specific status codes. NI-VISA status codes may also be
+ returned. These are documented in the NI-VISA Programmer Reference Manual which is
+ available from <http://ni.com/>.
+ */
+ enum tFANTOMStatus
+ {
+ kStatusFirst = (kStatusOffset + 0),
+
+ //! Error: Bluetooth pairing operation failed.
+ //! Warning: You have already paired with that Bluetooth device.
+ kStatusPairingFailed = (kStatusOffset + -5), // 0x54B
+
+ //! Error: Bluetooth search failed.
+ kStatusBluetoothSearchFailed = (kStatusOffset + -6), // 0x54A
+
+ //! Error: System library not found.
+ kStatusSystemLibraryNotFound = (kStatusOffset + -7), // 0x549
+
+ //! Error: Bluetooth unpairing operation failed.
+ kStatusUnpairingFailed = (kStatusOffset + -8), // 0x548
+
+ //! Error: Invalid filename specified.
+ kStatusInvalidFilename = (kStatusOffset + -9), // 0x547
+
+ //! Error: Invalid iterator dereference. (No object to get.)
+ kStatusInvalidIteratorDereference = (kStatusOffset + -10), // 0x546
+
+ //! Error: Resource locking operation failed.
+ kStatusLockOperationFailed = (kStatusOffset + -11), // 0x545
+
+ //! Error: Could not determine the requested size.
+ kStatusSizeUnknown = (kStatusOffset + -12), // 0x544
+
+ //! Error: Cannot open two objects at once.
+ kStatusDuplicateOpen = (kStatusOffset + -13), // 0x543
+
+ //! Error: File is empty.
+ //! Warning: The requested file is empty.
+ kStatusEmptyFile = (kStatusOffset + -14), // 0x542
+
+ //! Error: Firmware download failed.
+ kStatusFirmwareDownloadFailed = (kStatusOffset + -15), // 0x541
+
+ //! Error: Could not locate virtual serial port.
+ kStatusPortNotFound = (kStatusOffset + -16), // 0x540
+
+ //! Error: No more items found.
+ kStatusNoMoreItemsFound = (kStatusOffset + -17), // 0x53F
+
+ //! Error: Too many unconfigured devices.
+ kStatusTooManyUnconfiguredDevices = (kStatusOffset + -18), // 0x53E
+
+ //! Error: Command mismatch in firmware response.
+ kStatusCommandMismatch = (kStatusOffset + -19), // 0x53D
+
+ //! Error: Illegal operation.
+ kStatusIllegalOperation = (kStatusOffset + -20), // 0x53C
+
+ //! Error: Could not update local Bluetooth cache with new name.
+ //! Warning: Could not update local Bluetooth cache with new name.
+ kStatusBluetoothCacheUpdateFailed = (kStatusOffset + -21), // 0x53B
+
+ //! Error: Selected device is not an NXT.
+ kStatusNonNXTDeviceSelected = (kStatusOffset + -22), // 0x53A
+
+ //! Error: Communication error. Retry the operation.
+ kStatusRetryConnection = (kStatusOffset + -23), // 0x539
+
+ //! Error: Could not connect to NXT. Turn the NXT off and then back on before continuing.
+ kStatusPowerCycleNXT = (kStatusOffset + -24), // 0x538
+
+ //! Error: This feature is not yet implemented.
+ kStatusFeatureNotImplemented = (kStatusOffset + -99), // 0x4ED
+
+ //! Error: Firmware reported an illegal handle.
+ kStatusFWIllegalHandle = (kStatusOffset + -189), // 0x493
+
+ //! Error: Firmware reported an illegal file name.
+ kStatusFWIllegalFileName = (kStatusOffset + -190), // 0x492
+
+ //! Error: Firmware reported an out of bounds reference.
+ kStatusFWOutOfBounds = (kStatusOffset + -191), // 0x491
+
+ //! Error: Firmware could not find module.
+ kStatusFWModuleNotFound = (kStatusOffset + -192), // 0x490
+
+ //! Error: Firmware reported that the file already exists.
+ kStatusFWFileExists = (kStatusOffset + -193), // 0x48F
+
+ //! Error: Firmware reported that the file is full.
+ kStatusFWFileIsFull = (kStatusOffset + -194), // 0x48E
+
+ //! Error: Firmware reported the append operation is not possible.
+ kStatusFWAppendNotPossible = (kStatusOffset + -195), // 0x48D
+
+ //! Error: Firmware has no write buffers available.
+ kStatusFWNoWriteBuffers = (kStatusOffset + -196), // 0x48C
+
+ //! Error: Firmware reported that file is busy.
+ kStatusFWFileIsBusy = (kStatusOffset + -197), // 0x48B
+
+ //! Error: Firmware reported the undefined error.
+ kStatusFWUndefinedError = (kStatusOffset + -198), // 0x48A
+
+ //! Error: Firmware reported that no linear space is available.
+ kStatusFWNoLinearSpace = (kStatusOffset + -199), // 0x489
+
+ //! Error: Firmware reported that handle has already been closed.
+ kStatusFWHandleAlreadyClosed = (kStatusOffset + -200), // 0x488
+
+ //! Error: Firmware could not find file.
+ kStatusFWFileNotFound = (kStatusOffset + -201), // 0x487
+
+ //! Error: Firmware reported that the requested file is not linear.
+ kStatusFWNotLinearFile = (kStatusOffset + -202), // 0x486
+
+ //! Error: Firmware reached the end of the file.
+ kStatusFWEndOfFile = (kStatusOffset + -203), // 0x485
+
+ //! Error: Firmware expected an end of file.
+ kStatusFWEndOfFileExpected = (kStatusOffset + -204), // 0x484
+
+ //! Error: Firmware cannot handle more files.
+ kStatusFWNoMoreFiles = (kStatusOffset + -205), // 0x483
+
+ //! Error: Firmware reported the NXT is out of space.
+ kStatusFWNoSpace = (kStatusOffset + -206), // 0x482
+
+ //! Error: Firmware could not create a handle.
+ kStatusFWNoMoreHandles = (kStatusOffset + -207), // 0x481
+
+ //! Error: Firmware reported an unknown error code.
+ kStatusFWUnknownErrorCode = (kStatusOffset + -208), // 0x480
+
+ kStatusLast = (kStatusOffset + -999)
+ };
+
+ /*!
+ \brief Class that contains a status code and the file name and line number where that
+ status code was generated.
+ */
+ class tStatus
+ {
+ public:
+
+ // methods
+
+ //! constructor
+ /*!
+ Creates a tStatus object intialized to success.
+
+ \post The status code is set to VI_SUCCESS.
+ */
+ inline tStatus( void ) :
+ _code( VI_SUCCESS ),
+ _lineNumber( 0 )
+ {
+ _fileName[0] = '\0';
+ }
+
+
+ //! copy constructor
+ /*!
+ Copies the code, line number, and file name from the specified tStatus object.
+
+ \param status The status object to copy.
+ */
+ inline tStatus( const tStatus& status ) :
+ _code( status._code ),
+ _lineNumber( status._lineNumber )
+ {
+ ::strcpy( _fileName, "" );
+ ::strncat( _fileName, status._fileName, kMaxFileNameLength - 1 );
+ }
+
+
+ //! constructor with code, filename, and line number
+ /*!
+ Creates a tStatus object initialized to the specified code, file name, and line number.
+ Note that the nFANTOM_mLocation macro can be used to pass the fileName and lineNumber
+ parameters.
+
+ \param code A status code.
+ \param fileName The name of the file in which the status code was generated.
+ \param lineNumber The line number in the file at which the status code was generated.
+ */
+ inline tStatus( ViStatus code, const char* fileName, ViUInt32 lineNumber ) :
+ _code( code ),
+ _lineNumber( lineNumber )
+ {
+ ::strcpy( _fileName, "" );
+ ::strncat( _fileName, reinterpret_cast<const char*>( fileName ), kMaxFileNameLength - 1 );
+ }
+
+
+ //! destructor
+ inline ~tStatus()
+ {
+ }
+
+
+ //! Returns the status code for this status object.
+ /*!
+ \return The status code for this status object.
+ */
+ inline ViStatus getCode( void ) const
+ {
+ return _code;
+ }
+
+
+ //! Returns the file name in which the status code, for this status object, was generated.
+ /*!
+ \return The file name in which the status code, for this status object, was generated.
+ */
+ inline const char* getFileName( void ) const
+ {
+ return _fileName;
+ }
+
+
+ //! Returns the line number at which the status code, for this status object, was
+ // generated.
+ /*!
+ \return The line number at which the status code, for this status object, was
+ generated.
+ */
+ inline ViUInt32 getLineNumber( void ) const
+ {
+ return _lineNumber;
+ }
+
+
+ //! Sets the status code, file name, and line number for this status object, if
+ // appropriate.
+ /*!
+ Stores the specified status code, file name, and line number in this status object if
+ this status object contains a successful status code or if this status object
+ contains a warning status code and the specified status code is fatal. A fatal
+ status code is denoted by a negative value. A successful status code is denoted
+ by VI_SUCCESS.
+
+ \param code A status code.
+ \param fileName The name of the file in which the status code was generated.
+ \param lineNumber The line number in the file at which the status code was generated.
+ */
+ inline void setCode( ViStatus code, const char* fileName, ViUInt32 lineNumber )
+ {
+ if(( isSuccess() && code != VI_SUCCESS ) || ( isNotFatal() && code < VI_SUCCESS ))
+ {
+ _code = code;
+ _lineNumber = lineNumber;
+ ::strcpy( _fileName, "" );
+ ::strncat( _fileName, fileName, kMaxFileNameLength - 1 );
+ }
+ }
+
+
+ //! Assigns the specified status object to this status object, if appropriate.
+ /*!
+ Stores the status code, file name, and line number of the specified status object in
+ this status object if this status object contains a successful status code or if
+ this status object contains a warning status code and the status code of the
+ speciied status object is fatal. A fatal status code is denoted by a negative
+ value. A successful status code is denoted by VI_SUCCESS.
+
+ \param status The status object to assign.
+ */
+ inline void assign( const tStatus& status )
+ {
+ setCode( status.getCode(), status.getFileName(), status.getLineNumber());
+ }
+
+
+ //! Clears the status code for this status object.
+ /*!
+ \post status The code is set to VI_SUCCESS.
+ */
+ inline void clear( void )
+ {
+ _code = VI_SUCCESS;
+ _lineNumber = 0;
+ _fileName[0] = '\0';
+ }
+
+
+ //! Returns true if this status object contains a status code that is fatal.
+ /*!
+ A status code with a negative value is considered fatal.
+
+ \return true if this status object contains a status code that is
+ fatal; false otherwise.
+ */
+ inline bool isFatal( void ) const
+ {
+ return ( _code < VI_SUCCESS );
+ }
+
+ //! Returns true if this status object contains a status code that is not fatal.
+ /*!
+ Any status code with a non-negative (including zero) value is considered non-fatal.
+
+ \return true if this status object contains a non-fatal status code;
+ false otherwise.
+ */
+ inline bool isNotFatal( void ) const
+ {
+ return !isFatal();
+ }
+
+
+ //! Returns true if this status object contains a status code that is a warning.
+ /*!
+ A status code with a non-zero, positive value is considered a warning.
+
+ \return true if this status object contains a status code that is a warning; false
+ otherwise.
+ */
+ inline bool isWarning( void ) const
+ {
+ return ( _code > VI_SUCCESS );
+ }
+
+
+ //! Returns true if this status object contains the status code for success.
+ /*!
+ A value of VI_SUCCESS represents success.
+
+ \return true if this status object contains the status code for success; false
+ otherwise.
+ */
+ inline bool isSuccess( void ) const
+ {
+ return ( _code == VI_SUCCESS );
+ }
+
+ private:
+
+ // declared private to prevent assignment
+ tStatus& operator=(const tStatus& rhs);
+
+ enum
+ {
+ kMaxFileNameLength = 101
+ };
+
+ ViStatus _code;
+ ViChar _fileName[ kMaxFileNameLength ];
+ ViUInt32 _lineNumber;
+ };
+
+
+ // declarations for globally-scoped globals...
+ inline ViStatus convertStatus( ViUInt8 firmwareStatus )
+ {
+ ViStatus status;
+ switch (firmwareStatus)
+ {
+ // each of these cases corresponds to a unique status code returned by the firmware
+ case 0x00 : status = kStatusSuccess;
+ break;
+ case 0x81 : status = kStatusFWNoMoreHandles; // No more available handles
+ break;
+ case 0x82 : status = kStatusFWNoSpace; // No space
+ break;
+ case 0x83 : status = kStatusFWNoMoreFiles; // No more files
+ break;
+ case 0x84 : status = kStatusFWEndOfFileExpected; // End of file expected
+ break;
+ case 0x85 : status = kStatusFWEndOfFile; // End of file reached
+ break;
+ case 0x86 : status = kStatusFWNotLinearFile; // Not a linear file
+ break;
+ case 0x87 : status = kStatusFWFileNotFound; // File not found
+ break;
+ case 0x88 : status = kStatusFWHandleAlreadyClosed; // Handle is already closed
+ break;
+ case 0x89 : status = kStatusFWNoLinearSpace; // No linear space available
+ break;
+ case 0x8A : status = kStatusFWUndefinedError; // Undefined error
+ break;
+ case 0x8B : status = kStatusFWFileIsBusy; // File is busy
+ break;
+ case 0x8C : status = kStatusFWNoWriteBuffers; // No write buffers available
+ break;
+ case 0x8D : status = kStatusFWAppendNotPossible; // Append not possible
+ break;
+ case 0x8E : status = kStatusFWFileIsFull; // File is full
+ break;
+ case 0x8F : status = kStatusFWFileExists; // File already exists
+ break;
+ case 0x90 : status = kStatusFWModuleNotFound; // Module not found
+ break;
+ case 0x91 : status = kStatusFWOutOfBounds; // Out of module I/O map boundary
+ break;
+ case 0x92 : status = kStatusFWIllegalFileName; // Illegal file name
+ break;
+ case 0x93 : status = kStatusFWIllegalHandle; // Illegal handle
+ break;
+ default :
+ status = kStatusFWUnknownErrorCode;
+ }
+ return status;
+ }
+
+ // prototypes...
+
+} // namespace nFANTOM100
+
+// inline functions and function macros...
+
+#endif // ___fantom_tStatus_h___
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/advanceFileIterator.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/advanceFileIterator.vi
new file mode 100644
index 0000000..427df5b
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/advanceFileIterator.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/advanceModuleIterator.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/advanceModuleIterator.vi
new file mode 100644
index 0000000..46617f5
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/advanceModuleIterator.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/advanceNXTIterator.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/advanceNXTIterator.vi
new file mode 100644
index 0000000..e223afd
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/advanceNXTIterator.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/bluetoothFactoryReset.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/bluetoothFactoryReset.vi
new file mode 100644
index 0000000..d821675
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/bluetoothFactoryReset.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/bootSamba.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/bootSamba.vi
new file mode 100644
index 0000000..a1bf225
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/bootSamba.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/closeFile.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/closeFile.vi
new file mode 100644
index 0000000..f5b1e12
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/closeFile.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/createFile.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/createFile.vi
new file mode 100644
index 0000000..b3442ac
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/createFile.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/createFileIterator.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/createFileIterator.vi
new file mode 100644
index 0000000..4ad1d34
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/createFileIterator.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/createModule.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/createModule.vi
new file mode 100644
index 0000000..bd1f3e8
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/createModule.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/createModuleIterator.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/createModuleIterator.vi
new file mode 100644
index 0000000..051e858
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/createModuleIterator.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/createNXT.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/createNXT.vi
new file mode 100644
index 0000000..bb38bb8
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/createNXT.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/createNXTIterator.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/createNXTIterator.vi
new file mode 100644
index 0000000..2827435
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/createNXTIterator.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/destroyFile.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/destroyFile.vi
new file mode 100644
index 0000000..a57aea3
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/destroyFile.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/destroyFileIterator.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/destroyFileIterator.vi
new file mode 100644
index 0000000..0010789
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/destroyFileIterator.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/destroyModule.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/destroyModule.vi
new file mode 100644
index 0000000..66af71f
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/destroyModule.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/destroyModuleIterator.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/destroyModuleIterator.vi
new file mode 100644
index 0000000..c0a4b9a
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/destroyModuleIterator.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/destroyNXT.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/destroyNXT.vi
new file mode 100644
index 0000000..3065055
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/destroyNXT.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/destroyNXTIterator.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/destroyNXTIterator.vi
new file mode 100644
index 0000000..f763b9a
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/destroyNXTIterator.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/downloadFirmware.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/downloadFirmware.vi
new file mode 100644
index 0000000..d0c082b
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/downloadFirmware.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/eraseUserFlash.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/eraseUserFlash.vi
new file mode 100644
index 0000000..4961a39
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/eraseUserFlash.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/findDeviceInFirmwareDownloadMode.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/findDeviceInFirmwareDownloadMode.vi
new file mode 100644
index 0000000..44bfc91
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/findDeviceInFirmwareDownloadMode.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/findNXT.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/findNXT.vi
new file mode 100644
index 0000000..78b9034
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/findNXT.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getAvailableSize.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getAvailableSize.vi
new file mode 100644
index 0000000..c6f2be6
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getAvailableSize.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getDeviceInfo.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getDeviceInfo.vi
new file mode 100644
index 0000000..1fbc025
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getDeviceInfo.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getFile.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getFile.vi
new file mode 100644
index 0000000..6a31965
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getFile.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getFileName.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getFileName.vi
new file mode 100644
index 0000000..b5d7724
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getFileName.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getFileSize.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getFileSize.vi
new file mode 100644
index 0000000..d0d18dc
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getFileSize.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getFileSizeFromIterator.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getFileSizeFromIterator.vi
new file mode 100644
index 0000000..b9ee459
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getFileSizeFromIterator.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getFilenameFromIterator.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getFilenameFromIterator.vi
new file mode 100644
index 0000000..f389374
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getFilenameFromIterator.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getFirmwareVersion.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getFirmwareVersion.vi
new file mode 100644
index 0000000..d31e7b1
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getFirmwareVersion.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getIOMapSize.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getIOMapSize.vi
new file mode 100644
index 0000000..b85503e
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getIOMapSize.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getModule.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getModule.vi
new file mode 100644
index 0000000..c7aa164
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getModule.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getModuleID.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getModuleID.vi
new file mode 100644
index 0000000..c361683
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getModuleID.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getModuleName.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getModuleName.vi
new file mode 100644
index 0000000..1e677ac
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getModuleName.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getModuleNameFromIterator.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getModuleNameFromIterator.vi
new file mode 100644
index 0000000..f398170
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getModuleNameFromIterator.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getModuleSize.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getModuleSize.vi
new file mode 100644
index 0000000..504956b
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getModuleSize.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getNXTFromIterator.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getNXTFromIterator.vi
new file mode 100644
index 0000000..8301df2
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getNXTFromIterator.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getResourceString.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getResourceString.vi
new file mode 100644
index 0000000..55f8fe7
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getResourceString.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getStringFromNXTIterator.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getStringFromNXTIterator.vi
new file mode 100644
index 0000000..9f97c2a
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/getStringFromNXTIterator.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/isPaired.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/isPaired.vi
new file mode 100644
index 0000000..a2f9602
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/isPaired.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/nakedRead.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/nakedRead.vi
new file mode 100644
index 0000000..00a43de
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/nakedRead.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/nakedWrite.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/nakedWrite.vi
new file mode 100644
index 0000000..01bd8e1
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/nakedWrite.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/nxt.ctl b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/nxt.ctl
new file mode 100644
index 0000000..2f06605
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/nxt.ctl
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/openForRead.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/openForRead.vi
new file mode 100644
index 0000000..74dd60b
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/openForRead.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/openForWrite.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/openForWrite.vi
new file mode 100644
index 0000000..180bd70
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/openForWrite.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/pairBluetooth.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/pairBluetooth.vi
new file mode 100644
index 0000000..1845031
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/pairBluetooth.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/pollAvailableLength.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/pollAvailableLength.vi
new file mode 100644
index 0000000..0b74f5d
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/pollAvailableLength.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/read.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/read.vi
new file mode 100644
index 0000000..9cf87a4
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/read.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/readBufferData.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/readBufferData.vi
new file mode 100644
index 0000000..1ebef92
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/readBufferData.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/readIOMap.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/readIOMap.vi
new file mode 100644
index 0000000..be244b0
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/readIOMap.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/remove.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/remove.vi
new file mode 100644
index 0000000..4216b11
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/remove.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/sendDirectCommand.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/sendDirectCommand.vi
new file mode 100644
index 0000000..c7694ca
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/sendDirectCommand.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/setNXTName.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/setNXTName.vi
new file mode 100644
index 0000000..19339d2
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/setNXTName.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/unpairBluetooth.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/unpairBluetooth.vi
new file mode 100644
index 0000000..c2e3b7c
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/unpairBluetooth.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/write.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/write.vi
new file mode 100644
index 0000000..9f556a0
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/write.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/writeIOMap.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/writeIOMap.vi
new file mode 100644
index 0000000..dda451b
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/macosx/writeIOMap.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/advanceFileIterator.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/advanceFileIterator.vi
new file mode 100644
index 0000000..19fc124
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/advanceFileIterator.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/advanceModuleIterator.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/advanceModuleIterator.vi
new file mode 100644
index 0000000..b9879c7
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/advanceModuleIterator.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/advanceNXTIterator.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/advanceNXTIterator.vi
new file mode 100644
index 0000000..a0fe1f1
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/advanceNXTIterator.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/bluetoothFactoryReset.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/bluetoothFactoryReset.vi
new file mode 100644
index 0000000..0f9c6a8
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/bluetoothFactoryReset.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/bootSamba.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/bootSamba.vi
new file mode 100644
index 0000000..397a119
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/bootSamba.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/closeFile.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/closeFile.vi
new file mode 100644
index 0000000..3e893e7
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/closeFile.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/createFile.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/createFile.vi
new file mode 100644
index 0000000..1445f12
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/createFile.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/createFileIterator.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/createFileIterator.vi
new file mode 100644
index 0000000..5554f4b
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/createFileIterator.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/createModule.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/createModule.vi
new file mode 100644
index 0000000..b640ae7
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/createModule.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/createModuleIterator.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/createModuleIterator.vi
new file mode 100644
index 0000000..fd79dba
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/createModuleIterator.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/createNXT.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/createNXT.vi
new file mode 100644
index 0000000..47b3243
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/createNXT.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/createNXTIterator.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/createNXTIterator.vi
new file mode 100644
index 0000000..c6f8f24
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/createNXTIterator.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/destroyFile.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/destroyFile.vi
new file mode 100644
index 0000000..c71a99a
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/destroyFile.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/destroyFileIterator.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/destroyFileIterator.vi
new file mode 100644
index 0000000..783c4f4
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/destroyFileIterator.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/destroyModule.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/destroyModule.vi
new file mode 100644
index 0000000..0cf7fb7
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/destroyModule.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/destroyModuleIterator.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/destroyModuleIterator.vi
new file mode 100644
index 0000000..5e40e7e
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/destroyModuleIterator.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/destroyNXT.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/destroyNXT.vi
new file mode 100644
index 0000000..42409c3
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/destroyNXT.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/destroyNXTIterator.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/destroyNXTIterator.vi
new file mode 100644
index 0000000..b9a9113
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/destroyNXTIterator.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/downloadFirmware.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/downloadFirmware.vi
new file mode 100644
index 0000000..cf95da4
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/downloadFirmware.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/eraseUserFlash.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/eraseUserFlash.vi
new file mode 100644
index 0000000..d3c9154
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/eraseUserFlash.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/findDeviceInFirmwareDownloadMode.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/findDeviceInFirmwareDownloadMode.vi
new file mode 100644
index 0000000..4a0b7c6
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/findDeviceInFirmwareDownloadMode.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/findNXT.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/findNXT.vi
new file mode 100644
index 0000000..747c8cd
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/findNXT.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getAvailableSize.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getAvailableSize.vi
new file mode 100644
index 0000000..b511b2d
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getAvailableSize.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getDeviceInfo.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getDeviceInfo.vi
new file mode 100644
index 0000000..835046a
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getDeviceInfo.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getFile.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getFile.vi
new file mode 100644
index 0000000..2931da1
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getFile.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getFileName.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getFileName.vi
new file mode 100644
index 0000000..40ec334
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getFileName.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getFileSize.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getFileSize.vi
new file mode 100644
index 0000000..3ba069e
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getFileSize.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getFileSizeFromIterator.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getFileSizeFromIterator.vi
new file mode 100644
index 0000000..9228800
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getFileSizeFromIterator.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getFilenameFromIterator.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getFilenameFromIterator.vi
new file mode 100644
index 0000000..bbbf882
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getFilenameFromIterator.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getFirmwareVersion.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getFirmwareVersion.vi
new file mode 100644
index 0000000..38760ac
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getFirmwareVersion.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getIOMapSize.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getIOMapSize.vi
new file mode 100644
index 0000000..adf1396
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getIOMapSize.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getModule.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getModule.vi
new file mode 100644
index 0000000..eeff3c8
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getModule.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getModuleID.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getModuleID.vi
new file mode 100644
index 0000000..2250164
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getModuleID.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getModuleName.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getModuleName.vi
new file mode 100644
index 0000000..b0620c8
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getModuleName.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getModuleNameFromIterator.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getModuleNameFromIterator.vi
new file mode 100644
index 0000000..f0e31ce
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getModuleNameFromIterator.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getModuleSize.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getModuleSize.vi
new file mode 100644
index 0000000..1b2a5f6
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getModuleSize.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getNXTFromIterator.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getNXTFromIterator.vi
new file mode 100644
index 0000000..8acd597
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getNXTFromIterator.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getResourceString.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getResourceString.vi
new file mode 100644
index 0000000..c0d019a
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getResourceString.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getStringFromNXTIterator.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getStringFromNXTIterator.vi
new file mode 100644
index 0000000..8dee827
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/getStringFromNXTIterator.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/isPaired.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/isPaired.vi
new file mode 100644
index 0000000..1c73992
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/isPaired.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/nakedRead.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/nakedRead.vi
new file mode 100644
index 0000000..9c40980
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/nakedRead.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/nakedWrite.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/nakedWrite.vi
new file mode 100644
index 0000000..f2f875a
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/nakedWrite.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/nxt.ctl b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/nxt.ctl
new file mode 100644
index 0000000..6016dd1
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/nxt.ctl
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/openForRead.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/openForRead.vi
new file mode 100644
index 0000000..48d08e5
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/openForRead.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/openForWrite.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/openForWrite.vi
new file mode 100644
index 0000000..e5d83c8
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/openForWrite.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/pairBluetooth.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/pairBluetooth.vi
new file mode 100644
index 0000000..52fb06a
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/pairBluetooth.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/pollAvailableLength.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/pollAvailableLength.vi
new file mode 100644
index 0000000..6d05f67
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/pollAvailableLength.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/read.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/read.vi
new file mode 100644
index 0000000..c20cab9
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/read.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/readBufferData.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/readBufferData.vi
new file mode 100644
index 0000000..6b621d8
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/readBufferData.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/readIOMap.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/readIOMap.vi
new file mode 100644
index 0000000..9d89134
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/readIOMap.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/remove.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/remove.vi
new file mode 100644
index 0000000..9870267
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/remove.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/sendDirectCommand.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/sendDirectCommand.vi
new file mode 100644
index 0000000..dba13c6
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/sendDirectCommand.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/setNXTName.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/setNXTName.vi
new file mode 100644
index 0000000..65aa4ac
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/setNXTName.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/unpairBluetooth.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/unpairBluetooth.vi
new file mode 100644
index 0000000..9389c36
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/unpairBluetooth.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/write.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/write.vi
new file mode 100644
index 0000000..d6f95d9
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/write.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/writeIOMap.vi b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/writeIOMap.vi
new file mode 100644
index 0000000..621546c
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/include/labview/win32/writeIOMap.vi
Binary files differ
diff --git a/AT91SAM7S256/armdebug/FantomModule/pyfantom/__init__.py b/AT91SAM7S256/armdebug/FantomModule/pyfantom/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/pyfantom/__init__.py
diff --git a/AT91SAM7S256/armdebug/FantomModule/setup.py b/AT91SAM7S256/armdebug/FantomModule/setup.py
new file mode 100644
index 0000000..e713d2f
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/setup.py
@@ -0,0 +1,40 @@
+from distutils.core import setup, Extension
+import sys
+import os
+
+def getextensions():
+ mac_ext = Extension("FantomModule",
+ define_macros=[('PYFANTOM_DEBUG', '0')], # set to '1' to print debug messges
+ include_dirs=['.'],
+ extra_compile_args=["-Wno-strict-prototypes"],
+ extra_link_args=["-framework Fantom"],
+ sources=["FantomModule.cpp"]
+ )
+ return [mac_ext]
+
+# Must specify i386 arch via environment variable since Fantom libraries are i386 only
+# Order of gcc flags is important, it can't be specified via Extension() module
+os.environ['ARCHFLAGS'] = '-arch i386'
+
+# install the main library
+setup(name="pyfantom",
+ version="0.1",
+ author="Tat-Chee Wan",
+ author_email="tcwan@cs.usm.my",
+ url="",
+ description="Python Extension to call Fantom Driver",
+ long_description="Python Wrapper for Fantom Driver on Mac OS X.",
+ license="GPL",
+ packages=["pyfantom"],
+ ext_modules=getextensions(),
+ classifiers = [ "Development Status :: 3 - Alpha",
+ "Intended Audience :: Developers",
+ # Need to confirm Fantom / NI-VISA license compatibility
+ # "License :: OSI Approved :: GNU General Public License (GPL)",
+ # "License :: OSI Approved :: GNU General Public License v2",
+ "Programming Language :: C++",
+ "Topic :: Software Development :: Libraries",
+ "Topic :: System :: Networking",
+ "Topic :: Communications",
+ "Operating System :: MacOS :: MacOS X" ]
+ )
diff --git a/AT91SAM7S256/armdebug/FantomModule/visatype.h b/AT91SAM7S256/armdebug/FantomModule/visatype.h
new file mode 100644
index 0000000..a667ff1
--- /dev/null
+++ b/AT91SAM7S256/armdebug/FantomModule/visatype.h
@@ -0,0 +1,155 @@
+/*---------------------------------------------------------------------------*/
+/* Distributed by VXIplug&play Systems Alliance */
+/* */
+/* Do not modify the contents of this file. */
+/*---------------------------------------------------------------------------*/
+/* */
+/* Title : VISATYPE.H */
+/* Date : 08-01-98 */
+/* Purpose : Fundamental VISA data types and macro definitions */
+/* */
+/*---------------------------------------------------------------------------*/
+
+#ifndef __VISATYPE_HEADER__
+#define __VISATYPE_HEADER__
+
+#if (defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)) && !defined(_NI_mswin16_)
+#define _VI_FAR
+#define _VI_FUNC __stdcall
+#define _VI_FUNCC __cdecl
+#define _VI_FUNCH __stdcall
+#define _VI_SIGNED signed
+#elif defined(_CVI_) && defined(_NI_i386_)
+#define _VI_FAR
+#define _VI_FUNC _pascal
+#define _VI_FUNCC
+#define _VI_FUNCH _pascal
+#define _VI_SIGNED signed
+#elif (defined(_WINDOWS) || defined(_Windows)) && !defined(_NI_mswin16_)
+#define _VI_FAR _far
+#define _VI_FUNC _far _pascal _export
+#define _VI_FUNCC _far _cdecl _export
+#define _VI_FUNCH _far _pascal
+#define _VI_SIGNED signed
+#elif (defined(hpux) || defined(__hpux)) && (defined(__cplusplus) || defined(__cplusplus__))
+#define _VI_FAR
+#define _VI_FUNC
+#define _VI_FUNCC
+#define _VI_FUNCH
+#define _VI_SIGNED
+#else
+#define _VI_FAR
+#define _VI_FUNC
+#define _VI_FUNCC
+#define _VI_FUNCH
+#define _VI_SIGNED signed
+#endif
+
+#define _VI_ERROR (-2147483647L-1) /* 0x80000000 */
+#define _VI_PTR _VI_FAR *
+
+/*- VISA Types --------------------------------------------------------------*/
+
+typedef unsigned long ViUInt32;
+typedef ViUInt32 _VI_PTR ViPUInt32;
+typedef ViUInt32 _VI_PTR ViAUInt32;
+
+typedef _VI_SIGNED long ViInt32;
+typedef ViInt32 _VI_PTR ViPInt32;
+typedef ViInt32 _VI_PTR ViAInt32;
+
+typedef unsigned short ViUInt16;
+typedef ViUInt16 _VI_PTR ViPUInt16;
+typedef ViUInt16 _VI_PTR ViAUInt16;
+
+typedef _VI_SIGNED short ViInt16;
+typedef ViInt16 _VI_PTR ViPInt16;
+typedef ViInt16 _VI_PTR ViAInt16;
+
+typedef unsigned char ViUInt8;
+typedef ViUInt8 _VI_PTR ViPUInt8;
+typedef ViUInt8 _VI_PTR ViAUInt8;
+
+typedef _VI_SIGNED char ViInt8;
+typedef ViInt8 _VI_PTR ViPInt8;
+typedef ViInt8 _VI_PTR ViAInt8;
+
+typedef char ViChar;
+typedef ViChar _VI_PTR ViPChar;
+typedef ViChar _VI_PTR ViAChar;
+
+typedef unsigned char ViByte;
+typedef ViByte _VI_PTR ViPByte;
+typedef ViByte _VI_PTR ViAByte;
+
+typedef void _VI_PTR ViAddr;
+typedef ViAddr _VI_PTR ViPAddr;
+typedef ViAddr _VI_PTR ViAAddr;
+
+typedef float ViReal32;
+typedef ViReal32 _VI_PTR ViPReal32;
+typedef ViReal32 _VI_PTR ViAReal32;
+
+typedef double ViReal64;
+typedef ViReal64 _VI_PTR ViPReal64;
+typedef ViReal64 _VI_PTR ViAReal64;
+
+typedef ViPByte ViBuf;
+typedef ViPByte ViPBuf;
+typedef ViPByte _VI_PTR ViABuf;
+
+typedef ViPChar ViString;
+typedef ViPChar ViPString;
+typedef ViPChar _VI_PTR ViAString;
+
+typedef ViString ViRsrc;
+typedef ViString ViPRsrc;
+typedef ViString _VI_PTR ViARsrc;
+
+typedef ViUInt16 ViBoolean;
+typedef ViBoolean _VI_PTR ViPBoolean;
+typedef ViBoolean _VI_PTR ViABoolean;
+
+typedef ViInt32 ViStatus;
+typedef ViStatus _VI_PTR ViPStatus;
+typedef ViStatus _VI_PTR ViAStatus;
+
+typedef ViUInt32 ViVersion;
+typedef ViVersion _VI_PTR ViPVersion;
+typedef ViVersion _VI_PTR ViAVersion;
+
+typedef ViUInt32 ViObject;
+typedef ViObject _VI_PTR ViPObject;
+typedef ViObject _VI_PTR ViAObject;
+
+typedef ViObject ViSession;
+typedef ViSession _VI_PTR ViPSession;
+typedef ViSession _VI_PTR ViASession;
+
+typedef ViUInt32 ViAttr;
+
+#ifndef _VI_CONST_STRING_DEFINED
+typedef const ViChar * ViConstString;
+#define _VI_CONST_STRING_DEFINED
+#endif
+
+/*- Completion and Error Codes ----------------------------------------------*/
+
+#define VI_SUCCESS (0L)
+
+/*- Other VISA Definitions --------------------------------------------------*/
+
+#define VI_NULL (0)
+
+#define VI_TRUE (1)
+#define VI_FALSE (0)
+
+/*- Backward Compatibility Macros -------------------------------------------*/
+
+#define VISAFN _VI_FUNC
+#define ViPtr _VI_PTR
+
+#endif
+
+/*- The End -----------------------------------------------------------------*/
+
diff --git a/AT91SAM7S256/armdebug/GNU-GPLv2.txt b/AT91SAM7S256/armdebug/GNU-GPLv2.txt
new file mode 100644
index 0000000..5b6e7c6
--- /dev/null
+++ b/AT91SAM7S256/armdebug/GNU-GPLv2.txt
@@ -0,0 +1,340 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/AT91SAM7S256/armdebug/Host/README b/AT91SAM7S256/armdebug/Host/README
new file mode 100644
index 0000000..23d95c9
--- /dev/null
+++ b/AT91SAM7S256/armdebug/Host/README
@@ -0,0 +1,21 @@
+The nxt-gdb-server.py script is initially developed by Nicolas Schodet.
+
+It depends on the following libraries:
+ - nxt-python v2.1.x http://code.google.com/p/nxt-python/
+ - pyusb v0.4x http://pyusb.wiki.sourceforge.net
+ - libusb v0.1.x http://libusb.org/
+
+Currently, it does not work with libusb v1.x, on Mac OSX, it causes segfaults.
+
+ Installation
+ ============
+
+ There is no specific installation requirements (at this moment). Just run the python script
+ in a terminal window.
+
+ Usage
+ =====
+
+ 1. Connect the USB cable from the PC Host to the NXT
+ 2. start nxt-gdb-server.py
+ 3. start arm-none-eabi-gdb, configured as remote for port 2828 (default)
diff --git a/AT91SAM7S256/armdebug/Host/gdb-commands.txt b/AT91SAM7S256/armdebug/Host/gdb-commands.txt
new file mode 100644
index 0000000..3135a1e
--- /dev/null
+++ b/AT91SAM7S256/armdebug/Host/gdb-commands.txt
@@ -0,0 +1,43 @@
+# This file contains hand coded GDB commands for testing the GDB Server <-> NXT interface
+
+# Display all Registers
+$g#67
+
+# Display R0
+$p0#A0
+
+# Display R1
+$p1#A1
+
+# Display PC
+$pF#B6
+
+# Display FPSCR (dummy)
+$p18#D9
+
+# Display User CPSR
+$p19#DA
+
+# Query Status
+$?#3F
+
+# Query Thread
+$qC#B4
+
+# Set R1 to 0xAA
+$P1=000000AA#60
+
+# Read 16 bytes of Memory from 0x00201d74 (padding bytes after debug_mode + 4 bytes of debug_InUSBBuf)
+$m00201D74,0010#FC
+
+# Write 2 bytes of memory to 0x00201d74 (padding bytes after debug_mode)
+$M00201D74,0002:AA55#03
+
+# Write 2 bytes of memory to 0x00201d74 (padding bytes after debug_mode)
+$M00201D74,0002:9966#F5
+
+# GDB Read Instruction at Address (PC)
++$m1001de,4#58
+
+# Continue Execution
+$c#63
diff --git a/AT91SAM7S256/armdebug/Host/nxt-gdb-server.py b/AT91SAM7S256/armdebug/Host/nxt-gdb-server.py
new file mode 100755
index 0000000..47a552d
--- /dev/null
+++ b/AT91SAM7S256/armdebug/Host/nxt-gdb-server.py
@@ -0,0 +1,202 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2011 the NxOS developers
+#
+# Module Developed by: Nicolas Schodet
+# TC Wan
+#
+# See AUTHORS for a full list of the developers.
+#
+# See COPYING for redistribution license
+#
+# Exchange GDB messages with the NXT brick.
+#
+# Every message is encapsulated with the debug command and message length.
+# This can be used by the firmware to make the distinction between debug
+# messages and regular messages.
+#
+import nxt.locator
+import socket
+import optparse
+import select
+import usb
+import struct
+
+CTRLC = chr(3)
+STATUS_QUERY = "$?#3F"
+DEFAULT_PORT = 2828
+SELECT_TIMEOUT = 0.1
+DEBUG = True
+DEBUG2 = False
+NXT_RECV_ERR = -1
+
+# Libusb 0.12.x blocks on USB reads
+LIBUSB_RECEIVE_BLOCKING = True
+
+class NXTGDBServer:
+
+ # Socket read size.
+ recv_size = 1024
+
+ # Maximum message size.
+ pack_size = 61
+
+ # Debug command header, no reply.
+ debug_command = 0x8d
+
+ def __init__ (self, port):
+ """Initialise server."""
+ self.port = port
+ self.in_buf = ''
+
+ def pack (self, data, segment_no):
+ """Return packed data to send to NXT."""
+ # Insert command and length.
+ assert len (data) <= self.pack_size
+ return struct.pack ('BBB', self.debug_command, 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) == 0:
+ return '', 0 # No message, exit
+ if len (data) < 3:
+ return '', NXT_RECV_ERR
+ header, body = data[0:3], data[3:]
+ command, segment_no, length = struct.unpack ('BBB', header)
+ if command != self.debug_command or length != len (body):
+ return '', NXT_RECV_ERR
+ return body, segment_no
+
+ def segment (self, data):
+ """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:
+ msg, self.in_buf = self.in_buf[0:end + 3], self.in_buf[end + 3:]
+ gdbprefix = msg[0]
+ if gdbprefix in ['+', '-']:
+ gdbprefix = msg[1]
+ assert gdbprefix == '$', "not a GDB command"
+ # Make segments.
+ seg_no = 0
+ while msg:
+ seg, msg = msg[0:self.pack_size], msg[self.pack_size:]
+ seg_no += 1
+ if not msg: # Last segment.
+ seg_no = 0
+ segs.append (self.pack (seg, seg_no))
+ # Look for next one.
+ end = self.in_buf.find ('#')
+ return segs
+
+ def reassemble (self, sock):
+ msg = ''
+ prev_segno = 0
+ segno = NXT_RECV_ERR # force initial pass through while loop
+ while segno != 0:
+ try:
+ s, segno = self.unpack (sock.recv ())
+ if len (s) == 0:
+ if segno == 0 and prev_segno == 0:
+ return '' # No message pending
+ else:
+ segno = NXT_RECV_ERR # Keep waiting for segments
+ # Ignore error packets
+ if segno >= 0:
+ # Check segno, if non-zero it must be monotonically increasing from 1, otherwise 0
+ if segno > 0:
+ assert segno == prev_segno + 1, "segno = %s, prev_segno = %s" % (segno, prev_segno)
+ prev_segno = segno
+ msg += s
+ except usb.USBError as e:
+ # Some pyusb are buggy, ignore some "errors".
+ if e.args != ('No error', ):
+ raise e
+ return msg
+
+ def run (self):
+ """Endless run loop."""
+ # Create the listening socket.
+ s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
+ s.setsockopt (socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+ s.bind (('', self.port))
+ s.listen (1)
+ # Open connection to the NXT brick.
+ brick = nxt.locator.find_one_brick ()
+ brick.sock.debug = DEBUG
+ print "Waiting for GDB connection on port %s..." % self.port
+ while True:
+ # Wait for a connection.
+ client, addr = s.accept ()
+ print "Client from", addr
+ # Work loop, wait for a message from client socket or NXT brick.
+ while client is not None:
+ data = ''
+ # Wait for a message from client or timeout.
+ rlist, wlist, xlist = select.select ([ client ], [ ], [ ],
+ SELECT_TIMEOUT)
+ for c in rlist:
+ assert c is client
+ # Data from client, read it and forward it to NXT brick.
+ 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)
+ data = ''
+ for s in segments:
+ try:
+ brick.sock.send (s)
+ except usb.USBError as e:
+ # Some pyusb are buggy, ignore some "errors".
+ if e.args != ('No error', ):
+ raise e
+ if segments != [] and LIBUSB_RECEIVE_BLOCKING:
+ if DEBUG2:
+ print "Accessing Blocking sock.recv()"
+ data = self.reassemble (brick.sock)
+ else:
+ client.close ()
+ client = None
+ if not LIBUSB_RECEIVE_BLOCKING:
+ if DEBUG2:
+ print "Accessing Non-Blocking sock.recv()"
+ data = self.reassemble (brick.sock)
+
+ # Is there something from NXT brick?
+ if data:
+ if DEBUG:
+ print "[NXT->GDB] %s" % data
+ if client:
+ client.send (data)
+ data = ''
+ print "Connection closed, waiting for GDB connection on port %s..." % self.port
+
+if __name__ == '__main__':
+ # Read options from command line.
+ parser = optparse.OptionParser (description = """
+ Gateway between the GNU debugger and a NXT brick.
+ """)
+ parser.add_option ('-p', '--port', type = 'int', default = DEFAULT_PORT,
+ help = "server listening port (default: %default)", metavar = "PORT")
+ (options, args) = parser.parse_args ()
+ if args:
+ parser.error ("Too many arguments")
+ # Run.
+ s = NXTGDBServer (options.port)
+ s.run ()
diff --git a/AT91SAM7S256/armdebug/LEGO_Open_Source_License.doc b/AT91SAM7S256/armdebug/LEGO_Open_Source_License.doc
new file mode 100644
index 0000000..94b65e6
--- /dev/null
+++ b/AT91SAM7S256/armdebug/LEGO_Open_Source_License.doc
Binary files differ
diff --git a/AT91SAM7S256/armdebug/README b/AT91SAM7S256/armdebug/README
new file mode 100644
index 0000000..0e5ca38
--- /dev/null
+++ b/AT91SAM7S256/armdebug/README
@@ -0,0 +1,22 @@
+Introduction
+============
+armdebug is an ARM Assembly Language Instruction debugger for the NXT.
+It is intended for embedding in the NXT firmware (e.g. NXT Improved Firmware),
+as well as for use with NxOS.
+
+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
+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
+========
+The armdebug code is dual-licensed. Please see COPYING for more details.
+Other projects included in this repository have their respective licenses.
diff --git a/AT91SAM7S256/armdebug/SConscript b/AT91SAM7S256/armdebug/SConscript
new file mode 100644
index 0000000..c495847
--- /dev/null
+++ b/AT91SAM7S256/armdebug/SConscript
@@ -0,0 +1,13 @@
+# This scons build script is used by NxOS
+
+from glob import glob
+
+Import('env')
+
+
+for source in glob('Debugger/*.[cS]'):
+ obj = env.Object(source.split('.')[0], source)
+ env.Append(NXOS_DEBUG=obj)
+
+if env['WITH_DOXYGEN']:
+ env.Doxygen('Doxyfile')
diff --git a/AT91SAM7S256/armdebug/SConstruct b/AT91SAM7S256/armdebug/SConstruct
new file mode 100644
index 0000000..fa88d7a
--- /dev/null
+++ b/AT91SAM7S256/armdebug/SConstruct
@@ -0,0 +1,182 @@
+# -*- mode: python -*-
+###############################################################
+# This scons build script is used to check the armdebug project
+# code for syntax errors. It does not build working executable
+# code since it links to external routines.
+###############################################################
+
+import os
+import os.path
+import new
+from glob import glob
+
+###############################################################
+# Utility functions.
+###############################################################
+
+# Similar to env.WhereIs, but always searches os.environ.
+def find_on_path(filename):
+ paths = os.environ.get('PATH')
+ if not paths:
+ return None
+ for p in paths.split(':'):
+ path = os.path.abspath(os.path.join(p, filename))
+ if os.path.isfile(path):
+ return p
+ return None
+
+# Run the given gcc binary, and parses its output to work out the gcc
+# version.
+def determine_gcc_version(gcc_binary):
+ stdout = os.popen('%s --version' % gcc_binary)
+ gcc_output = stdout.read().split()
+ stdout.close()
+ grab_next = False
+ for token in gcc_output:
+ if grab_next:
+ return token
+ elif token[-1] == ')':
+ grab_next = True
+ return None
+
+# Check that a given cross-compiler tool exists. If it does, the path is
+# added to the build environment, and the given environment variable is
+# set to the tool name.
+#
+# This is used to check for the presence of a working cross-compiler
+# toolchain, and to properly set up the environment to do it. See below
+# in the configuration section for details.
+def CheckTool(context, envname, toolname=None, hostprefix=None):
+ toolname = toolname or envname.lower()
+ if hostprefix is None:
+ hostprefix = '%s-' % context.env['CROSS_COMPILE_HOST']
+ toolname = '%s%s' % (hostprefix, toolname)
+ context.Message("Checking for %s..." % toolname)
+ toolpath = find_on_path(toolname)
+ if not toolpath:
+ context.Result('not found')
+ return False
+ else:
+ context.Result('ok')
+ context.env[envname] = toolname
+ context.env.AppendENVPath('PATH', toolpath)
+ return True
+
+# Find the correct variant and version of libgcc.a in the cross-compiler
+# toolchain.
+def CheckLibGcc(context, gccname):
+ context.Message("Locating a cross-compiled libgcc...")
+ toolpath = find_on_path(gccname)
+ if not toolpath:
+ context.Result("%s not found" % toolname)
+ return False
+ gcc_version = determine_gcc_version(gccname)
+ if not gcc_version:
+ context.Result("Could not determine gcc version")
+ return False
+ gcc_install_dir = os.path.split(os.path.normpath(toolpath))[0]
+ for libdir in ['interwork', 'thumb', '']:
+ libgcc_path = os.path.join(gcc_install_dir, 'lib', 'gcc',
+ context.env['CROSS_COMPILE_HOST'],
+ gcc_version, libdir, 'libgcc.a')
+ if os.path.isfile(libgcc_path):
+ break
+ if not os.path.isfile(libgcc_path):
+ context.Result("libgcc.a not found")
+ return False
+ context.Result("ok - " + libgcc_path)
+ context.env.Append(LIBGCC=libgcc_path)
+ return True
+
+def CheckDoxygen(context):
+ context.Message("Looking for Doxygen...")
+ doxypath = find_on_path('doxygen')
+ if doxypath:
+ context.Result("ok")
+ context.env.AppendENVPath('PATH', doxypath)
+ context.env['WITH_DOXYGEN'] = True
+ else:
+ context.Result("not found")
+ context.env['WITH_DOXYGEN'] = False
+
+
+
+###############################################################
+# Options that can be provided on the commandline
+###############################################################
+
+opts = Variables('scons.options', ARGUMENTS)
+
+opts.Add(PathVariable('gccprefix',
+ 'Prefix of the cross-gcc to use (by default arm-none-eabi)',
+ 'arm-none-eabi', PathVariable.PathAccept))
+
+Help('''
+Type: 'scons' to build object files.
+
+ - To use another cross-gcc than arm-none-eabi-gcc:
+ scons gccprefix=arm-softfloat-eabi
+
+Options are saved persistent in the file 'scons.options'. That means
+after you have called e.g. 'scons gccprefix=arm-softfloat-eabi' it's enough
+to call only 'scons' to build both using the new gcc version again.
+''')
+
+###############################################################
+# Construct and configure a cross-compiler environment
+###############################################################
+env = Environment(options = opts,
+ tools = ['gcc', 'as', 'gnulink', 'ar'],
+ toolpath = ['scons_tools'],
+ LIBGCC = [], CPPPATH = '#',
+ WITH_DOXYGEN = False)
+opts.Update(env)
+opts.Save('scons.options', env)
+
+if not env.GetOption('clean'):
+ conf = Configure(env, custom_tests = {'CheckTool': CheckTool,
+ 'CheckLibGcc': CheckLibGcc,
+ 'CheckDoxygen': CheckDoxygen})
+ conf.env['CROSS_COMPILE_HOST'] = env['gccprefix']
+ if not (conf.CheckTool('CC', 'gcc') and conf.CheckTool('AR') and
+ conf.CheckTool('OBJCOPY') and conf.CheckTool('LINK', 'ld') and
+ conf.CheckLibGcc(conf.env['CC'])):
+ print "Missing or incomplete arm-elf toolchain, cannot continue!"
+ Exit(1)
+ env = conf.Finish()
+
+mycflags = ['-mcpu=arm7tdmi', '-Os', '-Wextra', '-Wall', '-Werror',
+ '-Wno-div-by-zero', '-Wfloat-equal', '-Wshadow',
+ '-Wpointer-arith', '-Wbad-function-cast',
+ '-Wmissing-prototypes', '-ffreestanding',
+ '-fsigned-char', '-ffunction-sections', '-std=gnu99',
+ '-fdata-sections', '-fomit-frame-pointer', '-msoft-float']
+myasflags = ['-Wall', '-Werror', '-Os'];
+if str(env['LIBGCC']).find('interwork') != -1:
+ mycflags.append('-mthumb-interwork')
+ myasflags.append('-Wa,-mcpu=arm7tdmi,-mfpu=softfpa,-mthumb-interwork')
+elif str(env['LIBGCC']).find('thumb') != -1:
+ mycflags.append('-mthumb')
+ myasflags.append('-Wa,-mcpu=arm7tdmi,-mfpu=softfpa,-mthumb')
+else:
+ myasflags.append('-Wa,-mcpu=arm7tdmi,-mfpu=softfpa')
+mycflags.append('-g')
+mycflags.append('-ggdb')
+# Big Endian Output (disabled by default)
+#mycflags.append('-D__BIG_ENDIAN__')
+# Test build for NxOS (Comment out for NXT Firmware)
+mycflags.append('-D__NXOS__')
+
+myasflags.append('-g')
+myasflags.append('-ggdb')
+# Big Endian Output (disabled by default)
+#mycflags.append('-D__BIG_ENDIAN__')
+# Test build for NxOS (Comment out for NXT Firmware)
+myasflags.append('-D__NXOS__')
+
+env.Replace(CCFLAGS = mycflags, ASFLAGS = myasflags )
+
+# Build the baseplate, and all selected application kernels.
+
+numProcs = os.sysconf('SC_NPROCESSORS_ONLN')
+SConscript(['SConscript'], 'numProcs env CheckTool')
diff --git a/AT91SAM7S256/armdebug/nxt-python-2.1.0.tar.gz b/AT91SAM7S256/armdebug/nxt-python-2.1.0.tar.gz
new file mode 100644
index 0000000..014132b
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-2.1.0.tar.gz
Binary files differ
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/.project b/AT91SAM7S256/armdebug/nxt-python-fantom/.project
new file mode 100644
index 0000000..1b06536
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/.project
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>nxt-python-fantom</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ </buildSpec>
+ <natures>
+ </natures>
+</projectDescription>
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/LICENSE b/AT91SAM7S256/armdebug/nxt-python-fantom/LICENSE
new file mode 100644
index 0000000..818433e
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/LICENSE
@@ -0,0 +1,674 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ <program> Copyright (C) <year> <name of author>
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/MANIFEST.in b/AT91SAM7S256/armdebug/nxt-python-fantom/MANIFEST.in
new file mode 100644
index 0000000..9dd36e1
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/MANIFEST.in
@@ -0,0 +1,4 @@
+include docs/*.html *.url *.css *.txt
+include README LICENSE install.bat MANIFEST.in
+include examples/*.py
+exclude arduino/*
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/PKG-INFO b/AT91SAM7S256/armdebug/nxt-python-fantom/PKG-INFO
new file mode 100644
index 0000000..1e0e361
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/PKG-INFO
@@ -0,0 +1,168 @@
+Metadata-Version: 1.0
+Name: nxt-python
+Version: 2.1.0
+Summary: LEGO Mindstorms NXT Control Package
+Home-page: http://code.google.com/p/nxt-python/
+Author: Marcus Wanner
+Author-email: marcusw@cox.net
+License: Gnu GPL v3
+Description: NXT-Python is a package for controlling a LEGO NXT robot using the Python
+ programming language. It can communicate using either USB or Bluetooth. It is
+ available under the Gnu GPL license. It is based on NXT_Python, where releases
+ halted in May 2007.
+
+ Requirements:
+
+ * Python 2.6 (http://www.python.org)
+ And at least one comm library:
+ * Bluetooth communications:
+ Linux/Windows: PyBluez (http://code.google.com/p/pybluez/)
+ (package python-bluez in deb-based linuxes)
+ Mac: LightBlue (http://lightblue.sourceforge.net/)
+ * USB communications:
+ PyUSB (http://sourceforge.net/projects/pyusb/)
+
+ Installation (if using source package):
+
+ * Untar/unzip source package
+ * In package directory, run "python setup.py install" (as root), or if
+ under windows, double-click install.bat.
+ * To use USB on Linux as non-superuser, at a root terminal type:
+ groupadd lego
+ usermod -a -G lego [username]
+ echo 'BUS=="usb", SYSFS{idVendor}=="0694", GROUP="lego", MODE="0660"' \
+ > /etc/udev/rules.d/70-lego.rules
+
+ Getting Started:
+
+ Take a look at the examples directory. Feel free to copy that code into your
+ scripts and don't be afraid to experiment! If you are having trouble with
+ something, you may find the solution in the docstrings (for example,
+ help('nxt.sensor.Ultrasonic')) or even in the source code (especially for
+ digital sensors).
+
+ Notes/FAQ:
+ (I have tried to put the most important stuff first, but it would be a good
+ idea to read the whole section. In any case, read it all the way through
+ before asking for help. Thanks!)
+
+ -=-=-About v2-=-=-
+ This version is part of the 2.x series of releases. Programs designed for
+ NXT_Python or for the 1.x series of nxt-python will not work with this version.
+ If you are trying to get an old program to work, it most likely needs a 1.x
+ series release, which can be downloaded from the nxt-python downloads page at
+ googlecode. New projects should use a 2.x series release (hint: this is one!)
+ due to the new features and API improvements. Converting old projects is
+ somewhat difficult and not officially supported, though as always you're
+ welcome to ask for help.
+ -=-=-Problems and Their Solutions-=-=-
+ Support for a number of sensors has not been tested at all, due to lack of
+ hardware. I have started a project to test this code, but the going is slow
+ and I have decided to go ahead and release rather than waiting several more
+ months. If you have a problem with a digital sensor, see the troubleshooting
+ guide below and don't forget to report your trouble!
+ The Synchronized Motor support has not been extensively tested for accuracy.
+ It seems to mostly work well but the accuracy of the braking function and the
+ closeness of the two motors to each other have not been assesed.
+ NXT-Python has not been tested and may not work with custom nxt firmware
+ versions (if you don't know what that means, you don't need to worry about it).
+ However, if the firmware uses the standard USB/BT communications protocol,
+ everything should more or less work. NXT-Python has been tested with bricks
+ using LEGO firmware version up to 1.29 and is compatible with protocol version
+ 1.124 (used by most if not all of the official firmwares). It has also been
+ reported working with LeJOS.
+ -=-=-If you co'd the SVN...-=-=-
+ The Arduino directory of an svn checkout (not included with release
+ packages) contains a digital sensor unit test system called nxtduemu. It is
+ intended for developers and advanced users who are looking to experiment with
+ sensors and the digital sensor framework and classes. See Arduino/README for
+ more info and usage instructions.
+
+ Specific Stability Status:
+ nxt.brick, nxt.telegram, nxt.direct, and nxt.system:
+ Hardly changed since NXT_Python; very, very stable.
+ USB Communication System (nxt.usbsock)
+ On Linux: Very stable and extensively tested.
+ On Windows: Somewhat tested; seems to work pretty well.
+ On Mac: Should be working, though I have not heard either way.
+ BlueTooth Communication System (nxt.bluesock, nxt.lightblueglue)
+ On Linux: Stable; well tested.
+ On Windows: Stable; working last I checked.
+ On Mac: Reported working.
+ nxt.locator:
+ Stable, somewhat tested. One developer reported problems.
+ nxt.motor:
+ Stable except for Synchronized Motor support, which is experimental at
+ this stage and has not been extensively tested.
+ nxt.sensor:
+ Code not specific to a particular sensor is well tested and working
+ great. More than half of the sensor classes were last reported working;
+ the rest have not to my knowlege been tested and were written blindly
+ from the manuacturers' specifications.
+ nxt.error:
+ If there's a problem with this one, I'm gonna cry.
+
+ Contact:
+
+ NXT-Python's Head Developer:
+ Marcus Wanner (marcusw@cox.net)
+ The support and development mailing list:
+ http://groups.google.com/group/nxt-python
+ Report bugs and suggest new features at:
+ http://code.google.com/p/nxt-python/issues/list
+
+ Thanks to:
+
+ Doug Lau for writing NXT_Python, our starting point.
+ rhn for creating what would become v2, making lots of smaller changes, and
+ reviewing tons of code.
+ mindsensors.com (esp. Ryan Kneip) for helping out with the code for a lot of
+ their sensors and expanding the sensors covered by the type checking
+ database.
+ HiTechnic for providing identification information for their sensors. I note
+ that they have now included this information in their website. ;)
+ Linus Atorf, Samuel Leeman-Munk, melducky, Simon Levy, Steve Castellotti,
+ Paulo Vieira, zonedabone, migpics, and anyone else I forgot for various
+ fixes and additions.
+ All our users for their interest and support!
+
+
+
+ Troubleshooting Digital Sensors (don't read unless you have problems):
+ If you are getting errors, strange behavor, or incorrect values from a digital
+ sensor, chances are that there is a bug in our code. Follow these instructions
+ to try and find out what's wrong:
+ 1. Test the sensor with a different access library to make sure it's working
+ right.
+ 2. Check your code again. There are some weird "features" in the interfaces
+ of some of the sensors; make sure you are doing things right.
+ 3. Locate the sensor class's source code in nxt-python. It should be
+ somewhere in nxt/sensor/<manufacturer>.py, under the heading "class SensorName(
+ BaseDigitalSensor):". Read any comments for instructions on certain things.
+
+ If you get to here and are still having a problem, you can either go ahead and
+ report it now or continue to try and find and fix the problem and then report
+ it (or not report it at all, but that wouldn't be very nice...).
+ Python experience required beyond this point.
+
+ 4. Get the sensor's specifications from the manufacturer's website. Make
+ sure it includes a table of I2C registers and instructions for using them.
+ 5. Pick one of the following depending on what the problem is:
+ ####Errors:
+ Cause: We screwed up.
+ Solution: Check the line mentioned in the error for incorrect syntax or
+ other problem. A bit of python experience and maybe some googling is needed
+ here.
+ ####Strange Behavior (in sensors with modes/commands):
+ Cause: nxt-python's command enumerations are incorrect.
+ Solution: Verify them using the sensor's specs, and correct any problems.
+ See "Incorrect Values" for more.
+ ####Incorrect Values:
+ Cause: nxt-python is processing the value wrong.
+ Solution: Check what goes on in the sampling method against what the spec
+ says should be done. If there is an inconsistency, try to fix it.
+ Cause: nxt-python has an incorrect register number or type in I2C_ADDRESS.
+ Solution: Verify the address (the number) and the string (the struct format
+ string). To verify the address, use the spec. To verify the struct format, you
+ wil
+Platform: UNKNOWN
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/README b/AT91SAM7S256/armdebug/nxt-python-fantom/README
new file mode 100644
index 0000000..5d9a214
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/README
@@ -0,0 +1,169 @@
+NXT-Python is a package for controlling a LEGO NXT robot using the Python
+programming language. It can communicate using either USB or Bluetooth. It is
+available under the Gnu GPL license. It is based on NXT_Python, where releases
+halted in May 2007.
+
+Requirements:
+
+ * Python 2.6 (http://www.python.org)
+ And at least one comm library:
+ * Bluetooth communications:
+ Linux/Windows: PyBluez (http://code.google.com/p/pybluez/)
+ (package python-bluez in deb-based linuxes)
+ Mac: LightBlue (http://lightblue.sourceforge.net/)
+ * USB communications:
+ PyUSB (http://sourceforge.net/projects/pyusb/)
+
+Installation (if using source package):
+
+ * Untar/unzip source package
+ * In package directory, run "python setup.py install" (as root), or if
+ under windows, double-click install.bat.
+ * To use USB on Linux as non-superuser, at a root terminal type:
+ groupadd lego
+ usermod -a -G lego [username]
+ echo 'BUS=="usb", SYSFS{idVendor}=="0694", GROUP="lego", MODE="0660"' \
+ > /etc/udev/rules.d/70-lego.rules
+
+Getting Started:
+
+ Take a look at the examples directory. Feel free to copy that code into your
+scripts and don't be afraid to experiment! If you are having trouble with
+something, you may find the solution in the docstrings (for example,
+help('nxt.sensor.Ultrasonic')) or even in the source code (especially for
+digital sensors).
+
+Notes/FAQ:
+ (I have tried to put the most important stuff first, but it would be a good
+ idea to read the whole section. In any case, read it all the way through
+ before asking for help. Thanks!)
+
+ -=-=-About v2-=-=-
+ This version is part of the 2.x series of releases. Programs designed for
+NXT_Python or for the 1.x series of nxt-python will not work with this version.
+If you are trying to get an old program to work, it most likely needs a 1.x
+series release, which can be downloaded from the nxt-python downloads page at
+googlecode. New projects should use a 2.x series release (hint: this is one!)
+due to the new features and API improvements. Converting old projects is
+somewhat difficult and not officially supported, though as always you're
+welcome to ask for help.
+ -=-=-Problems and Their Solutions-=-=-
+ Support for a number of sensors has not been tested at all, due to lack of
+hardware. I have started a project to test this code, but the going is slow
+and I have decided to go ahead and release rather than waiting several more
+months. If you have a problem with a digital sensor, see the troubleshooting
+guide below and don't forget to report your trouble!
+ The Synchronized Motor support has not been extensively tested for accuracy.
+It seems to mostly work well but the accuracy of the braking function and the
+closeness of the two motors to each other have not been assesed.
+ NXT-Python has not been tested and may not work with custom nxt firmware
+versions (if you don't know what that means, you don't need to worry about it).
+However, if the firmware uses the standard USB/BT communications protocol,
+everything should more or less work. NXT-Python has been tested with bricks
+using LEGO firmware version up to 1.29 and is compatible with protocol version
+1.124 (used by most if not all of the official firmwares). It has also been
+reported working with LeJOS.
+ -=-=-If you co'd the SVN...-=-=-
+ The Arduino directory of an svn checkout (not included with release
+packages) contains a digital sensor unit test system called nxtduemu. It is
+intended for developers and advanced users who are looking to experiment with
+sensors and the digital sensor framework and classes. See Arduino/README for
+more info and usage instructions.
+
+Specific Stability Status:
+ nxt.brick, nxt.telegram, nxt.direct, and nxt.system:
+ Hardly changed since NXT_Python; very, very stable.
+ USB Communication System (nxt.usbsock)
+ On Linux: Very stable and extensively tested.
+ On Windows: Somewhat tested; seems to work pretty well.
+ On Mac: Should be working, though I have not heard either way.
+ BlueTooth Communication System (nxt.bluesock, nxt.lightblueglue)
+ On Linux: Stable; well tested.
+ On Windows: Stable; working last I checked.
+ On Mac: Reported working.
+ nxt.locator:
+ Stable, somewhat tested. One developer reported problems.
+ nxt.motor:
+ Stable except for Synchronized Motor support, which is experimental at
+ this stage and has not been extensively tested.
+ nxt.sensor:
+ Code not specific to a particular sensor is well tested and working
+ great. More than half of the sensor classes were last reported working;
+ the rest have not to my knowlege been tested and were written blindly
+ from the manuacturers' specifications.
+ nxt.error:
+ If there's a problem with this one, I'm gonna cry.
+
+Contact:
+
+ NXT-Python's Head Developer:
+ Marcus Wanner (marcusw@cox.net)
+ The support and development mailing list:
+ http://groups.google.com/group/nxt-python
+ Report bugs and suggest new features at:
+ http://code.google.com/p/nxt-python/issues/list
+
+Thanks to:
+
+ Doug Lau for writing NXT_Python, our starting point.
+ rhn for creating what would become v2, making lots of smaller changes, and
+ reviewing tons of code.
+ mindsensors.com (esp. Ryan Kneip) for helping out with the code for a lot of
+ their sensors and expanding the sensors covered by the type checking
+ database.
+ HiTechnic for providing identification information for their sensors. I note
+ that they have now included this information in their website. ;)
+ Linus Atorf, Samuel Leeman-Munk, melducky, Simon Levy, Steve Castellotti,
+ Paulo Vieira, zonedabone, migpics, and anyone else I forgot for various
+ fixes and additions.
+ All our users for their interest and support!
+
+
+
+Troubleshooting Digital Sensors (don't read unless you have problems):
+If you are getting errors, strange behavor, or incorrect values from a digital
+sensor, chances are that there is a bug in our code. Follow these instructions
+to try and find out what's wrong:
+ 1. Test the sensor with a different access library to make sure it's working
+right.
+ 2. Check your code again. There are some weird "features" in the interfaces
+of some of the sensors; make sure you are doing things right.
+ 3. Locate the sensor class's source code in nxt-python. It should be
+somewhere in nxt/sensor/<manufacturer>.py, under the heading "class SensorName(
+BaseDigitalSensor):". Read any comments for instructions on certain things.
+
+If you get to here and are still having a problem, you can either go ahead and
+report it now or continue to try and find and fix the problem and then report
+it (or not report it at all, but that wouldn't be very nice...).
+Python experience required beyond this point.
+
+ 4. Get the sensor's specifications from the manufacturer's website. Make
+sure it includes a table of I2C registers and instructions for using them.
+ 5. Pick one of the following depending on what the problem is:
+####Errors:
+ Cause: We screwed up.
+ Solution: Check the line mentioned in the error for incorrect syntax or
+other problem. A bit of python experience and maybe some googling is needed
+here.
+####Strange Behavior (in sensors with modes/commands):
+ Cause: nxt-python's command enumerations are incorrect.
+ Solution: Verify them using the sensor's specs, and correct any problems.
+ See "Incorrect Values" for more.
+####Incorrect Values:
+ Cause: nxt-python is processing the value wrong.
+ Solution: Check what goes on in the sampling method against what the spec
+says should be done. If there is an inconsistency, try to fix it.
+ Cause: nxt-python has an incorrect register number or type in I2C_ADDRESS.
+ Solution: Verify the address (the number) and the string (the struct format
+string). To verify the address, use the spec. To verify the struct format, you
+will need to read this: <http://docs.python.org/library/struct.html#format-
+strings> or have experience with struct.
+Read the spec for the sensor to determine how the given value should be read,
+then start at the sample method and read through it, checking for problems as
+you go. If it seems right, go back to the I2C_ADDRESS chunk (near the top of the
+class) and make sure that the correct struct format string is being used. The
+most common problem here is values that are off by plus or minus 128 or 32768
+because of an incorrect signed/unsigned setting. This can be fixed by switching
+the case (as in upper or lower) of the letter in the string. Other problems
+could include the wrong size (B, H, or L) being used, or, in the two latter
+ones, the wrong byte order (< or >). As always, common sense required.
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/examples/alpharex.py b/AT91SAM7S256/armdebug/nxt-python-fantom/examples/alpharex.py
new file mode 100644
index 0000000..13c5979
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/examples/alpharex.py
@@ -0,0 +1,151 @@
+r'''Alpha Rex API
+
+ A high-level, object-oriented programming interface to Lego MINDSTORMS
+ NXT's "Alpha Rex" model (see [1] for assembling instructions), along with a
+ small collection of functions demonstrating obvious usage scenarios.
+
+ 1. http://www.active-robots.com/products/mindstorms4schools/building-instructions.shtml
+'''
+
+from time import sleep
+
+from nxt.brick import Brick
+from nxt.locator import find_one_brick
+from nxt.motor import Motor, PORT_A, PORT_B, PORT_C
+from nxt.sensor import Light, Sound, Touch, Ultrasonic
+from nxt.sensor import PORT_1, PORT_2, PORT_3, PORT_4
+
+
+FORTH = 100
+BACK = -100
+
+
+class AlphaRex(object):
+ r'''A high-level controller for the Alpha Rex model.
+
+ This class implements methods for the most obvious actions performable
+ by Alpha Rex, such as walk, wave its arms, and retrieve sensor samples.
+ Additionally, it also allows direct access to the robot's components
+ through public attributes.
+ '''
+ def __init__(self, brick='NXT'):
+ r'''Creates a new Alpha Rex controller.
+
+ brick
+ Either an nxt.brick.Brick object, or an NXT brick's name as a
+ string. If omitted, a Brick named 'NXT' is looked up.
+ '''
+ if isinstance(brick, basestring):
+ brick = find_one_brick(name=brick)
+
+ self.brick = brick
+ self.arms = Motor(brick, PORT_A)
+ self.legs = [Motor(brick, PORT_B), Motor(brick, PORT_C)]
+
+ self.touch = Touch(brick, PORT_1)
+ self.sound = Sound(brick, PORT_2)
+ self.light = Light(brick, PORT_3)
+ self.ultrasonic = Ultrasonic(brick, PORT_4)
+
+ def echolocate(self):
+ r'''Reads the Ultrasonic sensor's output.
+ '''
+ return self.ultrasonic.get_sample()
+
+ def feel(self):
+ r'''Reads the Touch sensor's output.
+ '''
+ return self.touch.get_sample()
+
+ def hear(self):
+ r'''Reads the Sound sensor's output.
+ '''
+ return self.sound.get_sample()
+
+ def say(self, line, times=1):
+ r'''Plays a sound file named (line + '.rso'), which is expected to be
+ stored in the brick. The file is played (times) times.
+
+ line
+ The name of a sound file stored in the brick.
+
+ times
+ How many times the sound file will be played before this method
+ returns.
+ '''
+ for i in range(0, times):
+ self.brick.play_sound_file(False, line + '.rso')
+ sleep(1)
+
+ def see(self):
+ r'''Reads the Light sensor's output.
+ '''
+ return self.light.get_sample()
+
+ def walk(self, secs, power=FORTH):
+ r'''Simultaneously activates the leg motors, causing Alpha Rex to walk.
+
+ secs
+ How long the motors will rotate.
+
+ power
+ The strength effected by the motors. Positive values will cause
+ Alpha Rex to walk forward, while negative values will cause it
+ to walk backwards. If you are unsure about how much force to
+ apply, the special values FORTH and BACK provide reasonable
+ defaults. If omitted, FORTH is used.
+ '''
+ for motor in self.legs:
+ motor.run(power=power)
+
+ sleep(secs)
+
+ for motor in self.legs:
+ motor.idle()
+
+ def wave(self, secs, power=100):
+ r'''Make Alpha Rex move its arms.
+
+ secs
+ How long the arms' motor will rotate.
+
+ power
+ The strength effected by the motor. If omitted, (100) is used.
+ '''
+ self.arms.run(power=power)
+ sleep(secs)
+ self.arms.idle()
+
+
+def wave_and_talk():
+ r'''Connects to a nearby Alpha Rex, then commands it to wave its arms and
+ play the sound file 'Object.rso'.
+ '''
+ robot = AlphaRex()
+ robot.wave(1)
+ robot.say('Object')
+
+
+def walk_forth_and_back():
+ r'''Connects to a nearby Alpha Rex, then commands it to walk forward and
+ then backwards.
+ '''
+ robot = AlphaRex()
+ robot.walk(10, FORTH)
+ robot.walk(10, BACK)
+
+
+def walk_to_object():
+ r'''Connects to a nearby Alpha Rex, then commands it to walk until it
+ approaches an obstacle, then stop and say 'Object' three times.
+ '''
+ robot = AlphaRex()
+ while robot.echolocate() > 10:
+ robot.walk(1, FORTH)
+
+ robot.say('Object', 3)
+
+
+if __name__ == '__main__':
+ walk_to_object()
+
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/examples/cnc.py b/AT91SAM7S256/armdebug/nxt-python-fantom/examples/cnc.py
new file mode 100644
index 0000000..456cf92
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/examples/cnc.py
@@ -0,0 +1,53 @@
+#Script to control a NXT 2-axis CNC "Pancake maker"
+#Illustrates controlling more than one motor at the same time without trying to
+#sync them. Uses the thread module.
+#Written 2/3/11 by Marcus Wanner
+#
+#For more info and warnings see:
+#http://groups.google.com/group/nxt-python/browse_thread/thread/f6ef0865ae768ef
+
+import nxt, thread, time
+b = nxt.find_one_brick(name = 'MyNXT')
+mx = nxt.Motor(b, nxt.PORT_A)
+my = nxt.Motor(b, nxt.PORT_B)
+motors = [mx, my]
+
+def turnmotor(m, power, degrees):
+ m.turn(power, degrees)
+
+#here are the instructions...
+#the first value is the time to start the instruction
+#the second is the axis (0 for x, 1 for y)
+#the third is the power
+#the fourth is the degrees
+#it's probably not a good idea to run simultaneous turn
+#functions on a single motor, so be careful with this
+instructions = (
+ [0, 0, 80, 180],
+ [0, 1, -40, 1080],
+ [1, 0, -80, 180],
+ [2, 0, 80, 180],
+ [3, 1, 100, 360],
+ [3, 0, -100, 360],
+)
+#how long from start until the last instruction is ended
+length = 5
+
+def runinstruction(i):
+ motorid, speed, degrees = i
+ #THIS IS THE IMPORTANT PART!
+ thread.start_new_thread(
+ turnmotor,
+ (motors[motorid], speed, degrees))
+
+#main loop
+seconds = 0
+while 1:
+ print "Tick %d" % seconds
+ for i in instructions:
+ if i[0] == seconds:
+ runinstruction(i[1:])
+ seconds = seconds + 1
+ if seconds >= length:
+ break
+ time.sleep(1)
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/examples/latency.py b/AT91SAM7S256/armdebug/nxt-python-fantom/examples/latency.py
new file mode 100644
index 0000000..b4b1f26
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/examples/latency.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+
+import time
+import nxt.locator
+from nxt.sensor import *
+
+b = nxt.locator.find_one_brick()
+
+#Touch sensor latency test
+touch = Touch(b, PORT_1)
+start = time.time()
+for i in range(100):
+ touch.get_sample()
+stop = time.time()
+print 'touch latency: %s ms' % (1000 * (stop - start) / 100.0)
+
+#Ultrasonic sensor latency test
+ultrasonic = Ultrasonic(b, PORT_4)
+start = time.time()
+for i in range(100):
+ ultrasonic.get_sample()
+stop = time.time()
+print 'ultrasonic latency: %s ms' % (1000 * (stop - start) / 100.0)
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/examples/mary.py b/AT91SAM7S256/armdebug/nxt-python-fantom/examples/mary.py
new file mode 100644
index 0000000..907cc23
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/examples/mary.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+#
+# Converted from mary.rb found in ruby_nxt package
+# Plays "Mary Had A Little Lamb"
+# Author: Christopher Continanza <christopher.continanza@villanova.edu>
+
+from time import sleep
+import nxt.locator
+
+FREQ_C = 523
+FREQ_D = 587
+FREQ_E = 659
+FREQ_G = 784
+
+b = nxt.locator.find_one_brick()
+
+b.play_tone_and_wait(FREQ_E, 500)
+b.play_tone_and_wait(FREQ_D, 500)
+b.play_tone_and_wait(FREQ_C, 500)
+b.play_tone_and_wait(FREQ_D, 500)
+b.play_tone_and_wait(FREQ_E, 500)
+b.play_tone_and_wait(FREQ_E, 500)
+b.play_tone_and_wait(FREQ_E, 500)
+sleep(0.5)
+b.play_tone_and_wait(FREQ_D, 500)
+b.play_tone_and_wait(FREQ_D, 500)
+b.play_tone_and_wait(FREQ_D, 500)
+sleep(0.5)
+b.play_tone_and_wait(FREQ_E, 500)
+b.play_tone_and_wait(FREQ_G, 500)
+b.play_tone_and_wait(FREQ_G, 500)
+sleep(0.5)
+b.play_tone_and_wait(FREQ_E, 500)
+b.play_tone_and_wait(FREQ_D, 500)
+b.play_tone_and_wait(FREQ_C, 500)
+b.play_tone_and_wait(FREQ_D, 500)
+b.play_tone_and_wait(FREQ_E, 500)
+b.play_tone_and_wait(FREQ_E, 500)
+b.play_tone_and_wait(FREQ_E, 500)
+b.play_tone_and_wait(FREQ_E, 500)
+b.play_tone_and_wait(FREQ_D, 500)
+b.play_tone_and_wait(FREQ_D, 500)
+b.play_tone_and_wait(FREQ_E, 500)
+b.play_tone_and_wait(FREQ_D, 500)
+b.play_tone_and_wait(FREQ_C, 750)
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/examples/message_test.py b/AT91SAM7S256/armdebug/nxt-python-fantom/examples/message_test.py
new file mode 100644
index 0000000..c2fbda7
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/examples/message_test.py
@@ -0,0 +1,15 @@
+#!/usr/bin/env python
+
+#During this test you need to run any program on the brick
+#which doesn't use the messaging system. Most programs fit
+#this requirement.
+
+import nxt.locator
+
+b = nxt.locator.find_one_brick()
+for box in range(10):
+ b.message_write(box, 'message test %d' % box)
+for box in range(10):
+ local_box, message = b.message_read(box, box, True)
+ print local_box, message
+print 'Test succeeded!'
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/examples/spin.py b/AT91SAM7S256/armdebug/nxt-python-fantom/examples/spin.py
new file mode 100644
index 0000000..fc7cb2c
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/examples/spin.py
@@ -0,0 +1,14 @@
+#!/usr/bin/env python
+
+import nxt.locator
+from nxt.motor import *
+
+def spin_around(b):
+ m_left = Motor(b, PORT_B)
+ m_left.turn(100, 360)
+ m_right = Motor(b, PORT_C)
+ m_right.turn(-100, 360)
+
+b = nxt.locator.find_one_brick()
+spin_around(b)
+
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/examples/test_sensors.py b/AT91SAM7S256/armdebug/nxt-python-fantom/examples/test_sensors.py
new file mode 100644
index 0000000..4c8d249
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/examples/test_sensors.py
@@ -0,0 +1,11 @@
+#!/usr/bin/env python
+
+import nxt.locator
+from nxt.sensor import *
+
+b = nxt.locator.find_one_brick()
+
+print 'Touch:', Touch(b, PORT_1).get_sample()
+print 'Sound:', Sound(b, PORT_2).get_sample()
+print 'Light:', Light(b, PORT_3).get_sample()
+print 'Ultrasonic:', Ultrasonic(b, PORT_4).get_sample()
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/install.bat b/AT91SAM7S256/armdebug/nxt-python-fantom/install.bat
new file mode 100644
index 0000000..afa7bfc
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/install.bat
@@ -0,0 +1,11 @@
+@echo off
+@call setup.py install
+if errorlevel 1 goto error
+goto end
+:error
+echo -=-=-=-=-=-=-=-=-=-=-
+echo There was an error during the installation.
+echo Please check the above text for more information.
+pause
+:end
+@echo on
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/__init__.py b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/__init__.py
new file mode 100644
index 0000000..01be052
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/__init__.py
@@ -0,0 +1,17 @@
+# nxt.__init__ module -- LEGO Mindstorms NXT python package
+# Copyright (C) 2006 Douglas P Lau
+# Copyright (C) 2009 Marcus Wanner
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+from .locator import find_one_brick
+from .motor import *
+from .sensor import *
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/bluesock.py b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/bluesock.py
new file mode 100644
index 0000000..99917f2
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/bluesock.py
@@ -0,0 +1,82 @@
+# nxt.bluesock module -- Bluetooth socket communication with LEGO Minstorms NXT
+# Copyright (C) 2006, 2007 Douglas P Lau
+# Copyright (C) 2009 Marcus Wanner
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+try:
+ import fantomglue as bluetooth
+except ImportError:
+ try:
+ import bluetooth
+ except ImportError:
+ import lightblueglue as bluetooth
+
+import os
+from .brick import Brick
+
+class BlueSock(object):
+
+ bsize = 118 # Bluetooth socket block size
+ PORT = 1 # Standard NXT rfcomm port
+
+ def __init__(self, host):
+ self.host = host
+ self.sock = None
+ self.debug = False
+
+ def __str__(self):
+ return 'Bluetooth (%s)' % self.host
+
+ def connect(self):
+ if self.debug:
+ print 'Connecting via Bluetooth...'
+ sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
+ sock.connect((self.host, BlueSock.PORT))
+ self.sock = sock
+ if self.debug:
+ print 'Connected.'
+ return Brick(self)
+
+ def close(self):
+ if self.debug:
+ print 'Closing Bluetooth connection...'
+ self.sock.close()
+ if self.debug:
+ print 'Bluetooth connection closed.'
+
+ def send(self, data):
+ if self.debug:
+ print 'Send:',
+ print ':'.join('%02x' % ord(c) for c in data)
+ l0 = len(data) & 0xFF
+ l1 = (len(data) >> 8) & 0xFF
+ d = chr(l0) + chr(l1) + data
+ self.sock.send(d)
+
+ def recv(self):
+ data = self.sock.recv(2)
+ l0 = ord(data[0])
+ l1 = ord(data[1])
+ plen = l0 + (l1 << 8)
+ data = self.sock.recv(plen)
+ if self.debug:
+ print 'Recv:',
+ print ':'.join('%02x' % ord(c) for c in data)
+ return data
+
+def _check_brick(arg, value):
+ return arg is None or arg == value
+
+def find_bricks(host=None, name=None):
+ for h, n in bluetooth.discover_devices(lookup_names=True):
+ if _check_brick(host, h) and _check_brick(name, n):
+ yield BlueSock(h)
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/brick.py b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/brick.py
new file mode 100644
index 0000000..240ba27
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/brick.py
@@ -0,0 +1,226 @@
+# nxt.brick module -- Classes to represent LEGO Mindstorms NXT bricks
+# Copyright (C) 2006 Douglas P Lau
+# Copyright (C) 2009 Marcus Wanner, rhn
+# Copyright (C) 2010 rhn, Marcus Wanner, zonedabone
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+from time import sleep
+from threading import Lock
+from .error import FileNotFound, ModuleNotFound
+from .telegram import OPCODES, Telegram
+from .sensor import get_sensor
+
+def _make_poller(opcode, poll_func, parse_func):
+ def poll(self, *args, **kwargs):
+ ogram = poll_func(opcode, *args, **kwargs)
+ with self.lock:
+ self.sock.send(str(ogram))
+ igram = Telegram(opcode=opcode, pkt=self.sock.recv())
+ return parse_func(igram)
+ return poll
+
+class _Meta(type):
+ 'Metaclass which adds one method for each telegram opcode'
+
+ def __init__(cls, name, bases, dict):
+ super(_Meta, cls).__init__(name, bases, dict)
+ for opcode in OPCODES:
+ poll_func, parse_func = OPCODES[opcode]
+ m = _make_poller(opcode, poll_func, parse_func)
+ setattr(cls, poll_func.__name__, m)
+
+
+class FileFinder(object):
+ 'A generator to find files on a NXT brick.'
+
+ def __init__(self, brick, pattern):
+ self.brick = brick
+ self.pattern = pattern
+ self.handle = None
+
+ def _close(self):
+ if self.handle is not None:
+ self.brick.close(self.handle)
+ self.handle = None
+
+ def __del__(self):
+ self._close()
+
+ def __iter__(self):
+ results = []
+ self.handle, fname, size = self.brick.find_first(self.pattern)
+ results.append((fname, size))
+ while True:
+ try:
+ handle, fname, size = self.brick.find_next(self.handle)
+ results.append((fname, size))
+ except FileNotFound:
+ self._close()
+ break
+ for result in results:
+ yield result
+
+
+def File(brick, name, mode='r', size=None):
+ """Opens a file for reading/writing. Mode is 'r' or 'w'. If mode is 'w',
+ size must be provided.
+ """
+ if mode == 'w':
+ if size is not None:
+ return FileWriter(brick, name, size)
+ else:
+ return ValueError('Size not specified')
+ elif mode == 'r':
+ return FileReader(brick, name)
+ else:
+ return ValueError('Mode ' + str(mode) + ' not supported')
+
+
+class FileReader(object):
+ """Context manager to read a file on a NXT brick. Do use the iterator or
+ the read() method, but not both at the same time!
+ The iterator returns strings of an arbitrary (short) length.
+ """
+
+ def __init__(self, brick, fname):
+ self.brick = brick
+ self.handle, self.size = brick.open_read(fname)
+
+ def read(self, bytes=None):
+ if bytes is not None:
+ remaining = bytes
+ else:
+ remaining = self.size
+ bsize = self.brick.sock.bsize
+ data = []
+ while remaining > 0:
+ handle, bsize, buffer_ = self.brick.read(self.handle,
+ min(bsize, remaining))
+ remaining -= len(buffer_)
+ data.append(buffer_)
+ return ''.join(data)
+
+ def close(self):
+ if self.handle is not None:
+ self.brick.close(self.handle)
+ self.handle = None
+
+ def __del__(self):
+ self.close()
+
+ def __enter__(self):
+ return self
+
+ def __exit__(self, etp, value, tb):
+ self.close()
+
+ def __iter__(self):
+ rem = self.size
+ bsize = self.brick.sock.bsize
+ while rem > 0:
+ handle, bsize, data = self.brick.read(self.handle,
+ min(bsize, rem))
+ yield data
+ rem -= len(data)
+
+
+class FileWriter(object):
+ "Object to write to a file on a NXT brick"
+
+ def __init__(self, brick, fname, size):
+ self.brick = brick
+ self.handle = self.brick.open_write(fname, size)
+ self._position = 0
+ self.size = size
+
+ def __del__(self):
+ self.close()
+
+ def close(self):
+ if self.handle is not None:
+ self.brick.close(self.handle)
+ self.handle = None
+
+ def tell(self):
+ return self._position
+
+ def write(self, data):
+ remaining = len(data)
+ if remaining > self.size - self._position:
+ raise ValueError('Data will not fit into remaining space')
+ bsize = self.brick.sock.bsize
+ data_position = 0
+
+ while remaining > 0:
+ batch_size = min(bsize, remaining)
+ next_data_position = data_position + batch_size
+ buffer_ = data[data_position:next_data_position]
+
+ handle, size = self.brick.write(self.handle, buffer_)
+
+ self._position += batch_size
+ data_position = next_data_position
+ remaining -= batch_size
+
+
+class ModuleFinder(object):
+ 'Iterator to lookup modules on a NXT brick'
+
+ def __init__(self, brick, pattern):
+ self.brick = brick
+ self.pattern = pattern
+ self.handle = None
+
+ def _close(self):
+ if self.handle:
+ self.brick.close(self.handle)
+ self.handle = None
+
+ def __del__(self):
+ self._close()
+
+ def __iter__(self):
+ self.handle, mname, mid, msize, miomap_size = \
+ self.brick.request_first_module(self.pattern)
+ yield (mname, mid, msize, miomap_size)
+ while True:
+ try:
+ handle, mname, mid, msize, miomap_size = \
+ self.brick.request_next_module(
+ self.handle)
+ yield (mname, mid, msize, miomap_size)
+ except ModuleNotFound:
+ self._close()
+ break
+
+
+class Brick(object): #TODO: this begs to have explicit methods
+ 'Main object for NXT Control'
+
+ __metaclass__ = _Meta
+
+ def __init__(self, sock):
+ self.sock = sock
+ self.lock = Lock()
+
+ def play_tone_and_wait(self, frequency, duration):
+ self.play_tone(frequency, duration)
+ sleep(duration / 1000.0)
+
+ def __del__(self):
+ print "Deleting Brick"
+ self.sock.close()
+
+ find_files = FileFinder
+ find_modules = ModuleFinder
+ open_file = File
+ get_sensor = get_sensor
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/direct.py b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/direct.py
new file mode 100644
index 0000000..50b7f2a
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/direct.py
@@ -0,0 +1,216 @@
+# nxt.direct module -- LEGO Mindstorms NXT direct telegrams
+# Copyright (C) 2006, 2007 Douglas P Lau
+# Copyright (C) 2009 Marcus Wanner
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+'Use for direct communication with the NXT ***EXTREMELY ADVANCED USERS ONLY***'
+
+def _create(opcode):
+ 'Create a simple direct telegram'
+ from telegram import Telegram
+ return Telegram(True, opcode)
+
+def start_program(opcode, fname):
+ tgram = _create(opcode)
+ tgram.add_filename(fname)
+ return tgram
+
+def _parse_simple(tgram):
+ tgram.check_status()
+
+def stop_program(opcode):
+ return _create(opcode)
+
+def play_sound_file(opcode, loop, fname):
+ tgram = _create(opcode)
+ tgram.add_u8(loop)
+ tgram.add_filename(fname)
+ return tgram
+
+def play_tone(opcode, frequency, duration):
+ 'Play a tone at frequency (Hz) for duration (ms)'
+ tgram = _create(opcode)
+ tgram.add_u16(frequency)
+ tgram.add_u16(duration)
+ return tgram
+
+def set_output_state(opcode, port, power, mode, regulation, turn_ratio,
+ run_state, tacho_limit):
+ tgram = _create(opcode)
+ tgram.add_u8(port)
+ tgram.add_s8(power)
+ tgram.add_u8(mode)
+ tgram.add_u8(regulation)
+ tgram.add_s8(turn_ratio)
+ tgram.add_u8(run_state)
+ tgram.add_u32(tacho_limit)
+ return tgram
+
+def set_input_mode(opcode, port, sensor_type, sensor_mode):
+ tgram = _create(opcode)
+ tgram.add_u8(port)
+ tgram.add_u8(sensor_type)
+ tgram.add_u8(sensor_mode)
+ return tgram
+
+def get_output_state(opcode, port):
+ tgram = _create(opcode)
+ tgram.add_u8(port)
+ return tgram
+
+def _parse_get_output_state(tgram):
+ tgram.check_status()
+ port = tgram.parse_u8()
+ power = tgram.parse_s8()
+ mode = tgram.parse_u8()
+ regulation = tgram.parse_u8()
+ turn_ratio = tgram.parse_s8()
+ run_state = tgram.parse_u8()
+ tacho_limit = tgram.parse_u32()
+ tacho_count = tgram.parse_s32()
+ block_tacho_count = tgram.parse_s32()
+ rotation_count = tgram.parse_s32()
+ return (port, power, mode, regulation, turn_ratio, run_state,
+ tacho_limit, tacho_count, block_tacho_count, rotation_count)
+
+def get_input_values(opcode, port):
+ tgram = _create(opcode)
+ tgram.add_u8(port)
+ return tgram
+
+def _parse_get_input_values(tgram):
+ tgram.check_status()
+ port = tgram.parse_u8()
+ valid = tgram.parse_u8()
+ calibrated = tgram.parse_u8()
+ sensor_type = tgram.parse_u8()
+ sensor_mode = tgram.parse_u8()
+ raw_ad_value = tgram.parse_u16()
+ normalized_ad_value = tgram.parse_u16()
+ scaled_value = tgram.parse_s16()
+ calibrated_value = tgram.parse_s16()
+ return (port, valid, calibrated, sensor_type, sensor_mode, raw_ad_value,
+ normalized_ad_value, scaled_value, calibrated_value)
+
+def reset_input_scaled_value(opcode, port):
+ tgram = _create(opcode)
+ tgram.add_u8(port)
+ return tgram
+
+def message_write(opcode, inbox, message):
+ tgram = _create(opcode)
+ tgram.add_u8(inbox)
+ tgram.add_u8(len(message) + 1)
+ tgram.add_string(len(message), message)
+ tgram.add_u8(0)
+ return tgram
+
+def reset_motor_position(opcode, port, relative):
+ tgram = _create(opcode)
+ tgram.add_u8(port)
+ tgram.add_u8(relative)
+ return tgram
+
+def get_battery_level(opcode):
+ return _create(opcode)
+
+def _parse_get_battery_level(tgram):
+ tgram.check_status()
+ millivolts = tgram.parse_u16()
+ return millivolts
+
+def stop_sound_playback(opcode):
+ return _create(opcode)
+
+def keep_alive(opcode):
+ return _create(opcode)
+
+def _parse_keep_alive(tgram):
+ tgram.check_status()
+ sleep_time = tgram.parse_u32()
+ return sleep_time
+
+def ls_get_status(opcode, port):
+ 'Get status of low-speed sensor (ultrasonic)'
+ tgram = _create(opcode)
+ tgram.add_u8(port)
+ return tgram
+
+def _parse_ls_get_status(tgram):
+ tgram.check_status()
+ n_bytes = tgram.parse_u8()
+ return n_bytes
+
+def ls_write(opcode, port, tx_data, rx_bytes):
+ 'Write a low-speed command to a sensor (ultrasonic)'
+ tgram = _create(opcode)
+ tgram.add_u8(port)
+ tgram.add_u8(len(tx_data))
+ tgram.add_u8(rx_bytes)
+ tgram.add_string(len(tx_data), tx_data)
+ return tgram
+
+def ls_read(opcode, port):
+ 'Read a low-speed sensor value (ultrasonic)'
+ tgram = _create(opcode)
+ tgram.add_u8(port)
+ return tgram
+
+def _parse_ls_read(tgram):
+ tgram.check_status()
+ n_bytes = tgram.parse_u8()
+ contents = tgram.parse_string()
+ return contents[:n_bytes]
+
+def get_current_program_name(opcode):
+ return _create(opcode)
+
+def _parse_get_current_program_name(tgram):
+ tgram.check_status()
+ fname = tgram.parse_string()
+ return fname
+
+def message_read(opcode, remote_inbox, local_inbox, remove):
+ tgram = _create(opcode)
+ tgram.add_u8(remote_inbox)
+ tgram.add_u8(local_inbox)
+ tgram.add_u8(remove)
+ return tgram
+
+def _parse_message_read(tgram):
+ tgram.check_status()
+ local_inbox = tgram.parse_u8()
+ n_bytes = tgram.parse_u8()
+ message = tgram.parse_string()
+ return (local_inbox, message[:n_bytes])
+
+OPCODES = {
+ 0x00: (start_program, _parse_simple),
+ 0x01: (stop_program, _parse_simple),
+ 0x02: (play_sound_file, _parse_simple),
+ 0x03: (play_tone, _parse_simple),
+ 0x04: (set_output_state, _parse_simple),
+ 0x05: (set_input_mode, _parse_simple),
+ 0x06: (get_output_state, _parse_get_output_state),
+ 0x07: (get_input_values, _parse_get_input_values),
+ 0x08: (reset_input_scaled_value, _parse_simple),
+ 0x09: (message_write, _parse_simple),
+ 0x0A: (reset_motor_position, _parse_simple),
+ 0x0B: (get_battery_level, _parse_get_battery_level),
+ 0x0C: (stop_sound_playback, _parse_simple),
+ 0x0D: (keep_alive, _parse_keep_alive),
+ 0x0E: (ls_get_status, _parse_ls_get_status),
+ 0x0F: (ls_write, _parse_simple),
+ 0x10: (ls_read, _parse_ls_read),
+ 0x11: (get_current_program_name, _parse_get_current_program_name),
+ 0x13: (message_read, _parse_message_read),
+}
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/error.py b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/error.py
new file mode 100644
index 0000000..3d14497
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/error.py
@@ -0,0 +1,87 @@
+# nxt.error module -- LEGO Mindstorms NXT error handling
+# Copyright (C) 2006, 2007 Douglas P Lau
+# Copyright (C) 2009 Marcus Wanner
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+'Declarations for the errors'
+
+class ProtocolError(Exception):
+ pass
+
+class SysProtError(ProtocolError):
+ pass
+
+class FileExistsError(SysProtError):
+ pass
+
+class FileNotFound(SysProtError):
+ pass
+
+class ModuleNotFound(SysProtError):
+ pass
+
+class DirProtError(ProtocolError):
+ pass
+
+class I2CError(DirProtError):
+ pass
+
+class I2CPendingError(I2CError):
+ pass
+
+CODES = {
+ 0x00: None,
+ 0x20: I2CPendingError('Pending communication transaction in progress'),
+ 0x40: DirProtError('Specified mailbox queue is empty'),
+ 0x81: SysProtError('No more handles'),
+ 0x82: SysProtError('No space'),
+ 0x83: SysProtError('No more files'),
+ 0x84: SysProtError('End of file expected'),
+ 0x85: SysProtError('End of file'),
+ 0x86: SysProtError('Not a linear file'),
+ 0x87: FileNotFound('File not found'),
+ 0x88: SysProtError('Handle already closed'),
+ 0x89: SysProtError('No linear space'),
+ 0x8A: SysProtError('Undefined error'),
+ 0x8B: SysProtError('File is busy'),
+ 0x8C: SysProtError('No write buffers'),
+ 0x8D: SysProtError('Append not possible'),
+ 0x8E: SysProtError('File is full'),
+ 0x8F: FileExistsError('File exists'),
+ 0x90: ModuleNotFound('Module not found'),
+ 0x91: SysProtError('Out of bounds'),
+ 0x92: SysProtError('Illegal file name'),
+ 0x93: SysProtError('Illegal handle'),
+ 0xBD: DirProtError('Request failed (i.e. specified file not found)'),
+ 0xBE: DirProtError('Unknown command opcode'),
+ 0xBF: DirProtError('Insane packet'),
+ 0xC0: DirProtError('Data contains out-of-range values'),
+ 0xDD: DirProtError('Communication bus error'),
+ 0xDE: DirProtError('No free memory in communication buffer'),
+ 0xDF: DirProtError('Specified channel/connection is not valid'),
+ 0xE0: I2CError('Specified channel/connection not configured or busy'),
+ 0xEC: DirProtError('No active program'),
+ 0xED: DirProtError('Illegal size specified'),
+ 0xEE: DirProtError('Illegal mailbox queue ID specified'),
+ 0xEF: DirProtError('Attempted to access invalid field of a structure'),
+ 0xF0: DirProtError('Bad input or output specified'),
+ 0xFB: DirProtError('Insufficient memory available'),
+ 0xFF: DirProtError('Bad arguments'),
+}
+
+def check_status(status):
+ if status:
+ ex = CODES.get(status)
+ if ex:
+ raise ex
+ else:
+ raise ProtocolError, status
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/fantomglue.py b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/fantomglue.py
new file mode 100644
index 0000000..697655f
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/fantomglue.py
@@ -0,0 +1,211 @@
+# fantom.py module -- Glue code from NXT_Python to Fantom, allowing
+# NXT_Python to run on Mac without modification. Supports subset of
+# PyBluez/bluetooth.py used by NXT_Python.
+#
+# Copyright (C) 2011 Tat-Chee Wan
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+import pyfantom
+
+USB_BUFSIZE = 64
+
+RFCOMM=11 # lightblue const
+FANTOM_BT = RFCOMM # For compatibilty with lightblue
+FANTOM_USB = 0
+
+# Bluetooth Iterator
+def discover_devices(lookup_names=False): # parameter is ignored
+ pairs = []
+ for d in pyfantom.NXTIterator(True):
+ # h: host, n: name
+ h = d.get_resource_string()
+ nxt = d.get_nxt()
+ device_info = nxt.get_device_info()
+ n = device_info.name
+ del nxt
+ pairs.append((h, n))
+ return pairs
+
+class BluetoothSocket:
+
+ def __init__(self, proto = FANTOM_BT, _sock=None):
+ # We instantiate a NXT object only when we connect if none supplied
+ self._sock = _sock
+ self._proto = proto
+ self.debug = True
+
+ def __str__(self):
+ return 'FantomGlue BT (%s)' % self.device_name()
+
+ def device_name(self):
+ devinfo = self._sock.get_device_info()
+ return devinfo.name
+
+ def connect(self, addrport):
+ addr, port = addrport
+ if self._sock is None:
+ # Port is ignored
+ paired_addr = pair_bluetooth(addr)
+ if self.debug:
+ print "BT Paired Addr: ", paired_addr
+ self._sock = pyfantom.NXT(paired_addr)
+
+ def send(self, data):
+ return self._sock.write( data )
+
+ def recv(self, numbytes):
+ return self._sock.read( numbytes )
+
+ def close(self):
+ if self._sock is not None:
+ self._sock.close()
+ self._sock = None
+
+ #def __del__(self):
+ # """Destroy interface."""
+ # if self._sock is not None:
+ # del self._sock
+ # if self.debug:
+ # print "NXT object deleted"
+ # else:
+ # if self.debug:
+ # print "No NXT Object when calling __del__ for BluetoothSocket"
+
+class BluetoothError(IOError):
+ pass
+
+def _check_brick(arg, value):
+ return arg is None or arg == value
+
+
+def find_devices(lookup_names=False): # parameter is ignored
+ devicelist = []
+ for d in pyfantom.NXTIterator(False):
+ #name = d.get_name()
+ #addr = d.get_resource_string()
+ #print "NXT addr: ", addr
+ nxt = d.get_nxt()
+ devicelist.append(nxt)
+ return devicelist
+
+# FIXME: The semantics of find_devices is different from discover_devices
+#
+# # h: host, n: name
+# hostmatched = None
+# namematched = None
+# h = d.get_resource_string()
+# nxt = d.get_nxt()
+# device_info = nxt.get_device_info()
+# n = device_info.name
+# if _check_brick(host, h) and _check_brick(name, n):
+# yield nxt
+# else:
+# del nxt # Does not match criteria
+
+class USBSocket:
+
+ def __init__(self, device=None):
+ # We instantiate a NXT object only when we connect if none supplied
+ # FIXME: The addr is not passed in, so we can't actually create a NXT object later
+ #self.device = device
+ self._sock = device
+ self.debug = True
+
+ def __str__(self):
+ return 'FantomGlue USB (%s)' % self.device_name()
+
+ def device_name(self):
+ devinfo = self._sock.get_device_info()
+ return devinfo.name
+
+ def connect(self):
+ if self._sock is None:
+ # Port is ignored
+ if self.debug:
+ print "No NXT object assigned"
+ self._sock = pyfantom.NXT(addr) # FIXME: No address!
+ else:
+ if self.debug:
+ print "Using existing NXT object"
+
+ def send(self, data):
+ return self._sock.write( data )
+
+ def recv(self, numbytes):
+ return self._sock.read( numbytes )
+
+ #def poll_command(self, numbytes):
+ # I'm not sure if this is specific to Direct Command Processing
+ # Or if it refers to any data transmission
+ #print "Bytes Available:", self._sock.bytes_available()
+ #return self._sock.read_buffer( numbytes, 0 )
+
+ def close(self):
+ if self._sock is not None:
+ self._sock.close()
+ self._sock = None
+
+ #def __del__(self):
+ # """Destroy interface."""
+ # if self._sock is not None:
+ # del self._sock
+ # if self.debug:
+ # print "NXT object deleted"
+ # else:
+ # if self.debug:
+ # print "No NXT Object when calling __del__ for USBSocket"
+
+if __name__ == '__main__':
+ #get_info = False
+ get_info = True
+ write_read = True
+ for i in find_devices():
+ if get_info:
+ print " firmware version:", i.get_firmware_version()
+ print " get device info:", i.get_device_info()
+ rs = i.get_resource_string()
+ print " resource string:", rs
+ if write_read:
+ nxt = USBSocket(i)
+ nxt.connect()
+ import struct
+ # Write VERSION SYS_CMD.
+ # Query:
+ # SYS_CMD: 0x01
+ # VERSION: 0x88
+ cmd = struct.pack('2B', 0x01, 0x88)
+ r = nxt.send(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.recv(USB_BUFSIZE) # Doesn't work if it exceeds buffer content length (exception)
+ #rep = nxt.recv(7) # Works, since reply is 7 bytes
+ rep = nxt.recv(5) # Works, read length < remaining buffer content length
+ print "read", struct.unpack('%dB' % len(rep), rep)
+ rep = nxt.recv(5) # Works, remaining buffer content length is non-zero
+ print "read", struct.unpack('%dB' % len(rep), rep)
+ rep = nxt.recv(1) # Doesn't work if no bytes are in read buffer
+ # Same thing, without response.
+ #cmd = struct.pack('2B', 0x81, 0x88)
+ #r = nxt.send(cmd)
+ #print "wrote", r
+ #rep = nxt.recv(USB_BUFSIZE)
+ #rep = nxt.recv(7)
+ #print "read", struct.unpack('%dB' % len(rep), rep)
+ nxt.close()
+ del nxt
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/lightblueglue.py b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/lightblueglue.py
new file mode 100644
index 0000000..f2ab92f
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/lightblueglue.py
@@ -0,0 +1,53 @@
+# bluetooth.py module -- Glue code from NXT_Python to Lightblue, allowing
+# NXT_Python to run on Mac without modification. Supports subset of
+# PyBluez/bluetooth.py used by NXT_Python.
+#
+# Copyright (C) 2007 Simon D. Levy
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+import lightblue
+
+RFCOMM=11
+
+def discover_devices(lookup_names=False): # parameter is ignored
+ pairs = []
+ d = lightblue.finddevices()
+ for p in d:
+ h = p[0]
+ n = p[1]
+ pairs.append((h, n))
+ return pairs
+
+class BluetoothSocket:
+
+ def __init__(self, proto = RFCOMM, _sock=None):
+ if _sock is None:
+ _sock = lightblue.socket(proto)
+ self._sock = _sock
+ self._proto = proto
+
+ def connect(self, addrport):
+ addr, port = addrport
+ self._sock.connect( (addr, port ))
+
+ def send(self, data):
+ return self._sock.send( data )
+
+ def recv(self, numbytes):
+ return self._sock.recv( numbytes )
+
+ def close(self):
+ return self._sock.close()
+
+class BluetoothError(IOError):
+ pass
+
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/locator.py b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/locator.py
new file mode 100644
index 0000000..4adc680
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/locator.py
@@ -0,0 +1,57 @@
+# nxt.locator module -- Locate LEGO Minstorms NXT bricks via USB or Bluetooth
+# Copyright (C) 2006, 2007 Douglas P Lau
+# Copyright (C) 2009 Marcus Wanner
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+class BrickNotFoundError(Exception):
+ pass
+
+class NoBackendError(Exception):
+ pass
+
+def find_bricks(host=None, name=None, silent=False):
+ """Used by find_one_brick to look for bricks ***ADVANCED USERS ONLY***"""
+
+ try:
+ import usbsock
+ usb_available = True
+ socks = usbsock.find_bricks(host, name)
+ for s in socks:
+ yield s
+ except ImportError:
+ usb_available = False
+ import sys
+ if not silent: print >>sys.stderr, "USB module unavailable, not searching there"
+
+ try:
+ import bluesock
+ try:
+ socks = bluesock.find_bricks(host, name)
+ for s in socks:
+ yield s
+ except (bluesock.bluetooth.BluetoothError, IOError): #for cases such as no adapter, bluetooth throws IOError, not BluetoothError
+ pass
+ except ImportError:
+ import sys
+ if not silent: print >>sys.stderr, "Bluetooth module unavailable, not searching there"
+ if not usb_available:
+ raise NoBackendError("Neither USB nor Bluetooth could be used! Did you install PyUSB or PyBluez?")
+
+
+def find_one_brick(host=None, name=None, silent=False):
+ """Use to find one brick. After it returns a usbsock object or a bluesock
+object, it automatically connects to it. The host and name args limit
+the search to a given MAC or brick name. Set silent to True to stop
+nxt-python from printing anything during the search."""
+ for s in find_bricks(host, name, silent):
+ return s.connect()
+ raise BrickNotFoundError
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/motor.py b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/motor.py
new file mode 100644
index 0000000..f29a5a5
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/motor.py
@@ -0,0 +1,431 @@
+# nxt.motor module -- Class to control LEGO Mindstorms NXT motors
+# Copyright (C) 2006 Douglas P Lau
+# Copyright (C) 2009 Marcus Wanner, rhn
+# Copyright (C) 2010 rhn
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+"""Use for motor control"""
+
+import time
+import warnings
+
+PORT_A = 0x00
+PORT_B = 0x01
+PORT_C = 0x02
+PORT_ALL = 0xFF
+
+MODE_IDLE = 0x00
+MODE_MOTOR_ON = 0x01
+MODE_BRAKE = 0x02
+MODE_REGULATED = 0x04
+
+REGULATION_IDLE = 0x00
+REGULATION_MOTOR_SPEED = 0x01
+REGULATION_MOTOR_SYNC = 0x02
+
+RUN_STATE_IDLE = 0x00
+RUN_STATE_RAMP_UP = 0x10
+RUN_STATE_RUNNING = 0x20
+RUN_STATE_RAMP_DOWN = 0x40
+
+LIMIT_RUN_FOREVER = 0
+
+class BlockedException(Exception):
+ pass
+
+class OutputState(object):
+ """An object holding the internal state of a motor, not including rotation
+ counters.
+ """
+ def __init__(self, values):
+ (self.power, self.mode, self.regulation,
+ self.turn_ratio, self.run_state, self.tacho_limit) = values
+
+ def to_list(self):
+ """Returns a list of properties that can be used with set_output_state.
+ """
+ return [self.power, self.mode, self.regulation,
+ self.turn_ratio, self.run_state, self.tacho_limit]
+
+ def __str__(self):
+ modes = []
+ if self.mode & MODE_MOTOR_ON:
+ modes.append('on')
+ if self.mode & MODE_BRAKE:
+ modes.append('brake')
+ if self.mode & MODE_REGULATED:
+ modes.append('regulated')
+ if not modes:
+ modes.append('idle')
+ mode = '&'.join(modes)
+ regulation = 'regulation: ' + \
+ ['idle', 'speed', 'sync'][self.regulation]
+ run_state = 'run state: ' + {0: 'idle', 0x10: 'ramp_up',
+ 0x20: 'running', 0x40: 'ramp_down'}[self.run_state]
+ return ', '.join([mode, regulation, str(self.turn_ratio), run_state] + [str(self.tacho_limit)])
+
+
+class TachoInfo:
+ """An object containing the information about the rotation of a motor"""
+ def __init__(self, values):
+ self.tacho_count, self.block_tacho_count, self.rotation_count = values
+
+ def get_target(self, tacho_limit, direction):
+ """Returns a TachoInfo object which corresponds to tacho state after
+ moving for tacho_limit ticks. Direction can be 1 (add) or -1 (subtract)
+ """
+ # TODO: adjust other fields
+ if abs(direction) != 1:
+ raise ValueError('Invalid direction')
+ new_tacho = self.tacho_count + direction * tacho_limit
+ return TachoInfo([new_tacho, None, None])
+
+ def is_greater(self, target, direction):
+ return direction * (self.tacho_count - target.tacho_count) > 0
+
+ def is_near(self, target, threshold):
+ difference = abs(target.tacho_count - self.tacho_count)
+ return difference < threshold
+
+ def __str__(self):
+ return str((self.tacho_count, self.block_tacho_count,
+ self.rotation_count))
+
+
+class SynchronizedTacho(object):
+ def __init__(self, leader_tacho, follower_tacho):
+ self.leader_tacho = leader_tacho
+ self.follower_tacho = follower_tacho
+
+ def get_target(self, tacho_limit, direction):
+ """This method will leave follower's target as None"""
+ leader_tacho = self.leader_tacho.get_target(tacho_limit, direction)
+ return SynchronizedTacho(leader_tacho, None)
+
+ def is_greater(self, other, direction):
+ return self.leader_tacho.is_greater(other.leader_tacho, direction)
+
+ def is_near(self, other, threshold):
+ return self.leader_tacho.is_near(other.leader_tacho, threshold)
+
+ def __str__(self):
+ if self.follower_tacho is not None:
+ t2 = str(self.follower_tacho.tacho_count)
+ else:
+ t2 = 'None'
+ t1 = str(self.leader_tacho.tacho_count)
+ return 'tacho: ' + t1 + ' ' + t2
+
+
+def get_tacho_and_state(values):
+ """A convenience function. values is the list of values from
+ get_output_state. Returns both OutputState and TachoInfo.
+ """
+ return OutputState(values[1:7]), TachoInfo(values[7:])
+
+
+class BaseMotor(object):
+ """Base class for motors"""
+ debug = 0
+ def _debug_out(self, message):
+ if self.debug:
+ print message
+
+ def turn(self, power, tacho_units, brake=True, timeout=1, emulate=True):
+ """Use this to turn a motor. The motor will not stop until it turns the
+ desired distance. Accuracy is much better over a USB connection than
+ with bluetooth...
+ power is a value between -127 and 128 (an absolute value greater than
+ 64 is recommended)
+ tacho_units is the number of degrees to turn the motor. values smaller
+ than 50 are not recommended and may have strange results.
+ brake is whether or not to hold the motor after the function exits
+ (either by reaching the distance or throwing an exception).
+ timeout is the number of seconds after which a BlockedException is
+ raised if the motor doesn't turn
+ emulate is a boolean value. If set to False, the motor is aware of the
+ tacho limit. If True, a run() function equivalent is used.
+ Warning: motors remember their positions and not using emulate
+ may lead to strange behavior, especially with synced motors
+ """
+
+ tacho_limit = tacho_units
+
+ if tacho_limit < 0:
+ raise ValueError, "tacho_units must be greater than 0!"
+
+ if self.method == 'bluetooth':
+ threshold = 70
+ elif self.method == 'usb':
+ threshold = 5
+ else:
+ threshold = 30 #compromise
+
+ tacho = self.get_tacho()
+ state = self._get_new_state()
+
+ # Update modifiers even if they aren't used, might have been changed
+ state.power = power
+ if not emulate:
+ state.tacho_limit = tacho_limit
+
+ self._debug_out('Updating motor information...')
+ self._set_state(state)
+
+ direction = 1 if power > 0 else -1
+ self._debug_out('tachocount: ' + str(tacho))
+ current_time = time.time()
+ tacho_target = tacho.get_target(tacho_limit, direction)
+
+ blocked = False
+ try:
+ while True:
+ time.sleep(self._eta(tacho, tacho_target, power) / 2)
+
+ if not blocked: # if still blocked, don't reset the counter
+ last_tacho = tacho
+ last_time = current_time
+
+ tacho = self.get_tacho()
+ current_time = time.time()
+ blocked = self._is_blocked(tacho, last_tacho, direction)
+ if blocked:
+ self._debug_out(('not advancing', last_tacho, tacho))
+ # the motor can be up to 80+ degrees in either direction from target when using bluetooth
+ if current_time - last_time > timeout:
+ if tacho.is_near(tacho_target, threshold):
+ break
+ else:
+ raise BlockedException("Blocked!")
+ else:
+ self._debug_out(('advancing', last_tacho, tacho))
+ if tacho.is_near(tacho_target, threshold) or tacho.is_greater(tacho_target, direction):
+ break
+ finally:
+ if brake:
+ self.brake()
+ else:
+ self.idle()
+
+
+class Motor(BaseMotor):
+ def __init__(self, brick, port):
+ self.brick = brick
+ self.port = port
+ self._read_state()
+ self.sync = 0
+ self.turn_ratio = 0
+ if str(type(self.brick.sock)) == "<class 'nxt.bluesock.BlueSock'>":
+ self.method = 'bluetooth'
+ elif str(type(self.brick.sock)) == "<class 'nxt.usbsock.USBSock'>":
+ self.method = 'usb'
+ else:
+ print "Warning: Socket object does not of a known type."
+ print "The name is: " + str(type(self.brick.sock))
+ print "Please report this problem to the developers!"
+ print "For now, turn() accuracy will not be optimal."
+ print "Continuing happily..."
+ self.method = None
+
+ def _set_state(self, state):
+ self._debug_out('Setting brick output state...')
+ list_state = [self.port] + state.to_list()
+ self.brick.set_output_state(*list_state)
+ self._debug_out(state)
+ self._state = state
+ self._debug_out('State set.')
+
+ def _read_state(self):
+ self._debug_out('Getting brick output state...')
+ values = self.brick.get_output_state(self.port)
+ self._debug_out('State got.')
+ self._state, tacho = get_tacho_and_state(values)
+ return self._state, tacho
+
+ #def get_tacho_and_state here would allow tacho manipulation
+
+ def _get_state(self):
+ """Returns a copy of the current motor state for manipulation."""
+ return OutputState(self._state.to_list())
+
+ def _get_new_state(self):
+ state = self._get_state()
+ if self.sync:
+ state.mode = MODE_MOTOR_ON | MODE_REGULATED
+ state.regulation = REGULATION_MOTOR_SYNC
+ state.turn_ratio = self.turn_ratio
+ else:
+ state.mode = MODE_MOTOR_ON | MODE_REGULATED
+ state.regulation = REGULATION_MOTOR_SPEED
+ state.run_state = RUN_STATE_RUNNING
+ state.tacho_limit = LIMIT_RUN_FOREVER
+ return state
+
+ def get_tacho(self):
+ return self._read_state()[1]
+
+ def reset_position(self, relative):
+ """Resets the counters. Relative can be True or False"""
+ self.brick.reset_motor_position(self.port, relative)
+
+ def run(self, power=100, regulated=False):
+ '''Tells the motor to run continuously. If regulated is True, then the
+ synchronization starts working.
+ '''
+ state = self._get_new_state()
+ state.power = power
+ if not regulated:
+ state.mode = MODE_MOTOR_ON
+ self._set_state(state)
+
+ def brake(self):
+ """Holds the motor in place"""
+ state = self._get_new_state()
+ state.power = 0
+ state.mode = MODE_MOTOR_ON | MODE_BRAKE | MODE_REGULATED
+ self._set_state(state)
+
+ def idle(self):
+ '''Tells the motor to stop whatever it's doing. It also desyncs it'''
+ state = self._get_new_state()
+ state.power = 0
+ state.mode = MODE_IDLE
+ state.regulation = REGULATION_IDLE
+ state.run_state = RUN_STATE_IDLE
+ self._set_state(state)
+
+ def weak_turn(self, power, tacho_units):
+ """Tries to turn a motor for the specified distance. This function
+ returns immediately, and it's not guaranteed that the motor turns that
+ distance. This is an interface to use tacho_limit without
+ REGULATION_MODE_SPEED
+ """
+ tacho_limit = tacho_units
+ tacho = self.get_tacho()
+ state = self._get_new_state()
+
+ # Update modifiers even if they aren't used, might have been changed
+ state.mode = MODE_MOTOR_ON
+ state.regulation = REGULATION_IDLE
+ state.power = power
+ state.tacho_limit = tacho_limit
+
+ self._debug_out('Updating motor information...')
+ self._set_state(state)
+
+ def _eta(self, current, target, power):
+ """Returns time in seconds. Do not trust it too much"""
+ tacho = abs(current.tacho_count - target.tacho_count)
+ return (float(tacho) / abs(power)) / 5
+
+ def _is_blocked(self, tacho, last_tacho, direction):
+ """Returns if any of the engines is blocked"""
+ return direction * (last_tacho.tacho_count - tacho.tacho_count) >= 0
+
+
+class SynchronizedMotors(BaseMotor):
+ """The object used to make two motors run in sync. Many objects may be
+ present at the same time but they can't be used at the same time.
+ Warning! Movement methods reset tacho counter.
+ THIS CODE IS EXPERIMENTAL!!!
+ """
+ def __init__(self, leader, follower, turn_ratio):
+ """Turn ratio can be >= 0 only! If you want to have it reversed,
+ change motor order.
+ """
+ if follower.brick != leader.brick:
+ raise ValueError('motors belong to different bricks')
+ self.leader = leader
+ self.follower = follower
+ self.method = self.leader.method #being from the same brick, they both have the same com method.
+
+ if turn_ratio < 0:
+ raise ValueError('Turn ratio <0. Change motor order instead!')
+
+ if self.leader.port == self.follower.port:
+ raise ValueError("The same motor passed twice")
+ elif self.leader.port > self.follower.port:
+ self.turn_ratio = turn_ratio
+ else:
+ self._debug_out('reversed')
+ self.turn_ratio = -turn_ratio
+
+ def _get_new_state(self):
+ return self.leader._get_new_state()
+
+ def _set_state(self, state):
+ self.leader._set_state(state)
+ self.follower._set_state(state)
+
+ def get_tacho(self):
+ leadertacho = self.leader.get_tacho()
+ followertacho = self.follower.get_tacho()
+ return SynchronizedTacho(leadertacho, followertacho)
+
+ def reset_position(self, relative):
+ """Resets the counters. Relative can be True or False"""
+ self.leader.reset_position(relative)
+ self.follower.reset_position(relative)
+
+ def _enable(self): # This works as expected. I'm not sure why.
+ #self._disable()
+ self.reset_position(True)
+ self.leader.sync = True
+ self.follower.sync = True
+ self.leader.turn_ratio = self.turn_ratio
+ self.follower.turn_ratio = self.turn_ratio
+
+ def _disable(self): # This works as expected. (tacho is reset ok)
+ self.leader.sync = False
+ self.follower.sync = False
+ #self.reset_position(True)
+ self.leader.idle()
+ self.follower.idle()
+ #self.reset_position(True)
+
+ def run(self, power=100):
+ """Warning! After calling this method, make sure to call idle. The
+ motors are reported to behave wildly otherwise.
+ """
+ self._enable()
+ self.leader.run(power, True)
+ self.follower.run(power, True)
+
+ def brake(self):
+ self._disable() # reset the counters
+ self._enable()
+ self.leader.brake() # brake both motors at the same time
+ self.follower.brake()
+ self._disable() # now brake as usual
+ self.leader.brake()
+ self.follower.brake()
+
+ def idle(self):
+ self._disable()
+
+ def turn(self, power, tacho_units, brake=True, timeout=1):
+ self._enable()
+ # non-emulation is a nightmare, tacho is being counted differently
+ try:
+ if power < 0:
+ self.leader, self.follower = self.follower, self.leader
+ BaseMotor.turn(self, power, tacho_units, brake, timeout, emulate=True)
+ finally:
+ if power < 0:
+ self.leader, self.follower = self.follower, self.leader
+
+ def _eta(self, tacho, target, power):
+ return self.leader._eta(tacho.leader_tacho, target.leader_tacho, power)
+
+ def _is_blocked(self, tacho, last_tacho, direction):
+ # no need to check both, they're synced
+ return self.leader._is_blocked(tacho.leader_tacho, last_tacho.leader_tacho, direction)
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/pyusbglue.py b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/pyusbglue.py
new file mode 100644
index 0000000..b140dfe
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/pyusbglue.py
@@ -0,0 +1,82 @@
+# pyusbglue.py module -- Glue code from NXT_Python to libusb for USB access.
+#
+# Copyright (C) 2011 Tat-Chee Wan
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+import usb
+
+USB_BUFSIZE = 64
+
+ID_VENDOR_LEGO = 0x0694
+ID_PRODUCT_NXT = 0x0002
+
+class USBSocket:
+ bsize = 60 # USB socket block size
+
+ def __init__(self, device):
+ self.device = device
+ self.handle = None
+ self.debug = False
+
+ def device_name(self):
+ return self.device.filename
+
+ def connect(self):
+ 'Use to connect to NXT.'
+ if self.debug:
+ print 'PyUSB Connecting...'
+ config = self.device.configurations[0]
+ iface = config.interfaces[0][0]
+ self.blk_out, self.blk_in = iface.endpoints
+ self.handle = self.device.open()
+ self.handle.setConfiguration(1)
+ self.handle.claimInterface(0)
+ self.handle.reset()
+ if self.debug:
+ print 'Connected.'
+
+ def close(self):
+ 'Use to close the connection.'
+ if self.debug:
+ print 'Closing USB connection...'
+ self.device = None
+ self.handle = None
+ self.blk_out = None
+ self.blk_in = None
+ if self.debug:
+ print 'USB connection closed.'
+
+ def send(self, data):
+ 'Use to send raw data over USB connection ***ADVANCED USERS ONLY***'
+ if self.debug:
+ print 'Send:',
+ print ':'.join('%02x' % ord(c) for c in data)
+ self.handle.bulkWrite(self.blk_out.address, data)
+
+ def recv(self, numbytes):
+ 'Use to recieve raw data over USB connection ***ADVANCED USERS ONLY***'
+ data = self.handle.bulkRead(self.blk_in.address, numbytes)
+ if self.debug:
+ print 'Recv:',
+ print ':'.join('%02x' % (c & 0xFF) for c in data)
+ # NOTE: bulkRead returns a tuple of ints ... make it sane
+ return ''.join(chr(d & 0xFF) for d in data)
+
+def find_devices(lookup_names=False): # parameter is ignored
+ devicelist = []
+ for bus in usb.busses():
+ for device in bus.devices:
+ if device.idVendor == ID_VENDOR_LEGO and device.idProduct == ID_PRODUCT_NXT:
+ devicelist.append(device)
+ return devicelist
+
+
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/sensor/__init__.py b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/sensor/__init__.py
new file mode 100644
index 0000000..8f2a337
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/sensor/__init__.py
@@ -0,0 +1,50 @@
+# nxt.sensor module -- Classes to read LEGO Mindstorms NXT sensors
+# Copyright (C) 2006,2007 Douglas P Lau
+# Copyright (C) 2009 Marcus Wanner, Paulo Vieira, rhn
+# Copyright (C) 2010 Marcus Wanner
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+from .common import *
+from .analog import BaseAnalogSensor
+from .digital import BaseDigitalSensor, find_class
+from .generic import Touch, Light, Sound, Ultrasonic, Color20
+import mindsensors
+MSSumoEyes = mindsensors.SumoEyes
+MSCompassv2 = mindsensors.Compassv2
+MSDIST = mindsensors.DIST
+MSRTC = mindsensors.RTC
+MSACCL = mindsensors.ACCL
+MSServo = mindsensors.Servo
+MSMTRMUX = mindsensors.MTRMUX
+MSLineLeader = mindsensors.LineLeader
+MSMMX = mindsensors.MMX
+MSPS2 = mindsensors.PS2
+MSHID = mindsensors.HID
+import hitechnic
+HTCompass = hitechnic.Compass
+HTAccelerometer = hitechnic.Accelerometer
+HTGyro = hitechnic.Gyro
+HTColorv2 = hitechnic.Colorv2
+HTEOPD = hitechnic.EOPD
+HTIRReceiver = hitechnic.IRReceiver
+HTIRSeekerv2 = hitechnic.IRSeekerv2
+HTPrototype = hitechnic.Prototype
+
+
+def get_sensor(brick, port):
+ """Tries to detect the sensor type and return the correct sensor
+object. Does not work for sensors with no identification information (such as
+all analog sensors or the MindSensors RTC.
+ """
+ base_sensor = BaseDigitalSensor(brick, port, False)
+ info = base_sensor.get_sensor_info()
+ return find_class(info)(brick, port, check_compatible=False)
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/sensor/analog.py b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/sensor/analog.py
new file mode 100644
index 0000000..e8d9b7b
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/sensor/analog.py
@@ -0,0 +1,41 @@
+# nxt.sensor.analog module -- submodule for use with analog sensors
+# Copyright (C) 2006,2007 Douglas P Lau
+# Copyright (C) 2009 Marcus Wanner, Paulo Vieira, rhn
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+from common import *
+
+
+class RawReading: # can be converted to the old version
+ """A pseudo-structure holding the raw sensor values as returned by the NXT
+ brick.
+ """
+ def __init__(self, values):
+ (self.port, self.valid, self.calibrated, self.sensor_type, self.mode,
+ self.raw_ad_value, self.normalized_ad_value, self.scaled_value,
+ self.calibrated_value) = values
+
+ def __repr__(self):
+ return str((self.port, self.valid, self.calibrated, self.sensor_type, self.mode,
+ self.raw_ad_value, self.normalized_ad_value, self.scaled_value,
+ self.calibrated_value))
+
+
+class BaseAnalogSensor(Sensor):
+ """Object for analog sensors."""
+ def get_input_values(self):
+ """Returns the raw sensor values as returned by the NXT brick."""
+ return RawReading(self.brick.get_input_values(self.port))
+
+ def reset_input_scaled_value(self):
+ self.brick.reset_input_scaled_value()
+
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/sensor/common.py b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/sensor/common.py
new file mode 100644
index 0000000..5afd6c8
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/sensor/common.py
@@ -0,0 +1,67 @@
+# nxt.sensor.common module -- submodule with stuff useful in all sensors
+# Copyright (C) 2006,2007 Douglas P Lau
+# Copyright (C) 2009 Marcus Wanner, Paulo Vieira, rhn
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+PORT_1 = 0x00
+PORT_2 = 0x01
+PORT_3 = 0x02
+PORT_4 = 0x03
+
+class Type(object):
+ 'Namespace for enumeration of the type of sensor'
+ # NOTE: just a namespace (enumeration)
+ NO_SENSOR = 0x00
+ SWITCH = 0x01 # Touch sensor
+ TEMPERATURE = 0x02
+ REFLECTION = 0x03
+ ANGLE = 0x04
+ LIGHT_ACTIVE = 0x05 # Light sensor (illuminated)
+ LIGHT_INACTIVE = 0x06 # Light sensor (ambient)
+ SOUND_DB = 0x07 # Sound sensor (unadjusted)
+ SOUND_DBA = 0x08 # Sound sensor (adjusted)
+ CUSTOM = 0x09
+ LOW_SPEED = 0x0A
+ LOW_SPEED_9V = 0x0B # Low-speed I2C (Ultrasonic sensor)
+ HIGH_SPEED = 0x0C #Possibly other mode for I2C; may be used by future sensors.
+ COLORFULL = 0x0D #NXT 2.0 color sensor in full color mode (color sensor mode)
+ COLORRED = 0x0E #NXT 2.0 color sensor with red light on (light sensor mode)
+ COLORGREEN = 0x0F #NXT 2.0 color sensor with green light on (light sensor mode)
+ COLORBLUE = 0x10 #NXT 2.0 color sensor in with blue light on (light sensor mode)
+ COLORNONE = 0x11 #NXT 2.0 color sensor in with light off (light sensor mode)
+ COLOREXIT = 0x12 #NXT 2.0 color sensor internal state (not sure what this is for yet)
+
+
+class Mode(object):
+ 'Namespace for enumeration of the mode of sensor'
+ # NOTE: just a namespace (enumeration)
+ RAW = 0x00
+ BOOLEAN = 0x20
+ TRANSITION_CNT = 0x40
+ PERIOD_COUNTER = 0x60
+ PCT_FULL_SCALE = 0x80
+ CELSIUS = 0xA0
+ FAHRENHEIT = 0xC0
+ ANGLE_STEPS = 0xE0
+ MASK = 0xE0
+ MASK_SLOPE = 0x1F # Why isn't this slope thing documented?
+
+
+class Sensor(object):
+ 'Main sensor object'
+
+ def __init__(self, brick, port):
+ self.brick = brick
+ self.port = port
+
+ def set_input_mode(self, type_, mode):
+ self.brick.set_input_mode(self.port, type_, mode)
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/sensor/digital.py b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/sensor/digital.py
new file mode 100644
index 0000000..dbc730f
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/sensor/digital.py
@@ -0,0 +1,227 @@
+# nxt.sensor module -- Classes to read LEGO Mindstorms NXT sensors
+# Copyright (C) 2006,2007 Douglas P Lau
+# Copyright (C) 2009 Marcus Wanner, Paulo Vieira, rhn
+# Copyright (C) 2010,2011 Marcus Wanner
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+from nxt.error import I2CError, I2CPendingError, DirProtError
+
+from common import *
+from time import sleep, time
+import struct
+
+
+class SensorInfo:
+ def __init__(self, version, product_id, sensor_type):
+ self.version = version
+ self.product_id = product_id
+ self.sensor_type = sensor_type
+
+ def clarifybinary(self, instr, label):
+ outstr = ''
+ outstr += (label + ': `' + instr + '`\n')
+ for char in instr:
+ outstr += (hex(ord(char))+', ')
+ outstr += ('\n')
+ return outstr
+
+ def __str__(self):
+ outstr = ''
+ outstr += (self.clarifybinary(str(self.version), 'Version'))
+ outstr += (self.clarifybinary(str(self.product_id), 'Product ID'))
+ outstr += (self.clarifybinary(str(self.sensor_type), 'Type'))
+ return outstr
+
+class BaseDigitalSensor(Sensor):
+ """Object for digital sensors. I2C_ADDRESS is the dictionary storing name
+ to i2c address mappings. It should be updated in every subclass. When
+ subclassing this class, make sure to call add_compatible_sensor to add
+ compatible sensor data.
+ """
+ I2C_DEV = 0x02
+ I2C_ADDRESS = {'version': (0x00, '8s'),
+ 'product_id': (0x08, '8s'),
+ 'sensor_type': (0x10, '8s'),
+# 'factory_zero': (0x11, 1), # is this really correct?
+ 'factory_scale_factor': (0x12, 'B'),
+ 'factory_scale_divisor': (0x13, 'B'),
+ }
+
+ def __init__(self, brick, port, check_compatible=True):
+ """Creates a BaseDigitalSensor. If check_compatible is True, queries
+ the sensor for its name, and if a wrong sensor class was used, prints
+ a warning.
+ """
+ super(BaseDigitalSensor, self).__init__(brick, port)
+ self.set_input_mode(Type.LOW_SPEED_9V, Mode.RAW)
+ self.last_poll = time()
+ self.poll_delay = 0.01
+ sleep(0.1) # Give I2C time to initialize
+ #Don't do type checking if this class has no compatible sensors listed.
+ try: self.compatible_sensors
+ except AttributeError: check_compatible = False
+ if check_compatible:
+ sensor = self.get_sensor_info()
+ if not sensor in self.compatible_sensors:
+ print ('WARNING: Wrong sensor class chosen for sensor ' +
+ str(sensor.product_id) + ' on port ' + str(port) + '. ' + """
+You may be using the wrong type of sensor or may have connected the cable
+incorrectly. If you are sure you're using the correct sensor class for the
+sensor, this message is likely in error and you should disregard it and file a
+bug report, including the output of get_sensor_info(). This message can be
+suppressed by passing "check_compatible=False" when creating the sensor object.""")
+
+ def _ls_get_status(self, n_bytes):
+ for n in range(10):
+ try:
+ b = self.brick.ls_get_status(self.port)
+ if b >= n_bytes:
+ return b
+ except I2CPendingError:
+ pass
+ raise I2CError, 'ls_get_status timeout'
+
+ def _i2c_command(self, address, value, format):
+ """Writes an i2c value to the given address. value must be a string. value is
+ a tuple of values corresponding to the given format.
+ """
+ value = struct.pack(format, *value)
+ msg = chr(self.I2C_DEV) + chr(address) + value
+ if self.last_poll+self.poll_delay > time():
+ diff = time() - self.last_poll
+ sleep(self.poll_delay - diff)
+ self.last_poll = time()
+ self.brick.ls_write(self.port, msg, 0)
+
+ def _i2c_query(self, address, format):
+ """Reads an i2c value from given address, and returns a value unpacked
+ according to the given format. Format is the same as in the struct
+ module. See http://docs.python.org/library/struct.html#format-strings
+ """
+ n_bytes = struct.calcsize(format)
+ msg = chr(self.I2C_DEV) + chr(address)
+ if self.last_poll+self.poll_delay > time():
+ diff = time() - self.last_poll
+ sleep(self.poll_delay - diff)
+ self.last_poll = time()
+ self.brick.ls_write(self.port, msg, n_bytes)
+ try:
+ self._ls_get_status(n_bytes)
+ finally:
+ #we should clear the buffer no matter what happens
+ data = self.brick.ls_read(self.port)
+ if len(data) < n_bytes:
+ raise I2CError, 'Read failure: Not enough bytes'
+ data = struct.unpack(format, data[-n_bytes:])
+ return data
+
+ def read_value(self, name):
+ """Reads a value from the sensor. Name must be a string found in
+ self.I2C_ADDRESS dictionary. Entries in self.I2C_ADDRESS are in the
+ name: (address, format) form, with format as in the struct module.
+ Be careful on unpacking single variables - struct module puts them in
+ tuples containing only one element.
+ """
+ address, fmt = self.I2C_ADDRESS[name]
+ for n in range(3):
+ try:
+ return self._i2c_query(address, fmt)
+ except DirProtError:
+ pass
+ raise I2CError, "read_value timeout"
+
+ def write_value(self, name, value):
+ """Writes value to the sensor. Name must be a string found in
+ self.I2C_ADDRESS dictionary. Entries in self.I2C_ADDRESS are in the
+ name: (address, format) form, with format as in the struct module.
+ value is a tuple of values corresponding to the format from
+ self.I2C_ADDRESS dictionary.
+ """
+ address, fmt = self.I2C_ADDRESS[name]
+ self._i2c_command(address, value, fmt)
+
+ def get_sensor_info(self):
+ version = self.read_value('version')[0].split('\0')[0]
+ product_id = self.read_value('product_id')[0].split('\0')[0]
+ sensor_type = self.read_value('sensor_type')[0].split('\0')[0]
+ return SensorInfo(version, product_id, sensor_type)
+
+ @classmethod
+ def add_compatible_sensor(cls, version, product_id, sensor_type):
+ """Adds an entry in the compatibility table for the sensor. If version
+ is None, then it's the default class for this model. If product_id is
+ None, then this is the default class for this vendor.
+ """
+ try:
+ cls.compatible_sensors
+ except AttributeError:
+ cls.compatible_sensors = []
+ finally:
+ cls.compatible_sensors.append(SCompatibility(version, product_id,
+ sensor_type))
+ add_mapping(cls, version, product_id, sensor_type)
+
+
+class SCompatibility(SensorInfo):
+ """An object that helps manage the sensor mappings"""
+ def __eq__(self, other):
+ if self.product_id is None:
+ return self.product_id == other.product_id
+ elif self.version is None:
+ return (self.product_id == other.product_id and
+ self.sensor_type == other.sensor_type)
+ else:
+ return (self.version == other.version and
+ self.product_id == other.product_id and
+ self.sensor_type == other.sensor_type)
+
+sensor_mappings = {}
+
+
+def add_mapping(cls, version, product_id, sensor_type):
+ "None means any other value"
+ if product_id not in sensor_mappings:
+ sensor_mappings[product_id] = {}
+ models = sensor_mappings[product_id]
+
+ if sensor_type is None:
+ if sensor_type in models:
+ raise ValueError('Already registered!')
+ models[sensor_type] = cls
+ return
+
+ if sensor_type not in models:
+ models[sensor_type] = {}
+ versions = models[sensor_type]
+
+ if version in versions:
+ raise ValueError('Already registered!')
+ else:
+ versions[version] = cls
+
+
+class SearchError(Exception):
+ pass
+
+
+def find_class(info):
+ """Returns an appropriate class for the given SensorInfo"""
+ dic = sensor_mappings
+ for val, msg in zip((info.product_id, info.sensor_type, info.version),
+ ('Vendor', 'Model', 'Version')):
+ if val in dic:
+ dic = dic[val]
+ elif None in dic:
+ dic = dic[None]
+ else:
+ raise SearchError(msg + ' not found')
+ return dic[info.sensor_type][None]
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/sensor/generic.py b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/sensor/generic.py
new file mode 100644
index 0000000..b3d792f
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/sensor/generic.py
@@ -0,0 +1,154 @@
+# nxt.sensor.generic module -- Classes to read LEGO Mindstorms NXT sensors
+# Copyright (C) 2006,2007 Douglas P Lau
+# Copyright (C) 2009 Marcus Wanner, Paulo Vieira, rhn
+# Copyright (C) 2010 melducky, Marcus Wanner
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+from .common import *
+from .digital import BaseDigitalSensor
+from .analog import BaseAnalogSensor
+
+
+class Touch(BaseAnalogSensor):
+ """The LEGO touch sensor"""
+
+ def __init__(self, brick, port):
+ super(Touch, self).__init__(brick, port)
+ self.set_input_mode(Type.SWITCH, Mode.BOOLEAN)
+
+ def is_pressed(self):
+ return bool(self.get_input_values().scaled_value)
+
+ get_sample = is_pressed
+
+
+class Light(BaseAnalogSensor):
+ """Object for light sensors. It automatically turns off light when it's not
+ used.
+ """
+ def __init__(self, brick, port, illuminated=True):
+ super(Light, self).__init__(brick, port)
+
+ def set_illuminated(self, active):
+ if active:
+ type_ = Type.LIGHT_ACTIVE
+ else:
+ type_ = Type.LIGHT_INACTIVE
+ self.set_input_mode(type_, Mode.RAW)
+
+ def get_lightness(self):
+ return self.get_input_values().scaled_value
+
+ get_sample = get_lightness
+
+
+class Sound(BaseAnalogSensor):
+ 'Object for sound sensors'
+
+ def __init__(self, brick, port, adjusted=True):
+ super(Sound, self).__init__(brick, port)
+ self.set_adjusted(adjusted)
+
+ def set_adjusted(self, active):
+ if active:
+ type_ = Type.SOUND_DBA
+ else:
+ type_ = Type.SOUND_DB
+ self.set_input_mode(type_, Mode.RAW)
+
+ def get_loudness(self):
+ return self.get_input_values().scaled_value
+
+ get_sample = get_loudness
+
+
+class Ultrasonic(BaseDigitalSensor):
+ """Object for ultrasonic sensors"""
+ I2C_ADDRESS = BaseDigitalSensor.I2C_ADDRESS.copy()
+ I2C_ADDRESS.update({'measurement_units': (0x14, '7s'),
+ 'continuous_measurement_interval': (0x40, 'B'),
+ 'command': (0x41, 'B'),
+ 'measurement_byte_0': (0x42, 'B'),
+ 'measurements': (0x42, '8B'),
+ 'actual_scale_factor': (0x51, 'B'),
+ 'actual_scale_divisor': (0x52, 'B'),
+ })
+
+ class Commands:
+ 'These are for passing to command()'
+ OFF = 0x00
+ SINGLE_SHOT = 0x01
+ CONTINUOUS_MEASUREMENT = 0x02
+ EVENT_CAPTURE = 0x03 #Optimize results when other Ultrasonic sensors running
+ REQUEST_WARM_RESET = 0x04
+
+ def __init__(self, brick, port, check_compatible=True):
+ super(Ultrasonic, self).__init__(brick, port, check_compatible)
+ self.set_input_mode(Type.LOW_SPEED_9V, Mode.RAW)
+
+ def get_distance(self):
+ 'Function to get data from the ultrasonic sensor'
+ return self.read_value('measurement_byte_0')[0]
+
+ get_sample = get_distance
+
+ def get_measurement_units(self):
+ return self.read_value('measurement_units')[0].split('\0')[0]
+
+ def get_all_measurements(self):
+ "Returns all the past readings in measurement_byte_0 through 7"
+ return self.read_value('measurements')
+
+ def get_measurement_no(self, number):
+ "Returns measurement_byte_number"
+ if not 0 <= number < 8:
+ raise ValueError('Measurements are numbered 0 to 7, not ' + str(number))
+ base_address, format = self.I2C_ADDRESS['measurement_byte_0']
+ return self._i2c_query(base_address + number, format)[0]
+
+ def command(self, command):
+ self.write_value('command', (command, ))
+
+ def get_interval(self):
+ 'Get the sample interval for continuous measurement mode -- Unknown units'
+ return self.read_value('continuous_measurement_interval')
+
+ def set_interval(self, interval):
+ """Set the sample interval for continuous measurement mode.
+Unknown units; default is 1"""
+ self.write_value('continuous_measurement_interval', interval)
+
+Ultrasonic.add_compatible_sensor(None, 'LEGO', 'Sonar') #Tested with version 'V1.0'
+
+
+class Color20(BaseAnalogSensor):
+ def __init__(self, brick, port):
+ super(Color20, self).__init__(brick, port)
+ self.set_light_color(Type.COLORFULL)
+
+ def set_light_color(self, color):
+ """color should be one of the COLOR* Type namespace values, e.g. Type.COLORBLUE"""
+ self.set_input_mode(color, Mode.RAW)
+
+ def get_light_color(self):
+ """Returns one of the COLOR* Type namespace values, e.g. Type.COLORRED"""
+ return self.get_input_values().sensor_type
+
+ def get_reflected_light(self, color):
+ self.set_light_color(color)
+ return self.get_input_values().scaled_value
+
+ def get_color(self):
+ self.get_reflected_light(Type.COLORFULL)
+ return self.get_input_values().scaled_value
+
+ get_sample = get_color
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/sensor/hitechnic.py b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/sensor/hitechnic.py
new file mode 100644
index 0000000..3c152d3
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/sensor/hitechnic.py
@@ -0,0 +1,611 @@
+# nxt.sensor.hitechnic module -- Classes to read HiTechnic sensors
+# Copyright (C) 2006,2007 Douglas P Lau
+# Copyright (C) 2009 Marcus Wanner, Paulo Vieira, rhn
+# Copyright (C) 2010 rhn, Marcus Wanner, melducky, Samuel Leeman-Munk
+# Copyright (C) 2011 jerradgenson, Marcus Wanner
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+from .common import *
+from .digital import BaseDigitalSensor
+from .analog import BaseAnalogSensor
+
+
+class Compass(BaseDigitalSensor):
+ """Hitechnic compass sensor."""
+ I2C_ADDRESS = BaseDigitalSensor.I2C_ADDRESS.copy()
+ I2C_ADDRESS.update({'mode': (0x41, 'B'),
+ 'heading': (0x42, 'B'),
+ 'adder' : (0x43, 'B'),
+ })
+
+ class Modes:
+ MEASUREMENT = 0x00
+ CALIBRATION = 0x43
+ CALIBRATION_FAILED = 0x02
+
+ def get_heading(self):
+ """Returns heading from North in degrees."""
+
+ two_degree_heading = self.read_value('heading')[0]
+ adder = self.read_value('adder')[0]
+ heading = two_degree_heading * 2 + adder
+
+ return heading
+
+ get_sample = get_heading
+
+ def get_relative_heading(self,target=0):
+ rheading = self.get_sample()-target
+ if rheading > 180:
+ rheading -= 360
+ elif rheading < -180:
+ rheading += 360
+ return rheading
+
+ def is_in_range(self,minval,maxval):
+ """This deserves a little explanation:
+if max > min, it's straightforward, but
+if min > max, it switches the values of max and min
+and returns true if heading is NOT between the new max and min
+ """
+ if minval > maxval:
+ (maxval,minval) = (minval,maxval)
+ inverted = True
+ else:
+ inverted = False
+ heading = self.get_sample()
+ in_range = (heading > minval) and (heading < maxval)
+ #an xor handles the reversal
+ #a faster, more compact way of saying
+ #if !reversed return in_range
+ #if reversed return !in_range
+ return bool(inverted) ^ bool(in_range)
+
+ def get_mode(self):
+ return self.read_value('mode')[0]
+
+ def set_mode(self, mode):
+ if mode != self.Modes.MEASUREMENT and \
+ mode != self.Modes.CALIBRATION:
+ raise ValueError('Invalid mode specified: ' + str(mode))
+ self.write_value('mode', (mode, ))
+
+Compass.add_compatible_sensor(None, 'HiTechnc', 'Compass ') #Tested with version '\xfdV1.23 '
+Compass.add_compatible_sensor(None, 'HITECHNC', 'Compass ') #Tested with version '\xfdV2.1 '
+
+
+class Accelerometer(BaseDigitalSensor):
+ 'Object for Accelerometer sensors. Thanks to Paulo Vieira.'
+ I2C_ADDRESS = BaseDigitalSensor.I2C_ADDRESS.copy()
+ I2C_ADDRESS.update({'x_axis_high': (0x42, 'b'),
+ 'y_axis_high': (0x43, 'b'),
+ 'z_axis_high': (0x44, 'b'),
+ 'xyz_short': (0x42, '3b'),
+ 'all_data': (0x42, '3b3B')
+ })
+
+ class Acceleration:
+ def __init__(self, x, y, z):
+ self.x, self.y, self.z = x, y, z
+
+ def __init__(self, brick, port, check_compatible=True):
+ super(Accelerometer, self).__init__(brick, port, check_compatible)
+
+ def get_acceleration(self):
+ """Returns the acceleration along x, y, z axes. Units are unknown to me.
+ """
+ xh, yh, zh, xl, yl, zl = self.read_value('all_data')
+ x = xh << 2 + xl
+ y = yh << 2 + yl
+ z = zh << 2 + yl
+ return self.Acceleration(x, y, z)
+
+ get_sample = get_acceleration
+
+Accelerometer.add_compatible_sensor(None, 'HiTechnc', 'Accel. ')
+Accelerometer.add_compatible_sensor(None, 'HITECHNC', 'Accel. ') #Tested with version '\xfdV1.1 '
+
+
+class IRReceiver(BaseDigitalSensor):
+ """Object for HiTechnic IRReceiver sensors for use with LEGO Power Functions IR
+Remotes. Coded to HiTechnic's specs for the sensor but not tested. Please report
+whether this worked for you or not!
+ """
+ I2C_ADDRESS = BaseDigitalSensor.I2C_ADDRESS.copy()
+ I2C_ADDRESS.update({
+ 'm1A': (0x42, 'b'),
+ 'm1B': (0x43, 'b'),
+ 'm2A': (0x44, 'b'),
+ 'm2B': (0x45, 'b'),
+ 'm3A': (0x46, 'b'),
+ 'm3B': (0x47, 'b'),
+ 'm4A': (0x48, 'b'),
+ 'm4B': (0x49, 'b'),
+ 'all_data': (0x42, '8b')
+ })
+
+ class SpeedReading:
+ def __init__(self, m1A, m1B, m2A, m2B, m3A, m3B, m4A, m4B):
+ self.m1A, self.m1B, self.m2A, self.m2B, self.m3A, self.m3B, self.m4A, self.m4B = m1A, m1B, m2A, m2B, m3A, m3B, m4A, m4B
+ self.channel_1 = (m1A, m1B)
+ self.channel_2 = (m2A, m2B)
+ self.channel_3 = (m3A, m3B)
+ self.channel_4 = (m4A, m4B)
+
+ def __init__(self, brick, port, check_compatible=True):
+ super(IRReceiver, self).__init__(brick, port, check_compatible)
+
+ def get_speeds(self):
+ """Returns the motor speeds for motors A and B on channels 1-4.
+Values are -128, -100, -86, -72, -58, -44, -30, -16, 0, 16, 30, 44, 58, 72, 86
+and 100. -128 specifies motor brake mode. Note that no motors are actually
+being controlled here!
+ """
+ m1A, m1B, m2A, m2B, m3A, m3B, m4A, m4B = self.read_value('all_data')
+ return self.SpeedReading(m1A, m1B, m2A, m2B, m3A, m3B, m4A, m4B)
+
+ get_sample = get_speeds
+
+IRReceiver.add_compatible_sensor(None, 'HiTechnc', 'IRRecv ')
+IRReceiver.add_compatible_sensor(None, 'HITECHNC', 'IRRecv ')
+
+
+class IRSeekerv2(BaseDigitalSensor):
+ """Object for HiTechnic IRSeeker sensors. Coded to HiTechnic's specs for the sensor
+but not tested. Please report whether this worked for you or not!
+ """
+ I2C_ADDRESS = BaseDigitalSensor.I2C_ADDRESS.copy()
+ I2C_ADDRESS.update({
+ 'dspmode': (0x41, 'B'),
+ 'DC_direction': (0x42, 'B'),
+ 'DC_sensor_1': (0x43, 'B'),
+ 'DC_sensor_2': (0x44, 'B'),
+ 'DC_sensor_3': (0x45, 'B'),
+ 'DC_sensor_4': (0x46, 'B'),
+ 'DC_sensor_5': (0x47, 'B'),
+ 'DC_sensor_mean': (0x48, 'B'),
+ 'all_DC': (0x42, '7B'),
+ 'AC_direction': (0x49, 'B'),
+ 'AC_sensor_1': (0x4A, 'B'),
+ 'AC_sensor_2': (0x4B, 'B'),
+ 'AC_sensor_3': (0x4C, 'B'),
+ 'AC_sensor_4': (0x4D, 'B'),
+ 'AC_sensor_5': (0x4E, 'B'),
+ 'all_AC': (0x49, '6B')
+ })
+ I2C_DEV = 0x10 #different from standard 0x02
+
+ class DSPModes:
+ #Modes for modulated (AC) data.
+ AC_DSP_1200Hz = 0x00
+ AC_DSP_600Hz = 0x01
+
+ class _data:
+ def get_dir_brightness(self, direction):
+ "Gets the brightness of a given direction (1-9)."
+ if direction%2 == 1: #if it's an odd number
+ exec("val = self.sensor_%d" % ((direction-1)/2+1))
+ else:
+ exec("val = (self.sensor_%d+self.sensor_%d)/2" % (direction/2, (direction/2)+1))
+ return val
+
+ class DCData(_data):
+ def __init__(self, direction, sensor_1, sensor_2, sensor_3, sensor_4, sensor_5, sensor_mean):
+ self.direction, self.sensor_1, self.sensor_2, self.sensor_3, self.sensor_4, self.sensor_5, self.sensor_mean = direction, sensor_1, sensor_2, sensor_3, sensor_4, sensor_5, sensor_mean
+
+ class ACData(_data):
+ def __init__(self, direction, sensor_1, sensor_2, sensor_3, sensor_4, sensor_5):
+ self.direction, self.sensor_1, self.sensor_2, self.sensor_3, self.sensor_4, self.sensor_5 = direction, sensor_1, sensor_2, sensor_3, sensor_4, sensor_5
+
+
+ def __init__(self, brick, port, check_compatible=True):
+ super(IRSeekerv2, self).__init__(brick, port, check_compatible)
+
+ def get_dc_values(self):
+ """Returns the unmodulated (DC) values.
+ """
+ direction, sensor_1, sensor_2, sensor_3, sensor_4, sensor_5, sensor_mean = self.read_value('all_DC')
+ return self.DCData(direction, sensor_1, sensor_2, sensor_3, sensor_4, sensor_5, sensor_mean)
+
+ def get_ac_values(self):
+ """Returns the modulated (AC) values. 600Hz and 1200Hz modes can be selected
+between by using the set_dsp_mode() function.
+ """
+ direction, sensor_1, sensor_2, sensor_3, sensor_4, sensor_5 = self.read_value('all_AC')
+ return self.ACData(direction, sensor_1, sensor_2, sensor_3, sensor_4, sensor_5)
+
+ def get_dsp_mode(self):
+ return self.read_value('dspmode')[0]
+
+ def set_dsp_mode(self, mode):
+ self.write_value('dspmode', (mode, ))
+
+ get_sample = get_ac_values
+
+IRSeekerv2.add_compatible_sensor(None, 'HiTechnc', 'NewIRDir')
+IRSeekerv2.add_compatible_sensor(None, 'HITECHNC', 'NewIRDir')
+
+
+class EOPD(BaseAnalogSensor):
+ """Object for HiTechnic Electro-Optical Proximity Detection sensors.
+ """
+
+ # To be divided by processed value.
+ _SCALE_CONSTANT = 250
+
+ # Maximum distance the sensor can detect.
+ _MAX_DISTANCE = 1023
+
+ def __init__(self, brick, port):
+ super(EOPD, self).__init__(brick, port)
+ from math import sqrt
+ self.sqrt = sqrt
+
+ def set_range_long(self):
+ ''' Choose this mode to increase the sensitivity
+ of the EOPD sensor by approximately 4x. May
+ cause sensor overload.
+ '''
+
+ self.set_input_mode(Type.LIGHT_ACTIVE, Mode.RAW)
+
+ def set_range_short(self):
+ ''' Choose this mode to prevent the EOPD sensor from
+ being overloaded by white objects.
+ '''
+
+ self.set_input_mode(Type.LIGHT_INACTIVE, Mode.RAW)
+
+ def get_raw_value(self):
+ '''Unscaled value read from sensor.'''
+
+ return self._MAX_DISTANCE - self.get_input_values().raw_ad_value
+
+ def get_processed_value(self):
+ '''Derived from the square root of the raw value.'''
+
+ return self.sqrt(self.get_raw_value())
+
+ def get_scaled_value(self):
+ ''' Returns a value that will scale linearly as distance
+ from target changes. This is the method that should
+ generally be called to get EOPD sensor data.
+ '''
+
+ try:
+ result = self._SCALE_CONSTANT / self.get_processed_value()
+ return result
+
+ except ZeroDivisionError:
+ return self._SCALE_CONSTANT
+
+ get_sample = get_scaled_value
+
+
+class Colorv2(BaseDigitalSensor):
+ """Object for HiTechnic Color v2 Sensors. Coded to HiTechnic's specs for the sensor
+but not tested. Please report whether this worked for you or not!"""
+ I2C_ADDRESS = BaseDigitalSensor.I2C_ADDRESS.copy()
+ I2C_ADDRESS.update({
+ 'mode': (0x41, 'B'),
+ 'number': (0x42, 'B'),
+ 'red': (0x43, 'B'),
+ 'green': (0x44, 'B'),
+ 'blue': (0x45, 'B'),
+ 'white': (0x46, 'B'),
+ 'index': (0x47, 'B'),
+ 'normred': (0x48, 'B'),
+ 'normgreen': (0x49, 'B'),
+ 'normblue': (0x4A, 'B'),
+ 'all_data': (0x42, '9B'),
+ 'rawred': (0x42, '<H'),
+ 'rawgreen': (0x44, '<H'),
+ 'rawblue': (0x46, '<H'),
+ 'rawwhite': (0x48, '<H'),
+ 'all_raw_data': (0x42, '<4H')
+ })
+
+ class Modes:
+ ACTIVE = 0x00 #get measurements using get_active_color
+ PASSIVE = 0x01 #get measurements using get_passive_color
+ RAW = 0x03 #get measurements using get_passive_color
+ BLACK_CALIBRATION = 0x42 #hold away from objects, results saved in EEPROM
+ WHITE_CALIBRATION = 0x43 #hold in front of white surface, results saved in EEPROM
+ LED_POWER_LOW = 0x4C #saved in EEPROM, must calibrate after using
+ LED_POWER_HIGH = 0x48 #saved in EEPROM, must calibrate after using
+ RANGE_NEAR = 0x4E #saved in EEPROM, only affects active mode
+ RANGE_FAR = 0x46 #saved in EEPROM, only affects active mode, more susceptable to noise
+ FREQ_50 = 0x35 #saved in EEPROM, use when local wall power is 50Hz
+ FREQ_60 = 0x36 #saved in EEPROM, use when local wall power is 60Hz
+
+ class ActiveData:
+ def __init__(self, number, red, green, blue, white, index, normred, normgreen, normblue):
+ self.number, self.red, self.green, self.blue, self.white, self.index, self.normred, self.normgreen, self.normblue = number, red, green, blue, white, index, normred, normgreen, normblue
+
+ class PassiveData:
+ #also holds raw mode data
+ def __init__(self, red, green, blue, white):
+ self.red, self.green, self.blue, self.white = red, green, blue, white
+
+ def __init__(self, brick, port, check_compatible=True):
+ super(Colorv2, self).__init__(brick, port, check_compatible)
+
+ def get_active_color(self):
+ """Returns color values when in active mode.
+ """
+ number, red, green, blue, white, index, normred, normgreen, normblue = self.read_value('all_data')
+ return self.ActiveData(number, red, green, blue, white, index, normred, normgreen, normblue)
+
+ get_sample = get_active_color
+
+ def get_passive_color(self):
+ """Returns color values when in passive or raw mode.
+ """
+ red, green, blue, white = self.read_value('all_raw_data')
+ return self.PassiveData(red, green, blue, white)
+
+ def get_mode(self):
+ return self.read_value('mode')[0]
+
+ def set_mode(self, mode):
+ self.write_value('mode', (mode, ))
+
+Colorv2.add_compatible_sensor(None, 'HiTechnc', 'ColorPD')
+Colorv2.add_compatible_sensor(None, 'HITECHNC', 'ColorPD')
+Colorv2.add_compatible_sensor(None, 'HiTechnc', 'ColorPD ')
+Colorv2.add_compatible_sensor(None, 'HITECHNC', 'ColorPD ')
+
+
+class Gyro(BaseAnalogSensor):
+ 'Object for gyro sensors'
+#This class is for the hitechnic gryo sensor. When the gryo is not
+#moving there will be a constant offset that will change with
+#temperature and other ambient factors. The calibrate() function
+#takes the currect value and uses it to offset subsequesnt ones.
+
+ def __init__(self, brick, port):
+ super(Gyro, self).__init__(brick, port)
+ self.set_input_mode(Type.ANGLE, Mode.RAW)
+ self.offset = 0
+
+ def get_rotation_speed(self):
+ return self.get_input_values().scaled_value - self.offset
+
+ def set_zero(self, value):
+ self.offset = value
+
+ def calibrate(self):
+ self.set_zero(self.get_rotation_speed())
+
+ get_sample = get_rotation_speed
+
+
+class Prototype(BaseDigitalSensor):
+ """Object for HiTechnic sensor prototype boards. Coded to HiTechnic's specs but not
+tested. Please report whether this worked for you or not!
+ """
+ I2C_ADDRESS = BaseDigitalSensor.I2C_ADDRESS.copy()
+ I2C_ADDRESS.update({
+ 'A0': (0x42, '<H'),
+ 'A0': (0x44, '<H'),
+ 'A0': (0x46, '<H'),
+ 'A0': (0x48, '<H'),
+ 'A0': (0x4A, '<H'),
+ 'all_analog': (0x42, '<5H'),
+ 'digital_in': (0x4C, 'B'),
+ 'digital_out': (0x4D, 'B'),
+ 'digital_cont': (0x4E, 'B'),
+ 'sample_time': (0x4F, 'B'),
+ })
+
+ class Digital_Data():
+ """Container for 6 bits of digital data. Takes an integer or a list of six bools
+and can be converted into a list of bools or an integer."""
+ def __init__(self, pins):
+ if isinstance(pins, int):
+ self.dataint = pins
+ self.datalst = self.tolist(pins)
+ else:
+ self.dataint = self.toint(pins)
+ self.datalst = pins
+ self.d0, self.d1, self.d2, self.d3, self.d4, self.d5 = self.datalst
+
+ def tolist(self, val):
+ lst = []
+ for i in range(6):
+ lst.append(bool(val & 2**i))
+ return lst
+
+ def toint(self, lst):
+ val = 0
+ for i in range(6):
+ val += int(bool(lst[i])) * (2**i)
+ return val
+
+ def __int__(self):
+ return self.dataint
+
+ def __iter__(self):
+ return iter(self.datalst)
+
+ def __getitem__(self, i):
+ return self.datalst[i]
+
+ class Analog_Data():
+ def __init__(self, a0, a1, a2, a3, a4):
+ self.a0, self.a1, self.a2, self.a3, self.a4 = a0, a1, a2, a3, a4
+
+ def get_analog(self):
+ return Analog_Data(self.read_value('all_analog'))
+
+ def get_digital(self):
+ return Digital_Data(self.read_value('digital_in')[0])
+
+ def set_digital(self, pins):
+ """Can take a Digital_Data() object"""
+ self.write_value('digital_out', (int(pins), ))
+
+ def set_digital_modes(self, modes):
+ """Sets input/output mode of digital pins. Can take a Digital_Data() object."""
+ self.write_value('digital_cont', (int(modes), ))
+
+Prototype.add_compatible_sensor(None, 'HiTechnc', 'Proto ')
+
+
+class ServoCon(BaseDigitalSensor):
+ """Object for HiTechnic FIRST Servo Controllers. Coded to HiTechnic's specs for
+the sensor but not tested. Please report whether this worked for you or not!"""
+ I2C_ADDRESS = BaseDigitalSensor.I2C_ADDRESS.copy()
+ I2C_ADDRESS.update({
+ 'status': (0x40, 'B'),
+ 'steptime': (0x41, 'B'),
+ 's1pos': (0x42, 'B'),
+ 's2pos': (0x43, 'B'),
+ 's3pos': (0x44, 'B'),
+ 'p4pos': (0x45, 'B'),
+ 'p5pos': (0x46, 'B'),
+ 'p6pos': (0x47, 'B'),
+ 'pwm': (0x46, 'B'),
+ })
+
+ class Status:
+ RUNNING = 0x00 #all motors stopped
+ STOPPED = 0x01 #motor(s) moving
+
+ def __init__(self, brick, port, check_compatible=True):
+ super(ServoCon, self).__init__(brick, port, check_compatible)
+
+ def get_status(self):
+ """Returns the status of the motors. 0 for all stopped, 1 for
+some running.
+ """
+ return self.read_value('status')[0]
+
+ def set_step_time(self, time):
+ """Sets the step time (0-15).
+ """
+ self.write_value('steptime', (time, ))
+
+ def set_pos(self, num, pos):
+ """Sets the position of a server. num is the servo number (1-6),
+pos is the position (0-255).
+ """
+ self.write_value('s%dpos' % num, (pos, ))
+
+ def get_pwm(self):
+ """Gets the "PWM enable" value. The function of this value is
+nontrivial and can be found in the documentation for the sensor.
+ """
+ return self.read_value('pwm')[0]
+
+ def set_pwm(self, pwm):
+ """Sets the "PWM enable" value. The function of this value is
+nontrivial and can be found in the documentation for the sensor.
+ """
+ self.write_value('pwm', (pwm, ))
+
+ServoCon.add_compatible_sensor(None, 'HiTechnc', 'ServoCon')
+
+
+class MotorCon(BaseDigitalSensor):
+ """Object for HiTechnic FIRST Motor Controllers. Coded to HiTechnic's specs for
+the sensor but not tested. Please report whether this worked for you or not!"""
+ I2C_ADDRESS = BaseDigitalSensor.I2C_ADDRESS.copy()
+ I2C_ADDRESS.update({
+ 'm1enctarget': (0x40, '>l'),
+ 'm1mode': (0x44, 'B'),
+ 'm1power': (0x45, 'b'),
+ 'm2power': (0x46, 'b'),
+ 'm2mode': (0x47, 'B'),
+ 'm2enctarget': (0x48, '>l'),
+ 'm1enccurrent': (0x4c, '>l'),
+ 'm2enccurrent': (0x50, '>l'),
+ 'batteryvoltage': (0x54, '2B'),
+ 'm1gearratio': (0x56, 'b'),
+ 'm1pid': (0x57, '3B'),
+ 'm2gearratio': (0x5a, 'b'),
+ 'm2pid': (0x5b, '3B'),
+ })
+
+ class PID_Data():
+ def __init__(self, p, i, d):
+ self.p, self.i, self.d = p, i, d
+
+ def __init__(self, brick, port, check_compatible=True):
+ super(MotorCon, self).__init__(brick, port, check_compatible)
+
+ def set_enc_target(self, mot, val):
+ """Set the encoder target (-2147483648-2147483647) for a motor
+ """
+ self.write_value('m%denctarget'%mot, (val, ))
+
+ def get_enc_target(self, mot):
+ """Get the encoder target for a motor
+ """
+ return self.read_value('m%denctarget'%mot)[0]
+
+ def get_enc_current(self, mot):
+ """Get the current encoder value for a motor
+ """
+ return self.read_value('m%denccurrent'%mot)[0]
+
+ def set_mode(self, mot, mode):
+ """Set the mode for a motor. This value is a bit mask and you can
+find details about it in the sensor's documentation.
+ """
+ self.write_value('m%dmode'%mot, (mode, ))
+
+ def get_mode(self, mot):
+ """Get the mode for a motor. This value is a bit mask and you can
+find details about it in the sensor's documentation.
+ """
+ return self.read_value('m%dmode'%mot)[0]
+
+ def set_power(self, mot, power):
+ """Set the power (-100-100) for a motor
+ """
+ self.write_value('m%dpower'%mot, (power, ))
+
+ def get_power(self, mot):
+ """Get the power for a motor
+ """
+ return self.read_value('m%dpower'%mot)[0]
+
+ def set_gear_ratio(self, mot, ratio):
+ """Set the gear ratio for a motor
+ """
+ self.write_value('m%dgearratio'%mot, (ratio, ))
+
+ def get_gear_ratio(self, mot):
+ """Get the gear ratio for a motor
+ """
+ return self.read_value('m%dgearratio'%mot)[0]
+
+ def set_pid(self, mot, piddata):
+ """Set the PID coefficients for a motor. Takes data in
+MotorCon.PID_Data(p, i, d) format.
+ """
+ self.write_value('m%dpid'%mot, (piddata.p, piddata.i, piddata.d))
+
+ def get_pid(self, mot):
+ """Get the PID coefficients for a motor. Returns a PID_Data() object.
+ """
+ p, i, d = self.read_value('m%dpid'%mot)
+ return self.PID_Data(p, i, d)
+
+ def get_battery_voltage(self):
+ """Gets the battery voltage (in millivolts/20)
+ """
+ high, low = self.read_value('bateryvoltage')[0]
+ return high << 2 + low
+
+MotorCon.add_compatible_sensor(None, 'HiTechnc', 'MotorCon')
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/sensor/mindsensors.py b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/sensor/mindsensors.py
new file mode 100644
index 0000000..de6c7ee
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/sensor/mindsensors.py
@@ -0,0 +1,815 @@
+# nxt.sensor.mindsensors module -- Classes implementing Mindsensors sensors
+# Copyright (C) 2006,2007 Douglas P Lau
+# Copyright (C) 2009 Marcus Wanner, Paulo Vieira, rhn
+# Copyright (C) 2010 Marcus Wanner, MindSensors
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+
+from .common import *
+from .digital import BaseDigitalSensor, SensorInfo
+from .analog import BaseAnalogSensor
+
+
+class SumoEyes(BaseAnalogSensor):
+ """The class to control Mindsensors Sumo sensor. Warning: long range not
+ working for my sensor.
+ """
+ #range: 5-10cm
+ class Reading:
+ """Contains the reading of SumoEyes sensor. left and right can be True or
+ False. If True, then there is something there, if False, then it's empty
+ there.
+ """
+ def __init__(self, raw_reading):
+ self.raw = raw_reading
+ val = raw_reading.normalized_ad_value # FIXME: make it rely on raw_ad_value
+ right = 600 < val < 700
+ both = 700 <= val < 900
+ left = 300 < val < 400
+ self.left = left or both
+ self.right = right or both
+
+ def __str__(self):
+ return '(left: ' + str(self.left) + ', right: ' + str(self.right) + ')'
+
+ def __init__(self, brick, port, long_range=False):
+ super(SumoEyes, self).__init__(brick, port)
+ self.set_long_range(long_range)
+
+ def set_long_range(self, val):
+ """Sets if the sensor should operate in long range mode (12 inches) or
+ the short range mode (6 in). val should be True or False.
+ """
+ if val:
+ type_ = Type.LIGHT_INACTIVE
+ else:
+ type_ = Type.LIGHT_ACTIVE
+ self.set_input_mode(type_, Mode.RAW)
+
+ def get_sample(self):
+ """Returns the processed meaningful values of the sensor"""
+ return self.Reading(self.get_input_values())
+
+
+class Compassv2(BaseDigitalSensor):
+ """Class for the now-discontinued CMPS-Nx sensor. Also works with v1.1 sensors.
+Note that when using a v1.x sensor, some of the commands are not supported!
+To determine your sensor's version, use get_sensor_info().version"""
+ I2C_ADDRESS = BaseDigitalSensor.I2C_ADDRESS.copy()
+ I2C_ADDRESS.update({'command': (0x41, '<B'),
+ 'heading': (0x42, '<H'),
+ 'x_offset': (0x44, '<h'), #unsure about signedness for this one
+ 'y_offset': (0x46, '<h'), #and this one
+ 'x_range': (0x48, '<H'),
+ 'y_range': (0x4A, '<H'),
+ 'x_raw': (0x4C, '<H'), #and this one
+ 'y_raw': (0x4E, '<H'), #and this one
+ })
+
+ class Commands:
+ AUTO_TRIG_ON = 'A'
+ AUTO_TRIG_OFF = 'S'
+ MAP_HEADING_BYTE = 'B' # map heading to 0-255 range
+ MAP_HEADING_INTEGER = 'I' # map heading to 0-36000 (or 3600) range
+ SAMPLING_50_HZ = 'E' # set sampling frequency to 50 Hz
+ SAMPLING_60_HZ = 'U' # set sampling frequency to 60 Hz
+ SET_ADPA_MODE_ON = 'N' # set ADPA mode on
+ SET_ADPA_MODE_OFF = 'O' # set ADPA mode off
+ BEGIN_CALIBRATION = 'C' # begin calibration
+ DONE_CALIBRATION = 'D' # done with calibration
+ LOAD_USER_CALIBRATION = 'L' # load user calibration value
+
+ def __init__(self, brick, port, check_compatible=True):
+ super(Compassv2, self).__init__(brick, port, check_compatible)
+ self.command(self.Commands.MAP_HEADING_INTEGER)
+
+ def command(self, command):
+ value = ord(command)
+ self.write_value('command', (value, ))
+
+ def get_heading(self):
+ return self.read_value('heading')[0]
+
+ get_sample = get_heading
+
+Compassv2.add_compatible_sensor(None, 'mndsnsrs', 'CMPS')
+
+
+class DIST(BaseDigitalSensor):
+ """Class for the Distance Infrared Sensor"""
+ I2C_ADDRESS = BaseDigitalSensor.I2C_ADDRESS.copy()
+ I2C_ADDRESS.update({'command': (0x41, '<B'),
+ 'distance': (0x42, '<H'),
+ 'voltage': (0x44, '<H'),
+ 'type': (0x50, '<B'),
+ 'no_of_data_points': (0x51, '<B'),
+ 'min_distance': (0x52, '<H'),
+ 'max_distance': (0x54, '<H'),
+ })
+
+ class Commands:
+ TYPE_GP2D12 = '1' #GP2D12 sensor Module
+ TYPE_GP2D120 = '2' #Short range sensor Module
+ TYPE_GP2Y0A21YK = '3' #Medium range sensor Module
+ TYPE_GP2Y0A02YK = '4' #Long range sensor Module
+ TYPE_CUSTOM = '5' #Custom sensor Module
+ POWER_ON = 'E' #Sensor module power on
+ POWER_OFF = 'D' #Sensor module power offset
+ ADPA_ON = 'N' #ADPA mode on
+ ADPA_OFF = 'O' #ADPA mode off (default)
+
+ def command(self, command):
+ value = ord(command)
+ self.write_value('command', (value, ))
+
+ def get_distance(self):
+ return self.read_value('distance')[0]
+
+ get_sample = get_distance
+
+ def get_type(self):
+ return self.read_value('type')[0]
+
+ def get_voltage(self):
+ return self.read_value('voltage')[0]
+
+ def get_min_distance(self):
+ return self.read_value('min_distance')[0]
+
+ def get_max_distance(self):
+ return self.read_value('max_distance')[0]
+
+DIST.add_compatible_sensor(None, 'mndsnsrs', 'DIST')
+
+
+class RTC(BaseDigitalSensor):
+ """Class for the RealTime Clock sensor"""
+ #TODO: Create a function to set the clock
+ #Has no indentification
+ I2C_ADDRESS = BaseDigitalSensor.I2C_ADDRESS.copy()
+ I2C_ADDRESS.update({'seconds': (0x00, '<B'),
+ 'minutes': (0x01, '<B'),
+ 'hours': (0x02, '<B'),
+ 'day': (0x03, '<B'),
+ 'date': (0x04, '<B'),
+ 'month': (0x05, '<B'),
+ 'year': (0x06, '<B'),
+ })
+ I2C_DEV = 0xD0
+
+ def __init__(self, brick, port, check_compatible=False): #check_compatible must remain false due to no identification!
+ super(RTC, self).__init__(brick, port, check_compatible)
+
+ def get_seconds(self):
+ gs = self.read_value('seconds')[0]
+ gs2 = gs & 0xf # bitmasks
+ gs3 = gs & 0x70
+ gs3 = gs3 >> 4
+ return str(gs3) + str(gs2)
+
+ def get_minutes(self):
+ gm = self.read_value('minutes')[0]
+ gm2 = gm & 0xf
+ gm3 = gm & 0x70
+ gm3 = gm3 >> 4
+ return str(gm3) + str(gm2)
+
+ def get_hours(self):
+ gh = self.read_value('hours')[0]
+ gh2 = gh & 0xf
+ gh3 = gh & 0x30
+ gh3 = gh3 >> 4
+ return str(gh3) + str(gh2)
+
+ def get_day(self):
+ gwd = self.read_value('day')[0]
+ gwd = gwd & 0x07
+ return gwd
+
+ def get_month(self):
+ gmo = self.read_value('month')[0]
+ gmo2 = gmo & 0xf
+ gmo3 = gmo & 0x10
+ gmo3 = gmo3 >> 4
+ return str(gmo3) + str(gmo2)
+
+ def get_year(self):
+ """Last two digits (10 for 2010)"""
+ gy = self.read_value('year')[0]
+ gy2 = gy & 0xf
+ gy3 = gy & 0xF0
+ gy3 = gy3 >> 4
+ return str(gy3) + str(gy2)
+
+ def get_date(self):
+ gd = self.read_value('date')[0]
+ gd2 = gd & 0xf
+ gd3 = gd & 0x60
+ gd3 = gd3 >> 4
+ return str(gd3) + str(gd2)
+
+ def hour_mode(self, mode):
+ """Writes mode bit and re-enters hours, which is required"""
+ if mode == 12 or 24:
+ hm = self.read_value('hours')[0]
+ hm2 = hm & 0x40
+ hm2 = hm2 >> 6
+ if mode == 12 and hm2 == 0: #12_HOUR = 1
+ hm3 = hm + 64
+ self.write_value('hours', (hm3, ))
+ elif mode == 24 and hm2 == 1: #24_HOUR = 0
+ hm3 = hm - 64
+ self.write_value('hours', (hm3, ))
+ else:
+ print 'That mode is already selected!'
+ else:
+ raise ValueError('Must be 12 or 24!')
+
+ def get_mer(self):
+ mer = self.read_value('hours')[0]
+ mer2 = mer & 0x40
+ mer2 = mer2 >> 6
+ if mer2 == 1:
+ mer3 = mer & 0x20
+ mer3 = mer3 >> 0x10
+ return mer3
+ else:
+ print 'Cannot get mer! In 24-hour mode!'
+
+ def get_sample(self):
+ """Returns a struct_time() tuple which can be processed by the time module."""
+ import time
+ return time.struct_time((
+ int(self.get_year())+2000,
+ int(self.get_month()),
+ int(self.get_date()),
+ int(self.get_hours()),
+ int(self.get_minutes()),
+ int(self.get_seconds()),
+ int(self.get_day()),
+ 0, #Should be the Julian Day, but computing that is hard.
+ 0 #No daylight savings time to worry about here.
+ ))
+
+
+class ACCL(BaseDigitalSensor):
+ """Class for Accelerometer sensor"""
+ I2C_ADDRESS = BaseDigitalSensor.I2C_ADDRESS.copy()
+ I2C_ADDRESS.update({'sensitivity': (0x19, 'B'),
+ 'command': (0x41, 'B'),
+ 'x_tilt': (0x42, 'b'),
+ 'y_tilt': (0x43, 'b'),
+ 'z_tilt': (0x44, 'b'),
+ 'all_tilt': (0x42, '3b'),
+
+ 'x_accel': (0x45, '<h'),
+ 'y_accel': (0x47, '<h'),
+ 'z_accel': (0x49, '<h'),
+ 'all_accel': (0x45, '<3h'),
+
+ 'x_offset': (0x4B, '<h'),
+ 'x_range': (0x4D, '<h'),
+
+ 'y_offset': (0x4F, '<h'),
+ 'y_range': (0x51, '<h'),
+
+ 'z_offset': (0x53, '<h'),
+ 'z_range': (0x55, '<h'),
+ })
+
+ class Commands:
+ SENS_15G = '1' #that's 1.5...Alt. 2.5G (sensors older than V3.20)
+ SENS_2G = '2' #Alt .3.3G
+ SENS_4G = '3' #Alt. 6.7G
+ SENS_6G = '4' #Alt. 10G
+ X_CALIBRATION = 'X' #Acquire X point calibration
+ X_CAL_AND_END = 'x' #X point calibration and end calibration
+ Y_CALIBRATION = 'Y' #Acquire Y point calibration
+ Y_CAL_AND_END = 'y' #Y point calibration and end calibration
+ Z_CALIBRATION = 'Z' #Acquire Z point calibration
+ Z_CAL_AND_END = 'z' #Z point calibration and end calibration
+ CAL_RESET = 'R' #Reset to factory set calibration
+ ADPA_ON = 'N' #Set ADPA mode On
+ ADPA_OFF = 'O' #Set ADPA mode Off (default)
+
+ def __init__(self, brick, port, check_compatible=True):
+ super(ACCL, self).__init__(brick, port, check_compatible)
+
+ def command(self, command):
+ value = ord(command)
+ self.write_value('command', (value, ))
+
+ def get_sensitivity(self):
+ return chr(self.read_value('sensitivity')[0])
+
+ def get_tilt(self, axis):
+ xyz = str(axis) + '_tilt'
+ return self.read_value(xyz)[0]
+
+ def get_all_tilt(self):
+ return self.read_value('all_tilt')
+
+ def get_accel(self, axis):
+ xyz = str(axis) + '_accel'
+ return self.read_value(xyz)[0]
+
+ def get_all_accel(self):
+ return self.read_value('all_accel')
+
+ get_sample = get_all_accel
+
+ def get_offset(self, axis):
+ xyz = str(axis) + '_offset'
+ return self.read_value(xyz)[0]
+
+ def get_range(self, axis):
+ xyz = str(axis) + '_range'
+ return self.read_value(xyz)[0]
+
+ def set_offset(self, axis, value):
+ xyz = str(axis) + '_offset'
+ self.write_value(xyz, (value, ))
+
+ def set_range(self, axis, value):
+ xyz = str(axis) + '_range'
+ self.write_value(xyz, (value, ))
+
+ACCL.add_compatible_sensor(None, 'mndsnsrs', 'ACCL-NX') #Tested with version 'V3.20'
+
+
+class MTRMUX(BaseDigitalSensor):
+ """Class for RCX Motor Multiplexer sensor"""
+ I2C_ADDRESS = BaseDigitalSensor.I2C_ADDRESS.copy()
+ I2C_ADDRESS.update({'command' : (0x41, '<B'),
+ 'direction_m1': (0x42, '<B'),
+ 'speed_m1': (0x43, '<B'),
+ 'direction_m2': (0x44, '<B'),
+ 'speed_m2': (0x45, '<B'),
+ 'direction_m3': (0x46, '<B'),
+ 'speed_m3': (0x47, '<B'),
+ 'direction_m4': (0x48, '<B'),
+ 'speed_m4': (0x49, '<B'),
+ })
+ I2C_DEV = 0xB4
+
+ class Commands:
+ FLOAT = 0x00
+ FORWARD = 0x01
+ REVERSE = 0x02
+ BRAKE = 0x03
+
+ def __init__(self, brick, port, check_compatible=True):
+ super(MTRMUX, self).__init__(brick, port, check_compatible)
+
+ def command(self, command):
+ self.write_value('command', (command, ))
+
+ def set_direction(self, number, value):
+ addressname = 'direction_m' + str(number)
+ self.write_value(addressname, (value, ))
+
+ def set_speed(self, number, value):
+ addressname = 'speed_m' + str(number)
+ self.write_value(addressname, (value, ))
+
+ def get_direction(self, number):
+ addressname = 'direction_m' + str(number)
+ self.read_value(addressname)
+
+ def get_speed(self, number):
+ addressname = 'speed_m' + str(number)
+ self.read_value(addressname)
+
+MTRMUX.add_compatible_sensor(None, 'mndsnsrs', 'MTRMUX') #Tested with version 'V2.11'
+
+
+class LineLeader(BaseDigitalSensor):
+ """Class for Line Sensor Array"""
+ I2C_ADDRESS = BaseDigitalSensor.I2C_ADDRESS.copy()
+ I2C_ADDRESS.update({'command': (0x41, '<B'),
+ 'steering': (0x42, '<b'),
+ 'average': (0x43, '<B'),
+ 'result': (0x44, '<B'),
+ 'set_point': (0x45, '<B'),
+
+ 'kp': (0x46, '<B'),
+ 'ki': (0x47, '<B'),
+ 'kd': (0x48, '<B'),
+ 'kp_divisor':(0x61, '<B'),
+ 'ki_divisor':(0x62, '<B'),
+ 'kd_divisor':(0x63, '<B'),
+ #One byte for each sensor, so byte# = sensor#
+ 'calibrated_reading_byte1': (0x49, '<B'),
+ 'calibrated_reading_byte2': (0x4A, '<B'),
+ 'calibrated_reading_byte3': (0x4B, '<B'),
+ 'calibrated_reading_byte4': (0x4C, '<B'),
+ 'calibrated_reading_byte5': (0x4D, '<B'),
+ 'calibrated_reading_byte6': (0x4E, '<B'),
+ 'calibrated_reading_byte7': (0x4F, '<B'),
+ 'calibrated_reading_byte8': (0x50, '<B'),
+ 'all_calibrated_readings': (0x49, '<8B'),
+
+ 'w_read_limit':(0x51, '<H'),
+ 'b_read_limit':(0x59, '<B'),
+ 'w_cal_data1':(0x64, '<B'),
+ 'b_cal_data':(0x6C, '<B'),
+
+ 'uncal_sensor1_voltage_byte1':(0x74, '<B'),
+ 'uncal_sensor2_voltage_byte1':(0x76, '<B'),
+ 'uncal_sensor3_voltage_byte1':(0x78, '<B'),
+ 'uncal_sensor4_voltage_byte1':(0x7A, '<B'),
+ 'uncal_sensor5_voltage_byte1':(0x7C, '<B'),
+ 'uncal_sensor6_voltage_byte1':(0x7E, '<B'),
+ 'uncal_sensor7_voltage_byte1':(0x80, '<B'),
+ 'uncal_sensor8_voltage_byte1':(0x82, '<B'),
+ 'all_uncal_readings': (0x74, '<8B'),
+ })
+
+ class Commands:
+ CALIBRATE_WHITE = 'W'
+ CALIBRATE_BLACK = 'B'
+ SENSOR_SLEEP = 'D'
+ US_CONFIG = 'A'
+ EU_CONFIG = 'E'
+ UNI_CONFIG = 'U'
+ SENSOR_WAKE = 'P'
+ COLOR_INVERT = 'I'
+ COLOR_INVERT_REVERSE = 'R'
+ SNAPSHOT = 'S'
+
+ def __init__(self, brick, port, check_compatible=True):
+ super(LineLeader, self).__init__(brick, port, check_compatible)
+
+ def command(self, command):
+ value = ord(command)
+ self.write_value('command', (value, ))
+
+ def get_steering(self):
+ 'Value to add to the left and subtract from the right motor\'s power.'
+ return self.read_value('steering')[0]
+
+ def get_average(self):
+ 'Weighted average; greater as line is closer to right edge. 0 for no line.'
+ return self.read_value('average')[0]
+
+ def get_result(self):
+ 'Bitmap, one bit for each sensor'
+ return self.read_value('result')[0]
+
+ def set_set_point(self, value):
+ 'Average value for steering to gravitate to. 10 (left) to 80 (right).'
+ self.write_value('set_point', (value, ))
+
+ def set_pid(self, pid, value):
+ addressname = 'k' + str(pid)
+ self.write_value(addressname, (value, ))
+
+ def set_pid_divisor(self, pid, value):
+ addressname = 'k' + str(pid) + '_divisor'
+ self.write_value(addressname, (value, ))
+
+ def get_reading(self, number):
+ addressname = 'calibrated_reading_byte' + str(number)
+ return self.read_value(addressname)[0]
+
+ def get_reading_all(self):
+ return self.read_value('all_calibrated_readings')
+
+ get_sample = get_reading_all
+
+ def get_uncal_reading(self, number):
+ addressname = 'uncal_sensor' + str(number) + '_voltage_byte1'
+ return self.read_value(addressname)[0]
+
+ def get_uncal_all(self):
+ return self.read_value('all_uncal_readings')
+
+LineLeader.add_compatible_sensor(None, 'mndsnsrs', 'LineLdr') #Tested with version 'V1.16'
+
+
+class Servo(BaseDigitalSensor):
+ """Class for Servo sensors"""
+ I2C_ADDRESS = BaseDigitalSensor.I2C_ADDRESS.copy()
+ I2C_ADDRESS.update({'command' : (0x41, '<B'),
+
+ 'servo_1_pos': (0x42, '<H'),
+ 'servo_2_pos': (0x44, '<H'),
+ 'servo_3_pos': (0x46, '<H'),
+ 'servo_4_pos': (0x48, '<H'),
+ 'servo_5_pos': (0x4A, '<H'),
+ 'servo_6_pos': (0x4C, '<H'),
+ 'servo_7_pos': (0x4E, '<H'),
+ 'servo_8_pos': (0x50, '<H'),
+
+ 'servo_1_speed': (0x52, '<B'),
+ 'servo_2_speed': (0x53, '<B'),
+ 'servo_3_speed': (0x54, '<B'),
+ 'servo_4_speed': (0x55, '<B'),
+ 'servo_5_speed': (0x56, '<B'),
+ 'servo_6_speed': (0x57, '<B'),
+ 'servo_7_speed': (0x58, '<B'),
+ 'servo_8_speed': (0x59, '<B'),
+
+ 'servo_1_quick': (0x5A, '<B'),
+ 'servo_2_quick': (0x5B, '<B'),
+ 'servo_3_quick': (0x5C, '<B'),
+ 'servo_4_quick': (0x5D, '<B'),
+ 'servo_5_quick': (0x5E, '<B'),
+ 'servo_6_quick': (0x5F, '<B'),
+ 'servo_7_quick': (0x60, '<B'),
+ 'servo_8_quick': (0x61, '<B'),
+ })
+ I2C_DEV = 0xB0
+
+ COMMANDVALUES = {'R': (0x52), #Resume macro execution
+ 'S': (0x53), #reset initial position and speed
+ 'I1': (0x4931), #store initial position motor 1
+ 'I2': (0x4932), #store initial position motor 2
+ 'I3': (0x4933), #etc...
+ 'I4': (0x4934),
+ 'I5': (0x4935),
+ 'I6': (0x4936),
+ 'I7': (0x4937),
+ 'I8': (0x4938),
+ 'H': (0x48), #Halt macro
+ 'Gx': (0x4778), #not going to work yet x = variable
+ 'EM': (0x454d), #Edit Macro
+ 'P': (0x50), #Pause Macro
+ }
+
+ class Commands:
+ RESUME_MACRO = 'R'
+ RESET_POS_SPEED = 'S'
+ STORE_MOTOR_POS_1 = 'I1'
+ STORE_MOTOR_POS_2 = 'I2'
+ STORE_MOTOR_POS_3 = 'I3'
+ STORE_MOTOR_POS_4 = 'I4'
+ STORE_MOTOR_POS_5 = 'I5'
+ STORE_MOTOR_POS_6 = 'I6'
+ STORE_MOTOR_POS_7 = 'I7'
+ STORE_MOTOR_POS_8 = 'I8'
+ HALT_MACRO = 'H'
+ X_TO_VAR = 'Gx' #not going to work yet
+ EDIT_MACRO = 'EM'
+ PAUSE_MACRO = 'P'
+
+ def __init__(self, brick, port, check_compatible=True):
+ super(Servo, self).__init__(brick, port, check_compatible)
+
+ def command(self, command):
+ value = self.COMMANDVALUES[command]
+ self.write_value('command', (value, ))
+
+ def get_bat_level(self):
+ return self.read_value('command')[0]
+
+ def set_position(self, number, value):
+ addressname = 'servo_' + str(number) + '_pos'
+ self.write_value(addressname, (value, ))
+
+ def get_position(self, number):
+ return self.read_value('servo_' + str(number) + '_pos')[0]
+
+ def set_speed(self, number, value):
+ addressname = 'servo_' + str(number) + '_speed'
+ self.write_value(addressname, (value, ))
+
+ def get_speed(self, number):
+ return self.read_value('servo_' + str(number) + '_speed')[0]
+
+ def set_quick(self, number, value):
+ addressname = 'servo_' + str(number) + '_quick'
+ self.write_value(addressname, (value, ))
+
+Servo.add_compatible_sensor(None, 'mndsnsrs', 'NXTServo') #Tested with version 'V1.20'
+
+
+class MMX(BaseDigitalSensor):
+ """Class for MMX sensors"""
+ I2C_ADDRESS = BaseDigitalSensor.I2C_ADDRESS.copy()
+ I2C_ADDRESS.update({'command' : (0x41, '<B'),
+ #Motor Writes
+ 'encoder_1_target': (0x42, '<l'),
+ 'speed_1': (0x46, '<B'),
+ 'seconds_to_run_1': (0x47, '<B'),
+ 'command_b_1': (0x48, '<B'),
+ 'command_a_1': (0x49, '<B'),
+
+ 'encoder_2_target': (0x4A, '<l'),
+ 'speed_2': (0x4E, '<B'),
+ 'seconds_to_run_2': (0x4F, '<B'),
+ 'command_b_2': (0x50, '<B'),
+ 'command_a_2': (0x51, '<B'),
+ #Motor reads
+ 'encoder_1_pos': (0x62, '<H'),
+ 'encoder_2_pos': (0x66, '<H'),
+ 'status_m1': (0x72, '<B'),
+ 'status_m2': (0x73, '<B'),
+ 'tasks_running_m1': (0x76, '<H'),
+ 'tasks_running_m2': (0x77, '<H'),
+ #PID Control
+ 'p_encoder': (0x7A, '<H'),
+ 'i_encoder': (0x7C, '<H'),
+ 'd_encoder': (0x7E, '<H'),
+ 'p_speed': (0x80, '<H'),
+ 'i_speed': (0x82, '<H'),
+ 'd_speed': (0x84, '<H'),
+ 'pass_count': (0x86, '<B'),
+ 'tolerance': (0x87, '<B'),
+ })
+ I2C_DEV = 0x06
+
+ class Commands:
+ RESET_PARAMS_ENCODERS = 'R'
+ ISSUE_SYNCED_COMMANDS = 'S'
+ MOTOR_1_FLOAT_STOP = 'a'
+ MOTOR_2_FLOAT_STOP = 'b'
+ BOTH_FLOAT_STOP = 'c'
+ MOTOR_1_BRAKE_STOP = 'A'
+ MOTOR_2_BRAKE_STOP = 'B'
+ BOTH_BRAKE_STOP = 'C'
+ MOTOR_1_ENC_RESET = 'r'
+ MOTOR_2_ENC_RESET = 's'
+
+ def __init__(self, brick, port, check_compatible=True):
+ super(MMX, self).__init__(brick, port, check_compatible)
+
+ def command(self, command):
+ value = ord(command)
+ self.write_value('command', (value, ))
+
+ def get_bat_level(self):
+ return self.read_value('command')[0]
+
+ def set_encoder_target(self, motor_number, value):
+ addressname = 'encoder_' + str(motor_number) + '_target'
+ self.write_value(addressname, (value, ))
+
+ def set_speed(self, motor_number, value):
+ addressname = 'speed_' + str(motor_number)
+ self.write_value(addressname, (value, ))
+
+ def set_time_run(self, motor_number, seconds):
+ addressname = 'seconds_to_run_' + str(motor_number)
+ self.write_value(addressname, (seconds, ))
+
+ def command_b(self, motor_number, value):
+ addressname = 'command_b_' + str(motor_number)
+ self.write_value(addressname, (value, ))
+
+ def command_a(self, motor_number, bit_num, bit_val):
+ addressname = 'command_a_' + str(motor_number)
+ s = self.read_value(addressname)[0]
+ #I feel like there must be an easier way to write one bit...
+ val = bit_val << bit_num
+ if bit_val == 1:
+ value = val | s
+ self.write_value(addressname, (value, ))
+ return value #testing purposes
+ elif bit_val == 0:
+ val = 1
+ val = val << bit_num
+ val = val ^ 0xFF
+ value = val & s
+ self.write_value(addressname, (value, ))
+ return value
+
+ def get_encoder_pos(self, motor_number):
+ addressname = 'encoder_' +str(motor_number) +'_pos'
+ return self.read_value(addressname)[0]
+
+ def get_motor_status(self, motor_number, bit_num):
+ addressname = 'status_m' + str(motor_number)
+ s = self.read_value(addressname)[0]
+ x = 1
+ x = x << bit_num
+ value = x & s
+ value = value >> bit_num
+ return value
+
+ def get_tasks(self, motor_number):
+ addressname = 'tasks_running_m' + str(motor_number)
+ return self.read_value(addressname)[0]
+
+ def set_pid(self, pid, target, value):
+ addressname = str(pid) + '_' + str(target)
+ self.write_value(addressname, (value, ))
+
+ def set_pass_count(self, value):
+ self.write_value('pass_count', (value, ))
+
+ def set_tolerance(self, value):
+ self.write_value('tolerance', (value, ))
+
+MMX.add_compatible_sensor(None, 'mndsnsrs', 'NxTMMX') #Tested with version 'V1.01'
+
+
+class HID(BaseDigitalSensor):
+ """Class for Human Interface Device sensors.
+These are connected to a computer and look like a keyboard to it."""
+ I2C_ADDRESS = BaseDigitalSensor.I2C_ADDRESS.copy()
+ I2C_ADDRESS.update({'command' : (0x41, '<B'),
+ 'modifier' : (0x42, '<B'),
+ 'keyboard_data' : (0x43, '<B'),
+ })
+ I2C_DEV = 0x04
+
+ class Commands:
+ TRANSMIT = 'T'
+ ASCII_MODE = 'A'
+ DIRECT_MODE = 'D'
+
+ def __init__(self, brick, port, check_compatible=True):
+ super(HID, self).__init__(brick, port, check_compatible)
+
+ def command(self, command):
+ value = ord(command)
+ self.write_value('command', (value, ))
+
+ def set_modifier(self, mod):
+ self.write_value('modifier', (mod, ))
+
+ def write_data(self, data):
+ data = ord(data)
+ self.write_value('keyboard_data', (data, ))
+
+HID.add_compatible_sensor(None, 'mndsnsrs', 'NXTHID') #Tested with version 'V1.02'
+
+
+class PS2(BaseDigitalSensor):
+ I2C_ADDRESS = BaseDigitalSensor.I2C_ADDRESS.copy()
+ I2C_ADDRESS.update({'command' : (0x41, '<B'),
+ 'button_set_1': (0x42, '<B'),
+ 'button_set_2': (0x43, '<B'),
+ 'x_left_joystick': (0x44, '<b'),
+ 'y_left_joystick': (0x45, '<b'),
+ 'x_right_joystick': (0x46, '<b'),
+ 'y_right_joystick': (0x47, '<b'),
+ })
+
+ class ControllerState:
+ class Buttons:
+ left, down, right, up, square, cross, circle, triangle, r1, r2, r3, l1, l2, l3 = [0 for i in range(14)] #14 zeros
+ def __init__(self, buttons_1, buttons_2, left_x, left_y, right_x, right_y):
+ self.leftstick = (left_x, left_y)
+ self.rightstick = (right_x, right_y)
+ buttons_1 = ~buttons_1
+ buttons_2 = ~buttons_2
+ self.buttons = self.Buttons()
+ self.buttons.left = bool(buttons_1 & 0x80)
+ self.buttons.down = bool(buttons_1 & 0x40)
+ self.buttons.right = bool(buttons_1 & 0x20)
+ self.buttons.up = bool(buttons_1 & 0x10)
+ self.buttons.square = bool(buttons_2 & 0x80)
+ self.buttons.cross = bool(buttons_2 & 0x40)
+ self.buttons.circle = bool(buttons_2 & 0x20)
+ self.buttons.triangle = bool(buttons_2 & 0x10)
+ self.buttons.r1 = bool(buttons_2 & 0x08)
+ self.buttons.r2 = bool(buttons_2 & 0x02)
+ self.buttons.r3 = bool(buttons_1 & 0x04)
+ self.buttons.l1 = bool(buttons_2 & 0x04)
+ self.buttons.l2 = bool(buttons_2 & 0x01)
+ self.buttons.l3 = bool(buttons_1 & 0x02)
+
+ class Commands:
+ POWER_ON = 'E'
+ POWER_OFF = 'D'
+ DIGITAL_MODE = 'A'
+ ANALOG_MODE = 's'
+ ADPA_ON = 'N'
+ ADPA_OFF = 'O'
+
+ def __init__(self, brick, port, check_compatible=True):
+ super(PS2, self).__init__(brick, port, check_compatible)
+
+ def command(self, command):
+ value = ord(command)
+ self.write_value('command', (value, ))
+
+ def get_joystick(self, xy, lr):
+ addressname = str(xy) + '_' + str(lr) + '_joystick'
+ return self.read_value(addressname)[0]
+
+ def get_buttons(self, setnum):
+ addressname = 'button_set_' + str(setnum)
+ return self.read_value(addressname)[0]
+
+ def get_sample(self):
+ return self.ControllerState(
+ get_buttons(0),
+ get_buttons(1),
+ get_joystick('x', 'l'),
+ get_joystick('y', 'l'),
+ get_joystick('x', 'r'),
+ get_joystick('y', 'r'))
+
+PS2.add_compatible_sensor(None, 'mndsnsrs', 'PSPNX') #Tested with version 'V2.00'
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/system.py b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/system.py
new file mode 100644
index 0000000..a82d5d6
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/system.py
@@ -0,0 +1,297 @@
+# nxt.system module -- LEGO Mindstorms NXT system telegrams
+# Copyright (C) 2006 Douglas P Lau
+# Copyright (C) 2009 Marcus Wanner
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+'Use for communications regarding the NXT filesystem and such ***ADVANCED USERS ONLY***'
+
+def _create(opcode):
+ 'Create a simple system telegram'
+ from telegram import Telegram
+ return Telegram(False, opcode)
+
+def _create_with_file(opcode, fname):
+ tgram = _create(opcode)
+ tgram.add_filename(fname)
+ return tgram
+
+def _create_with_handle(opcode, handle):
+ tgram = _create(opcode)
+ tgram.add_u8(handle)
+ return tgram
+
+def open_read(opcode, fname):
+ return _create_with_file(opcode, fname)
+
+def _parse_open_read(tgram):
+ tgram.check_status()
+ handle = tgram.parse_u8()
+ n_bytes = tgram.parse_u32()
+ return (handle, n_bytes)
+
+def open_write(opcode, fname, n_bytes):
+ tgram = _create_with_file(opcode, fname)
+ tgram.add_u32(n_bytes)
+ return tgram
+
+def _parse_open_write(tgram):
+ tgram.check_status()
+ handle = tgram.parse_u8()
+ return handle
+
+def read(opcode, handle, n_bytes):
+ tgram = _create_with_handle(opcode, handle)
+ tgram.add_u16(n_bytes)
+ return tgram
+
+def _parse_read(tgram):
+ tgram.check_status()
+ handle = tgram.parse_u8()
+ n_bytes = tgram.parse_u16()
+ data = tgram.parse_string()
+ return (handle, n_bytes, data)
+
+def write(opcode, handle, data):
+ tgram = _create_with_handle(opcode, handle)
+ tgram.add_string(len(data), data)
+ return tgram
+
+def _parse_write(tgram):
+ tgram.check_status()
+ handle = tgram.parse_u8()
+ n_bytes = tgram.parse_u16()
+ return (handle, n_bytes)
+
+def close(opcode, handle):
+ return _create_with_handle(opcode, handle)
+
+def _parse_close(tgram):
+ tgram.check_status()
+ handle = tgram.parse_u8()
+ return handle
+
+def delete(opcode, fname):
+ return _create_with_file(opcode, fname)
+
+def _parse_delete(tgram):
+ tgram.check_status()
+ handle = tgram.parse_u8()
+ fname = tgram.parse_string()
+ return (handle, fname)
+
+def find_first(opcode, fname):
+ return _create_with_file(opcode, fname)
+
+def _parse_find(tgram):
+ tgram.check_status()
+ handle = tgram.parse_u8()
+ fname = tgram.parse_string(20)
+ n_bytes = tgram.parse_u32()
+ return (handle, fname, n_bytes)
+
+def find_next(opcode, handle):
+ return _create_with_handle(opcode, handle)
+
+def get_firmware_version(opcode):
+ return _create(opcode)
+
+def _parse_get_firmware_version(tgram):
+ tgram.check_status()
+ prot_minor = tgram.parse_u8()
+ prot_major = tgram.parse_u8()
+ prot_version = (prot_major, prot_minor)
+ fw_minor = tgram.parse_u8()
+ fw_major = tgram.parse_u8()
+ fw_version = (fw_major, fw_minor)
+ return (prot_version, fw_version)
+
+def open_write_linear(opcode, fname, n_bytes):
+ tgram = _create_with_file(opcode, fname)
+ tgram.add_u32(n_bytes)
+ return tgram
+
+def open_read_linear(opcode, fname):
+ return _create_with_file(opcode, fname)
+
+def _parse_open_read_linear(tgram):
+ tgram.check_status()
+ n_bytes = tgram.parse_u32()
+ return n_bytes
+
+def open_write_data(opcode, fname, n_bytes):
+ tgram = _create_with_file(opcode, fname)
+ tgram.add_u32(n_bytes)
+ return tgram
+
+def open_append_data(opcode, fname):
+ return _create_with_file(opcode, fname)
+
+def _parse_open_append_data(tgram):
+ tgram.check_status()
+ handle = tgram.parse_u8()
+ n_bytes = tgram.parse_u32()
+ return (handle, n_bytes)
+
+def request_first_module(opcode, mname):
+ return _create_with_file(opcode, mname)
+
+def _parse_request_module(tgram):
+ tgram.check_status()
+ handle = tgram.parse_u8()
+ mname = tgram.parse_string(20)
+ mod_id = tgram.parse_u32()
+ mod_size = tgram.parse_u32()
+ mod_iomap_size = tgram.parse_u16()
+ return (handle, mname, mod_id, mod_size, mod_iomap_size)
+
+def request_next_module(opcode, handle):
+ return _create_with_handle(opcode, handle)
+
+def close_module_handle(opcode, handle):
+ return _create_with_handle(opcode, handle)
+
+def read_io_map(opcode, mod_id, offset, n_bytes):
+ tgram = _create(opcode)
+ tgram.add_u32(mod_id)
+ tgram.add_u16(offset)
+ tgram.add_u16(n_bytes)
+ return tgram
+
+def _parse_read_io_map(tgram):
+ tgram.check_status()
+ mod_id = tgram.parse_u32()
+ n_bytes = tgram.parse_u16()
+ contents = tgram.parse_string()
+ return (mod_id, n_bytes, contents)
+
+def write_io_map(opcode, mod_id, offset, content):
+ tgram = _create(opcode)
+ tgram.add_u32(mod_id)
+ tgram.add_u16(offset)
+ tgram.add_u16(len(content))
+ tgram.add_string(len(content), content)
+ return tgram
+
+def _parse_write_io_map(tgram):
+ tgram.check_status()
+ mod_id = tgram.parse_u32()
+ n_bytes = tgram.parse_u16()
+ return (mod_id, n_bytes)
+
+def boot(opcode):
+ # Note: this command is USB only (no Bluetooth)
+ tgram = _create(opcode)
+ tgram.add_string(19, "Let's dance: SAMBA\0")
+ return tgram
+
+def _parse_boot(tgram):
+ tgram.check_status()
+ resp = tgram.parse_string()
+ # Resp should be 'Yes\0'
+ return resp
+
+def set_brick_name(opcode, bname):
+ tgram = _create(opcode)
+ if len(bname) > 15:
+ print "Warning! Brick name %s will be truncated to %s!" % (bname, bname[0:15])
+ bname = bname[0:15]
+ elif len(bname) < 15:
+ bname += '\x00' * (15-len(bname)) #fill the extra chars with nulls
+ tgram.add_string(len(bname), bname)
+ return tgram
+
+def _parse_set_brick_name(tgram):
+ tgram.check_status()
+
+def get_device_info(opcode):
+ return _create(opcode)
+
+def _parse_get_device_info(tgram):
+ tgram.check_status()
+ name = tgram.parse_string(15)
+ a0 = tgram.parse_u8()
+ a1 = tgram.parse_u8()
+ a2 = tgram.parse_u8()
+ a3 = tgram.parse_u8()
+ a4 = tgram.parse_u8()
+ a5 = tgram.parse_u8()
+ a6 = tgram.parse_u8()
+ # FIXME: what is a6 for?
+ address = '%02X:%02X:%02X:%02X:%02X:%02X' % (a0, a1, a2, a3, a4, a5)
+ signal_strength = tgram.parse_u32()
+ user_flash = tgram.parse_u32()
+ return (name, address, signal_strength, user_flash)
+
+def delete_user_flash(opcode):
+ return _create(opcode)
+
+def _parse_delete_user_flash(tgram):
+ tgram.check_status()
+
+def poll_command_length(opcode, buf_num):
+ tgram = _create(opcode)
+ tgram.add_u8(buf_num)
+ return tgram
+
+def _parse_poll_command_length(tgram):
+ buf_num = tgram.parse_u8()
+ tgram.check_status()
+ n_bytes = tgram.parse_u8()
+ return (buf_num, n_bytes)
+
+def poll_command(opcode, buf_num, n_bytes):
+ tgram = _create(opcode)
+ tgram.add_u8(buf_num)
+ tgram.add_u8(n_bytes)
+ return tgram
+
+def _parse_poll_command(tgram):
+ buf_num = tgram.parse_u8()
+ tgram.check_status()
+ n_bytes = tgram.parse_u8()
+ command = tgram.parse_string()
+ return (buf_num, n_bytes, command)
+
+def bluetooth_factory_reset(opcode):
+ # Note: this command is USB only (no Bluetooth)
+ return _create(opcode)
+
+def _parse_bluetooth_factory_reset(tgram):
+ tgram.check_status()
+
+OPCODES = {
+ 0x80: (open_read, _parse_open_read),
+ 0x81: (open_write, _parse_open_write),
+ 0x82: (read, _parse_read),
+ 0x83: (write, _parse_write),
+ 0x84: (close, _parse_close),
+ 0x85: (delete, _parse_delete),
+ 0x86: (find_first, _parse_find),
+ 0x87: (find_next, _parse_find),
+ 0x88: (get_firmware_version, _parse_get_firmware_version),
+ 0x89: (open_write_linear, _parse_open_write),
+ 0x8A: (open_read_linear, _parse_open_read_linear),
+ 0x8B: (open_write_data, _parse_open_write),
+ 0x8C: (open_append_data, _parse_open_append_data),
+ 0x90: (request_first_module, _parse_request_module),
+ 0x91: (request_next_module, _parse_request_module),
+ 0x92: (close_module_handle, _parse_close),
+ 0x94: (read_io_map, _parse_read_io_map),
+ 0x95: (write_io_map, _parse_write_io_map),
+ 0x97: (boot, _parse_boot),
+ 0x98: (set_brick_name, _parse_set_brick_name),
+ 0x9B: (get_device_info, _parse_get_device_info),
+ 0xA0: (delete_user_flash, _parse_delete_user_flash),
+ 0xA1: (poll_command_length, _parse_poll_command_length),
+ 0xA2: (poll_command, _parse_poll_command),
+ 0xA4: (bluetooth_factory_reset, _parse_bluetooth_factory_reset),
+}
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/telegram.py b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/telegram.py
new file mode 100644
index 0000000..1fc5b3e
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/telegram.py
@@ -0,0 +1,118 @@
+# nxt.telegram module -- LEGO Mindstorms NXT telegram formatting and parsing
+# Copyright (C) 2006 Douglas P Lau
+# Copyright (C) 2009 Marcus Wanner
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+'Used by nxt.system for sending telegrams to the NXT'
+
+from cStringIO import StringIO
+from struct import pack, unpack
+import nxt.error
+
+class InvalidReplyError(Exception):
+ pass
+
+class InvalidOpcodeError(Exception):
+ pass
+
+class Telegram(object):
+
+ TYPE = 0 # type byte offset
+ CODE = 1 # code byte offset
+ DATA = 2 # data byte offset
+
+ TYPE_NOT_DIRECT = 0x01 # system vs. direct type
+ TYPE_REPLY = 0x02 # reply type (from NXT brick)
+ TYPE_REPLY_NOT_REQUIRED = 0x80 # reply not required flag
+
+ def __init__(self, direct=False, opcode=0, reply_req=True, pkt=None):
+ if pkt:
+ self.pkt = StringIO(pkt)
+ self.typ = self.parse_u8()
+ self.opcode = self.parse_u8()
+ if not self.is_reply():
+ raise InvalidReplyError
+ if self.opcode != opcode:
+ raise InvalidOpcodeError, self.opcode
+ else:
+ self.pkt = StringIO()
+ typ = 0
+ if not direct:
+ typ |= Telegram.TYPE_NOT_DIRECT
+ if not reply_req:
+ typ |= Telegram.TYPE_REPLY_NOT_REQUIRED
+ self.add_u8(typ)
+ self.add_u8(opcode)
+
+ def __str__(self):
+ return self.pkt.getvalue()
+
+ def is_reply(self):
+ return self.typ == Telegram.TYPE_REPLY
+
+ def add_string(self, n_bytes, v):
+ self.pkt.write(pack('%ds' % n_bytes, v))
+
+ def add_filename(self, fname):
+ self.pkt.write(pack('20s', fname))
+
+ def add_s8(self, v):
+ self.pkt.write(pack('<b', v))
+
+ def add_u8(self, v):
+ self.pkt.write(pack('<B', v))
+
+ def add_s16(self, v):
+ self.pkt.write(pack('<h', v))
+
+ def add_u16(self, v):
+ self.pkt.write(pack('<H', v))
+
+ def add_s32(self, v):
+ self.pkt.write(pack('<i', v))
+
+ def add_u32(self, v):
+ self.pkt.write(pack('<I', v))
+
+ def parse_string(self, n_bytes=0):
+ if n_bytes:
+ return unpack('%ss' % n_bytes,
+ self.pkt.read(n_bytes))[0]
+ else:
+ return self.pkt.read()
+
+ def parse_s8(self):
+ return unpack('<b', self.pkt.read(1))[0]
+
+ def parse_u8(self):
+ return unpack('<B', self.pkt.read(1))[0]
+
+ def parse_s16(self):
+ return unpack('<h', self.pkt.read(2))[0]
+
+ def parse_u16(self):
+ return unpack('<H', self.pkt.read(2))[0]
+
+ def parse_s32(self):
+ return unpack('<i', self.pkt.read(4))[0]
+
+ def parse_u32(self):
+ return unpack('<I', self.pkt.read(4))[0]
+
+ def check_status(self):
+ nxt.error.check_status(self.parse_u8())
+
+import nxt.direct
+import nxt.system
+
+OPCODES = dict(nxt.system.OPCODES)
+OPCODES.update(nxt.direct.OPCODES)
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/usbsock.py b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/usbsock.py
new file mode 100644
index 0000000..5ff2b36
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/usbsock.py
@@ -0,0 +1,133 @@
+# nxt.usbsock module -- USB socket communication with LEGO Minstorms NXT
+# Copyright (C) 2006, 2007 Douglas P Lau
+# Copyright (C) 2009 Marcus Wanner
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+USB_BUFSIZE = 64
+
+try:
+ import fantomglue as usb
+except ImportError:
+ import pyusbglue as usb
+
+from nxt.brick import Brick
+
+class USBSock(object):
+ 'Object for USB connection to NXT'
+
+ bsize = 60 # USB socket block size
+
+ def __init__(self, device):
+ self.sock = usb.USBSocket(device)
+ self.debug = True
+
+ def __str__(self):
+ return 'USB (%s)' % (self.sock.device_name())
+
+ def connect(self):
+ 'Use to connect to NXT.'
+ if self.debug:
+ print 'Connecting via USB...'
+ self.sock.connect()
+ return Brick(self)
+
+ def close(self):
+ 'Use to close the connection.'
+ if self.debug:
+ print 'Closing USB connection...'
+ self.sock.close()
+ #self.sock = None
+ if self.debug:
+ print 'USB connection closed.'
+
+ def send(self, data):
+ 'Use to send raw data over USB connection ***ADVANCED USERS ONLY***'
+ if self.debug:
+ print 'Send:',
+ print ':'.join('%02x' % ord(c) for c in data)
+ self.sock.send(data)
+
+ def recv(self, num_bytes=USB_BUFSIZE):
+ 'Use to recieve raw data over USB connection ***ADVANCED USERS ONLY***'
+ data = self.sock.recv(num_bytes)
+ if self.debug:
+ print 'Recv:',
+ print ':'.join('%02x' % ord(c) for c in data)
+ return data
+
+ def __del__(self):
+ """Destroy interface."""
+ if self.sock is not None:
+ del self.sock
+ if self.debug:
+ print 'Deleted USBSocket.'
+
+
+def _check_brick(arg, value):
+ return arg is None or arg == value
+
+def find_bricks(host=None, name=None):
+ get_info = False
+ 'Use to look for NXTs connected by USB only. ***ADVANCED USERS ONLY***'
+ for d in usb.find_devices(lookup_names=True):
+ if get_info:
+ # pyfantom specific debug info
+ print " firmware version:", d.get_firmware_version()
+ print " get device info:", d.get_device_info()
+ rs = d.get_resource_string()
+ print " resource string:", rs
+ # FIXME: probably should check host and name
+ yield USBSock(d)
+
+if __name__ == '__main__':
+ write_read = True
+ socks = find_bricks()
+ for s in socks:
+ #llsocks = usb.find_devices()
+ #for ls in llsocks:
+ #s = USBSock(ls)
+ print s.sock
+ brick = s.connect()
+ if write_read:
+ import struct
+ # Write VERSION SYS_CMD.
+ # Query:
+ # SYS_CMD: 0x01
+ # VERSION: 0x88
+ cmd = struct.pack('2B', 0x01, 0x88)
+ brick.sock.send(cmd)
+ #s.send(cmd)
+ #s.sock.send(cmd)
+ print "wrote", len(cmd)
+ # Response:
+ # REPLY_CMD: 0x02
+ # VERSION: 0x88
+ # SUCCESS: 0x00
+ # PROTOCOL_VERSION minor
+ # PROTOCOL_VERSION major
+ # FIRMWARE_VERSION minor
+ # FIRMWARE_VERSION major
+ rep = brick.sock.recv(7)
+ #rep = s.recv(7)
+ #rep = s.sock.recv(7)
+ print "read", struct.unpack('%dB' % len(rep), rep)
+ # Same thing, without response.
+ #cmd = struct.pack('2B', 0x81, 0x88)
+ #brick.sock.send(cmd)
+ #print "wrote", cmd
+ #rep = brick.sock.recv()
+ #print "read", struct.unpack('%dB' % len(rep), rep)
+ #s.close()
+ #del s
+ #brick.sock.close()
+ del brick
+
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/utils.py b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/utils.py
new file mode 100644
index 0000000..98ba6df
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/utils.py
@@ -0,0 +1,33 @@
+# nxt.utils module -- Generic utilities to support other modules
+# Copyright (C) 2010 Vladimir Moskva
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+from collections import defaultdict
+
+def parse_command_line_arguments(arguments):
+ keyword_parameters = defaultdict(lambda: None)
+ parameters = []
+ current_key = None
+
+ for argument in arguments[1:]:
+ if argument in ('-h', '--host'):
+ current_key = 'host'
+ else:
+ if current_key is not None:
+ if argument.startswith('-'):
+ raise Exception('Invalid arguments')
+ keyword_parameters[current_key] = argument
+ current_key = None
+ else:
+ parameters.append(argument)
+ return parameters, keyword_parameters
+
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/scripts/nxt_filer b/AT91SAM7S256/armdebug/nxt-python-fantom/scripts/nxt_filer
new file mode 100644
index 0000000..767d268
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/scripts/nxt_filer
@@ -0,0 +1,142 @@
+#!/usr/bin/env python
+#
+# nxt_filer program -- Simple GUI to manage files on a LEGO Mindstorms NXT
+# Copyright (C) 2006 Douglas P Lau
+# Copyright (C) 2010 rhn
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+import cStringIO
+import gtk
+import os.path
+import urllib2
+import sys
+
+import nxt.locator
+from nxt.brick import FileFinder, FileReader, FileWriter
+from nxt.utils import parse_command_line_arguments
+
+def read_file(b, fname):
+ with FileReader(b, fname) as r:
+ with open(fname, 'wb') as f:
+ for data in r:
+ f.write(data)
+
+class NXTListing(gtk.ListStore):
+
+ def __init__(self, brick):
+ gtk.ListStore.__init__(self, str, str)
+ self.set_sort_column_id(0, gtk.SORT_ASCENDING)
+ self.populate(brick, '*.*')
+
+ def populate(self, brick, pattern):
+ f = FileFinder(brick, pattern)
+ for (fname, size) in f:
+ self.append((fname, str(size)))
+
+def write_file(b, fname, data):
+ w = FileWriter(b, fname, len(data))
+ print 'Pushing %s (%d bytes) ...' % (fname, w.size),
+ sys.stdout.flush()
+ w.write(data)
+ print 'wrote %d bytes' % len(data)
+ w.close()
+
+def write_files(b, names):
+ for fname in names.split('\r\n'):
+ if fname:
+ print 'File:', fname
+ bname = os.path.basename(fname)
+ url = urllib2.urlopen(fname)
+ try:
+ data = url.read()
+ finally:
+ url.close()
+ print 'name %s, size: %d ' % (bname, len(data))
+ write_file(b, bname, data)
+
+class NXT_Filer(gtk.Window):
+ TARGETS = gtk.target_list_add_uri_targets()
+
+ def __init__(self, brick):
+ gtk.Window.__init__(self)
+ self.brick = brick
+ self.set_border_width(6)
+ self.nxt_model = NXTListing(brick)
+ h = gtk.HBox()
+ h.pack_start(self.make_file_panel(str(brick.sock),
+ self.nxt_model), True)
+ self.add(h)
+ self.connect('destroy', self.quit)
+
+ def make_file_list(self):
+ tv = gtk.TreeView()
+ tv.set_headers_visible(True)
+ tv.set_property('fixed_height_mode', True)
+ r = gtk.CellRendererText()
+ c = gtk.TreeViewColumn('File name', r, text=0)
+ c.set_fixed_width(200)
+ c.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
+ tv.append_column(c)
+ r = gtk.CellRendererText()
+ c = gtk.TreeViewColumn('Bytes', r, text=1)
+ c.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
+ c.set_fixed_width(80)
+ tv.append_column(c)
+
+# tv.enable_model_drag_source(gtk.gdk.BUTTON1_MASK, self.TARGETS,
+# gtk.gdk.ACTION_DEFAULT | gtk.gdk.ACTION_MOVE)
+ tv.enable_model_drag_dest(self.TARGETS, gtk.gdk.ACTION_COPY)
+# tv.connect("drag_data_get", self.drag_data_get_data)
+ tv.connect("drag_data_received", self.drag_data_received_data)
+
+ return tv
+
+ def make_file_panel(self, name, model):
+ v = gtk.VBox()
+ v.pack_start(gtk.Label(name), False)
+ tv = self.make_file_list()
+ tv.set_model(model)
+ s = gtk.ScrolledWindow()
+ s.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
+ s.add(tv)
+ s.set_border_width(2)
+ v.pack_start(s, True)
+ return v
+
+ def drag_data_get_data(self, treeview, context, selection, target_id,
+ etime):
+ treeselection = treeview.get_selection()
+ model, iter = treeselection.get_selected()
+ data = model.get_value(iter, 0)
+ print data
+ selection.set(selection.target, 8, data)
+
+ def drag_data_received_data(self, treeview, context, x, y, selection,
+ info, etime):
+ if context.action == gtk.gdk.ACTION_COPY:
+ write_files(self.brick, selection.data)
+ # FIXME: update file listing after writing files
+ # FIXME: finish context
+
+ def quit(self, w):
+ 'Quit the program'
+ self.brick.sock.close()
+ gtk.main_quit()
+
+if __name__ == '__main__':
+ # FIXME: add dialog with progress bar when scanning bluetooth devices
+ arguments, keyword_arguments = parse_command_line_arguments(sys.argv)
+
+ brick = nxt.locator.find_one_brick(keyword_arguments['host'])
+ win = NXT_Filer(brick)
+ win.show_all()
+ gtk.main()
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/scripts/nxt_push b/AT91SAM7S256/armdebug/nxt-python-fantom/scripts/nxt_push
new file mode 100644
index 0000000..395b38f
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/scripts/nxt_push
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+#
+# nxt_push program -- Push a file to a LEGO Mindstorms NXT brick
+# Copyright (C) 2006 Douglas P Lau
+# Copyright (C) 2010 rhn
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+import sys
+import nxt.locator
+from nxt.brick import FileWriter
+from nxt.error import FileNotFound
+from nxt.utils import parse_command_line_arguments
+
+def _write_file(b, fname, data):
+ w = FileWriter(b, fname, len(data))
+ print 'Pushing %s (%d bytes) ...' % (fname, w.size),
+ sys.stdout.flush()
+ w.write(data)
+ print 'wrote %d bytes' % len(data)
+ w.close()
+
+def write_file(b, fname):
+ f = open(fname)
+ data = f.read()
+ f.close()
+ try:
+ b.delete(fname)
+ print 'Overwriting %s on NXT' % fname
+ except FileNotFound:
+ pass
+ _write_file(b, fname, data)
+
+if __name__ == '__main__':
+ arguments, keyword_arguments = parse_command_line_arguments(sys.argv)
+
+ brick = nxt.locator.find_one_brick(keyword_arguments['host'])
+ for filename in arguments:
+ write_file(brick, filename)
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/scripts/nxt_test b/AT91SAM7S256/armdebug/nxt-python-fantom/scripts/nxt_test
new file mode 100644
index 0000000..5cc0fcd
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/scripts/nxt_test
@@ -0,0 +1,33 @@
+#!/usr/bin/env python
+
+#Lists various information from all bricks it can connect to.
+
+import sys, traceback
+import nxt.locator
+import nxt.brick
+
+b = None
+socks = nxt.locator.find_bricks()
+for sock in socks:
+ try:
+ b = sock.connect()
+
+ name, host, signal_strength, user_flash = b.get_device_info()
+ print 'NXT brick name: %s' % name
+ print 'Host address: %s' % host
+ print 'Bluetooth signal strength: %s' % signal_strength
+ print 'Free user flash: %s' % user_flash
+ prot_version, fw_version = b.get_firmware_version()
+ print 'Protocol version %s.%s' % prot_version
+ print 'Firmware version %s.%s' % fw_version
+ millivolts = b.get_battery_level()
+ print 'Battery level %s mV' % millivolts
+ except:
+ print "Error with brick:"
+ traceback.print_tb(sys.exc_info()[2])
+ print str(sys.exc_info()[1])
+ if b:
+ b.sock.close()
+
+if not b:
+ print "No bricks found!"
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/scripts/pyenv-nxt_test b/AT91SAM7S256/armdebug/nxt-python-fantom/scripts/pyenv-nxt_test
new file mode 100755
index 0000000..c78061c
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/scripts/pyenv-nxt_test
@@ -0,0 +1,3 @@
+#!/bin/sh
+export PYTHONPATH=~/gitrepo/armdebug/nxt-python-fantom
+arch -i386 /usr/bin/python2.6 ~/gitrepo/armdebug/nxt-python-fantom/scripts/nxt_test
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/scripts/pyenv-syspython b/AT91SAM7S256/armdebug/nxt-python-fantom/scripts/pyenv-syspython
new file mode 100755
index 0000000..cea6c52
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/scripts/pyenv-syspython
@@ -0,0 +1,3 @@
+#!/bin/sh
+export PYTHONPATH=~/gitrepo/armdebug/nxt-python-fantom
+arch -i386 /usr/bin/python2.6
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/setup.py b/AT91SAM7S256/armdebug/nxt-python-fantom/setup.py
new file mode 100644
index 0000000..9899347
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/setup.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+
+from distutils.core import setup
+
+try:
+ readme = open('README', 'r')
+ ldesc = readme.read(8192)
+ readme.close()
+except:
+ ldesc = ""
+
+setup(
+ name='nxt-python',
+ version='2.1.0',
+ author='Marcus Wanner',
+ author_email='marcusw@cox.net',
+ description='LEGO Mindstorms NXT Control Package',
+ url='http://code.google.com/p/nxt-python/',
+ license='Gnu GPL v3',
+ packages=['nxt', 'nxt.sensor'],
+ scripts=['scripts/nxt_push', 'scripts/nxt_test', 'scripts/nxt_filer'],
+ long_description=ldesc
+)