This code drives the DataFlash devices connected to SPI port on the EB55 board.
: InitSPI \ --
Initialise the SPI Chip Select and Mode Registers. The AT45DB321 DataFlash ICs are on Chip Select 0 to 3. The AT25256W (not fitted) IC is on Chip Select 4.
: OpenSPI \ --
Open the SPI.
: CloseSPI \ --
Close the SPI.
: XferSPI \ Tx -- Rx
Transmit and Receive via the SPI.
: CSHigh \ --
Wait till SPI Transfer is finished - At least 1 SPI DLYBCT period.
: DF_Xfer \ pcs TxByte -- RxByte
Transfer a byte to/from the AT45DB321 DataFlash bank - PCS needs to be orred into bits 19..16 before transmission
: DF_PCS \ addr -- pcs
Calculate the Peripheral Chip Select (PCS) value given a DataFlash Address.
: DF_PageOffset \ addr --
Set the AT45DB321 Page and Offset.
: DF_GetStatus \ pcs -- status
Read the status of an AT45DB321 DataFlash chip.
: DF_SetupPageRead \ src --
Setup an AT45DB321 DataFlash for a Page Read.
: DF_PageToBuffer1 \ dest --
Copy a page in an AT45DB321 DataFlash to it's SRAM Buffer 1.
: DF_SetupBuffer1Write \ dest --
Setup an AT45DB321 DataFlash for a buffer 1 write.
: DF_Buffer1ToPage \ dest --
Copy the SRAM buffer 1 in an AT45DB321 DataFlash to a page.
: DF_FetchPage \ dest src len -- dest' src' len'
Get a page (or partial page) of data from "src" and store it in "dest", also update "src", "len" & "dest" accordingly.
: DF_StorePage \ dest src len -- dest' src' len'
Store a page (or partial page) of data from "src" and store it in "dest", also update "src", "len" & "dest" accordingly.
: DF_Capacity \ -- capacity
Sample the first four SPI selects to find out how much is there.
: DATAFLASH@ \ sram_addr length dataflash_addr -- t/f(good)
Get data from the DataFlash, returns Success flag (0 = Success).
: DATAFLASH! \ sram_addr length dataflash_addr -- t/f(good)
Store data in the DataFlash, returning Success flag (0 = Success).
: Str! \ $addr DFaddr -- T/F(Good) ; counted string
Write a counted string to the Flash.
: Str@ \ $addr len DFaddr -- T/F(Good)
Use this to fetch a counted string stored in DataFlash into a buffer of size len and display it.