SA9200: Give LCD about an 8% speedup. Sync optional LCD settings to defaults in lcd_i...
[kugel-rb.git] / flash / uart_boot / flash.c
blob854de204544ec1c3ed498952be3456809319a16a
1 // flash.cpp : higher-level functions for flashing the chip
2 //
4 #include "scalar_types.h" // (U)INT8/16/32
5 #include "Uart.h" // platform abstraction for UART
6 #include "client.h" // client functions
9 // read the manufacturer and device ID
10 int ReadID(tUartHandle serial_handle, UINT32 base, UINT8* pManufacturerID, UINT8* pDeviceID)
12 base &= 0xFFF80000; // round down to 512k align, to make shure
14 WriteByte(serial_handle, base + 0x5555, 0xAA); // enter command mode
15 WriteByte(serial_handle, base + 0x2AAA, 0x55);
16 WriteByte(serial_handle, base + 0x5555, 0x90); // ID command
17 SLEEP(20); // Atmel wants 20ms pause here
19 *pManufacturerID = ReadByte(serial_handle, base + 0);
20 *pDeviceID = ReadByte(serial_handle, base + 1);
22 WriteByte(serial_handle, base + 0, 0xF0); // reset flash (back to normal read mode)
23 SLEEP(20); // Atmel wants 20ms pause here
25 return 0;
29 // erase the sector which contains the given address
30 int EraseSector(tUartHandle serial_handle, UINT32 address)
32 UINT32 base = address & 0xFFF80000; // round down to 512k align
34 WriteByte(serial_handle, base + 0x5555, 0xAA); // enter command mode
35 WriteByte(serial_handle, base + 0x2AAA, 0x55);
36 WriteByte(serial_handle, base + 0x5555, 0x80); // eraze command
37 WriteByte(serial_handle, base + 0x5555, 0xAA); // enter command mode
38 WriteByte(serial_handle, base + 0x2AAA, 0x55);
39 WriteByte(serial_handle, address, 0x30); // eraze the sector
40 SLEEP(25); // sector eraze time: 25ms
42 return 0;
46 // erase the whole flash
47 int EraseChip(tUartHandle serial_handle, UINT32 base)
49 base &= 0xFFF80000; // round down to 512k align, to make shure
51 WriteByte(serial_handle, base + 0x5555, 0xAA); // enter command mode
52 WriteByte(serial_handle, base + 0x2AAA, 0x55);
53 WriteByte(serial_handle, base + 0x5555, 0x80); // eraze command
54 WriteByte(serial_handle, base + 0x5555, 0xAA); // enter command mode
55 WriteByte(serial_handle, base + 0x2AAA, 0x55);
56 WriteByte(serial_handle, base + 0x5555, 0x10); // chip eraze command
57 SLEEP(100); // chip eraze time: 100ms
59 return 0;
63 // program a bunch of bytes "by hand"
64 int ProgramBytes(tUartHandle serial_handle, UINT32 address, UINT8* pData, UINT32 size)
66 UINT32 base = address & 0xFFF80000; // round down to 512k align
68 while (size--)
70 WriteByte(serial_handle, base + 0x5555, 0xAA); // enter command mode
71 WriteByte(serial_handle, base + 0x2AAA, 0x55);
72 WriteByte(serial_handle, base + 0x5555, 0xA0); // byte program command
73 WriteByte(serial_handle, address++, *pData++);
74 // UART protocol is slow enough such that I don't have to wait 20us here
76 return 0;