Initial transfer from sourceforge
This commit is contained in:
commit
f2259c5424
415 changed files with 73200 additions and 0 deletions
8
lpctool/testing/ChangeLog
Normal file
8
lpctool/testing/ChangeLog
Normal file
|
@ -0,0 +1,8 @@
|
|||
2007-10-05 Simon Budig <simon@budig.de>
|
||||
|
||||
toolcom.c: added info line for flash erase.
|
||||
|
||||
2007-10-05 Ch. Klippel <ck@mamalala.net>
|
||||
|
||||
*/* initial import into SVN
|
||||
|
41
lpctool/testing/Makefile
Normal file
41
lpctool/testing/Makefile
Normal file
|
@ -0,0 +1,41 @@
|
|||
###############################################################
|
||||
#####
|
||||
##### Makefile for ramtool and lpctool
|
||||
#####
|
||||
###############################################################
|
||||
|
||||
include Makefile.inc
|
||||
|
||||
all: lpctool
|
||||
|
||||
tool_data.h: force_look
|
||||
cd flashtool; $(MAKE) $(MFLAGS)
|
||||
|
||||
lpctool: tool_data.h
|
||||
gcc -Os infohelper.c lpctool_serial.c bootcom.c toolcom.c lpctool.c -o lpctool
|
||||
strip lpctool
|
||||
|
||||
upload: lpctool
|
||||
./lpctool -i -v
|
||||
|
||||
resident: romtool.bin lpctool
|
||||
./lpctool -S -i -a romtool.bin -v
|
||||
|
||||
uresident: romtool.bin lpctool
|
||||
./lpctool -d /dev/ttyUSB0 -S -i -a romtool.bin -v
|
||||
|
||||
install: lpctool
|
||||
cp lpctool $(INSTALLDIR_BIN)
|
||||
|
||||
uninstall:
|
||||
rm $(INSTALLDIR_BIN)/lpctool
|
||||
|
||||
clean:
|
||||
$(RM) *.o *~ lpctool tool_data.h
|
||||
cd flashtool; make clean
|
||||
|
||||
force_look :
|
||||
true
|
||||
|
||||
|
||||
### EOF
|
37
lpctool/testing/Makefile.inc
Normal file
37
lpctool/testing/Makefile.inc
Normal file
|
@ -0,0 +1,37 @@
|
|||
|
||||
###############################################################
|
||||
#####
|
||||
##### PATHS (default installation)
|
||||
#####
|
||||
###############################################################
|
||||
|
||||
ARMBASE=/opt/armtool/4.1.1
|
||||
INCLUDEPATH=$(ARMBASE)/include
|
||||
LIBPATH=$(ARMBASE)/arm-elf/lib/interwork
|
||||
ARMPATH=$(ARMBASE)/bin
|
||||
TOOLPREFIX=/arm-elf-
|
||||
|
||||
INSTALLDIR_BIN=/usr/local/bin
|
||||
|
||||
-include Makefile.local
|
||||
|
||||
###############################################################
|
||||
#####
|
||||
##### Compiler, Linker and Tools
|
||||
#####
|
||||
###############################################################
|
||||
|
||||
CC=$(ARMPATH)$(TOOLPREFIX)gcc
|
||||
AS=$(ARMPATH)$(TOOLPREFIX)as
|
||||
LD=$(ARMPATH)$(TOOLPREFIX)ld
|
||||
OC=$(ARMPATH)$(TOOLPREFIX)objcopy
|
||||
OD=$(ARMPATH)$(TOOLPREFIX)objdump
|
||||
|
||||
CPUFLAGS=-mcpu=arm7tdmi-s
|
||||
OPTFLAGS=-Os
|
||||
#OPTFLAGS=-O0
|
||||
#OPTFLAGS=
|
||||
CFLAGS=$(CPUFLAGS) -c -Wall -mthumb-interwork -msoft-float -I$(INCLUDEPATH)
|
||||
ASFLAGS=$(CPUFLAGS) -D --gstabs -mthumb-interwork -mfpu=softfpa
|
||||
LDFLAGS=$(OPTFLAGS) -Tlpc2220.ld
|
||||
ROMLDFLAGS=$(OPTFLAGS) -Tlpc2220_rom.ld
|
25
lpctool/testing/Makefile.local.WinARM
Normal file
25
lpctool/testing/Makefile.local.WinARM
Normal file
|
@ -0,0 +1,25 @@
|
|||
###############################################################
|
||||
#####
|
||||
##### Makefile.local.WinARM for boop
|
||||
##### Created in the early morninghours
|
||||
#####
|
||||
##### Makefile.local.WinARM V1.0 by alterego - alteregon@gmx.net
|
||||
#####
|
||||
###############################################################
|
||||
|
||||
###############################################################
|
||||
#####
|
||||
##### PATHS (default installation)
|
||||
#####
|
||||
##### You can put your path-config into Makefile.local
|
||||
##### to override these defaults
|
||||
#####
|
||||
###############################################################
|
||||
|
||||
ARMBASE=c:/WinARM/
|
||||
INCLUDEPATH=$(ARMBASE)/include
|
||||
LIBPATH=$(ARMBASE)/arm-elf/lib/interwork
|
||||
ARMPATH=$(ARMBASE)/bin
|
||||
TOOLPREFIX=/arm-elf-
|
||||
|
||||
######################## EOF ##################################
|
25
lpctool/testing/Makefile.local.linuxARM
Normal file
25
lpctool/testing/Makefile.local.linuxARM
Normal file
|
@ -0,0 +1,25 @@
|
|||
###############################################################
|
||||
#####
|
||||
##### Makefile.local.linuxARM for boop
|
||||
##### Created in the early morninghours
|
||||
#####
|
||||
##### Makefile.local.linuxARM
|
||||
#####
|
||||
###############################################################
|
||||
|
||||
###############################################################
|
||||
#####
|
||||
##### PATHS (default installation)
|
||||
#####
|
||||
##### You can put your path-config into Makefile.local
|
||||
##### to override these defaults
|
||||
#####
|
||||
###############################################################
|
||||
|
||||
ARMBASE=/opt/arm-elf
|
||||
INCLUDEPATH=$(ARMBASE)/include
|
||||
LIBPATH=$(ARMBASE)/lib/gcc/arm-elf/4.1.1/interwork
|
||||
ARMPATH=$(ARMBASE)/bin
|
||||
TOOLPREFIX=/arm-elf-
|
||||
|
||||
######################## EOF ##################################
|
9
lpctool/testing/baudrate.h
Normal file
9
lpctool/testing/baudrate.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
|
||||
// serial baudrate
|
||||
// this is the baudrate at which lpctool communicates with flashtool
|
||||
|
||||
//~#define TOOLBAUD 115200UL
|
||||
#define TOOLBAUD 38400UL // use this if problems occur
|
||||
// USB-UART bridges like FT232 or PL2303
|
||||
// have glitches on the handshake lines
|
||||
// when the baudrate is changed.
|
308
lpctool/testing/bootcom.c
Normal file
308
lpctool/testing/bootcom.c
Normal file
|
@ -0,0 +1,308 @@
|
|||
#include "infohelper.h"
|
||||
#include "lpctool_serial.h"
|
||||
#include "bootcom.h"
|
||||
#include "tool_data.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <termios.h>
|
||||
|
||||
unsigned int uuencode(unsigned char *ibuf, unsigned char *obuf, int len)
|
||||
{
|
||||
unsigned int slen, r,s;
|
||||
unsigned char q;
|
||||
slen = len;
|
||||
|
||||
r = 0;
|
||||
s = 0;
|
||||
|
||||
while(slen >= 45)
|
||||
{
|
||||
|
||||
obuf[r++]=77;
|
||||
for(q=0;q<45;q+=3)
|
||||
{
|
||||
|
||||
obuf[r++]=0x20+(( ibuf[s]>>2)&0x3f);
|
||||
obuf[r++]=0x20+(((ibuf[s]<<4) | (ibuf[s+1]>>4))&0x3f);
|
||||
s++;
|
||||
obuf[r++]=0x20+(((ibuf[s]<<2)|(ibuf[s+1]>>6))&0x3f);
|
||||
s++;
|
||||
obuf[r++]=0x20+( ibuf[s++]&0x3f);
|
||||
}
|
||||
obuf[r++] = '\r';
|
||||
obuf[r++] = '\n';
|
||||
slen -= 45;
|
||||
}
|
||||
|
||||
if(slen)
|
||||
{
|
||||
obuf[r++]=0x20+slen;
|
||||
for(q=0;q<slen;q+=3)
|
||||
{
|
||||
obuf[r++]=0x20+(( ibuf[s]>>2)&0x3f);
|
||||
obuf[r++]=0x20+(((ibuf[s]<<4) | (ibuf[s+1]>>4))&0x3f);
|
||||
s++;
|
||||
obuf[r++]=0x20+(((ibuf[s]<<2)|(ibuf[s+1]>>6))&0x3f);
|
||||
s++;
|
||||
obuf[r++]=0x20+( ibuf[s++]&0x3f);
|
||||
}
|
||||
obuf[r++] = '\r';
|
||||
obuf[r++] = '\n';
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void printBuf(unsigned char len, unsigned char *buf)
|
||||
{
|
||||
unsigned char cnt;
|
||||
cnt = 0;
|
||||
while(len--)
|
||||
printf("%c",buf[cnt++]);
|
||||
}
|
||||
|
||||
int getOK(unsigned char oktype)
|
||||
{
|
||||
char buf[4];
|
||||
unsigned char q;
|
||||
|
||||
switch(oktype)
|
||||
{
|
||||
case OK_LIT:
|
||||
q = getBuf(4, buf);
|
||||
if(strncmp(buf, "OK\r\n", 4))
|
||||
{
|
||||
return printError("wrong response, expected OK");
|
||||
}
|
||||
return 1;
|
||||
break;
|
||||
|
||||
case OK_0:
|
||||
q = getBuf(3, buf);
|
||||
if(strncmp(buf, "0", 1))
|
||||
{
|
||||
return printError("wrong response, expected 0");
|
||||
}
|
||||
return 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int openBootLoader(unsigned int cfreq)
|
||||
{
|
||||
char buf[20];
|
||||
unsigned char q;
|
||||
|
||||
printInfoS(2,"initiating auto-baud",0);
|
||||
tcflush(serialDev, TCIOFLUSH);
|
||||
sendBuf(sprintf(buf, "?\r\n"), buf);
|
||||
|
||||
printInfoS(2,"awaiting autobaud response",0);
|
||||
|
||||
q = getBuf(14, buf);
|
||||
|
||||
if(strncmp(buf, "Synchronized\r\n", 14))
|
||||
{
|
||||
return printError("autobaud detection failed");
|
||||
}
|
||||
|
||||
printInfoS(2,"got response, answering",0);
|
||||
|
||||
q = sendBufE(q, buf);
|
||||
|
||||
if(!getOK(OK_LIT))
|
||||
{
|
||||
return printError("cant synchronize bootloader");
|
||||
}
|
||||
|
||||
printInfoS(2,"setting frequency",0);
|
||||
|
||||
sendBufE(sprintf(buf, "%i\r\n", cfreq), buf);
|
||||
|
||||
if(!getOK(OK_LIT))
|
||||
{
|
||||
return printError("cant set frequency");
|
||||
}
|
||||
|
||||
printInfoS(2,"switching baudrate",0);
|
||||
|
||||
sendBufE(sprintf(buf, "B 38400 1\r\n"), buf);
|
||||
|
||||
if(!getOK(OK_0))
|
||||
{
|
||||
return printError("cant set baudrate");
|
||||
}
|
||||
|
||||
reconfSerial(38400, 1, 10);
|
||||
|
||||
printInfoS(2,"disabling echo",0);
|
||||
|
||||
sendBufE(sprintf(buf, "A 0\r\n"), buf);
|
||||
|
||||
if(!getOK(OK_0))
|
||||
{
|
||||
return printError("cant disable echo");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int unlockBootLoader(void)
|
||||
{
|
||||
char buf[20];
|
||||
|
||||
sendBuf(sprintf(buf, "U 23130\r\n"), buf);
|
||||
|
||||
if(!getOK(OK_0))
|
||||
{
|
||||
return printError("cant unlock bootloader");
|
||||
}
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
int goBootLoader(unsigned long addr)
|
||||
{
|
||||
char buf[20];
|
||||
|
||||
sendBuf(sprintf(buf, "G %lu A\r\n", addr), buf);
|
||||
|
||||
if(!getOK(OK_0))
|
||||
{
|
||||
return printError("cant issue go command");;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define BSIZE 400
|
||||
|
||||
int uploadData(unsigned long addr, unsigned long len, unsigned char *ibuf)
|
||||
{
|
||||
char buf[128];
|
||||
unsigned char uubuf[BSIZE*3];
|
||||
unsigned int blen, csum;
|
||||
unsigned long slen, saddr, soff;
|
||||
slen = len;
|
||||
saddr = addr;
|
||||
soff = 0;
|
||||
|
||||
if(addr & 0x3)
|
||||
{
|
||||
return printError("RAM address not on dword boundary");
|
||||
}
|
||||
|
||||
while(slen >= BSIZE)
|
||||
{
|
||||
sendBuf(sprintf(buf, "W %lu %i\r\n", saddr+soff, BSIZE), buf);
|
||||
if(!getOK(OK_0))
|
||||
{
|
||||
return printError("cant write data");
|
||||
}
|
||||
|
||||
csum = 0;
|
||||
|
||||
for(blen = 0; blen < BSIZE; blen++)
|
||||
{
|
||||
csum += ibuf[soff+blen];
|
||||
}
|
||||
|
||||
blen = uuencode(ibuf+soff, uubuf, BSIZE);
|
||||
sendBuf(blen, (char*)uubuf);
|
||||
sendBuf(sprintf(buf, "%u\r\n", csum), buf);
|
||||
if(!getOK(OK_LIT))
|
||||
{
|
||||
return printError("error in checksum");
|
||||
}
|
||||
slen -= BSIZE;
|
||||
soff += BSIZE;
|
||||
}
|
||||
|
||||
if(slen)
|
||||
{
|
||||
sendBuf(sprintf(buf, "W %lu %lu\r\n", saddr+soff, slen), buf);
|
||||
if(!getOK(OK_0))
|
||||
{
|
||||
|
||||
return printError("cant write remaining data");
|
||||
}
|
||||
|
||||
csum = 0;
|
||||
|
||||
for(blen = 0; blen < slen; blen++)
|
||||
{
|
||||
csum += ibuf[soff+blen];
|
||||
}
|
||||
|
||||
blen = uuencode(ibuf+soff, uubuf, slen);
|
||||
sendBuf(blen, (char*)uubuf);
|
||||
sendBuf(sprintf(buf, "%i\r\n", csum), buf);
|
||||
|
||||
if(!getOK(OK_LIT))
|
||||
{
|
||||
return printError("error in checksum for remaining data");
|
||||
}
|
||||
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int uploadRAM(int fd, int loc)
|
||||
{
|
||||
unsigned char buf[70000];
|
||||
|
||||
unsigned long fx, total, size;
|
||||
total = 0;
|
||||
|
||||
if(fd)
|
||||
{
|
||||
printInfoS(2,"reading image into buffer", 0);
|
||||
fx = read(fd,buf,70000);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(fx=0; fx<tool_len; fx++)
|
||||
{
|
||||
buf[fx] = tool_data[fx];
|
||||
}
|
||||
fx = tool_len;
|
||||
}
|
||||
|
||||
size = fx;
|
||||
|
||||
printInfoS(0,"starting ram upload", 0);
|
||||
|
||||
printProgress(0,"RAM",total,fx);
|
||||
|
||||
while(fx)
|
||||
{
|
||||
if(fx >= 256)
|
||||
{
|
||||
if(!uploadData(loc+total, 256, buf+total))
|
||||
{
|
||||
return printError("Error in upload");
|
||||
}
|
||||
total += 256;
|
||||
fx -= 256;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!uploadData(loc+total, fx, buf+total))
|
||||
{
|
||||
return printError("Error in upload");
|
||||
}
|
||||
total += fx;
|
||||
fx -= fx;
|
||||
}
|
||||
|
||||
printProgress(0,"RAM",total,size);
|
||||
}
|
||||
|
||||
printInfoH(0,"ram upload complete, total bytes:", total);
|
||||
|
||||
return 1;
|
||||
}
|
12
lpctool/testing/bootcom.h
Normal file
12
lpctool/testing/bootcom.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#ifndef BOOTCOM_H
|
||||
#define BOOTCOM_H
|
||||
|
||||
#define OK_LIT 0x00
|
||||
#define OK_0 0x01
|
||||
|
||||
unsigned int uuencode(unsigned char *ibuf, unsigned char *obuf, int len);
|
||||
int openBootLoader(unsigned int cfreq);
|
||||
int uploadData(unsigned long addr, unsigned long len, unsigned char *ibuf);
|
||||
int uploadRAM(int fd, int loc);
|
||||
|
||||
#endif
|
4
lpctool/testing/fla.sh
Normal file
4
lpctool/testing/fla.sh
Normal file
|
@ -0,0 +1,4 @@
|
|||
#!/bin/sh
|
||||
|
||||
#~ ./lpctool -d /dev/ttyS0 -i -v -e -a ../../boop/trunk/boop_rom.bin
|
||||
./lpctool -d /dev/ttyUSB0 -i -v -e -a ../../boop/trunk/boop_rom.bin
|
51
lpctool/testing/flashtool/Makefile
Normal file
51
lpctool/testing/flashtool/Makefile
Normal file
|
@ -0,0 +1,51 @@
|
|||
|
||||
include ../Makefile.inc
|
||||
|
||||
|
||||
all: tool_data.h
|
||||
|
||||
ramtool.bin: ramtool.elf
|
||||
$(OC) -O binary ramtool.elf ramtool.bin
|
||||
|
||||
ramtool.elf: crt.o serial.o lcd.o fonty.o flash.o ramtool.o lpc2220.ld
|
||||
$(LD) $(LDFLAGS) -o ramtool.elf crt.o serial.o lcd.o fonty.o flash.o ramtool.o
|
||||
|
||||
romtool.bin: romtool.elf
|
||||
$(OC) -O binary romtool.elf romtool.bin
|
||||
|
||||
romtool.elf: crt.o serial.o lcd.o fonty.o flash.o romtool.o lpc2220_rom.ld
|
||||
$(LD) $(ROMLDFLAGS) -o romtool.elf crt.o serial.o lcd.o fonty.o flash.o romtool.o
|
||||
|
||||
crt.o: crt.s
|
||||
$(AS) $(ASFLAGS) -o crt.o crt.s
|
||||
|
||||
flash.o: flash.c flash.h serial.h lcd.h
|
||||
$(CC) $(CFLAGS) -o flash.o flash.c
|
||||
|
||||
lcd.o: lcd.c lcd.h lpc2220.h
|
||||
$(CC) $(CFLAGS) -o lcd.o lcd.c
|
||||
|
||||
fonty.o: fonty.c fonty.h charset.bits charset.info lcd.h
|
||||
$(CC) $(CFLAGS) -o fonty.o fonty.c
|
||||
|
||||
serial.o: serial.c serial.h lcd.h lpc2220.h
|
||||
$(CC) $(CFLAGS) -o serial.o serial.c
|
||||
|
||||
ramtool.o: ramtool.c serial.o lcd.h flash.h lpc2220.h
|
||||
$(CC) $(CFLAGS) -o ramtool.o ramtool.c
|
||||
|
||||
romtool.o: ramtool.c serial.o lcd.h flash.h lpc2220.h
|
||||
$(CC) $(CFLAGS) -DRESIDENT -o romtool.o ramtool.c
|
||||
|
||||
bin2h: bin2h.c ramtool.bin
|
||||
gcc -Os bin2h.c -o bin2h
|
||||
strip bin2h
|
||||
|
||||
tool_data.h: bin2h
|
||||
./bin2h > tool_data.h
|
||||
mv tool_data.h ..
|
||||
|
||||
clean:
|
||||
$(RM) *.o ramtool.elf ramtool.bin romtool.elf romtool.bin *~ bin2h
|
||||
|
||||
### EOF
|
30
lpctool/testing/flashtool/bin2h.c
Normal file
30
lpctool/testing/flashtool/bin2h.c
Normal file
|
@ -0,0 +1,30 @@
|
|||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
#include <fcntl.h>
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int fd;
|
||||
unsigned long cnt, cnt2;
|
||||
unsigned char buf[0x10000];
|
||||
|
||||
fd = open("ramtool.bin", O_RDONLY);
|
||||
|
||||
if(fd)
|
||||
{
|
||||
cnt = read(fd, buf, 0x10000);
|
||||
cnt2 = 0;
|
||||
printf("#define tool_len 0x%08lX\n",cnt);
|
||||
printf("const unsigned char tool_data[] = {\n\t");
|
||||
while(cnt--)
|
||||
{
|
||||
printf("0x%02X,",buf[cnt2++]);
|
||||
if((cnt2 & 0x0F) == 0)
|
||||
printf("\n\t");
|
||||
}
|
||||
printf("\n};\n");
|
||||
close(fd);
|
||||
}
|
||||
return 0;
|
||||
}
|
118
lpctool/testing/flashtool/charset.bits
Normal file
118
lpctool/testing/flashtool/charset.bits
Normal file
|
@ -0,0 +1,118 @@
|
|||
const unsigned char charset_bits[] = {
|
||||
0x80, 0xc0, 0x80, 0xe0, 0x80, 0xc0, 0x80, 0xf0, 0x01, 0x03, 0x01, 0x07,
|
||||
0x01, 0x03, 0x01, 0x0f, 0x80, 0x88, 0xaa, 0xff, 0xff, 0xaa, 0x88, 0x80,
|
||||
0x00, 0xc0, 0x00, 0xe0, 0x00, 0xc0, 0x00, 0xf0, 0x00, 0x03, 0x00, 0x07,
|
||||
0x00, 0x03, 0x00, 0x0f, 0x80, 0x88, 0xaa, 0xab, 0xab, 0xaa, 0x88, 0x80,
|
||||
0x80, 0x80, 0x80, 0x70, 0x01, 0x01, 0x01, 0x0e, 0x0e, 0x01, 0x01, 0x01,
|
||||
0x70, 0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0x00, 0x00, 0x80, 0x00, 0x24,
|
||||
0x00, 0x80, 0x00, 0x00, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x80, 0x00, 0x80,
|
||||
0x00, 0x80, 0x00, 0x92, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0xaa,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0x80, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0xaa, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x81,
|
||||
0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0xaa, 0x02, 0x05, 0x02, 0x00,
|
||||
0x3e, 0x41, 0x41, 0x22, 0x02, 0x05, 0x02, 0x00, 0x7f, 0x09, 0x09, 0x01,
|
||||
0x1c, 0x22, 0x41, 0x4f, 0x41, 0x22, 0x1c, 0x1c, 0x22, 0x41, 0x4f, 0x47,
|
||||
0x22, 0x1c, 0x1c, 0x22, 0x41, 0x4f, 0x4f, 0x2e, 0x1c, 0x1c, 0x22, 0x41,
|
||||
0x4f, 0x5f, 0x3e, 0x1c, 0x1c, 0x22, 0x41, 0x7f, 0x7f, 0x3e, 0x1c, 0x1c,
|
||||
0x22, 0x71, 0x7f, 0x7f, 0x3e, 0x1c, 0x1c, 0x3a, 0x79, 0x7f, 0x7f, 0x3e,
|
||||
0x1c, 0x1c, 0x3e, 0x7d, 0x7f, 0x7f, 0x3e, 0x1c, 0x1c, 0x3e, 0x7f, 0x7f,
|
||||
0x7f, 0x3e, 0x1c, 0x00, 0x00, 0x5f, 0x03, 0x00, 0x03, 0x14, 0x7f, 0x14,
|
||||
0x7f, 0x14, 0x24, 0x4a, 0xff, 0x4a, 0x32, 0x63, 0x13, 0x08, 0x64, 0x63,
|
||||
0x36, 0x49, 0x55, 0x22, 0x50, 0x03, 0x1c, 0x22, 0x41, 0x41, 0x22, 0x1c,
|
||||
0x14, 0x08, 0x3e, 0x08, 0x14, 0x08, 0x08, 0x3e, 0x08, 0x08, 0x80, 0x60,
|
||||
0x60, 0x08, 0x08, 0x08, 0x08, 0x08, 0x60, 0x60, 0xc0, 0x30, 0x0c, 0x03,
|
||||
0x3e, 0x51, 0x49, 0x45, 0x3e, 0x00, 0x42, 0x7f, 0x40, 0x00, 0x42, 0x61,
|
||||
0x51, 0x49, 0x46, 0x22, 0x41, 0x49, 0x49, 0x36, 0x18, 0x14, 0x12, 0x7f,
|
||||
0x10, 0x27, 0x45, 0x45, 0x45, 0x39, 0x3e, 0x49, 0x49, 0x49, 0x32, 0x61,
|
||||
0x11, 0x09, 0x05, 0x03, 0x36, 0x49, 0x49, 0x49, 0x36, 0x26, 0x49, 0x49,
|
||||
0x49, 0x3e, 0x6c, 0x6c, 0x80, 0x6c, 0x6c, 0x08, 0x14, 0x22, 0x41, 0x14,
|
||||
0x14, 0x14, 0x14, 0x41, 0x22, 0x14, 0x08, 0x02, 0x01, 0x51, 0x09, 0x06,
|
||||
0x3e, 0x41, 0x59, 0x55, 0x5e, 0x7e, 0x09, 0x09, 0x09, 0x7e, 0x7f, 0x49,
|
||||
0x49, 0x49, 0x36, 0x3e, 0x41, 0x41, 0x41, 0x22, 0x7f, 0x41, 0x41, 0x41,
|
||||
0x3e, 0x7f, 0x49, 0x49, 0x41, 0x41, 0x7f, 0x09, 0x09, 0x01, 0x01, 0x3e,
|
||||
0x41, 0x41, 0x49, 0x3a, 0x7f, 0x08, 0x08, 0x08, 0x7f, 0x41, 0x7f, 0x41,
|
||||
0x30, 0x41, 0x41, 0x41, 0x3f, 0x7f, 0x08, 0x14, 0x22, 0x41, 0x7f, 0x40,
|
||||
0x40, 0x40, 0x40, 0x7f, 0x02, 0x0c, 0x02, 0x7f, 0x7f, 0x02, 0x04, 0x08,
|
||||
0x7f, 0x3e, 0x41, 0x41, 0x41, 0x3e, 0x7f, 0x09, 0x09, 0x09, 0x06, 0x3e,
|
||||
0x41, 0x41, 0x41, 0xbe, 0x7f, 0x09, 0x09, 0x09, 0x76, 0x26, 0x49, 0x49,
|
||||
0x49, 0x32, 0x01, 0x01, 0x7f, 0x01, 0x01, 0x3f, 0x40, 0x40, 0x40, 0x3f,
|
||||
0x1f, 0x20, 0x40, 0x20, 0x1f, 0x7f, 0x20, 0x10, 0x20, 0x7f, 0x41, 0x22,
|
||||
0x1c, 0x22, 0x41, 0x07, 0x08, 0x70, 0x08, 0x07, 0x61, 0x51, 0x49, 0x45,
|
||||
0x43, 0x7f, 0x41, 0x41, 0x03, 0x0c, 0x30, 0xc0, 0x41, 0x41, 0x7f, 0x02,
|
||||
0x01, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01, 0x02, 0x20, 0x54, 0x54,
|
||||
0x78, 0x7f, 0x48, 0x48, 0x30, 0x38, 0x44, 0x44, 0x24, 0x30, 0x48, 0x48,
|
||||
0x7f, 0x38, 0x54, 0x54, 0x18, 0x08, 0x7e, 0x09, 0x02, 0x98, 0xa4, 0xa4,
|
||||
0x78, 0x7f, 0x08, 0x08, 0x70, 0x44, 0x7d, 0x40, 0x44, 0x84, 0x7d, 0x7f,
|
||||
0x10, 0x28, 0x44, 0x41, 0x7f, 0x40, 0x7c, 0x04, 0x18, 0x04, 0x78, 0x7c,
|
||||
0x08, 0x04, 0x78, 0x38, 0x44, 0x44, 0x38, 0xfc, 0x24, 0x24, 0x18, 0x18,
|
||||
0x24, 0x24, 0xfc, 0x7c, 0x08, 0x04, 0x08, 0x48, 0x54, 0x54, 0x24, 0x04,
|
||||
0x3f, 0x44, 0x3c, 0x40, 0x20, 0x7c, 0x1c, 0x20, 0x40, 0x20, 0x1c, 0x3c,
|
||||
0x40, 0x30, 0x40, 0x3c, 0x44, 0x28, 0x10, 0x28, 0x44, 0x9c, 0xa0, 0xa0,
|
||||
0x7c, 0x64, 0x54, 0x54, 0x4c, 0x08, 0x36, 0x41, 0x77, 0x41, 0x36, 0x08,
|
||||
0x08, 0x08, 0x2a, 0x1c, 0x08, 0x08, 0x1c, 0x2a, 0x08, 0x08, 0x00, 0x00,
|
||||
0x00, 0xdf, 0xdf, 0x07, 0x07, 0x00, 0x07, 0x07, 0x14, 0x3e, 0x14, 0x3e,
|
||||
0x14, 0x24, 0x4a, 0xff, 0x4a, 0x32, 0xf3, 0xfb, 0x18, 0xdf, 0xc7, 0x36,
|
||||
0x49, 0x55, 0x22, 0x50, 0x04, 0x07, 0x03, 0x3c, 0x7e, 0xc3, 0x81, 0x81,
|
||||
0xc3, 0x7e, 0x3c, 0x14, 0x08, 0x3e, 0x08, 0x14, 0x18, 0x7e, 0x7e, 0x18,
|
||||
0x80, 0x60, 0x60, 0x18, 0x18, 0x18, 0x18, 0x18, 0x60, 0x60, 0xc0, 0xf0,
|
||||
0x3c, 0x0f, 0x03, 0x7e, 0xff, 0xc3, 0xff, 0x7e, 0x04, 0xc6, 0xff, 0xff,
|
||||
0xc0, 0xe6, 0xf7, 0xd3, 0xdf, 0xce, 0x42, 0xc3, 0xdb, 0xff, 0x76, 0x38,
|
||||
0x3c, 0x36, 0xff, 0xff, 0x5f, 0xdf, 0xdb, 0xfb, 0x73, 0x7e, 0xff, 0xdb,
|
||||
0xfb, 0x72, 0x03, 0xf3, 0xfb, 0x0f, 0x07, 0x76, 0xff, 0xdb, 0xff, 0x76,
|
||||
0x4e, 0xdf, 0xdb, 0xff, 0x7e, 0x6c, 0x6c, 0x80, 0x6c, 0x6c, 0x18, 0x3c,
|
||||
0x66, 0xc3, 0x81, 0x36, 0x36, 0x36, 0x36, 0x81, 0xc3, 0x66, 0x3c, 0x18,
|
||||
0x06, 0xd3, 0xd9, 0x0f, 0x06, 0x7e, 0xc3, 0xdb, 0xd7, 0xde, 0xfe, 0xff,
|
||||
0x33, 0xff, 0xfe, 0xff, 0xff, 0xdb, 0xff, 0x66, 0x7e, 0xff, 0xc3, 0xe7,
|
||||
0x66, 0xff, 0xff, 0xc3, 0xff, 0x7e, 0xff, 0xff, 0xdb, 0xdb, 0xc3, 0xff,
|
||||
0xff, 0x1b, 0x1b, 0x03, 0x7e, 0xff, 0xc3, 0xfb, 0x7a, 0xff, 0xff, 0x18,
|
||||
0xff, 0xff, 0xc3, 0xff, 0xff, 0xc3, 0x60, 0xe3, 0xc3, 0xff, 0x7f, 0xff,
|
||||
0xff, 0x1c, 0xf7, 0xe3, 0xff, 0xff, 0xc0, 0xc0, 0xc0, 0xff, 0xfe, 0x0c,
|
||||
0xfe, 0xff, 0xff, 0xfe, 0x18, 0x7f, 0xff, 0x7e, 0xff, 0xc3, 0xff, 0x7e,
|
||||
0xff, 0xff, 0x1b, 0x1f, 0x0e, 0x7e, 0xff, 0xc3, 0x7f, 0xde, 0xff, 0xff,
|
||||
0x1b, 0xff, 0xee, 0x4e, 0xdf, 0xdb, 0xfb, 0x72, 0x03, 0xff, 0xff, 0x03,
|
||||
0x03, 0x7f, 0xff, 0xc0, 0xff, 0x7f, 0x3f, 0x7f, 0xc0, 0x7f, 0x3f, 0xff,
|
||||
0x7f, 0x30, 0x7f, 0xff, 0xe7, 0xe7, 0x18, 0x18, 0xe7, 0xe7, 0x0f, 0x1f,
|
||||
0xf0, 0x1f, 0x0f, 0xe3, 0xf3, 0xdb, 0xcf, 0xc7, 0xff, 0xff, 0xc3, 0xc3,
|
||||
0x03, 0x0f, 0x3c, 0xf0, 0xc0, 0xc3, 0xc3, 0xff, 0xff, 0x04, 0x06, 0x03,
|
||||
0x06, 0x04, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x03, 0x07, 0x60, 0xf4, 0xd4,
|
||||
0xf4, 0xf8, 0xff, 0xff, 0xcc, 0xfc, 0x78, 0x78, 0xfc, 0xcc, 0xcc, 0x48,
|
||||
0x78, 0xfc, 0xcc, 0xff, 0xff, 0x78, 0xfc, 0xac, 0xbc, 0xb8, 0x18, 0xfe,
|
||||
0xff, 0x1b, 0x1b, 0xb8, 0xbc, 0xac, 0xfc, 0x78, 0xff, 0xff, 0x18, 0xf8,
|
||||
0xf0, 0xcc, 0xfd, 0xfd, 0xc0, 0xc0, 0xcc, 0xfd, 0x7d, 0xff, 0xff, 0x10,
|
||||
0xfc, 0xec, 0x7f, 0xff, 0xc0, 0xc0, 0xfc, 0xfc, 0x0c, 0xfc, 0x0c, 0xfc,
|
||||
0xf8, 0xfc, 0xf8, 0x0c, 0xfc, 0xf8, 0x78, 0xfc, 0xcc, 0xfc, 0x78, 0xfc,
|
||||
0xfc, 0x6c, 0x7c, 0x38, 0x38, 0x7c, 0x6c, 0xfc, 0xf8, 0xfc, 0xf8, 0x0c,
|
||||
0x1c, 0x18, 0xd8, 0xdc, 0xfc, 0xec, 0x6c, 0x0c, 0x7f, 0xff, 0xcc, 0xcc,
|
||||
0x7c, 0xfc, 0xc0, 0x7c, 0xfc, 0x3c, 0x7c, 0xc0, 0x7c, 0x3c, 0x7c, 0xfc,
|
||||
0xc0, 0x60, 0xc0, 0xfc, 0x7c, 0xcc, 0xfc, 0x30, 0xfc, 0xdc, 0x9c, 0xbc,
|
||||
0xb0, 0xfc, 0x7c, 0xcc, 0xec, 0xfc, 0xdc, 0xcc, 0x10, 0x56, 0xef, 0x81,
|
||||
0xef, 0xef, 0x81, 0xee, 0x56, 0x10, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x18,
|
||||
0x3c, 0x7e, 0x18, 0x18, 0x8f, 0xc7, 0xe3, 0xf1, 0xf8, 0x7c, 0x3e, 0x1f,
|
||||
0xc7, 0xe3, 0xf1, 0xf8, 0x7c, 0x3e, 0x1f, 0x8f, 0xe3, 0xf1, 0xf8, 0x7c,
|
||||
0x3e, 0x1f, 0x8f, 0xc7, 0xf1, 0xf8, 0x7c, 0x3e, 0x1f, 0x8f, 0xc7, 0xe3,
|
||||
0xf8, 0x7c, 0x3e, 0x1f, 0x8f, 0xc7, 0xe3, 0xf1, 0x7c, 0x3e, 0x1f, 0x8f,
|
||||
0xc7, 0xe3, 0xf1, 0xf8, 0x3e, 0x1f, 0x8f, 0xc7, 0xe3, 0xf1, 0xf8, 0x7c,
|
||||
0x1f, 0x8f, 0xc7, 0xe3, 0xf1, 0xf8, 0x7c, 0x3e, 0xff, 0xff, 0xe7, 0xc3,
|
||||
0xc3, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xc3, 0xc3, 0xe7, 0xff, 0xff,
|
||||
0xff, 0xf8, 0xe0, 0xc0, 0xc0, 0xe0, 0xf8, 0xff, 0xff, 0x1f, 0x07, 0x03,
|
||||
0x03, 0x07, 0x1f, 0xff, 0x1c, 0x3e, 0x77, 0x63, 0x77, 0x3e, 0x1c, 0x1c,
|
||||
0x36, 0x63, 0x41, 0x63, 0x36, 0x1c, 0x1c, 0x08, 0x41, 0x63, 0x41, 0x08,
|
||||
0x1c, 0x08, 0x14, 0x22, 0x49, 0x22, 0x14, 0x08, 0x55, 0xaa, 0x55, 0xaa,
|
||||
0x55, 0xaa, 0x55, 0xaa, 0x33, 0x33, 0xcc, 0xcc, 0x33, 0x33, 0xcc, 0xcc,
|
||||
0x33, 0x33, 0x0e, 0x11, 0x0e, 0x12, 0x1f, 0x10, 0x19, 0x15, 0x12, 0x11,
|
||||
0x15, 0x0a, 0x07, 0x04, 0x1e, 0x17, 0x15, 0x09, 0x0e, 0x15, 0x09, 0x01,
|
||||
0x1d, 0x03, 0x0a, 0x15, 0x0a, 0x12, 0x15, 0x0e, 0x0a, 0x10, 0x0a, 0x04,
|
||||
0x0a, 0x11, 0x0a, 0x0a, 0x0a, 0x11, 0x0a, 0x04, 0x01, 0x15, 0x02, 0x01,
|
||||
0x03, 0x07, 0x03, 0x01, 0x04, 0x06, 0x07, 0x06, 0x04, 0x04, 0x0e, 0x1f,
|
||||
0x1f, 0x0e, 0x04, 0x18, 0x3c, 0x7e, 0x7e, 0x3c, 0x18, 0x3c, 0x42, 0x81,
|
||||
0x81, 0x81, 0x81, 0x42, 0x3c, 0x3c, 0x42, 0x99, 0xbd, 0xbd, 0x99, 0x42,
|
||||
0x3c, 0x7f, 0x49, 0x41, 0x6b, 0x41, 0x49, 0x7f, 0x80, 0x40, 0x20, 0x10,
|
||||
0x0f, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x07, 0x3e, 0x01, 0x01, 0x01,
|
||||
0x01, 0x02, 0x04, 0x38, 0x08, 0x08, 0x08, 0x08, 0x01, 0x01, 0x01, 0x01,
|
||||
0x15, 0x0a, 0x15, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
22
lpctool/testing/flashtool/charset.info
Normal file
22
lpctool/testing/flashtool/charset.info
Normal file
|
@ -0,0 +1,22 @@
|
|||
const unsigned char charset_info[] = {
|
||||
0x08, 0x84, 0x48, 0x84, 0x44, 0x44, 0x48, 0x88, // 0- 15 graticule & borders
|
||||
0x88, 0x88, 0x88, 0x87, 0x77, 0x77, 0x77, 0x77, // 16- 31 graticule & symbols
|
||||
0x21, 0x35, 0x55, 0x51, 0x33, 0x55, 0x35, 0x24, // 32- 47 ascii, font 1
|
||||
0x55, 0x55, 0x55, 0x55, 0x55, 0x23, 0x44, 0x45, // 48- 63 ascii, font 1
|
||||
0x55, 0x55, 0x55, 0x55, 0x53, 0x55, 0x55, 0x55, // 64- 80 ascii, font 1
|
||||
0x55, 0x55, 0x55, 0x55, 0x55, 0x53, 0x43, 0x35, // 80- 95 ascii, font 1
|
||||
0x24, 0x44, 0x44, 0x44, 0x43, 0x34, 0x35, 0x44, // 96-112 ascii, font 1
|
||||
0x44, 0x44, 0x34, 0x55, 0x54, 0x43, 0x13, 0x55, // 112-127 ascii, font 1
|
||||
0x32, 0x55, 0x55, 0x53, 0x44, 0x54, 0x35, 0x25, // 128-143 ascii, bold font
|
||||
0x55, 0x55, 0x55, 0x55, 0x55, 0x23, 0x54, 0x55, // 144-159 ascii, bold font
|
||||
0x55, 0x55, 0x55, 0x55, 0x54, 0x55, 0x55, 0x55, // 160-175 ascii, bold font
|
||||
0x55, 0x55, 0x55, 0x55, 0x65, 0x54, 0x54, 0x55, // 176-191 ascii, bold font
|
||||
0x25, 0x55, 0x55, 0x55, 0x54, 0x45, 0x47, 0x55, // 192-207 ascii, bold font
|
||||
0x55, 0x55, 0x55, 0x57, 0x55, 0x54, 0x24, 0x55, // 208-223 ascii, bold font
|
||||
0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x77, 0x77, // 224-239 symbols
|
||||
0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 240-255 symbols
|
||||
0x33, 0x33, 0x33, 0x33, 0x33, 0x12, 0x33, 0x33, // 256-271 small numbers
|
||||
0x55, 0x33, 0x68, 0x87, 0x84, 0x44, 0x44, 0x44 // 272-288 symbols
|
||||
};
|
||||
|
||||
const unsigned char charset_dlines = 1;
|
163
lpctool/testing/flashtool/crt.s
Normal file
163
lpctool/testing/flashtool/crt.s
Normal file
|
@ -0,0 +1,163 @@
|
|||
/* *************************************************************
|
||||
|
||||
crt.s STARTUP ASSEMBLY CODE
|
||||
-----------------------
|
||||
|
||||
|
||||
Module includes the interrupt vectors and start-up code.
|
||||
|
||||
****************************************************************/
|
||||
|
||||
/* Stack Sizes */
|
||||
.set UND_STACK_SIZE, 0x00000004 /* stack for "undefined instruction" interrupts is 4 bytes */
|
||||
.set ABT_STACK_SIZE, 0x00000004 /* stack for "abort" interrupts is 4 bytes */
|
||||
.set FIQ_STACK_SIZE, 0x00000010 /* stack for "FIQ" interrupts is 4 bytes */
|
||||
.set IRQ_STACK_SIZE, 0X00000020 /* stack for "IRQ" normal interrupts is 4 bytes */
|
||||
.set SVC_STACK_SIZE, 0x00000010 /* stack for "SVC" supervisor mode is 4 bytes */
|
||||
|
||||
|
||||
|
||||
/* Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs (program status registers) */
|
||||
.set MODE_USR, 0x10 /* Normal User Mode */
|
||||
.set MODE_FIQ, 0x11 /* FIQ Processing Fast Interrupts Mode */
|
||||
.set MODE_IRQ, 0x12 /* IRQ Processing Standard Interrupts Mode */
|
||||
.set MODE_SVC, 0x13 /* Supervisor Processing Software Interrupts Mode */
|
||||
.set MODE_ABT, 0x17 /* Abort Processing memory Faults Mode */
|
||||
.set MODE_UND, 0x1B /* Undefined Processing Undefined Instructions Mode */
|
||||
.set MODE_SYS, 0x1F /* System Running Priviledged Operating System Tasks Mode */
|
||||
|
||||
.set I_BIT, 0x80 /* when I bit is set, IRQ is disabled (program status registers) */
|
||||
.set F_BIT, 0x40 /* when F bit is set, FIQ is disabled (program status registers) */
|
||||
|
||||
|
||||
.text
|
||||
.arm
|
||||
|
||||
.global Reset_Handler
|
||||
.global _startup
|
||||
.func _startup
|
||||
|
||||
_startup:
|
||||
|
||||
# Exception Vectors
|
||||
|
||||
_vectors: ldr PC, Reset_Addr
|
||||
ldr PC, Undef_Addr
|
||||
ldr PC, SWI_Addr
|
||||
ldr PC, PAbt_Addr
|
||||
ldr PC, DAbt_Addr
|
||||
nop /* Reserved Vector (holds Philips ISP checksum) */
|
||||
ldr PC, [PC,#-0xFF0] /* see page 71 of "Insiders Guide to the Philips ARM7-Based Microcontrollers" by Trevor Martin */
|
||||
ldr PC, FIQ_Addr
|
||||
|
||||
Reset_Addr: .word Reset_Handler /* defined in this module below */
|
||||
Undef_Addr: .word UNDEF_Routine /* defined in main.c */
|
||||
SWI_Addr: .word SWI_Routine /* defined in main.c */
|
||||
PAbt_Addr: .word UNDEF_Routine /* defined in main.c */
|
||||
DAbt_Addr: .word UNDEF_Routine /* defined in main.c */
|
||||
IRQ_Addr: .word IRQ_Routine /* defined in main.c */
|
||||
FIQ_Addr: .word FIQ_Routine /* defined in main.c */
|
||||
.word 0 /* rounds the vectors and ISR addresses to 64 bytes total */
|
||||
|
||||
|
||||
# Reset Handler
|
||||
|
||||
Reset_Handler:
|
||||
|
||||
/* Setup a stack for each mode - note that this only sets up a usable stack
|
||||
for User mode. Also each mode is setup with interrupts initially disabled. */
|
||||
|
||||
ldr r0, =_stack_end
|
||||
msr CPSR_c, #MODE_UND|I_BIT|F_BIT /* Undefined Instruction Mode */
|
||||
mov sp, r0
|
||||
sub r0, r0, #UND_STACK_SIZE
|
||||
msr CPSR_c, #MODE_ABT|I_BIT|F_BIT /* Abort Mode */
|
||||
mov sp, r0
|
||||
sub r0, r0, #ABT_STACK_SIZE
|
||||
msr CPSR_c, #MODE_FIQ|I_BIT|F_BIT /* FIQ Mode */
|
||||
mov sp, r0
|
||||
sub r0, r0, #FIQ_STACK_SIZE
|
||||
msr CPSR_c, #MODE_IRQ|I_BIT|F_BIT /* IRQ Mode */
|
||||
mov sp, r0
|
||||
sub r0, r0, #IRQ_STACK_SIZE
|
||||
msr CPSR_c, #MODE_SVC|I_BIT|F_BIT /* Supervisor Mode */
|
||||
mov sp, r0
|
||||
sub r0, r0, #SVC_STACK_SIZE
|
||||
msr CPSR_c, #MODE_SYS|F_BIT /* User Mode */
|
||||
mov sp, r0
|
||||
|
||||
/* set up pins and membanks */
|
||||
ldr r0, = PINSEL2
|
||||
ldr r2, =0xD6041D4
|
||||
str r2, [r0]
|
||||
|
||||
ldr r1, =0x10000420
|
||||
ldr r0,=BCFG0
|
||||
str r1,[r0]
|
||||
str r1,[r0,#0x08]
|
||||
|
||||
/* copy .data section (Copy from ROM to RAM) */
|
||||
ldr R1, =_etext
|
||||
ldr R2, =_data
|
||||
ldr R3, =_edata
|
||||
1: cmp R2, R3
|
||||
ldrlo R0, [R1], #4
|
||||
strlo R0, [R2], #4
|
||||
blo 1b
|
||||
|
||||
/* Clear .bss section (Zero init) */
|
||||
|
||||
mov R0, #0
|
||||
ldr R1, =_bss_start
|
||||
ldr R2, =_bss_end
|
||||
2: cmp R1, R2
|
||||
strlo R0, [R1], #4
|
||||
blo 2b
|
||||
|
||||
|
||||
|
||||
/* set up the pll */
|
||||
ldr r0, =0xe01fc000
|
||||
ldr r2, =0xaa
|
||||
ldr r3, =0x55
|
||||
ldr r1, =0x03
|
||||
str r1, [r0,#0x80]
|
||||
ldr r1, =0x0
|
||||
str r1, [r0,#0x100]
|
||||
ldr r1, =0x42
|
||||
str r1,[r0,#0x84]
|
||||
str r2, [r0,#0x8c]
|
||||
str r3, [r0,#0x8c]
|
||||
|
||||
ldr r2, =IO0PIN
|
||||
mov r3, #0x10
|
||||
str r3, [r2,#0xc]
|
||||
ldr r3, [r2,#8]
|
||||
bic r3, r3, #0x10
|
||||
str r3, [r2,#8]
|
||||
|
||||
ldr r1, =0xc42
|
||||
ldr r0, =BCFG1
|
||||
str r1, [r0]
|
||||
|
||||
ldr r2, =PINSEL0
|
||||
ldr r3, [r2,#0x14]
|
||||
orr r3, r3, #0x800
|
||||
str r3, [r2,#0x14]
|
||||
ldr r3, [r2,#0x14]
|
||||
orr r3, r3, #0x800000
|
||||
str r3, [r2,#0x14]
|
||||
|
||||
/* Enter the C code */
|
||||
mov r0,#0
|
||||
mov r1,r0
|
||||
mov r2,r0
|
||||
mov fp,r0
|
||||
mov r7,r0
|
||||
ldr r10,=main
|
||||
mov lr,pc
|
||||
bx r10
|
||||
|
||||
.endfunc
|
||||
entry_mask: .word 0x4FFFFFFF /* defined in this module below */
|
||||
.end
|
230
lpctool/testing/flashtool/flash.c
Normal file
230
lpctool/testing/flashtool/flash.c
Normal file
|
@ -0,0 +1,230 @@
|
|||
#include "lpc2220.h"
|
||||
#include "flash.h"
|
||||
#include "serial.h"
|
||||
#include "lcd.h"
|
||||
|
||||
const unsigned long secaddr[19] =
|
||||
{ 0x00000,
|
||||
0x02000,
|
||||
0x03000,
|
||||
0x04000,
|
||||
0x08000,
|
||||
0x10000,
|
||||
0x18000,
|
||||
0x20000,
|
||||
0x28000,
|
||||
0x30000,
|
||||
0x38000,
|
||||
0x40000,
|
||||
0x48000,
|
||||
0x50000,
|
||||
0x58000,
|
||||
0x60000,
|
||||
0x68000,
|
||||
0x70000,
|
||||
0x78000 };
|
||||
|
||||
unsigned long flash_base;
|
||||
unsigned short check1, check2;
|
||||
|
||||
void slow(void)
|
||||
{
|
||||
BCFG0 = 0x10000420;
|
||||
BCFG2 = 0x10000420;
|
||||
}
|
||||
|
||||
void fast(void)
|
||||
{
|
||||
BCFG0 = 0x10000400;
|
||||
BCFG2 = 0x10000400;
|
||||
}
|
||||
int eraseSector(unsigned char chip, unsigned char secnum)
|
||||
{
|
||||
|
||||
if(chip == 0)
|
||||
flash_base = FLASH0_BASE;
|
||||
else
|
||||
flash_base = FLASH1_BASE;
|
||||
|
||||
*((volatile unsigned short *)(flash_base | 0xAAA)) = 0xAA;
|
||||
*((volatile unsigned short *)(flash_base | 0x554)) = 0x55;
|
||||
*((volatile unsigned short *)(flash_base | 0xAAA)) = 0x80;
|
||||
*((volatile unsigned short *)(flash_base | 0xAAA)) = 0xAA;
|
||||
*((volatile unsigned short *)(flash_base | 0x554)) = 0x55;
|
||||
*((volatile unsigned short *)(flash_base + (secaddr[secnum]<<1))) = 0x30;
|
||||
retry:
|
||||
check1 = *((volatile unsigned short *)flash_base);
|
||||
check2 = *((volatile unsigned short *)flash_base);
|
||||
if((check1 & 0x44) == (check2 & 0x44))
|
||||
goto done;
|
||||
if(!(check2 & 0x24))
|
||||
goto retry;
|
||||
check1 = *((volatile unsigned short *)flash_base);
|
||||
check2 = *((volatile unsigned short *)flash_base);
|
||||
if((check1 & 0x44) == (check2 & 0x44))
|
||||
goto done;
|
||||
*((volatile unsigned short *)flash_base) = 0xF0;
|
||||
return -1;
|
||||
|
||||
done:
|
||||
check1 = *((volatile unsigned short *)flash_base);
|
||||
check2 = *((volatile unsigned short *)flash_base);
|
||||
if(check1 != check2)
|
||||
goto retry;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int eraseSectorAt(unsigned long sadr)
|
||||
{
|
||||
|
||||
flash_base = sadr & 0xFF000000;
|
||||
|
||||
*((volatile unsigned short *)(flash_base | 0xAAA)) = 0xAA;
|
||||
*((volatile unsigned short *)(flash_base | 0x554)) = 0x55;
|
||||
*((volatile unsigned short *)(flash_base | 0xAAA)) = 0x80;
|
||||
*((volatile unsigned short *)(flash_base | 0xAAA)) = 0xAA;
|
||||
*((volatile unsigned short *)(flash_base | 0x554)) = 0x55;
|
||||
*((volatile unsigned short *)(sadr)) = 0x30;
|
||||
|
||||
retry:
|
||||
check1 = *((volatile unsigned short *)flash_base);
|
||||
check2 = *((volatile unsigned short *)flash_base);
|
||||
if((check1 & 0x44) == (check2 & 0x44))
|
||||
goto done;
|
||||
if(!(check2 & 0x24))
|
||||
goto retry;
|
||||
check1 = *((volatile unsigned short *)flash_base);
|
||||
check2 = *((volatile unsigned short *)flash_base);
|
||||
if((check1 & 0x44) == (check2 & 0x44))
|
||||
goto done;
|
||||
*((volatile unsigned short *)flash_base) = 0xF0;
|
||||
return -1;
|
||||
|
||||
done:
|
||||
check1 = *((volatile unsigned short *)flash_base);
|
||||
check2 = *((volatile unsigned short *)flash_base);
|
||||
if(check1 != check2)
|
||||
goto retry;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int eraseFlash(unsigned char chip)
|
||||
{
|
||||
if(chip == 0)
|
||||
flash_base = FLASH0_BASE;
|
||||
else
|
||||
flash_base = FLASH1_BASE;
|
||||
|
||||
*((volatile unsigned short *)(flash_base | 0xAAA)) = 0xAA;
|
||||
*((volatile unsigned short *)(flash_base | 0x554)) = 0x55;
|
||||
*((volatile unsigned short *)(flash_base | 0xAAA)) = 0x80;
|
||||
*((volatile unsigned short *)(flash_base | 0xAAA)) = 0xAA;
|
||||
*((volatile unsigned short *)(flash_base | 0x554)) = 0x55;
|
||||
*((volatile unsigned short *)(flash_base | 0xAAA)) = 0x10;
|
||||
|
||||
retry:
|
||||
check1 = *((volatile unsigned short *)flash_base);
|
||||
check2 = *((volatile unsigned short *)flash_base);
|
||||
if((check1 & 0x44) == (check2 & 0x44))
|
||||
goto done;
|
||||
if(!(check2 & 0x24))
|
||||
goto retry;
|
||||
check1 = *((volatile unsigned short *)flash_base);
|
||||
check2 = *((volatile unsigned short *)flash_base);
|
||||
if((check1 & 0x44) == (check2 & 0x44))
|
||||
goto done;
|
||||
*((volatile unsigned short *)flash_base) = 0xF0;
|
||||
return -1;
|
||||
|
||||
done:
|
||||
check1 = *((volatile unsigned short *)flash_base);
|
||||
check2 = *((volatile unsigned short *)flash_base);
|
||||
if(check1 != check2)
|
||||
goto retry;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int writeWord(unsigned long addr, unsigned short data)
|
||||
{
|
||||
flash_base = addr & 0xFF000000;
|
||||
*((volatile unsigned short *)(flash_base | 0xAAA)) = 0xAA;
|
||||
*((volatile unsigned short *)(flash_base | 0x554)) = 0x55;
|
||||
*((volatile unsigned short *)(flash_base | 0xAAA)) = 0xA0;
|
||||
*((volatile unsigned short *)(addr)) = data;
|
||||
|
||||
retry:
|
||||
check1 = *((volatile unsigned short *)addr);
|
||||
check2 = *((volatile unsigned short *)addr);
|
||||
if((check1 & 0x40) == (check2 & 0x40))
|
||||
goto done;
|
||||
if(!(check2 & 0x20))
|
||||
goto retry;
|
||||
check1 = *((volatile unsigned short *)addr);
|
||||
check2 = *((volatile unsigned short *)addr);
|
||||
if((check1 & 0x40) == (check2 & 0x40))
|
||||
goto done;
|
||||
*((volatile unsigned short *)addr) = 0xF0;
|
||||
return -1;
|
||||
|
||||
done:
|
||||
check1 = *((volatile unsigned short *)addr);
|
||||
check2 = *((volatile unsigned short *)addr);
|
||||
if(check1 != check2)
|
||||
goto retry;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void prepareBulk(unsigned long dst)
|
||||
{
|
||||
flash_base = dst & 0xFF000000;
|
||||
|
||||
*((volatile unsigned short *)(flash_base | 0xAAA)) = 0xAA;
|
||||
*((volatile unsigned short *)(flash_base | 0x554)) = 0x55;
|
||||
*((volatile unsigned short *)(flash_base | 0xAAA)) = 0x20;
|
||||
}
|
||||
|
||||
void endBulk(unsigned long dst)
|
||||
{
|
||||
flash_base = dst & 0xFF000000;
|
||||
|
||||
*((volatile unsigned short *)(flash_base)) = 0x90;
|
||||
*((volatile unsigned short *)(flash_base)) = 0x00;
|
||||
}
|
||||
|
||||
int writeBulk(unsigned long src, unsigned long dst, unsigned long cnt)
|
||||
{
|
||||
flash_base = dst;
|
||||
while(cnt--)
|
||||
{
|
||||
if(*((volatile unsigned short *)src) != 0xFFFF)
|
||||
{
|
||||
*((volatile unsigned short *)flash_base) = 0xA0;
|
||||
*((volatile unsigned short *)flash_base) = *((volatile unsigned short *)src);
|
||||
|
||||
retry:
|
||||
check1 = *((volatile unsigned short *)flash_base);
|
||||
check2 = *((volatile unsigned short *)flash_base);
|
||||
if((check1 & 0x40) == (check2 & 0x40))
|
||||
goto done;
|
||||
if(!(check2 & 0x20))
|
||||
goto retry;
|
||||
check1 = *((volatile unsigned short *)flash_base);
|
||||
check2 = *((volatile unsigned short *)flash_base);
|
||||
if((check1 & 0x40) == (check2 & 0x40))
|
||||
goto done;
|
||||
*((volatile unsigned short *)flash_base) = 0xF0;
|
||||
return -1;
|
||||
|
||||
done:
|
||||
check1 = *((volatile unsigned short *)flash_base);
|
||||
check2 = *((volatile unsigned short *)flash_base);
|
||||
if(check1 != check2)
|
||||
goto retry;
|
||||
}
|
||||
src+=2;
|
||||
flash_base+=2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
16
lpctool/testing/flashtool/flash.h
Normal file
16
lpctool/testing/flashtool/flash.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#ifndef FLASH_H
|
||||
#define FLASH_H
|
||||
|
||||
#define FLASH0_BASE 0x80000000
|
||||
#define FLASH1_BASE 0x82000000
|
||||
|
||||
void prepareBulk(unsigned long dst);
|
||||
void endBulk(unsigned long dst);
|
||||
int eraseSector(unsigned char chip, unsigned char secnum);
|
||||
int eraseSectorAt(unsigned long sadr);
|
||||
int eraseFlash(unsigned char chip);
|
||||
int writeWord(unsigned long addr, unsigned short data);
|
||||
int writeBulk(unsigned long src, unsigned long dst, unsigned long cnt);
|
||||
void lcd_set(unsigned char s);
|
||||
|
||||
#endif
|
175
lpctool/testing/flashtool/fonty.c
Normal file
175
lpctool/testing/flashtool/fonty.c
Normal file
|
@ -0,0 +1,175 @@
|
|||
#include "lcd.h"
|
||||
#include "fonty.h"
|
||||
|
||||
#include "charset.info"
|
||||
#include "charset.bits"
|
||||
|
||||
static unsigned char tx, ty;
|
||||
static unsigned short coff;
|
||||
unsigned char *font_bits, *font_info;
|
||||
|
||||
void set_font(unsigned char f)
|
||||
{
|
||||
font_bits = (unsigned char*) charset_bits;
|
||||
font_info = (unsigned char*) charset_info;
|
||||
switch(f)
|
||||
{
|
||||
case 0:
|
||||
coff = 0;
|
||||
break;
|
||||
case 1:
|
||||
coff = 96;
|
||||
break;
|
||||
case 2:
|
||||
coff = 224;
|
||||
break;
|
||||
case 3:
|
||||
case 4:
|
||||
coff = 272;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void _draw_char(
|
||||
unsigned int ch, // char
|
||||
unsigned char c, // color
|
||||
unsigned char m // mode
|
||||
)
|
||||
{
|
||||
unsigned char p,s;
|
||||
unsigned int cpos, cnt;
|
||||
|
||||
cpos = 0;
|
||||
|
||||
for(cnt=0; cnt<ch; cnt++)
|
||||
{
|
||||
if(cnt & 0x01)
|
||||
{
|
||||
cpos += (font_info[cnt>>1] & 0x0F);
|
||||
}
|
||||
else
|
||||
{
|
||||
cpos += (font_info[cnt>>1] >> 4);
|
||||
}
|
||||
}
|
||||
|
||||
p = font_info[ch>>1];
|
||||
if(ch & 0x01)
|
||||
{
|
||||
p &= 0x0F;
|
||||
}
|
||||
else
|
||||
{
|
||||
p >>= 4;
|
||||
}
|
||||
|
||||
if(ty & 0x07)
|
||||
{
|
||||
s = ty & 0x07;
|
||||
|
||||
for(cnt=0;cnt<p;cnt++)
|
||||
{
|
||||
if(c & 0x02)
|
||||
drawbuf[0][p-cnt-1] = font_bits[cpos+cnt] << s;
|
||||
else
|
||||
drawbuf[0][p-cnt-1] = 0x00;
|
||||
|
||||
if(c & 0x01)
|
||||
drawbuf[1][p-cnt-1] = font_bits[cpos+cnt] << s;
|
||||
else
|
||||
drawbuf[1][p-cnt-1] = 0x00;
|
||||
}
|
||||
do_rcu(tx,ty,p,m);
|
||||
|
||||
for(cnt=0;cnt<p;cnt++)
|
||||
{
|
||||
if(c & 0x02)
|
||||
drawbuf[0][p-cnt-1] = font_bits[cpos+cnt] >> (8-s);
|
||||
else
|
||||
drawbuf[0][p-cnt-1] = 0x00;
|
||||
|
||||
if(c & 0x01)
|
||||
drawbuf[1][p-cnt-1] = font_bits[cpos+cnt] >> (8-s);
|
||||
else
|
||||
drawbuf[1][p-cnt-1] = 0x00;
|
||||
}
|
||||
do_rcu(tx,ty+8,p,m);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(cnt=0;cnt<p;cnt++)
|
||||
{
|
||||
if(c & 0x02)
|
||||
drawbuf[0][p-cnt-1] = font_bits[cpos+cnt];
|
||||
else
|
||||
drawbuf[0][p-cnt-1] = 0x00;
|
||||
|
||||
if(c & 0x01)
|
||||
drawbuf[1][p-cnt-1] = font_bits[cpos+cnt];
|
||||
else
|
||||
drawbuf[1][p-cnt-1] = 0x00;
|
||||
}
|
||||
do_rcu(tx,ty,p,m);
|
||||
}
|
||||
tx += (p+1);
|
||||
}
|
||||
|
||||
void draw_char(unsigned char x, unsigned char y, unsigned char ch, unsigned char c, unsigned char m)
|
||||
{
|
||||
tx = x;
|
||||
ty = y;
|
||||
_draw_char(ch+coff, c, m);
|
||||
}
|
||||
|
||||
void draw_string(unsigned char x, unsigned char y, char *st, unsigned char c, unsigned char m)
|
||||
{
|
||||
unsigned char cp;
|
||||
tx = x;
|
||||
ty = y;
|
||||
|
||||
cp = 0;
|
||||
while(st[cp] != 0)
|
||||
{
|
||||
_draw_char(st[cp]+coff, c, m);
|
||||
cp++;
|
||||
}
|
||||
}
|
||||
|
||||
void draw_stringc(unsigned char x, unsigned char y, char *st, unsigned char cnt, unsigned char c, unsigned char m)
|
||||
{
|
||||
unsigned char cp,cx;
|
||||
cx = cnt;
|
||||
tx = x;
|
||||
ty = y;
|
||||
|
||||
cp = 0;
|
||||
while(cx--)
|
||||
{
|
||||
_draw_char(st[cp]+coff, c, m);
|
||||
cp++;
|
||||
}
|
||||
}
|
||||
|
||||
extern char hval[16];
|
||||
|
||||
void draw_hexC(unsigned char x, unsigned char y, const unsigned char v, unsigned char c, unsigned char m)
|
||||
{
|
||||
tx = x;
|
||||
ty = y;
|
||||
_draw_char(hval[v>>4]+coff, c, m);
|
||||
_draw_char(hval[v & 0x0F]+coff, c, m);
|
||||
}
|
||||
|
||||
void draw_hexS(unsigned char x, unsigned char y, const unsigned short v, unsigned char c, unsigned char m)
|
||||
{
|
||||
tx = x;
|
||||
ty = y;
|
||||
draw_hexC(x, y, v >> 8, c, m);
|
||||
draw_hexC(tx, ty, v & 0xFF, c, m);
|
||||
}
|
||||
|
||||
void draw_hexW(unsigned char x, unsigned char y, const unsigned long v, unsigned char c, unsigned char m)
|
||||
{
|
||||
draw_hexS(x, y, v >> 16, c, m);
|
||||
draw_hexS(tx, ty, v & 0xFFFF, c, m);
|
||||
}
|
14
lpctool/testing/flashtool/fonty.h
Normal file
14
lpctool/testing/flashtool/fonty.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#ifndef FONTY_H
|
||||
#define FONTY_H
|
||||
|
||||
extern unsigned char drawbuf[2][128];
|
||||
|
||||
void set_font(unsigned char f);
|
||||
void draw_char(unsigned char x, unsigned char y, unsigned char ch, unsigned char c, unsigned char m);
|
||||
void draw_string(unsigned char x, unsigned char y, char *st, unsigned char c, unsigned char m);
|
||||
void draw_stringc(unsigned char x, unsigned char y, char *st, unsigned char cnt, unsigned char c, unsigned char m);
|
||||
void draw_hexC(unsigned char x, unsigned char y, const unsigned char v, unsigned char c, unsigned char m);
|
||||
void draw_hexS(unsigned char x, unsigned char y, const unsigned short v, unsigned char c, unsigned char m);
|
||||
void draw_hexW(unsigned char x, unsigned char y, const unsigned long v, unsigned char c, unsigned char m);
|
||||
|
||||
#endif
|
43
lpctool/testing/flashtool/irq.c
Normal file
43
lpctool/testing/flashtool/irq.c
Normal file
|
@ -0,0 +1,43 @@
|
|||
#include "lpc2220.hh"
|
||||
#include "irq.h"
|
||||
|
||||
#define IRQ_MASK 0x00000080
|
||||
|
||||
static inline unsigned asm_get_cpsr(void)
|
||||
{
|
||||
unsigned long retval;
|
||||
asm volatile (" mrs %0, cpsr" : "=r" (retval) : /* no inputs */ );
|
||||
return retval;
|
||||
}
|
||||
|
||||
static inline void asm_set_cpsr(unsigned val)
|
||||
{
|
||||
asm volatile (" msr cpsr, %0" : /* no outputs */ : "r" (val) );
|
||||
}
|
||||
|
||||
unsigned enableIRQ(void)
|
||||
{
|
||||
unsigned _cpsr;
|
||||
|
||||
_cpsr = asm_get_cpsr();
|
||||
asm_set_cpsr(_cpsr & ~IRQ_MASK);
|
||||
return _cpsr;
|
||||
}
|
||||
|
||||
unsigned disableIRQ(void)
|
||||
{
|
||||
unsigned _cpsr;
|
||||
|
||||
_cpsr = asm_get_cpsr();
|
||||
asm_set_cpsr(_cpsr | IRQ_MASK);
|
||||
return _cpsr;
|
||||
}
|
||||
|
||||
unsigned restoreIRQ(unsigned oldCPSR)
|
||||
{
|
||||
unsigned _cpsr;
|
||||
|
||||
_cpsr = asm_get_cpsr();
|
||||
asm_set_cpsr((_cpsr & ~IRQ_MASK) | (oldCPSR & IRQ_MASK));
|
||||
return _cpsr;
|
||||
}
|
450
lpctool/testing/flashtool/lcd.c
Normal file
450
lpctool/testing/flashtool/lcd.c
Normal file
|
@ -0,0 +1,450 @@
|
|||
#include "lpc2220.h"
|
||||
#include "lcd.h"
|
||||
#include "fonty.h"
|
||||
//#include "b.h"
|
||||
|
||||
void pause(unsigned int ptime)
|
||||
{
|
||||
unsigned long xx;
|
||||
xx = ptime * 750;
|
||||
while(xx--)
|
||||
{};
|
||||
}
|
||||
|
||||
void clearStatus(void)
|
||||
{
|
||||
draw_block(0, 151, 128, 10, 3, DRAW_ERASE);
|
||||
timer++;
|
||||
}
|
||||
|
||||
void drawStatus(char *msg)
|
||||
{
|
||||
draw_block(0, 152, 128, 10, 3, DRAW_PUT);
|
||||
draw_string(1,152,">>",3,DRAW_XOR);
|
||||
draw_string(16,152,msg,3,DRAW_XOR);
|
||||
timer = 0;
|
||||
}
|
||||
|
||||
void lcd_fill(unsigned char f)
|
||||
{
|
||||
unsigned char x,y;
|
||||
for(y=0;y<20;y++)
|
||||
{
|
||||
LCD_CMD = 0xB0;
|
||||
LCD_CMD = y;
|
||||
LCD_CMD = 0x10;
|
||||
LCD_CMD = 0x00;
|
||||
for(x=0;x<128;x++)
|
||||
{
|
||||
LCD_DATA = f;
|
||||
LCD_DATA = f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void lcd_set(unsigned char s)
|
||||
{
|
||||
if(s == 0)
|
||||
{
|
||||
LCD_CMD = 0xA0; // set segment remap (00H mapped to seg0)
|
||||
LCD_CMD = 0xC8; // set com output scan direction (remapped mode)
|
||||
}
|
||||
else
|
||||
{
|
||||
LCD_CMD = 0xA1; // set segment remap (7FH mapped to seg0)
|
||||
LCD_CMD = 0xC0; // set com output scan direction (normal mode)
|
||||
}
|
||||
}
|
||||
|
||||
void lcd_init(unsigned char s)
|
||||
{
|
||||
LCD_CMD = 0xE1; // exit power save mode
|
||||
LCD_CMD = 0xE2; // software reset
|
||||
pause(0x64);
|
||||
LCD_CMD = 0xAB; // start internal oscillator
|
||||
LCD_CMD = 0x27; // set internal regulator resistor ratio (8.1)
|
||||
LCD_CMD = 0x81; // volume cmd
|
||||
LCD_CMD = 0x3B; // volume cmd value
|
||||
LCD_CMD = 0x65; // set DC-DC converter factor (4x)
|
||||
LCD_CMD = 0x60; // set upper window corner ax cmd
|
||||
LCD_CMD = 0x1C; // set upper window corner ax value
|
||||
LCD_CMD = 0x61; // set upper window corner ay cmd
|
||||
LCD_CMD = 0x0A; // set upper window corner ay value
|
||||
LCD_CMD = 0x62; // set lower window corner bx cmd
|
||||
LCD_CMD = 0x75; // set lower window corner bx value
|
||||
LCD_CMD = 0x63; // set lower window corner by cmd
|
||||
LCD_CMD = 0x81; // set lower window corner by value
|
||||
LCD_CMD = 0x90; // set PWM and FRC (4-frames)
|
||||
LCD_CMD = 0x88; // set white mode frame 2nd and 1st cmd
|
||||
LCD_CMD = 0x00; // set white mode frame 2nd and 1st value
|
||||
LCD_CMD = 0x89; // set white mode frame 4th and 3rd cmd
|
||||
LCD_CMD = 0x00; // set white mode frame 4th and 3rd value
|
||||
LCD_CMD = 0x8A; // set light gray mode frame 2nd and 1st cmd
|
||||
LCD_CMD = 0x55; // set light gray mode frame 2nd and 1st value
|
||||
LCD_CMD = 0x8B; // set light gray mode frame 4th and 3rd cmd
|
||||
LCD_CMD = 0x55; // set light gray mode frame 4th and 3rd vakue
|
||||
LCD_CMD = 0x8C; // set dark gray mode frame 2nd and 1st cmd
|
||||
LCD_CMD = 0x66; // set dark gray mode frame 2nd and 1st value
|
||||
LCD_CMD = 0x8D; // set dark gray mode frame 4th and 3rd cmd
|
||||
LCD_CMD = 0x66; // set dark gray mode frame 4th and 3rd vakue
|
||||
LCD_CMD = 0x8E; // set black mode frame 2nd and 1st cmd
|
||||
LCD_CMD = 0xAA; // set black mode frame 2nd and 1st value
|
||||
LCD_CMD = 0x8F; // set black mode frame 4th and 3rd cmd
|
||||
LCD_CMD = 0xAA; // set black mode frame 4th and 3rd value
|
||||
|
||||
lcd_set(s);
|
||||
|
||||
LCD_CMD = 0x2E; // set power control register (boost on, reg on, buffer off)
|
||||
|
||||
pause(0x64);
|
||||
|
||||
LCD_CMD = 0x2F; // set power control register (boost on, reg on, buffer on)
|
||||
LCD_CMD = 0xA4; // set entire display on, normal mode)
|
||||
LCD_CMD = 0xA6; // set normal display mode, inverse = 0xA7
|
||||
|
||||
|
||||
lcd_fill(0x00);
|
||||
|
||||
LCD_CMD = 0xAF;
|
||||
|
||||
set_font(0);
|
||||
}
|
||||
|
||||
void lcd_enable(unsigned char e)
|
||||
{
|
||||
if(e)
|
||||
{
|
||||
LCD_CMD = 0xAF; // set display on
|
||||
}
|
||||
else
|
||||
{
|
||||
LCD_CMD = 0xAE; // set display off
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
unsigned char rcubuf[2][128];
|
||||
unsigned char drawbuf[2][128];
|
||||
|
||||
void do_rcu(unsigned char x, unsigned char y, unsigned char l, unsigned char m)
|
||||
{
|
||||
unsigned char q;
|
||||
|
||||
LCD_CMD = 0xB0;
|
||||
LCD_CMD = (y >> 3);
|
||||
LCD_CMD = (0x10 + (x >> 4));
|
||||
LCD_CMD = (x & 0x0F);
|
||||
|
||||
q = LCD_DATA;
|
||||
q = l;
|
||||
|
||||
while(q--)
|
||||
{
|
||||
rcubuf[0][q] = LCD_DATA;
|
||||
rcubuf[1][q] = LCD_DATA;
|
||||
}
|
||||
|
||||
q = LCD_DATA;
|
||||
|
||||
LCD_CMD = 0xB0;
|
||||
LCD_CMD = (y >> 3);
|
||||
LCD_CMD = (0x10 + (x >> 4));
|
||||
LCD_CMD = (x & 0x0F);
|
||||
|
||||
q = l;
|
||||
|
||||
switch(m)
|
||||
{
|
||||
case DRAW_PUT: // draw put
|
||||
while(q--)
|
||||
{
|
||||
LCD_DATA = rcubuf[0][q] | drawbuf[0][q];
|
||||
LCD_DATA = rcubuf[1][q] | drawbuf[1][q];
|
||||
}
|
||||
break;
|
||||
case DRAW_XOR: // draw xor
|
||||
while(q--)
|
||||
{
|
||||
LCD_DATA = rcubuf[0][q] ^ drawbuf[0][q];
|
||||
LCD_DATA = rcubuf[1][q] ^ drawbuf[1][q];
|
||||
}
|
||||
break;
|
||||
case DRAW_ERASE: // draw erase
|
||||
while(q--)
|
||||
{
|
||||
LCD_DATA = rcubuf[0][q] & ~drawbuf[0][q];
|
||||
LCD_DATA = rcubuf[1][q] & ~drawbuf[1][q];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void do_rcuS(unsigned char x, unsigned char y, unsigned char m)
|
||||
{
|
||||
unsigned char q;
|
||||
|
||||
LCD_CMD = 0xB0;
|
||||
LCD_CMD = (y >> 3);
|
||||
LCD_CMD = (0x10 + (x >> 4));
|
||||
LCD_CMD = (x & 0x0F);
|
||||
|
||||
q = LCD_DATA;
|
||||
rcubuf[0][0] = LCD_DATA;
|
||||
rcubuf[1][0] = LCD_DATA;
|
||||
|
||||
q = LCD_DATA;
|
||||
|
||||
LCD_CMD = 0xB0;
|
||||
LCD_CMD = (y >> 3);
|
||||
LCD_CMD = (0x10 + (x >> 4));
|
||||
LCD_CMD = (x & 0x0F);
|
||||
|
||||
switch(m)
|
||||
{
|
||||
case 0: // draw put
|
||||
LCD_DATA = rcubuf[0][0] | drawbuf[0][0];
|
||||
LCD_DATA = rcubuf[1][0] | drawbuf[1][0];
|
||||
break;
|
||||
case 1: // draw xor
|
||||
LCD_DATA = rcubuf[0][0] ^ drawbuf[0][0];
|
||||
LCD_DATA = rcubuf[1][0] ^ drawbuf[1][0];
|
||||
break;
|
||||
case 2: // draw erase
|
||||
LCD_DATA = rcubuf[0][0] & ~drawbuf[0][0];
|
||||
LCD_DATA = rcubuf[1][0] & ~drawbuf[1][0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void draw_block(unsigned char x, unsigned char y, unsigned char w, unsigned char h, unsigned char c, unsigned char m)
|
||||
{
|
||||
unsigned char q,s;
|
||||
unsigned char yy,ss,vv,ww,xx;
|
||||
unsigned char segm;
|
||||
|
||||
s = y;
|
||||
|
||||
if(h)
|
||||
{
|
||||
|
||||
|
||||
|
||||
yy = h;
|
||||
ss = y >> 3;
|
||||
vv = y & 0x07;
|
||||
|
||||
ww = yy & 0x07;
|
||||
|
||||
segm = 0xFF;
|
||||
|
||||
xx = 8;
|
||||
if(yy < 8)
|
||||
{
|
||||
segm >>= (8-ww);
|
||||
xx -= (8-ww);
|
||||
if(vv > (8-xx))
|
||||
{
|
||||
xx = yy -(vv-(8-xx));
|
||||
}
|
||||
else
|
||||
{
|
||||
xx = yy;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
xx -= vv;
|
||||
}
|
||||
|
||||
segm <<= vv;
|
||||
|
||||
q = w;
|
||||
while(q--)
|
||||
{
|
||||
if(c & 0x02)
|
||||
drawbuf[0][q] = segm;
|
||||
else
|
||||
drawbuf[0][q] = 0;
|
||||
|
||||
if(c & 0x01)
|
||||
drawbuf[1][q] = segm;
|
||||
else
|
||||
drawbuf[1][q] = 0;
|
||||
}
|
||||
do_rcu(x,s,w,m);
|
||||
|
||||
yy -= xx;
|
||||
|
||||
while(yy > 8)
|
||||
{
|
||||
s += 8;
|
||||
yy -= 8;
|
||||
q = w;
|
||||
while(q--)
|
||||
{
|
||||
if(c & 0x02)
|
||||
drawbuf[0][q] = 0xFF;
|
||||
else
|
||||
drawbuf[0][q] = 0;
|
||||
|
||||
if(c & 0x01)
|
||||
drawbuf[1][q] = 0xFF;
|
||||
else
|
||||
drawbuf[1][q] = 0;
|
||||
}
|
||||
do_rcu(x,s,w,m);
|
||||
}
|
||||
|
||||
if(yy)
|
||||
{
|
||||
s += 8;
|
||||
q = w;
|
||||
while(q--)
|
||||
{
|
||||
if(c & 0x02)
|
||||
drawbuf[0][q] = 0xFF >> (8-yy);
|
||||
else
|
||||
drawbuf[0][q] = 0;
|
||||
|
||||
if(c & 0x01)
|
||||
drawbuf[1][q] = 0xFF >> (8-yy);
|
||||
else
|
||||
drawbuf[1][q] = 0;
|
||||
}
|
||||
do_rcu(x,s,w,m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw_hline(unsigned char x, unsigned char y, unsigned char l, unsigned char c, unsigned char m)
|
||||
{
|
||||
unsigned char p,q;
|
||||
|
||||
q = l;
|
||||
p = 0x01 << (y & 0x07);
|
||||
|
||||
while(q--)
|
||||
{
|
||||
if(c & 0x02)
|
||||
drawbuf[0][q] = p;
|
||||
else
|
||||
drawbuf[0][q] = 0;
|
||||
|
||||
if(c & 0x01)
|
||||
drawbuf[1][q] = p;
|
||||
else
|
||||
drawbuf[1][q] = 0;
|
||||
}
|
||||
do_rcu(x,y,l,m);
|
||||
}
|
||||
|
||||
void draw_vline(unsigned char x, unsigned char y, unsigned char l, unsigned char c, unsigned char m)
|
||||
{
|
||||
unsigned char s;
|
||||
unsigned char yy,ss,vv,ww,xx;
|
||||
unsigned char segm;
|
||||
|
||||
s = y;
|
||||
|
||||
if(l)
|
||||
{
|
||||
|
||||
|
||||
|
||||
yy = l;
|
||||
ss = y >> 3;
|
||||
vv = y & 0x07;
|
||||
|
||||
ww = yy & 0x07;
|
||||
|
||||
segm = 0xFF;
|
||||
|
||||
xx = 8;
|
||||
if(yy < 8)
|
||||
{
|
||||
segm >>= (8-ww);
|
||||
xx -= (8-ww);
|
||||
if(vv > (8-xx))
|
||||
{
|
||||
xx = yy -(vv-(8-xx));
|
||||
}
|
||||
else
|
||||
{
|
||||
xx = yy;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
xx -= vv;
|
||||
}
|
||||
|
||||
segm <<= vv;
|
||||
|
||||
if(c & 0x02)
|
||||
drawbuf[0][0] = segm;
|
||||
else
|
||||
drawbuf[0][0] = 0;
|
||||
|
||||
if(c & 0x01)
|
||||
drawbuf[1][0] = segm;
|
||||
else
|
||||
drawbuf[1][0] = 0;
|
||||
|
||||
do_rcuS(x,s,m);
|
||||
|
||||
yy -= xx;
|
||||
|
||||
while(yy > 8)
|
||||
{
|
||||
s += 8;
|
||||
yy -= 8;
|
||||
if(c & 0x02)
|
||||
drawbuf[0][0] = 0xFF;
|
||||
else
|
||||
drawbuf[0][0] = 0;
|
||||
|
||||
if(c & 0x01)
|
||||
drawbuf[1][0] = 0xFF;
|
||||
else
|
||||
drawbuf[1][0] = 0;
|
||||
do_rcuS(x,s,m);
|
||||
}
|
||||
|
||||
if(yy)
|
||||
{
|
||||
s += 8;
|
||||
if(c & 0x02)
|
||||
drawbuf[0][0] = 0xFF >> (8-yy);
|
||||
else
|
||||
drawbuf[0][0] = 0;
|
||||
|
||||
if(c & 0x01)
|
||||
drawbuf[1][0] = 0xFF >> (8-yy);
|
||||
else
|
||||
drawbuf[1][0] = 0;
|
||||
do_rcuS(x,s,m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw_rect(unsigned char x, unsigned char y, unsigned char w, unsigned char h, unsigned char lw, unsigned char c, unsigned char m)
|
||||
{
|
||||
if(lw)
|
||||
{
|
||||
if(lw == 1)
|
||||
{
|
||||
draw_hline(x, y, w, c, m);
|
||||
draw_hline(x, y+h-1, w, c, m);
|
||||
|
||||
draw_vline(x, y+1, h-2, c, m);
|
||||
draw_vline(x+w-1, y+1, h-2, c, m);
|
||||
}
|
||||
else
|
||||
{
|
||||
draw_block(x, y, w, lw, c, m);
|
||||
draw_block(x, y+h-lw, w, lw, c, m);
|
||||
draw_block(x, y+lw, lw, h-(2*lw), c, m);
|
||||
draw_block(x+w-lw, y+lw, lw, h-(2*lw), c, m);
|
||||
}
|
||||
}
|
||||
}
|
42
lpctool/testing/flashtool/lcd.h
Normal file
42
lpctool/testing/flashtool/lcd.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
#ifndef LCD_H
|
||||
#define LCD_H
|
||||
|
||||
// the lcd data & command ports
|
||||
#define LCD_CMD (*((volatile unsigned char *) 0x81000000))
|
||||
#define LCD_DATA (*((volatile unsigned char *) 0x81000001))
|
||||
|
||||
// drawmodes
|
||||
#define DRAW_PUT 0
|
||||
#define DRAW_XOR 1
|
||||
#define DRAW_ERASE 2
|
||||
#define DRAW_RAW 10
|
||||
#define DRAW_RAW_INV 11
|
||||
|
||||
#define TIMEOUT 0x00400000
|
||||
|
||||
struct t_bitmap
|
||||
{
|
||||
unsigned char width;
|
||||
unsigned char height;
|
||||
unsigned char mode;
|
||||
unsigned char *data;
|
||||
} ;
|
||||
|
||||
extern unsigned long timer;
|
||||
|
||||
struct t_bitmap bitmap;
|
||||
|
||||
void lcd_init(unsigned char s);
|
||||
void lcd_enable(unsigned char e);
|
||||
|
||||
void do_rcu(unsigned char x, unsigned char y, unsigned char l, unsigned char m);
|
||||
|
||||
void lcd_fill(unsigned char f);
|
||||
void draw_block(unsigned char x, unsigned char y, unsigned char w, unsigned char h, unsigned char c, unsigned char m);
|
||||
void draw_hline(unsigned char x, unsigned char y, unsigned char l, unsigned char c, unsigned char m);
|
||||
void draw_vline(unsigned char x, unsigned char y, unsigned char l, unsigned char c, unsigned char m);
|
||||
void draw_rect(unsigned char x, unsigned char y, unsigned char w, unsigned char h, unsigned char lw, unsigned char c, unsigned char m);
|
||||
void clearStatus(void);
|
||||
void drawStatus(char *msg);
|
||||
|
||||
#endif
|
261
lpctool/testing/flashtool/lpc2220.h
Normal file
261
lpctool/testing/flashtool/lpc2220.h
Normal file
|
@ -0,0 +1,261 @@
|
|||
/********************************************************/
|
||||
/* */
|
||||
/* philips */
|
||||
/* lpc2220 */
|
||||
/* */
|
||||
/********************************************************/
|
||||
#ifndef LPC2220_H
|
||||
#define LPC2220_H
|
||||
|
||||
/* External Memory Controller (EMC) */
|
||||
#define BCFG0 (*((volatile unsigned long *) 0xFFE00000))
|
||||
#define BCFG1 (*((volatile unsigned long *) 0xFFE00004))
|
||||
#define BCFG2 (*((volatile unsigned long *) 0xFFE00008))
|
||||
#define BCFG3 (*((volatile unsigned long *) 0xFFE0000C))
|
||||
|
||||
/* Vectored Interrupt Controller (VIC) */
|
||||
#define VICIRQStatus (*((volatile unsigned long *) 0xFFFFF000))
|
||||
#define VICFIQStatus (*((volatile unsigned long *) 0xFFFFF004))
|
||||
#define VICRawIntr (*((volatile unsigned long *) 0xFFFFF008))
|
||||
#define VICIntSelect (*((volatile unsigned long *) 0xFFFFF00C))
|
||||
#define VICIntEnable (*((volatile unsigned long *) 0xFFFFF010))
|
||||
#define VICIntEnClr (*((volatile unsigned long *) 0xFFFFF014))
|
||||
#define VICSoftInt (*((volatile unsigned long *) 0xFFFFF018))
|
||||
#define VICSoftIntClr (*((volatile unsigned long *) 0xFFFFF01C))
|
||||
#define VICProtection (*((volatile unsigned long *) 0xFFFFF020))
|
||||
#define VICVectAddr (*((volatile unsigned long *) 0xFFFFF030))
|
||||
#define VICDefVectAddr (*((volatile unsigned long *) 0xFFFFF034))
|
||||
#define VICVectAddr0 (*((volatile unsigned long *) 0xFFFFF100))
|
||||
#define VICVectAddr1 (*((volatile unsigned long *) 0xFFFFF104))
|
||||
#define VICVectAddr2 (*((volatile unsigned long *) 0xFFFFF108))
|
||||
#define VICVectAddr3 (*((volatile unsigned long *) 0xFFFFF10C))
|
||||
#define VICVectAddr4 (*((volatile unsigned long *) 0xFFFFF110))
|
||||
#define VICVectAddr5 (*((volatile unsigned long *) 0xFFFFF114))
|
||||
#define VICVectAddr6 (*((volatile unsigned long *) 0xFFFFF118))
|
||||
#define VICVectAddr7 (*((volatile unsigned long *) 0xFFFFF11C))
|
||||
#define VICVectAddr8 (*((volatile unsigned long *) 0xFFFFF120))
|
||||
#define VICVectAddr9 (*((volatile unsigned long *) 0xFFFFF124))
|
||||
#define VICVectAddr10 (*((volatile unsigned long *) 0xFFFFF128))
|
||||
#define VICVectAddr11 (*((volatile unsigned long *) 0xFFFFF12C))
|
||||
#define VICVectAddr12 (*((volatile unsigned long *) 0xFFFFF130))
|
||||
#define VICVectAddr13 (*((volatile unsigned long *) 0xFFFFF134))
|
||||
#define VICVectAddr14 (*((volatile unsigned long *) 0xFFFFF138))
|
||||
#define VICVectAddr15 (*((volatile unsigned long *) 0xFFFFF13C))
|
||||
#define VICVectCntl0 (*((volatile unsigned long *) 0xFFFFF200))
|
||||
#define VICVectCntl1 (*((volatile unsigned long *) 0xFFFFF204))
|
||||
#define VICVectCntl2 (*((volatile unsigned long *) 0xFFFFF208))
|
||||
#define VICVectCntl3 (*((volatile unsigned long *) 0xFFFFF20C))
|
||||
#define VICVectCntl4 (*((volatile unsigned long *) 0xFFFFF210))
|
||||
#define VICVectCntl5 (*((volatile unsigned long *) 0xFFFFF214))
|
||||
#define VICVectCntl6 (*((volatile unsigned long *) 0xFFFFF218))
|
||||
#define VICVectCntl7 (*((volatile unsigned long *) 0xFFFFF21C))
|
||||
#define VICVectCntl8 (*((volatile unsigned long *) 0xFFFFF220))
|
||||
#define VICVectCntl9 (*((volatile unsigned long *) 0xFFFFF224))
|
||||
#define VICVectCntl10 (*((volatile unsigned long *) 0xFFFFF228))
|
||||
#define VICVectCntl11 (*((volatile unsigned long *) 0xFFFFF22C))
|
||||
#define VICVectCntl12 (*((volatile unsigned long *) 0xFFFFF230))
|
||||
#define VICVectCntl13 (*((volatile unsigned long *) 0xFFFFF234))
|
||||
#define VICVectCntl14 (*((volatile unsigned long *) 0xFFFFF238))
|
||||
#define VICVectCntl15 (*((volatile unsigned long *) 0xFFFFF23C))
|
||||
|
||||
/* Pin Connect Block */
|
||||
#define PINSEL0 (*((volatile unsigned long *) 0xE002C000))
|
||||
#define PINSEL1 (*((volatile unsigned long *) 0xE002C004))
|
||||
#define PINSEL2 (*((volatile unsigned long *) 0xE002C014))
|
||||
|
||||
/* General Purpose Input/Output (GPIO) */
|
||||
#define IOPIN0 (*((volatile unsigned long *) 0xE0028000))
|
||||
#define IOSET0 (*((volatile unsigned long *) 0xE0028004))
|
||||
#define IODIR0 (*((volatile unsigned long *) 0xE0028008))
|
||||
#define IOCLR0 (*((volatile unsigned long *) 0xE002800C))
|
||||
#define IOPIN1 (*((volatile unsigned long *) 0xE0028010))
|
||||
#define IOSET1 (*((volatile unsigned long *) 0xE0028014))
|
||||
#define IODIR1 (*((volatile unsigned long *) 0xE0028018))
|
||||
#define IOCLR1 (*((volatile unsigned long *) 0xE002801C))
|
||||
#define IOPIN2 (*((volatile unsigned long *) 0xE0028020))
|
||||
#define IOSET2 (*((volatile unsigned long *) 0xE0028024))
|
||||
#define IODIR2 (*((volatile unsigned long *) 0xE0028028))
|
||||
#define IOCLR2 (*((volatile unsigned long *) 0xE002802C))
|
||||
#define IOPIN3 (*((volatile unsigned long *) 0xE0028030))
|
||||
#define IOSET3 (*((volatile unsigned long *) 0xE0028034))
|
||||
#define IODIR3 (*((volatile unsigned long *) 0xE0028038))
|
||||
#define IOCLR3 (*((volatile unsigned long *) 0xE002803C))
|
||||
|
||||
/* Phase Locked Loop (PLL) */
|
||||
#define PLLCON (*((volatile unsigned char *) 0xE01FC080))
|
||||
#define PLLCFG (*((volatile unsigned char *) 0xE01FC084))
|
||||
#define PLLSTAT (*((volatile unsigned short*) 0xE01FC088))
|
||||
#define PLLFEED (*((volatile unsigned char *) 0xE01FC08C))
|
||||
|
||||
/* VPB Divider */
|
||||
#define VPBDIV (*((volatile unsigned char *) 0xE01FC100))
|
||||
|
||||
/* Power Control */
|
||||
#define PCON (*((volatile unsigned char *) 0xE01FC0C0))
|
||||
#define PCONP (*((volatile unsigned long *) 0xE01FC0C4))
|
||||
|
||||
/* External Interrupts */
|
||||
#define EXTINT (*((volatile unsigned char *) 0xE01FC140))
|
||||
#define EXTWAKE (*((volatile unsigned char *) 0xE01FC144))
|
||||
#define EXTMODE (*((volatile unsigned char *) 0xE01FC148))
|
||||
#define EXTPOLAR (*((volatile unsigned char *) 0xE01FC14C))
|
||||
|
||||
/* Timer 0 */
|
||||
#define T0IR (*((volatile unsigned long *) 0xE0004000))
|
||||
#define T0TCR (*((volatile unsigned long *) 0xE0004004))
|
||||
#define T0TC (*((volatile unsigned long *) 0xE0004008))
|
||||
#define T0PR (*((volatile unsigned long *) 0xE000400C))
|
||||
#define T0PC (*((volatile unsigned long *) 0xE0004010))
|
||||
#define T0MCR (*((volatile unsigned long *) 0xE0004014))
|
||||
#define T0MR0 (*((volatile unsigned long *) 0xE0004018))
|
||||
#define T0MR1 (*((volatile unsigned long *) 0xE000401C))
|
||||
#define T0MR2 (*((volatile unsigned long *) 0xE0004020))
|
||||
#define T0MR3 (*((volatile unsigned long *) 0xE0004024))
|
||||
#define T0CCR (*((volatile unsigned long *) 0xE0004028))
|
||||
#define T0CR0 (*((volatile unsigned long *) 0xE000402C))
|
||||
#define T0CR1 (*((volatile unsigned long *) 0xE0004030))
|
||||
#define T0CR2 (*((volatile unsigned long *) 0xE0004034))
|
||||
#define T0CR3 (*((volatile unsigned long *) 0xE0004038))
|
||||
#define T0EMR (*((volatile unsigned long *) 0xE000403C))
|
||||
|
||||
/* Timer 1 */
|
||||
#define T1IR (*((volatile unsigned long *) 0xE0008000))
|
||||
#define T1TCR (*((volatile unsigned long *) 0xE0008004))
|
||||
#define T1TC (*((volatile unsigned long *) 0xE0008008))
|
||||
#define T1PR (*((volatile unsigned long *) 0xE000800C))
|
||||
#define T1PC (*((volatile unsigned long *) 0xE0008010))
|
||||
#define T1MCR (*((volatile unsigned long *) 0xE0008014))
|
||||
#define T1MR0 (*((volatile unsigned long *) 0xE0008018))
|
||||
#define T1MR1 (*((volatile unsigned long *) 0xE000801C))
|
||||
#define T1MR2 (*((volatile unsigned long *) 0xE0008020))
|
||||
#define T1MR3 (*((volatile unsigned long *) 0xE0008024))
|
||||
#define T1CCR (*((volatile unsigned long *) 0xE0008028))
|
||||
#define T1CR0 (*((volatile unsigned long *) 0xE000802C))
|
||||
#define T1CR1 (*((volatile unsigned long *) 0xE0008030))
|
||||
#define T1CR2 (*((volatile unsigned long *) 0xE0008034))
|
||||
#define T1CR3 (*((volatile unsigned long *) 0xE0008038))
|
||||
#define T1EMR (*((volatile unsigned long *) 0xE000803C))
|
||||
|
||||
/* Pulse Width Modulator (PWM) */
|
||||
#define PWMIR (*((volatile unsigned long *) 0xE0014000))
|
||||
#define PWMTCR (*((volatile unsigned long *) 0xE0014004))
|
||||
#define PWMTC (*((volatile unsigned long *) 0xE0014008))
|
||||
#define PWMPR (*((volatile unsigned long *) 0xE001400C))
|
||||
#define PWMPC (*((volatile unsigned long *) 0xE0014010))
|
||||
#define PWMMCR (*((volatile unsigned long *) 0xE0014014))
|
||||
#define PWMMR0 (*((volatile unsigned long *) 0xE0014018))
|
||||
#define PWMMR1 (*((volatile unsigned long *) 0xE001401C))
|
||||
#define PWMMR2 (*((volatile unsigned long *) 0xE0014020))
|
||||
#define PWMMR3 (*((volatile unsigned long *) 0xE0014024))
|
||||
#define PWMMR4 (*((volatile unsigned long *) 0xE0014040))
|
||||
#define PWMMR5 (*((volatile unsigned long *) 0xE0014044))
|
||||
#define PWMMR6 (*((volatile unsigned long *) 0xE0014048))
|
||||
#define PWMCCR (*((volatile unsigned long *) 0xE0014028))
|
||||
#define PWMCR0 (*((volatile unsigned long *) 0xE001402C))
|
||||
#define PWMCR1 (*((volatile unsigned long *) 0xE0014030))
|
||||
#define PWMCR2 (*((volatile unsigned long *) 0xE0014034))
|
||||
#define PWMCR3 (*((volatile unsigned long *) 0xE0014038))
|
||||
#define PWMEMR (*((volatile unsigned long *) 0xE001403C))
|
||||
#define PWMPCR (*((volatile unsigned long *) 0xE001404C))
|
||||
#define PWMLER (*((volatile unsigned long *) 0xE0014050))
|
||||
|
||||
/* Universal Asynchronous Receiver Transmitter 0 (UART0) */
|
||||
#define U0RBR (*((volatile unsigned char *) 0xE000C000))
|
||||
#define U0THR (*((volatile unsigned char *) 0xE000C000))
|
||||
#define U0IER (*((volatile unsigned char *) 0xE000C004))
|
||||
#define U0IIR (*((volatile unsigned char *) 0xE000C008))
|
||||
#define U0FCR (*((volatile unsigned char *) 0xE000C008))
|
||||
#define U0LCR (*((volatile unsigned char *) 0xE000C00C))
|
||||
#define U0MCR (*((volatile unsigned char *) 0xE000C010))
|
||||
#define U0LSR (*((volatile unsigned char *) 0xE000C014))
|
||||
#define U0MSR (*((volatile unsigned char *) 0xE000C018))
|
||||
#define U0SCR (*((volatile unsigned char *) 0xE000C01C))
|
||||
#define U0FDR (*((volatile unsigned char *) 0xE000C028))
|
||||
#define U0DLL (*((volatile unsigned char *) 0xE000C000))
|
||||
#define U0DLM (*((volatile unsigned char *) 0xE000C004))
|
||||
|
||||
/* Universal Asynchronous Receiver Transmitter 1 (UART1) */
|
||||
#define U1RBR (*((volatile unsigned char *) 0xE0010000))
|
||||
#define U1THR (*((volatile unsigned char *) 0xE0010000))
|
||||
#define U1IER (*((volatile unsigned char *) 0xE0010004))
|
||||
#define U1IIR (*((volatile unsigned char *) 0xE0010008))
|
||||
#define U1FCR (*((volatile unsigned char *) 0xE0010008))
|
||||
#define U1LCR (*((volatile unsigned char *) 0xE001000C))
|
||||
#define U1MCR (*((volatile unsigned char *) 0xE0010010))
|
||||
#define U1LSR (*((volatile unsigned char *) 0xE0010014))
|
||||
#define U1MSR (*((volatile unsigned char *) 0xE0010018))
|
||||
#define U1SCR (*((volatile unsigned char *) 0xE001001C))
|
||||
#define U1DLL (*((volatile unsigned char *) 0xE0010000))
|
||||
#define U1DLM (*((volatile unsigned char *) 0xE0010004))
|
||||
|
||||
/* I2C Interface */
|
||||
#define I2CONSET (*((volatile unsigned char *) 0xE001C000))
|
||||
#define I2STAT (*((volatile unsigned char *) 0xE001C004))
|
||||
#define I2DAT (*((volatile unsigned char *) 0xE001C008))
|
||||
#define I2ADR (*((volatile unsigned char *) 0xE001C00C))
|
||||
#define I2SCLH (*((volatile unsigned short*) 0xE001C010))
|
||||
#define I2SCLL (*((volatile unsigned short*) 0xE001C014))
|
||||
#define I2CONCLR (*((volatile unsigned char *) 0xE001C018))
|
||||
|
||||
/* SPI0 (Serial Peripheral Interface 0) */
|
||||
#define S0SPCR (*((volatile unsigned char *) 0xE0020000))
|
||||
#define S0SPSR (*((volatile unsigned char *) 0xE0020004))
|
||||
#define S0SPDR (*((volatile unsigned char *) 0xE0020008))
|
||||
#define S0SPCCR (*((volatile unsigned char *) 0xE002000C))
|
||||
#define S0SPTCR (*((volatile unsigned char *) 0xE0020010))
|
||||
#define S0SPTSR (*((volatile unsigned char *) 0xE0020014))
|
||||
#define S0SPTOR (*((volatile unsigned char *) 0xE0020018))
|
||||
#define S0SPINT (*((volatile unsigned char *) 0xE002001C))
|
||||
|
||||
/* SPI1 (Serial Peripheral Interface 1) */
|
||||
#define S1SPCR (*((volatile unsigned char *) 0xE0030000))
|
||||
#define S1SPSR (*((volatile unsigned char *) 0xE0030004))
|
||||
#define S1SPDR (*((volatile unsigned char *) 0xE0030008))
|
||||
#define S1SPCCR (*((volatile unsigned char *) 0xE003000C))
|
||||
#define S1SPTCR (*((volatile unsigned char *) 0xE0030010))
|
||||
#define S1SPTSR (*((volatile unsigned char *) 0xE0030014))
|
||||
#define S1SPTOR (*((volatile unsigned char *) 0xE0030018))
|
||||
#define S1SPINT (*((volatile unsigned char *) 0xE003001C))
|
||||
|
||||
/* Real Time Clock */
|
||||
#define ILR (*((volatile unsigned char *) 0xE0024000))
|
||||
#define CTC (*((volatile unsigned short*) 0xE0024004))
|
||||
#define CCR (*((volatile unsigned char *) 0xE0024008))
|
||||
#define CIIR (*((volatile unsigned char *) 0xE002400C))
|
||||
#define AMR (*((volatile unsigned char *) 0xE0024010))
|
||||
#define CTIME0 (*((volatile unsigned long *) 0xE0024014))
|
||||
#define CTIME1 (*((volatile unsigned long *) 0xE0024018))
|
||||
#define CTIME2 (*((volatile unsigned long *) 0xE002401C))
|
||||
#define SEC (*((volatile unsigned char *) 0xE0024020))
|
||||
#define MIN (*((volatile unsigned char *) 0xE0024024))
|
||||
#define HOUR (*((volatile unsigned char *) 0xE0024028))
|
||||
#define DOM (*((volatile unsigned char *) 0xE002402C))
|
||||
#define DOW (*((volatile unsigned char *) 0xE0024030))
|
||||
#define DOY (*((volatile unsigned short*) 0xE0024034))
|
||||
#define MONTH (*((volatile unsigned char *) 0xE0024038))
|
||||
#define YEAR (*((volatile unsigned short*) 0xE002403C))
|
||||
#define ALSEC (*((volatile unsigned char *) 0xE0024060))
|
||||
#define ALMIN (*((volatile unsigned char *) 0xE0024064))
|
||||
#define ALHOUR (*((volatile unsigned char *) 0xE0024068))
|
||||
#define ALDOM (*((volatile unsigned char *) 0xE002406C))
|
||||
#define ALDOW (*((volatile unsigned char *) 0xE0024070))
|
||||
#define ALDOY (*((volatile unsigned short*) 0xE0024074))
|
||||
#define ALMON (*((volatile unsigned char *) 0xE0024078))
|
||||
#define ALYEAR (*((volatile unsigned short*) 0xE002407C))
|
||||
#define PREINT (*((volatile unsigned short*) 0xE0024080))
|
||||
#define PREFRAC (*((volatile unsigned short*) 0xE0024084))
|
||||
|
||||
/* A/D Converter */
|
||||
#define ADCR (*((volatile unsigned long *) 0xE0034000))
|
||||
#define ADDR (*((volatile unsigned long *) 0xE0034004))
|
||||
|
||||
/* Watchdog */
|
||||
#define WDMOD (*((volatile unsigned char *) 0xE0000000))
|
||||
#define WDTC (*((volatile unsigned long *) 0xE0000004))
|
||||
#define WDFEED (*((volatile unsigned char *) 0xE0000008))
|
||||
#define WDTV (*((volatile unsigned long *) 0xE000000C))
|
||||
|
||||
/* Memory Mapping control register */
|
||||
#define MEMMAP (*((volatile unsigned long *) 0xE01FC040))
|
||||
|
||||
#endif /* __ASM_ARCH_HARDWARE_H */
|
60
lpctool/testing/flashtool/lpc2220.ld
Normal file
60
lpctool/testing/flashtool/lpc2220.ld
Normal file
|
@ -0,0 +1,60 @@
|
|||
/* identify the Entry Point */
|
||||
|
||||
ENTRY(Reset_Handler)
|
||||
|
||||
/* specify the LPC2106 memory areas */
|
||||
|
||||
MEMORY
|
||||
{
|
||||
flash : ORIGIN = 0x00000000, LENGTH = 128K /* free FLASH EPROM area */
|
||||
ram : ORIGIN = 0x40000200, LENGTH = 64K - 0x200 /* free RAM area */
|
||||
}
|
||||
|
||||
/* define a global symbol _stack_end */
|
||||
|
||||
_stack_end = 0x4000FEDC;
|
||||
|
||||
/* now define the output sections */
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
startup :
|
||||
{
|
||||
*(.startup)
|
||||
} >ram /* the startup code goes into FLASH */
|
||||
|
||||
.text : /* collect all sections that should go into FLASH after startup */
|
||||
{
|
||||
*(.text) /* all .text sections (code) */
|
||||
*(.rodata) /* all .rodata sections (constants, strings, etc.) */
|
||||
*(.rodata*) /* all .rodata* sections (constants, strings, etc.) */
|
||||
*(.glue_7) /* all .glue_7 sections (no idea what these are) */
|
||||
*(.glue_7t) /* all .glue_7t sections (no idea what these are) */
|
||||
_etext = .; /* define a global symbol _etext just after the last code byte */
|
||||
} >ram /* put all the above into FLASH */
|
||||
|
||||
.data : /* collect all initialized .data sections that go into RAM */
|
||||
{
|
||||
_data = .; /* create a global symbol marking the start of the .data section */
|
||||
*(.data) /* all .data sections */
|
||||
_edata = .; /* define a global symbol marking the end of the .data section */
|
||||
} >ram /* put all the above into RAM (but load the LMA copy into FLASH) */
|
||||
|
||||
.bss : /* collect all uninitialized .bss sections that go into RAM */
|
||||
{
|
||||
_bss_start = .; /* define a global symbol marking the start of the .bss section */
|
||||
*(.bss) /* all .bss sections */
|
||||
} >ram /* put all the above in RAM (it will be cleared in the startup code */
|
||||
|
||||
. = ALIGN(4); /* advance location counter to the next 32-bit boundary */
|
||||
_bss_end = . ; /* define a global symbol marking the end of the .bss section */
|
||||
|
||||
_end = .; /* define a global symbol marking the end of application RAM */
|
||||
}
|
||||
|
||||
PROVIDE( BCFG0 = 0xFFE00000);
|
||||
PROVIDE( BCFG1 = 0xFFE00004);
|
||||
PROVIDE( BCFG2 = 0xFFE00008);
|
||||
PROVIDE( PINSEL0 = 0xE002C000);
|
||||
PROVIDE( PINSEL2 = 0xE002C014);
|
||||
PROVIDE( IO0PIN = 0xE0028000);
|
61
lpctool/testing/flashtool/lpc2220_rom.ld
Normal file
61
lpctool/testing/flashtool/lpc2220_rom.ld
Normal file
|
@ -0,0 +1,61 @@
|
|||
/* identify the Entry Point */
|
||||
|
||||
ENTRY(_startup)
|
||||
|
||||
/* specify the LPC2106 memory areas */
|
||||
|
||||
MEMORY
|
||||
{
|
||||
flash : ORIGIN = 0x80000000, LENGTH = 1M /* FLASH ROM */
|
||||
ram : ORIGIN = 0x40000200, LENGTH = 64K - 0x220 /* free RAM area */
|
||||
}
|
||||
|
||||
/* define a global symbol _stack_end */
|
||||
|
||||
_stack_end = 0x4000FEDC;
|
||||
|
||||
/* now define the output sections */
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = 0; /* set location counter to address zero */
|
||||
|
||||
startup :
|
||||
{
|
||||
*(.startup)
|
||||
} >flash /* the startup code goes into FLASH */
|
||||
|
||||
.text : /* collect all sections that should go into FLASH after startup */
|
||||
{
|
||||
*(.text) /* all .text sections (code) */
|
||||
*(.rodata) /* all .rodata sections (constants, strings, etc.) */
|
||||
*(.rodata*) /* all .rodata* sections (constants, strings, etc.) */
|
||||
*(.glue_7) /* all .glue_7 sections (no idea what these are) */
|
||||
*(.glue_7t) /* all .glue_7t sections (no idea what these are) */
|
||||
_etext = .; /* define a global symbol _etext just after the last code byte */
|
||||
} >flash /* put all the above into FLASH */
|
||||
|
||||
.data : /* collect all initialized .data sections that go into RAM */
|
||||
{
|
||||
_data = .; /* create a global symbol marking the start of the .data section */
|
||||
*(.data) /* all .data sections */
|
||||
_edata = .; /* define a global symbol marking the end of the .data section */
|
||||
} >ram AT >flash /* put all the above into RAM (but load the LMA copy into FLASH) */
|
||||
|
||||
.bss : /* collect all uninitialized .bss sections that go into RAM */
|
||||
{
|
||||
_bss_start = .; /* define a global symbol marking the start of the .bss section */
|
||||
*(.bss) /* all .bss sections */
|
||||
} >ram /* put all the above in RAM (it will be cleared in the startup code */
|
||||
|
||||
. = ALIGN(4); /* advance location counter to the next 32-bit boundary */
|
||||
_bss_end = . ; /* define a global symbol marking the end of the .bss section */
|
||||
}
|
||||
_end = .; /* define a global symbol marking the end of application RAM */
|
||||
|
||||
PROVIDE( BCFG0 = 0xFFE00000);
|
||||
PROVIDE( BCFG1 = 0xFFE00004);
|
||||
PROVIDE( BCFG2 = 0xFFE00008);
|
||||
PROVIDE( PINSEL0 = 0xE002C000);
|
||||
PROVIDE( PINSEL2 = 0xE002C014);
|
||||
PROVIDE( IO0PIN = 0xE0028000);
|
368
lpctool/testing/flashtool/ramtool.c
Normal file
368
lpctool/testing/flashtool/ramtool.c
Normal file
|
@ -0,0 +1,368 @@
|
|||
void IRQ_Routine (void) __attribute__ ((interrupt("IRQ")));
|
||||
void FIQ_Routine (void) __attribute__ ((interrupt("FIQ")));
|
||||
void SWI_Routine (void) __attribute__ ((interrupt("SWI")));
|
||||
void UNDEF_Routine (void) __attribute__ ((interrupt("UNDEF")));
|
||||
|
||||
typedef volatile unsigned int *reg32_t;
|
||||
|
||||
|
||||
#include "lpc2220.h"
|
||||
#include "serial.h"
|
||||
#include "flash.h"
|
||||
#include "lcd.h"
|
||||
#include "../toolcmd.h"
|
||||
#include "fonty.h"
|
||||
|
||||
union
|
||||
{
|
||||
unsigned long wbuf[128];
|
||||
unsigned short sbuf[256];
|
||||
unsigned char bbuf[512];
|
||||
} buf;
|
||||
|
||||
unsigned long checksum;
|
||||
unsigned short count;
|
||||
unsigned long adr;
|
||||
unsigned long numBytes;
|
||||
|
||||
void putHN(unsigned char pos, unsigned long hn)
|
||||
{
|
||||
draw_string(33,pos,"0x",3,DRAW_PUT);
|
||||
draw_hexW(45,pos,hn,3,DRAW_PUT);
|
||||
}
|
||||
|
||||
void putInfoVal(unsigned char pos, char *name, unsigned long val)
|
||||
{
|
||||
draw_block(0, pos, 128, 8, 3, DRAW_ERASE);
|
||||
|
||||
draw_string(0,pos,name,3,DRAW_PUT);
|
||||
putHN(pos, val);
|
||||
}
|
||||
|
||||
void ACK(void)
|
||||
{
|
||||
serial_puts(ACKTOKEN);
|
||||
}
|
||||
|
||||
void BACK(void)
|
||||
{
|
||||
serial_puts(BACKTOKEN);
|
||||
}
|
||||
|
||||
void NACK(void)
|
||||
{
|
||||
serial_puts(NACKTOKEN);
|
||||
}
|
||||
|
||||
int receiveBuf(void)
|
||||
{
|
||||
unsigned long ccheck;
|
||||
unsigned short cnt, cnt2, cnt3;
|
||||
|
||||
cnt = count<<2;
|
||||
|
||||
if(cnt > 512)
|
||||
return 0;
|
||||
|
||||
checksum = 0;
|
||||
ccheck = 0;
|
||||
cnt2 = 0;
|
||||
|
||||
#define XFERSIZE 16
|
||||
|
||||
while(cnt >= XFERSIZE)
|
||||
{
|
||||
cnt3=XFERSIZE;
|
||||
while(cnt3--)
|
||||
{
|
||||
buf.bbuf[cnt2] = serial_getc();
|
||||
checksum += buf.bbuf[cnt2++];
|
||||
}
|
||||
BACK();
|
||||
cnt -= XFERSIZE;
|
||||
}
|
||||
|
||||
if(cnt)
|
||||
{
|
||||
while(cnt--)
|
||||
{
|
||||
buf.bbuf[cnt2] = serial_getc();
|
||||
checksum += buf.bbuf[cnt2++];
|
||||
}
|
||||
BACK();
|
||||
}
|
||||
|
||||
ccheck = serial_getc() << 24;
|
||||
ccheck += serial_getc() << 16;
|
||||
ccheck += serial_getc() << 8;
|
||||
ccheck += serial_getc();
|
||||
|
||||
if(ccheck == checksum)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
drawStatus("Wrong Checksum");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
unsigned char i;
|
||||
unsigned char counter;
|
||||
|
||||
count = 0;
|
||||
adr = 0x00000000;
|
||||
timer = TIMEOUT+1;
|
||||
numBytes = 0;
|
||||
|
||||
lcd_init(0);
|
||||
|
||||
IODIR0|=0x10;
|
||||
IOCLR0=0x10;
|
||||
|
||||
serial_init();
|
||||
|
||||
set_font(1);
|
||||
#ifdef RESIDENT
|
||||
draw_string(0, 0,">> FlashTool V0.2-r",3,DRAW_PUT);
|
||||
#else
|
||||
draw_string(0, 0,">> FlashTool V0.2",3,DRAW_PUT);
|
||||
#endif
|
||||
set_font(0);
|
||||
draw_string(0,14,"This tool is licensed under",3,DRAW_PUT);
|
||||
draw_string(0,22,"the GNU GPL 3 or later",3,DRAW_PUT);
|
||||
draw_string(0,34,"(c) 2007 Ch. Klippel",3,DRAW_PUT);
|
||||
draw_string(0,42,"<ck@mamalala.net>",3,DRAW_PUT);
|
||||
|
||||
drawStatus("FlashTool ready!");
|
||||
|
||||
adr = 0x00000000;
|
||||
while (1)
|
||||
{
|
||||
i = serial_getc();
|
||||
|
||||
if (i) // misses 0x00 !
|
||||
{
|
||||
counter += 10;
|
||||
if ( counter > 100)
|
||||
counter = 50;
|
||||
|
||||
putInfoVal(counter, "i:", i);
|
||||
}
|
||||
|
||||
if(i==HELO_CMD)
|
||||
{
|
||||
serial_puts(HELOTOKEN);
|
||||
drawStatus("Sent HELO");
|
||||
}
|
||||
else if(i==BULKENABLE_CMD)
|
||||
{
|
||||
putInfoVal(80, "Bulk:", 1);
|
||||
if((adr & 0xFF000000) == 0x80000000 || (adr & 0xFF000000) == 0x82000000)
|
||||
{
|
||||
prepareBulk(adr);
|
||||
drawStatus("Enabled bulk write");
|
||||
draw_string(100,80,ACKTOKEN,3,DRAW_PUT);
|
||||
ACK();
|
||||
}
|
||||
else
|
||||
{
|
||||
draw_string(100,80,NACKTOKEN,3,DRAW_PUT);
|
||||
NACK();
|
||||
}
|
||||
}
|
||||
else if(i==SKIP_CMD)
|
||||
{
|
||||
adr += (serial_getc() << 16);
|
||||
adr += serial_getc();
|
||||
ACK();
|
||||
}
|
||||
else if(i==BULKDISABLE_CMD)
|
||||
{
|
||||
putInfoVal(80, "Bulk:", 0);
|
||||
if((adr & 0xFF000000) == 0x80000000 || (adr & 0xFF000000) == 0x82000000)
|
||||
{
|
||||
endBulk(adr);
|
||||
drawStatus("Disabled bulk write");
|
||||
draw_string(100,80,ACKTOKEN,3,DRAW_PUT);
|
||||
ACK();
|
||||
}
|
||||
else
|
||||
{
|
||||
draw_string(100,80,NACKTOKEN,3,DRAW_PUT);
|
||||
NACK();
|
||||
}
|
||||
}
|
||||
else if(i==SETADR_CMD)
|
||||
{
|
||||
adr = serial_getc() << 24;
|
||||
adr += serial_getc() << 16;
|
||||
adr += serial_getc() << 8;
|
||||
adr += serial_getc();
|
||||
|
||||
putInfoVal(72, "Addr:", adr);
|
||||
|
||||
if((adr & 0xFF000000) == 0x40000000 || (adr & 0xFF000000) == 0x80000000 || (adr & 0xFF000000) == 0x82000000)
|
||||
{
|
||||
drawStatus("Address changed");
|
||||
draw_string(100,72,ACKTOKEN,3,DRAW_PUT);
|
||||
ACK();
|
||||
}
|
||||
else
|
||||
{
|
||||
draw_string(100,72,NACKTOKEN,3,DRAW_PUT);
|
||||
adr = 0x00000000;
|
||||
NACK();
|
||||
}
|
||||
}
|
||||
else if(i==FILLBUF_CMD)
|
||||
{
|
||||
count = serial_getc();
|
||||
putInfoVal(88, "Buf:", count<<2);
|
||||
if(count > 0 && count <= 128)
|
||||
{
|
||||
if(receiveBuf())
|
||||
{
|
||||
ACK();
|
||||
}
|
||||
else
|
||||
{
|
||||
goto fail_f;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fail_f:
|
||||
draw_string(100,88,NACKTOKEN,3,DRAW_PUT);
|
||||
count = 0;
|
||||
NACK();
|
||||
}
|
||||
}
|
||||
else if(i==WRITE_CMD)
|
||||
{
|
||||
putInfoVal(96, "Write:", adr);
|
||||
i = serial_getc();
|
||||
if(i==WRITEGO_CMD && count > 0)
|
||||
{
|
||||
if(writeBulk((unsigned long) &buf.bbuf, adr, count<<1) == 0)
|
||||
{
|
||||
adr += (count<<2);
|
||||
ACK();
|
||||
}
|
||||
else
|
||||
{
|
||||
draw_string(100,96,NACKTOKEN,3,DRAW_PUT);
|
||||
NACK();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(i==SECTERASE_CMD)
|
||||
{
|
||||
|
||||
drawStatus("Erasing Flash Sector");
|
||||
if(eraseSectorAt(adr) == 0)
|
||||
{
|
||||
drawStatus("Erased Flash Sector");
|
||||
ACK();
|
||||
}
|
||||
else
|
||||
{
|
||||
drawStatus("Erase Sector FAILED!!");
|
||||
NACK();
|
||||
}
|
||||
}
|
||||
else if(i==FULLERASE_CMD)
|
||||
{
|
||||
unsigned char w;
|
||||
w = 0xFF;
|
||||
if((adr & 0xFF000000) == 0x82000000)
|
||||
{
|
||||
drawStatus("Erasing Flash #1");
|
||||
w = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
drawStatus("Erasing Flash #0");
|
||||
w = 0;
|
||||
}
|
||||
if(eraseFlash(w) == 0)
|
||||
{
|
||||
if(w==1)
|
||||
{
|
||||
drawStatus("Erased Flash #1");
|
||||
}
|
||||
else if(w==0)
|
||||
{
|
||||
drawStatus("Erased Flash #0");
|
||||
}
|
||||
ACK();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(w)
|
||||
{
|
||||
drawStatus("Flash #1 Erase FAILED!!");
|
||||
}
|
||||
else
|
||||
{
|
||||
drawStatus("Flash #0 Erase FAILED!!");
|
||||
}
|
||||
NACK();
|
||||
}
|
||||
}
|
||||
else if(i==SETNUMBYTES_CMD)
|
||||
{
|
||||
numBytes = serial_getc() << 24;
|
||||
numBytes += serial_getc() << 16;
|
||||
numBytes += serial_getc() << 8;
|
||||
numBytes += serial_getc();
|
||||
putInfoVal(104, "NumB:", numBytes);
|
||||
if(numBytes <= 0x00100000)
|
||||
{
|
||||
draw_string(100,104,ACKTOKEN,3,DRAW_PUT);
|
||||
ACK();
|
||||
}
|
||||
else
|
||||
{
|
||||
draw_string(100,104,NACKTOKEN,3,DRAW_PUT);
|
||||
NACK();
|
||||
}
|
||||
}
|
||||
else if(i==READ_CMD)
|
||||
{
|
||||
for(adr = 0x40000200; adr < 0x40000210; adr+=4)
|
||||
{
|
||||
putHexW((unsigned long)(*(volatile unsigned long *)(adr)));
|
||||
serial_putc('\n');
|
||||
}
|
||||
for(adr = 0x80000000; adr < 0x80000010; adr+=4)
|
||||
{
|
||||
putHexW((unsigned long)(*(volatile unsigned long *)(adr)));
|
||||
serial_putc('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Stubs for various interrupts (may be replaced later) */
|
||||
/* ---------------------------------------------------- */
|
||||
|
||||
void IRQ_Routine (void) {
|
||||
while (1) ;
|
||||
}
|
||||
|
||||
void FIQ_Routine (void) {
|
||||
while (1) ;
|
||||
}
|
||||
|
||||
|
||||
void SWI_Routine (void) {
|
||||
while (1) ;
|
||||
}
|
||||
|
||||
|
||||
void UNDEF_Routine (void) {
|
||||
while (1) ;
|
||||
}
|
247
lpctool/testing/flashtool/serial.c
Normal file
247
lpctool/testing/flashtool/serial.c
Normal file
|
@ -0,0 +1,247 @@
|
|||
/*
|
||||
* minor changes (c) 2007 ch.klippel
|
||||
*
|
||||
* (C) Copyright 2004
|
||||
* DAVE Srl
|
||||
* http://www.dave-tech.it
|
||||
* http://www.wawnet.biz
|
||||
* mailto:info@wawnet.biz
|
||||
*
|
||||
* (C) Copyright 2002-2004
|
||||
* Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
|
||||
*
|
||||
* (C) Copyright 2002
|
||||
* Sysgo Real-Time Solutions, GmbH <www.elinos.com>
|
||||
* Marius Groeger <mgroeger@sysgo.de>
|
||||
*
|
||||
* (C) Copyright 2002
|
||||
* Sysgo Real-Time Solutions, GmbH <www.elinos.com>
|
||||
* Alex Zuepke <azu@sysgo.de>
|
||||
*
|
||||
* Copyright (C) 1999 2000 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "lpc2220.h"
|
||||
#include "serial.h"
|
||||
#include "lcd.h"
|
||||
#include "../baudrate.h"
|
||||
|
||||
unsigned long timer;
|
||||
|
||||
|
||||
/* flush serial input queue. returns 0 on success or negative error
|
||||
* number otherwise
|
||||
*/
|
||||
int serial_flush_input(void)
|
||||
{
|
||||
volatile unsigned int tmp;
|
||||
|
||||
/* keep on reading as long as the receiver is not empty */
|
||||
while(RX_DATA(U0LSR)) {
|
||||
tmp = GET_CHAR(U0RBR);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* flush output queue. returns 0 on success or negative error number
|
||||
* otherwise
|
||||
*/
|
||||
int serial_flush_output(void)
|
||||
{
|
||||
/* wait until the transmitter is no longer busy */
|
||||
while(TX_READY(U0LSR)==0) {
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void serial_setbrg (unsigned int baudrate)
|
||||
{
|
||||
|
||||
/* get correct divisor */
|
||||
U0LCR = 0x83;
|
||||
|
||||
switch(baudrate) {
|
||||
|
||||
case 75:
|
||||
U0DLL = 161;
|
||||
U0DLM = 1;
|
||||
U0FDR = (1 << 4) + 14;
|
||||
break;
|
||||
|
||||
case 150:
|
||||
U0DLL = 195;
|
||||
U0DLM = 0;
|
||||
U0FDR = (1 << 4) + 15;
|
||||
break;
|
||||
|
||||
case 300:
|
||||
U0DLL = 184;
|
||||
U0DLM = 0;
|
||||
U0FDR = (2 << 4) + 15;
|
||||
break;
|
||||
|
||||
case 600:
|
||||
U0DLL = 156;
|
||||
U0DLM = 0;
|
||||
U0FDR = (1 << 4) + 4;
|
||||
break;
|
||||
|
||||
case 1200:
|
||||
U0DLL = 130;
|
||||
U0DLM = 0;
|
||||
U0FDR = (7 << 4) + 14;
|
||||
break;
|
||||
|
||||
case 2400:
|
||||
U0DLL = 180;
|
||||
U0DLM = 0;
|
||||
U0FDR = (12 << 4) + 1;
|
||||
break;
|
||||
|
||||
case 4800:
|
||||
U0DLL = 90;
|
||||
U0DLM = 0;
|
||||
U0FDR = (1 << 4) + 4;
|
||||
break;
|
||||
|
||||
case 9600:
|
||||
U0DLL = 23;
|
||||
U0DLM = 0;
|
||||
U0FDR = (8 << 4) + 9;
|
||||
break;
|
||||
|
||||
case 19200:
|
||||
U0DLL = 11;
|
||||
U0DLM = 0;
|
||||
U0FDR = (9 << 4) + 11;
|
||||
break;
|
||||
|
||||
case 38400:
|
||||
U0DLL = 5;
|
||||
U0DLM = 0;
|
||||
U0FDR = (9 << 4) + 13;
|
||||
break;
|
||||
|
||||
case 57600:
|
||||
U0DLL = 6;
|
||||
U0DLM = 0;
|
||||
U0FDR = (14 << 4) + 5;
|
||||
break;
|
||||
|
||||
case 115200:
|
||||
U0DLL = 3;
|
||||
U0DLM = 0;
|
||||
U0FDR = (14 << 4) + 5;
|
||||
break;
|
||||
}
|
||||
U0LCR = 0x03;
|
||||
|
||||
serial_flush_output();
|
||||
serial_flush_input();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Initialise the serial port with the given baudrate. The settings
|
||||
* are always 8 data bits, no parity, 1 stop bit, no start bits.
|
||||
*
|
||||
*/
|
||||
int serial_init (void)
|
||||
{
|
||||
PINSEL0=0x05; // pin select -> tx, rx
|
||||
serial_setbrg (TOOLBAUD);
|
||||
U0FCR = 0x07; // enable fifo
|
||||
timer = TIMEOUT+1;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Output a single byte to the serial port.
|
||||
*/
|
||||
void serial_putc (const char c)
|
||||
{
|
||||
/* wait for room in the transmit FIFO */
|
||||
while(TX_READY(U0LSR)==0);
|
||||
|
||||
PUT_CHAR(U0THR,c);
|
||||
}
|
||||
|
||||
/*
|
||||
* Read a single byte from the serial port. Returns 1 on success, 0
|
||||
* otherwise. When the function is succesfull, the character read is
|
||||
* written into its argument c.
|
||||
*/
|
||||
int serial_tstc (void)
|
||||
{
|
||||
return (RX_DATA(U0LSR));
|
||||
}
|
||||
|
||||
/*
|
||||
* Read a single byte from the serial port. Returns 1 on success, 0
|
||||
* otherwise. When the function is succesfull, the character read is
|
||||
* written into its argument c.
|
||||
*/
|
||||
|
||||
int serial_getc (void)
|
||||
{
|
||||
while(((U0LSR) & USRRxData) <= 0)
|
||||
{
|
||||
if(timer == TIMEOUT)
|
||||
{
|
||||
clearStatus();
|
||||
timer++;
|
||||
}
|
||||
else if(timer < TIMEOUT)
|
||||
{
|
||||
timer++;
|
||||
}
|
||||
}
|
||||
return (U0RBR);
|
||||
}
|
||||
|
||||
void serial_puts (const char *s)
|
||||
{
|
||||
while (*s != 0) {
|
||||
serial_putc (*s++);
|
||||
}
|
||||
}
|
||||
|
||||
const char hval[16] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' };
|
||||
|
||||
void putHexC(const unsigned char v)
|
||||
{
|
||||
serial_putc(hval[v>>4]);
|
||||
serial_putc(hval[v & 0x0F]);
|
||||
}
|
||||
|
||||
void putHexS(const unsigned short v)
|
||||
{
|
||||
putHexC(v >> 8);
|
||||
putHexC(v & 0xFF);
|
||||
}
|
||||
|
||||
void putHexW(const unsigned long v)
|
||||
{
|
||||
putHexS(v >> 16);
|
||||
putHexS(v & 0xFFFF);
|
||||
}
|
24
lpctool/testing/flashtool/serial.h
Normal file
24
lpctool/testing/flashtool/serial.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
#ifndef BOOP_SERIAL_H
|
||||
#define BOOP_SERIAL_H
|
||||
|
||||
#define USRRxData (1 << 0)
|
||||
#define USRTxHoldEmpty (1 << 6)
|
||||
#define GET_CHAR(p) p
|
||||
#define PUT_CHAR(p,c) (p= (unsigned )(c))
|
||||
#define TX_READY(s) ((s) & USRTxHoldEmpty)
|
||||
#define RX_DATA(s) ((s) & USRRxData)
|
||||
|
||||
int serial_flush_input(void);
|
||||
int serial_flush_output(void);
|
||||
void serial_setbrg (unsigned int baudrate);
|
||||
int serial_init (void);
|
||||
void serial_putc (const char c);
|
||||
int serial_tstc (void);
|
||||
int serial_getc (void);
|
||||
void serial_puts (const char *s);
|
||||
|
||||
void putHexC(const unsigned char v);
|
||||
void putHexS(const unsigned short v);
|
||||
void putHexW(const unsigned long v);
|
||||
|
||||
#endif /* BOOP_SERIAL_H */
|
104
lpctool/testing/infohelper.c
Normal file
104
lpctool/testing/infohelper.c
Normal file
|
@ -0,0 +1,104 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include "infohelper.h"
|
||||
|
||||
char verbosity;
|
||||
|
||||
int printError(char *err)
|
||||
{
|
||||
printf("ERROR: %s\n",err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int printErrorS(char *err, char *xtra)
|
||||
{
|
||||
if(xtra)
|
||||
printf("ERROR: %s %s\n", err, xtra);
|
||||
else
|
||||
printf("ERROR: %s\n", err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int printInfoS(unsigned char level, char *msg, char *xtra)
|
||||
{
|
||||
if(level <= verbosity)
|
||||
{
|
||||
if(xtra)
|
||||
printf("Info : %s %s\n", msg, xtra);
|
||||
else
|
||||
printf("Info : %s\n", msg);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int printInfoC(unsigned char level, char *msg, char xtra)
|
||||
{
|
||||
if(level <= verbosity)
|
||||
{
|
||||
if(xtra)
|
||||
printf("Info : %s %c\n", msg, xtra);
|
||||
else
|
||||
printf("Info : %s\n", msg);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int printInfoH(unsigned char level, char *msg, unsigned long val)
|
||||
{
|
||||
if(level <= verbosity)
|
||||
{
|
||||
printf("Info : %s 0x%08lX\n", msg, val);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int printInfoU(unsigned char level, char *msg, unsigned long val)
|
||||
{
|
||||
if(level <= verbosity)
|
||||
{
|
||||
printf("Info : %s %li\n", msg, val);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char heartbeat[] = { ".oOo" };
|
||||
|
||||
int printProgress(unsigned char level, char *msg, float cval, float maxval)
|
||||
{
|
||||
unsigned int cur, cnt;
|
||||
|
||||
static char beat = 0;
|
||||
|
||||
if(level <= verbosity)
|
||||
{
|
||||
cur = (35 / maxval) * cval;
|
||||
|
||||
cnt = 35-cur;
|
||||
|
||||
printf("Progress: [");
|
||||
|
||||
while(cur--)
|
||||
printf("*");
|
||||
|
||||
if(cnt)
|
||||
printf("%c",heartbeat[beat]);
|
||||
else
|
||||
printf("*");
|
||||
|
||||
while(cnt--)
|
||||
printf(" ");
|
||||
|
||||
printf("\b]\r");
|
||||
fflush(stdout);
|
||||
beat++;
|
||||
beat &= 0x03;
|
||||
}
|
||||
}
|
||||
|
14
lpctool/testing/infohelper.h
Normal file
14
lpctool/testing/infohelper.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#ifndef TOOL_INFOHELPER
|
||||
#define TOOL_INFOHELPER
|
||||
|
||||
extern char verbosity;
|
||||
|
||||
int printError(char *err);
|
||||
int printErrorS(char *err, char *xtra);
|
||||
int printInfoS(unsigned char level, char *msg, char *xtra);
|
||||
int printInfoC(unsigned char level, char *msg, char xtra);
|
||||
int printInfoH(unsigned char level, char *msg, unsigned long val);
|
||||
int printInfoU(unsigned char level, char *msg, unsigned long val);
|
||||
int printProgress(unsigned char level, char *msg, float cval, float maxval);
|
||||
|
||||
#endif
|
492
lpctool/testing/lpctool.c
Normal file
492
lpctool/testing/lpctool.c
Normal file
|
@ -0,0 +1,492 @@
|
|||
#include "infohelper.h"
|
||||
#include "lpctool_serial.h"
|
||||
#include "bootcom.h"
|
||||
#include "toolcom.h"
|
||||
|
||||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 9
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
unsigned long radr, f0adr, f1adr, gadr;
|
||||
|
||||
void printHeader(void)
|
||||
{
|
||||
printf("\nlpctool V%i.%i\n\n", VERSION_MAJOR, VERSION_MINOR);
|
||||
printf("This Software is free Software under GNU GPL 3 or later\n");
|
||||
printf("(c) 2007 Ch. Klippel <ck@mamalala.net>\n\n");
|
||||
}
|
||||
|
||||
void printUsage(void)
|
||||
{
|
||||
printf("usage: lpctool [-d NAME] [-i] [-r [NAME]] [-R ADDRESS] [-X [ADDRESS]] [-a [NAME] [-A ADRDESS]] [-e] [-b [NAME] [-B ADDRESS]] [-E] [-s] [-S] [-c] [-C] [-v] [-V]\n\n");
|
||||
printf(" -d NAME specify serial device, default is /dev/ttyS0\n");
|
||||
printf(" -i use compiled-in flash-tool instead of external ram image file\n");
|
||||
printf(" -r NAME specify file for ram, default is ramtool.bin\n");
|
||||
printf(" -R ADDRESS optionally specifies the start-address to load into ram\n");
|
||||
printf(" default is 0x40000200 - must be specified in hex\n");
|
||||
printf(" -X ADDRESS set the execution address for the uploaded ram image\n");
|
||||
printf(" defualt is 0x40000200, omiting the address disables execution\n");
|
||||
printf(" -a NAME specify file for flash #0, default is flash0.bin\n");
|
||||
printf(" -A ADDRESS optionally specifies the start-address to load into flash #0\n");
|
||||
printf(" default is 0x80000000 - must be specified in hex\n");
|
||||
printf(" -e completely erase the first flash before writing\n");
|
||||
printf(" default is no erase\n");
|
||||
printf(" -b NAME specify file for flash #1, default is flash1.bin\n");
|
||||
printf(" -B ADDRESS optionally specifies the start-address to load into flash #1\n");
|
||||
printf(" default is 0x82000000 - must be specified in hex\n");
|
||||
printf(" -E completely erase the second flash before writing\n");
|
||||
printf(" defualt is no erase\n");
|
||||
printf(" -S only erase the first sector in flash before writing\n");
|
||||
printf(" this is a lot faster if only the first sector is used\n");
|
||||
printf(" -c write flash0 in chunk mode instead of write-all\n");
|
||||
printf(" -C write flash1 in chunk mode instead of write-all\n");
|
||||
printf(" in chunk mode, parts with 4 consectuive 0xFFFFFFFF or more\n");
|
||||
printf(" in the image are skipped. speeds upload when the image has\n");
|
||||
printf(" gaps. defualt is off\n");
|
||||
printf(" -N do not reset the device after uploading to flash\n");
|
||||
printf(" by default the device gets reset after upload\n");
|
||||
printf(" -? print this help\n");
|
||||
printf(" -v print version\n");
|
||||
printf(" -V be more verbose\n");
|
||||
printf("\n");
|
||||
printf("at least -r or -i must be given to be usefull. everything in [] is optional\n");
|
||||
printf("examples:\n");
|
||||
printf("\n");
|
||||
printf("to just load ramtool.bin, starting at 0x40000200, using serial device /dev/ttyS0 :\n");
|
||||
printf("lpcload -r\n\n");
|
||||
printf("to do the same, but using serial device /dev/ttyS1 instead :\n");
|
||||
printf("lpcload -r -d /dev/ttyS1\n\n");
|
||||
printf("using the file image.bin as source for the ram, use /dev/ttyS1 as serial device :\n");
|
||||
printf("lpcload -r image.bin -d /dev/ttyS1\n");
|
||||
}
|
||||
|
||||
unsigned long parseHex(char *buf)
|
||||
{
|
||||
unsigned char cnt;
|
||||
unsigned long adr;
|
||||
|
||||
cnt = 0;
|
||||
adr = 0;
|
||||
|
||||
while(buf[cnt])
|
||||
{
|
||||
adr <<= 4;
|
||||
if(buf[cnt] >= '0' && buf[cnt] <= '9')
|
||||
{
|
||||
adr += (buf[cnt] - '0');
|
||||
}
|
||||
else if(buf[cnt] >= 'A' && buf[cnt] <= 'F')
|
||||
{
|
||||
adr += (buf[cnt] - 'A' + 10);
|
||||
}
|
||||
else if(buf[cnt] >= 'a' && buf[cnt] <= 'f')
|
||||
{
|
||||
adr += (buf[cnt] - 'a' + 10);
|
||||
}
|
||||
else if(buf[cnt] == 'x' || buf[cnt] == 'X')
|
||||
{
|
||||
adr = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
cnt++;
|
||||
}
|
||||
return adr;
|
||||
}
|
||||
|
||||
const char hval[] = { "0123456789ABCDEF" };
|
||||
|
||||
void printHexC(unsigned char num)
|
||||
{
|
||||
printf("%c%c", hval[(num&0xF0)>>4], hval[num&0x0F]);
|
||||
}
|
||||
|
||||
void printHexS(unsigned short num)
|
||||
{
|
||||
printHexC((num & 0xFF00) >> 8);
|
||||
printHexC(num & 0x00FF);
|
||||
}
|
||||
|
||||
void printHexW(unsigned long num)
|
||||
{
|
||||
printHexS((num & 0xFFFF0000) >> 16);
|
||||
printHexS(num & 0x0000FFFF);
|
||||
}
|
||||
/*
|
||||
void enterBootLD(void)
|
||||
{
|
||||
setDTR(1);
|
||||
usleep(10);
|
||||
setRTS(1);
|
||||
usleep(100);
|
||||
setRTS(0);
|
||||
usleep(10);
|
||||
setDTR(0);
|
||||
usleep(100);
|
||||
}
|
||||
|
||||
void resetFB(void)
|
||||
{
|
||||
setRTS(1);
|
||||
usleep(100);
|
||||
setRTS(0);
|
||||
}
|
||||
*/
|
||||
|
||||
// eINT1 low on RESET to enter bootloader
|
||||
void enterBootLD(void)
|
||||
{
|
||||
setRTS(1);
|
||||
usleep(1000);
|
||||
setDTR(1);
|
||||
usleep(1000);
|
||||
setDTR(0);
|
||||
usleep(1000);
|
||||
setRTS(0);
|
||||
usleep(1000);
|
||||
}
|
||||
|
||||
void resetFB(void)
|
||||
{
|
||||
setDTR(1);
|
||||
usleep(100);
|
||||
setDTR(0);
|
||||
}
|
||||
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
char sname[256];
|
||||
char rname[256];
|
||||
char f0name[256];
|
||||
char f1name[256];
|
||||
unsigned char i, cmd;
|
||||
unsigned int uflags;
|
||||
int fd;
|
||||
|
||||
sprintf(sname,"/dev/ttyS0");
|
||||
sprintf(rname,"ramtool.bin");
|
||||
sprintf(f0name,"flash0.bin");
|
||||
sprintf(f1name,"flash1.bin");
|
||||
|
||||
verbosity = 0;
|
||||
uflags = 0;
|
||||
|
||||
radr = 0x40000200;
|
||||
f0adr = 0x80000000;
|
||||
f1adr = 0x82000000;
|
||||
gadr = radr;
|
||||
|
||||
printHeader();
|
||||
|
||||
for(i=1;i<argc;i++)
|
||||
{
|
||||
if(argv[i][0] == '-')
|
||||
{
|
||||
cmd = 0;
|
||||
if(argv[i][1] == '-')
|
||||
{
|
||||
cmd = argv[i][2];
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd = argv[i][1];
|
||||
}
|
||||
|
||||
switch(cmd)
|
||||
{
|
||||
case 'v':
|
||||
verbosity = 2;
|
||||
break;
|
||||
case 'V':
|
||||
goto end;
|
||||
case 'd':
|
||||
if((argc > i+1) && (argv[i+1][0] != '-'))
|
||||
{
|
||||
strncpy(sname,argv[++i],256);
|
||||
printInfoS(1,"using serial device",sname);
|
||||
}
|
||||
else
|
||||
{
|
||||
printError("Error in device argument");
|
||||
goto bailout;
|
||||
}
|
||||
break;
|
||||
case 'r':
|
||||
if((argc > i+1) && (argv[i+1][0] != '-'))
|
||||
{
|
||||
strncpy(rname,argv[++i],256);
|
||||
printInfoS(1,"using ram image",rname);
|
||||
}
|
||||
uflags |= 0x01;
|
||||
break;
|
||||
case 'R':
|
||||
if((argc > i+1) && (argv[i+1][0] != '-'))
|
||||
{
|
||||
radr = parseHex(argv[++i]);
|
||||
printInfoH(1,"loading ram @",radr);
|
||||
}
|
||||
else
|
||||
printInfoH(1,"used -R but no address given, using default", radr);
|
||||
break;
|
||||
case 'a':
|
||||
if((argc > i+1) && (argv[i+1][0] != '-'))
|
||||
{
|
||||
strncpy(f0name,argv[++i],256);
|
||||
printInfoS(1,"using flash #0 image",f0name);
|
||||
}
|
||||
uflags |= 0x02;
|
||||
break;
|
||||
case 'A':
|
||||
if((argc > i+1) && (argv[i+1][0] != '-'))
|
||||
{
|
||||
f0adr = parseHex(argv[++i]);
|
||||
printInfoH(1,"setting address for flash #0 @",f0adr);
|
||||
}
|
||||
else
|
||||
printInfoH(1,"used -A but no address given, using default",f0adr);
|
||||
break;
|
||||
case 'b':
|
||||
if((argc > i+1) && (argv[i+1][0] != '-'))
|
||||
{
|
||||
strncpy(f1name,argv[++i],256);
|
||||
printInfoS(1,"using flash #1 image",f1name);
|
||||
}
|
||||
uflags |= 0x04;
|
||||
break;
|
||||
case 'B':
|
||||
if((argc > i+1) && (argv[i+1][0] != '-'))
|
||||
{
|
||||
f1adr = parseHex(argv[++i]);
|
||||
printInfoH(1,"setting address for flash #1 @",f1adr);
|
||||
}
|
||||
else
|
||||
printInfoH(1,"used -B but no address given, using default",f1adr);
|
||||
break;
|
||||
case 'X':
|
||||
if((argc > i+1) && (argv[i+1][0] != '-'))
|
||||
{
|
||||
gadr = parseHex(argv[++i]);
|
||||
printInfoH(1,"setting ram execute address @",gadr);
|
||||
uflags |= 0x08;
|
||||
}
|
||||
else
|
||||
printInfoS(1,"disabling auto-run",0);
|
||||
break;
|
||||
case 'e':
|
||||
printInfoS(1,"erasing flash #0 before write",0);
|
||||
uflags |= 0x10;
|
||||
break;
|
||||
case 'E':
|
||||
printInfoS(1,"erasing flash #1 before write",0);
|
||||
uflags |= 0x20;
|
||||
break;
|
||||
case 'S':
|
||||
printInfoS(1,"only erasing start sector",0);
|
||||
uflags |= 0x40;
|
||||
break;
|
||||
case 's':
|
||||
printInfoS(1,"auto-erasing sectors as needed",0);
|
||||
uflags |= 0x80;
|
||||
break;
|
||||
case 'N':
|
||||
printInfoS(1,"don't reset after flash upload is done",0);
|
||||
uflags |= 0x100;
|
||||
break;
|
||||
case 'c':
|
||||
printInfoS(1,"using chunk mode for flash #0",0);
|
||||
uflags |= 0x200;
|
||||
break;
|
||||
case 'C':
|
||||
printInfoS(1,"using chunk mode for flash #1",0);
|
||||
uflags |= 0x400;
|
||||
break;
|
||||
case 'i':
|
||||
uflags |= 0x800;
|
||||
break;
|
||||
default:
|
||||
goto bailout;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bailout:
|
||||
printUsage();
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
if(!uflags)
|
||||
{
|
||||
printUsage();
|
||||
printInfoS(0,"\nnothing to do!",0);
|
||||
goto end;
|
||||
}
|
||||
|
||||
printInfoS(2,"opening serial device",sname);
|
||||
if(openSerial(sname) <= 0)
|
||||
{
|
||||
printError("Error opening serial device");
|
||||
goto end;
|
||||
}
|
||||
|
||||
if((uflags & 0x01) || (uflags & 0x800))
|
||||
{
|
||||
if(!(uflags & 0x800))
|
||||
{
|
||||
printInfoS(2,"opening ram image",rname);
|
||||
fd = open(rname,O_RDONLY);
|
||||
if(fd < 0)
|
||||
{
|
||||
printErrorS("can't open",rname);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fd = 0;
|
||||
}
|
||||
|
||||
#if TOOLBAUD <= 38400
|
||||
printInfoS(2,"wait for buggy serial ports",0);
|
||||
setRTS(0);
|
||||
usleep(100000);
|
||||
#endif
|
||||
|
||||
printInfoS(2,"reset into bootmode",0);
|
||||
enterBootLD();
|
||||
|
||||
printInfoS(2,"opening bootloader",0);
|
||||
if(!openBootLoader(10000))
|
||||
{
|
||||
printError("Error opening BootLoader");
|
||||
goto end;
|
||||
}
|
||||
|
||||
printInfoS(2,"unlocking bootloader",0);
|
||||
if(!unlockBootLoader())
|
||||
{
|
||||
printError("Error unlocking BootLoader");
|
||||
goto end;
|
||||
}
|
||||
if(!(uflags & 0x800))
|
||||
{
|
||||
printInfoS(1,"uploading ram image",rname);
|
||||
}
|
||||
else
|
||||
{
|
||||
printInfoS(1,"uploading compiled-in ram image",0);
|
||||
}
|
||||
if(uploadRAM(fd, radr))
|
||||
{
|
||||
printInfoS(1,"ram uploaded",0);
|
||||
if(!(uflags&0x08))
|
||||
{
|
||||
printInfoH(1,"executing code at ram address",gadr);
|
||||
if(!goBootLoader(gadr))
|
||||
{
|
||||
printError("Error starting from ram");
|
||||
goto end;
|
||||
}
|
||||
printInfoH(2,"code execution started",gadr);
|
||||
}
|
||||
}
|
||||
if(fd)
|
||||
{
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
//~ reconfSerial(TOOLBAUD, 0, 5);
|
||||
|
||||
if(uflags & 0x06)
|
||||
{
|
||||
printInfoS(2,"opening ram tool",0);
|
||||
if(openRamTool())
|
||||
printInfoS(2,"opened ramtool",0);
|
||||
else
|
||||
goto end;
|
||||
|
||||
if(uflags & 0x02)
|
||||
{
|
||||
printInfoS(2,"opening flash0 image",f0name);
|
||||
fd = open(f0name,O_RDONLY);
|
||||
if(fd < 0)
|
||||
{
|
||||
printErrorS("cant open",f0name);
|
||||
goto end;
|
||||
}
|
||||
printInfoS(1,"uploading flash0 image",f0name);
|
||||
if(uflags & 0x200)
|
||||
{
|
||||
if(uploadChunks(fd, f0adr, (uflags & 0x50)))
|
||||
printInfoS(1,"flash #0 uploaded",0);
|
||||
else
|
||||
goto end;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(uploadFlash(fd, f0adr, (uflags & 0x50)))
|
||||
printInfoS(1,"flash #0 uploaded",0);
|
||||
else
|
||||
goto end;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(uflags & 0x04)
|
||||
{
|
||||
printInfoS(2,"opening flash1 image",f1name);
|
||||
fd = open(f1name,O_RDONLY);
|
||||
if(fd < 0)
|
||||
{
|
||||
printErrorS("cant open",f1name);
|
||||
goto end;
|
||||
}
|
||||
printInfoS(1,"uploading flash1 image",f1name);
|
||||
|
||||
if(uflags & 0x400)
|
||||
{
|
||||
if(uploadChunks(fd, f1adr, (uflags & 0x60)))
|
||||
printInfoS(1,"flash #1 uploaded",0);
|
||||
else
|
||||
goto end;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(uploadFlash(fd, f1adr, (uflags & 0x60)))
|
||||
printInfoS(1,"flash #1 uploaded",0);
|
||||
else
|
||||
goto end;
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
|
||||
if((uflags & 06) && !(uflags & 0x100))
|
||||
{
|
||||
printInfoS(2,"reset device",0);
|
||||
resetFB();
|
||||
}
|
||||
}
|
||||
|
||||
end:
|
||||
if(fd)
|
||||
{
|
||||
printInfoS(2,"closing file descriptor",0);
|
||||
close(fd);
|
||||
}
|
||||
printInfoS(2,"closing serial device",sname);
|
||||
closeSerial();
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
259
lpctool/testing/lpctool_serial.c
Normal file
259
lpctool/testing/lpctool_serial.c
Normal file
|
@ -0,0 +1,259 @@
|
|||
#include "lpctool_serial.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <termios.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "infohelper.h"
|
||||
|
||||
#define MAX(x,y) ((x) > (y) ? (x) : (y))
|
||||
#define MIN(x,y) ((x) < (y) ? (x) : (y))
|
||||
|
||||
int serialDev = -1;
|
||||
static struct termios term;
|
||||
|
||||
// change baudrate
|
||||
// doesn't really do anything if it's the same
|
||||
void setBaud(unsigned int baud)
|
||||
{
|
||||
|
||||
printInfoU(0, "Setting baudrate to", baud);
|
||||
switch(baud)
|
||||
{
|
||||
case 2400:
|
||||
cfsetispeed(&term,B2400);
|
||||
cfsetospeed(&term,B2400);
|
||||
break;
|
||||
case 4800:
|
||||
cfsetispeed(&term,B4800);
|
||||
cfsetospeed(&term,B4800);
|
||||
break;
|
||||
case 9600:
|
||||
cfsetispeed(&term,B9600);
|
||||
cfsetospeed(&term,B9600);
|
||||
break;
|
||||
case 19200:
|
||||
cfsetispeed(&term,B19200);
|
||||
cfsetospeed(&term,B19200);
|
||||
break;
|
||||
case 38400:
|
||||
cfsetispeed(&term,B38400);
|
||||
cfsetospeed(&term,B38400);
|
||||
break;
|
||||
case 57600:
|
||||
cfsetispeed(&term,B57600);
|
||||
cfsetospeed(&term,B57600);
|
||||
break;
|
||||
case 115200:
|
||||
cfsetispeed(&term,B115200);
|
||||
cfsetospeed(&term,B115200);
|
||||
break;
|
||||
case 230400:
|
||||
cfsetispeed(&term,B230400);
|
||||
cfsetospeed(&term,B230400);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void setFlow(unsigned char flow)
|
||||
{
|
||||
if(flow == 0)
|
||||
{
|
||||
term.c_iflag&=~(IXON|IXOFF|IXANY|INLCR|ICRNL);
|
||||
}
|
||||
else
|
||||
{
|
||||
term.c_iflag&=~(INLCR|ICRNL|IXANY);
|
||||
term.c_iflag|=(IXON|IXOFF);
|
||||
}
|
||||
}
|
||||
|
||||
void setTimeout(unsigned int tout)
|
||||
{
|
||||
term.c_cc[VMIN]=0;
|
||||
term.c_cc[VTIME]=tout; // 10 seconds timeout
|
||||
}
|
||||
|
||||
int openSerial(char *dev)
|
||||
{
|
||||
|
||||
serialDev=open(dev,O_RDWR);
|
||||
if(serialDev<0)
|
||||
{
|
||||
printf("cannot acces %s\n",dev);
|
||||
return serialDev;
|
||||
}
|
||||
|
||||
tcflush(serialDev, TCIOFLUSH);
|
||||
|
||||
setDTR(0);
|
||||
setRTS(0);
|
||||
|
||||
tcgetattr(serialDev,&term);
|
||||
|
||||
setBaud(TOOLBAUD);
|
||||
|
||||
term.c_cflag = (term.c_cflag & ~CSIZE) | CS8;
|
||||
term.c_cflag |= CLOCAL | CREAD;
|
||||
|
||||
term.c_cflag &= ~(PARENB | PARODD);
|
||||
term.c_cflag &= ~CSTOPB;
|
||||
term.c_iflag=IGNBRK;
|
||||
|
||||
term.c_iflag |= IXON | IXOFF;
|
||||
|
||||
term.c_lflag=0;
|
||||
|
||||
term.c_oflag=0;
|
||||
|
||||
|
||||
setTimeout(5);
|
||||
|
||||
if (tcsetattr(serialDev, TCSANOW, &term)!=0)
|
||||
return printError("setattr stage 1 failed");
|
||||
|
||||
|
||||
if (tcgetattr(serialDev, &term)!=0)
|
||||
return printError("getattr failed");
|
||||
|
||||
|
||||
term.c_cflag &= ~CRTSCTS;
|
||||
|
||||
if (tcsetattr(serialDev, TCSANOW, &term)!=0)
|
||||
return printError("setattr stage 2 failed");
|
||||
|
||||
return serialDev;
|
||||
}
|
||||
|
||||
int closeSerial(void)
|
||||
{
|
||||
if(serialDev)
|
||||
{
|
||||
tcflush(serialDev, TCIOFLUSH);
|
||||
close(serialDev);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return serialDev;
|
||||
}
|
||||
|
||||
int reconfSerial(unsigned int baud, unsigned char flow, unsigned char tout)
|
||||
{
|
||||
if(serialDev > 0)
|
||||
{
|
||||
|
||||
setBaud(baud);
|
||||
setFlow(flow);
|
||||
setTimeout(tout);
|
||||
return tcsetattr(serialDev,TCSANOW,&term);
|
||||
}
|
||||
else
|
||||
return serialDev;
|
||||
}
|
||||
|
||||
#define XFERSIZE 16
|
||||
|
||||
int sendBuf(unsigned int len, char *buf)
|
||||
{
|
||||
unsigned int boff;
|
||||
int ret;
|
||||
|
||||
if(serialDev > 0)
|
||||
{
|
||||
boff = 0;
|
||||
//~ tcflush(serialDev, TCIOFLUSH);
|
||||
while (boff < len)
|
||||
{
|
||||
ret = write (serialDev, buf+boff, MIN (len - boff, XFERSIZE));
|
||||
|
||||
#if 0
|
||||
printf("sent %i: %c\n", ret, *(buf+boff));
|
||||
#endif
|
||||
|
||||
if (ret < 0 && errno != EAGAIN)
|
||||
{
|
||||
perror ("error writing to serial port");
|
||||
return 0;
|
||||
}
|
||||
boff += ret;
|
||||
}
|
||||
return boff;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sendBufE(unsigned int len, char *buf)
|
||||
{
|
||||
return(getBuf(sendBuf(len,buf), buf));
|
||||
}
|
||||
|
||||
int getBuf(unsigned int len, char *buf)
|
||||
{
|
||||
unsigned int boff;
|
||||
int ret;
|
||||
|
||||
if(serialDev > 0)
|
||||
{
|
||||
boff = 0;
|
||||
while (boff < len)
|
||||
{
|
||||
ret = read (serialDev, buf+boff, MIN (len - boff, XFERSIZE));
|
||||
if (ret < 0 && errno != EAGAIN)
|
||||
{
|
||||
perror ("error reading from serial port");
|
||||
return 0;
|
||||
}
|
||||
boff += ret;
|
||||
}
|
||||
return boff;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void setDTR(unsigned char val)
|
||||
{
|
||||
int mcs;
|
||||
if(serialDev)
|
||||
{
|
||||
ioctl (serialDev, TIOCMGET, &mcs);
|
||||
if(val)
|
||||
{
|
||||
mcs |= TIOCM_DTR;
|
||||
ioctl (serialDev, TIOCMSET, &mcs);
|
||||
}
|
||||
else
|
||||
{
|
||||
mcs &= ~TIOCM_DTR;
|
||||
ioctl (serialDev, TIOCMSET, &mcs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setRTS(unsigned char val)
|
||||
{
|
||||
int mcs;
|
||||
if(serialDev)
|
||||
{
|
||||
ioctl (serialDev, TIOCMGET, &mcs);
|
||||
if(val)
|
||||
{
|
||||
mcs |= TIOCM_RTS;
|
||||
ioctl (serialDev, TIOCMSET, &mcs);
|
||||
}
|
||||
else
|
||||
{
|
||||
mcs &= ~TIOCM_RTS;
|
||||
ioctl (serialDev, TIOCMSET, &mcs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
16
lpctool/testing/lpctool_serial.h
Normal file
16
lpctool/testing/lpctool_serial.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#ifndef LPCTOOL_SERIAL_H
|
||||
#define LPCTOOL_SERIAL_H
|
||||
|
||||
#include "baudrate.h"
|
||||
|
||||
int openSerial(char *dev);
|
||||
int closeSerial(void);
|
||||
int reconfSerial(unsigned int baud, unsigned char flow, unsigned char tout);
|
||||
int sendBuf(unsigned int len, char *buf);
|
||||
int getBuf(unsigned int len, char *buf);
|
||||
void setDTR(unsigned char val);
|
||||
void setRTS(unsigned char val);
|
||||
|
||||
extern int serialDev;
|
||||
|
||||
#endif
|
31
lpctool/testing/toolcmd.h
Normal file
31
lpctool/testing/toolcmd.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
#ifndef TOOLCMD_H
|
||||
#define TOOLCMD_H
|
||||
|
||||
#define HELO_CMD '.'
|
||||
#define BULKENABLE_CMD 'B'
|
||||
#define BULKDISABLE_CMD 'X'
|
||||
#define SETADR_CMD 'A'
|
||||
#define FILLBUF_CMD 'F'
|
||||
#define WRITE_CMD 'W'
|
||||
#define WRITEGO_CMD '!'
|
||||
#define SECTERASE_CMD 'P'
|
||||
#define FULLERASE_CMD 'E'
|
||||
#define SETNUMBYTES_CMD 'S'
|
||||
#define READ_CMD 'R'
|
||||
#define SKIP_CMD '>'
|
||||
#define HELOTOKEN "HELO"
|
||||
#define ACKTOKEN "ACK!"
|
||||
#define NACKTOKEN "NACK"
|
||||
#define BACKTOKEN "!"
|
||||
|
||||
#define MIN_GAP 0x10
|
||||
|
||||
typedef struct t_chunk
|
||||
{
|
||||
unsigned long start;
|
||||
unsigned long len;
|
||||
struct t_chunk *prev;
|
||||
struct t_chunk *next;
|
||||
} t_chunk;
|
||||
|
||||
#endif
|
549
lpctool/testing/toolcom.c
Normal file
549
lpctool/testing/toolcom.c
Normal file
|
@ -0,0 +1,549 @@
|
|||
#include "infohelper.h"
|
||||
#include "lpctool_serial.h"
|
||||
#include "toolcom.h"
|
||||
#include "toolcmd.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <termios.h>
|
||||
|
||||
const unsigned long secinfo[20] =
|
||||
{ 0x00000,
|
||||
0x04000,
|
||||
0x06000,
|
||||
0x08000,
|
||||
0x10000,
|
||||
0x20000,
|
||||
0x30000,
|
||||
0x40000,
|
||||
0x50000,
|
||||
0x60000,
|
||||
0x70000,
|
||||
0x80000,
|
||||
0x90000,
|
||||
0xA0000,
|
||||
0xB0000,
|
||||
0xC0000,
|
||||
0xD0000,
|
||||
0xE0000,
|
||||
0xF0000,
|
||||
0x100000 };
|
||||
|
||||
|
||||
struct t_chunk *chunklist = NULL;
|
||||
|
||||
union {
|
||||
unsigned char cbuf[MAXBUF];
|
||||
unsigned short sbuf[MAXBUF/2];
|
||||
unsigned long lbuf[MAXBUF/4];
|
||||
} buffs;
|
||||
|
||||
int makeList(unsigned long *buf, unsigned long len)
|
||||
{
|
||||
unsigned long mlen;
|
||||
t_chunk *mlist;
|
||||
int cnt;
|
||||
unsigned long gap, pos;
|
||||
if(chunklist)
|
||||
freeList();
|
||||
|
||||
mlen = len>>2;
|
||||
gap = 0;
|
||||
pos = 0;
|
||||
cnt = 1;
|
||||
|
||||
if(mlen)
|
||||
{
|
||||
printInfoS(2,"creating list of chunks",0);
|
||||
|
||||
chunklist = malloc(sizeof(t_chunk));
|
||||
|
||||
mlist = chunklist;
|
||||
|
||||
if(mlist)
|
||||
{
|
||||
mlist->start = 0x80000000;
|
||||
mlist->len = 0;
|
||||
mlist->prev = NULL;
|
||||
mlist->next = NULL;
|
||||
}
|
||||
|
||||
while(mlen)
|
||||
{
|
||||
gap = 0;
|
||||
if(buf[pos] != 0xFFFFFFFF)
|
||||
{
|
||||
mlist->len += 4;
|
||||
mlen --;
|
||||
pos ++;
|
||||
}
|
||||
else while(buf[pos] == 0xFFFFFFFF)
|
||||
{
|
||||
gap += 4;
|
||||
pos ++;
|
||||
mlen --;
|
||||
}
|
||||
if(gap)
|
||||
{
|
||||
if(gap >= MIN_GAP)
|
||||
{
|
||||
mlist->next = malloc(sizeof(t_chunk));
|
||||
if(mlist->next)
|
||||
{
|
||||
cnt++;
|
||||
mlist->next->start = chunklist->start + (pos*4);
|
||||
mlist->next->prev = mlist;
|
||||
mlist->next->next = NULL;
|
||||
mlist->next->len = 0;
|
||||
mlist = mlist->next;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
mlist->len += gap;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
printInfoH(2, "chunk entries created:",cnt);
|
||||
return(cnt);
|
||||
}
|
||||
|
||||
void freeList(void)
|
||||
{
|
||||
t_chunk *mlist;
|
||||
int cnt;
|
||||
|
||||
if(chunklist)
|
||||
{
|
||||
mlist = chunklist;
|
||||
cnt = 0;
|
||||
|
||||
while(mlist->next != NULL)
|
||||
{
|
||||
mlist = mlist->next;
|
||||
cnt++;
|
||||
free(mlist->prev);
|
||||
}
|
||||
cnt++;
|
||||
free(mlist);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int getRESULT(unsigned char acktype)
|
||||
{
|
||||
char buf[4];
|
||||
unsigned char q;
|
||||
|
||||
switch(acktype)
|
||||
{
|
||||
case ACK:
|
||||
q = getBuf(4, buf);
|
||||
if(strncmp(buf, ACKTOKEN, 4))
|
||||
{
|
||||
return printError("wrong response, expected ACK!");
|
||||
}
|
||||
return 1;
|
||||
break;
|
||||
|
||||
case HELO:
|
||||
q = getBuf(4, buf);
|
||||
if(strncmp(buf, HELOTOKEN, 4))
|
||||
{
|
||||
return printError("wrong response, expected HELO");
|
||||
}
|
||||
return 1;
|
||||
break;
|
||||
case BACK:
|
||||
q = getBuf(1, buf);
|
||||
if(strncmp(buf, BACKTOKEN, 1))
|
||||
{
|
||||
return printError("wrong response, expected !");
|
||||
}
|
||||
return 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int openRamTool()
|
||||
{
|
||||
unsigned char q;
|
||||
|
||||
//~ char buf = HELO_CMD;
|
||||
char buf[1];
|
||||
buf[0] = HELO_CMD;
|
||||
|
||||
printInfoS(0,"Waiting for FlashTool", 0);
|
||||
usleep(1000000);
|
||||
|
||||
//~ while(1)
|
||||
//~ {
|
||||
tcflush(serialDev, TCIOFLUSH); // flush transmit/recieve buffers
|
||||
|
||||
printInfoC(0,"Sending command HELO_CMD", buf[0]);
|
||||
//~ sendBuf(1, &buf);
|
||||
sendBuf(1, buf);
|
||||
|
||||
//~ write (serialDev, &buf, 1);
|
||||
|
||||
printInfoS(0,"Waiting for token HELO", 0);
|
||||
usleep(100000);
|
||||
|
||||
//~ tcflush(serialDev, TCIOFLUSH);
|
||||
|
||||
//~ reconfSerial(TOOLBAUD, 0, 50); // longer timeout
|
||||
|
||||
q = getRESULT(HELO);
|
||||
|
||||
//~ while (1)
|
||||
//~ {
|
||||
//~ q = getBuf(1, &buf);
|
||||
//~ printInfoU(0,"Got", q);
|
||||
//~ }
|
||||
//~ reconfSerial(TOOLBAUD, 0, 5); // shorter timeout
|
||||
|
||||
printInfoU(0,"FlashTool sent", q);
|
||||
|
||||
//~ if
|
||||
|
||||
//~ }
|
||||
|
||||
return q;
|
||||
}
|
||||
|
||||
int setToolAdr(unsigned long adr)
|
||||
{
|
||||
char buf[5];
|
||||
|
||||
buf[0] = SETADR_CMD;
|
||||
buf[1] =(adr & 0xFF000000) >> 24;
|
||||
buf[2] =(adr & 0x00FF0000) >> 16;
|
||||
buf[3] =(adr & 0x0000FF00) >> 8;
|
||||
buf[4] = adr & 0x000000FF;
|
||||
|
||||
sendBuf(5, buf);
|
||||
|
||||
return getRESULT(ACK);
|
||||
}
|
||||
|
||||
int eraseFlash(void)
|
||||
{
|
||||
char buf[1];
|
||||
printInfoS(0,"erasing flash", 0);
|
||||
buf[0] = FULLERASE_CMD;
|
||||
sendBuf(1, buf);
|
||||
return getRESULT(ACK);
|
||||
}
|
||||
|
||||
int eraseFlashSector(void)
|
||||
{
|
||||
char buf[1];
|
||||
buf[0] = SECTERASE_CMD;
|
||||
sendBuf(1, buf);
|
||||
return getRESULT(ACK);
|
||||
}
|
||||
|
||||
int enableBulk(unsigned char b)
|
||||
{
|
||||
char buf[1];
|
||||
if(b)
|
||||
buf[0] = BULKENABLE_CMD;
|
||||
else
|
||||
buf[0] = BULKDISABLE_CMD;
|
||||
|
||||
sendBuf(1, buf);
|
||||
return getRESULT(ACK);
|
||||
}
|
||||
|
||||
int setNumBytes(unsigned long numBytes)
|
||||
{
|
||||
char buf[5];
|
||||
|
||||
buf[0] = SETNUMBYTES_CMD;
|
||||
buf[1] =(numBytes & 0xFF000000) >> 24;
|
||||
buf[2] =(numBytes & 0x00FF0000) >> 16;
|
||||
buf[3] =(numBytes & 0x0000FF00) >> 8;
|
||||
buf[4] = numBytes & 0x000000FF;
|
||||
|
||||
sendBuf(5, buf);
|
||||
|
||||
return getRESULT(ACK);
|
||||
}
|
||||
|
||||
int writeFlash(void)
|
||||
{
|
||||
char buf[2];
|
||||
|
||||
buf[0] = WRITE_CMD;
|
||||
buf[1] = WRITEGO_CMD;
|
||||
|
||||
tcflush(serialDev, TCIOFLUSH);
|
||||
sendBuf(2, buf);
|
||||
|
||||
return getRESULT(ACK);
|
||||
}
|
||||
|
||||
int uploadBuf(unsigned char nwords, unsigned char* buf)
|
||||
{
|
||||
unsigned short cnt,cnt2, cnt3;
|
||||
unsigned long checksum;
|
||||
char tbuf[6];
|
||||
checksum = 0;
|
||||
tbuf[0] = FILLBUF_CMD;
|
||||
tbuf[1] = nwords;
|
||||
|
||||
if(!sendBuf(2,tbuf))
|
||||
return 0;
|
||||
|
||||
cnt = nwords << 2;
|
||||
cnt2 = 0;
|
||||
|
||||
#define XFERSIZE 16
|
||||
|
||||
while(cnt >= XFERSIZE)
|
||||
{
|
||||
|
||||
cnt3=XFERSIZE;
|
||||
while(cnt3--)
|
||||
checksum += buf[cnt2++];
|
||||
|
||||
if(!sendBuf(XFERSIZE, (char*)buf+cnt2-XFERSIZE))
|
||||
return 0;
|
||||
|
||||
if(!getRESULT(BACK))
|
||||
return 0;
|
||||
|
||||
cnt -= XFERSIZE;
|
||||
}
|
||||
|
||||
if(cnt)
|
||||
{
|
||||
cnt3 = cnt;
|
||||
while(cnt--)
|
||||
checksum += buf[cnt2++];
|
||||
|
||||
if(!sendBuf(cnt3, (char*)buf+cnt2-cnt3))
|
||||
return 0;
|
||||
|
||||
if(!getRESULT(BACK))
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
tbuf[0] = (checksum >> 24) & 0xFF;
|
||||
tbuf[1] = (checksum >> 16) & 0xFF;
|
||||
tbuf[2] = (checksum >> 8) & 0xFF;
|
||||
tbuf[3] = checksum & 0xFF;
|
||||
if(!sendBuf(4, tbuf))
|
||||
return 0;
|
||||
|
||||
return getRESULT(ACK);
|
||||
}
|
||||
|
||||
int uploadChunks(int fd, unsigned long loc, unsigned int erase)
|
||||
{
|
||||
unsigned long fsize, cnt, total, csize;
|
||||
unsigned char buf[MAXBUF];
|
||||
unsigned int numChunks;
|
||||
t_chunk *curr_chunk;
|
||||
|
||||
if(!setToolAdr(loc))
|
||||
{
|
||||
freeList();
|
||||
return printError("failed to set address");
|
||||
}
|
||||
|
||||
if(erase & 0x40)
|
||||
{
|
||||
printInfoS(2,"erasing flash sector", 0);
|
||||
if(!eraseFlashSector())
|
||||
return printError("failed to erase start sector");
|
||||
printInfoS(2,"flash sector erased", 0);
|
||||
}
|
||||
else if((erase & 0x20) || (erase & 0x10))
|
||||
{
|
||||
printInfoS(2,"erasing whole flash", 0);
|
||||
reconfSerial(TOOLBAUD, 0, 200);
|
||||
|
||||
if(!eraseFlash())
|
||||
return printError("failed to erase whole flash");
|
||||
reconfSerial(TOOLBAUD, 0, 5);
|
||||
|
||||
printInfoS(2,"whole flash erased", 0);
|
||||
}
|
||||
|
||||
printInfoS(2,"enabling bulk write",0);
|
||||
if(!enableBulk(1))
|
||||
return printError("bulk write enable failed");
|
||||
|
||||
fsize = read(fd, buf, MAXBUF);
|
||||
total = fsize;
|
||||
cnt = 0;
|
||||
|
||||
printInfoH(2,"setting total number of bytes to", fsize);
|
||||
if(!setNumBytes(fsize))
|
||||
return printError("cannot set total number of bytes");
|
||||
|
||||
printInfoS(0,"starting flash upload (chunk mode)", 0);
|
||||
|
||||
numChunks = makeList((unsigned long*)buf, fsize);
|
||||
curr_chunk = chunklist;
|
||||
|
||||
printProgress(0,"Flash",cnt,total);
|
||||
|
||||
while(numChunks--)
|
||||
{
|
||||
if(!setToolAdr(curr_chunk->start))
|
||||
{
|
||||
freeList();
|
||||
return printError("failed to set address");
|
||||
}
|
||||
|
||||
csize = curr_chunk->len;
|
||||
cnt = curr_chunk->start & 0x00FFFFFF;
|
||||
|
||||
while(csize >= 512)
|
||||
{
|
||||
if(!uploadBuf(128, buf+cnt))
|
||||
{
|
||||
freeList();
|
||||
return printError("buffer upload failed");;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!writeFlash())
|
||||
{
|
||||
freeList();
|
||||
return printError("flash write failed");;
|
||||
}
|
||||
}
|
||||
csize -= 512;
|
||||
cnt += 512;
|
||||
printProgress(0,"Flash",cnt,total);
|
||||
}
|
||||
if(csize)
|
||||
{
|
||||
if(!uploadBuf(csize>>2, buf+cnt))
|
||||
{
|
||||
freeList();
|
||||
return printError("buffer upload failed");;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!writeFlash())
|
||||
{
|
||||
freeList();
|
||||
return printError("flash write failed");;
|
||||
}
|
||||
}
|
||||
csize = 0;
|
||||
printProgress(0,"Flash",cnt,total);
|
||||
}
|
||||
|
||||
curr_chunk = curr_chunk->next;
|
||||
}
|
||||
|
||||
printProgress(0,"Flash",total,total);
|
||||
|
||||
freeList();
|
||||
|
||||
if(!enableBulk(0))
|
||||
return printError("bulk write disable failed");;
|
||||
|
||||
printInfoH(0,"flash upload (chunk mode) complete, total bytes:", total);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int uploadFlash(int fd, unsigned long loc, unsigned int erase)
|
||||
{
|
||||
unsigned long fsize, cnt, total;
|
||||
unsigned char buf[MAXBUF];
|
||||
|
||||
printInfoH(2,"setting address to", loc);
|
||||
if(!setToolAdr(loc))
|
||||
return printError("failed to set address");
|
||||
|
||||
if(erase & 0x40)
|
||||
{
|
||||
printInfoS(2,"erasing flash sector", 0);
|
||||
if(!eraseFlashSector())
|
||||
return printError("failed to erase start sector");
|
||||
printInfoS(2,"flash sector erased", 0);
|
||||
}
|
||||
else if((erase & 0x20) || (erase & 0x10))
|
||||
{
|
||||
printInfoS(2,"erasing whole flash", 0);
|
||||
reconfSerial(TOOLBAUD, 0, 200);
|
||||
|
||||
if(!eraseFlash())
|
||||
return printError("failed to erase whole flash");
|
||||
reconfSerial(TOOLBAUD, 0, 5);
|
||||
|
||||
printInfoS(2,"whole flash erased", 0);
|
||||
}
|
||||
|
||||
printInfoS(2,"enabling bulk write",0);
|
||||
if(!enableBulk(1))
|
||||
return printError("bulk write enable failed");
|
||||
|
||||
fsize = read(fd, buf, MAXBUF);
|
||||
|
||||
printInfoH(2,"setting total number of bytes to", fsize);
|
||||
if(!setNumBytes(fsize))
|
||||
return printError("cannot set total number of bytes");
|
||||
|
||||
cnt = 0;
|
||||
total = fsize;
|
||||
|
||||
printInfoS(0,"starting flash upload", 0);
|
||||
printProgress(0,"Flash",cnt,total);
|
||||
|
||||
while(fsize >= 512)
|
||||
{
|
||||
if(!uploadBuf(128, buf+cnt))
|
||||
{
|
||||
return printError("buffer upload failed");;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!writeFlash())
|
||||
return printError("flash write failed");;
|
||||
}
|
||||
fsize -= 512;
|
||||
cnt += 512;
|
||||
printProgress(0,"Flash",cnt,total);
|
||||
}
|
||||
|
||||
if(fsize)
|
||||
{
|
||||
if(!uploadBuf(fsize>>2, buf+cnt))
|
||||
{
|
||||
return printError("buffer upload failed");;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!writeFlash())
|
||||
return printError("flash write failed");;
|
||||
}
|
||||
fsize = 0;
|
||||
printProgress(0,"Flash",total,total);
|
||||
}
|
||||
|
||||
if(!enableBulk(0))
|
||||
return printError("bulk write disable failed");;
|
||||
|
||||
printInfoH(0,"flash upload complete, total bytes:", total);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
21
lpctool/testing/toolcom.h
Normal file
21
lpctool/testing/toolcom.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
#ifndef TOOLCOM_H
|
||||
#define TOOLCOM_H
|
||||
|
||||
#define ACK 0x00
|
||||
#define HELO 0x01
|
||||
#define BACK 0x02
|
||||
|
||||
#define MAXBUF 0x00100000
|
||||
|
||||
int makeList(unsigned long *buf, unsigned long len);
|
||||
void freeList(void);
|
||||
int openRamTool();
|
||||
int setToolAdr(unsigned long adr);
|
||||
int eraseFlash(void);
|
||||
int writeFlash(void);
|
||||
int enableBulk(unsigned char b);
|
||||
int setNumBytes(unsigned long numBytes);
|
||||
int uploadFlash(int fd, unsigned long loc, unsigned int erase);
|
||||
int uploadChunks(int fd, unsigned long loc, unsigned int erase);
|
||||
|
||||
#endif
|
8
lpctool/trunk/ChangeLog
Normal file
8
lpctool/trunk/ChangeLog
Normal file
|
@ -0,0 +1,8 @@
|
|||
2007-10-05 Simon Budig <simon@budig.de>
|
||||
|
||||
toolcom.c: added info line for flash erase.
|
||||
|
||||
2007-10-05 Ch. Klippel <ck@mamalala.net>
|
||||
|
||||
*/* initial import into SVN
|
||||
|
114
lpctool/trunk/Makefile
Normal file
114
lpctool/trunk/Makefile
Normal file
|
@ -0,0 +1,114 @@
|
|||
###############################################################
|
||||
#####
|
||||
##### Makefile for ramtool and lpctool
|
||||
#####
|
||||
###############################################################
|
||||
|
||||
###############################################################
|
||||
#####
|
||||
##### PATHS (default installation)
|
||||
#####
|
||||
###############################################################
|
||||
|
||||
ARMBASE=/opt/summon-arm-toolchain
|
||||
INCLUDEPATH=$(ARMBASE)/include
|
||||
LIBPATH=$(ARMBASE)/arm-elf/lib/interwork
|
||||
ARMPATH=$(ARMBASE)/bin
|
||||
TOOLPREFIX=/arm-none-eabi-
|
||||
|
||||
INSTALLDIR_BIN=/usr/local/bin
|
||||
|
||||
-include Makefile.local
|
||||
|
||||
###############################################################
|
||||
#####
|
||||
##### Compiler, Linker and Tools
|
||||
#####
|
||||
###############################################################
|
||||
|
||||
CC=$(ARMPATH)$(TOOLPREFIX)gcc
|
||||
AS=$(ARMPATH)$(TOOLPREFIX)as
|
||||
LD=$(ARMPATH)$(TOOLPREFIX)ld
|
||||
OC=$(ARMPATH)$(TOOLPREFIX)objcopy
|
||||
OD=$(ARMPATH)$(TOOLPREFIX)objdump
|
||||
|
||||
CPUFLAGS=-mcpu=arm7tdmi-s
|
||||
OPTFLAGS=-Os
|
||||
#OPTFLAGS=-O0
|
||||
#OPTFLAGS=
|
||||
CFLAGS=$(CPUFLAGS) -c -Wall -mthumb-interwork -msoft-float -I$(INCLUDEPATH)
|
||||
ASFLAGS=$(CPUFLAGS) -D --gstabs -mthumb-interwork -mfpu=softfpa
|
||||
LDFLAGS=$(OPTFLAGS) -Tlpc2220.ld
|
||||
ROMLDFLAGS=$(OPTFLAGS) -Tlpc2220_rom.ld
|
||||
|
||||
###############################################################
|
||||
#####
|
||||
##### Do the whole shabang
|
||||
#####
|
||||
###############################################################
|
||||
|
||||
all: ramtool.bin romtool.bin lpctool
|
||||
|
||||
ramtool.bin: ramtool.elf
|
||||
$(OC) -O binary ramtool.elf ramtool.bin
|
||||
|
||||
ramtool.elf: crt.o serial.o lcd.o fonty.o flash.o ramtool.o lpc2220.ld
|
||||
$(LD) $(LDFLAGS) -o ramtool.elf crt.o serial.o lcd.o fonty.o flash.o ramtool.o
|
||||
|
||||
romtool.bin: romtool.elf
|
||||
$(OC) -O binary romtool.elf romtool.bin
|
||||
|
||||
romtool.elf: crt.o serial.o lcd.o fonty.o flash.o romtool.o lpc2220_rom.ld
|
||||
$(LD) $(ROMLDFLAGS) -o romtool.elf crt.o serial.o lcd.o fonty.o flash.o romtool.o
|
||||
|
||||
crt.o: crt.s
|
||||
$(AS) $(ASFLAGS) -o crt.o crt.s
|
||||
|
||||
flash.o: flash.c flash.h serial.h lcd.h
|
||||
$(CC) $(CFLAGS) -o flash.o flash.c
|
||||
|
||||
lcd.o: lcd.c lcd.h lpc2220.h
|
||||
$(CC) $(CFLAGS) -o lcd.o lcd.c
|
||||
|
||||
fonty.o: fonty.c fonty.h charset.bits charset.info lcd.h
|
||||
$(CC) $(CFLAGS) -o fonty.o fonty.c
|
||||
|
||||
serial.o: serial.c serial.h lcd.h lpc2220.h
|
||||
$(CC) $(CFLAGS) -o serial.o serial.c
|
||||
|
||||
ramtool.o: ramtool.c serial.o lcd.h flash.h lpc2220.h
|
||||
$(CC) $(CFLAGS) -o ramtool.o ramtool.c
|
||||
|
||||
romtool.o: ramtool.c serial.o lcd.h flash.h lpc2220.h
|
||||
$(CC) $(CFLAGS) -DRESIDENT -o romtool.o ramtool.c
|
||||
|
||||
bin2h: bin2h.c ramtool.bin
|
||||
gcc -Os bin2h.c -o bin2h
|
||||
strip bin2h
|
||||
|
||||
tool_data.h: bin2h
|
||||
./bin2h > tool_data.h
|
||||
|
||||
lpctool: infohelper.c lpctool_serial.c bootcom.c toolcom.c lpctool.c infohelper.h lpctool_serial.h bootcom.h toolcom.h tool_data.h
|
||||
gcc -Os infohelper.c lpctool_serial.c bootcom.c toolcom.c lpctool.c -o lpctool
|
||||
strip lpctool
|
||||
|
||||
upload: lpctool
|
||||
./lpctool -i -v
|
||||
|
||||
resident: romtool.bin lpctool
|
||||
./lpctool -S -i -a romtool.bin -v
|
||||
|
||||
uresident: romtool.bin lpctool
|
||||
./lpctool -d /dev/ttyUSB0 -S -i -a romtool.bin -v
|
||||
|
||||
install: lpctool
|
||||
cp lpctool $(INSTALLDIR_BIN)
|
||||
|
||||
uninstall:
|
||||
rm $(INSTALLDIR_BIN)/lpctool
|
||||
|
||||
clean:
|
||||
$(RM) *.o ramtool.elf ramtool.bin romtool.elf romtool.bin *~ lpctool tool_data.h bin2h
|
||||
|
||||
### EOF
|
25
lpctool/trunk/Makefile.local.WinARM
Normal file
25
lpctool/trunk/Makefile.local.WinARM
Normal file
|
@ -0,0 +1,25 @@
|
|||
###############################################################
|
||||
#####
|
||||
##### Makefile.local.WinARM for boop
|
||||
##### Created in the early morninghours
|
||||
#####
|
||||
##### Makefile.local.WinARM V1.0 by alterego - alteregon@gmx.net
|
||||
#####
|
||||
###############################################################
|
||||
|
||||
###############################################################
|
||||
#####
|
||||
##### PATHS (default installation)
|
||||
#####
|
||||
##### You can put your path-config into Makefile.local
|
||||
##### to override these defaults
|
||||
#####
|
||||
###############################################################
|
||||
|
||||
ARMBASE=c:/WinARM/
|
||||
INCLUDEPATH=$(ARMBASE)/include
|
||||
LIBPATH=$(ARMBASE)/arm-elf/lib/interwork
|
||||
ARMPATH=$(ARMBASE)/bin
|
||||
TOOLPREFIX=/arm-elf-
|
||||
|
||||
######################## EOF ##################################
|
25
lpctool/trunk/Makefile.local.linuxARM
Normal file
25
lpctool/trunk/Makefile.local.linuxARM
Normal file
|
@ -0,0 +1,25 @@
|
|||
###############################################################
|
||||
#####
|
||||
##### Makefile.local.linuxARM for boop
|
||||
##### Created in the early morninghours
|
||||
#####
|
||||
##### Makefile.local.linuxARM
|
||||
#####
|
||||
###############################################################
|
||||
|
||||
###############################################################
|
||||
#####
|
||||
##### PATHS (default installation)
|
||||
#####
|
||||
##### You can put your path-config into Makefile.local
|
||||
##### to override these defaults
|
||||
#####
|
||||
###############################################################
|
||||
|
||||
ARMBASE=/opt/arm-elf
|
||||
INCLUDEPATH=$(ARMBASE)/include
|
||||
LIBPATH=$(ARMBASE)/lib/gcc/arm-elf/4.1.1/interwork
|
||||
ARMPATH=$(ARMBASE)/bin
|
||||
TOOLPREFIX=/arm-elf-
|
||||
|
||||
######################## EOF ##################################
|
30
lpctool/trunk/bin2h.c
Normal file
30
lpctool/trunk/bin2h.c
Normal file
|
@ -0,0 +1,30 @@
|
|||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
#include <fcntl.h>
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int fd;
|
||||
unsigned long cnt, cnt2;
|
||||
unsigned char buf[0x10000];
|
||||
|
||||
fd = open("ramtool.bin", O_RDONLY);
|
||||
|
||||
if(fd)
|
||||
{
|
||||
cnt = read(fd, buf, 0x10000);
|
||||
cnt2 = 0;
|
||||
printf("#define tool_len 0x%08X\n",cnt);
|
||||
printf("const unsigned char tool_data[] = {\n\t");
|
||||
while(cnt--)
|
||||
{
|
||||
printf("0x%02X,",buf[cnt2++]);
|
||||
if((cnt2 & 0x0F) == 0)
|
||||
printf("\n\t");
|
||||
}
|
||||
printf("\n};\n");
|
||||
close(fd);
|
||||
}
|
||||
return 0;
|
||||
}
|
307
lpctool/trunk/bootcom.c
Normal file
307
lpctool/trunk/bootcom.c
Normal file
|
@ -0,0 +1,307 @@
|
|||
#include "infohelper.h"
|
||||
#include "lpctool_serial.h"
|
||||
#include "bootcom.h"
|
||||
#include "tool_data.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <termios.h>
|
||||
|
||||
unsigned int uuencode(unsigned char *ibuf, unsigned char *obuf, int len)
|
||||
{
|
||||
unsigned int slen, r,s;
|
||||
unsigned char q;
|
||||
slen = len;
|
||||
|
||||
r = 0;
|
||||
s = 0;
|
||||
|
||||
while(slen >= 45)
|
||||
{
|
||||
|
||||
obuf[r++]=77;
|
||||
for(q=0;q<45;q+=3)
|
||||
{
|
||||
|
||||
obuf[r++]=0x20+(( ibuf[s]>>2)&0x3f);
|
||||
obuf[r++]=0x20+(((ibuf[s]<<4) | (ibuf[s+1]>>4))&0x3f);
|
||||
s++;
|
||||
obuf[r++]=0x20+(((ibuf[s]<<2)|(ibuf[s+1]>>6))&0x3f);
|
||||
s++;
|
||||
obuf[r++]=0x20+( ibuf[s++]&0x3f);
|
||||
}
|
||||
obuf[r++] = '\r';
|
||||
obuf[r++] = '\n';
|
||||
slen -= 45;
|
||||
}
|
||||
|
||||
if(slen)
|
||||
{
|
||||
obuf[r++]=0x20+slen;
|
||||
for(q=0;q<slen;q+=3)
|
||||
{
|
||||
obuf[r++]=0x20+(( ibuf[s]>>2)&0x3f);
|
||||
obuf[r++]=0x20+(((ibuf[s]<<4) | (ibuf[s+1]>>4))&0x3f);
|
||||
s++;
|
||||
obuf[r++]=0x20+(((ibuf[s]<<2)|(ibuf[s+1]>>6))&0x3f);
|
||||
s++;
|
||||
obuf[r++]=0x20+( ibuf[s++]&0x3f);
|
||||
}
|
||||
obuf[r++] = '\r';
|
||||
obuf[r++] = '\n';
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void printBuf(unsigned char len, unsigned char *buf)
|
||||
{
|
||||
unsigned char cnt;
|
||||
cnt = 0;
|
||||
while(len--)
|
||||
printf("%c",buf[cnt++]);
|
||||
}
|
||||
|
||||
int getOK(unsigned char oktype)
|
||||
{
|
||||
char buf[4];
|
||||
unsigned char q;
|
||||
|
||||
switch(oktype)
|
||||
{
|
||||
case OK_LIT:
|
||||
q = getBuf(4, buf);
|
||||
if(strncmp(buf, "OK\r\n", 4))
|
||||
{
|
||||
return printError("wrong response, expected OK");
|
||||
}
|
||||
return 1;
|
||||
break;
|
||||
|
||||
case OK_0:
|
||||
q = getBuf(3, buf);
|
||||
if(strncmp(buf, "0", 1))
|
||||
{
|
||||
return printError("wrong response, expected 0");
|
||||
}
|
||||
return 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int openBootLoader(unsigned int cfreq)
|
||||
{
|
||||
char buf[20];
|
||||
unsigned char q;
|
||||
|
||||
printInfoS(2,"initiating auto-baud",0);
|
||||
sendBuf(sprintf(buf, "?\r\n"), buf);
|
||||
|
||||
printInfoS(2,"awaiting autobaud response",0);
|
||||
|
||||
q = getBuf(14, buf);
|
||||
|
||||
if(strncmp(buf, "Synchronized\r\n", 14))
|
||||
{
|
||||
return printError("autobaud detection failed");
|
||||
}
|
||||
|
||||
printInfoS(2,"got response, answering",0);
|
||||
|
||||
q = sendBufE(q, buf);
|
||||
|
||||
if(!getOK(OK_LIT))
|
||||
{
|
||||
return printError("cant synchronize bootloader");
|
||||
}
|
||||
|
||||
printInfoS(2,"setting frequency",0);
|
||||
|
||||
sendBufE(sprintf(buf, "%i\r\n", cfreq), buf);
|
||||
|
||||
if(!getOK(OK_LIT))
|
||||
{
|
||||
return printError("cant set frequency");
|
||||
}
|
||||
|
||||
printInfoS(2,"switching baudrate",0);
|
||||
|
||||
sendBufE(sprintf(buf, "B 38400 1\r\n"), buf);
|
||||
|
||||
if(!getOK(OK_0))
|
||||
{
|
||||
return printError("cant set baudrate");
|
||||
}
|
||||
|
||||
reconfSerial(38400, 1, 10);
|
||||
|
||||
printInfoS(2,"disabling echo",0);
|
||||
|
||||
sendBufE(sprintf(buf, "A 0\r\n"), buf);
|
||||
|
||||
if(!getOK(OK_0))
|
||||
{
|
||||
return printError("cant disable echo");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int unlockBootLoader(void)
|
||||
{
|
||||
char buf[20];
|
||||
|
||||
sendBuf(sprintf(buf, "U 23130\r\n"), buf);
|
||||
|
||||
if(!getOK(OK_0))
|
||||
{
|
||||
return printError("cant unlock bootloader");
|
||||
}
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
int goBootLoader(unsigned long addr)
|
||||
{
|
||||
char buf[20];
|
||||
|
||||
sendBuf(sprintf(buf, "G %i A\r\n", addr), buf);
|
||||
|
||||
if(!getOK(OK_0))
|
||||
{
|
||||
return printError("cant issue go command");;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define BSIZE 400
|
||||
|
||||
int uploadData(unsigned long addr, unsigned long len, unsigned char *ibuf)
|
||||
{
|
||||
char buf[128];
|
||||
unsigned char uubuf[BSIZE*3];
|
||||
unsigned int blen, csum;
|
||||
unsigned long slen, saddr, soff;
|
||||
slen = len;
|
||||
saddr = addr;
|
||||
soff = 0;
|
||||
|
||||
if(addr & 0x3)
|
||||
{
|
||||
return printError("RAM address not on dword boundary");
|
||||
}
|
||||
|
||||
while(slen >= BSIZE)
|
||||
{
|
||||
sendBuf(sprintf(buf, "W %i %i\r\n", saddr+soff, BSIZE), buf);
|
||||
if(!getOK(OK_0))
|
||||
{
|
||||
return printError("cant write data");
|
||||
}
|
||||
|
||||
csum = 0;
|
||||
|
||||
for(blen = 0; blen < BSIZE; blen++)
|
||||
{
|
||||
csum += ibuf[soff+blen];
|
||||
}
|
||||
|
||||
blen = uuencode(ibuf+soff, uubuf, BSIZE);
|
||||
sendBuf(blen, (char*)uubuf);
|
||||
sendBuf(sprintf(buf, "%u\r\n", csum), buf);
|
||||
if(!getOK(OK_LIT))
|
||||
{
|
||||
return printError("error in checksum");
|
||||
}
|
||||
slen -= BSIZE;
|
||||
soff += BSIZE;
|
||||
}
|
||||
|
||||
if(slen)
|
||||
{
|
||||
sendBuf(sprintf(buf, "W %i %i\r\n", saddr+soff, slen), buf);
|
||||
if(!getOK(OK_0))
|
||||
{
|
||||
|
||||
return printError("cant write remaining data");
|
||||
}
|
||||
|
||||
csum = 0;
|
||||
|
||||
for(blen = 0; blen < slen; blen++)
|
||||
{
|
||||
csum += ibuf[soff+blen];
|
||||
}
|
||||
|
||||
blen = uuencode(ibuf+soff, uubuf, slen);
|
||||
sendBuf(blen, (char*)uubuf);
|
||||
sendBuf(sprintf(buf, "%i\r\n", csum), buf);
|
||||
|
||||
if(!getOK(OK_LIT))
|
||||
{
|
||||
return printError("error in checksum for remaining data");
|
||||
}
|
||||
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int uploadRAM(int fd, int loc)
|
||||
{
|
||||
unsigned char buf[70000];
|
||||
|
||||
unsigned long fx, total, size;
|
||||
total = 0;
|
||||
|
||||
if(fd)
|
||||
{
|
||||
printInfoS(2,"reading image into buffer", 0);
|
||||
fx = read(fd,buf,70000);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(fx=0; fx<tool_len; fx++)
|
||||
{
|
||||
buf[fx] = tool_data[fx];
|
||||
}
|
||||
fx = tool_len;
|
||||
}
|
||||
|
||||
size = fx;
|
||||
|
||||
printInfoS(0,"starting ram upload", 0);
|
||||
|
||||
printProgress(0,"RAM",total,fx);
|
||||
|
||||
while(fx)
|
||||
{
|
||||
if(fx >= 256)
|
||||
{
|
||||
if(!uploadData(loc+total, 256, buf+total))
|
||||
{
|
||||
return printError("Error in upload");
|
||||
}
|
||||
total += 256;
|
||||
fx -= 256;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!uploadData(loc+total, fx, buf+total))
|
||||
{
|
||||
return printError("Error in upload");
|
||||
}
|
||||
total += fx;
|
||||
fx -= fx;
|
||||
}
|
||||
|
||||
printProgress(0,"RAM",total,size);
|
||||
}
|
||||
|
||||
printInfoH(0,"ram upload complete, total bytes:", total);
|
||||
|
||||
return 1;
|
||||
}
|
12
lpctool/trunk/bootcom.h
Normal file
12
lpctool/trunk/bootcom.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#ifndef BOOTCOM_H
|
||||
#define BOOTCOM_H
|
||||
|
||||
#define OK_LIT 0x00
|
||||
#define OK_0 0x01
|
||||
|
||||
unsigned int uuencode(unsigned char *ibuf, unsigned char *obuf, int len);
|
||||
int openBootLoader(unsigned int cfreq);
|
||||
int uploadData(unsigned long addr, unsigned long len, unsigned char *ibuf);
|
||||
int uploadRAM(int fd, int loc);
|
||||
|
||||
#endif
|
118
lpctool/trunk/charset.bits
Normal file
118
lpctool/trunk/charset.bits
Normal file
|
@ -0,0 +1,118 @@
|
|||
const unsigned char charset_bits[] = {
|
||||
0x80, 0xc0, 0x80, 0xe0, 0x80, 0xc0, 0x80, 0xf0, 0x01, 0x03, 0x01, 0x07,
|
||||
0x01, 0x03, 0x01, 0x0f, 0x80, 0x88, 0xaa, 0xff, 0xff, 0xaa, 0x88, 0x80,
|
||||
0x00, 0xc0, 0x00, 0xe0, 0x00, 0xc0, 0x00, 0xf0, 0x00, 0x03, 0x00, 0x07,
|
||||
0x00, 0x03, 0x00, 0x0f, 0x80, 0x88, 0xaa, 0xab, 0xab, 0xaa, 0x88, 0x80,
|
||||
0x80, 0x80, 0x80, 0x70, 0x01, 0x01, 0x01, 0x0e, 0x0e, 0x01, 0x01, 0x01,
|
||||
0x70, 0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0x00, 0x00, 0x80, 0x00, 0x24,
|
||||
0x00, 0x80, 0x00, 0x00, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x80, 0x00, 0x80,
|
||||
0x00, 0x80, 0x00, 0x92, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0xaa,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0x80, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0xaa, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x81,
|
||||
0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0xaa, 0x02, 0x05, 0x02, 0x00,
|
||||
0x3e, 0x41, 0x41, 0x22, 0x02, 0x05, 0x02, 0x00, 0x7f, 0x09, 0x09, 0x01,
|
||||
0x1c, 0x22, 0x41, 0x4f, 0x41, 0x22, 0x1c, 0x1c, 0x22, 0x41, 0x4f, 0x47,
|
||||
0x22, 0x1c, 0x1c, 0x22, 0x41, 0x4f, 0x4f, 0x2e, 0x1c, 0x1c, 0x22, 0x41,
|
||||
0x4f, 0x5f, 0x3e, 0x1c, 0x1c, 0x22, 0x41, 0x7f, 0x7f, 0x3e, 0x1c, 0x1c,
|
||||
0x22, 0x71, 0x7f, 0x7f, 0x3e, 0x1c, 0x1c, 0x3a, 0x79, 0x7f, 0x7f, 0x3e,
|
||||
0x1c, 0x1c, 0x3e, 0x7d, 0x7f, 0x7f, 0x3e, 0x1c, 0x1c, 0x3e, 0x7f, 0x7f,
|
||||
0x7f, 0x3e, 0x1c, 0x00, 0x00, 0x5f, 0x03, 0x00, 0x03, 0x14, 0x7f, 0x14,
|
||||
0x7f, 0x14, 0x24, 0x4a, 0xff, 0x4a, 0x32, 0x63, 0x13, 0x08, 0x64, 0x63,
|
||||
0x36, 0x49, 0x55, 0x22, 0x50, 0x03, 0x1c, 0x22, 0x41, 0x41, 0x22, 0x1c,
|
||||
0x14, 0x08, 0x3e, 0x08, 0x14, 0x08, 0x08, 0x3e, 0x08, 0x08, 0x80, 0x60,
|
||||
0x60, 0x08, 0x08, 0x08, 0x08, 0x08, 0x60, 0x60, 0xc0, 0x30, 0x0c, 0x03,
|
||||
0x3e, 0x51, 0x49, 0x45, 0x3e, 0x00, 0x42, 0x7f, 0x40, 0x00, 0x42, 0x61,
|
||||
0x51, 0x49, 0x46, 0x22, 0x41, 0x49, 0x49, 0x36, 0x18, 0x14, 0x12, 0x7f,
|
||||
0x10, 0x27, 0x45, 0x45, 0x45, 0x39, 0x3e, 0x49, 0x49, 0x49, 0x32, 0x61,
|
||||
0x11, 0x09, 0x05, 0x03, 0x36, 0x49, 0x49, 0x49, 0x36, 0x26, 0x49, 0x49,
|
||||
0x49, 0x3e, 0x6c, 0x6c, 0x80, 0x6c, 0x6c, 0x08, 0x14, 0x22, 0x41, 0x14,
|
||||
0x14, 0x14, 0x14, 0x41, 0x22, 0x14, 0x08, 0x02, 0x01, 0x51, 0x09, 0x06,
|
||||
0x3e, 0x41, 0x59, 0x55, 0x5e, 0x7e, 0x09, 0x09, 0x09, 0x7e, 0x7f, 0x49,
|
||||
0x49, 0x49, 0x36, 0x3e, 0x41, 0x41, 0x41, 0x22, 0x7f, 0x41, 0x41, 0x41,
|
||||
0x3e, 0x7f, 0x49, 0x49, 0x41, 0x41, 0x7f, 0x09, 0x09, 0x01, 0x01, 0x3e,
|
||||
0x41, 0x41, 0x49, 0x3a, 0x7f, 0x08, 0x08, 0x08, 0x7f, 0x41, 0x7f, 0x41,
|
||||
0x30, 0x41, 0x41, 0x41, 0x3f, 0x7f, 0x08, 0x14, 0x22, 0x41, 0x7f, 0x40,
|
||||
0x40, 0x40, 0x40, 0x7f, 0x02, 0x0c, 0x02, 0x7f, 0x7f, 0x02, 0x04, 0x08,
|
||||
0x7f, 0x3e, 0x41, 0x41, 0x41, 0x3e, 0x7f, 0x09, 0x09, 0x09, 0x06, 0x3e,
|
||||
0x41, 0x41, 0x41, 0xbe, 0x7f, 0x09, 0x09, 0x09, 0x76, 0x26, 0x49, 0x49,
|
||||
0x49, 0x32, 0x01, 0x01, 0x7f, 0x01, 0x01, 0x3f, 0x40, 0x40, 0x40, 0x3f,
|
||||
0x1f, 0x20, 0x40, 0x20, 0x1f, 0x7f, 0x20, 0x10, 0x20, 0x7f, 0x41, 0x22,
|
||||
0x1c, 0x22, 0x41, 0x07, 0x08, 0x70, 0x08, 0x07, 0x61, 0x51, 0x49, 0x45,
|
||||
0x43, 0x7f, 0x41, 0x41, 0x03, 0x0c, 0x30, 0xc0, 0x41, 0x41, 0x7f, 0x02,
|
||||
0x01, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01, 0x02, 0x20, 0x54, 0x54,
|
||||
0x78, 0x7f, 0x48, 0x48, 0x30, 0x38, 0x44, 0x44, 0x24, 0x30, 0x48, 0x48,
|
||||
0x7f, 0x38, 0x54, 0x54, 0x18, 0x08, 0x7e, 0x09, 0x02, 0x98, 0xa4, 0xa4,
|
||||
0x78, 0x7f, 0x08, 0x08, 0x70, 0x44, 0x7d, 0x40, 0x44, 0x84, 0x7d, 0x7f,
|
||||
0x10, 0x28, 0x44, 0x41, 0x7f, 0x40, 0x7c, 0x04, 0x18, 0x04, 0x78, 0x7c,
|
||||
0x08, 0x04, 0x78, 0x38, 0x44, 0x44, 0x38, 0xfc, 0x24, 0x24, 0x18, 0x18,
|
||||
0x24, 0x24, 0xfc, 0x7c, 0x08, 0x04, 0x08, 0x48, 0x54, 0x54, 0x24, 0x04,
|
||||
0x3f, 0x44, 0x3c, 0x40, 0x20, 0x7c, 0x1c, 0x20, 0x40, 0x20, 0x1c, 0x3c,
|
||||
0x40, 0x30, 0x40, 0x3c, 0x44, 0x28, 0x10, 0x28, 0x44, 0x9c, 0xa0, 0xa0,
|
||||
0x7c, 0x64, 0x54, 0x54, 0x4c, 0x08, 0x36, 0x41, 0x77, 0x41, 0x36, 0x08,
|
||||
0x08, 0x08, 0x2a, 0x1c, 0x08, 0x08, 0x1c, 0x2a, 0x08, 0x08, 0x00, 0x00,
|
||||
0x00, 0xdf, 0xdf, 0x07, 0x07, 0x00, 0x07, 0x07, 0x14, 0x3e, 0x14, 0x3e,
|
||||
0x14, 0x24, 0x4a, 0xff, 0x4a, 0x32, 0xf3, 0xfb, 0x18, 0xdf, 0xc7, 0x36,
|
||||
0x49, 0x55, 0x22, 0x50, 0x04, 0x07, 0x03, 0x3c, 0x7e, 0xc3, 0x81, 0x81,
|
||||
0xc3, 0x7e, 0x3c, 0x14, 0x08, 0x3e, 0x08, 0x14, 0x18, 0x7e, 0x7e, 0x18,
|
||||
0x80, 0x60, 0x60, 0x18, 0x18, 0x18, 0x18, 0x18, 0x60, 0x60, 0xc0, 0xf0,
|
||||
0x3c, 0x0f, 0x03, 0x7e, 0xff, 0xc3, 0xff, 0x7e, 0x04, 0xc6, 0xff, 0xff,
|
||||
0xc0, 0xe6, 0xf7, 0xd3, 0xdf, 0xce, 0x42, 0xc3, 0xdb, 0xff, 0x76, 0x38,
|
||||
0x3c, 0x36, 0xff, 0xff, 0x5f, 0xdf, 0xdb, 0xfb, 0x73, 0x7e, 0xff, 0xdb,
|
||||
0xfb, 0x72, 0x03, 0xf3, 0xfb, 0x0f, 0x07, 0x76, 0xff, 0xdb, 0xff, 0x76,
|
||||
0x4e, 0xdf, 0xdb, 0xff, 0x7e, 0x6c, 0x6c, 0x80, 0x6c, 0x6c, 0x18, 0x3c,
|
||||
0x66, 0xc3, 0x81, 0x36, 0x36, 0x36, 0x36, 0x81, 0xc3, 0x66, 0x3c, 0x18,
|
||||
0x06, 0xd3, 0xd9, 0x0f, 0x06, 0x7e, 0xc3, 0xdb, 0xd7, 0xde, 0xfe, 0xff,
|
||||
0x33, 0xff, 0xfe, 0xff, 0xff, 0xdb, 0xff, 0x66, 0x7e, 0xff, 0xc3, 0xe7,
|
||||
0x66, 0xff, 0xff, 0xc3, 0xff, 0x7e, 0xff, 0xff, 0xdb, 0xdb, 0xc3, 0xff,
|
||||
0xff, 0x1b, 0x1b, 0x03, 0x7e, 0xff, 0xc3, 0xfb, 0x7a, 0xff, 0xff, 0x18,
|
||||
0xff, 0xff, 0xc3, 0xff, 0xff, 0xc3, 0x60, 0xe3, 0xc3, 0xff, 0x7f, 0xff,
|
||||
0xff, 0x1c, 0xf7, 0xe3, 0xff, 0xff, 0xc0, 0xc0, 0xc0, 0xff, 0xfe, 0x0c,
|
||||
0xfe, 0xff, 0xff, 0xfe, 0x18, 0x7f, 0xff, 0x7e, 0xff, 0xc3, 0xff, 0x7e,
|
||||
0xff, 0xff, 0x1b, 0x1f, 0x0e, 0x7e, 0xff, 0xc3, 0x7f, 0xde, 0xff, 0xff,
|
||||
0x1b, 0xff, 0xee, 0x4e, 0xdf, 0xdb, 0xfb, 0x72, 0x03, 0xff, 0xff, 0x03,
|
||||
0x03, 0x7f, 0xff, 0xc0, 0xff, 0x7f, 0x3f, 0x7f, 0xc0, 0x7f, 0x3f, 0xff,
|
||||
0x7f, 0x30, 0x7f, 0xff, 0xe7, 0xe7, 0x18, 0x18, 0xe7, 0xe7, 0x0f, 0x1f,
|
||||
0xf0, 0x1f, 0x0f, 0xe3, 0xf3, 0xdb, 0xcf, 0xc7, 0xff, 0xff, 0xc3, 0xc3,
|
||||
0x03, 0x0f, 0x3c, 0xf0, 0xc0, 0xc3, 0xc3, 0xff, 0xff, 0x04, 0x06, 0x03,
|
||||
0x06, 0x04, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x03, 0x07, 0x60, 0xf4, 0xd4,
|
||||
0xf4, 0xf8, 0xff, 0xff, 0xcc, 0xfc, 0x78, 0x78, 0xfc, 0xcc, 0xcc, 0x48,
|
||||
0x78, 0xfc, 0xcc, 0xff, 0xff, 0x78, 0xfc, 0xac, 0xbc, 0xb8, 0x18, 0xfe,
|
||||
0xff, 0x1b, 0x1b, 0xb8, 0xbc, 0xac, 0xfc, 0x78, 0xff, 0xff, 0x18, 0xf8,
|
||||
0xf0, 0xcc, 0xfd, 0xfd, 0xc0, 0xc0, 0xcc, 0xfd, 0x7d, 0xff, 0xff, 0x10,
|
||||
0xfc, 0xec, 0x7f, 0xff, 0xc0, 0xc0, 0xfc, 0xfc, 0x0c, 0xfc, 0x0c, 0xfc,
|
||||
0xf8, 0xfc, 0xf8, 0x0c, 0xfc, 0xf8, 0x78, 0xfc, 0xcc, 0xfc, 0x78, 0xfc,
|
||||
0xfc, 0x6c, 0x7c, 0x38, 0x38, 0x7c, 0x6c, 0xfc, 0xf8, 0xfc, 0xf8, 0x0c,
|
||||
0x1c, 0x18, 0xd8, 0xdc, 0xfc, 0xec, 0x6c, 0x0c, 0x7f, 0xff, 0xcc, 0xcc,
|
||||
0x7c, 0xfc, 0xc0, 0x7c, 0xfc, 0x3c, 0x7c, 0xc0, 0x7c, 0x3c, 0x7c, 0xfc,
|
||||
0xc0, 0x60, 0xc0, 0xfc, 0x7c, 0xcc, 0xfc, 0x30, 0xfc, 0xdc, 0x9c, 0xbc,
|
||||
0xb0, 0xfc, 0x7c, 0xcc, 0xec, 0xfc, 0xdc, 0xcc, 0x10, 0x56, 0xef, 0x81,
|
||||
0xef, 0xef, 0x81, 0xee, 0x56, 0x10, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x18,
|
||||
0x3c, 0x7e, 0x18, 0x18, 0x8f, 0xc7, 0xe3, 0xf1, 0xf8, 0x7c, 0x3e, 0x1f,
|
||||
0xc7, 0xe3, 0xf1, 0xf8, 0x7c, 0x3e, 0x1f, 0x8f, 0xe3, 0xf1, 0xf8, 0x7c,
|
||||
0x3e, 0x1f, 0x8f, 0xc7, 0xf1, 0xf8, 0x7c, 0x3e, 0x1f, 0x8f, 0xc7, 0xe3,
|
||||
0xf8, 0x7c, 0x3e, 0x1f, 0x8f, 0xc7, 0xe3, 0xf1, 0x7c, 0x3e, 0x1f, 0x8f,
|
||||
0xc7, 0xe3, 0xf1, 0xf8, 0x3e, 0x1f, 0x8f, 0xc7, 0xe3, 0xf1, 0xf8, 0x7c,
|
||||
0x1f, 0x8f, 0xc7, 0xe3, 0xf1, 0xf8, 0x7c, 0x3e, 0xff, 0xff, 0xe7, 0xc3,
|
||||
0xc3, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xc3, 0xc3, 0xe7, 0xff, 0xff,
|
||||
0xff, 0xf8, 0xe0, 0xc0, 0xc0, 0xe0, 0xf8, 0xff, 0xff, 0x1f, 0x07, 0x03,
|
||||
0x03, 0x07, 0x1f, 0xff, 0x1c, 0x3e, 0x77, 0x63, 0x77, 0x3e, 0x1c, 0x1c,
|
||||
0x36, 0x63, 0x41, 0x63, 0x36, 0x1c, 0x1c, 0x08, 0x41, 0x63, 0x41, 0x08,
|
||||
0x1c, 0x08, 0x14, 0x22, 0x49, 0x22, 0x14, 0x08, 0x55, 0xaa, 0x55, 0xaa,
|
||||
0x55, 0xaa, 0x55, 0xaa, 0x33, 0x33, 0xcc, 0xcc, 0x33, 0x33, 0xcc, 0xcc,
|
||||
0x33, 0x33, 0x0e, 0x11, 0x0e, 0x12, 0x1f, 0x10, 0x19, 0x15, 0x12, 0x11,
|
||||
0x15, 0x0a, 0x07, 0x04, 0x1e, 0x17, 0x15, 0x09, 0x0e, 0x15, 0x09, 0x01,
|
||||
0x1d, 0x03, 0x0a, 0x15, 0x0a, 0x12, 0x15, 0x0e, 0x0a, 0x10, 0x0a, 0x04,
|
||||
0x0a, 0x11, 0x0a, 0x0a, 0x0a, 0x11, 0x0a, 0x04, 0x01, 0x15, 0x02, 0x01,
|
||||
0x03, 0x07, 0x03, 0x01, 0x04, 0x06, 0x07, 0x06, 0x04, 0x04, 0x0e, 0x1f,
|
||||
0x1f, 0x0e, 0x04, 0x18, 0x3c, 0x7e, 0x7e, 0x3c, 0x18, 0x3c, 0x42, 0x81,
|
||||
0x81, 0x81, 0x81, 0x42, 0x3c, 0x3c, 0x42, 0x99, 0xbd, 0xbd, 0x99, 0x42,
|
||||
0x3c, 0x7f, 0x49, 0x41, 0x6b, 0x41, 0x49, 0x7f, 0x80, 0x40, 0x20, 0x10,
|
||||
0x0f, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x07, 0x3e, 0x01, 0x01, 0x01,
|
||||
0x01, 0x02, 0x04, 0x38, 0x08, 0x08, 0x08, 0x08, 0x01, 0x01, 0x01, 0x01,
|
||||
0x15, 0x0a, 0x15, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
22
lpctool/trunk/charset.info
Normal file
22
lpctool/trunk/charset.info
Normal file
|
@ -0,0 +1,22 @@
|
|||
const unsigned char charset_info[] = {
|
||||
0x08, 0x84, 0x48, 0x84, 0x44, 0x44, 0x48, 0x88, // 0- 15 graticule & borders
|
||||
0x88, 0x88, 0x88, 0x87, 0x77, 0x77, 0x77, 0x77, // 16- 31 graticule & symbols
|
||||
0x21, 0x35, 0x55, 0x51, 0x33, 0x55, 0x35, 0x24, // 32- 47 ascii, font 1
|
||||
0x55, 0x55, 0x55, 0x55, 0x55, 0x23, 0x44, 0x45, // 48- 63 ascii, font 1
|
||||
0x55, 0x55, 0x55, 0x55, 0x53, 0x55, 0x55, 0x55, // 64- 80 ascii, font 1
|
||||
0x55, 0x55, 0x55, 0x55, 0x55, 0x53, 0x43, 0x35, // 80- 95 ascii, font 1
|
||||
0x24, 0x44, 0x44, 0x44, 0x43, 0x34, 0x35, 0x44, // 96-112 ascii, font 1
|
||||
0x44, 0x44, 0x34, 0x55, 0x54, 0x43, 0x13, 0x55, // 112-127 ascii, font 1
|
||||
0x32, 0x55, 0x55, 0x53, 0x44, 0x54, 0x35, 0x25, // 128-143 ascii, bold font
|
||||
0x55, 0x55, 0x55, 0x55, 0x55, 0x23, 0x54, 0x55, // 144-159 ascii, bold font
|
||||
0x55, 0x55, 0x55, 0x55, 0x54, 0x55, 0x55, 0x55, // 160-175 ascii, bold font
|
||||
0x55, 0x55, 0x55, 0x55, 0x65, 0x54, 0x54, 0x55, // 176-191 ascii, bold font
|
||||
0x25, 0x55, 0x55, 0x55, 0x54, 0x45, 0x47, 0x55, // 192-207 ascii, bold font
|
||||
0x55, 0x55, 0x55, 0x57, 0x55, 0x54, 0x24, 0x55, // 208-223 ascii, bold font
|
||||
0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x77, 0x77, // 224-239 symbols
|
||||
0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 240-255 symbols
|
||||
0x33, 0x33, 0x33, 0x33, 0x33, 0x12, 0x33, 0x33, // 256-271 small numbers
|
||||
0x55, 0x33, 0x68, 0x87, 0x84, 0x44, 0x44, 0x44 // 272-288 symbols
|
||||
};
|
||||
|
||||
const unsigned char charset_dlines = 1;
|
163
lpctool/trunk/crt.s
Normal file
163
lpctool/trunk/crt.s
Normal file
|
@ -0,0 +1,163 @@
|
|||
/* *************************************************************
|
||||
|
||||
crt.s STARTUP ASSEMBLY CODE
|
||||
-----------------------
|
||||
|
||||
|
||||
Module includes the interrupt vectors and start-up code.
|
||||
|
||||
****************************************************************/
|
||||
|
||||
/* Stack Sizes */
|
||||
.set UND_STACK_SIZE, 0x00000004 /* stack for "undefined instruction" interrupts is 4 bytes */
|
||||
.set ABT_STACK_SIZE, 0x00000004 /* stack for "abort" interrupts is 4 bytes */
|
||||
.set FIQ_STACK_SIZE, 0x00000010 /* stack for "FIQ" interrupts is 4 bytes */
|
||||
.set IRQ_STACK_SIZE, 0X00000020 /* stack for "IRQ" normal interrupts is 4 bytes */
|
||||
.set SVC_STACK_SIZE, 0x00000010 /* stack for "SVC" supervisor mode is 4 bytes */
|
||||
|
||||
|
||||
|
||||
/* Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs (program status registers) */
|
||||
.set MODE_USR, 0x10 /* Normal User Mode */
|
||||
.set MODE_FIQ, 0x11 /* FIQ Processing Fast Interrupts Mode */
|
||||
.set MODE_IRQ, 0x12 /* IRQ Processing Standard Interrupts Mode */
|
||||
.set MODE_SVC, 0x13 /* Supervisor Processing Software Interrupts Mode */
|
||||
.set MODE_ABT, 0x17 /* Abort Processing memory Faults Mode */
|
||||
.set MODE_UND, 0x1B /* Undefined Processing Undefined Instructions Mode */
|
||||
.set MODE_SYS, 0x1F /* System Running Priviledged Operating System Tasks Mode */
|
||||
|
||||
.set I_BIT, 0x80 /* when I bit is set, IRQ is disabled (program status registers) */
|
||||
.set F_BIT, 0x40 /* when F bit is set, FIQ is disabled (program status registers) */
|
||||
|
||||
|
||||
.text
|
||||
.arm
|
||||
|
||||
.global Reset_Handler
|
||||
.global _startup
|
||||
.func _startup
|
||||
|
||||
_startup:
|
||||
|
||||
# Exception Vectors
|
||||
|
||||
_vectors: ldr PC, Reset_Addr
|
||||
ldr PC, Undef_Addr
|
||||
ldr PC, SWI_Addr
|
||||
ldr PC, PAbt_Addr
|
||||
ldr PC, DAbt_Addr
|
||||
nop /* Reserved Vector (holds Philips ISP checksum) */
|
||||
ldr PC, [PC,#-0xFF0] /* see page 71 of "Insiders Guide to the Philips ARM7-Based Microcontrollers" by Trevor Martin */
|
||||
ldr PC, FIQ_Addr
|
||||
|
||||
Reset_Addr: .word Reset_Handler /* defined in this module below */
|
||||
Undef_Addr: .word UNDEF_Routine /* defined in main.c */
|
||||
SWI_Addr: .word SWI_Routine /* defined in main.c */
|
||||
PAbt_Addr: .word UNDEF_Routine /* defined in main.c */
|
||||
DAbt_Addr: .word UNDEF_Routine /* defined in main.c */
|
||||
IRQ_Addr: .word IRQ_Routine /* defined in main.c */
|
||||
FIQ_Addr: .word FIQ_Routine /* defined in main.c */
|
||||
.word 0 /* rounds the vectors and ISR addresses to 64 bytes total */
|
||||
|
||||
|
||||
# Reset Handler
|
||||
|
||||
Reset_Handler:
|
||||
|
||||
/* Setup a stack for each mode - note that this only sets up a usable stack
|
||||
for User mode. Also each mode is setup with interrupts initially disabled. */
|
||||
|
||||
ldr r0, =_stack_end
|
||||
msr CPSR_c, #MODE_UND|I_BIT|F_BIT /* Undefined Instruction Mode */
|
||||
mov sp, r0
|
||||
sub r0, r0, #UND_STACK_SIZE
|
||||
msr CPSR_c, #MODE_ABT|I_BIT|F_BIT /* Abort Mode */
|
||||
mov sp, r0
|
||||
sub r0, r0, #ABT_STACK_SIZE
|
||||
msr CPSR_c, #MODE_FIQ|I_BIT|F_BIT /* FIQ Mode */
|
||||
mov sp, r0
|
||||
sub r0, r0, #FIQ_STACK_SIZE
|
||||
msr CPSR_c, #MODE_IRQ|I_BIT|F_BIT /* IRQ Mode */
|
||||
mov sp, r0
|
||||
sub r0, r0, #IRQ_STACK_SIZE
|
||||
msr CPSR_c, #MODE_SVC|I_BIT|F_BIT /* Supervisor Mode */
|
||||
mov sp, r0
|
||||
sub r0, r0, #SVC_STACK_SIZE
|
||||
msr CPSR_c, #MODE_SYS|F_BIT /* User Mode */
|
||||
mov sp, r0
|
||||
|
||||
/* set up pins and membanks */
|
||||
ldr r0, = PINSEL2
|
||||
ldr r2, =0xD6041D4
|
||||
str r2, [r0]
|
||||
|
||||
ldr r1, =0x10000420
|
||||
ldr r0,=BCFG0
|
||||
str r1,[r0]
|
||||
str r1,[r0,#0x08]
|
||||
|
||||
/* copy .data section (Copy from ROM to RAM) */
|
||||
ldr R1, =_etext
|
||||
ldr R2, =_data
|
||||
ldr R3, =_edata
|
||||
1: cmp R2, R3
|
||||
ldrlo R0, [R1], #4
|
||||
strlo R0, [R2], #4
|
||||
blo 1b
|
||||
|
||||
/* Clear .bss section (Zero init) */
|
||||
|
||||
mov R0, #0
|
||||
ldr R1, =_bss_start
|
||||
ldr R2, =_bss_end
|
||||
2: cmp R1, R2
|
||||
strlo R0, [R1], #4
|
||||
blo 2b
|
||||
|
||||
|
||||
|
||||
/* set up the pll */
|
||||
ldr r0, =0xe01fc000
|
||||
ldr r2, =0xaa
|
||||
ldr r3, =0x55
|
||||
ldr r1, =0x03
|
||||
str r1, [r0,#0x80]
|
||||
ldr r1, =0x0
|
||||
str r1, [r0,#0x100]
|
||||
ldr r1, =0x42
|
||||
str r1,[r0,#0x84]
|
||||
str r2, [r0,#0x8c]
|
||||
str r3, [r0,#0x8c]
|
||||
|
||||
ldr r2, =IO0PIN
|
||||
mov r3, #0x10
|
||||
str r3, [r2,#0xc]
|
||||
ldr r3, [r2,#8]
|
||||
bic r3, r3, #0x10
|
||||
str r3, [r2,#8]
|
||||
|
||||
ldr r1, =0xc42
|
||||
ldr r0, =BCFG1
|
||||
str r1, [r0]
|
||||
|
||||
ldr r2, =PINSEL0
|
||||
ldr r3, [r2,#0x14]
|
||||
orr r3, r3, #0x800
|
||||
str r3, [r2,#0x14]
|
||||
ldr r3, [r2,#0x14]
|
||||
orr r3, r3, #0x800000
|
||||
str r3, [r2,#0x14]
|
||||
|
||||
/* Enter the C code */
|
||||
mov r0,#0
|
||||
mov r1,r0
|
||||
mov r2,r0
|
||||
mov fp,r0
|
||||
mov r7,r0
|
||||
ldr r10,=main
|
||||
mov lr,pc
|
||||
bx r10
|
||||
|
||||
.endfunc
|
||||
entry_mask: .word 0x4FFFFFFF /* defined in this module below */
|
||||
.end
|
230
lpctool/trunk/flash.c
Normal file
230
lpctool/trunk/flash.c
Normal file
|
@ -0,0 +1,230 @@
|
|||
#include "lpc2220.h"
|
||||
#include "flash.h"
|
||||
#include "serial.h"
|
||||
#include "lcd.h"
|
||||
|
||||
const unsigned long secaddr[19] =
|
||||
{ 0x00000,
|
||||
0x02000,
|
||||
0x03000,
|
||||
0x04000,
|
||||
0x08000,
|
||||
0x10000,
|
||||
0x18000,
|
||||
0x20000,
|
||||
0x28000,
|
||||
0x30000,
|
||||
0x38000,
|
||||
0x40000,
|
||||
0x48000,
|
||||
0x50000,
|
||||
0x58000,
|
||||
0x60000,
|
||||
0x68000,
|
||||
0x70000,
|
||||
0x78000 };
|
||||
|
||||
unsigned long flash_base;
|
||||
unsigned short check1, check2;
|
||||
|
||||
void slow(void)
|
||||
{
|
||||
BCFG0 = 0x10000420;
|
||||
BCFG2 = 0x10000420;
|
||||
}
|
||||
|
||||
void fast(void)
|
||||
{
|
||||
BCFG0 = 0x10000400;
|
||||
BCFG2 = 0x10000400;
|
||||
}
|
||||
int eraseSector(unsigned char chip, unsigned char secnum)
|
||||
{
|
||||
|
||||
if(chip == 0)
|
||||
flash_base = FLASH0_BASE;
|
||||
else
|
||||
flash_base = FLASH1_BASE;
|
||||
|
||||
*((volatile unsigned short *)(flash_base | 0xAAA)) = 0xAA;
|
||||
*((volatile unsigned short *)(flash_base | 0x554)) = 0x55;
|
||||
*((volatile unsigned short *)(flash_base | 0xAAA)) = 0x80;
|
||||
*((volatile unsigned short *)(flash_base | 0xAAA)) = 0xAA;
|
||||
*((volatile unsigned short *)(flash_base | 0x554)) = 0x55;
|
||||
*((volatile unsigned short *)(flash_base + (secaddr[secnum]<<1))) = 0x30;
|
||||
retry:
|
||||
check1 = *((volatile unsigned short *)flash_base);
|
||||
check2 = *((volatile unsigned short *)flash_base);
|
||||
if((check1 & 0x44) == (check2 & 0x44))
|
||||
goto done;
|
||||
if(!(check2 & 0x24))
|
||||
goto retry;
|
||||
check1 = *((volatile unsigned short *)flash_base);
|
||||
check2 = *((volatile unsigned short *)flash_base);
|
||||
if((check1 & 0x44) == (check2 & 0x44))
|
||||
goto done;
|
||||
*((volatile unsigned short *)flash_base) = 0xF0;
|
||||
return -1;
|
||||
|
||||
done:
|
||||
check1 = *((volatile unsigned short *)flash_base);
|
||||
check2 = *((volatile unsigned short *)flash_base);
|
||||
if(check1 != check2)
|
||||
goto retry;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int eraseSectorAt(unsigned long sadr)
|
||||
{
|
||||
|
||||
flash_base = sadr & 0xFF000000;
|
||||
|
||||
*((volatile unsigned short *)(flash_base | 0xAAA)) = 0xAA;
|
||||
*((volatile unsigned short *)(flash_base | 0x554)) = 0x55;
|
||||
*((volatile unsigned short *)(flash_base | 0xAAA)) = 0x80;
|
||||
*((volatile unsigned short *)(flash_base | 0xAAA)) = 0xAA;
|
||||
*((volatile unsigned short *)(flash_base | 0x554)) = 0x55;
|
||||
*((volatile unsigned short *)(sadr)) = 0x30;
|
||||
|
||||
retry:
|
||||
check1 = *((volatile unsigned short *)flash_base);
|
||||
check2 = *((volatile unsigned short *)flash_base);
|
||||
if((check1 & 0x44) == (check2 & 0x44))
|
||||
goto done;
|
||||
if(!(check2 & 0x24))
|
||||
goto retry;
|
||||
check1 = *((volatile unsigned short *)flash_base);
|
||||
check2 = *((volatile unsigned short *)flash_base);
|
||||
if((check1 & 0x44) == (check2 & 0x44))
|
||||
goto done;
|
||||
*((volatile unsigned short *)flash_base) = 0xF0;
|
||||
return -1;
|
||||
|
||||
done:
|
||||
check1 = *((volatile unsigned short *)flash_base);
|
||||
check2 = *((volatile unsigned short *)flash_base);
|
||||
if(check1 != check2)
|
||||
goto retry;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int eraseFlash(unsigned char chip)
|
||||
{
|
||||
if(chip == 0)
|
||||
flash_base = FLASH0_BASE;
|
||||
else
|
||||
flash_base = FLASH1_BASE;
|
||||
|
||||
*((volatile unsigned short *)(flash_base | 0xAAA)) = 0xAA;
|
||||
*((volatile unsigned short *)(flash_base | 0x554)) = 0x55;
|
||||
*((volatile unsigned short *)(flash_base | 0xAAA)) = 0x80;
|
||||
*((volatile unsigned short *)(flash_base | 0xAAA)) = 0xAA;
|
||||
*((volatile unsigned short *)(flash_base | 0x554)) = 0x55;
|
||||
*((volatile unsigned short *)(flash_base | 0xAAA)) = 0x10;
|
||||
|
||||
retry:
|
||||
check1 = *((volatile unsigned short *)flash_base);
|
||||
check2 = *((volatile unsigned short *)flash_base);
|
||||
if((check1 & 0x44) == (check2 & 0x44))
|
||||
goto done;
|
||||
if(!(check2 & 0x24))
|
||||
goto retry;
|
||||
check1 = *((volatile unsigned short *)flash_base);
|
||||
check2 = *((volatile unsigned short *)flash_base);
|
||||
if((check1 & 0x44) == (check2 & 0x44))
|
||||
goto done;
|
||||
*((volatile unsigned short *)flash_base) = 0xF0;
|
||||
return -1;
|
||||
|
||||
done:
|
||||
check1 = *((volatile unsigned short *)flash_base);
|
||||
check2 = *((volatile unsigned short *)flash_base);
|
||||
if(check1 != check2)
|
||||
goto retry;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int writeWord(unsigned long addr, unsigned short data)
|
||||
{
|
||||
flash_base = addr & 0xFF000000;
|
||||
*((volatile unsigned short *)(flash_base | 0xAAA)) = 0xAA;
|
||||
*((volatile unsigned short *)(flash_base | 0x554)) = 0x55;
|
||||
*((volatile unsigned short *)(flash_base | 0xAAA)) = 0xA0;
|
||||
*((volatile unsigned short *)(addr)) = data;
|
||||
|
||||
retry:
|
||||
check1 = *((volatile unsigned short *)addr);
|
||||
check2 = *((volatile unsigned short *)addr);
|
||||
if((check1 & 0x40) == (check2 & 0x40))
|
||||
goto done;
|
||||
if(!(check2 & 0x20))
|
||||
goto retry;
|
||||
check1 = *((volatile unsigned short *)addr);
|
||||
check2 = *((volatile unsigned short *)addr);
|
||||
if((check1 & 0x40) == (check2 & 0x40))
|
||||
goto done;
|
||||
*((volatile unsigned short *)addr) = 0xF0;
|
||||
return -1;
|
||||
|
||||
done:
|
||||
check1 = *((volatile unsigned short *)addr);
|
||||
check2 = *((volatile unsigned short *)addr);
|
||||
if(check1 != check2)
|
||||
goto retry;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void prepareBulk(unsigned long dst)
|
||||
{
|
||||
flash_base = dst & 0xFF000000;
|
||||
|
||||
*((volatile unsigned short *)(flash_base | 0xAAA)) = 0xAA;
|
||||
*((volatile unsigned short *)(flash_base | 0x554)) = 0x55;
|
||||
*((volatile unsigned short *)(flash_base | 0xAAA)) = 0x20;
|
||||
}
|
||||
|
||||
void endBulk(unsigned long dst)
|
||||
{
|
||||
flash_base = dst & 0xFF000000;
|
||||
|
||||
*((volatile unsigned short *)(flash_base)) = 0x90;
|
||||
*((volatile unsigned short *)(flash_base)) = 0x00;
|
||||
}
|
||||
|
||||
int writeBulk(unsigned long src, unsigned long dst, unsigned long cnt)
|
||||
{
|
||||
flash_base = dst;
|
||||
while(cnt--)
|
||||
{
|
||||
if(*((volatile unsigned short *)src) != 0xFFFF)
|
||||
{
|
||||
*((volatile unsigned short *)flash_base) = 0xA0;
|
||||
*((volatile unsigned short *)flash_base) = *((volatile unsigned short *)src);
|
||||
|
||||
retry:
|
||||
check1 = *((volatile unsigned short *)flash_base);
|
||||
check2 = *((volatile unsigned short *)flash_base);
|
||||
if((check1 & 0x40) == (check2 & 0x40))
|
||||
goto done;
|
||||
if(!(check2 & 0x20))
|
||||
goto retry;
|
||||
check1 = *((volatile unsigned short *)flash_base);
|
||||
check2 = *((volatile unsigned short *)flash_base);
|
||||
if((check1 & 0x40) == (check2 & 0x40))
|
||||
goto done;
|
||||
*((volatile unsigned short *)flash_base) = 0xF0;
|
||||
return -1;
|
||||
|
||||
done:
|
||||
check1 = *((volatile unsigned short *)flash_base);
|
||||
check2 = *((volatile unsigned short *)flash_base);
|
||||
if(check1 != check2)
|
||||
goto retry;
|
||||
}
|
||||
src+=2;
|
||||
flash_base+=2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
16
lpctool/trunk/flash.h
Normal file
16
lpctool/trunk/flash.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#ifndef FLASH_H
|
||||
#define FLASH_H
|
||||
|
||||
#define FLASH0_BASE 0x80000000
|
||||
#define FLASH1_BASE 0x82000000
|
||||
|
||||
void prepareBulk(unsigned long dst);
|
||||
void endBulk(unsigned long dst);
|
||||
int eraseSector(unsigned char chip, unsigned char secnum);
|
||||
int eraseSectorAt(unsigned long sadr);
|
||||
int eraseFlash(unsigned char chip);
|
||||
int writeWord(unsigned long addr, unsigned short data);
|
||||
int writeBulk(unsigned long src, unsigned long dst, unsigned long cnt);
|
||||
void lcd_set(unsigned char s);
|
||||
|
||||
#endif
|
171
lpctool/trunk/fonty.c
Normal file
171
lpctool/trunk/fonty.c
Normal file
|
@ -0,0 +1,171 @@
|
|||
#include "lcd.h"
|
||||
#include "fonty.h"
|
||||
|
||||
#include "charset.info"
|
||||
#include "charset.bits"
|
||||
|
||||
static unsigned char tx, ty;
|
||||
static unsigned short coff;
|
||||
unsigned char *font_bits, *font_info;
|
||||
|
||||
void set_font(unsigned char f)
|
||||
{
|
||||
font_bits = (unsigned char*) charset_bits;
|
||||
font_info = (unsigned char*) charset_info;
|
||||
switch(f)
|
||||
{
|
||||
case 0:
|
||||
coff = 0;
|
||||
break;
|
||||
case 1:
|
||||
coff = 96;
|
||||
break;
|
||||
case 2:
|
||||
coff = 224;
|
||||
break;
|
||||
case 3:
|
||||
case 4:
|
||||
coff = 272;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void _draw_char(unsigned int ch, unsigned char c, unsigned char m)
|
||||
{
|
||||
unsigned char p,s;
|
||||
unsigned int cpos, cnt;
|
||||
|
||||
cpos = 0;
|
||||
|
||||
for(cnt=0; cnt<ch; cnt++)
|
||||
{
|
||||
if(cnt & 0x01)
|
||||
{
|
||||
cpos += (font_info[cnt>>1] & 0x0F);
|
||||
}
|
||||
else
|
||||
{
|
||||
cpos += (font_info[cnt>>1] >> 4);
|
||||
}
|
||||
}
|
||||
|
||||
p = font_info[ch>>1];
|
||||
if(ch & 0x01)
|
||||
{
|
||||
p &= 0x0F;
|
||||
}
|
||||
else
|
||||
{
|
||||
p >>= 4;
|
||||
}
|
||||
|
||||
if(ty & 0x07)
|
||||
{
|
||||
s = ty & 0x07;
|
||||
|
||||
for(cnt=0;cnt<p;cnt++)
|
||||
{
|
||||
if(c & 0x02)
|
||||
drawbuf[0][p-cnt-1] = font_bits[cpos+cnt] << s;
|
||||
else
|
||||
drawbuf[0][p-cnt-1] = 0x00;
|
||||
|
||||
if(c & 0x01)
|
||||
drawbuf[1][p-cnt-1] = font_bits[cpos+cnt] << s;
|
||||
else
|
||||
drawbuf[1][p-cnt-1] = 0x00;
|
||||
}
|
||||
do_rcu(tx,ty,p,m);
|
||||
|
||||
for(cnt=0;cnt<p;cnt++)
|
||||
{
|
||||
if(c & 0x02)
|
||||
drawbuf[0][p-cnt-1] = font_bits[cpos+cnt] >> (8-s);
|
||||
else
|
||||
drawbuf[0][p-cnt-1] = 0x00;
|
||||
|
||||
if(c & 0x01)
|
||||
drawbuf[1][p-cnt-1] = font_bits[cpos+cnt] >> (8-s);
|
||||
else
|
||||
drawbuf[1][p-cnt-1] = 0x00;
|
||||
}
|
||||
do_rcu(tx,ty+8,p,m);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(cnt=0;cnt<p;cnt++)
|
||||
{
|
||||
if(c & 0x02)
|
||||
drawbuf[0][p-cnt-1] = font_bits[cpos+cnt];
|
||||
else
|
||||
drawbuf[0][p-cnt-1] = 0x00;
|
||||
|
||||
if(c & 0x01)
|
||||
drawbuf[1][p-cnt-1] = font_bits[cpos+cnt];
|
||||
else
|
||||
drawbuf[1][p-cnt-1] = 0x00;
|
||||
}
|
||||
do_rcu(tx,ty,p,m);
|
||||
}
|
||||
tx += (p+1);
|
||||
}
|
||||
|
||||
void draw_char(unsigned char x, unsigned char y, unsigned char ch, unsigned char c, unsigned char m)
|
||||
{
|
||||
tx = x;
|
||||
ty = y;
|
||||
_draw_char(ch+coff, c, m);
|
||||
}
|
||||
|
||||
void draw_string(unsigned char x, unsigned char y, char *st, unsigned char c, unsigned char m)
|
||||
{
|
||||
unsigned char cp;
|
||||
tx = x;
|
||||
ty = y;
|
||||
|
||||
cp = 0;
|
||||
while(st[cp] != 0)
|
||||
{
|
||||
_draw_char(st[cp]+coff, c, m);
|
||||
cp++;
|
||||
}
|
||||
}
|
||||
|
||||
void draw_stringc(unsigned char x, unsigned char y, char *st, unsigned char cnt, unsigned char c, unsigned char m)
|
||||
{
|
||||
unsigned char cp,cx;
|
||||
cx = cnt;
|
||||
tx = x;
|
||||
ty = y;
|
||||
|
||||
cp = 0;
|
||||
while(cx--)
|
||||
{
|
||||
_draw_char(st[cp]+coff, c, m);
|
||||
cp++;
|
||||
}
|
||||
}
|
||||
|
||||
extern char hval[16];
|
||||
|
||||
void draw_hexC(unsigned char x, unsigned char y, const unsigned char v, unsigned char c, unsigned char m)
|
||||
{
|
||||
tx = x;
|
||||
ty = y;
|
||||
_draw_char(hval[v>>4]+coff, c, m);
|
||||
_draw_char(hval[v & 0x0F]+coff, c, m);
|
||||
}
|
||||
|
||||
void draw_hexS(unsigned char x, unsigned char y, const unsigned short v, unsigned char c, unsigned char m)
|
||||
{
|
||||
tx = x;
|
||||
ty = y;
|
||||
draw_hexC(x, y, v >> 8, c, m);
|
||||
draw_hexC(tx, ty, v & 0xFF, c, m);
|
||||
}
|
||||
|
||||
void draw_hexW(unsigned char x, unsigned char y, const unsigned long v, unsigned char c, unsigned char m)
|
||||
{
|
||||
draw_hexS(x, y, v >> 16, c, m);
|
||||
draw_hexS(tx, ty, v & 0xFFFF, c, m);
|
||||
}
|
14
lpctool/trunk/fonty.h
Normal file
14
lpctool/trunk/fonty.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#ifndef FONTY_H
|
||||
#define FONTY_H
|
||||
|
||||
extern unsigned char drawbuf[2][128];
|
||||
|
||||
void set_font(unsigned char f);
|
||||
void draw_char(unsigned char x, unsigned char y, unsigned char ch, unsigned char c, unsigned char m);
|
||||
void draw_string(unsigned char x, unsigned char y, char *st, unsigned char c, unsigned char m);
|
||||
void draw_stringc(unsigned char x, unsigned char y, char *st, unsigned char cnt, unsigned char c, unsigned char m);
|
||||
void draw_hexC(unsigned char x, unsigned char y, const unsigned char v, unsigned char c, unsigned char m);
|
||||
void draw_hexS(unsigned char x, unsigned char y, const unsigned short v, unsigned char c, unsigned char m);
|
||||
void draw_hexW(unsigned char x, unsigned char y, const unsigned long v, unsigned char c, unsigned char m);
|
||||
|
||||
#endif
|
78
lpctool/trunk/infohelper.c
Normal file
78
lpctool/trunk/infohelper.c
Normal file
|
@ -0,0 +1,78 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include "infohelper.h"
|
||||
|
||||
char verbosity;
|
||||
|
||||
int printError(char *err)
|
||||
{
|
||||
printf("ERROR: %s\n",err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int printErrorS(char *err, char *xtra)
|
||||
{
|
||||
if(xtra)
|
||||
printf("ERROR: %s %s\n", err, xtra);
|
||||
else
|
||||
printf("ERROR: %s\n", err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int printInfoS(unsigned char level, char *msg, char *xtra)
|
||||
{
|
||||
if(level <= verbosity)
|
||||
{
|
||||
if(xtra)
|
||||
printf("Info : %s %s\n", msg, xtra);
|
||||
else
|
||||
printf("Info : %s\n", msg);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int printInfoH(unsigned char level, char *msg, unsigned long val)
|
||||
{
|
||||
if(level <= verbosity)
|
||||
{
|
||||
printf("Info : %s 0x%08X\n", msg, val);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char heartbeat[] = { ".oOo" };
|
||||
|
||||
int printProgress(unsigned char level, char *msg, float cval, float maxval)
|
||||
{
|
||||
unsigned int cur, cnt;
|
||||
|
||||
static char beat = 0;
|
||||
|
||||
if(level <= verbosity)
|
||||
{
|
||||
cur = (35 / maxval) * cval;
|
||||
|
||||
cnt = 35-cur;
|
||||
|
||||
printf("Progress: [");
|
||||
|
||||
while(cur--)
|
||||
printf("*");
|
||||
|
||||
if(cnt)
|
||||
printf("%c",heartbeat[beat]);
|
||||
else
|
||||
printf("*");
|
||||
|
||||
while(cnt--)
|
||||
printf(" ");
|
||||
|
||||
printf("\b]\r");
|
||||
fflush(stdout);
|
||||
beat++;
|
||||
beat &= 0x03;
|
||||
}
|
||||
}
|
||||
|
12
lpctool/trunk/infohelper.h
Normal file
12
lpctool/trunk/infohelper.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#ifndef TOOL_INFOHELPER
|
||||
#define TOOL_INFOHELPER
|
||||
|
||||
extern char verbosity;
|
||||
|
||||
int printError(char *err);
|
||||
int printErrorS(char *err, char *xtra);
|
||||
int printInfoS(unsigned char level, char *msg, char *xtra);
|
||||
int printInfoH(unsigned char level, char *msg, unsigned long val);
|
||||
int printProgress(unsigned char level, char *msg, float cval, float maxval);
|
||||
|
||||
#endif
|
43
lpctool/trunk/irq.c
Normal file
43
lpctool/trunk/irq.c
Normal file
|
@ -0,0 +1,43 @@
|
|||
#include "lpc2220.hh"
|
||||
#include "irq.h"
|
||||
|
||||
#define IRQ_MASK 0x00000080
|
||||
|
||||
static inline unsigned asm_get_cpsr(void)
|
||||
{
|
||||
unsigned long retval;
|
||||
asm volatile (" mrs %0, cpsr" : "=r" (retval) : /* no inputs */ );
|
||||
return retval;
|
||||
}
|
||||
|
||||
static inline void asm_set_cpsr(unsigned val)
|
||||
{
|
||||
asm volatile (" msr cpsr, %0" : /* no outputs */ : "r" (val) );
|
||||
}
|
||||
|
||||
unsigned enableIRQ(void)
|
||||
{
|
||||
unsigned _cpsr;
|
||||
|
||||
_cpsr = asm_get_cpsr();
|
||||
asm_set_cpsr(_cpsr & ~IRQ_MASK);
|
||||
return _cpsr;
|
||||
}
|
||||
|
||||
unsigned disableIRQ(void)
|
||||
{
|
||||
unsigned _cpsr;
|
||||
|
||||
_cpsr = asm_get_cpsr();
|
||||
asm_set_cpsr(_cpsr | IRQ_MASK);
|
||||
return _cpsr;
|
||||
}
|
||||
|
||||
unsigned restoreIRQ(unsigned oldCPSR)
|
||||
{
|
||||
unsigned _cpsr;
|
||||
|
||||
_cpsr = asm_get_cpsr();
|
||||
asm_set_cpsr((_cpsr & ~IRQ_MASK) | (oldCPSR & IRQ_MASK));
|
||||
return _cpsr;
|
||||
}
|
450
lpctool/trunk/lcd.c
Normal file
450
lpctool/trunk/lcd.c
Normal file
|
@ -0,0 +1,450 @@
|
|||
#include "lpc2220.h"
|
||||
#include "lcd.h"
|
||||
#include "fonty.h"
|
||||
//#include "b.h"
|
||||
|
||||
void pause(unsigned int ptime)
|
||||
{
|
||||
unsigned long xx;
|
||||
xx = ptime * 750;
|
||||
while(xx--)
|
||||
{};
|
||||
}
|
||||
|
||||
void clearStatus(void)
|
||||
{
|
||||
draw_block(0, 151, 128, 10, 3, DRAW_ERASE);
|
||||
timer++;
|
||||
}
|
||||
|
||||
void drawStatus(char *msg)
|
||||
{
|
||||
draw_block(0, 152, 128, 10, 3, DRAW_PUT);
|
||||
draw_string(1,152,">>",3,DRAW_XOR);
|
||||
draw_string(16,152,msg,3,DRAW_XOR);
|
||||
timer = 0;
|
||||
}
|
||||
|
||||
void lcd_fill(unsigned char f)
|
||||
{
|
||||
unsigned char x,y;
|
||||
for(y=0;y<20;y++)
|
||||
{
|
||||
LCD_CMD = 0xB0;
|
||||
LCD_CMD = y;
|
||||
LCD_CMD = 0x10;
|
||||
LCD_CMD = 0x00;
|
||||
for(x=0;x<128;x++)
|
||||
{
|
||||
LCD_DATA = f;
|
||||
LCD_DATA = f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void lcd_set(unsigned char s)
|
||||
{
|
||||
if(s == 0)
|
||||
{
|
||||
LCD_CMD = 0xA0; // set segment remap (00H mapped to seg0)
|
||||
LCD_CMD = 0xC8; // set com output scan direction (remapped mode)
|
||||
}
|
||||
else
|
||||
{
|
||||
LCD_CMD = 0xA1; // set segment remap (7FH mapped to seg0)
|
||||
LCD_CMD = 0xC0; // set com output scan direction (normal mode)
|
||||
}
|
||||
}
|
||||
|
||||
void lcd_init(unsigned char s)
|
||||
{
|
||||
LCD_CMD = 0xE1; // exit power save mode
|
||||
LCD_CMD = 0xE2; // software reset
|
||||
pause(0x64);
|
||||
LCD_CMD = 0xAB; // start internal oscillator
|
||||
LCD_CMD = 0x27; // set internal regulator resistor ratio (8.1)
|
||||
LCD_CMD = 0x81; // volume cmd
|
||||
LCD_CMD = 0x3B; // volume cmd value
|
||||
LCD_CMD = 0x65; // set DC-DC converter factor (4x)
|
||||
LCD_CMD = 0x60; // set upper window corner ax cmd
|
||||
LCD_CMD = 0x1C; // set upper window corner ax value
|
||||
LCD_CMD = 0x61; // set upper window corner ay cmd
|
||||
LCD_CMD = 0x0A; // set upper window corner ay value
|
||||
LCD_CMD = 0x62; // set lower window corner bx cmd
|
||||
LCD_CMD = 0x75; // set lower window corner bx value
|
||||
LCD_CMD = 0x63; // set lower window corner by cmd
|
||||
LCD_CMD = 0x81; // set lower window corner by value
|
||||
LCD_CMD = 0x90; // set PWM and FRC (4-frames)
|
||||
LCD_CMD = 0x88; // set white mode frame 2nd and 1st cmd
|
||||
LCD_CMD = 0x00; // set white mode frame 2nd and 1st value
|
||||
LCD_CMD = 0x89; // set white mode frame 4th and 3rd cmd
|
||||
LCD_CMD = 0x00; // set white mode frame 4th and 3rd value
|
||||
LCD_CMD = 0x8A; // set light gray mode frame 2nd and 1st cmd
|
||||
LCD_CMD = 0x55; // set light gray mode frame 2nd and 1st value
|
||||
LCD_CMD = 0x8B; // set light gray mode frame 4th and 3rd cmd
|
||||
LCD_CMD = 0x55; // set light gray mode frame 4th and 3rd vakue
|
||||
LCD_CMD = 0x8C; // set dark gray mode frame 2nd and 1st cmd
|
||||
LCD_CMD = 0x66; // set dark gray mode frame 2nd and 1st value
|
||||
LCD_CMD = 0x8D; // set dark gray mode frame 4th and 3rd cmd
|
||||
LCD_CMD = 0x66; // set dark gray mode frame 4th and 3rd vakue
|
||||
LCD_CMD = 0x8E; // set black mode frame 2nd and 1st cmd
|
||||
LCD_CMD = 0xAA; // set black mode frame 2nd and 1st value
|
||||
LCD_CMD = 0x8F; // set black mode frame 4th and 3rd cmd
|
||||
LCD_CMD = 0xAA; // set black mode frame 4th and 3rd value
|
||||
|
||||
lcd_set(s);
|
||||
|
||||
LCD_CMD = 0x2E; // set power control register (boost on, reg on, buffer off)
|
||||
|
||||
pause(0x64);
|
||||
|
||||
LCD_CMD = 0x2F; // set power control register (boost on, reg on, buffer on)
|
||||
LCD_CMD = 0xA4; // set entire display on, normal mode)
|
||||
LCD_CMD = 0xA6; // set normal display mode, inverse = 0xA7
|
||||
|
||||
|
||||
lcd_fill(0x00);
|
||||
|
||||
LCD_CMD = 0xAF;
|
||||
|
||||
set_font(0);
|
||||
}
|
||||
|
||||
void lcd_enable(unsigned char e)
|
||||
{
|
||||
if(e)
|
||||
{
|
||||
LCD_CMD = 0xAF; // set display on
|
||||
}
|
||||
else
|
||||
{
|
||||
LCD_CMD = 0xAE; // set display off
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
unsigned char rcubuf[2][128];
|
||||
unsigned char drawbuf[2][128];
|
||||
|
||||
void do_rcu(unsigned char x, unsigned char y, unsigned char l, unsigned char m)
|
||||
{
|
||||
unsigned char q;
|
||||
|
||||
LCD_CMD = 0xB0;
|
||||
LCD_CMD = (y >> 3);
|
||||
LCD_CMD = (0x10 + (x >> 4));
|
||||
LCD_CMD = (x & 0x0F);
|
||||
|
||||
q = LCD_DATA;
|
||||
q = l;
|
||||
|
||||
while(q--)
|
||||
{
|
||||
rcubuf[0][q] = LCD_DATA;
|
||||
rcubuf[1][q] = LCD_DATA;
|
||||
}
|
||||
|
||||
q = LCD_DATA;
|
||||
|
||||
LCD_CMD = 0xB0;
|
||||
LCD_CMD = (y >> 3);
|
||||
LCD_CMD = (0x10 + (x >> 4));
|
||||
LCD_CMD = (x & 0x0F);
|
||||
|
||||
q = l;
|
||||
|
||||
switch(m)
|
||||
{
|
||||
case DRAW_PUT: // draw put
|
||||
while(q--)
|
||||
{
|
||||
LCD_DATA = rcubuf[0][q] | drawbuf[0][q];
|
||||
LCD_DATA = rcubuf[1][q] | drawbuf[1][q];
|
||||
}
|
||||
break;
|
||||
case DRAW_XOR: // draw xor
|
||||
while(q--)
|
||||
{
|
||||
LCD_DATA = rcubuf[0][q] ^ drawbuf[0][q];
|
||||
LCD_DATA = rcubuf[1][q] ^ drawbuf[1][q];
|
||||
}
|
||||
break;
|
||||
case DRAW_ERASE: // draw erase
|
||||
while(q--)
|
||||
{
|
||||
LCD_DATA = rcubuf[0][q] & ~drawbuf[0][q];
|
||||
LCD_DATA = rcubuf[1][q] & ~drawbuf[1][q];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void do_rcuS(unsigned char x, unsigned char y, unsigned char m)
|
||||
{
|
||||
unsigned char q;
|
||||
|
||||
LCD_CMD = 0xB0;
|
||||
LCD_CMD = (y >> 3);
|
||||
LCD_CMD = (0x10 + (x >> 4));
|
||||
LCD_CMD = (x & 0x0F);
|
||||
|
||||
q = LCD_DATA;
|
||||
rcubuf[0][0] = LCD_DATA;
|
||||
rcubuf[1][0] = LCD_DATA;
|
||||
|
||||
q = LCD_DATA;
|
||||
|
||||
LCD_CMD = 0xB0;
|
||||
LCD_CMD = (y >> 3);
|
||||
LCD_CMD = (0x10 + (x >> 4));
|
||||
LCD_CMD = (x & 0x0F);
|
||||
|
||||
switch(m)
|
||||
{
|
||||
case 0: // draw put
|
||||
LCD_DATA = rcubuf[0][0] | drawbuf[0][0];
|
||||
LCD_DATA = rcubuf[1][0] | drawbuf[1][0];
|
||||
break;
|
||||
case 1: // draw xor
|
||||
LCD_DATA = rcubuf[0][0] ^ drawbuf[0][0];
|
||||
LCD_DATA = rcubuf[1][0] ^ drawbuf[1][0];
|
||||
break;
|
||||
case 2: // draw erase
|
||||
LCD_DATA = rcubuf[0][0] & ~drawbuf[0][0];
|
||||
LCD_DATA = rcubuf[1][0] & ~drawbuf[1][0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void draw_block(unsigned char x, unsigned char y, unsigned char w, unsigned char h, unsigned char c, unsigned char m)
|
||||
{
|
||||
unsigned char q,s;
|
||||
unsigned char yy,ss,vv,ww,xx;
|
||||
unsigned char segm;
|
||||
|
||||
s = y;
|
||||
|
||||
if(h)
|
||||
{
|
||||
|
||||
|
||||
|
||||
yy = h;
|
||||
ss = y >> 3;
|
||||
vv = y & 0x07;
|
||||
|
||||
ww = yy & 0x07;
|
||||
|
||||
segm = 0xFF;
|
||||
|
||||
xx = 8;
|
||||
if(yy < 8)
|
||||
{
|
||||
segm >>= (8-ww);
|
||||
xx -= (8-ww);
|
||||
if(vv > (8-xx))
|
||||
{
|
||||
xx = yy -(vv-(8-xx));
|
||||
}
|
||||
else
|
||||
{
|
||||
xx = yy;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
xx -= vv;
|
||||
}
|
||||
|
||||
segm <<= vv;
|
||||
|
||||
q = w;
|
||||
while(q--)
|
||||
{
|
||||
if(c & 0x02)
|
||||
drawbuf[0][q] = segm;
|
||||
else
|
||||
drawbuf[0][q] = 0;
|
||||
|
||||
if(c & 0x01)
|
||||
drawbuf[1][q] = segm;
|
||||
else
|
||||
drawbuf[1][q] = 0;
|
||||
}
|
||||
do_rcu(x,s,w,m);
|
||||
|
||||
yy -= xx;
|
||||
|
||||
while(yy > 8)
|
||||
{
|
||||
s += 8;
|
||||
yy -= 8;
|
||||
q = w;
|
||||
while(q--)
|
||||
{
|
||||
if(c & 0x02)
|
||||
drawbuf[0][q] = 0xFF;
|
||||
else
|
||||
drawbuf[0][q] = 0;
|
||||
|
||||
if(c & 0x01)
|
||||
drawbuf[1][q] = 0xFF;
|
||||
else
|
||||
drawbuf[1][q] = 0;
|
||||
}
|
||||
do_rcu(x,s,w,m);
|
||||
}
|
||||
|
||||
if(yy)
|
||||
{
|
||||
s += 8;
|
||||
q = w;
|
||||
while(q--)
|
||||
{
|
||||
if(c & 0x02)
|
||||
drawbuf[0][q] = 0xFF >> (8-yy);
|
||||
else
|
||||
drawbuf[0][q] = 0;
|
||||
|
||||
if(c & 0x01)
|
||||
drawbuf[1][q] = 0xFF >> (8-yy);
|
||||
else
|
||||
drawbuf[1][q] = 0;
|
||||
}
|
||||
do_rcu(x,s,w,m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw_hline(unsigned char x, unsigned char y, unsigned char l, unsigned char c, unsigned char m)
|
||||
{
|
||||
unsigned char p,q;
|
||||
|
||||
q = l;
|
||||
p = 0x01 << (y & 0x07);
|
||||
|
||||
while(q--)
|
||||
{
|
||||
if(c & 0x02)
|
||||
drawbuf[0][q] = p;
|
||||
else
|
||||
drawbuf[0][q] = 0;
|
||||
|
||||
if(c & 0x01)
|
||||
drawbuf[1][q] = p;
|
||||
else
|
||||
drawbuf[1][q] = 0;
|
||||
}
|
||||
do_rcu(x,y,l,m);
|
||||
}
|
||||
|
||||
void draw_vline(unsigned char x, unsigned char y, unsigned char l, unsigned char c, unsigned char m)
|
||||
{
|
||||
unsigned char s;
|
||||
unsigned char yy,ss,vv,ww,xx;
|
||||
unsigned char segm;
|
||||
|
||||
s = y;
|
||||
|
||||
if(l)
|
||||
{
|
||||
|
||||
|
||||
|
||||
yy = l;
|
||||
ss = y >> 3;
|
||||
vv = y & 0x07;
|
||||
|
||||
ww = yy & 0x07;
|
||||
|
||||
segm = 0xFF;
|
||||
|
||||
xx = 8;
|
||||
if(yy < 8)
|
||||
{
|
||||
segm >>= (8-ww);
|
||||
xx -= (8-ww);
|
||||
if(vv > (8-xx))
|
||||
{
|
||||
xx = yy -(vv-(8-xx));
|
||||
}
|
||||
else
|
||||
{
|
||||
xx = yy;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
xx -= vv;
|
||||
}
|
||||
|
||||
segm <<= vv;
|
||||
|
||||
if(c & 0x02)
|
||||
drawbuf[0][0] = segm;
|
||||
else
|
||||
drawbuf[0][0] = 0;
|
||||
|
||||
if(c & 0x01)
|
||||
drawbuf[1][0] = segm;
|
||||
else
|
||||
drawbuf[1][0] = 0;
|
||||
|
||||
do_rcuS(x,s,m);
|
||||
|
||||
yy -= xx;
|
||||
|
||||
while(yy > 8)
|
||||
{
|
||||
s += 8;
|
||||
yy -= 8;
|
||||
if(c & 0x02)
|
||||
drawbuf[0][0] = 0xFF;
|
||||
else
|
||||
drawbuf[0][0] = 0;
|
||||
|
||||
if(c & 0x01)
|
||||
drawbuf[1][0] = 0xFF;
|
||||
else
|
||||
drawbuf[1][0] = 0;
|
||||
do_rcuS(x,s,m);
|
||||
}
|
||||
|
||||
if(yy)
|
||||
{
|
||||
s += 8;
|
||||
if(c & 0x02)
|
||||
drawbuf[0][0] = 0xFF >> (8-yy);
|
||||
else
|
||||
drawbuf[0][0] = 0;
|
||||
|
||||
if(c & 0x01)
|
||||
drawbuf[1][0] = 0xFF >> (8-yy);
|
||||
else
|
||||
drawbuf[1][0] = 0;
|
||||
do_rcuS(x,s,m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw_rect(unsigned char x, unsigned char y, unsigned char w, unsigned char h, unsigned char lw, unsigned char c, unsigned char m)
|
||||
{
|
||||
if(lw)
|
||||
{
|
||||
if(lw == 1)
|
||||
{
|
||||
draw_hline(x, y, w, c, m);
|
||||
draw_hline(x, y+h-1, w, c, m);
|
||||
|
||||
draw_vline(x, y+1, h-2, c, m);
|
||||
draw_vline(x+w-1, y+1, h-2, c, m);
|
||||
}
|
||||
else
|
||||
{
|
||||
draw_block(x, y, w, lw, c, m);
|
||||
draw_block(x, y+h-lw, w, lw, c, m);
|
||||
draw_block(x, y+lw, lw, h-(2*lw), c, m);
|
||||
draw_block(x+w-lw, y+lw, lw, h-(2*lw), c, m);
|
||||
}
|
||||
}
|
||||
}
|
42
lpctool/trunk/lcd.h
Normal file
42
lpctool/trunk/lcd.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
#ifndef LCD_H
|
||||
#define LCD_H
|
||||
|
||||
// the lcd data & command ports
|
||||
#define LCD_CMD (*((volatile unsigned char *) 0x81000000))
|
||||
#define LCD_DATA (*((volatile unsigned char *) 0x81000001))
|
||||
|
||||
// drawmodes
|
||||
#define DRAW_PUT 0
|
||||
#define DRAW_XOR 1
|
||||
#define DRAW_ERASE 2
|
||||
#define DRAW_RAW 10
|
||||
#define DRAW_RAW_INV 11
|
||||
|
||||
#define TIMEOUT 0x00400000
|
||||
|
||||
struct t_bitmap
|
||||
{
|
||||
unsigned char width;
|
||||
unsigned char height;
|
||||
unsigned char mode;
|
||||
unsigned char *data;
|
||||
} ;
|
||||
|
||||
extern unsigned long timer;
|
||||
|
||||
struct t_bitmap bitmap;
|
||||
|
||||
void lcd_init(unsigned char s);
|
||||
void lcd_enable(unsigned char e);
|
||||
|
||||
void do_rcu(unsigned char x, unsigned char y, unsigned char l, unsigned char m);
|
||||
|
||||
void lcd_fill(unsigned char f);
|
||||
void draw_block(unsigned char x, unsigned char y, unsigned char w, unsigned char h, unsigned char c, unsigned char m);
|
||||
void draw_hline(unsigned char x, unsigned char y, unsigned char l, unsigned char c, unsigned char m);
|
||||
void draw_vline(unsigned char x, unsigned char y, unsigned char l, unsigned char c, unsigned char m);
|
||||
void draw_rect(unsigned char x, unsigned char y, unsigned char w, unsigned char h, unsigned char lw, unsigned char c, unsigned char m);
|
||||
void clearStatus(void);
|
||||
void drawStatus(char *msg);
|
||||
|
||||
#endif
|
261
lpctool/trunk/lpc2220.h
Normal file
261
lpctool/trunk/lpc2220.h
Normal file
|
@ -0,0 +1,261 @@
|
|||
/********************************************************/
|
||||
/* */
|
||||
/* philips */
|
||||
/* lpc2220 */
|
||||
/* */
|
||||
/********************************************************/
|
||||
#ifndef LPC2220_H
|
||||
#define LPC2220_H
|
||||
|
||||
/* External Memory Controller (EMC) */
|
||||
#define BCFG0 (*((volatile unsigned long *) 0xFFE00000))
|
||||
#define BCFG1 (*((volatile unsigned long *) 0xFFE00004))
|
||||
#define BCFG2 (*((volatile unsigned long *) 0xFFE00008))
|
||||
#define BCFG3 (*((volatile unsigned long *) 0xFFE0000C))
|
||||
|
||||
/* Vectored Interrupt Controller (VIC) */
|
||||
#define VICIRQStatus (*((volatile unsigned long *) 0xFFFFF000))
|
||||
#define VICFIQStatus (*((volatile unsigned long *) 0xFFFFF004))
|
||||
#define VICRawIntr (*((volatile unsigned long *) 0xFFFFF008))
|
||||
#define VICIntSelect (*((volatile unsigned long *) 0xFFFFF00C))
|
||||
#define VICIntEnable (*((volatile unsigned long *) 0xFFFFF010))
|
||||
#define VICIntEnClr (*((volatile unsigned long *) 0xFFFFF014))
|
||||
#define VICSoftInt (*((volatile unsigned long *) 0xFFFFF018))
|
||||
#define VICSoftIntClr (*((volatile unsigned long *) 0xFFFFF01C))
|
||||
#define VICProtection (*((volatile unsigned long *) 0xFFFFF020))
|
||||
#define VICVectAddr (*((volatile unsigned long *) 0xFFFFF030))
|
||||
#define VICDefVectAddr (*((volatile unsigned long *) 0xFFFFF034))
|
||||
#define VICVectAddr0 (*((volatile unsigned long *) 0xFFFFF100))
|
||||
#define VICVectAddr1 (*((volatile unsigned long *) 0xFFFFF104))
|
||||
#define VICVectAddr2 (*((volatile unsigned long *) 0xFFFFF108))
|
||||
#define VICVectAddr3 (*((volatile unsigned long *) 0xFFFFF10C))
|
||||
#define VICVectAddr4 (*((volatile unsigned long *) 0xFFFFF110))
|
||||
#define VICVectAddr5 (*((volatile unsigned long *) 0xFFFFF114))
|
||||
#define VICVectAddr6 (*((volatile unsigned long *) 0xFFFFF118))
|
||||
#define VICVectAddr7 (*((volatile unsigned long *) 0xFFFFF11C))
|
||||
#define VICVectAddr8 (*((volatile unsigned long *) 0xFFFFF120))
|
||||
#define VICVectAddr9 (*((volatile unsigned long *) 0xFFFFF124))
|
||||
#define VICVectAddr10 (*((volatile unsigned long *) 0xFFFFF128))
|
||||
#define VICVectAddr11 (*((volatile unsigned long *) 0xFFFFF12C))
|
||||
#define VICVectAddr12 (*((volatile unsigned long *) 0xFFFFF130))
|
||||
#define VICVectAddr13 (*((volatile unsigned long *) 0xFFFFF134))
|
||||
#define VICVectAddr14 (*((volatile unsigned long *) 0xFFFFF138))
|
||||
#define VICVectAddr15 (*((volatile unsigned long *) 0xFFFFF13C))
|
||||
#define VICVectCntl0 (*((volatile unsigned long *) 0xFFFFF200))
|
||||
#define VICVectCntl1 (*((volatile unsigned long *) 0xFFFFF204))
|
||||
#define VICVectCntl2 (*((volatile unsigned long *) 0xFFFFF208))
|
||||
#define VICVectCntl3 (*((volatile unsigned long *) 0xFFFFF20C))
|
||||
#define VICVectCntl4 (*((volatile unsigned long *) 0xFFFFF210))
|
||||
#define VICVectCntl5 (*((volatile unsigned long *) 0xFFFFF214))
|
||||
#define VICVectCntl6 (*((volatile unsigned long *) 0xFFFFF218))
|
||||
#define VICVectCntl7 (*((volatile unsigned long *) 0xFFFFF21C))
|
||||
#define VICVectCntl8 (*((volatile unsigned long *) 0xFFFFF220))
|
||||
#define VICVectCntl9 (*((volatile unsigned long *) 0xFFFFF224))
|
||||
#define VICVectCntl10 (*((volatile unsigned long *) 0xFFFFF228))
|
||||
#define VICVectCntl11 (*((volatile unsigned long *) 0xFFFFF22C))
|
||||
#define VICVectCntl12 (*((volatile unsigned long *) 0xFFFFF230))
|
||||
#define VICVectCntl13 (*((volatile unsigned long *) 0xFFFFF234))
|
||||
#define VICVectCntl14 (*((volatile unsigned long *) 0xFFFFF238))
|
||||
#define VICVectCntl15 (*((volatile unsigned long *) 0xFFFFF23C))
|
||||
|
||||
/* Pin Connect Block */
|
||||
#define PINSEL0 (*((volatile unsigned long *) 0xE002C000))
|
||||
#define PINSEL1 (*((volatile unsigned long *) 0xE002C004))
|
||||
#define PINSEL2 (*((volatile unsigned long *) 0xE002C014))
|
||||
|
||||
/* General Purpose Input/Output (GPIO) */
|
||||
#define IOPIN0 (*((volatile unsigned long *) 0xE0028000))
|
||||
#define IOSET0 (*((volatile unsigned long *) 0xE0028004))
|
||||
#define IODIR0 (*((volatile unsigned long *) 0xE0028008))
|
||||
#define IOCLR0 (*((volatile unsigned long *) 0xE002800C))
|
||||
#define IOPIN1 (*((volatile unsigned long *) 0xE0028010))
|
||||
#define IOSET1 (*((volatile unsigned long *) 0xE0028014))
|
||||
#define IODIR1 (*((volatile unsigned long *) 0xE0028018))
|
||||
#define IOCLR1 (*((volatile unsigned long *) 0xE002801C))
|
||||
#define IOPIN2 (*((volatile unsigned long *) 0xE0028020))
|
||||
#define IOSET2 (*((volatile unsigned long *) 0xE0028024))
|
||||
#define IODIR2 (*((volatile unsigned long *) 0xE0028028))
|
||||
#define IOCLR2 (*((volatile unsigned long *) 0xE002802C))
|
||||
#define IOPIN3 (*((volatile unsigned long *) 0xE0028030))
|
||||
#define IOSET3 (*((volatile unsigned long *) 0xE0028034))
|
||||
#define IODIR3 (*((volatile unsigned long *) 0xE0028038))
|
||||
#define IOCLR3 (*((volatile unsigned long *) 0xE002803C))
|
||||
|
||||
/* Phase Locked Loop (PLL) */
|
||||
#define PLLCON (*((volatile unsigned char *) 0xE01FC080))
|
||||
#define PLLCFG (*((volatile unsigned char *) 0xE01FC084))
|
||||
#define PLLSTAT (*((volatile unsigned short*) 0xE01FC088))
|
||||
#define PLLFEED (*((volatile unsigned char *) 0xE01FC08C))
|
||||
|
||||
/* VPB Divider */
|
||||
#define VPBDIV (*((volatile unsigned char *) 0xE01FC100))
|
||||
|
||||
/* Power Control */
|
||||
#define PCON (*((volatile unsigned char *) 0xE01FC0C0))
|
||||
#define PCONP (*((volatile unsigned long *) 0xE01FC0C4))
|
||||
|
||||
/* External Interrupts */
|
||||
#define EXTINT (*((volatile unsigned char *) 0xE01FC140))
|
||||
#define EXTWAKE (*((volatile unsigned char *) 0xE01FC144))
|
||||
#define EXTMODE (*((volatile unsigned char *) 0xE01FC148))
|
||||
#define EXTPOLAR (*((volatile unsigned char *) 0xE01FC14C))
|
||||
|
||||
/* Timer 0 */
|
||||
#define T0IR (*((volatile unsigned long *) 0xE0004000))
|
||||
#define T0TCR (*((volatile unsigned long *) 0xE0004004))
|
||||
#define T0TC (*((volatile unsigned long *) 0xE0004008))
|
||||
#define T0PR (*((volatile unsigned long *) 0xE000400C))
|
||||
#define T0PC (*((volatile unsigned long *) 0xE0004010))
|
||||
#define T0MCR (*((volatile unsigned long *) 0xE0004014))
|
||||
#define T0MR0 (*((volatile unsigned long *) 0xE0004018))
|
||||
#define T0MR1 (*((volatile unsigned long *) 0xE000401C))
|
||||
#define T0MR2 (*((volatile unsigned long *) 0xE0004020))
|
||||
#define T0MR3 (*((volatile unsigned long *) 0xE0004024))
|
||||
#define T0CCR (*((volatile unsigned long *) 0xE0004028))
|
||||
#define T0CR0 (*((volatile unsigned long *) 0xE000402C))
|
||||
#define T0CR1 (*((volatile unsigned long *) 0xE0004030))
|
||||
#define T0CR2 (*((volatile unsigned long *) 0xE0004034))
|
||||
#define T0CR3 (*((volatile unsigned long *) 0xE0004038))
|
||||
#define T0EMR (*((volatile unsigned long *) 0xE000403C))
|
||||
|
||||
/* Timer 1 */
|
||||
#define T1IR (*((volatile unsigned long *) 0xE0008000))
|
||||
#define T1TCR (*((volatile unsigned long *) 0xE0008004))
|
||||
#define T1TC (*((volatile unsigned long *) 0xE0008008))
|
||||
#define T1PR (*((volatile unsigned long *) 0xE000800C))
|
||||
#define T1PC (*((volatile unsigned long *) 0xE0008010))
|
||||
#define T1MCR (*((volatile unsigned long *) 0xE0008014))
|
||||
#define T1MR0 (*((volatile unsigned long *) 0xE0008018))
|
||||
#define T1MR1 (*((volatile unsigned long *) 0xE000801C))
|
||||
#define T1MR2 (*((volatile unsigned long *) 0xE0008020))
|
||||
#define T1MR3 (*((volatile unsigned long *) 0xE0008024))
|
||||
#define T1CCR (*((volatile unsigned long *) 0xE0008028))
|
||||
#define T1CR0 (*((volatile unsigned long *) 0xE000802C))
|
||||
#define T1CR1 (*((volatile unsigned long *) 0xE0008030))
|
||||
#define T1CR2 (*((volatile unsigned long *) 0xE0008034))
|
||||
#define T1CR3 (*((volatile unsigned long *) 0xE0008038))
|
||||
#define T1EMR (*((volatile unsigned long *) 0xE000803C))
|
||||
|
||||
/* Pulse Width Modulator (PWM) */
|
||||
#define PWMIR (*((volatile unsigned long *) 0xE0014000))
|
||||
#define PWMTCR (*((volatile unsigned long *) 0xE0014004))
|
||||
#define PWMTC (*((volatile unsigned long *) 0xE0014008))
|
||||
#define PWMPR (*((volatile unsigned long *) 0xE001400C))
|
||||
#define PWMPC (*((volatile unsigned long *) 0xE0014010))
|
||||
#define PWMMCR (*((volatile unsigned long *) 0xE0014014))
|
||||
#define PWMMR0 (*((volatile unsigned long *) 0xE0014018))
|
||||
#define PWMMR1 (*((volatile unsigned long *) 0xE001401C))
|
||||
#define PWMMR2 (*((volatile unsigned long *) 0xE0014020))
|
||||
#define PWMMR3 (*((volatile unsigned long *) 0xE0014024))
|
||||
#define PWMMR4 (*((volatile unsigned long *) 0xE0014040))
|
||||
#define PWMMR5 (*((volatile unsigned long *) 0xE0014044))
|
||||
#define PWMMR6 (*((volatile unsigned long *) 0xE0014048))
|
||||
#define PWMCCR (*((volatile unsigned long *) 0xE0014028))
|
||||
#define PWMCR0 (*((volatile unsigned long *) 0xE001402C))
|
||||
#define PWMCR1 (*((volatile unsigned long *) 0xE0014030))
|
||||
#define PWMCR2 (*((volatile unsigned long *) 0xE0014034))
|
||||
#define PWMCR3 (*((volatile unsigned long *) 0xE0014038))
|
||||
#define PWMEMR (*((volatile unsigned long *) 0xE001403C))
|
||||
#define PWMPCR (*((volatile unsigned long *) 0xE001404C))
|
||||
#define PWMLER (*((volatile unsigned long *) 0xE0014050))
|
||||
|
||||
/* Universal Asynchronous Receiver Transmitter 0 (UART0) */
|
||||
#define U0RBR (*((volatile unsigned char *) 0xE000C000))
|
||||
#define U0THR (*((volatile unsigned char *) 0xE000C000))
|
||||
#define U0IER (*((volatile unsigned char *) 0xE000C004))
|
||||
#define U0IIR (*((volatile unsigned char *) 0xE000C008))
|
||||
#define U0FCR (*((volatile unsigned char *) 0xE000C008))
|
||||
#define U0LCR (*((volatile unsigned char *) 0xE000C00C))
|
||||
#define U0MCR (*((volatile unsigned char *) 0xE000C010))
|
||||
#define U0LSR (*((volatile unsigned char *) 0xE000C014))
|
||||
#define U0MSR (*((volatile unsigned char *) 0xE000C018))
|
||||
#define U0SCR (*((volatile unsigned char *) 0xE000C01C))
|
||||
#define U0FDR (*((volatile unsigned char *) 0xE000C028))
|
||||
#define U0DLL (*((volatile unsigned char *) 0xE000C000))
|
||||
#define U0DLM (*((volatile unsigned char *) 0xE000C004))
|
||||
|
||||
/* Universal Asynchronous Receiver Transmitter 1 (UART1) */
|
||||
#define U1RBR (*((volatile unsigned char *) 0xE0010000))
|
||||
#define U1THR (*((volatile unsigned char *) 0xE0010000))
|
||||
#define U1IER (*((volatile unsigned char *) 0xE0010004))
|
||||
#define U1IIR (*((volatile unsigned char *) 0xE0010008))
|
||||
#define U1FCR (*((volatile unsigned char *) 0xE0010008))
|
||||
#define U1LCR (*((volatile unsigned char *) 0xE001000C))
|
||||
#define U1MCR (*((volatile unsigned char *) 0xE0010010))
|
||||
#define U1LSR (*((volatile unsigned char *) 0xE0010014))
|
||||
#define U1MSR (*((volatile unsigned char *) 0xE0010018))
|
||||
#define U1SCR (*((volatile unsigned char *) 0xE001001C))
|
||||
#define U1DLL (*((volatile unsigned char *) 0xE0010000))
|
||||
#define U1DLM (*((volatile unsigned char *) 0xE0010004))
|
||||
|
||||
/* I2C Interface */
|
||||
#define I2CONSET (*((volatile unsigned char *) 0xE001C000))
|
||||
#define I2STAT (*((volatile unsigned char *) 0xE001C004))
|
||||
#define I2DAT (*((volatile unsigned char *) 0xE001C008))
|
||||
#define I2ADR (*((volatile unsigned char *) 0xE001C00C))
|
||||
#define I2SCLH (*((volatile unsigned short*) 0xE001C010))
|
||||
#define I2SCLL (*((volatile unsigned short*) 0xE001C014))
|
||||
#define I2CONCLR (*((volatile unsigned char *) 0xE001C018))
|
||||
|
||||
/* SPI0 (Serial Peripheral Interface 0) */
|
||||
#define S0SPCR (*((volatile unsigned char *) 0xE0020000))
|
||||
#define S0SPSR (*((volatile unsigned char *) 0xE0020004))
|
||||
#define S0SPDR (*((volatile unsigned char *) 0xE0020008))
|
||||
#define S0SPCCR (*((volatile unsigned char *) 0xE002000C))
|
||||
#define S0SPTCR (*((volatile unsigned char *) 0xE0020010))
|
||||
#define S0SPTSR (*((volatile unsigned char *) 0xE0020014))
|
||||
#define S0SPTOR (*((volatile unsigned char *) 0xE0020018))
|
||||
#define S0SPINT (*((volatile unsigned char *) 0xE002001C))
|
||||
|
||||
/* SPI1 (Serial Peripheral Interface 1) */
|
||||
#define S1SPCR (*((volatile unsigned char *) 0xE0030000))
|
||||
#define S1SPSR (*((volatile unsigned char *) 0xE0030004))
|
||||
#define S1SPDR (*((volatile unsigned char *) 0xE0030008))
|
||||
#define S1SPCCR (*((volatile unsigned char *) 0xE003000C))
|
||||
#define S1SPTCR (*((volatile unsigned char *) 0xE0030010))
|
||||
#define S1SPTSR (*((volatile unsigned char *) 0xE0030014))
|
||||
#define S1SPTOR (*((volatile unsigned char *) 0xE0030018))
|
||||
#define S1SPINT (*((volatile unsigned char *) 0xE003001C))
|
||||
|
||||
/* Real Time Clock */
|
||||
#define ILR (*((volatile unsigned char *) 0xE0024000))
|
||||
#define CTC (*((volatile unsigned short*) 0xE0024004))
|
||||
#define CCR (*((volatile unsigned char *) 0xE0024008))
|
||||
#define CIIR (*((volatile unsigned char *) 0xE002400C))
|
||||
#define AMR (*((volatile unsigned char *) 0xE0024010))
|
||||
#define CTIME0 (*((volatile unsigned long *) 0xE0024014))
|
||||
#define CTIME1 (*((volatile unsigned long *) 0xE0024018))
|
||||
#define CTIME2 (*((volatile unsigned long *) 0xE002401C))
|
||||
#define SEC (*((volatile unsigned char *) 0xE0024020))
|
||||
#define MIN (*((volatile unsigned char *) 0xE0024024))
|
||||
#define HOUR (*((volatile unsigned char *) 0xE0024028))
|
||||
#define DOM (*((volatile unsigned char *) 0xE002402C))
|
||||
#define DOW (*((volatile unsigned char *) 0xE0024030))
|
||||
#define DOY (*((volatile unsigned short*) 0xE0024034))
|
||||
#define MONTH (*((volatile unsigned char *) 0xE0024038))
|
||||
#define YEAR (*((volatile unsigned short*) 0xE002403C))
|
||||
#define ALSEC (*((volatile unsigned char *) 0xE0024060))
|
||||
#define ALMIN (*((volatile unsigned char *) 0xE0024064))
|
||||
#define ALHOUR (*((volatile unsigned char *) 0xE0024068))
|
||||
#define ALDOM (*((volatile unsigned char *) 0xE002406C))
|
||||
#define ALDOW (*((volatile unsigned char *) 0xE0024070))
|
||||
#define ALDOY (*((volatile unsigned short*) 0xE0024074))
|
||||
#define ALMON (*((volatile unsigned char *) 0xE0024078))
|
||||
#define ALYEAR (*((volatile unsigned short*) 0xE002407C))
|
||||
#define PREINT (*((volatile unsigned short*) 0xE0024080))
|
||||
#define PREFRAC (*((volatile unsigned short*) 0xE0024084))
|
||||
|
||||
/* A/D Converter */
|
||||
#define ADCR (*((volatile unsigned long *) 0xE0034000))
|
||||
#define ADDR (*((volatile unsigned long *) 0xE0034004))
|
||||
|
||||
/* Watchdog */
|
||||
#define WDMOD (*((volatile unsigned char *) 0xE0000000))
|
||||
#define WDTC (*((volatile unsigned long *) 0xE0000004))
|
||||
#define WDFEED (*((volatile unsigned char *) 0xE0000008))
|
||||
#define WDTV (*((volatile unsigned long *) 0xE000000C))
|
||||
|
||||
/* Memory Mapping control register */
|
||||
#define MEMMAP (*((volatile unsigned long *) 0xE01FC040))
|
||||
|
||||
#endif /* __ASM_ARCH_HARDWARE_H */
|
60
lpctool/trunk/lpc2220.ld
Normal file
60
lpctool/trunk/lpc2220.ld
Normal file
|
@ -0,0 +1,60 @@
|
|||
/* identify the Entry Point */
|
||||
|
||||
ENTRY(Reset_Handler)
|
||||
|
||||
/* specify the LPC2106 memory areas */
|
||||
|
||||
MEMORY
|
||||
{
|
||||
flash : ORIGIN = 0x00000000, LENGTH = 128K /* free FLASH EPROM area */
|
||||
ram : ORIGIN = 0x40000200, LENGTH = 64K - 0x200 /* free RAM area */
|
||||
}
|
||||
|
||||
/* define a global symbol _stack_end */
|
||||
|
||||
_stack_end = 0x4000FEDC;
|
||||
|
||||
/* now define the output sections */
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
startup :
|
||||
{
|
||||
*(.startup)
|
||||
} >ram /* the startup code goes into FLASH */
|
||||
|
||||
.text : /* collect all sections that should go into FLASH after startup */
|
||||
{
|
||||
*(.text) /* all .text sections (code) */
|
||||
*(.rodata) /* all .rodata sections (constants, strings, etc.) */
|
||||
*(.rodata*) /* all .rodata* sections (constants, strings, etc.) */
|
||||
*(.glue_7) /* all .glue_7 sections (no idea what these are) */
|
||||
*(.glue_7t) /* all .glue_7t sections (no idea what these are) */
|
||||
_etext = .; /* define a global symbol _etext just after the last code byte */
|
||||
} >ram /* put all the above into FLASH */
|
||||
|
||||
.data : /* collect all initialized .data sections that go into RAM */
|
||||
{
|
||||
_data = .; /* create a global symbol marking the start of the .data section */
|
||||
*(.data) /* all .data sections */
|
||||
_edata = .; /* define a global symbol marking the end of the .data section */
|
||||
} >ram /* put all the above into RAM (but load the LMA copy into FLASH) */
|
||||
|
||||
.bss : /* collect all uninitialized .bss sections that go into RAM */
|
||||
{
|
||||
_bss_start = .; /* define a global symbol marking the start of the .bss section */
|
||||
*(.bss) /* all .bss sections */
|
||||
} >ram /* put all the above in RAM (it will be cleared in the startup code */
|
||||
|
||||
. = ALIGN(4); /* advance location counter to the next 32-bit boundary */
|
||||
_bss_end = . ; /* define a global symbol marking the end of the .bss section */
|
||||
|
||||
_end = .; /* define a global symbol marking the end of application RAM */
|
||||
}
|
||||
|
||||
PROVIDE( BCFG0 = 0xFFE00000);
|
||||
PROVIDE( BCFG1 = 0xFFE00004);
|
||||
PROVIDE( BCFG2 = 0xFFE00008);
|
||||
PROVIDE( PINSEL0 = 0xE002C000);
|
||||
PROVIDE( PINSEL2 = 0xE002C014);
|
||||
PROVIDE( IO0PIN = 0xE0028000);
|
61
lpctool/trunk/lpc2220_rom.ld
Normal file
61
lpctool/trunk/lpc2220_rom.ld
Normal file
|
@ -0,0 +1,61 @@
|
|||
/* identify the Entry Point */
|
||||
|
||||
ENTRY(_startup)
|
||||
|
||||
/* specify the LPC2106 memory areas */
|
||||
|
||||
MEMORY
|
||||
{
|
||||
flash : ORIGIN = 0x80000000, LENGTH = 1M /* FLASH ROM */
|
||||
ram : ORIGIN = 0x40000200, LENGTH = 64K - 0x220 /* free RAM area */
|
||||
}
|
||||
|
||||
/* define a global symbol _stack_end */
|
||||
|
||||
_stack_end = 0x4000FEDC;
|
||||
|
||||
/* now define the output sections */
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = 0; /* set location counter to address zero */
|
||||
|
||||
startup :
|
||||
{
|
||||
*(.startup)
|
||||
} >flash /* the startup code goes into FLASH */
|
||||
|
||||
.text : /* collect all sections that should go into FLASH after startup */
|
||||
{
|
||||
*(.text) /* all .text sections (code) */
|
||||
*(.rodata) /* all .rodata sections (constants, strings, etc.) */
|
||||
*(.rodata*) /* all .rodata* sections (constants, strings, etc.) */
|
||||
*(.glue_7) /* all .glue_7 sections (no idea what these are) */
|
||||
*(.glue_7t) /* all .glue_7t sections (no idea what these are) */
|
||||
_etext = .; /* define a global symbol _etext just after the last code byte */
|
||||
} >flash /* put all the above into FLASH */
|
||||
|
||||
.data : /* collect all initialized .data sections that go into RAM */
|
||||
{
|
||||
_data = .; /* create a global symbol marking the start of the .data section */
|
||||
*(.data) /* all .data sections */
|
||||
_edata = .; /* define a global symbol marking the end of the .data section */
|
||||
} >ram AT >flash /* put all the above into RAM (but load the LMA copy into FLASH) */
|
||||
|
||||
.bss : /* collect all uninitialized .bss sections that go into RAM */
|
||||
{
|
||||
_bss_start = .; /* define a global symbol marking the start of the .bss section */
|
||||
*(.bss) /* all .bss sections */
|
||||
} >ram /* put all the above in RAM (it will be cleared in the startup code */
|
||||
|
||||
. = ALIGN(4); /* advance location counter to the next 32-bit boundary */
|
||||
_bss_end = . ; /* define a global symbol marking the end of the .bss section */
|
||||
}
|
||||
_end = .; /* define a global symbol marking the end of application RAM */
|
||||
|
||||
PROVIDE( BCFG0 = 0xFFE00000);
|
||||
PROVIDE( BCFG1 = 0xFFE00004);
|
||||
PROVIDE( BCFG2 = 0xFFE00008);
|
||||
PROVIDE( PINSEL0 = 0xE002C000);
|
||||
PROVIDE( PINSEL2 = 0xE002C014);
|
||||
PROVIDE( IO0PIN = 0xE0028000);
|
485
lpctool/trunk/lpctool.c
Normal file
485
lpctool/trunk/lpctool.c
Normal file
|
@ -0,0 +1,485 @@
|
|||
#include "infohelper.h"
|
||||
#include "lpctool_serial.h"
|
||||
#include "bootcom.h"
|
||||
#include "toolcom.h"
|
||||
|
||||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 9
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
unsigned long radr, f0adr, f1adr, gadr;
|
||||
|
||||
void printHeader(void)
|
||||
{
|
||||
printf("\nlpctool V%i.%i\n\n", VERSION_MAJOR, VERSION_MINOR);
|
||||
printf("This Software is free Software under GNU GPL 3 or later\n");
|
||||
printf("(c) 2007 Ch. Klippel <ck@mamalala.net>\n\n");
|
||||
}
|
||||
|
||||
void printUsage(void)
|
||||
{
|
||||
printf("usage: lpctool [-d NAME] [-i] [-r [NAME]] [-R ADDRESS] [-X [ADDRESS]] [-a [NAME] [-A ADRDESS]] [-e] [-b [NAME] [-B ADDRESS]] [-E] [-s] [-S] [-c] [-C] [-v] [-V]\n\n");
|
||||
printf(" -d NAME specify serial device, default is /dev/ttyS0\n");
|
||||
printf(" -i use compiled-in flash-tool instead of external ram image file\n");
|
||||
printf(" -r NAME specify file for ram, default is ramtool.bin\n");
|
||||
printf(" -R ADDRESS optionally specifies the start-address to load into ram\n");
|
||||
printf(" default is 0x40000200 - must be specified in hex\n");
|
||||
printf(" -X ADDRESS set the execution address for the uploaded ram image\n");
|
||||
printf(" defualt is 0x40000200, omiting the address disables execution\n");
|
||||
printf(" -a NAME specify file for flash #0, default is flash0.bin\n");
|
||||
printf(" -A ADDRESS optionally specifies the start-address to load into flash #0\n");
|
||||
printf(" default is 0x80000000 - must be specified in hex\n");
|
||||
printf(" -e completely erase the first flash before writing\n");
|
||||
printf(" default is no erase\n");
|
||||
printf(" -b NAME specify file for flash #1, default is flash1.bin\n");
|
||||
printf(" -B ADDRESS optionally specifies the start-address to load into flash #1\n");
|
||||
printf(" default is 0x82000000 - must be specified in hex\n");
|
||||
printf(" -E completely erase the second flash before writing\n");
|
||||
printf(" defualt is no erase\n");
|
||||
printf(" -S only erase the first sector in flash before writing\n");
|
||||
printf(" this is a lot faster if only the first sector is used\n");
|
||||
printf(" -c write flash0 in chunk mode instead of write-all\n");
|
||||
printf(" -C write flash1 in chunk mode instead of write-all\n");
|
||||
printf(" in chunk mode, parts with 4 consectuive 0xFFFFFFFF or more\n");
|
||||
printf(" in the image are skipped. speeds upload when the image has\n");
|
||||
printf(" gaps. defualt is off\n");
|
||||
printf(" -N do not reset the device after uploading to flash\n");
|
||||
printf(" by default the device gets reset after upload\n");
|
||||
printf(" -? print this help\n");
|
||||
printf(" -v print version\n");
|
||||
printf(" -V be more verbose\n");
|
||||
printf("\n");
|
||||
printf("at least -r or -i must be given to be usefull. everything in [] is optional\n");
|
||||
printf("examples:\n");
|
||||
printf("\n");
|
||||
printf("to just load ramtool.bin, starting at 0x40000200, using serial device /dev/ttyS0 :\n");
|
||||
printf("lpcload -r\n\n");
|
||||
printf("to do the same, but using serial device /dev/ttyS1 instead :\n");
|
||||
printf("lpcload -r -d /dev/ttyS1\n\n");
|
||||
printf("using the file image.bin as source for the ram, use /dev/ttyS1 as serial device :\n");
|
||||
printf("lpcload -r image.bin -d /dev/ttyS1\n");
|
||||
}
|
||||
|
||||
unsigned long parseHex(char *buf)
|
||||
{
|
||||
unsigned char cnt;
|
||||
unsigned long adr;
|
||||
|
||||
cnt = 0;
|
||||
adr = 0;
|
||||
|
||||
while(buf[cnt])
|
||||
{
|
||||
adr <<= 4;
|
||||
if(buf[cnt] >= '0' && buf[cnt] <= '9')
|
||||
{
|
||||
adr += (buf[cnt] - '0');
|
||||
}
|
||||
else if(buf[cnt] >= 'A' && buf[cnt] <= 'F')
|
||||
{
|
||||
adr += (buf[cnt] - 'A' + 10);
|
||||
}
|
||||
else if(buf[cnt] >= 'a' && buf[cnt] <= 'f')
|
||||
{
|
||||
adr += (buf[cnt] - 'a' + 10);
|
||||
}
|
||||
else if(buf[cnt] == 'x' || buf[cnt] == 'X')
|
||||
{
|
||||
adr = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
cnt++;
|
||||
}
|
||||
return adr;
|
||||
}
|
||||
|
||||
const char hval[] = { "0123456789ABCDEF" };
|
||||
|
||||
void printHexC(unsigned char num)
|
||||
{
|
||||
printf("%c%c", hval[(num&0xF0)>>4], hval[num&0x0F]);
|
||||
}
|
||||
|
||||
void printHexS(unsigned short num)
|
||||
{
|
||||
printHexC((num & 0xFF00) >> 8);
|
||||
printHexC(num & 0x00FF);
|
||||
}
|
||||
|
||||
void printHexW(unsigned long num)
|
||||
{
|
||||
printHexS((num & 0xFFFF0000) >> 16);
|
||||
printHexS(num & 0x0000FFFF);
|
||||
}
|
||||
/*
|
||||
void enterBootLD(void)
|
||||
{
|
||||
setDTR(1);
|
||||
usleep(10);
|
||||
setRTS(1);
|
||||
usleep(100);
|
||||
setRTS(0);
|
||||
usleep(10);
|
||||
setDTR(0);
|
||||
usleep(100);
|
||||
}
|
||||
|
||||
void resetFB(void)
|
||||
{
|
||||
setRTS(1);
|
||||
usleep(100);
|
||||
setRTS(0);
|
||||
}
|
||||
*/
|
||||
void enterBootLD(void)
|
||||
{
|
||||
setRTS(1);
|
||||
usleep(10);
|
||||
setDTR(1);
|
||||
usleep(100);
|
||||
setDTR(0);
|
||||
usleep(10);
|
||||
setRTS(0);
|
||||
usleep(100);
|
||||
}
|
||||
|
||||
void resetFB(void)
|
||||
{
|
||||
setDTR(1);
|
||||
usleep(100);
|
||||
setDTR(0);
|
||||
}
|
||||
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
char sname[256];
|
||||
char rname[256];
|
||||
char f0name[256];
|
||||
char f1name[256];
|
||||
unsigned char i, cmd;
|
||||
unsigned int uflags;
|
||||
int fd;
|
||||
|
||||
sprintf(sname,"/dev/ttyS0");
|
||||
sprintf(rname,"ramtool.bin");
|
||||
sprintf(f0name,"flash0.bin");
|
||||
sprintf(f1name,"flash1.bin");
|
||||
|
||||
verbosity = 0;
|
||||
uflags = 0;
|
||||
|
||||
radr = 0x40000200;
|
||||
f0adr = 0x80000000;
|
||||
f1adr = 0x82000000;
|
||||
gadr = radr;
|
||||
|
||||
printHeader();
|
||||
|
||||
for(i=1;i<argc;i++)
|
||||
{
|
||||
if(argv[i][0] == '-')
|
||||
{
|
||||
cmd = 0;
|
||||
if(argv[i][1] == '-')
|
||||
{
|
||||
cmd = argv[i][2];
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd = argv[i][1];
|
||||
}
|
||||
|
||||
switch(cmd)
|
||||
{
|
||||
case 'v':
|
||||
verbosity = 2;
|
||||
break;
|
||||
case 'V':
|
||||
goto end;
|
||||
case 'd':
|
||||
if((argc > i+1) && (argv[i+1][0] != '-'))
|
||||
{
|
||||
strncpy(sname,argv[++i],256);
|
||||
printInfoS(1,"using serial device",sname);
|
||||
}
|
||||
else
|
||||
{
|
||||
printError("Error in device argument");
|
||||
goto bailout;
|
||||
}
|
||||
break;
|
||||
case 'r':
|
||||
if((argc > i+1) && (argv[i+1][0] != '-'))
|
||||
{
|
||||
strncpy(rname,argv[++i],256);
|
||||
printInfoS(1,"using ram image",rname);
|
||||
}
|
||||
uflags |= 0x01;
|
||||
break;
|
||||
case 'R':
|
||||
if((argc > i+1) && (argv[i+1][0] != '-'))
|
||||
{
|
||||
radr = parseHex(argv[++i]);
|
||||
printInfoH(1,"loading ram @",radr);
|
||||
}
|
||||
else
|
||||
printInfoH(1,"used -R but no address given, using default", radr);
|
||||
break;
|
||||
case 'a':
|
||||
if((argc > i+1) && (argv[i+1][0] != '-'))
|
||||
{
|
||||
strncpy(f0name,argv[++i],256);
|
||||
printInfoS(1,"using flash #0 image",f0name);
|
||||
}
|
||||
uflags |= 0x02;
|
||||
break;
|
||||
case 'A':
|
||||
if((argc > i+1) && (argv[i+1][0] != '-'))
|
||||
{
|
||||
f0adr = parseHex(argv[++i]);
|
||||
printInfoH(1,"setting address for flash #0 @",f0adr);
|
||||
}
|
||||
else
|
||||
printInfoH(1,"used -A but no address given, using default",f0adr);
|
||||
break;
|
||||
case 'b':
|
||||
if((argc > i+1) && (argv[i+1][0] != '-'))
|
||||
{
|
||||
strncpy(f1name,argv[++i],256);
|
||||
printInfoS(1,"using flash #1 image",f1name);
|
||||
}
|
||||
uflags |= 0x04;
|
||||
break;
|
||||
case 'B':
|
||||
if((argc > i+1) && (argv[i+1][0] != '-'))
|
||||
{
|
||||
f1adr = parseHex(argv[++i]);
|
||||
printInfoH(1,"setting address for flash #1 @",f1adr);
|
||||
}
|
||||
else
|
||||
printInfoH(1,"used -B but no address given, using default",f1adr);
|
||||
break;
|
||||
case 'X':
|
||||
if((argc > i+1) && (argv[i+1][0] != '-'))
|
||||
{
|
||||
gadr = parseHex(argv[++i]);
|
||||
printInfoH(1,"setting ram execute address @",gadr);
|
||||
uflags |= 0x08;
|
||||
}
|
||||
else
|
||||
printInfoS(1,"disabling auto-run",0);
|
||||
break;
|
||||
case 'e':
|
||||
printInfoS(1,"erasing flash #0 before write",0);
|
||||
uflags |= 0x10;
|
||||
break;
|
||||
case 'E':
|
||||
printInfoS(1,"erasing flash #1 before write",0);
|
||||
uflags |= 0x20;
|
||||
break;
|
||||
case 'S':
|
||||
printInfoS(1,"only erasing start sector",0);
|
||||
uflags |= 0x40;
|
||||
break;
|
||||
case 's':
|
||||
printInfoS(1,"auto-erasing sectors as needed",0);
|
||||
uflags |= 0x80;
|
||||
break;
|
||||
case 'N':
|
||||
printInfoS(1,"dont reset after flash upload is done",0);
|
||||
uflags |= 0x100;
|
||||
break;
|
||||
case 'c':
|
||||
printInfoS(1,"using chunk mode for flash #0",0);
|
||||
uflags |= 0x200;
|
||||
break;
|
||||
case 'C':
|
||||
printInfoS(1,"using chunk mode for flash #1",0);
|
||||
uflags |= 0x400;
|
||||
break;
|
||||
case 'i':
|
||||
uflags |= 0x800;
|
||||
break;
|
||||
default:
|
||||
goto bailout;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bailout:
|
||||
printUsage();
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
if(!uflags)
|
||||
{
|
||||
printUsage();
|
||||
printInfoS(0,"\nnothing to do!",0);
|
||||
goto end;
|
||||
}
|
||||
|
||||
printInfoS(2,"opening serial device",sname);
|
||||
if(openSerial(sname) <= 0)
|
||||
{
|
||||
printError("Error opening serial device");
|
||||
goto end;
|
||||
}
|
||||
|
||||
if((uflags & 0x01) || (uflags & 0x800))
|
||||
{
|
||||
if(!(uflags & 0x800))
|
||||
{
|
||||
printInfoS(2,"opening ram image",rname);
|
||||
fd = open(rname,O_RDONLY);
|
||||
if(fd < 0)
|
||||
{
|
||||
printErrorS("cant open",rname);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fd = 0;
|
||||
}
|
||||
|
||||
printInfoS(2,"reset into bootmode",0);
|
||||
enterBootLD();
|
||||
|
||||
printInfoS(2,"opening bootloader",0);
|
||||
if(!openBootLoader(10000))
|
||||
{
|
||||
printError("Error opening BootLoader");
|
||||
goto end;
|
||||
}
|
||||
|
||||
printInfoS(2,"unlocking bootloader",0);
|
||||
if(!unlockBootLoader())
|
||||
{
|
||||
printError("Error unlocking BootLoader");
|
||||
goto end;
|
||||
}
|
||||
if(!(uflags & 0x800))
|
||||
{
|
||||
printInfoS(1,"uploading ram image",rname);
|
||||
}
|
||||
else
|
||||
{
|
||||
printInfoS(1,"uploading compiled-in ram image",0);
|
||||
}
|
||||
if(uploadRAM(fd, radr))
|
||||
{
|
||||
printInfoS(1,"ram uploaded",0);
|
||||
if(!(uflags&0x08))
|
||||
{
|
||||
printInfoH(1,"executing code at ram address",gadr);
|
||||
if(!goBootLoader(gadr))
|
||||
{
|
||||
printError("Error starting from ram");
|
||||
goto end;
|
||||
}
|
||||
printInfoH(2,"code execution started",gadr);
|
||||
}
|
||||
}
|
||||
if(fd)
|
||||
{
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
usleep(100000);
|
||||
reconfSerial(TOOLBAUD, 0, 5);
|
||||
|
||||
//while(1)
|
||||
{};
|
||||
|
||||
if(uflags & 0x06)
|
||||
{
|
||||
printInfoS(2,"opening ram tool",0);
|
||||
if(openRamTool())
|
||||
printInfoS(2,"opened ramtool",0);
|
||||
else
|
||||
goto end;
|
||||
|
||||
if(uflags & 0x02)
|
||||
{
|
||||
printInfoS(2,"opening flash0 image",f0name);
|
||||
fd = open(f0name,O_RDONLY);
|
||||
if(fd < 0)
|
||||
{
|
||||
printErrorS("cant open",f0name);
|
||||
goto end;
|
||||
}
|
||||
printInfoS(1,"uploading flash0 image",f0name);
|
||||
if(uflags & 0x200)
|
||||
{
|
||||
if(uploadChunks(fd, f0adr, (uflags & 0x50)))
|
||||
printInfoS(1,"flash #0 uploaded",0);
|
||||
else
|
||||
goto end;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(uploadFlash(fd, f0adr, (uflags & 0x50)))
|
||||
printInfoS(1,"flash #0 uploaded",0);
|
||||
else
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
if(uflags & 0x04)
|
||||
{
|
||||
printInfoS(2,"opening flash1 image",f1name);
|
||||
fd = open(f1name,O_RDONLY);
|
||||
if(fd < 0)
|
||||
{
|
||||
printErrorS("cant open",f1name);
|
||||
goto end;
|
||||
}
|
||||
printInfoS(1,"uploading flash1 image",f1name);
|
||||
if(uflags & 0x400)
|
||||
{
|
||||
if(uploadChunks(fd, f1adr, (uflags & 0x60)))
|
||||
printInfoS(1,"flash #1 uploaded",0);
|
||||
else
|
||||
goto end;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(uploadFlash(fd, f1adr, (uflags & 0x60)))
|
||||
printInfoS(1,"flash #1 uploaded",0);
|
||||
else
|
||||
goto end;
|
||||
}
|
||||
|
||||
}
|
||||
close(fd);
|
||||
if((uflags & 06) && !(uflags & 0x100))
|
||||
{
|
||||
printInfoS(2,"reset device",0);
|
||||
resetFB();
|
||||
}
|
||||
}
|
||||
|
||||
end:
|
||||
if(fd)
|
||||
{
|
||||
printInfoS(2,"closing file descriptor",0);
|
||||
close(fd);
|
||||
}
|
||||
printInfoS(2,"closing serial device",sname);
|
||||
closeSerial();
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
247
lpctool/trunk/lpctool_serial.c
Normal file
247
lpctool/trunk/lpctool_serial.c
Normal file
|
@ -0,0 +1,247 @@
|
|||
#include "lpctool_serial.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <termios.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "infohelper.h"
|
||||
|
||||
#define MAX(x,y) ((x) > (y) ? (x) : (y))
|
||||
#define MIN(x,y) ((x) < (y) ? (x) : (y))
|
||||
|
||||
static int serialDev = -1;
|
||||
static struct termios term;
|
||||
|
||||
void setBaud(unsigned int baud)
|
||||
{
|
||||
// change baudrate
|
||||
switch(baud)
|
||||
{
|
||||
case 2400:
|
||||
cfsetispeed(&term,B2400);
|
||||
cfsetospeed(&term,B2400);
|
||||
break;
|
||||
case 4800:
|
||||
cfsetispeed(&term,B4800);
|
||||
cfsetospeed(&term,B4800);
|
||||
break;
|
||||
case 9600:
|
||||
cfsetispeed(&term,B9600);
|
||||
cfsetospeed(&term,B9600);
|
||||
break;
|
||||
case 19200:
|
||||
cfsetispeed(&term,B19200);
|
||||
cfsetospeed(&term,B19200);
|
||||
break;
|
||||
case 38400:
|
||||
cfsetispeed(&term,B38400);
|
||||
cfsetospeed(&term,B38400);
|
||||
break;
|
||||
case 57600:
|
||||
cfsetispeed(&term,B57600);
|
||||
cfsetospeed(&term,B57600);
|
||||
break;
|
||||
case 115200:
|
||||
cfsetispeed(&term,B115200);
|
||||
cfsetospeed(&term,B115200);
|
||||
break;
|
||||
case 230400:
|
||||
cfsetispeed(&term,B230400);
|
||||
cfsetospeed(&term,B230400);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void setFlow(unsigned char flow)
|
||||
{
|
||||
if(flow == 0)
|
||||
{
|
||||
term.c_iflag&=~(IXON|IXOFF|IXANY|INLCR|ICRNL);
|
||||
}
|
||||
else
|
||||
{
|
||||
term.c_iflag&=~(INLCR|ICRNL|IXANY);
|
||||
term.c_iflag|=(IXON|IXOFF);
|
||||
}
|
||||
}
|
||||
|
||||
void setTimeout(unsigned int tout)
|
||||
{
|
||||
term.c_cc[VMIN]=0;
|
||||
term.c_cc[VTIME]=tout; // 10 seconds timeout
|
||||
}
|
||||
|
||||
int openSerial(char *dev)
|
||||
{
|
||||
|
||||
serialDev=open(dev,O_RDWR);
|
||||
if(serialDev<0) {
|
||||
printf("cannot acces %s\n",dev);
|
||||
return serialDev;
|
||||
}
|
||||
|
||||
setDTR(0);
|
||||
setRTS(0);
|
||||
|
||||
tcgetattr(serialDev,&term);
|
||||
|
||||
setBaud(19200);
|
||||
|
||||
term.c_cflag = (term.c_cflag & ~CSIZE) | CS8;
|
||||
term.c_cflag |= CLOCAL | CREAD;
|
||||
|
||||
term.c_cflag &= ~(PARENB | PARODD);
|
||||
term.c_cflag &= ~CSTOPB;
|
||||
term.c_iflag=IGNBRK;
|
||||
|
||||
term.c_iflag |= IXON | IXOFF;
|
||||
|
||||
term.c_lflag=0;
|
||||
|
||||
term.c_oflag=0;
|
||||
|
||||
|
||||
setTimeout(30);
|
||||
|
||||
if (tcsetattr(serialDev, TCSANOW, &term)!=0)
|
||||
return printError("setattr stage 1 failed");
|
||||
|
||||
|
||||
if (tcgetattr(serialDev, &term)!=0)
|
||||
return printError("getattr failed");
|
||||
|
||||
|
||||
term.c_cflag &= ~CRTSCTS;
|
||||
|
||||
if (tcsetattr(serialDev, TCSANOW, &term)!=0)
|
||||
return printError("setattr stage 2 failed");
|
||||
|
||||
return serialDev;
|
||||
}
|
||||
|
||||
int closeSerial(void)
|
||||
{
|
||||
if(serialDev)
|
||||
{
|
||||
tcflush(serialDev, TCIOFLUSH);
|
||||
close(serialDev);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return serialDev;
|
||||
}
|
||||
|
||||
int reconfSerial(unsigned int baud, unsigned char flow, unsigned char tout)
|
||||
{
|
||||
if(serialDev > 0)
|
||||
{
|
||||
|
||||
setBaud(baud);
|
||||
setFlow(flow);
|
||||
setTimeout(tout);
|
||||
return tcsetattr(serialDev,TCSANOW,&term);
|
||||
}
|
||||
else
|
||||
return serialDev;
|
||||
}
|
||||
|
||||
#define XFERSIZE 16
|
||||
|
||||
int sendBuf(unsigned int len, char *buf)
|
||||
{
|
||||
unsigned int boff;
|
||||
int ret;
|
||||
|
||||
if(serialDev > 0)
|
||||
{
|
||||
boff = 0;
|
||||
while (boff < len)
|
||||
{
|
||||
ret = write (serialDev, buf+boff, MIN (len - boff, XFERSIZE));
|
||||
if (ret < 0 && errno != EAGAIN)
|
||||
{
|
||||
perror ("error writing to serial port");
|
||||
return 0;
|
||||
}
|
||||
boff += ret;
|
||||
}
|
||||
return boff;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sendBufE(unsigned int len, char *buf)
|
||||
{
|
||||
return(getBuf(sendBuf(len,buf), buf));
|
||||
}
|
||||
|
||||
int getBuf(unsigned int len, char *buf)
|
||||
{
|
||||
unsigned int boff;
|
||||
int ret;
|
||||
|
||||
if(serialDev > 0)
|
||||
{
|
||||
boff = 0;
|
||||
while (boff < len)
|
||||
{
|
||||
ret = read (serialDev, buf+boff, MIN (len - boff, XFERSIZE));
|
||||
if (ret < 0 && errno != EAGAIN)
|
||||
{
|
||||
perror ("error reading from serial port");
|
||||
return 0;
|
||||
}
|
||||
boff += ret;
|
||||
}
|
||||
return boff;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void setDTR(unsigned char val)
|
||||
{
|
||||
int mcs;
|
||||
if(serialDev)
|
||||
{
|
||||
ioctl (serialDev, TIOCMGET, &mcs);
|
||||
if(val)
|
||||
{
|
||||
mcs |= TIOCM_DTR;
|
||||
ioctl (serialDev, TIOCMSET, &mcs);
|
||||
}
|
||||
else
|
||||
{
|
||||
mcs &= ~TIOCM_DTR;
|
||||
ioctl (serialDev, TIOCMSET, &mcs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setRTS(unsigned char val)
|
||||
{
|
||||
int mcs;
|
||||
if(serialDev)
|
||||
{
|
||||
ioctl (serialDev, TIOCMGET, &mcs);
|
||||
if(val)
|
||||
{
|
||||
mcs |= TIOCM_RTS;
|
||||
ioctl (serialDev, TIOCMSET, &mcs);
|
||||
}
|
||||
else
|
||||
{
|
||||
mcs &= ~TIOCM_RTS;
|
||||
ioctl (serialDev, TIOCMSET, &mcs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
15
lpctool/trunk/lpctool_serial.h
Normal file
15
lpctool/trunk/lpctool_serial.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
#ifndef LPCTOOL_SERIAL_H
|
||||
#define LPCTOOL_SERIAL_H
|
||||
|
||||
|
||||
#define TOOLBAUD 115200
|
||||
|
||||
int openSerial(char *dev);
|
||||
int closeSerial(void);
|
||||
int reconfSerial(unsigned int baud, unsigned char flow, unsigned char tout);
|
||||
int sendBuf(unsigned int len, char *buf);
|
||||
int getBuf(unsigned int len, char *buf);
|
||||
void setDTR(unsigned char val);
|
||||
void setRTS(unsigned char val);
|
||||
|
||||
#endif
|
357
lpctool/trunk/ramtool.c
Normal file
357
lpctool/trunk/ramtool.c
Normal file
|
@ -0,0 +1,357 @@
|
|||
void IRQ_Routine (void) __attribute__ ((interrupt("IRQ")));
|
||||
void FIQ_Routine (void) __attribute__ ((interrupt("FIQ")));
|
||||
void SWI_Routine (void) __attribute__ ((interrupt("SWI")));
|
||||
void UNDEF_Routine (void) __attribute__ ((interrupt("UNDEF")));
|
||||
|
||||
typedef volatile unsigned int *reg32_t;
|
||||
|
||||
|
||||
#include "lpc2220.h"
|
||||
#include "serial.h"
|
||||
#include "flash.h"
|
||||
#include "lcd.h"
|
||||
#include "toolcmd.h"
|
||||
#include "fonty.h"
|
||||
|
||||
union
|
||||
{
|
||||
unsigned long wbuf[128];
|
||||
unsigned short sbuf[256];
|
||||
unsigned char bbuf[512];
|
||||
} buf;
|
||||
|
||||
unsigned long checksum;
|
||||
unsigned short count;
|
||||
unsigned long adr;
|
||||
unsigned long numBytes;
|
||||
|
||||
void putHN(unsigned char pos, unsigned long hn)
|
||||
{
|
||||
draw_string(33,pos,"0x",3,DRAW_PUT);
|
||||
draw_hexW(45,pos,hn,3,DRAW_PUT);
|
||||
}
|
||||
|
||||
void putInfoVal(unsigned char pos, char *name, unsigned long val)
|
||||
{
|
||||
draw_block(0, pos, 128, 8, 3, DRAW_ERASE);
|
||||
|
||||
draw_string(0,pos,name,3,DRAW_PUT);
|
||||
putHN(pos, val);
|
||||
}
|
||||
|
||||
void ACK(void)
|
||||
{
|
||||
serial_puts(ACKTOKEN);
|
||||
}
|
||||
|
||||
void BACK(void)
|
||||
{
|
||||
serial_puts(BACKTOKEN);
|
||||
}
|
||||
|
||||
void NACK(void)
|
||||
{
|
||||
serial_puts(NACKTOKEN);
|
||||
}
|
||||
|
||||
int receiveBuf(void)
|
||||
{
|
||||
unsigned long ccheck;
|
||||
unsigned short cnt, cnt2, cnt3;
|
||||
|
||||
cnt = count<<2;
|
||||
|
||||
if(cnt > 512)
|
||||
return 0;
|
||||
|
||||
checksum = 0;
|
||||
ccheck = 0;
|
||||
cnt2 = 0;
|
||||
|
||||
#define XFERSIZE 16
|
||||
|
||||
while(cnt >= XFERSIZE)
|
||||
{
|
||||
cnt3=XFERSIZE;
|
||||
while(cnt3--)
|
||||
{
|
||||
buf.bbuf[cnt2] = serial_getc();
|
||||
checksum += buf.bbuf[cnt2++];
|
||||
}
|
||||
BACK();
|
||||
cnt -= XFERSIZE;
|
||||
}
|
||||
|
||||
if(cnt)
|
||||
{
|
||||
while(cnt--)
|
||||
{
|
||||
buf.bbuf[cnt2] = serial_getc();
|
||||
checksum += buf.bbuf[cnt2++];
|
||||
}
|
||||
BACK();
|
||||
}
|
||||
|
||||
ccheck = serial_getc() << 24;
|
||||
ccheck += serial_getc() << 16;
|
||||
ccheck += serial_getc() << 8;
|
||||
ccheck += serial_getc();
|
||||
|
||||
if(ccheck == checksum)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
drawStatus("Wrong Checksum");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
unsigned char i;
|
||||
|
||||
count = 0;
|
||||
adr = 0x00000000;
|
||||
timer = TIMEOUT+1;
|
||||
numBytes = 0;
|
||||
|
||||
lcd_init(0);
|
||||
|
||||
IODIR0|=0x10;
|
||||
IOCLR0=0x10;
|
||||
|
||||
serial_init();
|
||||
|
||||
set_font(1);
|
||||
#ifdef RESIDENT
|
||||
draw_string(0, 0,">> FlashTool V0.2-r",3,DRAW_PUT);
|
||||
#else
|
||||
draw_string(0, 0,">> FlashTool V0.2",3,DRAW_PUT);
|
||||
#endif
|
||||
set_font(0);
|
||||
draw_string(0,14,"This tool is licensed under",3,DRAW_PUT);
|
||||
draw_string(0,22,"the GNU GPL 3 or later",3,DRAW_PUT);
|
||||
draw_string(0,34,"(c) 2007 Ch. Klippel",3,DRAW_PUT);
|
||||
draw_string(0,42,"<ck@mamalala.net>",3,DRAW_PUT);
|
||||
|
||||
drawStatus("FlashTool ready!");
|
||||
|
||||
adr = 0x00000000;
|
||||
while (1)
|
||||
{
|
||||
i = serial_getc();
|
||||
if(i==HELO_CMD)
|
||||
{
|
||||
serial_puts(HELOTOKEN);
|
||||
drawStatus("Sent HELO");
|
||||
}
|
||||
else if(i==BULKENABLE_CMD)
|
||||
{
|
||||
putInfoVal(80, "Bulk:", 1);
|
||||
if((adr & 0xFF000000) == 0x80000000 || (adr & 0xFF000000) == 0x82000000)
|
||||
{
|
||||
prepareBulk(adr);
|
||||
drawStatus("Enabled bulk write");
|
||||
draw_string(100,80,ACKTOKEN,3,DRAW_PUT);
|
||||
ACK();
|
||||
}
|
||||
else
|
||||
{
|
||||
draw_string(100,80,NACKTOKEN,3,DRAW_PUT);
|
||||
NACK();
|
||||
}
|
||||
}
|
||||
else if(i==SKIP_CMD)
|
||||
{
|
||||
adr += (serial_getc() << 16);
|
||||
adr += serial_getc();
|
||||
ACK();
|
||||
}
|
||||
else if(i==BULKDISABLE_CMD)
|
||||
{
|
||||
putInfoVal(80, "Bulk:", 0);
|
||||
if((adr & 0xFF000000) == 0x80000000 || (adr & 0xFF000000) == 0x82000000)
|
||||
{
|
||||
endBulk(adr);
|
||||
drawStatus("Disabled bulk write");
|
||||
draw_string(100,80,ACKTOKEN,3,DRAW_PUT);
|
||||
ACK();
|
||||
}
|
||||
else
|
||||
{
|
||||
draw_string(100,80,NACKTOKEN,3,DRAW_PUT);
|
||||
NACK();
|
||||
}
|
||||
}
|
||||
else if(i==SETADR_CMD)
|
||||
{
|
||||
adr = serial_getc() << 24;
|
||||
adr += serial_getc() << 16;
|
||||
adr += serial_getc() << 8;
|
||||
adr += serial_getc();
|
||||
|
||||
putInfoVal(72, "Addr:", adr);
|
||||
|
||||
if((adr & 0xFF000000) == 0x40000000 || (adr & 0xFF000000) == 0x80000000 || (adr & 0xFF000000) == 0x82000000)
|
||||
{
|
||||
drawStatus("Address changed");
|
||||
draw_string(100,72,ACKTOKEN,3,DRAW_PUT);
|
||||
ACK();
|
||||
}
|
||||
else
|
||||
{
|
||||
draw_string(100,72,NACKTOKEN,3,DRAW_PUT);
|
||||
adr = 0x00000000;
|
||||
NACK();
|
||||
}
|
||||
}
|
||||
else if(i==FILLBUF_CMD)
|
||||
{
|
||||
count = serial_getc();
|
||||
putInfoVal(88, "Buf:", count<<2);
|
||||
if(count > 0 && count <= 128)
|
||||
{
|
||||
if(receiveBuf())
|
||||
{
|
||||
ACK();
|
||||
}
|
||||
else
|
||||
{
|
||||
goto fail_f;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fail_f:
|
||||
draw_string(100,88,NACKTOKEN,3,DRAW_PUT);
|
||||
count = 0;
|
||||
NACK();
|
||||
}
|
||||
}
|
||||
else if(i==WRITE_CMD)
|
||||
{
|
||||
putInfoVal(96, "Write:", adr);
|
||||
i = serial_getc();
|
||||
if(i==WRITEGO_CMD && count > 0)
|
||||
{
|
||||
if(writeBulk((unsigned long) &buf.bbuf, adr, count<<1) == 0)
|
||||
{
|
||||
adr += (count<<2);
|
||||
ACK();
|
||||
}
|
||||
else
|
||||
{
|
||||
draw_string(100,96,NACKTOKEN,3,DRAW_PUT);
|
||||
NACK();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(i==SECTERASE_CMD)
|
||||
{
|
||||
|
||||
drawStatus("Erasing Flash Sector");
|
||||
if(eraseSectorAt(adr) == 0)
|
||||
{
|
||||
drawStatus("Erased Flash Sector");
|
||||
ACK();
|
||||
}
|
||||
else
|
||||
{
|
||||
drawStatus("Erase Sector FAILED!!");
|
||||
NACK();
|
||||
}
|
||||
}
|
||||
else if(i==FULLERASE_CMD)
|
||||
{
|
||||
unsigned char w;
|
||||
w = 0xFF;
|
||||
if((adr & 0xFF000000) == 0x82000000)
|
||||
{
|
||||
drawStatus("Erasing Flash #1");
|
||||
w = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
drawStatus("Erasing Flash #0");
|
||||
w = 0;
|
||||
}
|
||||
if(eraseFlash(w) == 0)
|
||||
{
|
||||
if(w==1)
|
||||
{
|
||||
drawStatus("Erased Flash #1");
|
||||
}
|
||||
else if(w==0)
|
||||
{
|
||||
drawStatus("Erased Flash #0");
|
||||
}
|
||||
ACK();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(w)
|
||||
{
|
||||
drawStatus("Flash #1 Erase FAILED!!");
|
||||
}
|
||||
else
|
||||
{
|
||||
drawStatus("Flash #0 Erase FAILED!!");
|
||||
}
|
||||
NACK();
|
||||
}
|
||||
}
|
||||
else if(i==SETNUMBYTES_CMD)
|
||||
{
|
||||
numBytes = serial_getc() << 24;
|
||||
numBytes += serial_getc() << 16;
|
||||
numBytes += serial_getc() << 8;
|
||||
numBytes += serial_getc();
|
||||
putInfoVal(104, "NumB:", numBytes);
|
||||
if(numBytes <= 0x00100000)
|
||||
{
|
||||
draw_string(100,104,ACKTOKEN,3,DRAW_PUT);
|
||||
ACK();
|
||||
}
|
||||
else
|
||||
{
|
||||
draw_string(100,104,NACKTOKEN,3,DRAW_PUT);
|
||||
NACK();
|
||||
}
|
||||
}
|
||||
else if(i==READ_CMD)
|
||||
{
|
||||
for(adr = 0x40000200; adr < 0x40000210; adr+=4)
|
||||
{
|
||||
putHexW((unsigned long)(*(volatile unsigned long *)(adr)));
|
||||
serial_putc('\n');
|
||||
}
|
||||
for(adr = 0x80000000; adr < 0x80000010; adr+=4)
|
||||
{
|
||||
putHexW((unsigned long)(*(volatile unsigned long *)(adr)));
|
||||
serial_putc('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Stubs for various interrupts (may be replaced later) */
|
||||
/* ---------------------------------------------------- */
|
||||
|
||||
void IRQ_Routine (void) {
|
||||
while (1) ;
|
||||
}
|
||||
|
||||
void FIQ_Routine (void) {
|
||||
while (1) ;
|
||||
}
|
||||
|
||||
|
||||
void SWI_Routine (void) {
|
||||
while (1) ;
|
||||
}
|
||||
|
||||
|
||||
void UNDEF_Routine (void) {
|
||||
while (1) ;
|
||||
}
|
246
lpctool/trunk/serial.c
Normal file
246
lpctool/trunk/serial.c
Normal file
|
@ -0,0 +1,246 @@
|
|||
/*
|
||||
* minor changes (c) 2007 ch.klippel
|
||||
*
|
||||
* (C) Copyright 2004
|
||||
* DAVE Srl
|
||||
* http://www.dave-tech.it
|
||||
* http://www.wawnet.biz
|
||||
* mailto:info@wawnet.biz
|
||||
*
|
||||
* (C) Copyright 2002-2004
|
||||
* Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
|
||||
*
|
||||
* (C) Copyright 2002
|
||||
* Sysgo Real-Time Solutions, GmbH <www.elinos.com>
|
||||
* Marius Groeger <mgroeger@sysgo.de>
|
||||
*
|
||||
* (C) Copyright 2002
|
||||
* Sysgo Real-Time Solutions, GmbH <www.elinos.com>
|
||||
* Alex Zuepke <azu@sysgo.de>
|
||||
*
|
||||
* Copyright (C) 1999 2000 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "lpc2220.h"
|
||||
#include "serial.h"
|
||||
#include "lcd.h"
|
||||
|
||||
unsigned long timer;
|
||||
|
||||
|
||||
/* flush serial input queue. returns 0 on success or negative error
|
||||
* number otherwise
|
||||
*/
|
||||
int serial_flush_input(void)
|
||||
{
|
||||
volatile unsigned int tmp;
|
||||
|
||||
/* keep on reading as long as the receiver is not empty */
|
||||
while(RX_DATA(U0LSR)) {
|
||||
tmp = GET_CHAR(U0RBR);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* flush output queue. returns 0 on success or negative error number
|
||||
* otherwise
|
||||
*/
|
||||
int serial_flush_output(void)
|
||||
{
|
||||
/* wait until the transmitter is no longer busy */
|
||||
while(TX_READY(U0LSR)==0) {
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void serial_setbrg (unsigned int baudrate)
|
||||
{
|
||||
|
||||
/* get correct divisor */
|
||||
U0LCR = 0x83;
|
||||
|
||||
switch(baudrate) {
|
||||
|
||||
case 75:
|
||||
U0DLL = 161;
|
||||
U0DLM = 1;
|
||||
U0FDR = (1 << 4) + 14;
|
||||
break;
|
||||
|
||||
case 150:
|
||||
U0DLL = 195;
|
||||
U0DLM = 0;
|
||||
U0FDR = (1 << 4) + 15;
|
||||
break;
|
||||
|
||||
case 300:
|
||||
U0DLL = 184;
|
||||
U0DLM = 0;
|
||||
U0FDR = (2 << 4) + 15;
|
||||
break;
|
||||
|
||||
case 600:
|
||||
U0DLL = 156;
|
||||
U0DLM = 0;
|
||||
U0FDR = (1 << 4) + 4;
|
||||
break;
|
||||
|
||||
case 1200:
|
||||
U0DLL = 130;
|
||||
U0DLM = 0;
|
||||
U0FDR = (7 << 4) + 14;
|
||||
break;
|
||||
|
||||
case 2400:
|
||||
U0DLL = 180;
|
||||
U0DLM = 0;
|
||||
U0FDR = (12 << 4) + 1;
|
||||
break;
|
||||
|
||||
case 4800:
|
||||
U0DLL = 90;
|
||||
U0DLM = 0;
|
||||
U0FDR = (1 << 4) + 4;
|
||||
break;
|
||||
|
||||
case 9600:
|
||||
U0DLL = 23;
|
||||
U0DLM = 0;
|
||||
U0FDR = (8 << 4) + 9;
|
||||
break;
|
||||
|
||||
case 19200:
|
||||
U0DLL = 11;
|
||||
U0DLM = 0;
|
||||
U0FDR = (9 << 4) + 11;
|
||||
break;
|
||||
|
||||
case 38400:
|
||||
U0DLL = 5;
|
||||
U0DLM = 0;
|
||||
U0FDR = (9 << 4) + 13;
|
||||
break;
|
||||
|
||||
case 57600:
|
||||
U0DLL = 6;
|
||||
U0DLM = 0;
|
||||
U0FDR = (14 << 4) + 5;
|
||||
break;
|
||||
|
||||
case 115200:
|
||||
U0DLL = 3;
|
||||
U0DLM = 0;
|
||||
U0FDR = (14 << 4) + 5;
|
||||
break;
|
||||
}
|
||||
U0LCR = 0x03;
|
||||
|
||||
serial_flush_output();
|
||||
serial_flush_input();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Initialise the serial port with the given baudrate. The settings
|
||||
* are always 8 data bits, no parity, 1 stop bit, no start bits.
|
||||
*
|
||||
*/
|
||||
int serial_init (void)
|
||||
{
|
||||
PINSEL0=0x05; // pin select -> tx, rx
|
||||
serial_setbrg (115200);
|
||||
U0FCR = 0x07; // enable fifo
|
||||
timer = TIMEOUT+1;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Output a single byte to the serial port.
|
||||
*/
|
||||
void serial_putc (const char c)
|
||||
{
|
||||
/* wait for room in the transmit FIFO */
|
||||
while(TX_READY(U0LSR)==0);
|
||||
|
||||
PUT_CHAR(U0THR,c);
|
||||
}
|
||||
|
||||
/*
|
||||
* Read a single byte from the serial port. Returns 1 on success, 0
|
||||
* otherwise. When the function is succesfull, the character read is
|
||||
* written into its argument c.
|
||||
*/
|
||||
int serial_tstc (void)
|
||||
{
|
||||
return (RX_DATA(U0LSR));
|
||||
}
|
||||
|
||||
/*
|
||||
* Read a single byte from the serial port. Returns 1 on success, 0
|
||||
* otherwise. When the function is succesfull, the character read is
|
||||
* written into its argument c.
|
||||
*/
|
||||
|
||||
int serial_getc (void)
|
||||
{
|
||||
while(((U0LSR) & USRRxData) <= 0)
|
||||
{
|
||||
if(timer == TIMEOUT)
|
||||
{
|
||||
clearStatus();
|
||||
timer++;
|
||||
}
|
||||
else if(timer < TIMEOUT)
|
||||
{
|
||||
timer++;
|
||||
}
|
||||
}
|
||||
return (U0RBR);
|
||||
}
|
||||
|
||||
void serial_puts (const char *s)
|
||||
{
|
||||
while (*s != 0) {
|
||||
serial_putc (*s++);
|
||||
}
|
||||
}
|
||||
|
||||
const char hval[16] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' };
|
||||
|
||||
void putHexC(const unsigned char v)
|
||||
{
|
||||
serial_putc(hval[v>>4]);
|
||||
serial_putc(hval[v & 0x0F]);
|
||||
}
|
||||
|
||||
void putHexS(const unsigned short v)
|
||||
{
|
||||
putHexC(v >> 8);
|
||||
putHexC(v & 0xFF);
|
||||
}
|
||||
|
||||
void putHexW(const unsigned long v)
|
||||
{
|
||||
putHexS(v >> 16);
|
||||
putHexS(v & 0xFFFF);
|
||||
}
|
24
lpctool/trunk/serial.h
Normal file
24
lpctool/trunk/serial.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
#ifndef BOOP_SERIAL_H
|
||||
#define BOOP_SERIAL_H
|
||||
|
||||
#define USRRxData (1 << 0)
|
||||
#define USRTxHoldEmpty (1 << 6)
|
||||
#define GET_CHAR(p) p
|
||||
#define PUT_CHAR(p,c) (p= (unsigned )(c))
|
||||
#define TX_READY(s) ((s) & USRTxHoldEmpty)
|
||||
#define RX_DATA(s) ((s) & USRRxData)
|
||||
|
||||
int serial_flush_input(void);
|
||||
int serial_flush_output(void);
|
||||
void serial_setbrg (unsigned int baudrate);
|
||||
int serial_init (void);
|
||||
void serial_putc (const char c);
|
||||
int serial_tstc (void);
|
||||
int serial_getc (void);
|
||||
void serial_puts (const char *s);
|
||||
|
||||
void putHexC(const unsigned char v);
|
||||
void putHexS(const unsigned short v);
|
||||
void putHexW(const unsigned long v);
|
||||
|
||||
#endif /* BOOP_SERIAL_H */
|
31
lpctool/trunk/toolcmd.h
Normal file
31
lpctool/trunk/toolcmd.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
#ifndef TOOLCMD_H
|
||||
#define TOOLCMD_H
|
||||
|
||||
#define HELO_CMD '.'
|
||||
#define BULKENABLE_CMD 'B'
|
||||
#define BULKDISABLE_CMD 'X'
|
||||
#define SETADR_CMD 'A'
|
||||
#define FILLBUF_CMD 'F'
|
||||
#define WRITE_CMD 'W'
|
||||
#define WRITEGO_CMD '!'
|
||||
#define SECTERASE_CMD 'P'
|
||||
#define FULLERASE_CMD 'E'
|
||||
#define SETNUMBYTES_CMD 'S'
|
||||
#define READ_CMD 'R'
|
||||
#define SKIP_CMD '>'
|
||||
#define HELOTOKEN "HELO"
|
||||
#define ACKTOKEN "ACK!"
|
||||
#define NACKTOKEN "NACK"
|
||||
#define BACKTOKEN "!"
|
||||
|
||||
#define MIN_GAP 0x10
|
||||
|
||||
typedef struct t_chunk
|
||||
{
|
||||
unsigned long start;
|
||||
unsigned long len;
|
||||
struct t_chunk *prev;
|
||||
struct t_chunk *next;
|
||||
} t_chunk;
|
||||
|
||||
#endif
|
528
lpctool/trunk/toolcom.c
Normal file
528
lpctool/trunk/toolcom.c
Normal file
|
@ -0,0 +1,528 @@
|
|||
#include "infohelper.h"
|
||||
#include "lpctool_serial.h"
|
||||
#include "toolcom.h"
|
||||
#include "toolcmd.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <termios.h>
|
||||
|
||||
const unsigned long secinfo[20] =
|
||||
{ 0x00000,
|
||||
0x04000,
|
||||
0x06000,
|
||||
0x08000,
|
||||
0x10000,
|
||||
0x20000,
|
||||
0x30000,
|
||||
0x40000,
|
||||
0x50000,
|
||||
0x60000,
|
||||
0x70000,
|
||||
0x80000,
|
||||
0x90000,
|
||||
0xA0000,
|
||||
0xB0000,
|
||||
0xC0000,
|
||||
0xD0000,
|
||||
0xE0000,
|
||||
0xF0000,
|
||||
0x100000 };
|
||||
|
||||
|
||||
struct t_chunk *chunklist = NULL;
|
||||
|
||||
union {
|
||||
unsigned char cbuf[MAXBUF];
|
||||
unsigned short sbuf[MAXBUF/2];
|
||||
unsigned long lbuf[MAXBUF/4];
|
||||
} buffs;
|
||||
|
||||
int makeList(unsigned long *buf, unsigned long len)
|
||||
{
|
||||
unsigned long mlen;
|
||||
t_chunk *mlist;
|
||||
int cnt;
|
||||
unsigned long gap, pos;
|
||||
if(chunklist)
|
||||
freeList();
|
||||
|
||||
mlen = len>>2;
|
||||
gap = 0;
|
||||
pos = 0;
|
||||
cnt = 1;
|
||||
|
||||
if(mlen)
|
||||
{
|
||||
printInfoS(2,"creating list of chunks",0);
|
||||
|
||||
chunklist = malloc(sizeof(t_chunk));
|
||||
|
||||
mlist = chunklist;
|
||||
|
||||
if(mlist)
|
||||
{
|
||||
mlist->start = 0x80000000;
|
||||
mlist->len = 0;
|
||||
mlist->prev = NULL;
|
||||
mlist->next = NULL;
|
||||
}
|
||||
|
||||
while(mlen)
|
||||
{
|
||||
gap = 0;
|
||||
if(buf[pos] != 0xFFFFFFFF)
|
||||
{
|
||||
mlist->len += 4;
|
||||
mlen --;
|
||||
pos ++;
|
||||
}
|
||||
else while(buf[pos] == 0xFFFFFFFF)
|
||||
{
|
||||
gap += 4;
|
||||
pos ++;
|
||||
mlen --;
|
||||
}
|
||||
if(gap)
|
||||
{
|
||||
if(gap >= MIN_GAP)
|
||||
{
|
||||
mlist->next = malloc(sizeof(t_chunk));
|
||||
if(mlist->next)
|
||||
{
|
||||
cnt++;
|
||||
mlist->next->start = chunklist->start + (pos*4);
|
||||
mlist->next->prev = mlist;
|
||||
mlist->next->next = NULL;
|
||||
mlist->next->len = 0;
|
||||
mlist = mlist->next;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
mlist->len += gap;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
printInfoH(2, "chunk entries created:",cnt);
|
||||
return(cnt);
|
||||
}
|
||||
|
||||
void freeList(void)
|
||||
{
|
||||
t_chunk *mlist;
|
||||
int cnt;
|
||||
|
||||
if(chunklist)
|
||||
{
|
||||
mlist = chunklist;
|
||||
cnt = 0;
|
||||
|
||||
while(mlist->next != NULL)
|
||||
{
|
||||
mlist = mlist->next;
|
||||
cnt++;
|
||||
free(mlist->prev);
|
||||
}
|
||||
cnt++;
|
||||
free(mlist);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int getRESULT(unsigned char acktype)
|
||||
{
|
||||
char buf[4];
|
||||
unsigned char q;
|
||||
|
||||
switch(acktype)
|
||||
{
|
||||
case ACK:
|
||||
q = getBuf(4, buf);
|
||||
if(strncmp(buf, ACKTOKEN, 4))
|
||||
{
|
||||
return printError("wrong response, expected ACK!");
|
||||
}
|
||||
return 1;
|
||||
break;
|
||||
|
||||
case HELO:
|
||||
q = getBuf(4, buf);
|
||||
if(strncmp(buf, HELOTOKEN, 4))
|
||||
{
|
||||
return printError("wrong response, expected HELO");
|
||||
}
|
||||
return 1;
|
||||
break;
|
||||
case BACK:
|
||||
q = getBuf(1, buf);
|
||||
if(strncmp(buf, BACKTOKEN, 1))
|
||||
{
|
||||
return printError("wrong response, expected !");
|
||||
}
|
||||
return 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int openRamTool()
|
||||
{
|
||||
char buf[1];
|
||||
unsigned char q;
|
||||
|
||||
buf[0] = HELO_CMD;
|
||||
|
||||
sendBuf(1, buf);
|
||||
|
||||
reconfSerial(TOOLBAUD, 0, 50);
|
||||
q = getRESULT(HELO);
|
||||
reconfSerial(TOOLBAUD, 0, 5);
|
||||
|
||||
return q;
|
||||
}
|
||||
|
||||
int setToolAdr(unsigned long adr)
|
||||
{
|
||||
char buf[5];
|
||||
|
||||
buf[0] = SETADR_CMD;
|
||||
buf[1] =(adr & 0xFF000000) >> 24;
|
||||
buf[2] =(adr & 0x00FF0000) >> 16;
|
||||
buf[3] =(adr & 0x0000FF00) >> 8;
|
||||
buf[4] = adr & 0x000000FF;
|
||||
|
||||
sendBuf(5, buf);
|
||||
|
||||
return getRESULT(ACK);
|
||||
}
|
||||
|
||||
int eraseFlash(void)
|
||||
{
|
||||
char buf[1];
|
||||
|
||||
printInfoS(0,"erasing flash", 0);
|
||||
|
||||
buf[0] = FULLERASE_CMD;
|
||||
|
||||
sendBuf(1, buf);
|
||||
|
||||
return getRESULT(ACK);
|
||||
}
|
||||
|
||||
int eraseFlashSector(void)
|
||||
{
|
||||
char buf[1];
|
||||
|
||||
buf[0] = SECTERASE_CMD;
|
||||
|
||||
sendBuf(1, buf);
|
||||
|
||||
return getRESULT(ACK);
|
||||
}
|
||||
|
||||
int enableBulk(unsigned char b)
|
||||
{
|
||||
char buf[1];
|
||||
|
||||
if(b)
|
||||
{
|
||||
buf[0] = BULKENABLE_CMD;
|
||||
}
|
||||
else
|
||||
{
|
||||
buf[0] = BULKDISABLE_CMD;
|
||||
}
|
||||
|
||||
sendBuf(1, buf);
|
||||
|
||||
return getRESULT(ACK);
|
||||
}
|
||||
|
||||
int setNumBytes(unsigned long numBytes)
|
||||
{
|
||||
char buf[5];
|
||||
|
||||
buf[0] = SETNUMBYTES_CMD;
|
||||
buf[1] =(numBytes & 0xFF000000) >> 24;
|
||||
buf[2] =(numBytes & 0x00FF0000) >> 16;
|
||||
buf[3] =(numBytes & 0x0000FF00) >> 8;
|
||||
buf[4] = numBytes & 0x000000FF;
|
||||
|
||||
sendBuf(5, buf);
|
||||
|
||||
return getRESULT(ACK);
|
||||
}
|
||||
|
||||
int writeFlash(void)
|
||||
{
|
||||
char buf[2];
|
||||
|
||||
buf[0] = WRITE_CMD;
|
||||
buf[1] = WRITEGO_CMD;
|
||||
|
||||
sendBuf(2, buf);
|
||||
|
||||
return getRESULT(ACK);
|
||||
}
|
||||
|
||||
int uploadBuf(unsigned char nwords, unsigned char* buf)
|
||||
{
|
||||
unsigned short cnt,cnt2, cnt3;
|
||||
unsigned long checksum;
|
||||
char tbuf[6];
|
||||
checksum = 0;
|
||||
tbuf[0] = FILLBUF_CMD;
|
||||
tbuf[1] = nwords;
|
||||
|
||||
if(!sendBuf(2,tbuf))
|
||||
return 0;
|
||||
|
||||
cnt = nwords << 2;
|
||||
cnt2 = 0;
|
||||
|
||||
#define XFERSIZE 16
|
||||
|
||||
while(cnt >= XFERSIZE)
|
||||
{
|
||||
|
||||
cnt3=XFERSIZE;
|
||||
while(cnt3--)
|
||||
checksum += buf[cnt2++];
|
||||
|
||||
if(!sendBuf(XFERSIZE, (char*)buf+cnt2-XFERSIZE))
|
||||
return 0;
|
||||
|
||||
if(!getRESULT(BACK))
|
||||
return 0;
|
||||
|
||||
cnt -= XFERSIZE;
|
||||
}
|
||||
|
||||
if(cnt)
|
||||
{
|
||||
cnt3 = cnt;
|
||||
while(cnt--)
|
||||
checksum += buf[cnt2++];
|
||||
|
||||
if(!sendBuf(cnt3, (char*)buf+cnt2-cnt3))
|
||||
return 0;
|
||||
|
||||
if(!getRESULT(BACK))
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
tbuf[0] = (checksum >> 24) & 0xFF;
|
||||
tbuf[1] = (checksum >> 16) & 0xFF;
|
||||
tbuf[2] = (checksum >> 8) & 0xFF;
|
||||
tbuf[3] = checksum & 0xFF;
|
||||
if(!sendBuf(4, tbuf))
|
||||
return 0;
|
||||
|
||||
return getRESULT(ACK);
|
||||
}
|
||||
|
||||
int uploadChunks(int fd, unsigned long loc, unsigned int erase)
|
||||
{
|
||||
unsigned long fsize, cnt, total, csize;
|
||||
unsigned char buf[MAXBUF];
|
||||
unsigned int numChunks;
|
||||
t_chunk *curr_chunk;
|
||||
|
||||
if(!setToolAdr(loc))
|
||||
{
|
||||
freeList();
|
||||
return printError("failed to set address");
|
||||
}
|
||||
|
||||
if(erase & 0x40)
|
||||
{
|
||||
printInfoS(2,"erasing flash sector", 0);
|
||||
if(!eraseFlashSector())
|
||||
return printError("failed to erase start sector");
|
||||
printInfoS(2,"flash sector erased", 0);
|
||||
}
|
||||
else if((erase & 0x20) || (erase & 0x10))
|
||||
{
|
||||
printInfoS(2,"erasing whole flash", 0);
|
||||
reconfSerial(TOOLBAUD, 0, 200);
|
||||
|
||||
if(!eraseFlash())
|
||||
return printError("failed to erase whole flash");
|
||||
reconfSerial(TOOLBAUD, 0, 5);
|
||||
|
||||
printInfoS(2,"whole flash erased", 0);
|
||||
}
|
||||
|
||||
printInfoS(2,"enabling bulk write",0);
|
||||
if(!enableBulk(1))
|
||||
return printError("bulk write enable failed");
|
||||
|
||||
fsize = read(fd, buf, MAXBUF);
|
||||
total = fsize;
|
||||
cnt = 0;
|
||||
|
||||
printInfoH(2,"setting total number of bytes to", fsize);
|
||||
if(!setNumBytes(fsize))
|
||||
return printError("cannot set total number of bytes");
|
||||
|
||||
printInfoS(0,"starting flash upload (chunk mode)", 0);
|
||||
|
||||
numChunks = makeList((unsigned long*)buf, fsize);
|
||||
curr_chunk = chunklist;
|
||||
|
||||
printProgress(0,"Flash",cnt,total);
|
||||
|
||||
while(numChunks--)
|
||||
{
|
||||
if(!setToolAdr(curr_chunk->start))
|
||||
{
|
||||
freeList();
|
||||
return printError("failed to set address");
|
||||
}
|
||||
|
||||
csize = curr_chunk->len;
|
||||
cnt = curr_chunk->start & 0x00FFFFFF;
|
||||
|
||||
while(csize >= 512)
|
||||
{
|
||||
if(!uploadBuf(128, buf+cnt))
|
||||
{
|
||||
freeList();
|
||||
return printError("buffer upload failed");;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!writeFlash())
|
||||
{
|
||||
freeList();
|
||||
return printError("flash write failed");;
|
||||
}
|
||||
}
|
||||
csize -= 512;
|
||||
cnt += 512;
|
||||
printProgress(0,"Flash",cnt,total);
|
||||
}
|
||||
if(csize)
|
||||
{
|
||||
if(!uploadBuf(csize>>2, buf+cnt))
|
||||
{
|
||||
freeList();
|
||||
return printError("buffer upload failed");;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!writeFlash())
|
||||
{
|
||||
freeList();
|
||||
return printError("flash write failed");;
|
||||
}
|
||||
}
|
||||
csize = 0;
|
||||
printProgress(0,"Flash",cnt,total);
|
||||
}
|
||||
|
||||
curr_chunk = curr_chunk->next;
|
||||
}
|
||||
|
||||
printProgress(0,"Flash",total,total);
|
||||
|
||||
freeList();
|
||||
|
||||
if(!enableBulk(0))
|
||||
return printError("bulk write disable failed");;
|
||||
|
||||
printInfoH(0,"flash upload (chunk mode) complete, total bytes:", total);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int uploadFlash(int fd, unsigned long loc, unsigned int erase)
|
||||
{
|
||||
unsigned long fsize, cnt, total;
|
||||
unsigned char buf[MAXBUF];
|
||||
|
||||
printInfoH(2,"setting address to", loc);
|
||||
if(!setToolAdr(loc))
|
||||
return printError("failed to set address");
|
||||
|
||||
if(erase & 0x40)
|
||||
{
|
||||
printInfoS(2,"erasing flash sector", 0);
|
||||
if(!eraseFlashSector())
|
||||
return printError("failed to erase start sector");
|
||||
printInfoS(2,"flash sector erased", 0);
|
||||
}
|
||||
else if((erase & 0x20) || (erase & 0x10))
|
||||
{
|
||||
printInfoS(2,"erasing whole flash", 0);
|
||||
reconfSerial(TOOLBAUD, 0, 200);
|
||||
|
||||
if(!eraseFlash())
|
||||
return printError("failed to erase whole flash");
|
||||
reconfSerial(TOOLBAUD, 0, 5);
|
||||
|
||||
printInfoS(2,"whole flash erased", 0);
|
||||
}
|
||||
|
||||
printInfoS(2,"enabling bulk write",0);
|
||||
if(!enableBulk(1))
|
||||
return printError("bulk write enable failed");
|
||||
|
||||
fsize = read(fd, buf, MAXBUF);
|
||||
|
||||
printInfoH(2,"setting total number of bytes to", fsize);
|
||||
if(!setNumBytes(fsize))
|
||||
return printError("cannot set total number of bytes");
|
||||
|
||||
cnt = 0;
|
||||
total = fsize;
|
||||
|
||||
printInfoS(0,"starting flash upload", 0);
|
||||
printProgress(0,"Flash",cnt,total);
|
||||
|
||||
while(fsize >= 512)
|
||||
{
|
||||
if(!uploadBuf(128, buf+cnt))
|
||||
{
|
||||
return printError("buffer upload failed");;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!writeFlash())
|
||||
return printError("flash write failed");;
|
||||
}
|
||||
fsize -= 512;
|
||||
cnt += 512;
|
||||
printProgress(0,"Flash",cnt,total);
|
||||
}
|
||||
if(fsize)
|
||||
{
|
||||
if(!uploadBuf(fsize>>2, buf+cnt))
|
||||
{
|
||||
return printError("buffer upload failed");;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!writeFlash())
|
||||
return printError("flash write failed");;
|
||||
}
|
||||
fsize = 0;
|
||||
printProgress(0,"Flash",total,total);
|
||||
}
|
||||
|
||||
if(!enableBulk(0))
|
||||
return printError("bulk write disable failed");;
|
||||
|
||||
printInfoH(0,"flash upload complete, total bytes:", total);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
21
lpctool/trunk/toolcom.h
Normal file
21
lpctool/trunk/toolcom.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
#ifndef TOOLCOM_H
|
||||
#define TOOLCOM_H
|
||||
|
||||
#define ACK 0x00
|
||||
#define HELO 0x01
|
||||
#define BACK 0x02
|
||||
|
||||
#define MAXBUF 0x00100000
|
||||
|
||||
int makeList(unsigned long *buf, unsigned long len);
|
||||
void freeList(void);
|
||||
int openRamTool();
|
||||
int setToolAdr(unsigned long adr);
|
||||
int eraseFlash(void);
|
||||
int writeFlash(void);
|
||||
int enableBulk(unsigned char b);
|
||||
int setNumBytes(unsigned long numBytes);
|
||||
int uploadFlash(int fd, unsigned long loc, unsigned int erase);
|
||||
int uploadChunks(int fd, unsigned long loc, unsigned int erase);
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue