summaryrefslogtreecommitdiff
path: root/flash/uart_boot/flash.c
diff options
context:
space:
mode:
authorJörg Hohensohn <hohensoh@rockbox.org>2003-11-30 11:37:43 +0000
committerJörg Hohensohn <hohensoh@rockbox.org>2003-11-30 11:37:43 +0000
commit6a4e4c87c24455e18bbd77565cb3e993ee350618 (patch)
tree6f2ceac4da97aa63ff8deef939bd3cc2d56d3466 /flash/uart_boot/flash.c
parent014c4fa1f8d56850cfd504a90221c293e4a158f6 (diff)
downloadrockbox-6a4e4c87c24455e18bbd77565cb3e993ee350618.zip
rockbox-6a4e4c87c24455e18bbd77565cb3e993ee350618.tar.gz
rockbox-6a4e4c87c24455e18bbd77565cb3e993ee350618.tar.bz2
rockbox-6a4e4c87c24455e18bbd77565cb3e993ee350618.tar.xz
source code for all my flash stuff, now finally in cvs
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4083 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'flash/uart_boot/flash.c')
-rw-r--r--flash/uart_boot/flash.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/flash/uart_boot/flash.c b/flash/uart_boot/flash.c
new file mode 100644
index 0000000..f27bb7e
--- /dev/null
+++ b/flash/uart_boot/flash.c
@@ -0,0 +1,77 @@
+// flash.cpp : higher-level functions for flashing the chip
+//
+
+#include "scalar_types.h" // (U)INT8/16/32
+#include "Uart.h" // platform abstraction for UART
+#include "client.h" // client functions
+
+
+// read the manufacturer and device ID
+int ReadID(tUartHandle serial_handle, UINT32 base, UINT8* pManufacturerID, UINT8* pDeviceID)
+{
+ base &= 0xFFF80000; // round down to 512k align, to make shure
+
+ WriteByte(serial_handle, base + 0x5555, 0xAA); // enter command mode
+ WriteByte(serial_handle, base + 0x2AAA, 0x55);
+ WriteByte(serial_handle, base + 0x5555, 0x90); // ID command
+ SLEEP(20); // Atmel wants 20ms pause here
+
+ *pManufacturerID = ReadByte(serial_handle, base + 0);
+ *pDeviceID = ReadByte(serial_handle, base + 1);
+
+ WriteByte(serial_handle, base + 0, 0xF0); // reset flash (back to normal read mode)
+ SLEEP(20); // Atmel wants 20ms pause here
+
+ return 0;
+}
+
+
+// erase the sector which contains the given address
+int EraseSector(tUartHandle serial_handle, UINT32 address)
+{
+ UINT32 base = address & 0xFFF80000; // round down to 512k align
+
+ WriteByte(serial_handle, base + 0x5555, 0xAA); // enter command mode
+ WriteByte(serial_handle, base + 0x2AAA, 0x55);
+ WriteByte(serial_handle, base + 0x5555, 0x80); // eraze command
+ WriteByte(serial_handle, base + 0x5555, 0xAA); // enter command mode
+ WriteByte(serial_handle, base + 0x2AAA, 0x55);
+ WriteByte(serial_handle, address, 0x30); // eraze the sector
+ SLEEP(25); // sector eraze time: 25ms
+
+ return 0;
+}
+
+
+// erase the whole flash
+int EraseChip(tUartHandle serial_handle, UINT32 base)
+{
+ base &= 0xFFF80000; // round down to 512k align, to make shure
+
+ WriteByte(serial_handle, base + 0x5555, 0xAA); // enter command mode
+ WriteByte(serial_handle, base + 0x2AAA, 0x55);
+ WriteByte(serial_handle, base + 0x5555, 0x80); // eraze command
+ WriteByte(serial_handle, base + 0x5555, 0xAA); // enter command mode
+ WriteByte(serial_handle, base + 0x2AAA, 0x55);
+ WriteByte(serial_handle, base + 0x5555, 0x10); // chip eraze command
+ SLEEP(100); // chip eraze time: 100ms
+
+ return 0;
+}
+
+
+// program a bunch of bytes "by hand"
+int ProgramBytes(tUartHandle serial_handle, UINT32 address, UINT8* pData, UINT32 size)
+{
+ UINT32 base = address & 0xFFF80000; // round down to 512k align
+
+ while (size--)
+ {
+ WriteByte(serial_handle, base + 0x5555, 0xAA); // enter command mode
+ WriteByte(serial_handle, base + 0x2AAA, 0x55);
+ WriteByte(serial_handle, base + 0x5555, 0xA0); // byte program command
+ WriteByte(serial_handle, address++, *pData++);
+ // UART protocol is slow enough such that I don't have to wait 20us here
+ }
+ return 0;
+} \ No newline at end of file