'#define PROP2_REVA #define PROP2_REVB CON XTALFREQ = 20_000_000 'PLL stage 0: crystal frequency XDIV = 20 'PLL stage 1: crystal divider (1..64) XMUL = 40 'PLL stage 2: crystal / div * mul (1..1024) XDIVP = 1 'PLL stage 3: crystal / div * mul / divp (1,2,4,6..30) dmadiv = 1 'sysclocks per streamer cycle compref = 0 'lag compensation - Useful values are: 3-0 for rx_wait, 19-22 for tx_wait '#define HR_READS #define D_REGD '#define CK_REGD blocks = 2 bytes = 50_000 addr = 4_100_000 ddata = $4_0000 '256 kB hr_base = 16 '0/16/32 'hyperram module base pin hrdrive = 7 '19 ohms HR drive strength ' hrdrive = 6 '22 ohms HR drive strength ' hrdrive = 5 '27 ohms HR drive strength ' hrdrive = 0 '34 ohms HR drive strength ' hrdrive = 4 '34 ohms HR drive strength ' hrdrive = 3 '46 ohms HR drive strength ' hrdrive = 2 '67 ohms HR drive strength ' hrdrive = 1 '115 ohms HR drive strength '---------------------------------------------------------------------------------------------- pinx = hr_base >> 5 bytx = hr_base >> 3 & 3 ram_ck = hr_base + 8 ram_rwds = hr_base + 10 ram_cs = hr_base + 12 flash_ck = hr_base + 9 flash_rwds = hr_base + 11 flash_cs = hr_base + 13 reset = hr_base + 15 _read = %100 _reg = %010 _linear = %001 readreg = _read | _reg | _linear readram = _read | _linear writereg = _reg | _linear writeram = _linear 'Streamer rate for copy testing xcfg = ($4000_0000 / dmadiv)<<1 'bit-shift is compensation to keep it unsigned DAT 'not Spin code ORG 0 'longword addressing at 0 '****************************************************************************** ' COG Variables (Auto-copied to cogram on COGINIT #%0x_xxxx,#0 after program load) '****************************************************************************** msec jmp #_diaginit xtalmul long XMUL 'Assumed to be units of MHz misc1 tickstart long 0 misc2 tickend long 0 FIT 4 'DON'T TOUCH THIS! - more than four preceding variables stops assembly with error ORGF 4 'DON'T TOUCH THIS! - fills unused memory to align with fixed reserved parameters '-------------------------------------------------------- '*** Boot-loader can fill all four of the following *** '-------------------------------------------------------- hw_rev long 0 'hubRAM addr $010 - unused reserved parameter - using to hold revA/B clk_freq long 25_000_000 'hubRAM addr $014 - sysclock frequency, integer frequency in hertz clk_mode long 0 'hubRAM addr $018 - clock mode config word, used directly in HUBSET asyn_baud long 230_400 'hubRAM addr $01c - comport baud rate, integer baud in hertz '-------------------------------------------------------- rstate long 1 count long 0 comp long compref hraddr long addr hrstart long addr hrbytes long bytes hrshorts long bytes/2 hrlongs long bytes/4 fastmask long $8000_0000 txcfg long DM_8bRF | DM_DIGI_IO | (hr_base << 17) | bytes ' DMA cycles (RFBYTE), pins "hr_base" rxcfg long DM_8bWF | DM_DIGI_IO | (hr_base << 17) | bytes ' DMA cycles (WFBYTE), pins "hr_base" #ifdef CK_REGD hrckmode long P_REGD | SPM_STEPS 'mode config for HR clock pin 'hrckmode long P_REGD | P_1K5R | SPM_STEPS 'mode config for HR clock pin, 1.5 kiloOhm drive 'hrckmode long P_REGD | P_1mA | SPM_STEPS 'mode config for HR clock pin, 1.0 milliAmp drive 'hrckmode long PM_DAC124 | ($f0<<8) | SPM_STEPS 'mode config for HR clock pin, 124 Ohm BIT_DAC (high=15, low=0) #else hrckmode long SPM_STEPS 'mode config for HR clock pin 'hrckmode long P_1K5R | SPM_STEPS 'mode config for HR clock pin, 1.5 kiloOhm drive 'hrckmode long P_1mA | SPM_STEPS 'mode config for HR clock pin, 1.0 milliAmp drive #endif #ifdef D_REGD hrdatmode long P_REGD 'mode config for data pin registers (in and out) #else hrdatmode long 0 #endif '------------------------------- '*** User code starts here *** '------------------------------- '------------------------------------------------------------------------------ send_block_dma 'write data to hyperRAM callpa #writeram, #send_ca rdfast fastmask, ptra 'non-blocking ' drvh #ram_rwds callpa hrbytes, #hr_clock_sp mov pa, comp add pa, #(22*dmadiv - 20) 'somewhat uneesasary crafting to help with subsequent tuning waitx pa drvl #ram_rwds 'no masking pollxfi 'clear prior event xinit txcfg, #0 'go! waitxfi 'wait for completion of DMA dirl #ram_rwds setbyte dira+pinx, #0, #bytx 'tristate the HR databus _ret_ outh #ram_cs '------------------------------------------------------------------------------ read_block_dma 'read data from hyperRAM callpa #readram, #send_ca 'block read command, includes padding clocks wrfast fastmask, ptra 'non-blocking setbyte dira+pinx, #0, #bytx 'tristate the HR databus for reading callpa hrbytes, #hr_clock_sp 'start SPI clock, WYPIN is returning instruction mov pa, comp add pa, #(23*dmadiv - 9) 'somewhat unnecessary crafting to help with subsequent tuning waitx pa pollxfi 'clear prior event xinit rxcfg, #0 'go! waitxfi 'wait for completion of DMA '.wloop ' testp #ram_ck wc ' if_nc jmp #.wloop outh #ram_cs _ret_ rdfast #0, #0 '------------------------------------------------------------------------------ hr_clock_sp wrpin hrckmode, #ram_ck dirl #ram_ck add pa, #22 'HR clocks to step out, with 22 leading spacers wxpin #dmadiv, #ram_ck 'HR clock step interval (DDR) dirh #ram_ck wrpin hrdatmode, #hr_base | 7<<6 'eight data pin registers (in and out) _ret_ wypin pa, #ram_ck 'HR clocks to step out '------------------------------------------------------------------------------ send_ca drvh #ram_cs 'ensure hyperRAM is deselected dirl #ram_ck wrpin #0, #ram_ck 'drop out of smartpin mode drvl #ram_ck fltl #ram_rwds wrpin #0, #hr_base | 7<<6 'unregister all data pins setbyte dira+pinx, #$ff, #bytx 'drive data pins andn hraddr, #%111 'address alignment of 16 byte increments or pa, hraddr 'merge address with the three bits of command rol pa, #5 outl #ram_cs 'begin "Command-Address" phase rep @.rend, #4 'four bytes of CA setbyte outa+pinx, pa, #bytx outnot #ram_ck rol pa, #8 .rend setbyte outa+pinx, #0, #bytx 'trailing two nulls outh #ram_ck _ret_ outl #ram_ck '------------------------------------------------------------------------------ send_cr0_bb 'write cog PB register to hyperRAM CR0 register decod hraddr, #11 'mov hraddr, ##$800 callpa #writereg, #send_ca ror pb, #8 setbyte outa+pinx, pb, #bytx outnot #ram_ck rol pb, #8 setbyte outa+pinx, pb, #bytx outnot #ram_ck setbyte dira+pinx, #0, #bytx 'tristate the HR databus _ret_ outh #ram_cs '------------------------------------------------------------------------------ read_cr0_bb 'read data from hyperRAM CR0 register to cog PA register decod hraddr, #11 'mov hraddr, ##$800 callpa #readreg, #send_ca setbyte dira+pinx, #0, #bytx 'tristate the HR databus for reading rep @.rend1, #23 '22 spacers + 1 to fetch first data byte outnot #ram_ck .rend1 mov pa, #0 outnot #ram_ck 'clock for fetching second data byte waitx #4 'compensation for prop2 I/O stages getbyte pa, ina+pinx, #bytx 'collect first data byte (12 sysclocks) outh #ram_cs _ret_ rolbyte pa, ina+pinx, #bytx 'collect second data byte (12 sysclocks) '------------------------------------------------------------------------------ send_block_bb 'write data to hyperRAM callpa #writeram, #send_ca rdfast fastmask, ptra 'non-blocking drvh #ram_rwds rep @.rend1, #22 '22 spacers outnot #ram_ck .rend1 outl #ram_rwds 'no masking rep @.rend2, hrbytes rfbyte pa 'fetch data to write to hyperRAM setbyte outa+pinx, pa, #bytx outnot #ram_ck .rend2 dirl #ram_rwds setbyte dira+pinx, #0, #bytx 'tristate the HR databus _ret_ outh #ram_cs '------------------------------------------------------------------------------ read_block_bb 'read data from hyperRAM callpa #readram, #send_ca wrfast fastmask, ptra 'non-blocking setbyte dira+pinx, #0, #bytx 'tristate the HR databus for reading rep @.rend1, #23 '22 spacers + 1 to fetch first data byte outnot #ram_ck .rend1 waitx #2 'compensation for prop2 I/O stages outnot #ram_ck 'clock for fetching second data byte nop rep @.rend2, hrbytes outnot #ram_ck getbyte pa, ina+pinx, #bytx 'collect data byte from three HR clocks prior (14 sysclocks) wfbyte pa 'stash it .rend2 outh #ram_cs _ret_ rdfast #0, #0 { '------------------------------------------------------------------------------ send_word_bb 'write PB to hyperRAM at "hraddr" callpa #writeram, #send_ca drvh #ram_rwds rep @.rend1, #22 '22 spacers outnot #ram_ck .rend1 outl #ram_rwds 'no masking rol pb, #8 setbyte outa+pinx, pb, #bytx outnot #ram_ck rol pb, #8 setbyte outa+pinx, pb, #bytx outnot #ram_ck rol pb, #8 setbyte outa+pinx, pb, #bytx outnot #ram_ck rol pb, #8 setbyte outa+pinx, pb, #bytx outnot #ram_ck .rend2 dirl #ram_rwds setbyte dira+pinx, #0, #bytx 'tristate the HR databus _ret_ outh #ram_cs '------------------------------------------------------------------------------ send_block_xoro 'write data to hyperRAM callpa #writeram, #send_ca drvh #ram_rwds rep @.rend1, #22 '22 spacers outnot #ram_ck .rend1 outl #ram_rwds 'no masking mov pa, hrbytes shr pa, #2 rep @.rend2, pa xoro32 rstate 'XORO32 has to be paired as a prefixing instruction mov pa, 0-0 rol pa, #8 setbyte outa+pinx, pa, #bytx outnot #ram_ck rol pa, #8 setbyte outa+pinx, pa, #bytx outnot #ram_ck rol pa, #8 setbyte outa+pinx, pa, #bytx outnot #ram_ck rol pa, #8 setbyte outa+pinx, pa, #bytx outnot #ram_ck .rend2 dirl #ram_rwds setbyte dira+pinx, #0, #bytx 'tristate the HR databus _ret_ outh #ram_cs '------------------------------------------------------------------------------ cmp_block_xoro 'read data from hyperRAM callpa #readram, #send_ca setbyte dira+pinx, #0, #bytx 'tristate the HR databus for reading rep @.rend1, #23 '22 spacers + 1 to fetch first data byte outnot #ram_ck .rend1 nop mov pa, hrbytes shr pa, #2 outnot #ram_ck 'clock for fetching second data byte mov pb, #0 rep @.rend2, pa rolbyte pa, ina+pinx, #bytx 'collect data byte from two HR clocks prior (14 sysclocks) outnot #ram_ck add count, pb nop rolbyte pa, ina+pinx, #bytx outnot #ram_ck waitx #2 rolbyte pa, ina+pinx, #bytx outnot #ram_ck xoro32 rstate 'XORO32 has to be paired as a prefixing instruction mov pb, 0-0 rolbyte pa, ina+pinx, #bytx outnot #ram_ck ' cmp pa, pb wz ' if_z add count, #1 xor pb, pa ones pb .rend2 add count, pb _ret_ outh #ram_cs } '============================================================================== '============================================================================== logloop call #setclkfrq 'set new sysclock rate mov pa, xtalmul call #itod mov pb, #" " call #putch mov pb, #"|" call #putch mov comp, #compref comploop { 'erase destination buffer wrfast #0, ptra rep @.rend1, hrlongs wflong #0 .rend1 rdfast #0, #0 'build hammer data mov hraddr, hrstart mov misc2, #blocks '40 x 50,000 = 2 million bytes .bhloop call #send_block_xoro add hraddr, hrshorts djnz misc2, #.bhloop } mov misc1, rstate 'backup the XORO32 state as the compare seed mov hraddr, hrstart mov misc2, #blocks '40 x 50,000 = 2 million bytes .bsloop wrfast #0, ptra rep @.rend1, hrlongs xoro32 rstate 'XORO32 has to be paired as a prefixing instruction mov pb, 0-0 movbyts pb, #%%0123 wflong pb .rend1 rdfast #0, #0 'send data block, starve refresh #ifdef HR_READS call #send_block_bb #else call #send_block_dma #endif add hraddr, hrshorts djnz misc2, #.bsloop { 'do hammering mov misc2, #25 'over two seconds ... mov hraddr, hrstart .fadeloop call #cmp_block_xoro 'used for hammering one block over and over djnz misc2, #.fadeloop } '------------------------------------------------- mov count, #0 mov rstate, misc1 're-seed XORO32 state for compare mov hraddr, hrstart mov misc2, #blocks '40 x 50,000 = 2 million bytes .cmploop 'read back data block, starve refresh again #ifdef HR_READS call #read_block_dma #else call #read_block_bb #endif 'check validity rdfast #0, ptra rep @.rend2, hrlongs rflong pa movbyts pa, #%%0123 xoro32 rstate 'XORO32 has to be paired as a prefixing instruction xor pa, 0-0 'all good is null result ones pa 'count the failed bits add count, pa .rend2 add hraddr, hrshorts '50,000 bytes djnz misc2, #.cmploop '------------------------------------------------- { comploop ' mov misc1, rstate 'backup the XORO32 state as the compare seed mov hraddr, #0 call #send_block_xoro mov misc1, rstate 'backup the XORO32 state as the compare seed mov hraddr, hrstart 'double length call #send_block_xoro ' mov pb, ##$1234_5678 ' mov hraddr, ##2_000_016 ' call #send_word_bb mov misc2, #25 mov hraddr, #0 .fadeloop call #cmp_block_xoro 'used for hammering one block over and over djnz misc2, #.fadeloop mov count, #0 mov rstate, misc1 're-seed XORO32 state for compare ' mov hraddr, #0 mov hraddr, hrstart 'check the extra data call #cmp_block_xoro ' waitx msec '2 ms } { 'erase destination buffer wrfast #0, ##ddata rep @.rend1, hrlongs wflong #0 .rend1 rdfast #0, #0 ' loc ptra, #ddata ' call #send_block_bb 'create reference sdata wrfast #0, ##sdata rep @.rend2, hrlongs getrnd pa wflong pa .rend2 rdfast #0, #0 'do the copy loc ptra, #sdata call #send_block_bb waitx msec '2 ms '----- diag ----- callpa #readram, #send_ca setbyte dira+pinx, #0, #bytx 'tristate the HR databus for reading rep #1, #28 'spacer clocks outnot #ram_ck ' rep #1, ##2_000_000 '2 seconds waitx #38 outnot #ram_ck outnot #ram_ck nop nop '--- end diag --- loc ptra, #ddata call #read_block_bb 'compare buffers loc ptra, #sdata loc ptrb, #ddata mov count, #0 rep @.rend, hrlongs rdlong pa, ptra++ rdlong pb, ptrb++ cmp pa, pb wz if_z add count, #1 .rend } mov pa, count 'tally of buffer matches call #itod incmod comp, #compref+9 wc 'number of columns if_nc jmp #comploop call #putnl ' jmp #logloop 'uncomment this line to cycle forever at one frequency cmp xtalmul, #390 wcz if_b ijnz xtalmul, #logloop 'loop back for next sysclock setting, keep going up until crash 'remember to PRESS RESET BUTTON after crash to minimise heating 'stop call #waittx hubset #$f1 'RCSLOW .cooldown waitx #500 jmp #.cooldown FIT $1e0 'this matches the default diag temporary register use '****************************************************************************** ' HUB Code '****************************************************************************** ORGH sdata long $2d0ba357,$6d6c66c2,$595880d2,$d4fad4fe,$9cc7a70c,$7ecc0330,$90ab2a27,$d6fd0f49 long $bfe7ab51,$d940a3c3,$27e396c4,$2c576dd4,$2de87729,$26fe32a7,$1239d672,$8364bccb long $8fb3ef25,$4d89a713,$e036f856,$6a47db67,$dfc1eec8,$e324a829,$748e9206,$3d226895 long $8c204d48,$3899c0f1,$0d10751c,$c6e7d2d0,$7453fc12,$0a7070c0,$70d5a2a7,$99e380e1 long $d9b2371d,$5f0ca73c,$a257df5e,$9bbd8ede,$2c3dccc3,$43324d7a,$7adca0c3,$930cca8a long $5da405be,$2f0211ca,$f057c5c0,$384f3723,$08e87bae,$199c19cd,$8ff88853,$1c537024 long $58683a9f,$1a389d07,$5df135cb,$0ca8df74,$25ac262d,$7ed66abf,$9a5d4035,$2c193890 long $5bc02c31,$6b4d7f9c,$37d93fb4,$65b3bee7,$14b70f1a,$0e92b6b9,$e7447de7,$5404f8b2 long $e0d5a0bb,$728450f0,$e288cbc0,$898c05cc,$aad7f32a,$26223eca,$a55bf452,$8275c77d long $7f5b8847,$47a512c0,$b496e901,$b4d629fc,$1bd3c32a,$2e312445,$8c22ef03,$ecd99578 long $98a2d236,$2e2c72f2,$3f8659e5,$8cd539c4,$b3f966c1,$1497f0f3,$14c6e7f0,$39fa4c65 long $60bc8c28,$421d26a2,$3d635d75,$ba6a9f16,$eeff695c,$68f1d40f,$d8d82ab2,$ddc0cb56 long $8e3fe27b,$f6d18020,$ccc9e163,$787707c0,$2bd3ffc1,$8efe1ce8,$f300f4ff,$b917df02 long $080c333d,$4f04564c,$aab74a66,$47f41627,$8545a704,$cff9fb64,$3b0d0b02,$68913991 long $a76ef57a,$daf3f653,$1ab25918,$b5944b86,$8257d86e,$c414d4d6,$0aba9492,$e0920004 long $465fffb5,$57eac3f8,$cfb66fdc,$cca2346f,$3d5aabb2,$d9588e33,$2f2d97ff,$0645145b long $59a00194,$7ee7a4ea,$4177e46d,$35723649,$5d3c4114,$4af13053,$941799a3,$c055d7a0 long $6b46ce15,$1bbad0d2,$d81450b4,$fced6dc0,$37a2d903,$4e981b01,$7abb7774,$8ca7742b long $de79b79a,$0c4ed7c4,$0c1aed82,$6a4501a2,$cf34729c,$8dd5ea58,$792297f0,$dfef2342 long $5b8037d2,$19d2a65e,$27d7d10f,$11d13657,$0588f65d,$9e224f92,$1b2bfc21,$c59eb4b2 long $81789f07,$4cabac71,$fdcc0c2d,$8f2a629f,$bdbd346b,$23005d82,$14a0e8ea,$491ae78c long $3565d28f,$3be55fab,$4ab0f8ee,$3d75b8ca,$2f0c25db,$98ccd4a3,$70b483be,$959800bb long $1b8f3e68,$a133c137,$57f02b81,$52c8ab2e,$e9f51945,$5222c383,$ef565ad7,$2efe5551 long $c8eee14c,$3654f36c,$6898077d,$1366348a,$e4a846b1,$7f35e1ac,$ca966722,$3dc05d08 long $83b82cd5,$b5d9c78f,$d163bab0,$2e0e0534,$d8b6af81,$055d7c14,$8cbb7049,$30cad4ce long $2f9f4900,$01fc6759,$6c948a41,$7da9eb23,$75848211,$e2933258,$3af5654e,$3bef0931 long $1d76d6ee,$793c3f51,$c87bb733,$1ff8b939,$507fb3af,$3e40c156,$779da2c2,$a9985f31 long $5805cc10,$661e285c,$f6316f75,$6777f286,$7077a5ca,$40ddd087,$e7061a71,$c10cf467 long $741432a2,$1bc6adf0,$4e6eb296,$ebfe6ad3,$f82b42d8,$7d78817f,$e0c0ec0c,$c1eb168b long $25c47f1c,$4fc740fb,$7e2cb89d,$b7fb2531,$874188a5,$9852e35d,$0056372c,$040c157a long $820c5409,$11e2c624,$364f93af,$39b3bb6d,$eeafb35e,$6281b6c1,$02775a4c,$5a404886 long $5bda6365,$dfc39737,$47fbf3a3,$0950444d,$a50431f4,$3275a376,$9ecd8bab,$33ea234f '============================================================================== _main mov bcdlen, #8 '--- tx init --- qdiv clk_freq, #500 'calculate two milliseconds drvl #reset 'reset the hyperRAM chip getqx msec waitx msec 'two milliseconds outh #reset waitx msec 'two milliseconds '---- title ---- call #putsi byte 13,10," HyperRAM Burst ",0 call #putsi #ifdef HR_READS byte "Reads",0 #else byte "Writes",0 #endif call #putsi #ifdef D_REGD byte " - Data pins registered",0 #else byte " - Data pins unregistered",0 #endif call #putsi #ifdef CK_REGD byte ", Clock pin registered",0 #else byte ", Clock pin unregistered",0 #endif call #putsi byte 13,10,"===============================",13,10,"HubStart HyperStart BYTES BLOCKS HR_DIV HR_WRITE HR_READ BASEPIN DRIVE CR0",13,10,0 mov pa, ##ddata call #itoh call #putsp mov pa, hrstart call #itoh call #putsp mov pa, hrbytes call #itoh mov pa, #blocks call #itod mov pa, #dmadiv call #itod call #putsp mov pa, txcfg call #itoh call #putsp mov pa, rxcfg call #itoh mov pa, #hr_base call #itod mov pa, #hrdrive call #itod mov bcdlen, #4 call #read_cr0_bb mov pb, pa andn pb, ##%111<<12 or pb, ##hrdrive<<12 call #send_cr0_bb call #putsp call #read_cr0_bb call #itoh mov bcdlen, #8 call #putsi byte 13,10," ------------------------------------------------------------------------------------------",13,10,"| COUNT OF BIT ERRORS |",13,10,"|------------------------------------------------------------------------------------------|",13,10,"| | Compensations |",13,10,"| XMUL |",0 .tloop mov pa, comp call #itod incmod comp, #compref+9 wc if_nc jmp #.tloop call #putsi byte " |",13,10,"|--------|---------------------------------------------------------------------------------|",13,10,0 getrnd rstate 'randomise initial seed or rstate, #1 'prevent a null seed { mov hrbytes, ##bytes setbyte txcfg ,hrbytes, #0 setbyte rxcfg ,hrbytes, #0 mov hrshorts, hrbytes shr hrshorts, #1 mov hrlongs, hrbytes shr hrlongs, #2 } setxfrq ##xcfg 'set streamer data rate mov ptra, ##ddata jmp #logloop ALIGNL '****************************************************************************** ' Subroutines '****************************************************************************** #include "init-diag.spin2"