CON 'FSRW P2 port testing 'Serial Output code at top of file 'FSRW Code starts around line#166 'Based on FSRW 1.5 (spin only version) and FSRW 2.6 '(fsrw 2.6 Copyright 2009 Tomas Rokicki and Jonathan Dummer ) CON SYS_CLK = 80_000_000 BAUD_RATE = 115_200 RX_PIN = 63 TX_PIN = 62 Mailbox1=$FFF80 Mailbox2=$FFF81 FSRW_COG=2 dat orgh 0 org 0 cog_entry coginit #FSRW_COG,#@FsrwStart setb outb, #TX_PIN setb dirb, #TX_PIN '******************************************************* '********* TEST CODE - PUT YOUR CODE HERE ************** ' ***** try some input/output loopback 'Look for command rdbyte tx_cmd, rx_target cmp tx_cmd,#0 wz, wc if_e jmp #loopback 'check for write byte command cmp tx_cmd,#1 wz,wc if_e rdbyte tx_char,hex_target if_e call #send_char 'check for write hex long cmp tx_cmd,#2 wz,wc if_e rdlong tx_hex, hex_target if_e call #send_LongHexSub 'check for write hex byte cmp tx_cmd,#3 wz,wc if_e rdbyte tx_hex, hex_target if_e call #send_ByteHexSub 'check for write string byte cmp tx_cmd,#4 wz,wc if_e rdlong tx_hex, hex_target if_e call #send_StringSub wrbyte #0,rx_target 'message received and processed jmp #loopback Send_StringSub 'send a string rdbyte tx_char,tx_hex cmp tx_char,#0 wz,wc if_z ret call #send_char add tx_hex,#1 jmp #Send_StringSub Send_LongHexSub 'Send 8 hex chars getnib tx_temp,tx_hex,#7 call #SendHexSub getnib tx_temp,tx_hex,#6 call #SendHexSub getnib tx_temp,tx_hex,#5 call #SendHexSub getnib tx_temp,tx_hex,#4 call #SendHexSub getnib tx_temp,tx_hex,#3 call #SendHexSub getnib tx_temp,tx_hex,#2 call #SendHexSub getnib tx_temp,tx_hex,#1 call #SendHexSub getnib tx_temp,tx_hex,#0 call #SendHexSub ret Send_ByteHexSub getnib tx_temp,tx_hex,#1 call #SendHexSub getnib tx_temp,tx_hex,#0 call #SendHexSub ret SendHexSub 'Send hex mov tx_char,tx_temp cmp tx_char,#10 wz,wc if_b add tx_char,#"0" if_b call #Send_Char if_b ret sub tx_char,#10 add tx_char,#"A" call #Send_Char ret '********* TEST CODE - REPLACE WITH YOUR CODE *********** '******************************************************** '******************************************************************************* ' Get one character from the input port. ' Input none ' Changes parm, temp, temp1, temp2 ' Output parm '******************************************************************************* rcv_char setedg #%0_10_000000 | RX_PIN 'select negative edge on p63 polledg 'clear edge detector waitedg 'wait for start bit waitx bit_time 'wait for middle of 1st data bit rep @.rep,#8 'ready for 8 bits testb inb,#RX_PIN wc 'sample rx rcr rx_char,#1 'rotate bit into byte waitx bit_time 'wait for middle of nth data bit .rep shr rx_char,#32-8 'justify received byte ret '******************************************************************************* ' Output a single character to the tx_pin. ' executes in COG mode ' Input: txchar - character to be sent ' Changes parm, temp1, temp2 ' Output none '******************************************************************************* send_char setb tx_char,#8 shl tx_char,#1 getct timer rep @.txrep,#10 testb tx_char,#0 wz setbnz outb,#TX_PIN addct1 timer,bit_time waitct1 shr tx_char,#1 .txrep ret bit_time long SYS_CLK / BAUD_RATE rx_target long Mailbox1'$FFF80 hex_target long Mailbox2'$FFF81 tx_cmd res 1 tx_char res 1 tx_hex res 1 timer res 1 rx_char res 1 tx_temp res 1 fit $1F0 CON 'FSRW Settings SdPin_MISO=24 '0 SdPin_CLK =22 '1 SdPin_MOSI=23 '2 SdPin_CS =27 '3 SECTORSHIFT = 9 ' DIRSIZE = 32 DIRSHIFT = 5 Messages=$1000 'storage for string messages pTargetFile=$1500 'Putting target filename here BlockBuffer=$2000 'storage for 512 byte block dat 'FSRW Vars FsrwStart org 'jmp #@Fsrw_init 'uncomment for hubexec jmp #Fsrw_init 'putting variables here in case need hubexec later 'NOTE: Can't use RES here tx_target long Mailbox1'$FFF80 'Mailbox for serial output tx_hexTarget long Mailbox2'$FFF81 'Mailbox for Hex output m_miso long 1<> Sector Address Shift=9 (not a high capacity card)",13,0 C58HCMessage byte ">> Sector Address Shift=0 (high capacity card)",13,0 Cmd59Message byte "Sending Command 59: Turning off CRC",13,0 Cmd2Message byte "Sending Command 2: Getting Card ID >>",0 Cmd37Message byte 13,"Sending Commands 3&7: Get then select RCA (relative card address) >>",0 Block0Message byte 13,13,"Going high-speed SPI and reading sector #0 (Master Boot Record)",13,0 BCheckMessage byte "Passed FAT block check (Last 2 bytes are $55AA)",13,0 FailMessage byte 13,13,"Something wrong, restarting....",0 MBR0Message byte "Checking to see if MBR is boot sector (true if no partitions)",13,0 MBR1Message byte "Checking first partition for boot sector",13,0 Fat16ID byte "FAT16" Fat32ID byte "FAT32" FS0Message byte ">> No file system ID in this block",13,0 FS1Message byte "This block identifies as FAT16 Boot Sector",13,0 FS2Message byte "This block identifies as FAT32 Boot Sector",13,0 SectorMessage byte "Sector size confirmed to be 512 bytes",13,0 ClusterMessage byte "#sectors in each cluster is $",0 FatsMessage byte 13,"Two copies of FAT confirmed",13,0 SectorsMessage byte "#of 512 byte sectors in this partition= $",0 Fat1Message byte 13,"#Start of FAT1= $",0 REntriesMessage byte 13,"#of root entries= $",0 SPerFatMessage byte 13,"#of sectors per fat= $",0 DRegionMessage byte 13,"Start of data region= $",0 RootDirMessage byte 13,"Root directory starts at byte= $",0 RootEndMessage byte 13,"Root directory ends at byte= $",0 FileFoundMessage byte 13,"Target file found !",0 FileFailMessage byte 13,"Target file not found !",0 DAT 'TargetFile orgh pTargetFile TargetFile byte "P2BOOT BIN" DAT 'Block Buffer orgh BlockBuffer