├── README.md └── TopCtrl.vhd /README.md: -------------------------------------------------------------------------------- 1 | # NISC 2 | A single instruction set processor architecture 3 | This is my first time using Github. 4 | Currently only preliminary specifications are given and may be further refined. 5 | Suggestions and requests are welcome. 6 | When I figure out how to do it I would like to list proposals and have a vote on which to implement. 7 | Implementing this might be a good project for a processor design course. 8 | VHDL code to follow when specs are firm. 9 | ## About NISC 10 | NISC is my particular brand of One Instruction Set Computer (OISC) with Transport Triggered Architecture (TTA). 11 | The operation it performs is Move. 12 | I call it NISC for Null Instruction Set Computer because the set of all opcodes is the null set. 13 | There is no instruction which tells it to Move. It just Moves. 14 | It is not related to [No Instruction Set Computing](https://en.wikipedia.org/wiki/No_instruction_set_computing). 15 | I didn't want to call it SISC for Single Instruction Set Computer because SISC sounds like CISC and I like to avoid confusion. I wasn't sure how to pronounce OISC. I also ruled out Mono-Instuction Set Computer (MISC) because I didn't want it filed under Misc. 16 | Although there is no opcode, instructions take two (or three) arguments. 17 | The arguments are source address, destination address, and immediate data. 18 | The source address and destination address are always present but the immediate data is optional. 19 | NISC is an entire family with a scalable architecture. 20 | What will be described is NISC6 because data and addresses are 2 to the 6th power (64 bits). NISC5 has 32 bit data and addresses. 21 | ## The Controller 22 | - There is a state machine which controls overall operation. 23 | - There are 3 registers which are not directly visible to the programmer. 24 | 1. SAR Source Address Register 25 | 2. DAR Destination Address Register 26 | 3. TMP Temporary Register 27 | - Everything else is memory mapped starting at the beginning of memory. There is a single memory space. 28 | - The memory is not byte addressable like many processors. Each address holds a 64 bit Word. 29 | - It is Little Endian where applicable. 30 | - Peripherals should be memory mapped. 31 | 32 | This is the Von Neumann version with unified code and data address space. 33 | Using a Harvard architecture with separate code and data spaces would double throughput but would require instruction invalidation for Jumps and Calls. I wanted to keep it simple. 34 | Making data and address widths equal allows us to fetch an address in a single cycle. If the data width is less than address width then multiple cycles are needed to fetch an address. With a wider data width, both addresses may be read at once saving a cycle. 35 | 36 | The state machine controller normally cycles through 4 states: 37 | 1. Output AP, Fetch Source Address, Increment AP (Argument Pointer, same as a Program Counter) 38 | 2. Output AP, Fetch Destination Address, Increment AP 39 | 3. Read from Source Address into TMP 40 | 4. Write TMP to Destination Address 41 | and then it repeats. 42 | 43 | Before it gets to state 1 the machine looks for Int and DMA Requests and will go to other states to acknowledge them. Once state 1 starts Int and DMA Requests will not be accepted again until state 4 finishes. Block instructions also alter this cycle by repeating state 3 and/or state 4 a counted number of times. 44 | ## Address Definitions 45 | ### Overview 46 | Processor addresses start at the beginning of memory. 128K Words Reserved for processor internals. 47 | Peripherals should be mapped following the processor addresses. 48 | RAM is mapped after the peripherals and before ROM. 49 | ROM is expected at the highest part of memory. 50 | ### Processor Addresses 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 |
AddrWidthNameReadWriteDMA RdDMA WrNOTES
1, 2, 3
000064APAPJumpAPAP4
000164APX(AP++)Call0no effect5
000264RNDRandomRel JumpRNDno effect6
000364CTRCount Rel CallCTRno effect7
000464IARInt Addr RegInt AddrIARIAR8, 9
000564ICRInt Ctrl RegInt Ctrl RegICRICR10
000664DMACRDMA Ctrl RegDMA Ctrl RegDMACRDMACR11
000764BLKCNT BLKCNT RegBLKCNT RegBLKCNTBLKCNT12
000864BLKCTRLBLKCTRL Reg BLKCTRL RegBLKCTRLBLKCTRL13
000964ACCACCACCACCACC14
000A64ACCI(ACC)(ACC)ACCno effect15
000B64ANDCYTMP AND ACC=>ACCCYCY16, 17
000C64ORZFTMP OR ACC=>ACCZFZF16, 18
000D64XORBITCNTTMP XOR ACC=>ACCBITCNTBITCNT16, 19
000E64ADDBCRZTMP + ACC=>ACCBCRZBCRZ20
000F64ADCBCROTMP + ACC + C=>ACCBCROBCRO21
001064SUBBCLZACC - TMP=>ACCBCLZBCLZ22
001164SBBBCLOACC - TMP - C=>ACCBCLOBCLO23
001264CMPall 1sadjust ZF and CYall 1sno effect24
00136SWAPTBDACC modifiedTBDno effect25
001464ILVIHigh ILVIBit interleaveHigh ILVIload only26
001564DLVIHigh DLVIBit deinterleaveHigh DLVIload only27
001664ILVPHigh ILVPPair interleaveHigh ILVPload only28
001764DLVPHigh DLVPPair deinterleaveHigh DLVPload only29
001864ILVNHigh ILVNNibble interleaveHigh ILVNload only30
001964DLVNHigh DLVNNibble deinterleaveHigh DLVNload only31
001A64ILVBHigh ILVBByte interleaveHigh ILVBload only32
001B64DLVBHigh DLVBByte deinterleaveHigh DLVBload only33
001C64ILVQHigh ILVQQuarter interleaveHigh ILVQload only34
001D64DLVQHigh DLVQQuarter deinterleaveHigh DLVQload only35
001E64ILVHHigh ILVHHalf interleaveHigh ILVHload only36
001F64DLVHHigh DLVHHalf deinterleaveHigh DLVHload only37
002064CVCV/NC ValueCV Value CV ValueCV Value38
002164NCCV/NC ValueNC ValueNC ValueNC Value39
002264ZVZV/NZ ValueZV Value ZV ValueZV Value40
002364NZZV/NZ ValueNZ ValueNZ ValueNZ Value41
002464POPO/PE ValuePO Value PO ValuePO Value42
002564PEPO/PE ValuePE ValuePE ValuePE Value43
44
003064WReg0WReg0 WReg0 WReg0WReg045
003164WReg1WReg1 WReg1 WReg1WReg145
003264WReg2WReg2 WReg2 WReg2WReg245
003364WReg3WReg3 WReg3 WReg3WReg345
003464WReg4WReg4 WReg4 WReg4WReg445
003564WReg5WReg5 WReg5 WReg5WReg545
003664WReg6WReg6 WReg6 WReg6WReg645
003764WReg7WReg7 WReg7 WReg7WReg745
003864WReg8WReg8 WReg8 WReg8WReg845
003964WReg9WReg9 WReg9 WReg9WReg945
003A64WRegAWRegA WRegA WRegAWRegA45
003B64WRegBWRegB WRegB WRegBWRegB45
003C64WRegCWRegC WRegC WRegCWRegC45
003D64WRegDWRegD WRegD WRegDWRegD45
003E64WRegEWRegE WRegE WRegEWRegE45
003F64WRegFWRegF WRegF WRegFWRegF45
0040
to
007F
64BRLS 46
008064Cnt1Cnt1Cnt1Cnt1Cnt147
008164Lim1Lim1Lim1Lim1Lim148
008264Und1Und1
or
Ovr1
Und1Und1Und149
008364Ovr1Und1
or
Ovr1
Ovr1Ovr1Ovr150
008464Cnt2Cnt2Cnt2Cnt2Cnt251
008564Lim2Lim2Lim2Lim2Lim252
008664Und2Und2
or
Ovr2
Und2Und2Und253
008764Ovr2Und2
or
Ovr2
Ovr2Ovr2Ovr254
008864Cnt3Cnt3Cnt3Cnt3Cnt351
008964Lim3Lim3Lim3Lim3Lim352
008A64Und3Und3
or
Ovr3
Und3Und3Und353
008B64Ovr3Und3
or
Ovr3
Ovr3Ovr3Ovr354
008C64Cnt4Cnt4Cnt4Cnt4Cnt451
008D64Lim4Lim4Lim4Lim4Lim452
008E64Und4Und4
or
Ovr4
Und4Und4Und453
008F64Ovr4Und4
or
Ovr4
Ovr4Ovr4Ovr454
009064Cnt5Cnt5Cnt5Cnt5Cnt551
009164Lim5Lim5Lim5Lim5Lim552
009264Und5Und5
or
Ovr5
Und5Und5Und553
009364Ovr5Und5
or
Ovr5
Ovr5Ovr5Ovr554
009464Cnt6Cnt6Cnt6Cnt6Cnt651
009564Lim6Lim6Lim6Lim6Lim652
009664Und6Und6
or
Ovr6
Und6Und6Und653
009764Ovr6Und6
or
Ovr6
Ovr6Ovr6Ovr654
009864Cnt7Cnt7Cnt7Cnt7Cnt751
009964Lim7Lim7Lim7Lim7Lim752
009A64Und7Und7
or
Ovr7
Und7Und7Und753
009B64Ovr7Und7
or
Ovr7
Ovr7Ovr7Ovr754
009C64Cnt8Cnt8Cnt8Cnt8Cnt851
009D64Lim8Lim8Lim8Lim8Lim852
009E64Und8Und8
or
Ovr8
Und8Und8Und853
009F64Ovr8Und8
or
Ovr8
Ovr8Ovr8Ovr854
00Ax64RegAxRegAxRegAxRegAxRegAx55, 56
00Bx64RegBx(RegAx)(RegAx)RegAxno effect55, 57
00Cx64RegCx(RegAx--)(++RegAx)RegAxno effect55, 58
00Dx64RegDx(--RegAx)(RegAx++)RegAxno effect55, 59
00Ex64RegEx(RegAx++)(--RegAx)RegAxno effect55, 60
00Fx64RegFx(++RegAx) (RegAx--) RegAxno effect55, 61
010064CHOP CHOPCHOPCHOP CHOP62
010164CHOPI(CHOP)(CHOP)0no effect63
0102
0103
32CHOPLH
CHOPHH
CHOP(31 downto 0)
CHOP(63 downto 32)
CHOP(31 downto 0)
CHOP(63 downto 32)
0no effect64
0104
0105
0106
0107
16CHOPQ0
CHOPQ1
CHOPQ2
CHOPQ3
CHOP(15 downto 0)
CHOP(31 downto 16)
CHOP(47 downto 32)
CHOP(63 downto 48)
CHOP(15 downto 0)
CHOP(31 downto 16)
CHOP(47 downto 32)
CHOP(63 downto 48)
0no effect65
0108
to
010F
8CHOPB0
to
CHOPB7
CHOP(7 downto 0)
to
CHOP(63 downto 56)
CHOP(7 downto 0)
to
CHOP(63 downto 56)
0no effect66
0110
to
011F
4CHOPN0
to
CHOPN15
CHOP(3 downto 0)
to
CHOP(63 downto 60)
CHOP(3 downto 0)
to
CHOP(63 downto 60)
0no effect67
0120
to
013F
2CHOPP0
to
CHOPP31
CHOP(1 downto 0)
to
CHOP(63 downto 62)
CHOP(1 downto 0)
to
CHOP(63 downto 62)
0no effect68
0140
to
017F
1CHOPB0
to
CHOPB63
CHOP(0)
to
CHOP(63)
CHOP(0)
to
CHOP(63)
0no effect69
44
10000
to
1FFFF
64CONST0000
to
FFFF
no effect0000
to
FFFF
no effect70
368 | 369 | NOTES: 370 | 1. DMA Read and Write must be different to avoid triggering the TTA effects. 371 | 2. Only the 4 lowest hex digits of address are shown. The high 12 digits are all 0's. 372 | 3. Addresses not shown (skipped) are undefined and should Read as 0. Write should have no effect. 373 | 4. Argument Pointer is the same as a Program Counter. Reset sets all bits. 374 | 5. Reading APX reads from memory pointed to by AP and increments AP. Writing APX pushes AP onto the stack and loads AP (Call). 375 | - Reading APX is the only instruction which uses the third argument as immediate data. 376 | 6. RND is an LFSR (Read only) which shifts on each clock. Writing adds to AP (Relative Jump). 377 | 7. CTR is an up-counter incremented on every clock. Writing CTR pushes AP onto the stack and adds to AP (Relative Call). 378 | 8. Interrupt Address Register holds the address of the ISR (Interrupt Service Routine) called during Interrupt Acknowledge. 379 | 9. Only one interrupt is implemented in processor. External interrupt controller may expand this. 380 | 10. Interrupt Control Register is a work in progress. Enable/Disable Bit is a minimum. 381 | 11. DMA Control defaults to enabled and can be used for debugging, allowing a single processor cycle then reading all registers. 382 | 12. BLKCNT is a counter with the number of times to repeat an instruction, counts after Write cycle when enabled. 383 | 13. BLKCTRL controls block operation. When loaded, the next instruction is a block instruction. 384 | - Bit 0 - Setting this bit starts a Block Instruction 385 | - Bit 1 - 0 = decrement Block Counter, 1 = increment Block Counter 386 | - Bit 2 - 1 = increment SAR 387 | - Bit 3 - 1 = decrement SAR, when Bit 2 and Bit 3 are the same SAR is unchanged 388 | - Bit 4 - 1 = increment DAR 389 | - Bit 5 - 1 = decrement DAR, when Bit 4 and Bit 5 sre the same DAR is unchanged 390 | - Bit 6 - 1 = read only once, write using same data. Bits 2 and 3 are ignored. Typically used for block fill. 391 | 14. Accumulator is affected by writes to this and the following 7 addresses. 392 | 15. Accumulator Indirect uses ACC as a pointer to memory. 393 | 16. Write clears Carry Flag. Zero Flag is set if all ACC bits are zero, cleared otherwise. 394 | 17. Write to AND causes data to be ANDed with ACC. Reading returns CY (Carry Flag). 395 | 18. Write to OR causes data to be ORed with ACC. Reading returns ZF (Zero Flag). 396 | 19. Write to XOR causes data to be XORed with ACC. Reading returns BITCNT (Count of set bits in ACC) from 0 to 64. 397 | 20. Write to ADD adds data to ACC. CY and ZF are adjusted appropriately. BCRZ is bit count from right (LSB) to first zero. 398 | 21. Write to ADC adds data and CY to ACC. CY and ZF are adjusted. BCRO is bit count from right to first 1 (0 to 64). 399 | 22. Write to SUB subtracts data from ACC. CY and ZF are adjusted. BCLZ is bit count from left (MSB) to first zero. 400 | 23. Write to SBB subtracts data and CY from ACC. CY and ZF are adjusted. BCLZ is bit count from left to first 1 bit. 401 | 24. CMP is compare. ZF and CY are adjusted as if value was subtracted from ACC. ACC is unchanged. 402 | 25. Swaps parts of ACC. TBD means To Be Determined. 403 | - Bit 0 swaps Bits within Pairs 404 | - Bit 1 swaps Pairs within Nibbles 405 | - Bit 2 swaps Nibbles within Bytes 406 | - Bit 3 swaps Bytes within Quarter Words 407 | - Bit 4 swaps Quarter Words within Half Words 408 | - Bit 5 swaps Half Words within ACC 409 | 26. Individual Bits are interleaved with Bits of ACC. Low order bits are in ACC. High order bits are available here. 410 | 27. Individual Bits are deinterleaved with Bits of ACC. Odd bits in ACC. Even bits are available here. 411 | 28. Bit Pairs are interleaved with Bits of ACC. Low order Pairs are in ACC. High order Pairs are available here. 412 | 29. Bit Pairs are deinterleaved with Bits of ACC. Odd Pairs in ACC. Even Pairs are available here. 413 | 30. Nibbles are interleaved with ACC. Low order Nibbles are in ACC. High order Nibbles are available here. 414 | 31. Nibbles are deinterleaved with ACC. Odd Nibbles in ACC. Even Nibbles are available here. 415 | 32. Bytes are interleaved with ACC. Low order Bytes are in ACC. High order Bytes are available here. 416 | 33. Byte are deinterleaved with ACC. Odd Bytes in ACC. Even Bytes are available here. 417 | 34. Quarter Words are interleaved with ACC. Low order Quarters are in ACC. High order Quarters are available here. 418 | 35. Quarter Words are deinterleaved with ACC. Odd Quarters in ACC. Even Quarters are available here. 419 | 36. Half Words are interleaved with ACC. Low Halves are in ACC. High Halves are available here. 420 | 37. Half Words are deinterleaved with ACC. Odd Halves in ACC. Even Halves are available here. 421 | 38. Write to CV sets the value returned when reading either CV or NC if CY is set when reading. 422 | 39. Write to NC sets the value returned when reading either CV or NC if CY is clear when reading. 423 | 40. Write to ZV sets the value returned when reading either ZV or NZ if ZF is set when reading. 424 | 41. Write to NZ sets the value returned when reading either ZV or NZ if ZF is clear when reading. 425 | 42. Write to PO sets the value returned when reading either PO or PE if BITCNT(0) is set when reading. Parity odd. 426 | 43. Write to PE sets the value returned when reading either PO or PE if BITCNT(0) is clear when reading. Parity even. 427 | 44. Space for more stuff. 428 | 45. Working Registers. These 16 registers do nothing special. They are just like RAM except they never generate wait states. 429 | 46. Barrel Rotate. There is only one register here. All addresses in this range read and write to it rotated relative to their addresses. Write to 30 and read from 31 rotates one bit to the right. Write to 38 and read from 30 rotates 8 bits to the left. 430 | 47. Unsigned counter which counts down when Und1 is read and counts up when Ovr1 is read. 431 | 48. Unsigned Limit register against which Cnt1 is compared. 432 | 49. Unsigned register which returns Und1 if Cnt1 =< Lim1 else returns Ovr1. Reading decrements Cnt1. DMA Rd does not affect Cnt1. 433 | 50. Unsigned register which returns Ovr1 if Cnt1 >= Lim1 else returns Und1. Reading increments Cnt1. DMA Rd does not affect Cnt1. 434 | 51. Unsigned counter similar to Cnt1. 435 | 52. Unsigned Limit register similar to Lim1. 436 | 53. Unsigned register similar to Und1. 437 | 54. Unsigned register similar to Ovr1. 438 | 55. x here means all values from 0 to F. 439 | 56. There are sixteen registers. 440 | 57. These addresses use the Ax registers as memory pointers for read and write. 441 | 58. These addresses use the Ax registers as stack pointers. Postdecremented read, Preincremented write. 442 | 59. These addresses use the Ax registers as stack pointers. Predecremented read, Postincremented write. 443 | 60. These addresses use the Ax registers as stack pointers. Postincremented read, Predecremented write. 444 | 61. These addresses use the Ax registers as stack pointers. Preincremented read, Postdecremented write. 445 | - 00FF is the system stack used for Call and Relative Call when the AP gets pushed. 446 | 62. There is only one register in the next 0x80 addresses. It gets CHOPped into pieces and put back together. 447 | 63. CHOP may be used as a memory pointer by using this address. 448 | 64. CHOP Low Half and Chop High Half are read and written here. They are in the low bits of a read. The high bits of the read are all zeroes. Only the low bits of a write are used. The high bits of the write are irrelevant and ignored. 449 | 65. CHOP in 4 16-bit quarters. Upper bits are zeroes for read and don't care for write. 450 | 66. CHOP 8 Bytes. 451 | 67. CHOP 16 Nibbles (4 Bits each). 452 | 68. CHOP Pairs of Bits. There are 32 of them. 453 | 69. CHOP Bits, all 64 of them individually addressable. 454 | 70. Small constant ROM. There is not actually a ROM here. With a little bit of hardware we can detect reads in this range and return the low 16 bits of address, eliminating the need to store small constants in the 0000-FFFF range in memory or to use them as immediate data in APX read instruction. With the huge memory space we have, I don't consider this wasteful. 455 | -------------------------------------------------------------------------------- /TopCtrl.vhd: -------------------------------------------------------------------------------- 1 | -- TopCtrl.vhdl 2 | -- Version 2.0 3 | -- Overall Machine State Controller for NISC 4 | -- Word Size = Addr Size for this model 5 | -- Interrupt Control 6 | -- DMA Control 7 | -- 4 cycle and block multi-cycle 8 | -- Fetch Src Addr 9 | -- Fetch Dst Addr 10 | -- Read Src 11 | -- Write Dest 12 | 13 | library IEEE; 14 | use IEEE.STD_LOGIC_1164.ALL; 15 | use IEEE.STD_LOGIC_ARITH.ALL; 16 | use IEEE.STD_LOGIC_UNSIGNED.ALL; 17 | 18 | entity TopCtrl is 19 | Port ( CLK : in std_logic; -- System Clock 20 | Reset_In : in std_logic; -- Reset Signal 21 | Ready : in std_logic; -- Ready Signal 22 | Rept : in std_logic; -- Block Repeat (repeats Read and Write) 23 | UseFSrc : in std_logic; -- Use First Source (Reads once and repeats Write) 24 | BUSRQ : in std_logic; -- DMA Bus Request 25 | INTRQ : in std_logic; -- Interrupt Request 26 | DMA_EN : in std_logic; -- DMA Enabled Status 27 | INT_EN : in std_logic; -- Interrupt Enabled Status 28 | Reset_Out : out std_logic; -- System Reset 29 | BUSACK : out std_logic; -- Bus Grant Acknowledged 30 | INTACK : out std_logic; -- Interrupt Acknowledged 31 | Fetch : out std_logic; -- Instruction Fetch Cycle 32 | SorD : out std_logic; -- Fetch SrcAddr or DstAddr 33 | Mem_RD : out std_logic; -- Memory Read Cycle 34 | Mem_WR : out std_logic); -- Memory Write Cycle 35 | end TopCtrl; 36 | 37 | architecture Behavioral of TopCtrl is 38 | 39 | type CycleCtrl_type is (State_Reset, State_BusGrant, State_IntStart, State_IntFinish, State_FetchSA, State_FetchDA, State_SourceRd, State_DestWr); 40 | 41 | signal TopState : CycleCtrl_type := State_Reset; 42 | 43 | signal reset_i : std_logic; 44 | signal busack_p : std_logic; 45 | signal intack_p : std_logic; 46 | signal fetch_p : std_logic; 47 | signal Mem_RD_p : std_logic; 48 | signal Mem_WR_p : std_logic; 49 | signal ready_i : std_logic; 50 | signal DMA_EN_i : std_logic; 51 | signal INT_EN_i : std_logic; 52 | signal SorD_i : std_logic; 53 | 54 | begin 55 | 56 | TopCtrl_State : process (CLK, Reset_In) is 57 | 58 | begin 59 | if rising_edge(CLK) then 60 | if Reset_In='1' then 61 | TopState <= State_Reset; 62 | else 63 | case TopState is 64 | -- Reset 65 | when State_Reset => 66 | if (Reset_In = '1') then 67 | TopState <= State_Reset; 68 | elsif (BUSRQ = '1' AND DMA_EN_i = '1') then 69 | TopState <= State_BusGrant; 70 | elsif (INTRQ = '1' AND INT_EN_i = '1') then 71 | TopState <= State_IntStart; 72 | else 73 | TopState <= State_FetchSA; 74 | end if; 75 | -- DMA (External) 76 | when State_BusGrant => 77 | if (BUSRQ = '1') then 78 | TopState <= State_BusGrant; -- continue bus grant 79 | elsif (BUSRQ = '0') then 80 | if (INTRQ = '1' AND INT_EN_i = '1') then 81 | TopState <= State_IntStart; -- service interrupt 82 | else 83 | TopState <= State_FetchSA; -- resume processing 84 | end if; 85 | end if; 86 | -- INT 87 | when State_IntStart => -- PC --> Stack 88 | if (ready_i = '0') then 89 | TopState <= State_IntStart; 90 | elsif (ready_i = '1') then 91 | TopState <= State_IntFinish; 92 | end if; 93 | 94 | when State_IntFinish => -- ISR Addr --> PC 95 | if (ready_i = '0') then 96 | TopState <= State_IntFinish; 97 | elsif (ready_i = '1') then 98 | if (BUSRQ = '1' AND DMA_EN_i = '1') then 99 | TopState <= State_BusGrant; -- bus grant 100 | else 101 | TopState <= State_FetchSA; -- resume processing 102 | end if; 103 | end if; 104 | -- Source Addr Fetch 105 | when State_FetchSA => -- Get Src Addr 106 | if (ready_i = '0') then 107 | TopState <= State_FetchSA; 108 | elsif (ready_i = '1') then 109 | TopState <= State_FetchDA; 110 | end if; 111 | 112 | -- Dest Addr Fetch 113 | when State_FetchDA => -- Get Dest Addr 114 | if (ready_i = '0') then 115 | TopState <= State_FetchDA; 116 | elsif (ready_i = '1') then 117 | TopState <= State_SourceRd; 118 | end if; 119 | -- Source RD 120 | when State_SourceRd => -- Read from Src Addr 121 | if (ready_i = '0') then 122 | TopState <= State_SourceRd; 123 | elsif (ready_i = '1') then 124 | TopState <= State_DestWr; 125 | end if; 126 | -- Dest WR 127 | when State_DestWr => -- Write to Dest Addr 128 | if (ready_i = '0') then 129 | TopState <= State_DestWr; 130 | elsif (ready_i = '1') then 131 | if (Rept = '1') then -- Block Mode 132 | if (UseFSrc = '1') then -- Block Fill 133 | TopState <= State_DestWr; 134 | else 135 | TopState <= State_SourceRd; 136 | end if; 137 | elsif (BUSRQ = '1' AND DMA_EN_i = '1') then 138 | TopState <= State_BusGrant; 139 | elsif (INTRQ = '1' AND INT_EN_i = '1') then 140 | TopState <= State_IntStart; 141 | else 142 | TopState <= State_FetchSA; 143 | end if; 144 | end if; 145 | when others => 146 | TopState <= State_Reset; 147 | end case; 148 | end if; 149 | end if; 150 | end process; 151 | 152 | 153 | ready_i <= Ready; 154 | DMA_EN_i <= DMA_EN; 155 | INT_EN_i <= INT_EN; 156 | 157 | -- signal assignment statements for combinatorial outputs 158 | 159 | reset_i <= '1' when (TopState = State_Reset) else 160 | '0'; 161 | 162 | busack_p <= '1' when (TopState = State_BusGrant) else 163 | '0'; 164 | 165 | intack_p <= '1' when (TopState = State_IntStart) else 166 | '1' when (TopState = State_IntFinish) else 167 | '0'; 168 | 169 | fetch_p <= '1' when (TopState = State_FetchSA) or (TopState = State_FetchDA) else 170 | '0'; 171 | 172 | SorD_i <= '1' when (TopState = State_FetchDA) else 173 | '0'; 174 | 175 | Mem_RD_p <= '1' when (TopState = State_SourceRd) else 176 | '0'; 177 | 178 | Mem_WR_p <= '1' when (TopState = State_DestWr) else 179 | '1' when (TopState = State_IntStart) else 180 | '0'; 181 | 182 | Reset_Out <= reset_i; 183 | BUSACK <= busack_p; 184 | INTACK <= intack_p; 185 | Fetch <= fetch_p; 186 | SorD <= SorD_i; 187 | Mem_RD <= Mem_RD_p; 188 | Mem_WR <= Mem_WR_p; 189 | 190 | end Behavioral; 191 | --------------------------------------------------------------------------------