1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2025-04-21 12:27:27 +03:00

start wrapper; proper serial port baudrate

This commit is contained in:
Bas Wijnen
2010-08-05 22:19:58 +02:00
parent a2add9a1d6
commit 7659673f33
11 changed files with 250 additions and 78 deletions

View File

@@ -80,6 +80,28 @@ static unsigned word_size
static void unbusy ():
while !(gpio_get_port (2) & (1 << 30)):
Iris::schedule ()
Iris::schedule ()
static void addr (unsigned d):
unbusy ()
*address = d
unbusy ()
static void cmd (unsigned d):
unbusy ()
*command = d
unbusy ()
static void wdata (unsigned d):
unbusy ()
*data = d
unbusy ()
static unsigned rdata ():
unbusy ()
unsigned ret = *data
unbusy ()
return ret
static void reset ():
Iris::Page data_page = Iris::my_memory.create_page ()
@@ -104,96 +126,148 @@ static void reset ():
EMC_NFCSR = EMC_NFCSR_NFE1 | EMC_NFCSR_NFCE1
// Reset nand.
*command = CMD_RESET
unbusy ()
cmd (CMD_RESET)
*command = CMD_READID
*address = 0
unsigned d = *data
cmd (CMD_READID)
addr (0)
unsigned d = rdata ()
//unsigned maker = d
d = *data
d = rdata ()
//unsigned device = d
d = *data
d = rdata ()
//unsigned internal_chip_number = 1 << (d & 0x3)
//unsigned cell_type = 2 << ((d >> 2) & 0x3)
//unsigned simultaneously_programmed_pages = 1 << ((d >> 4) & 0x3)
//bool can_interleave_program_between_chips = d & 0x40
//bool can_cache_program = d & 0x80
d = *data
d = rdata ()
page_bits = 10 + (d & 3)
kdebug ("page bits: ")
kdebug_num (page_bits)
kdebug ("\n")
Iris::debug ("page bits: %d\n", page_bits)
redundant_bits = (d & 4 ? 4 : 3)
block_bits = 64 + ((d >> 4) & 3)
Iris::debug ("redundant bits: %d\n", redundant_bits)
block_bits = 16 + ((d >> 4) & 3)
Iris::debug ("block bits: %d\n", block_bits)
word_size = (d & 0x40 ? 16 : 8)
Iris::debug ("word size: %d\n", word_size)
//unsigned serial_access_minimum = (d & 0x80 ? 25 : 50)
d = *data
d = rdata ()
//unsigned num_planes = 1 << ((d >> 2) & 3)
//unsigned plane_bits = 26 + ((d >> 4) & 7)
static void read (unsigned a, char *buffer):
unsigned column = a & ((1 << page_bits) - 1)
unsigned row = a >> page_bits
kdebug ("reading: ")
kdebug_num (a)
kdebug ("/")
kdebug_num (row)
kdebug ("/")
kdebug_num (column)
kdebug (": ")
*command = CMD_READ0
*address = column
*address = column >> 8
*address = row
*address = row >> 8
*address = row >> 16
*command = CMD_READSTART
//Iris::debug ("reading: %x/%x/%x: ", a, row, column)
cmd (CMD_READ0)
addr (column)
addr (column >> 8)
addr (row)
addr (row >> 8)
addr (row >> 16)
cmd (CMD_READSTART)
EMC_NFECR = EMC_NFECR_ECCE | EMC_NFECR_RS | EMC_NFECR_RS_DECODING | EMC_NFECR_ERST
// Wait for nand to be ready.
unbusy ()
for unsigned t = 0; t < 0x200; ++t:
buffer[t] = *data
buffer[t] = rdata ()
char error[9]
unsigned errcol = (1 << page_bits) + (column >> 5)
*command = CMD_RNDOUT
*address = errcol
*address = errcol >> 8
*command = CMD_RNDOUTSTART
// Spare space (starts at 1 << page_bits)
// 0: unused
// 2: detect valid data (at least 1 byte == 0 means valid)
// 5: unused
// 6: 9-byte ecc of 1st 512 bytes
// 15: 9-byte ecc of 2nd 512 bytes
// 24: 9-byte ecc of 3rd 512 bytes
// 33: 9-byte ecc of 4th 512 bytes
// 42: unused
// 64: end of space
unsigned errcol = (1 << page_bits) + (column >> 9) * 9 + 6
cmd (CMD_RNDOUT)
addr (errcol)
addr (errcol >> 8)
cmd (CMD_RNDOUTSTART)
for unsigned t = 0; t < 9; ++t:
error[t] = *data
error[t] = rdata ()
EMC_NFPAR (0) = ((unsigned *)error)[0]
EMC_NFPAR (1) = ((unsigned *)error)[1]
EMC_NFPAR (2) = error[9]
EMC_NFECR = EMC_NFECR_ECCE | EMC_NFECR_RS | EMC_NFECR_RS_DECODING | EMC_NFECR_PRDY
while !(EMC_NFINTS & EMC_NFINTS_DECF):
Iris::schedule ()
// delay...
//Iris::schedule ()
unsigned errs = (EMC_NFINTS & EMC_NFINTS_ERRCNT_MASK) >> EMC_NFINTS_ERRCNT_BIT
for unsigned i = 0; i < errs; ++i:
Iris::debug ("correcting %x on %x\n", EMC_NFERR (i) & 0xff, EMC_NFERR (i) >> 16)
buffer[EMC_NFERR (i) >> 16] ^= EMC_NFERR (i) & 0xff
static void write (unsigned a, char *buffer):
unsigned row = a >> page_bits
//Iris::debug ("writing: %x/%x: ", a, row)
cmd (CMD_SEQIN)
addr (0)
addr (0)
addr (row)
addr (row >> 8)
addr (row >> 16)
char ecc[4][9]
for unsigned i = 0; i < 0x4; ++i:
EMC_NFECR = EMC_NFECR_ECCE | EMC_NFECR_RS | EMC_NFECR_RS_ENCODING | EMC_NFECR_ERST
for unsigned j = 0; j < 0x200; ++j:
wdata (buffer[i * 0x200 + j])
while !(EMC_NFINTS & EMC_NFINTS_ENCF):
Iris::schedule ()
((unsigned *)ecc[i])[0] = EMC_NFPAR (0)
((unsigned *)ecc[i])[1] = EMC_NFPAR (1)
ecc[i][9] = EMC_NFPAR (2)
// Spare space (starts at 1 << page_bits)
// 0: unused
// 2: detect valid data (at least 1 byte == 0 means valid)
// 5: unused
// 6: 9-byte ecc of 1st 512 bytes
// 15: 9-byte ecc of 2nd 512 bytes
// 24: 9-byte ecc of 3rd 512 bytes
// 33: 9-byte ecc of 4th 512 bytes
// 42: unused
// 64: end of space
for unsigned i = 0; i < 6; ++i:
wdata (0)
for unsigned i = 0; i < 4; ++i:
for unsigned j = 0; j < 9; ++j:
wdata (ecc[i][j])
cmd (CMD_PAGEPROG)
Iris::debug ("nand program %d done\n", a)
static void erase (unsigned a):
unsigned row = a >> page_bits
cmd (CMD_ERASE1)
addr (row)
addr (row >> 8)
addr (row >> 16)
cmd (CMD_ERASE2)
Iris::debug ("nand erase %d done\n", a)
Iris::Num start ():
kdebug ("reading nand in 10 seconds\n")
kdebug ("starting nand operation in 10 seconds\n")
Iris::sleep (10 * HZ)
map_emc ()
map_gpio ()
// Arbitrary addresses where the pages are mapped.
command = (volatile char *)0x15000
address = (volatile char *)0x16000
data = (volatile char *)0x17000
reset ()
char buffer[0x200]
char buffer[0x800]
//erase (0)
// Send nand contents to serial port.
for unsigned a = 0; a < 0x4000; a += 0x200:
read (a, buffer)
//for unsigned s = 0; s < 0x10; ++s:
for unsigned t = 0; t < 0x10; ++t:
for unsigned s = 0; s < 0x10; ++s:
for unsigned t = 0; t < 0x20; ++t:
kdebug (" ")
kdebug_num (buffer[0 * 0x20 + t], 2)
kdebug_num (buffer[s * 0x20 + t], 2)
kdebug ("\n")
//kdebug ("\n")
kdebug ("\n")
// Exit.
return 0