'' +--------------------------------------------------------------------------+ '' | Cluso's "Fun with P2 ROM" (c)2019 "Cluso99" (Ray Rodrick) | '' +--------------------------------------------------------------------------+ '' RR20190201 0001a generalised test program '' b try >35MHz ''============================[ CON ]============================================================ CON '+-------[ Select for P2-EVAL ]------------------------------------------------+ _XTALFREQ = 20_000_000 ' crystal frequency _XDIV = 5 '\ '\ crystal divider to give 4.0MHz ' _XMUL = 6 '| 24 MHz '| crystal / div * mul to give 24.0MHz _XMUL = 40 '| 160 MHz '| crystal / div * mul to give 24.0MHz _XDIVP = 1 '/ '/ crystal / div * mul /divp to give 24.0MHz _XOSC = %10 '15pF ' %00=OFF, %01=OSC, %10=15pF, %11=30pF '+-------[ Select for P2D2 ]---------------------------------------------------+ { _XTALFREQ = 12_000_000 ' crystal frequency _XDIV = 4 '\ '\ crystal divider to give 3.0MHz _XMUL = 8 '| 24 MHz '| crystal / div * mul to give 24.0MHz _XDIVP = 2 '/ '/ crystal / div * mul /divp to give 24.0MHz _XOSC = %01 'OSC ' %00=OFF, %01=OSC, %10=15pF, %11=30pF } '+-----------------------------------------------------------------------------+ _XSEL = %11 'XI+PLL ' %00=rcfast(20+MHz), %01=rcslow(~20KHz), %10=XI(5ms), %11=XI+PLL(10ms) _XPPPP = ((_XDIVP>>1) + 15) & $F ' 1->15, 2->0, 4->1, 6->2...30->14 _CLOCKFREQ = _XTALFREQ / _XDIV * _XMUL / _XDIVP ' internal clock frequency _SETFREQ = 1<<24 + (_XDIV-1)<<18 + (_XMUL-1)<<8 + _XPPPP<<4 + _XOSC<<2 ' %0000_000e_dddddd_mmmmmmmmmm_pppp_cc_00 ' setup oscillator _ENAFREQ = _SETFREQ + _XSEL ' %0000_000e_dddddd_mmmmmmmmmm_pppp_cc_ss ' enable oscillator _1us = _clockfreq/1_000_000 ' 1us '------------------------------------------------------------------------------------------------ _baud = 115_200 _bitper = (_clockfreq / _baud) << 16 + 7 ' 115200 baud, 8 bits _txmode = %0000_0000_000_0000000000000_01_11110_0 'async tx mode, output enabled for smart output _rxmode = %0000_0000_000_0000000000000_00_11111_0 'async rx mode, input enabled for smart input '------------------------------------------------------------------------------------------------ rx_pin = 63 ' pin serial receiver tx_pin = 62 ' pin serial transmitter spi_cs = 61 ' pin SPI memory select (also sd_ck) spi_ck = 60 ' pin SPI memory clock (also sd_cs) spi_di = 59 ' pin SPI memory data in (also sd_di) spi_do = 58 ' pin SPI memory data out (also sd_do) '------------------------------------------------------------------------------------------------ test_pin = 49 CON '' +--------------------------------------------------------------------------+ '' | Cluso's LMM_SerialDebugger for P2 (c)2013-2018 "Cluso99" (Ray Rodrick)| '' +--------------------------------------------------------------------------+ '' xxxxxx : xx xx xx xx ... DOWNLOAD: to cog/lut/hub {addr1} following {byte(s)} '' xxxxxx - [xxxxxx] [L] LIST: from cog/lut/hub {addr1} to < {addr2} L=longs '' xxxxxx G GOTO: to cog/lut/hub {addr1} '' Q QUIT: Quit Rom Monitor and return to the User Program '' Lffffffff[.]xxx LOAD: Load file from SD '' Rffffffff[.]xxx RUN: Load & Run file from SD '' TAQOZ: goto TAQOZ '' +--------------------------------------------------------------------------+ '' LMM DEBUGGER - CALL Modes...(not all modes supported) '' +--------------------------------------------------------------------------+ _MODE = $F << 5 ' mode bits defining the call b8..b5 (b4..b0 are modifier options) _SHIFT = 5 ' shr # to extract mode bits _HEX_ = 2 << 5 ' hex... _REV_ = 1 << 4 ' - reverse byte order _SP = 1 << 3 ' - space between hex output pairs '_DIGITS = 7..0 where 8->0 ' - no. of digits to display _LIST = 3 << 5 ' LIST memory line (1/4 longs) from cog/hub _ADDR2 = 1 << 4 ' 1= use lmm_p2 as to-address _LONG_ = 1 << 1 ' 1=display longs xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx _TXSTRING = 4 << 5 ' tx string (nul terminated) from hub _RXSTRING = 5 << 5 ' rx string _ECHO_ = 1 << 4 ' - echo char _PROMPT = 1 << 3 ' - prompt (lmm_x) _ADDR = 1 << 2 ' - addr of string buffer supplied _NOLF = 1 << 1 ' - strip _MONITOR = 7 << 5 ' goto rom monitor '' +--------------------------------------------------------------------------+ '' P2 ROM SERIAL ROUTINES (HUBEXEC) '' +--------------------------------------------------------------------------+ _SerialInit = $fcab8 ' Serial Initialise (lmm_x & lmm_bufad must be set first) _HubTxCR = $fcae4 ' Sends (overwrites lmm_x) _HubTxRev = $fcaec ' Sends lmm_x with bytes reversed _HubTx = $fcaf0 ' Sends lmm_x (can be up to 4 bytes) _HubHexRev = $fcb24 ' Sends lmm_x with bytes reversed as Hex char(s) as defined in lmm_f _HubHex8 = $fcb28 ' Sends lmm_x as Hex char(s) after setting lmm_f as 8 hex chars _HubHex = $fcb2c ' Sends lmm_x as Hex char(s) as defined in lmm_f _HubTxStrVer = $fcb9c ' Sends $0 terminated string at lmm_p address after setting lmm_p=##_str_vers _HubTxString = $fcba4 ' Sends $0 terminated string at lmm_p address _HubListA2H = $fcbc4 ' List/Dump line(s) from lmm_p address to lmm_p2 address after setting lmm_f=#_LIST+_ADDR2 _HubList = $fcbc8 ' List/Dump line(s) from lmm_p address to lmm_p2 address according to lmm_f _HubRx = $fcb10 ' Recv char into lmm_x _HubRxStrMon = $fccc4 ' Recv string into lmm_bufad address after setting prompt=lmm_x=#"*" & params=lmm_f=#_RXSTRING+_ECHO_+_PROMPT _HubRxString = $fcccc ' Recv string into lmm_p/lmm_bufad address according to params in lmm_f _HubMonitor = $fcd78 ' Calls the Monitor; uses lmm_bufad as the input buffer address _RdLongCogHub = $fcf34 ' read cog/lut/hub long from lmm_p address into lmm_x, then lmm_p++ _str_vers = $fd014 ' locn of hub string, $0 terminated '' +--------------------------------------------------------------------------+ '' P2 ROM SD ROUTINES (HUBEXEC) '' +--------------------------------------------------------------------------+ _Start_SDcard = $fc560 ' initialise & read CSD/CID _Run_SDfile = $fc578 ' initialise & read CSD/CID _Load_SDfile = $fc590 ' initialise & read CSD/CID _SDcard_Init = $fc5a4 ' init hub data ptr=$0 _readMBR1 = $fc6dc ' do not load/run MBR/VOL code _readMBR = $fc6e0 ' VBR/MBR = SECTOR 0 _readDIR = $fc810 ' copy _fname1 -> fname _searchDIR = $fc840 ' 12th char must be $00 _readFILE = $fc900 ' DAT SECTOR# _readnxtSECTOR = $fc944 ' next sector# _readnxtSLOT = $fc948 ' next data slot _readSECTOR = $fc950 ' sector# _readREG = $fc974 ' CMD9,10: CSD,CID register _readBLOCK = $fc97c ' CMD17: PAR=sector, 512 bytes '' +--------------------------------------------------------------------------+ '' HUB ADDRESSES '' +--------------------------------------------------------------------------+ _HUBROM = $FC000 ' ROM $FC000 _HUBBUF = $FC000 ' overwrite Booter _HUBBUFSIZE = 80 ' RxString default size for _HUBBUF '' +--------------------------------------------------------------------------+ ''============[ COG VARIABLES $1CO-$1DF - SD BOOT]============================= cmdout = $1c0 ' The 8b CMDxx | $40 cmdpar = $1c1 ' The 32b parameters cmdcrc = $1c2 ' The 8b CRC (must be valid for CMD0 & CMD8) cmdpar2 = $1c3 ' SDV1=$0, SDV2=$40000000 cmdtype = $1c4 ' reply is R1=1, R3=3, R7=7, else 0 reply = $1c5 ' R1 reply (moved to replyR1 when R3/R7 32b reply here) replyR1 = $1c6 ' R1 reply (8b saved when R3/R7 32b reply follows) dataout = $1c7 ' 8/32 bit data being shifted out bytescnt = $1c8 ' #bytes to send/recv bitscnt = $1c9 ' #bits to be shifted in/out ctr1 = $1ca timeout = $1cb ' = starttime + delay spare = $1cc skiprun = $1cd ' 1= skip load/run mbr/vol & load/no-run fname '\ 1=SDV1, 2=SDV2(byte address), 3=SDHC/SDV2(block address) blocksh = $1ce '/ block shift 0/9 bits clustersh = $1cf ' sectors/cluster SHL 'n' bits vol_begin = $1d0 ' Ptn0: first sector of PTN fsi_begin = $1d1 ' Ptn0: sector of file system info fat_begin = $1d2 ' Ptn0: first sector of FAT table dir_begin = $1d3 ' Ptn0: first sector of DATA is DIR table dat_begin = $1d4 ' Ptn0: first sector of file's DATA ptn_size = $1d5 ' file-size 32KB = 64<<9 sectors _bufad = $1d6 _blocknr = $1d7 _sectors = $1d8 _entries = $1d9 bufad = $1da ' ptr sector buffer blocknr = $1db ' sector# fname = $1dc'[3] ' 8+3+1 _hubdata = $1df '' +--------------------------------------------------------------------------+ ''============[ COG VARIABLES $1E0-$1EF - MONITOR]============================= ''-------[ LMM parameters, etc ]----------------------------------------------- lmm_x = $1e0 ' parameter passed to/from LMM routine (typically a value) lmm_f = $1e1 ' parameter passed to LMM routine (function options; returns unchanged) lmm_p = $1e2 ' parameter passed to/from LMM routine (typically a hub/cog ptr/addr) lmm_p2 = $1e3 ' parameter passed to/from LMM routine (typically a 2nd hub/cog address) lmm_c = $1e4 ' parameter passed to/from LMM routine (typically a count) ''-------[ LMM additional workareas ]------------------------------------------ lmm_w = $1e5 ' workarea (never saved - short term use between calls, except _HubTx) lmm_tx = $1e6 ' _HubTx lmm_hx = $1e7 ' _HubHex/_HubString lmm_hx2 = $1e8 ' _HubHex lmm_hc = $1e9 ' " lmm_lx = $1ea ' _HubList lmm_lf = $1eb ' " lmm_lp = $1ec ' " lmm_lp2 = $1ed ' " lmm_lc = $1ee ' " lmm_bufad = $1ef ' _HubRxString '' +--------------------------------------------------------------------------+ '' ASCII equates '' +--------------------------------------------------------------------------+ _CLS_ = $0C _BS_ = $08 _LF_ = $0A _CR_ = $0D _TAQOZ_ = $1B ' goto TAQOZ '' +--------------------------------------------------------------------------+ _SDcard_Init2 = $fc5bc ' init w/o checking pullup. need to set _hubdata=0 first hubdata = 0 DAT org 0 entry '+=============================================================================+ '+-------[ Set Xtal ]----------------------------------------------------------+ entry2 hubset #0 ' set 20MHz+ mode hubset ##_SETFREQ ' setup oscillator waitx ##20_000_000/100 ' ~10ms hubset ##_ENAFREQ ' enable oscillator '+-----------------------------------------------------------------------------+ waitx ##_clockfreq*5 ' just a delay to get pc terminal running '+-----------------------------------------------------------------------------+ '+=============================================================================+ '+ Display results + '+=============================================================================+ '+-------[ Start Serial ]------------------------------------------------------+ mov lmm_bufad, ##_HUBBUF ' locn of hub buffer for serial routine mov lmm_x, ##_bitper ' sets serial baud call #_SerialInit ' initialise serial '+-----------------------------------------------------------------------------+ '' mov lmm_x, #0 ' clear PST screen '' call #_hubTx '+-----------------------------------------------------------------------------+ mov lmm_p, ##hubstring ' must be in hub! call #_HubTxString '+-----------------------------------------------------------------------------+ ' utilise SD ROM routines in P2-ES v33i initial rev silicon (will not be the same for rev2 silicon) '''' call #_SDcard_Init ' initialise SD card '<<<<<<<<<<<<<<<<<<<<<< mov _hubdata, #hubdata '\ Initialise SD card call #_SDcard_init2 '/ w/o pullup check mov lmm_p, ##str_init if_nz jmp #failed mov skiprun, #1 ' don't load/run MBR/VOL code call #_readMBR ' read MBR/VOL/FSI/FAT mov lmm_p, ##str_mbr if_nz jmp #failed { mov fname, ##("T"+"e"<<8+"s"<<16+"t"<<24) ' filename 8+3+$00 mov fname+1, ##("D"+"a"<<8+"t"<<16+"a"<<24) mov fname+2, ##("t"+"x"<<8+"t"<<16+$00<<24) } mov fname, ##("_"+"B"<<8+"O"<<16+"O"<<24) ' filename 8+3+$00 mov fname+1, ##("T"+"_"<<8+"P"<<16+"2"<<24) mov fname+2, ##("B"+"I"<<8+"X"<<16+$00<<24) '**** call #_readDIR ' find _BOOT_P2.BIX / _BOOT_P2.BIY call #_searchDIR ' search for specified file mov lmm_p, ##str_find if_nz jmp #failed ' _searchDIR returns: ' dat_begin = first sector of file data ' _sectors = length of file in bytes mov filestart, dat_begin ' save the file start sector mov filelen, _sectors ' save the file length(bytes) ' now let's display the start sector and file size in bytes... mov lmm_p, ##str_sector ' string ($0 terminated) call #_hubTxString ' print string mov lmm_x, filestart ' get the files 1st data sector# call #_hubHex8 ' print in hex, 8 digits mov lmm_x, ##"(" ' print " (" call #_hubTx ' print char(s) mov lmm_x, filelen ' get the files length(bytes) call #_hubHex8 ' print in hex, 8 digits mov lmm_x, #")" call #_hubTx ' print char(s) call #_hubTxCR ' print cr+lf ' now let's read the files first sector into hub databuf... mov _bufad, ##databuf ' set hub buffer address mov _blocknr, filestart ' set files 1st data sector call #_readSECTOR ' read the data sector into hub mov lmm_p, ##str_rdsector call #_HubTxString mov lmm_x, _blocknr ' get the files 1st data sector# call #_hubHex8 ' print in hex, 8 digits call #_hubTxCR ' print cr+lf if_nz jmp #failed ' read sector error! ' now let's dump that sector to the serial port... (we have already setup the serial) mov lmm_p, ##databuf ' start address ' or lmm_p, ##$10_0000 ' only required if address < $400 mov lmm_p2, lmm_p ' copy start address add lmm_p2, ##512 ' end addrs = start + length(bytes) call #_hubListA2H ' list the data to serial ' now let's read the second sector into hub databuf... (we will presume the data file is >2*512 bytes) mov _bufad, ##databuf ' set hub buffer address ' mov _blocknr, filestart ' set files 1st data sector (not reqd again) add _blocknr, #1 ' advance to next data sector call #_readSECTOR ' read the data sector into hub mov lmm_p, ##str_rdsector call #_HubTxString mov lmm_x, _blocknr ' get the files 1st data sector# call #_hubHex8 ' print in hex, 8 digits call #_hubTxCR ' print cr+lf if_nz jmp #failed ' read sector error! ' now let's dump that sector to the serial port... (we have already setup the serial) mov lmm_p, ##databuf ' start address ' or lmm_p, ##$10_0000 ' only required if address < $400 mov lmm_p2, lmm_p ' copy start address add lmm_p2, ##512 ' end addrs = start + length(bytes) call #_hubListA2H ' list the data to serial ' now let's call the ROM Monitor... monitor call #_hubMonitor ' call the ROM Monitor (already initialised) jmp #monitor ' in case we return from the monitor '+-----------------------------------------------------------------------------+ ' error handling, if any failed call #_hubTxString ' lmm-P set previously mov lmm_p, ##str_error call #_hubTxString jmp #monitor ' and go run the monitor '+-----------------------------------------------------------------------------+ filestart long 0 filelen long 0 fit $1C0 ' don't overwrite ROM SD & Monitor variables '+-----------------------------------------------------------------------------+ ''============[ HUB VARIABLES ]================================================= DAT orgh $4000 databuf long 0[512] ' sector buffer hubstring byte "Fun with P2 ROM v001a",13,10,0 str_init byte "Initialise ",0 str_mbr byte "Read MBR/VOL ",0 str_find byte "Find file ",0 str_rdsector byte "Read sector ",0 str_sector byte "File sector(length) ",0 str_error byte "***error***",13,10,0 str_success byte "Success",13,10,0 alignl ''--------------------------------------------------------------------------------------------------- '