embedded RTOS class project.
Dependencies: C12832_lcd USBDevice mbed-rtos mbed mmSPI_RTOS watchdog_RTOS
Fork of RTOS_project_fork_01 by
mmPython/mmUI.txt@0:8e898e1270d6, 2013-09-17 (annotated)
- Committer:
- gatedClock
- Date:
- Tue Sep 17 19:42:49 2013 +0000
- Revision:
- 0:8e898e1270d6
title.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gatedClock | 0:8e898e1270d6 | 1 | #!/usr/bin/python -tt # tt: detect mixed space/tab. |
gatedClock | 0:8e898e1270d6 | 2 | #---copyright-----------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 3 | # licensed for personal and academic use. |
gatedClock | 0:8e898e1270d6 | 4 | # commercial use must be approved by the account-holder of |
gatedClock | 0:8e898e1270d6 | 5 | # gated.clock@gmail.com |
gatedClock | 0:8e898e1270d6 | 6 | #-------imports---------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 7 | from Tkinter import * # Tk graphics. |
gatedClock | 0:8e898e1270d6 | 8 | import mmUSBserial # USB Serial object. |
gatedClock | 0:8e898e1270d6 | 9 | from mmUSBserial import * |
gatedClock | 0:8e898e1270d6 | 10 | import time # Time object. |
gatedClock | 0:8e898e1270d6 | 11 | from time import time, sleep |
gatedClock | 0:8e898e1270d6 | 12 | import threading # Threading object. |
gatedClock | 0:8e898e1270d6 | 13 | import tkFileDialog # File-select dialog object.' |
gatedClock | 0:8e898e1270d6 | 14 | import os # import os library. |
gatedClock | 0:8e898e1270d6 | 15 | #=======class===================================#=============================== |
gatedClock | 0:8e898e1270d6 | 16 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 17 | ''' |
gatedClock | 0:8e898e1270d6 | 18 | licensed for personal and accedemic use. |
gatedClock | 0:8e898e1270d6 | 19 | commercial use must be approved by the account-holder of |
gatedClock | 0:8e898e1270d6 | 20 | gated.clock@gmail.com |
gatedClock | 0:8e898e1270d6 | 21 | ''' |
gatedClock | 0:8e898e1270d6 | 22 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 23 | ''' |
gatedClock | 0:8e898e1270d6 | 24 | description: |
gatedClock | 0:8e898e1270d6 | 25 | |
gatedClock | 0:8e898e1270d6 | 26 | python/Tk code for interfacing with the mbed.org system. |
gatedClock | 0:8e898e1270d6 | 27 | this code provides a UI which is used to communicate over USB |
gatedClock | 0:8e898e1270d6 | 28 | to the mbed.org processor, and in turn the toy CPU programmed |
gatedClock | 0:8e898e1270d6 | 29 | into the altera device. |
gatedClock | 0:8e898e1270d6 | 30 | |
gatedClock | 0:8e898e1270d6 | 31 | this code provides a UI which is used to monitor and write-to the |
gatedClock | 0:8e898e1270d6 | 32 | toy CPU's registers and its main memory. |
gatedClock | 0:8e898e1270d6 | 33 | |
gatedClock | 0:8e898e1270d6 | 34 | I/O capability: |
gatedClock | 0:8e898e1270d6 | 35 | |
gatedClock | 0:8e898e1270d6 | 36 | * R0 write/read. |
gatedClock | 0:8e898e1270d6 | 37 | * R1 write/read. |
gatedClock | 0:8e898e1270d6 | 38 | * R2 write/read. |
gatedClock | 0:8e898e1270d6 | 39 | * R3 write/read. |
gatedClock | 0:8e898e1270d6 | 40 | * PC write/read. (that's 'Program Counter'.) |
gatedClock | 0:8e898e1270d6 | 41 | * IR write/read. (that's 'Instruction Register'.) |
gatedClock | 0:8e898e1270d6 | 42 | * MM address. (that's 'Main Memory.') |
gatedClock | 0:8e898e1270d6 | 43 | * MM content. |
gatedClock | 0:8e898e1270d6 | 44 | |
gatedClock | 0:8e898e1270d6 | 45 | Button Controls: |
gatedClock | 0:8e898e1270d6 | 46 | |
gatedClock | 0:8e898e1270d6 | 47 | * USB Connect/Disconnect. |
gatedClock | 0:8e898e1270d6 | 48 | * Register Read. |
gatedClock | 0:8e898e1270d6 | 49 | * Register Write. |
gatedClock | 0:8e898e1270d6 | 50 | * Main Memory Read. |
gatedClock | 0:8e898e1270d6 | 51 | * Main Memory Write. |
gatedClock | 0:8e898e1270d6 | 52 | * Main Memory Load-From-File. |
gatedClock | 0:8e898e1270d6 | 53 | * Main Memory Dump-To-File. |
gatedClock | 0:8e898e1270d6 | 54 | * Step CPU. |
gatedClock | 0:8e898e1270d6 | 55 | * Run-Fast, Run-Slow, Stop CPU. |
gatedClock | 0:8e898e1270d6 | 56 | * Run Test. |
gatedClock | 0:8e898e1270d6 | 57 | * Exit. |
gatedClock | 0:8e898e1270d6 | 58 | |
gatedClock | 0:8e898e1270d6 | 59 | ''' |
gatedClock | 0:8e898e1270d6 | 60 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 61 | if (1): # allow further indentation. |
gatedClock | 0:8e898e1270d6 | 62 | class mmUI: # UI class. |
gatedClock | 0:8e898e1270d6 | 63 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 64 | def __init__(self,masterWidget): # constructor. |
gatedClock | 0:8e898e1270d6 | 65 | |
gatedClock | 0:8e898e1270d6 | 66 | self.__masterWidget = masterWidget # promote to object scope. |
gatedClock | 0:8e898e1270d6 | 67 | |
gatedClock | 0:8e898e1270d6 | 68 | # master widget title. |
gatedClock | 0:8e898e1270d6 | 69 | self.__masterWidget.wm_title("CPU Control") |
gatedClock | 0:8e898e1270d6 | 70 | |
gatedClock | 0:8e898e1270d6 | 71 | self.__frame = Frame(masterWidget) # create frame widget. |
gatedClock | 0:8e898e1270d6 | 72 | self.__frame.grid(column=0, row=0) # use grid packer. |
gatedClock | 0:8e898e1270d6 | 73 | |
gatedClock | 0:8e898e1270d6 | 74 | self.__connected = 0 # not yet __connected to USB. |
gatedClock | 0:8e898e1270d6 | 75 | self.__isRunning = 0 # program execution not running. |
gatedClock | 0:8e898e1270d6 | 76 | self.__testRunning = 0 # test mode not runing. |
gatedClock | 0:8e898e1270d6 | 77 | self.__testIter = 0 # test mode iteration count. |
gatedClock | 0:8e898e1270d6 | 78 | self.__sleepVal = 0.04 # serial transceive sleep. 3 works. |
gatedClock | 0:8e898e1270d6 | 79 | |
gatedClock | 0:8e898e1270d6 | 80 | |
gatedClock | 0:8e898e1270d6 | 81 | self.uiR0 (0, 1, 10) # label/entry widgets (x, y, width) |
gatedClock | 0:8e898e1270d6 | 82 | self.uiR1 (0, 2, 10) |
gatedClock | 0:8e898e1270d6 | 83 | self.uiR2 (0, 3, 10) |
gatedClock | 0:8e898e1270d6 | 84 | self.uiR3 (0, 4, 10) |
gatedClock | 0:8e898e1270d6 | 85 | self.uiPC (0, 5, 10) |
gatedClock | 0:8e898e1270d6 | 86 | self.uiIR (0, 6, 10) |
gatedClock | 0:8e898e1270d6 | 87 | self.uimmADR (0, 7, 10) |
gatedClock | 0:8e898e1270d6 | 88 | self.uimmVAL (0, 8, 10) |
gatedClock | 0:8e898e1270d6 | 89 | |
gatedClock | 0:8e898e1270d6 | 90 | self.uiConnect (3, 1, 8) # button widgets (x, y, width) |
gatedClock | 0:8e898e1270d6 | 91 | self.uiRegRead (3, 2, 8) |
gatedClock | 0:8e898e1270d6 | 92 | self.uiRegWrite(3, 3, 8) |
gatedClock | 0:8e898e1270d6 | 93 | self.uimmRead (3, 4, 8) |
gatedClock | 0:8e898e1270d6 | 94 | self.uimmWrite (3, 5, 8) |
gatedClock | 0:8e898e1270d6 | 95 | self.uiProg (3, 6, 8) |
gatedClock | 0:8e898e1270d6 | 96 | self.uimmDump (3, 7, 8) |
gatedClock | 0:8e898e1270d6 | 97 | self.uiStep (3, 8, 8) |
gatedClock | 0:8e898e1270d6 | 98 | self.uiRun (3, 9, 8) |
gatedClock | 0:8e898e1270d6 | 99 | self.uiTest (3, 10, 8) |
gatedClock | 0:8e898e1270d6 | 100 | self.uiExit (3, 11, 8) |
gatedClock | 0:8e898e1270d6 | 101 | |
gatedClock | 0:8e898e1270d6 | 102 | self.refreshUI() # initial content display. |
gatedClock | 0:8e898e1270d6 | 103 | |
gatedClock | 0:8e898e1270d6 | 104 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 105 | def __del__(self): # destructor. |
gatedClock | 0:8e898e1270d6 | 106 | print "object destroyed." |
gatedClock | 0:8e898e1270d6 | 107 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 108 | # WIDGETS: BEGIN LABEL/ENTRY PAIRS. #=============================== |
gatedClock | 0:8e898e1270d6 | 109 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 110 | def uiR0(self,dColumn,dRow,dWidth): # R0. |
gatedClock | 0:8e898e1270d6 | 111 | |
gatedClock | 0:8e898e1270d6 | 112 | dColumnPlusOne = dColumn + 1 |
gatedClock | 0:8e898e1270d6 | 113 | |
gatedClock | 0:8e898e1270d6 | 114 | self.__R0Label = Label(self.__frame, text="R0") |
gatedClock | 0:8e898e1270d6 | 115 | self.__R0Label.grid(column=dColumn, row=dRow, sticky=(E)) |
gatedClock | 0:8e898e1270d6 | 116 | |
gatedClock | 0:8e898e1270d6 | 117 | self.__R0Entry = Entry(self.__frame, width=dWidth, background="GREEN") |
gatedClock | 0:8e898e1270d6 | 118 | self.__R0Entry.grid(column=dColumnPlusOne, row=dRow, sticky=(W)) |
gatedClock | 0:8e898e1270d6 | 119 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 120 | def uiR1(self,dColumn,dRow,dWidth): # R1. |
gatedClock | 0:8e898e1270d6 | 121 | |
gatedClock | 0:8e898e1270d6 | 122 | dColumnPlusOne = dColumn + 1 |
gatedClock | 0:8e898e1270d6 | 123 | |
gatedClock | 0:8e898e1270d6 | 124 | self.__R1Label = Label(self.__frame, text="R1") |
gatedClock | 0:8e898e1270d6 | 125 | self.__R1Label.grid(column=dColumn, row=dRow, sticky=(E)) |
gatedClock | 0:8e898e1270d6 | 126 | |
gatedClock | 0:8e898e1270d6 | 127 | self.__R1Entry = Entry(self.__frame, width=dWidth, background="GREEN") |
gatedClock | 0:8e898e1270d6 | 128 | self.__R1Entry.grid(column=dColumnPlusOne, row=dRow, sticky=(W)) |
gatedClock | 0:8e898e1270d6 | 129 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 130 | def uiR2(self,dColumn,dRow,dWidth): # R2. |
gatedClock | 0:8e898e1270d6 | 131 | |
gatedClock | 0:8e898e1270d6 | 132 | dColumnPlusOne = dColumn + 1 |
gatedClock | 0:8e898e1270d6 | 133 | |
gatedClock | 0:8e898e1270d6 | 134 | self.__R2Label = Label(self.__frame, text="R2") |
gatedClock | 0:8e898e1270d6 | 135 | self.__R2Label.grid(column=dColumn, row=dRow, sticky=(E)) |
gatedClock | 0:8e898e1270d6 | 136 | |
gatedClock | 0:8e898e1270d6 | 137 | self.__R2Entry = Entry(self.__frame, width=dWidth, background="GREEN") |
gatedClock | 0:8e898e1270d6 | 138 | self.__R2Entry.grid(column=dColumnPlusOne, row=dRow, sticky=(W)) |
gatedClock | 0:8e898e1270d6 | 139 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 140 | def uiR3(self,dColumn,dRow,dWidth): # R3. |
gatedClock | 0:8e898e1270d6 | 141 | |
gatedClock | 0:8e898e1270d6 | 142 | dColumnPlusOne = dColumn + 1 |
gatedClock | 0:8e898e1270d6 | 143 | |
gatedClock | 0:8e898e1270d6 | 144 | self.__R3Label = Label(self.__frame, text="R3") |
gatedClock | 0:8e898e1270d6 | 145 | self.__R3Label.grid(column=dColumn, row=dRow, sticky=(E)) |
gatedClock | 0:8e898e1270d6 | 146 | |
gatedClock | 0:8e898e1270d6 | 147 | self.__R3Entry = Entry(self.__frame, width=dWidth, background="GREEN") |
gatedClock | 0:8e898e1270d6 | 148 | self.__R3Entry.grid(column=dColumnPlusOne, row=dRow, sticky=(W)) |
gatedClock | 0:8e898e1270d6 | 149 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 150 | def uiPC(self,dColumn,dRow,dWidth): # program counter. |
gatedClock | 0:8e898e1270d6 | 151 | |
gatedClock | 0:8e898e1270d6 | 152 | dColumnPlusOne = dColumn + 1 |
gatedClock | 0:8e898e1270d6 | 153 | |
gatedClock | 0:8e898e1270d6 | 154 | self.__PCLabel = Label(self.__frame, text="PC") |
gatedClock | 0:8e898e1270d6 | 155 | self.__PCLabel.grid(column=dColumn, row=dRow, sticky=(E)) |
gatedClock | 0:8e898e1270d6 | 156 | |
gatedClock | 0:8e898e1270d6 | 157 | self.__PCEntry = Entry(self.__frame, width=dWidth, background="ORANGE") |
gatedClock | 0:8e898e1270d6 | 158 | self.__PCEntry.grid(column=dColumnPlusOne, row=dRow, sticky=(W)) |
gatedClock | 0:8e898e1270d6 | 159 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 160 | def uiIR(self,dColumn,dRow,dWidth): # instruction register. |
gatedClock | 0:8e898e1270d6 | 161 | |
gatedClock | 0:8e898e1270d6 | 162 | dColumnPlusOne = dColumn + 1 |
gatedClock | 0:8e898e1270d6 | 163 | |
gatedClock | 0:8e898e1270d6 | 164 | self.__IRLabel = Label(self.__frame, text="IR") |
gatedClock | 0:8e898e1270d6 | 165 | self.__IRLabel.grid(column=dColumn, row=dRow, sticky=(E)) |
gatedClock | 0:8e898e1270d6 | 166 | |
gatedClock | 0:8e898e1270d6 | 167 | self.__IREntry = Entry(self.__frame, width=dWidth, background="ORANGE") |
gatedClock | 0:8e898e1270d6 | 168 | self.__IREntry.grid(column=dColumnPlusOne, row=dRow, sticky=(W)) |
gatedClock | 0:8e898e1270d6 | 169 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 170 | def uimmADR(self,dColumn,dRow,dWidth):# mmADR. |
gatedClock | 0:8e898e1270d6 | 171 | |
gatedClock | 0:8e898e1270d6 | 172 | dColumnPlusOne = dColumn + 1 |
gatedClock | 0:8e898e1270d6 | 173 | |
gatedClock | 0:8e898e1270d6 | 174 | self.__mmADRLabel = Label(self.__frame, text="mmADR") |
gatedClock | 0:8e898e1270d6 | 175 | self.__mmADRLabel.grid(column=dColumn, row=dRow, sticky=(E)) |
gatedClock | 0:8e898e1270d6 | 176 | |
gatedClock | 0:8e898e1270d6 | 177 | self.__mmADREntry = Entry(self.__frame, width=dWidth, |
gatedClock | 0:8e898e1270d6 | 178 | background="MAROON", foreground="WHITE") |
gatedClock | 0:8e898e1270d6 | 179 | self.__mmADREntry.grid(column=dColumnPlusOne, row=dRow, sticky=(W)) |
gatedClock | 0:8e898e1270d6 | 180 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 181 | def uimmVAL(self,dColumn,dRow,dWidth):# mmVAL. |
gatedClock | 0:8e898e1270d6 | 182 | |
gatedClock | 0:8e898e1270d6 | 183 | dColumnPlusOne = dColumn + 1 |
gatedClock | 0:8e898e1270d6 | 184 | |
gatedClock | 0:8e898e1270d6 | 185 | self.__mmVALLabel = Label(self.__frame, text="mmVAL") |
gatedClock | 0:8e898e1270d6 | 186 | self.__mmVALLabel.grid(column=dColumn, row=dRow, sticky=(E)) |
gatedClock | 0:8e898e1270d6 | 187 | |
gatedClock | 0:8e898e1270d6 | 188 | self.__mmVALEntry = Entry(self.__frame, width=dWidth, |
gatedClock | 0:8e898e1270d6 | 189 | background="MAROON", foreground="WHITE") |
gatedClock | 0:8e898e1270d6 | 190 | self.__mmVALEntry.grid(column=dColumnPlusOne, row=dRow, sticky=(W)) |
gatedClock | 0:8e898e1270d6 | 191 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 192 | # WIDGETS: BEGIN BUTTONS. #=============================== |
gatedClock | 0:8e898e1270d6 | 193 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 194 | # generate the 'connect' button. |
gatedClock | 0:8e898e1270d6 | 195 | def uiConnect(self,dColumn,dRow,dWidth): |
gatedClock | 0:8e898e1270d6 | 196 | |
gatedClock | 0:8e898e1270d6 | 197 | self.__connectButton = Button(self.__frame, text="CONNECT", |
gatedClock | 0:8e898e1270d6 | 198 | command=self.selectConnectButtonPressed, |
gatedClock | 0:8e898e1270d6 | 199 | background="RED", |
gatedClock | 0:8e898e1270d6 | 200 | width = dWidth) |
gatedClock | 0:8e898e1270d6 | 201 | |
gatedClock | 0:8e898e1270d6 | 202 | self.__connectButton.grid(column=dColumn, row=dRow, sticky=(E)) |
gatedClock | 0:8e898e1270d6 | 203 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 204 | # generate the register-read button. |
gatedClock | 0:8e898e1270d6 | 205 | def uiRegRead(self,dColumn,dRow,dWidth): |
gatedClock | 0:8e898e1270d6 | 206 | self.__RegReadButton = Button(self.__frame, text="REG READ", |
gatedClock | 0:8e898e1270d6 | 207 | command=self.selectRegReadButtonPressed, |
gatedClock | 0:8e898e1270d6 | 208 | width = dWidth) |
gatedClock | 0:8e898e1270d6 | 209 | |
gatedClock | 0:8e898e1270d6 | 210 | self.__RegReadButton.grid(column=dColumn, row=dRow, sticky=(W)) |
gatedClock | 0:8e898e1270d6 | 211 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 212 | # generate the 'reg write' button. |
gatedClock | 0:8e898e1270d6 | 213 | def uiRegWrite(self,dColumn,dRow,dWidth): |
gatedClock | 0:8e898e1270d6 | 214 | self.__RegWriteButton = Button(self.__frame, text="REG WRITE", |
gatedClock | 0:8e898e1270d6 | 215 | command=self.selectRegWriteButtonPressed, |
gatedClock | 0:8e898e1270d6 | 216 | width = dWidth) |
gatedClock | 0:8e898e1270d6 | 217 | |
gatedClock | 0:8e898e1270d6 | 218 | self.__RegWriteButton.grid(column=dColumn, row=dRow, sticky=(W)) |
gatedClock | 0:8e898e1270d6 | 219 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 220 | # generate the mm-read button. |
gatedClock | 0:8e898e1270d6 | 221 | def uimmRead(self,dColumn,dRow,dWidth): |
gatedClock | 0:8e898e1270d6 | 222 | self.__mmReadButton = Button(self.__frame, text="MM READ", |
gatedClock | 0:8e898e1270d6 | 223 | command=self.selectmmReadButtonPressed, |
gatedClock | 0:8e898e1270d6 | 224 | width = dWidth) |
gatedClock | 0:8e898e1270d6 | 225 | |
gatedClock | 0:8e898e1270d6 | 226 | self.__mmReadButton.grid(column=dColumn, row=dRow, sticky=(W)) |
gatedClock | 0:8e898e1270d6 | 227 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 228 | # generate the 'mm write' button. |
gatedClock | 0:8e898e1270d6 | 229 | def uimmWrite(self,dColumn,dRow,dWidth): |
gatedClock | 0:8e898e1270d6 | 230 | self.__mmWriteButton = Button(self.__frame, text="MM WRITE", |
gatedClock | 0:8e898e1270d6 | 231 | command=self.selectmmWriteButtonPressed, |
gatedClock | 0:8e898e1270d6 | 232 | width = dWidth) |
gatedClock | 0:8e898e1270d6 | 233 | |
gatedClock | 0:8e898e1270d6 | 234 | self.__mmWriteButton.grid(column=dColumn, row=dRow, sticky=(W)) |
gatedClock | 0:8e898e1270d6 | 235 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 236 | def uiProg(self,dColumn,dRow,dWidth): # generate the 'program' button. |
gatedClock | 0:8e898e1270d6 | 237 | self.__ProgButton = Button(self.__frame, text="PROGRAM", |
gatedClock | 0:8e898e1270d6 | 238 | command=self.selectProgButtonPressed, |
gatedClock | 0:8e898e1270d6 | 239 | width = dWidth) |
gatedClock | 0:8e898e1270d6 | 240 | |
gatedClock | 0:8e898e1270d6 | 241 | self.__ProgButton.grid(column=dColumn, row=dRow, sticky=(W)) |
gatedClock | 0:8e898e1270d6 | 242 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 243 | # generate the 'mm dump' button. |
gatedClock | 0:8e898e1270d6 | 244 | def uimmDump(self,dColumn,dRow,dWidth): |
gatedClock | 0:8e898e1270d6 | 245 | self.__mmWriteButton = Button(self.__frame, text="DUMP", |
gatedClock | 0:8e898e1270d6 | 246 | command=self.selectmmDumpButtonPressed, |
gatedClock | 0:8e898e1270d6 | 247 | width = dWidth) |
gatedClock | 0:8e898e1270d6 | 248 | |
gatedClock | 0:8e898e1270d6 | 249 | self.__mmWriteButton.grid(column=dColumn, row=dRow, sticky=(W)) |
gatedClock | 0:8e898e1270d6 | 250 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 251 | def uiStep(self,dColumn,dRow,dWidth): # generate the 'step' button. |
gatedClock | 0:8e898e1270d6 | 252 | self.__StepButton = Button(self.__frame, text="STEP", |
gatedClock | 0:8e898e1270d6 | 253 | command=self.selectStepButtonPressed, |
gatedClock | 0:8e898e1270d6 | 254 | width = dWidth) |
gatedClock | 0:8e898e1270d6 | 255 | |
gatedClock | 0:8e898e1270d6 | 256 | self.__StepButton.grid(column=dColumn, row=dRow, sticky=(W)) |
gatedClock | 0:8e898e1270d6 | 257 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 258 | def uiRun(self,dColumn,dRow,dWidth): # generate the 'run' button. |
gatedClock | 0:8e898e1270d6 | 259 | self.__runButton = Button(self.__frame, text="RUN", |
gatedClock | 0:8e898e1270d6 | 260 | command=self.selectRunButtonPressed,width = dWidth) |
gatedClock | 0:8e898e1270d6 | 261 | |
gatedClock | 0:8e898e1270d6 | 262 | self.__runButton.grid(column=dColumn, row=dRow, sticky=(E)) |
gatedClock | 0:8e898e1270d6 | 263 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 264 | def uiTest(self,dColumn,dRow,dWidth): # generate the 'test' button. |
gatedClock | 0:8e898e1270d6 | 265 | self.__testButton = Button(self.__frame, text="TEST", |
gatedClock | 0:8e898e1270d6 | 266 | command=self.selectTestButtonPressed,width = dWidth) |
gatedClock | 0:8e898e1270d6 | 267 | |
gatedClock | 0:8e898e1270d6 | 268 | self.__testButton.grid(column=dColumn, row=dRow, sticky=(E)) |
gatedClock | 0:8e898e1270d6 | 269 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 270 | def uiExit(self,dColumn,dRow,dWidth): # generate the 'exit' button. |
gatedClock | 0:8e898e1270d6 | 271 | |
gatedClock | 0:8e898e1270d6 | 272 | self.__isRunning = 0 # end the running thread. |
gatedClock | 0:8e898e1270d6 | 273 | sleep(2.0) # give thread time to stop. |
gatedClock | 0:8e898e1270d6 | 274 | |
gatedClock | 0:8e898e1270d6 | 275 | self.__exitButton = Button(self.__frame, text="EXIT", |
gatedClock | 0:8e898e1270d6 | 276 | command=sys.exit,width = dWidth) |
gatedClock | 0:8e898e1270d6 | 277 | |
gatedClock | 0:8e898e1270d6 | 278 | self.__exitButton.grid(column=dColumn, row=dRow, sticky=(E)) |
gatedClock | 0:8e898e1270d6 | 279 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 280 | # BEGIN EXECUTE-WHEN-BUTTON-PRESSED CODE#=============================== |
gatedClock | 0:8e898e1270d6 | 281 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 282 | def selectConnectButtonPressed(self): # execute CONNECT. |
gatedClock | 0:8e898e1270d6 | 283 | if (self.__connected == 0): |
gatedClock | 0:8e898e1270d6 | 284 | self.__iUSB = mmUSBserial(idVendor=0x1234, idProduct=0x0006) |
gatedClock | 0:8e898e1270d6 | 285 | self.__connected = 1 |
gatedClock | 0:8e898e1270d6 | 286 | self.__connectButton["text"] = "DISCONNECT" |
gatedClock | 0:8e898e1270d6 | 287 | self.__connectButton["background"] = self.__frame.cget("background") |
gatedClock | 0:8e898e1270d6 | 288 | else: |
gatedClock | 0:8e898e1270d6 | 289 | del(self.__iUSB) |
gatedClock | 0:8e898e1270d6 | 290 | self.__connected = 0 |
gatedClock | 0:8e898e1270d6 | 291 | self.__connectButton["text"] = "CONNECT" |
gatedClock | 0:8e898e1270d6 | 292 | self.__connectButton["background"] = "RED" |
gatedClock | 0:8e898e1270d6 | 293 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 294 | def selectRegReadButtonPressed(self): # REG READ button has been pressed. |
gatedClock | 0:8e898e1270d6 | 295 | self.refreshUI() # ensure proper text formats. |
gatedClock | 0:8e898e1270d6 | 296 | |
gatedClock | 0:8e898e1270d6 | 297 | # real all registers. |
gatedClock | 0:8e898e1270d6 | 298 | self.__iUSB.write(self.buildReadAllRegisterCommand()) |
gatedClock | 0:8e898e1270d6 | 299 | messageVector = self.__iUSB.read() |
gatedClock | 0:8e898e1270d6 | 300 | |
gatedClock | 0:8e898e1270d6 | 301 | # parse-out the register entries. |
gatedClock | 0:8e898e1270d6 | 302 | hexTextR0 = "0x" + messageVector[ 1: 3] |
gatedClock | 0:8e898e1270d6 | 303 | hexTextR1 = "0x" + messageVector[ 3: 5] |
gatedClock | 0:8e898e1270d6 | 304 | hexTextR2 = "0x" + messageVector[ 5: 7] |
gatedClock | 0:8e898e1270d6 | 305 | hexTextR3 = "0x" + messageVector[ 7: 9] |
gatedClock | 0:8e898e1270d6 | 306 | hexTextPC = "0x" + messageVector[ 9:11] |
gatedClock | 0:8e898e1270d6 | 307 | hexTextIR = "0x" + messageVector[11:15] |
gatedClock | 0:8e898e1270d6 | 308 | |
gatedClock | 0:8e898e1270d6 | 309 | |
gatedClock | 0:8e898e1270d6 | 310 | self.__R0Entry.delete(0,99) # R0 to UI. |
gatedClock | 0:8e898e1270d6 | 311 | self.__R0Entry.insert(0,hexTextR0) |
gatedClock | 0:8e898e1270d6 | 312 | |
gatedClock | 0:8e898e1270d6 | 313 | self.__R1Entry.delete(0,99) # R1 to UI. |
gatedClock | 0:8e898e1270d6 | 314 | self.__R1Entry.insert(0,hexTextR1) |
gatedClock | 0:8e898e1270d6 | 315 | |
gatedClock | 0:8e898e1270d6 | 316 | self.__R2Entry.delete(0,99) # R2 to UI. |
gatedClock | 0:8e898e1270d6 | 317 | self.__R2Entry.insert(0,hexTextR2) |
gatedClock | 0:8e898e1270d6 | 318 | |
gatedClock | 0:8e898e1270d6 | 319 | self.__R3Entry.delete(0,99) # R3 to UI. |
gatedClock | 0:8e898e1270d6 | 320 | self.__R3Entry.insert(0,hexTextR3) |
gatedClock | 0:8e898e1270d6 | 321 | |
gatedClock | 0:8e898e1270d6 | 322 | self.__PCEntry.delete(0,99) # PC to UI. |
gatedClock | 0:8e898e1270d6 | 323 | self.__PCEntry.insert(0,hexTextPC) |
gatedClock | 0:8e898e1270d6 | 324 | |
gatedClock | 0:8e898e1270d6 | 325 | self.__IREntry.delete(0,99) # IR to UI. |
gatedClock | 0:8e898e1270d6 | 326 | self.__IREntry.insert(0,hexTextIR) |
gatedClock | 0:8e898e1270d6 | 327 | |
gatedClock | 0:8e898e1270d6 | 328 | #---- |
gatedClock | 0:8e898e1270d6 | 329 | self.refreshUI() # ensure proper text formats |
gatedClock | 0:8e898e1270d6 | 330 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 331 | def selectmmReadButtonPressed(self): # MM READ button has been pressed. |
gatedClock | 0:8e898e1270d6 | 332 | self.refreshUI() # ensure proper text formats. |
gatedClock | 0:8e898e1270d6 | 333 | |
gatedClock | 0:8e898e1270d6 | 334 | transmitmmADRText = self.formatByteStringForTransmit(self.__mmADREntry.get()) |
gatedClock | 0:8e898e1270d6 | 335 | commandText = self.buildReadMMCommand(transmitmmADRText) |
gatedClock | 0:8e898e1270d6 | 336 | |
gatedClock | 0:8e898e1270d6 | 337 | self.__iUSB.write(commandText) |
gatedClock | 0:8e898e1270d6 | 338 | |
gatedClock | 0:8e898e1270d6 | 339 | fetchTextmmVAL = self.__iUSB.read() |
gatedClock | 0:8e898e1270d6 | 340 | |
gatedClock | 0:8e898e1270d6 | 341 | buildHextmmVALString = fetchTextmmVAL[3:7] |
gatedClock | 0:8e898e1270d6 | 342 | |
gatedClock | 0:8e898e1270d6 | 343 | self.__mmVALEntry.delete(0,99) |
gatedClock | 0:8e898e1270d6 | 344 | self.__mmVALEntry.insert(0,buildHextmmVALString) |
gatedClock | 0:8e898e1270d6 | 345 | #---- |
gatedClock | 0:8e898e1270d6 | 346 | self.selectRegReadButtonPressed() # because registers are affected. |
gatedClock | 0:8e898e1270d6 | 347 | self.refreshUI() # ensure proper text formats |
gatedClock | 0:8e898e1270d6 | 348 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 349 | # before writing the register values currently displayed in the UI, |
gatedClock | 0:8e898e1270d6 | 350 | # this method will first run that data through a formatter, so that |
gatedClock | 0:8e898e1270d6 | 351 | # the data is transformed into '0x##' format. this is convenient for |
gatedClock | 0:8e898e1270d6 | 352 | # the user. for example, the user can type '12' in a register entry |
gatedClock | 0:8e898e1270d6 | 353 | # form, press the 'REG WRITE' button, and that data will be reformatted |
gatedClock | 0:8e898e1270d6 | 354 | # to appear as '0x12'. |
gatedClock | 0:8e898e1270d6 | 355 | |
gatedClock | 0:8e898e1270d6 | 356 | def selectRegWriteButtonPressed(self):# REG WRITE button has been pressed. |
gatedClock | 0:8e898e1270d6 | 357 | |
gatedClock | 0:8e898e1270d6 | 358 | self.refreshUI() # ensure proper text formats. |
gatedClock | 0:8e898e1270d6 | 359 | #---- |
gatedClock | 0:8e898e1270d6 | 360 | # place those values in the |
gatedClock | 0:8e898e1270d6 | 361 | # standard format. |
gatedClock | 0:8e898e1270d6 | 362 | R0Val = self.formatByteStringForTransmit(self.__R0Entry.get()) |
gatedClock | 0:8e898e1270d6 | 363 | R1Val = self.formatByteStringForTransmit(self.__R1Entry.get()) |
gatedClock | 0:8e898e1270d6 | 364 | R2Val = self.formatByteStringForTransmit(self.__R2Entry.get()) |
gatedClock | 0:8e898e1270d6 | 365 | R3Val = self.formatByteStringForTransmit(self.__R3Entry.get()) |
gatedClock | 0:8e898e1270d6 | 366 | PCVal = self.formatByteStringForTransmit(self.__PCEntry.get()) |
gatedClock | 0:8e898e1270d6 | 367 | IRVal = self.formatWordStringForTransmit(self.__IREntry.get()) |
gatedClock | 0:8e898e1270d6 | 368 | #---- |
gatedClock | 0:8e898e1270d6 | 369 | # write those values to the CPU. |
gatedClock | 0:8e898e1270d6 | 370 | self.__iUSB.write(self.buildWriteRegisterCommand("0",R0Val)) |
gatedClock | 0:8e898e1270d6 | 371 | self.__iUSB.write(self.buildWriteRegisterCommand("1",R1Val)) |
gatedClock | 0:8e898e1270d6 | 372 | self.__iUSB.write(self.buildWriteRegisterCommand("2",R2Val)) |
gatedClock | 0:8e898e1270d6 | 373 | self.__iUSB.write(self.buildWriteRegisterCommand("3",R3Val)) |
gatedClock | 0:8e898e1270d6 | 374 | self.__iUSB.write(self.buildWriteRegisterCommand("4",PCVal)) |
gatedClock | 0:8e898e1270d6 | 375 | self.__iUSB.write(self.buildWriteIRCommand ( IRVal)) |
gatedClock | 0:8e898e1270d6 | 376 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 377 | # before writing the main-memory values currently displayed in the UI, |
gatedClock | 0:8e898e1270d6 | 378 | # this method will first run that data through a formatter, so that |
gatedClock | 0:8e898e1270d6 | 379 | # the data is transformed into '0x##' or '0x####' format. |
gatedClock | 0:8e898e1270d6 | 380 | # this is convenient for the user. |
gatedClock | 0:8e898e1270d6 | 381 | # for example, the user can type '12' in the mmADR entry |
gatedClock | 0:8e898e1270d6 | 382 | # form, press the 'MM WRITE' button, and that data will be reformatted |
gatedClock | 0:8e898e1270d6 | 383 | # to appear as '0x12'. |
gatedClock | 0:8e898e1270d6 | 384 | |
gatedClock | 0:8e898e1270d6 | 385 | def selectmmWriteButtonPressed(self): # mm WRITE button has been pressed. |
gatedClock | 0:8e898e1270d6 | 386 | |
gatedClock | 0:8e898e1270d6 | 387 | self.refreshUI() # ensure proper text formats. |
gatedClock | 0:8e898e1270d6 | 388 | |
gatedClock | 0:8e898e1270d6 | 389 | # obtain mm values currently |
gatedClock | 0:8e898e1270d6 | 390 | # displayed in the UI. |
gatedClock | 0:8e898e1270d6 | 391 | self.__transmitmmADRText = self.__mmADREntry.get() |
gatedClock | 0:8e898e1270d6 | 392 | self.__transmitmmVALText = self.__mmVALEntry.get() |
gatedClock | 0:8e898e1270d6 | 393 | |
gatedClock | 0:8e898e1270d6 | 394 | # place those values in the |
gatedClock | 0:8e898e1270d6 | 395 | # standard format. |
gatedClock | 0:8e898e1270d6 | 396 | mmADRVAL = self.formatByteStringForTransmit(self.__mmADREntry.get()) |
gatedClock | 0:8e898e1270d6 | 397 | mmVALVal = self.formatWordStringForTransmit(self.__mmVALEntry.get()) |
gatedClock | 0:8e898e1270d6 | 398 | |
gatedClock | 0:8e898e1270d6 | 399 | # write those values to the CPU. |
gatedClock | 0:8e898e1270d6 | 400 | self.__iUSB.write(self.buildWriteMMCommand(mmADRVAL,mmVALVal)) |
gatedClock | 0:8e898e1270d6 | 401 | |
gatedClock | 0:8e898e1270d6 | 402 | self.selectRegReadButtonPressed() # because registers are affected. |
gatedClock | 0:8e898e1270d6 | 403 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 404 | def selectProgButtonPressed(self): # Program button has been pressed. |
gatedClock | 0:8e898e1270d6 | 405 | |
gatedClock | 0:8e898e1270d6 | 406 | # ask user for program source file |
gatedClock | 0:8e898e1270d6 | 407 | # name using a dialog. |
gatedClock | 0:8e898e1270d6 | 408 | fileName = tkFileDialog.askopenfilename(defaultextension='.txt') |
gatedClock | 0:8e898e1270d6 | 409 | |
gatedClock | 0:8e898e1270d6 | 410 | print("memory load started.") # announce to user. |
gatedClock | 0:8e898e1270d6 | 411 | self.progamMainMemory(fileName) # main part of programming. |
gatedClock | 0:8e898e1270d6 | 412 | print("memory load completed.") # announce to user. |
gatedClock | 0:8e898e1270d6 | 413 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 414 | def selectmmDumpButtonPressed(self): # MM dump button has been pressed. |
gatedClock | 0:8e898e1270d6 | 415 | |
gatedClock | 0:8e898e1270d6 | 416 | # obtain file-to-write-to name |
gatedClock | 0:8e898e1270d6 | 417 | # from user, using a dialog. |
gatedClock | 0:8e898e1270d6 | 418 | fileName = tkFileDialog.asksaveasfilename(defaultextension='.txt') |
gatedClock | 0:8e898e1270d6 | 419 | |
gatedClock | 0:8e898e1270d6 | 420 | print("memory dump started.") # announce to user. |
gatedClock | 0:8e898e1270d6 | 421 | self.dumpMainMemory(fileName) # dump main memory to file. |
gatedClock | 0:8e898e1270d6 | 422 | print("memory dump completed.") # announce to user. |
gatedClock | 0:8e898e1270d6 | 423 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 424 | def selectStepButtonPressed(self): # STEP button has been pressed. |
gatedClock | 0:8e898e1270d6 | 425 | self.__iUSB.write("50000000") # the command code. |
gatedClock | 0:8e898e1270d6 | 426 | self.selectRegReadButtonPressed() # monitor the result. |
gatedClock | 0:8e898e1270d6 | 427 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 428 | def selectRunButtonPressed(self): # RUN/STOP button has been pressed. |
gatedClock | 0:8e898e1270d6 | 429 | |
gatedClock | 0:8e898e1270d6 | 430 | if (self.__isRunning == 0): # start high speed run. |
gatedClock | 0:8e898e1270d6 | 431 | self.__isRunning = 1 |
gatedClock | 0:8e898e1270d6 | 432 | self.__runButton["text"] = "SLOW" |
gatedClock | 0:8e898e1270d6 | 433 | self.t = threading.Thread(target=self.doRun) |
gatedClock | 0:8e898e1270d6 | 434 | self.t.start() |
gatedClock | 0:8e898e1270d6 | 435 | |
gatedClock | 0:8e898e1270d6 | 436 | elif (self.__isRunning == 1): # switch to a slower run. |
gatedClock | 0:8e898e1270d6 | 437 | self.__isRunning = 2 |
gatedClock | 0:8e898e1270d6 | 438 | self.__runButton["text"] = "STOP" |
gatedClock | 0:8e898e1270d6 | 439 | |
gatedClock | 0:8e898e1270d6 | 440 | else: # stop the CPU. |
gatedClock | 0:8e898e1270d6 | 441 | self.__isRunning = 0 |
gatedClock | 0:8e898e1270d6 | 442 | self.__runButton["text"] = "RUN" |
gatedClock | 0:8e898e1270d6 | 443 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 444 | def selectTestButtonPressed(self): # TEST/STOP button has been pressed. |
gatedClock | 0:8e898e1270d6 | 445 | |
gatedClock | 0:8e898e1270d6 | 446 | if (self.__testRunning == 0): # start test. |
gatedClock | 0:8e898e1270d6 | 447 | self.__testRunning = 1 |
gatedClock | 0:8e898e1270d6 | 448 | self.__testButton["text"] = "STOP TEST" |
gatedClock | 0:8e898e1270d6 | 449 | self.t = threading.Thread(target=self.doTest) |
gatedClock | 0:8e898e1270d6 | 450 | self.t.start() |
gatedClock | 0:8e898e1270d6 | 451 | |
gatedClock | 0:8e898e1270d6 | 452 | |
gatedClock | 0:8e898e1270d6 | 453 | else: # stop test. |
gatedClock | 0:8e898e1270d6 | 454 | self.__testRunning = 0 |
gatedClock | 0:8e898e1270d6 | 455 | self.__testButton["text"] = "TEST" |
gatedClock | 0:8e898e1270d6 | 456 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 457 | # BEGIN UTILITY CODE. #=============================== |
gatedClock | 0:8e898e1270d6 | 458 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 459 | # guarantee 0x## format. |
gatedClock | 0:8e898e1270d6 | 460 | def formatByteStringForDisplay(self, byteText): |
gatedClock | 0:8e898e1270d6 | 461 | |
gatedClock | 0:8e898e1270d6 | 462 | xIndex = byteText.find("x") # eliminate any 0x, 0X prefix. |
gatedClock | 0:8e898e1270d6 | 463 | XIndex = byteText.find("X") |
gatedClock | 0:8e898e1270d6 | 464 | |
gatedClock | 0:8e898e1270d6 | 465 | theXindex = 0 |
gatedClock | 0:8e898e1270d6 | 466 | if (xIndex >= 0): theXindex = xIndex + 1 |
gatedClock | 0:8e898e1270d6 | 467 | if (XIndex >= 0): theXindex = XIndex + 1 |
gatedClock | 0:8e898e1270d6 | 468 | |
gatedClock | 0:8e898e1270d6 | 469 | buildText = byteText[theXindex:] # any 0x, 0X prefix gone. |
gatedClock | 0:8e898e1270d6 | 470 | |
gatedClock | 0:8e898e1270d6 | 471 | # build-out leading 0's. |
gatedClock | 0:8e898e1270d6 | 472 | if (len(buildText) == 0): buildText = "0" + buildText |
gatedClock | 0:8e898e1270d6 | 473 | if (len(buildText) == 1): buildText = "0" + buildText |
gatedClock | 0:8e898e1270d6 | 474 | |
gatedClock | 0:8e898e1270d6 | 475 | # truncate leading characters. |
gatedClock | 0:8e898e1270d6 | 476 | if (len(buildText) > 2): buildText = buildText[-2:] |
gatedClock | 0:8e898e1270d6 | 477 | |
gatedClock | 0:8e898e1270d6 | 478 | buildText = "0x" + buildText # add leading 0x. |
gatedClock | 0:8e898e1270d6 | 479 | |
gatedClock | 0:8e898e1270d6 | 480 | return(buildText) # 0x## format returned. |
gatedClock | 0:8e898e1270d6 | 481 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 482 | # guarantee 0x#### format. |
gatedClock | 0:8e898e1270d6 | 483 | def formatWordStringForDisplay(self, wordText): |
gatedClock | 0:8e898e1270d6 | 484 | |
gatedClock | 0:8e898e1270d6 | 485 | xIndex = wordText.find("x") # eliminate any 0x, 0X prefix. |
gatedClock | 0:8e898e1270d6 | 486 | XIndex = wordText.find("X") |
gatedClock | 0:8e898e1270d6 | 487 | |
gatedClock | 0:8e898e1270d6 | 488 | theXindex = 0 |
gatedClock | 0:8e898e1270d6 | 489 | if (xIndex >= 0): theXindex = xIndex + 1 |
gatedClock | 0:8e898e1270d6 | 490 | if (XIndex >= 0): theXindex = XIndex + 1 |
gatedClock | 0:8e898e1270d6 | 491 | |
gatedClock | 0:8e898e1270d6 | 492 | buildText = wordText[theXindex:] # any 0x, 0X prefix gone. |
gatedClock | 0:8e898e1270d6 | 493 | |
gatedClock | 0:8e898e1270d6 | 494 | # build-out leading 0's. |
gatedClock | 0:8e898e1270d6 | 495 | if (len(buildText) == 0): buildText = "0" + buildText |
gatedClock | 0:8e898e1270d6 | 496 | if (len(buildText) == 1): buildText = "0" + buildText |
gatedClock | 0:8e898e1270d6 | 497 | if (len(buildText) == 2): buildText = "0" + buildText |
gatedClock | 0:8e898e1270d6 | 498 | if (len(buildText) == 3): buildText = "0" + buildText |
gatedClock | 0:8e898e1270d6 | 499 | |
gatedClock | 0:8e898e1270d6 | 500 | |
gatedClock | 0:8e898e1270d6 | 501 | # truncate leading characters. |
gatedClock | 0:8e898e1270d6 | 502 | if (len(buildText) > 4): buildText = buildText[-4:] |
gatedClock | 0:8e898e1270d6 | 503 | |
gatedClock | 0:8e898e1270d6 | 504 | buildText = "0x" + buildText # add leading 0x. |
gatedClock | 0:8e898e1270d6 | 505 | |
gatedClock | 0:8e898e1270d6 | 506 | return(buildText) # 0x## format returned. |
gatedClock | 0:8e898e1270d6 | 507 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 508 | # guarantee ## format. |
gatedClock | 0:8e898e1270d6 | 509 | def formatByteStringForTransmit(self, byteText): |
gatedClock | 0:8e898e1270d6 | 510 | buildText = self.formatByteStringForDisplay(byteText) |
gatedClock | 0:8e898e1270d6 | 511 | buildText = buildText[-2:] |
gatedClock | 0:8e898e1270d6 | 512 | return(buildText) |
gatedClock | 0:8e898e1270d6 | 513 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 514 | # guarantee #### format. |
gatedClock | 0:8e898e1270d6 | 515 | def formatWordStringForTransmit(self, wordText): |
gatedClock | 0:8e898e1270d6 | 516 | buildText = self.formatWordStringForDisplay(wordText) |
gatedClock | 0:8e898e1270d6 | 517 | buildText = buildText[-4:] |
gatedClock | 0:8e898e1270d6 | 518 | return(buildText) |
gatedClock | 0:8e898e1270d6 | 519 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 520 | def refreshUI(self): # reformat UI text. |
gatedClock | 0:8e898e1270d6 | 521 | |
gatedClock | 0:8e898e1270d6 | 522 | # copy-in current form contents. |
gatedClock | 0:8e898e1270d6 | 523 | originalR0Entry = self.__R0Entry.get() |
gatedClock | 0:8e898e1270d6 | 524 | originalR1Entry = self.__R1Entry.get() |
gatedClock | 0:8e898e1270d6 | 525 | originalR2Entry = self.__R2Entry.get() |
gatedClock | 0:8e898e1270d6 | 526 | originalR3Entry = self.__R3Entry.get() |
gatedClock | 0:8e898e1270d6 | 527 | originalPCEntry = self.__PCEntry.get() |
gatedClock | 0:8e898e1270d6 | 528 | originalIREntry = self.__IREntry.get() |
gatedClock | 0:8e898e1270d6 | 529 | originalmmADREntry = self.__mmADREntry.get() |
gatedClock | 0:8e898e1270d6 | 530 | originalmmVALEntry = self.__mmVALEntry.get() |
gatedClock | 0:8e898e1270d6 | 531 | |
gatedClock | 0:8e898e1270d6 | 532 | # reformat form contents. |
gatedClock | 0:8e898e1270d6 | 533 | newR0Entry = self.formatByteStringForDisplay(originalR0Entry) |
gatedClock | 0:8e898e1270d6 | 534 | newR1Entry = self.formatByteStringForDisplay(originalR1Entry) |
gatedClock | 0:8e898e1270d6 | 535 | newR2Entry = self.formatByteStringForDisplay(originalR2Entry) |
gatedClock | 0:8e898e1270d6 | 536 | newR3Entry = self.formatByteStringForDisplay(originalR3Entry) |
gatedClock | 0:8e898e1270d6 | 537 | newPCEntry = self.formatByteStringForDisplay(originalPCEntry) |
gatedClock | 0:8e898e1270d6 | 538 | newIREntry = self.formatWordStringForDisplay(originalIREntry) |
gatedClock | 0:8e898e1270d6 | 539 | |
gatedClock | 0:8e898e1270d6 | 540 | newmmADREntry = self.formatByteStringForDisplay(originalmmADREntry) |
gatedClock | 0:8e898e1270d6 | 541 | newmmVALEntry = self.formatWordStringForDisplay(originalmmVALEntry) |
gatedClock | 0:8e898e1270d6 | 542 | |
gatedClock | 0:8e898e1270d6 | 543 | |
gatedClock | 0:8e898e1270d6 | 544 | self.__R0Entry. delete(0,99) # clear form contents. |
gatedClock | 0:8e898e1270d6 | 545 | self.__R1Entry. delete(0,99) |
gatedClock | 0:8e898e1270d6 | 546 | self.__R2Entry. delete(0,99) |
gatedClock | 0:8e898e1270d6 | 547 | self.__R3Entry. delete(0,99) |
gatedClock | 0:8e898e1270d6 | 548 | self.__PCEntry. delete(0,99) |
gatedClock | 0:8e898e1270d6 | 549 | self.__IREntry. delete(0,99) |
gatedClock | 0:8e898e1270d6 | 550 | self.__mmADREntry.delete(0,99) |
gatedClock | 0:8e898e1270d6 | 551 | self.__mmVALEntry.delete(0,99) |
gatedClock | 0:8e898e1270d6 | 552 | |
gatedClock | 0:8e898e1270d6 | 553 | # update form contents. |
gatedClock | 0:8e898e1270d6 | 554 | self.__R0Entry. insert(0,newR0Entry) |
gatedClock | 0:8e898e1270d6 | 555 | self.__R1Entry. insert(0,newR1Entry) |
gatedClock | 0:8e898e1270d6 | 556 | self.__R2Entry. insert(0,newR2Entry) |
gatedClock | 0:8e898e1270d6 | 557 | self.__R3Entry. insert(0,newR3Entry) |
gatedClock | 0:8e898e1270d6 | 558 | self.__PCEntry. insert(0,newPCEntry) |
gatedClock | 0:8e898e1270d6 | 559 | self.__IREntry. insert(0,newIREntry) |
gatedClock | 0:8e898e1270d6 | 560 | self.__mmADREntry.insert(0,newmmADREntry) |
gatedClock | 0:8e898e1270d6 | 561 | self.__mmVALEntry.insert(0,newmmVALEntry) |
gatedClock | 0:8e898e1270d6 | 562 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 563 | # build the command string for |
gatedClock | 0:8e898e1270d6 | 564 | # reading a value from a CPU register. |
gatedClock | 0:8e898e1270d6 | 565 | def buildReadRegisterCommand(self,regNum): |
gatedClock | 0:8e898e1270d6 | 566 | |
gatedClock | 0:8e898e1270d6 | 567 | commandText = "" # build command for read register. |
gatedClock | 0:8e898e1270d6 | 568 | commandText = commandText + "2" # command-code. |
gatedClock | 0:8e898e1270d6 | 569 | commandText = commandText + regNum # register number. |
gatedClock | 0:8e898e1270d6 | 570 | commandText = commandText + "0000000000000" |
gatedClock | 0:8e898e1270d6 | 571 | return(commandText) |
gatedClock | 0:8e898e1270d6 | 572 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 573 | # build the command string for |
gatedClock | 0:8e898e1270d6 | 574 | # reading all CPU register values. |
gatedClock | 0:8e898e1270d6 | 575 | def buildReadAllRegisterCommand(self): |
gatedClock | 0:8e898e1270d6 | 576 | |
gatedClock | 0:8e898e1270d6 | 577 | commandText = "" # build command for read register. |
gatedClock | 0:8e898e1270d6 | 578 | commandText = commandText + "7" # command-code. |
gatedClock | 0:8e898e1270d6 | 579 | commandText = commandText + "00000000000000" |
gatedClock | 0:8e898e1270d6 | 580 | return(commandText) |
gatedClock | 0:8e898e1270d6 | 581 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 582 | # build the command-string for |
gatedClock | 0:8e898e1270d6 | 583 | # writing a value to a CPU register. |
gatedClock | 0:8e898e1270d6 | 584 | def buildWriteRegisterCommand(self,regNum,regVal): |
gatedClock | 0:8e898e1270d6 | 585 | |
gatedClock | 0:8e898e1270d6 | 586 | commandText = "" |
gatedClock | 0:8e898e1270d6 | 587 | commandText = commandText + "1" # command-code. |
gatedClock | 0:8e898e1270d6 | 588 | commandText = commandText + regNum # register. |
gatedClock | 0:8e898e1270d6 | 589 | commandText = commandText + regVal # content. |
gatedClock | 0:8e898e1270d6 | 590 | commandText = commandText + "00000000000" |
gatedClock | 0:8e898e1270d6 | 591 | return(commandText) |
gatedClock | 0:8e898e1270d6 | 592 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 593 | # build the command-string for |
gatedClock | 0:8e898e1270d6 | 594 | # writing a value to the IR. |
gatedClock | 0:8e898e1270d6 | 595 | def buildWriteIRCommand(self,regVal): |
gatedClock | 0:8e898e1270d6 | 596 | |
gatedClock | 0:8e898e1270d6 | 597 | commandText = "" |
gatedClock | 0:8e898e1270d6 | 598 | commandText = commandText + "6" # command-code. |
gatedClock | 0:8e898e1270d6 | 599 | commandText = commandText + "5" # actually a placeholder. |
gatedClock | 0:8e898e1270d6 | 600 | commandText = commandText + regVal # content. |
gatedClock | 0:8e898e1270d6 | 601 | commandText = commandText + "000000000" |
gatedClock | 0:8e898e1270d6 | 602 | return(commandText) |
gatedClock | 0:8e898e1270d6 | 603 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 604 | # build the command-string for |
gatedClock | 0:8e898e1270d6 | 605 | # writing a main-memory value. |
gatedClock | 0:8e898e1270d6 | 606 | def buildWriteMMCommand(self,mmADR,mmVAL): |
gatedClock | 0:8e898e1270d6 | 607 | |
gatedClock | 0:8e898e1270d6 | 608 | commandText = "" |
gatedClock | 0:8e898e1270d6 | 609 | commandText = commandText + "3" # command-code. |
gatedClock | 0:8e898e1270d6 | 610 | commandText = commandText + mmADR # address. |
gatedClock | 0:8e898e1270d6 | 611 | commandText = commandText + mmVAL # value. |
gatedClock | 0:8e898e1270d6 | 612 | commandText = commandText + "00000000" |
gatedClock | 0:8e898e1270d6 | 613 | return(commandText) |
gatedClock | 0:8e898e1270d6 | 614 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 615 | def buildReadMMCommand(self,mmADR): # build read-mm command-string. |
gatedClock | 0:8e898e1270d6 | 616 | commandText = "" # build command for read main-memory. |
gatedClock | 0:8e898e1270d6 | 617 | commandText = commandText + "4" # command-code. |
gatedClock | 0:8e898e1270d6 | 618 | commandText = commandText + mmADR |
gatedClock | 0:8e898e1270d6 | 619 | commandText = commandText + "000000000000" |
gatedClock | 0:8e898e1270d6 | 620 | return(commandText) |
gatedClock | 0:8e898e1270d6 | 621 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 622 | # extract reg value payload. |
gatedClock | 0:8e898e1270d6 | 623 | def formatRegValPayload(self,messageVector): |
gatedClock | 0:8e898e1270d6 | 624 | buildHex = "0x" + messageVector[2:4] |
gatedClock | 0:8e898e1270d6 | 625 | return(buildHex) |
gatedClock | 0:8e898e1270d6 | 626 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 627 | def progamMainMemory(self,progFile): # core of loading program to MM. |
gatedClock | 0:8e898e1270d6 | 628 | |
gatedClock | 0:8e898e1270d6 | 629 | hFile = open(progFile, 'r') |
gatedClock | 0:8e898e1270d6 | 630 | fileLineList = hFile.readlines() # read file into a list. |
gatedClock | 0:8e898e1270d6 | 631 | hFile.close() # close the file. |
gatedClock | 0:8e898e1270d6 | 632 | |
gatedClock | 0:8e898e1270d6 | 633 | # load '0x12 0x3456' memory content |
gatedClock | 0:8e898e1270d6 | 634 | # format, into a list. |
gatedClock | 0:8e898e1270d6 | 635 | for listIndex in range(0, len(fileLineList)): |
gatedClock | 0:8e898e1270d6 | 636 | addressStartIndex = fileLineList[listIndex].find("0x") + 2 |
gatedClock | 0:8e898e1270d6 | 637 | dataStartIndex = fileLineList[listIndex].find("0x", addressStartIndex) + 2 |
gatedClock | 0:8e898e1270d6 | 638 | progAddress = fileLineList[listIndex][addressStartIndex : addressStartIndex + 2] |
gatedClock | 0:8e898e1270d6 | 639 | progAddress = format(listIndex,'02x') |
gatedClock | 0:8e898e1270d6 | 640 | progData = fileLineList[listIndex][dataStartIndex : dataStartIndex + 4] |
gatedClock | 0:8e898e1270d6 | 641 | commandText = self.buildWriteMMCommand(progAddress,progData) |
gatedClock | 0:8e898e1270d6 | 642 | self.__iUSB.write(commandText) |
gatedClock | 0:8e898e1270d6 | 643 | print(fileLineList[listIndex][0:len(fileLineList[listIndex])-1]) |
gatedClock | 0:8e898e1270d6 | 644 | sleep(self.__sleepVal) |
gatedClock | 0:8e898e1270d6 | 645 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 646 | def dumpMainMemory(self,dumpFile): # core of dumping MM to file. |
gatedClock | 0:8e898e1270d6 | 647 | |
gatedClock | 0:8e898e1270d6 | 648 | hFile = open(dumpFile, 'w') |
gatedClock | 0:8e898e1270d6 | 649 | |
gatedClock | 0:8e898e1270d6 | 650 | for loopIndex in range(0, 256): # traverse all of main-memory. |
gatedClock | 0:8e898e1270d6 | 651 | transmitmmADRText = "{}".format(hex(loopIndex)) |
gatedClock | 0:8e898e1270d6 | 652 | transmitmmADRText = transmitmmADRText[2:] |
gatedClock | 0:8e898e1270d6 | 653 | if (len(transmitmmADRText) == 1): transmitmmADRText = "0" + transmitmmADRText |
gatedClock | 0:8e898e1270d6 | 654 | commandText = self.buildReadMMCommand(transmitmmADRText) |
gatedClock | 0:8e898e1270d6 | 655 | self.__iUSB.write(commandText) |
gatedClock | 0:8e898e1270d6 | 656 | fetchTextmmVAL = self.__iUSB.read() |
gatedClock | 0:8e898e1270d6 | 657 | buildHextmmVALString = fetchTextmmVAL[3:7] |
gatedClock | 0:8e898e1270d6 | 658 | buildHexIndex = hex(loopIndex) |
gatedClock | 0:8e898e1270d6 | 659 | buildHexIndex = buildHexIndex[2:] |
gatedClock | 0:8e898e1270d6 | 660 | if (len(buildHexIndex) == 1): buildHexIndex = "0" + buildHexIndex |
gatedClock | 0:8e898e1270d6 | 661 | buildHexIndex = "0x" + buildHexIndex |
gatedClock | 0:8e898e1270d6 | 662 | dumpString = " {} 0x{}\n".format(buildHexIndex,buildHextmmVALString) |
gatedClock | 0:8e898e1270d6 | 663 | hFile.write(dumpString) |
gatedClock | 0:8e898e1270d6 | 664 | print(dumpString[0:len(dumpString)-1]) |
gatedClock | 0:8e898e1270d6 | 665 | sleep(self.__sleepVal) |
gatedClock | 0:8e898e1270d6 | 666 | |
gatedClock | 0:8e898e1270d6 | 667 | hFile.close() # close the dump file. |
gatedClock | 0:8e898e1270d6 | 668 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 669 | # BEGIN THREADED CODE. #=============================== |
gatedClock | 0:8e898e1270d6 | 670 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 671 | def doRun(self): # drives the CPU running. |
gatedClock | 0:8e898e1270d6 | 672 | while(self.__isRunning): |
gatedClock | 0:8e898e1270d6 | 673 | self.selectStepButtonPressed() |
gatedClock | 0:8e898e1270d6 | 674 | self.__masterWidget.update_idletasks() |
gatedClock | 0:8e898e1270d6 | 675 | if (self.__isRunning == 2): sleep(1.0) |
gatedClock | 0:8e898e1270d6 | 676 | #-----------------------------------------------#------------------------------- |
gatedClock | 0:8e898e1270d6 | 677 | # the test consists of loading the add-list program into main memory, |
gatedClock | 0:8e898e1270d6 | 678 | # running it, dumping the result to a file, and comparing that file |
gatedClock | 0:8e898e1270d6 | 679 | # to the expected result. |
gatedClock | 0:8e898e1270d6 | 680 | |
gatedClock | 0:8e898e1270d6 | 681 | def doTest(self): # drives the test. |
gatedClock | 0:8e898e1270d6 | 682 | while(self.__testRunning): |
gatedClock | 0:8e898e1270d6 | 683 | # load program into main memory. |
gatedClock | 0:8e898e1270d6 | 684 | self.progamMainMemory("prog_add_list.txt") |
gatedClock | 0:8e898e1270d6 | 685 | |
gatedClock | 0:8e898e1270d6 | 686 | # clear instruction register. |
gatedClock | 0:8e898e1270d6 | 687 | self.__iUSB.write(self.buildWriteIRCommand("0000")) |
gatedClock | 0:8e898e1270d6 | 688 | |
gatedClock | 0:8e898e1270d6 | 689 | # rewind program counter. |
gatedClock | 0:8e898e1270d6 | 690 | PCVal = self.formatByteStringForTransmit("0") |
gatedClock | 0:8e898e1270d6 | 691 | writePCcommand = self.buildWriteRegisterCommand("4",PCVal) |
gatedClock | 0:8e898e1270d6 | 692 | self.__iUSB.write(writePCcommand) |
gatedClock | 0:8e898e1270d6 | 693 | self.selectRegReadButtonPressed() |
gatedClock | 0:8e898e1270d6 | 694 | |
gatedClock | 0:8e898e1270d6 | 695 | |
gatedClock | 0:8e898e1270d6 | 696 | for stepIndex in range(0, 196): # step through program. |
gatedClock | 0:8e898e1270d6 | 697 | self.selectStepButtonPressed() |
gatedClock | 0:8e898e1270d6 | 698 | |
gatedClock | 0:8e898e1270d6 | 699 | # dump result to file. |
gatedClock | 0:8e898e1270d6 | 700 | self.dumpMainMemory ("dump_test.txt") |
gatedClock | 0:8e898e1270d6 | 701 | |
gatedClock | 0:8e898e1270d6 | 702 | # build and run test commands. |
gatedClock | 0:8e898e1270d6 | 703 | self.__testIter = self.__testIter + 1 |
gatedClock | 0:8e898e1270d6 | 704 | iterationText = "test iteration {}".format(self.__testIter) |
gatedClock | 0:8e898e1270d6 | 705 | iterationText = "echo '" + iterationText + "' >> testlog.txt" |
gatedClock | 0:8e898e1270d6 | 706 | os.system("echo ============================ >> testlog.txt") |
gatedClock | 0:8e898e1270d6 | 707 | os.system("date >> testlog.txt") |
gatedClock | 0:8e898e1270d6 | 708 | os.system(iterationText) |
gatedClock | 0:8e898e1270d6 | 709 | os.system("echo 'compare dump_test.txt against dump_add_list.txt' >> testlog.txt") |
gatedClock | 0:8e898e1270d6 | 710 | os.system("diff dump_add_list.txt dump_test.txt >> testlog.txt") |
gatedClock | 0:8e898e1270d6 | 711 | |
gatedClock | 0:8e898e1270d6 | 712 | self.__masterWidget.update_idletasks() |
gatedClock | 0:8e898e1270d6 | 713 | #===============================================#=============================== |
gatedClock | 0:8e898e1270d6 | 714 | |
gatedClock | 0:8e898e1270d6 | 715 | |
gatedClock | 0:8e898e1270d6 | 716 | |
gatedClock | 0:8e898e1270d6 | 717 | |
gatedClock | 0:8e898e1270d6 | 718 | |
gatedClock | 0:8e898e1270d6 | 719 | |
gatedClock | 0:8e898e1270d6 | 720 | |
gatedClock | 0:8e898e1270d6 | 721 | |
gatedClock | 0:8e898e1270d6 | 722 | |
gatedClock | 0:8e898e1270d6 | 723 | |
gatedClock | 0:8e898e1270d6 | 724 | |
gatedClock | 0:8e898e1270d6 | 725 | |
gatedClock | 0:8e898e1270d6 | 726 | |
gatedClock | 0:8e898e1270d6 | 727 | |
gatedClock | 0:8e898e1270d6 | 728 | |
gatedClock | 0:8e898e1270d6 | 729 | |
gatedClock | 0:8e898e1270d6 | 730 | |
gatedClock | 0:8e898e1270d6 | 731 | |
gatedClock | 0:8e898e1270d6 | 732 | |
gatedClock | 0:8e898e1270d6 | 733 | |
gatedClock | 0:8e898e1270d6 | 734 | |
gatedClock | 0:8e898e1270d6 | 735 | |
gatedClock | 0:8e898e1270d6 | 736 | |
gatedClock | 0:8e898e1270d6 | 737 | |
gatedClock | 0:8e898e1270d6 | 738 | |
gatedClock | 0:8e898e1270d6 | 739 | |
gatedClock | 0:8e898e1270d6 | 740 |