Initial transfer from sourceforge
This commit is contained in:
commit
f2259c5424
415 changed files with 73200 additions and 0 deletions
35
Asixtool/asix-testcode/Makefile
Normal file
35
Asixtool/asix-testcode/Makefile
Normal file
|
@ -0,0 +1,35 @@
|
|||
SDCCPATH=/opt/sdcc/
|
||||
SDCCBIN=$(SDCCPATH)/bin/
|
||||
SDCCEXTRA=$(SDCCPATH)/share/sdcc/
|
||||
|
||||
SDCC=$(SDCCBIN)/sdcc
|
||||
SDCCINC=$(SDCCEXTRA)/include/mcs51/
|
||||
SDCCLIB=$(SDCCEXTRA)/lib/large/
|
||||
SDCCMFLAGS=-mds390 --use-asix --opt-code-size --stack-size 0x80
|
||||
SDCCLFLAGS=--xram-loc 0x0000 --xram-size 0x8000 --iram-size 0x80 --code-loc 0x000000 --code-size 0x080000 --stack-loc 0x80 --idata-loc 0x30
|
||||
|
||||
OBJECTS=cpu_ax110xx.rel interrupt_ax110xx.rel main.rel uart/uart.rel
|
||||
|
||||
all : asix.bin
|
||||
|
||||
asix.bin: asix.ihx
|
||||
$(SDCCBIN)/makebin -p <asix.ihx >asix.bin
|
||||
|
||||
asix.ihx: $(OBJECTS)
|
||||
$(SDCC) -I$(SDCCINC) $(SDCCMFLAGS) $(SDCCLFLAGS) $(OBJECTS) -o asix.ihx
|
||||
|
||||
cpu_ax110xx.rel: cpu_ax110xx.c cpu_ax110xx.h ax110xx.h
|
||||
$(SDCC) -I$(SDCCINC) $(SDCCMFLAGS) -c cpu_ax110xx.c
|
||||
|
||||
interrupt_ax110xx.rel: interrupt_ax110xx.c interrupt_ax110xx.h ax110xx.h
|
||||
$(SDCC) -I$(SDCCINC) $(SDCCMFLAGS) -c interrupt_ax110xx.c
|
||||
|
||||
main.rel: main.c ax110xx.h interrupt_ax110xx.h cpu_ax110xx.h
|
||||
$(SDCC) -I$(SDCCINC) $(SDCCMFLAGS) -c main.c
|
||||
|
||||
uart/uart.rel: uart/uart.c ax110xx.h
|
||||
$(SDCC) -I$(SDCCINC) $(SDCCMFLAGS) -c -o uart/ uart/uart.c
|
||||
|
||||
clean:
|
||||
rm -f mon.ihx *.asm *.lst *.rel *.rst *.sym *.cdb *.map *.ihx *.lnk *.hex *.mem *.bin *~
|
||||
cd uart; rm -f *.asm *.lst *.rel *.rst *.sym *.cdb *.map *.ihx *.lnk *.hex *.mem *.bin *~; cd ..
|
35
Asixtool/asix-testcode/Makefile.bak
Normal file
35
Asixtool/asix-testcode/Makefile.bak
Normal file
|
@ -0,0 +1,35 @@
|
|||
SDCCPATH=F:/Tools/SDCC
|
||||
SDCCBIN=$(SDCCPATH)/bin
|
||||
SDCCEXTRA=$(SDCCPATH)/share/sdcc/
|
||||
|
||||
SDCC=$(SDCCBIN)/sdcc
|
||||
SDCCINC=$(SDCCPATH)/include/mcs51
|
||||
SDCCLIB=$(SDCCPATH)/lib/large/
|
||||
SDCCMFLAGS=-mds390 --use-asix --opt-code-size --stack-size 0x80
|
||||
SDCCLFLAGS=--xram-loc 0x0000 --xram-size 0x8000 --iram-size 0x80 --code-loc 0x000000 --code-size 0x080000 --stack-loc 0x80 --idata-loc 0x30
|
||||
|
||||
OBJECTS=cpu_ax110xx.rel interrupt_ax110xx.rel main.rel uart/uart.rel
|
||||
|
||||
all : asix.bin
|
||||
|
||||
asix.bin: asix.ihx
|
||||
$(SDCCBIN)/makebin -p <asix.ihx >asix.bin
|
||||
|
||||
asix.ihx: $(OBJECTS)
|
||||
$(SDCC) -I$(SDCCINC) $(SDCCMFLAGS) $(SDCCLFLAGS) $(OBJECTS) -o asix.ihx
|
||||
|
||||
cpu_ax110xx.rel: cpu_ax110xx.c cpu_ax110xx.h ax110xx.h
|
||||
$(SDCC) -I$(SDCCINC) $(SDCCMFLAGS) -c cpu_ax110xx.c
|
||||
|
||||
interrupt_ax110xx.rel: interrupt_ax110xx.c interrupt_ax110xx.h ax110xx.h
|
||||
$(SDCC) -I$(SDCCINC) $(SDCCMFLAGS) -c interrupt_ax110xx.c
|
||||
|
||||
main.rel: main.c ax110xx.h interrupt_ax110xx.h cpu_ax110xx.h
|
||||
$(SDCC) -I$(SDCCINC) $(SDCCMFLAGS) -c main.c
|
||||
|
||||
uart/uart.rel: uart/uart.c ax110xx.h
|
||||
$(SDCC) -I$(SDCCINC) $(SDCCMFLAGS) -c -o uart/ uart/uart.c
|
||||
|
||||
clean:
|
||||
rm -f mon.ihx *.asm *.lst *.rel *.rst *.sym *.cdb *.map *.ihx *.lnk *.hex *.mem *.bin *~
|
||||
cd uart; rm -f *.asm *.lst *.rel *.rst *.sym *.cdb *.map *.ihx *.lnk *.hex *.mem *.bin *~; cd ..
|
462
Asixtool/asix-testcode/ax110xx.h
Normal file
462
Asixtool/asix-testcode/ax110xx.h
Normal file
|
@ -0,0 +1,462 @@
|
|||
#ifndef AX110XX_H
|
||||
#define AX110XX_H
|
||||
|
||||
/* Byte Registers */
|
||||
__sfr __at (0x80) P0; // Port 0
|
||||
__sfr __at (0x81) SP; // Stack Pointer
|
||||
__sfr __at (0x82) DPL0; // Data Pointer 0 Low Byte
|
||||
__sfr __at (0x83) DPH0; // Data Pointer 0 High Byte
|
||||
__sfr __at (0x82) DPL; // Data Pointer 0 Low Byte
|
||||
__sfr __at (0x83) DPH; // Data Pointer 0 High Byte
|
||||
__sfr __at (0x84) DPL1; // Data Pointer 1 Low Byte
|
||||
__sfr __at (0x85) DPH1; // Data Pointer 1 High Byte
|
||||
__sfr __at (0x86) DPS; // Data Pointers Select Register
|
||||
__sfr __at (0x87) PCON; // Power Configuration Register
|
||||
__sfr __at (0x88) TCON; // Timer 0,1 Configuration Register
|
||||
__sfr __at (0x89) TMOD; // Timer 0,1 Control Mode Register
|
||||
__sfr __at (0x8A) TL0; // Timer 0 Low Byte Counter
|
||||
__sfr __at (0x8B) TL1; // Timer 1 Low Byte Counter
|
||||
__sfr __at (0x8C) TH0; // Timer 0 High Byte Counter
|
||||
__sfr __at (0x8D) TH1; // Timer 1 High Byte Counter
|
||||
__sfr __at (0x8E) CKCON; // Clock Control Register
|
||||
__sfr __at (0x8F) CSREPR; // Software Reset and External Program RAM Select Register
|
||||
|
||||
__sfr __at (0x90) P1; // Port 1
|
||||
__sfr __at (0x91) EIF; // Extended Interrupt Flag Register
|
||||
__sfr __at (0x92) WTST; // Program Wait States Register
|
||||
__sfr __at (0x93) DPX0; // Data Pointer Extended Register 0
|
||||
__sfr __at (0x93) DPX; // Data Pointer Extended Register 0
|
||||
__sfr __at (0x94) SDSTSR; // Software Timer and Software DMA complete interrupt status
|
||||
__sfr __at (0x95) DPX1; // Data Pointer Extended Register 1
|
||||
__sfr __at (0x96) I2CCIR; // I2C Command Index Register
|
||||
__sfr __at (0x97) I2CDR; // I2C Data Register
|
||||
__sfr __at (0x98) SCON0; // UART 0 Configuration Register
|
||||
__sfr __at (0x99) SBUF0; // UART 0 Buffer Register
|
||||
__sfr __at (0x9A) DBAR; // DMA Bus Arbitration Register
|
||||
__sfr __at (0x9B) DCIR; // DMA Command Index Register
|
||||
__sfr __at (0x9C) DDR; // DMA Data Register
|
||||
__sfr __at (0x9D) ACON; // Address Control Register
|
||||
__sfr __at (0x9E) PISSR1; // Peripheral Interrupt Status Summary Register 1
|
||||
__sfr __at (0x9F) PISSR2; // Peripheral Interrupt Status Summary Register 2
|
||||
|
||||
__sfr __at (0xA0) P2; // Port 2
|
||||
/* Local Bus Master Mode */
|
||||
__sfr __at (0xA1) LMSR; // Local Bus Mode Setup Register
|
||||
__sfr __at (0xA2) LCR; // Local Bus Command Register
|
||||
__sfr __at (0xA3) LSR; // Local Bus Status Register
|
||||
__sfr __at (0xA4) LDALR; // Local Bus Device Address Low Register
|
||||
__sfr __at (0xA5) LDAHR; // Local Bus Device Address High Register
|
||||
__sfr __at (0xA6) LDCSR; // Local Bus Device Chip Select Register
|
||||
/* Local Bus Slave Mode */
|
||||
__sfr __at (0xA1) LSAIER; // Local Bus Slave mode Action and Interrupt Enable Register
|
||||
__sfr __at (0xA2) LSCR; // Local Bus Slave mode Command Register
|
||||
__sfr __at (0xA3) LSSR; // Local Bus Slave mode Status Register
|
||||
__sfr __at (0xA4) XMWLR; // External Master Write-read Low Register
|
||||
__sfr __at (0xA5) XMWHR; // External Master Write-read High Register
|
||||
__sfr __at (0xA6) XMRLR; // External Master Read-only Low Register
|
||||
__sfr __at (0xA7) XMRHR; // External Master Read-only High Register
|
||||
__sfr __at (0xA8) IE; // Interrupt Enable register
|
||||
__sfr __at (0xA9) LDLR; // Local Bus Data Low Register
|
||||
__sfr __at (0xAA) LDHR; // Local Bus Data High Register
|
||||
__sfr __at (0xAB) DMALR; // Local Bus DMA Address Low Register
|
||||
__sfr __at (0xAC) DMAMR; // Local Bus DMA Address Medium Register
|
||||
__sfr __at (0xAD) DMAHR; // Local Bus DMA Address High Register
|
||||
__sfr __at (0xAE) TCIR; // TOE Command Index Register
|
||||
__sfr __at (0xAF) TDR; // TOE Data Register
|
||||
|
||||
__sfr __at (0xB0) P3; // Port 3
|
||||
__sfr __at (0xB1) CCAPL0; // PCA Module 0 Compare/Capture Low Byte Register
|
||||
__sfr __at (0xB2) CCAPL1; // PCA Module 1 Compare/Capture Low Byte Register
|
||||
__sfr __at (0xB3) CCAPL2; // PCA Module 2 Compare/Capture Low Byte Register
|
||||
__sfr __at (0xB4) CCAPL3; // PCA Module 3 Compare/Capture Low Byte Register
|
||||
__sfr __at (0xB5) CCAPL4; // PCA Module 4 Compare/Capture Low Byte Register
|
||||
__sfr __at (0xB6) MCIR; // MAC Command Index Register
|
||||
__sfr __at (0xB7) MDR; // MAC Data Register
|
||||
__sfr __at (0xB8) IP; // Interrupt Priority Register
|
||||
__sfr __at (0xB9) CCAPH0; // PCA Module 0 Compare/Capture High Byte Register
|
||||
__sfr __at (0xBA) CCAPH1; // PCA Module 1 Compare/Capture High Byte Register
|
||||
__sfr __at (0xBB) CCAPH2; // PCA Module 2 Compare/Capture High Byte Register
|
||||
__sfr __at (0xBC) CCAPH3; // PCA Module 3 Compare/Capture High Byte Register
|
||||
__sfr __at (0xBD) CCAPH4; // PCA Module 4 Compare/Capture High Byte Register
|
||||
__sfr __at (0xBE) EPCR; // Ethernet PHY Command Index Register
|
||||
__sfr __at (0xBF) EPDR; // Ethernet PHY Data Register
|
||||
|
||||
__sfr __at (0xC0) SCON1; // UART 1 Configuration Register
|
||||
__sfr __at (0xC1) SBUF1; // UART 1 Buffer Register
|
||||
__sfr __at (0xC2) CMOD; // PCA Timer/Counter Mode Register
|
||||
__sfr __at (0xC3) CCON; // PCA Timer/Counter Control Register
|
||||
__sfr __at (0xC4) CL; // PCA Timer/Counter Low
|
||||
__sfr __at (0xC5) CH; // PCA Timer/Counter High
|
||||
__sfr __at (0xC8) T2CON; // Timer 2 Configuration Register
|
||||
__sfr __at (0xC9) T2IF; // Timer 2 Interrupt Flags
|
||||
__sfr __at (0xCA) RLDL; // Timer 2 Reload Low Byte
|
||||
__sfr __at (0xCB) RLDH; // Timer 2 Reload High Byte
|
||||
__sfr __at (0xCC) TL2; // Timer 2 Low Byte Counter
|
||||
__sfr __at (0xCD) TH2; // Timer 2 High Byte Counter
|
||||
__sfr __at (0xCE) SPICIR; // SPI Command Index Register
|
||||
__sfr __at (0xCF) SPIDR; // SPI Data Register
|
||||
|
||||
__sfr __at (0xD0) PSW; // Program Status Word
|
||||
__sfr __at (0xD1) CCAPM0; // PCA Compare/Capture Module Mode Register 0
|
||||
__sfr __at (0xD2) CCAPM1; // PCA Compare/Capture Module Mode Register 1
|
||||
__sfr __at (0xD3) CCAPM2; // PCA Compare/Capture Module Mode Register 2
|
||||
__sfr __at (0xD4) CCAPM3; // PCA Compare/Capture Module Mode Register 3
|
||||
__sfr __at (0xD5) CCAPM4; // PCA Compare/Capture Module Mode Register 4
|
||||
__sfr __at (0xD6) OWCIR; // OneWire Command Index Register
|
||||
__sfr __at (0xD7) OWDR; // OneWire Data Register
|
||||
__sfr __at (0xD8) WDCON; // Watchdog Configuration
|
||||
__sfr __at (0xDE) CANCIR; // CAN Bus Command Index Register
|
||||
__sfr __at (0xDF) CANDR; // CAN Bus Data Register
|
||||
|
||||
__sfr __at (0xE0) ACC; // Accumulator
|
||||
/* UART2 registers */
|
||||
__sfr __at (0xE1) UR2_DLL;// High Speed UART2 Divisor Latch Low Register
|
||||
__sfr __at (0xE1) UR2_THR;// High Speed UART2 Transmit Holding Register for Writing
|
||||
__sfr __at (0xE1) UR2_RBR;// High Speed UART2 Receive Buffer Register for Reading
|
||||
__sfr __at (0xE2) UR2_DLH;// High Speed UART2 Divisor Latch High Register
|
||||
__sfr __at (0xE2) UR2_IER;// High Speed UART2 Interrupt Enable Register
|
||||
__sfr __at (0xE3) UR2_FCR;// High Speed UART2 FIFO Control Register for Writing
|
||||
__sfr __at (0xE3) UR2_IIR;// High Speed UART2 Interrupt Identification Register for Reading
|
||||
__sfr __at (0xE4) UR2_LCR;// High Speed UART2 Line Control Register
|
||||
__sfr __at (0xE5) UR2_MCR;// High Speed UART2 Modem Control Register
|
||||
__sfr __at (0xE6) UR2_LSR;// High Speed UART2 Line Status Register
|
||||
__sfr __at (0xE7) UR2_MSR;// High Speed UART2 Modem Status Register
|
||||
__sfr __at (0xE8) EIE; // External Interrupt Enable
|
||||
__sfr __at (0xE9) STATUS; // Status Register
|
||||
__sfr __at (0xEA) MXAX; // MOVX @Ri Extended Register
|
||||
__sfr __at (0xEB) TA; // Timed Access Protection
|
||||
|
||||
__sfr __at (0xF0) B; // B Working Register
|
||||
__sfr __at (0xF8) EIP; // Extended Interrupt Priority Register
|
||||
__sfr __at (0xF9) MD0; // MDU Data 0
|
||||
__sfr __at (0xFA) MD1; // MDU Data 1
|
||||
__sfr __at (0xFB) MD2; // MDU Data 2
|
||||
__sfr __at (0xFC) MD3; // MDU Data 3
|
||||
__sfr __at (0xFD) MD4; // MDU Data 4
|
||||
__sfr __at (0xFE) MD5; // MDU Data 5
|
||||
__sfr __at (0xFF) ARCON ;// MDU Control Register
|
||||
|
||||
/* Bit Registers */
|
||||
|
||||
/* P0 (0x80) Bit Registers */
|
||||
__sbit __at (0x80) P0_0;
|
||||
__sbit __at (0x81) P0_1;
|
||||
__sbit __at (0x82) P0_2;
|
||||
__sbit __at (0x83) P0_3;
|
||||
__sbit __at (0x84) P0_4;
|
||||
__sbit __at (0x85) P0_5;
|
||||
__sbit __at (0x86) P0_6;
|
||||
__sbit __at (0x87) P0_7;
|
||||
|
||||
/* DPS (0x86) Bit Values */
|
||||
#define SEL_ 0x01
|
||||
#define TSL_ 0x20
|
||||
#define ID0_ 0x40
|
||||
#define ID1_ 0x80
|
||||
|
||||
/* PCON (0x87) Bit Values */
|
||||
#define PMM_ 0x01
|
||||
#define STOP_ 0x02
|
||||
#define SWB_ 0x04
|
||||
#define PWE_ 0x10
|
||||
#define SMOD1_ 0x40
|
||||
#define SMOD2_ 0x80
|
||||
|
||||
/* TCON (0x88) Bit Registers */
|
||||
__sbit __at (0x88) IT0;
|
||||
__sbit __at (0x89) IE0;
|
||||
__sbit __at (0x8A) IT1;
|
||||
__sbit __at (0x8B) IE1;
|
||||
__sbit __at (0x8C) TR0;
|
||||
__sbit __at (0x8D) TF0;
|
||||
__sbit __at (0x8E) TR1;
|
||||
__sbit __at (0x8F) TF1;
|
||||
|
||||
/* TMOD (0x89) Bit Values */
|
||||
#define T0_M0_ 0x01
|
||||
#define T0_M1_ 0x02
|
||||
#define T0_CT_ 0x04
|
||||
#define T0_GATE_ 0x08
|
||||
#define T1_M0_ 0x10
|
||||
#define T1_M1_ 0x20
|
||||
#define T1_CT_ 0x40
|
||||
#define T1_GATE_ 0x80
|
||||
|
||||
#define T1_MASK_ 0xF0
|
||||
#define T0_MASK_ 0x0F
|
||||
|
||||
/* CKCON (0x8E) Bit Values */
|
||||
#define MD0_ 0x01
|
||||
#define MD1_ 0x02
|
||||
#define MD2_ 0x04
|
||||
#define T0M_ 0x08
|
||||
#define T1M_ 0x10
|
||||
#define T2M_ 0x20
|
||||
#define WD0_ 0x40
|
||||
#define WD1_ 0x80
|
||||
|
||||
/* CSREPR (0x8F) Bit Values */
|
||||
#define SW_RST 0x01
|
||||
#define SW_RBT 0x02
|
||||
#define FARM 0x04
|
||||
#define FAES 0x08
|
||||
#define PMS 0x10
|
||||
#define SCS_100M 0xC0
|
||||
#define SCS_75M 0x80
|
||||
#define SCS_50M 0x40
|
||||
#define SCS_25M 0x00
|
||||
|
||||
/* P1 (0x90) Bit Registers */
|
||||
__sbit __at (0x90) P1_0;
|
||||
__sbit __at (0x91) P1_1;
|
||||
__sbit __at (0x92) P1_2;
|
||||
__sbit __at (0x93) P1_3;
|
||||
__sbit __at (0x94) P1_4;
|
||||
__sbit __at (0x95) P1_5;
|
||||
__sbit __at (0x96) P1_6;
|
||||
__sbit __at (0x97) P1_7;
|
||||
|
||||
/* EIF (0x91) Bit Values */
|
||||
#define INT2F 0x01
|
||||
#define INT3F 0x02
|
||||
#define INT4F 0x04
|
||||
#define INT5F 0x08
|
||||
#define INT6F 0x10
|
||||
|
||||
/* SCON0 (0x98) Bit Registers */
|
||||
__sbit __at (0x98) RI0;
|
||||
__sbit __at (0x99) TI0;
|
||||
__sbit __at (0x9A) RB08;
|
||||
__sbit __at (0x9B) TB08;
|
||||
__sbit __at (0x9C) REN0;
|
||||
__sbit __at (0x9D) SM02;
|
||||
__sbit __at (0x9E) SM01;
|
||||
__sbit __at (0x9F) SM00;
|
||||
|
||||
/* DBAR (0x9A) Bit Values */
|
||||
#define BUS_REQ 0x01
|
||||
#define BUS_GRANT 0x80
|
||||
|
||||
/* ACON (0x9D) Bit Values */
|
||||
#define FLAT_MODE 0x02
|
||||
#define LARGE_MODE 0x00
|
||||
|
||||
/* PISSR1 (0x9E) Bit Values */
|
||||
#define LB_INT_STU 0x01
|
||||
#define LB_EXT_INT_STU 0x02
|
||||
#define ETH_INT_STU 0x04
|
||||
#define TOE_INT_STU 0x08
|
||||
#define OW_INT_STU 0x10
|
||||
#define SPI_INT_STU 0x20
|
||||
#define I2C_INT_STU 0x40
|
||||
#define CAN_INT_STU 0x80
|
||||
|
||||
/* PISSR2 (0x9F) Bit Values */
|
||||
#define UART2_INT_STU 0x01
|
||||
|
||||
/* P2 (0xA0) Bit Registers */
|
||||
__sbit __at (0xA0) P2_0;
|
||||
__sbit __at (0xA1) P2_1;
|
||||
__sbit __at (0xA2) P2_2;
|
||||
__sbit __at (0xA3) P2_3;
|
||||
__sbit __at (0xA4) P2_4;
|
||||
__sbit __at (0xA5) P2_5;
|
||||
__sbit __at (0xA6) P2_6;
|
||||
__sbit __at (0xA7) P2_7;
|
||||
|
||||
/* IE (0xA8) Bit Registers */
|
||||
__sbit __at (0xA8) EX0; /* 1=Enable External interrupt 0 */
|
||||
__sbit __at (0xA9) ET0; /* 1=Enable Timer 0 interrupt */
|
||||
__sbit __at (0xAA) EX1; /* 1=Enable External interrupt 1 */
|
||||
__sbit __at (0xAB) ET1; /* 1=Enable Timer 1 interrupt */
|
||||
__sbit __at (0xAC) ES0; /* 1=Enable Serial port 0 interrupt */
|
||||
__sbit __at (0xAD) ET2; /* 1=Enable Timer 2 interrupt */
|
||||
__sbit __at (0xAE) ES1; /* 1=Enable Serial port 1 interrupt */
|
||||
__sbit __at (0xAF) EA; /* 0=Disable all interrupts */
|
||||
|
||||
/* P3 (0xB0) Bit Registers (Mnemonics & Ports) */
|
||||
__sbit __at (0xB0) P3_0;
|
||||
__sbit __at (0xB1) P3_1;
|
||||
__sbit __at (0xB2) P3_2;
|
||||
__sbit __at (0xB3) P3_3;
|
||||
__sbit __at (0xB4) P3_4;
|
||||
__sbit __at (0xB5) P3_5;
|
||||
__sbit __at (0xB6) P3_6;
|
||||
__sbit __at (0xB7) P3_7;
|
||||
|
||||
__sbit __at (0xB0) RXD; /* Serial data input */
|
||||
__sbit __at (0xB1) TXD; /* Serial data output */
|
||||
__sbit __at (0xB2) INT0; /* External interrupt 0 */
|
||||
__sbit __at (0xB3) INT1; /* External interrupt 1 */
|
||||
__sbit __at (0xB4) T0; /* Timer 0 external input */
|
||||
__sbit __at (0xB5) T1; /* Timer 1 external input */
|
||||
__sbit __at (0xB6) WR; /* External data memory write strobe */
|
||||
__sbit __at (0xB7) RD; /* External data memory read strobe */
|
||||
|
||||
/* IP (0xB8) Bit Registers */
|
||||
__sbit __at (0xB8) PX0;
|
||||
__sbit __at (0xB9) PT0;
|
||||
__sbit __at (0xBA) PX1;
|
||||
__sbit __at (0xBB) PT1;
|
||||
__sbit __at (0xBC) PS0;
|
||||
__sbit __at (0xBD) PT2;
|
||||
__sbit __at (0xBE) PS1;
|
||||
|
||||
/* SCON1 (0xC0) Bit Registers */
|
||||
__sbit __at (0xC0) RI1;
|
||||
__sbit __at (0xC1) TI1;
|
||||
__sbit __at (0xC2) RB18;
|
||||
__sbit __at (0xC3) TB18;
|
||||
__sbit __at (0xC4) REN1;
|
||||
__sbit __at (0xC5) SM12;
|
||||
__sbit __at (0xC6) SM11;
|
||||
__sbit __at (0xC7) SM10;
|
||||
|
||||
/* CMOM (0xC2) Bit Values */
|
||||
#define PCA_ECF 0x01
|
||||
#define PCA_T0_OF 0x08
|
||||
#define PCA_EXT_CLK 0x0E
|
||||
#define PCA_GATE_OFF 0x80
|
||||
|
||||
/* CCON (0xC3) Bit Values */
|
||||
#define PCA_CCF0 0x01
|
||||
#define PCA_CCF1 0x02
|
||||
#define PCA_CCF2 0x04
|
||||
#define PCA_CCF3 0x08
|
||||
#define PCA_CCF4 0x10
|
||||
#define PCA_CR 0x40
|
||||
#define PCA_CF 0x80
|
||||
|
||||
/* T2CON (0xC8) Bit Registers */
|
||||
__sbit __at (0xC8) CPRL2;
|
||||
__sbit __at (0xC9) CT2;
|
||||
__sbit __at (0xCA) TR2;
|
||||
__sbit __at (0xCB) EXEN2;
|
||||
__sbit __at (0xCC) TCLK;
|
||||
__sbit __at (0xCD) RCLK;
|
||||
__sbit __at (0xCE) EXF2;
|
||||
__sbit __at (0xCF) TF2;
|
||||
|
||||
/* PSW (0xD0) Bit Registers */
|
||||
__sbit __at (0xD0) P;
|
||||
__sbit __at (0xD1) F1;
|
||||
__sbit __at (0xD2) OV;
|
||||
__sbit __at (0xD3) RS0;
|
||||
__sbit __at (0xD4) RS1;
|
||||
__sbit __at (0xD5) F0;
|
||||
__sbit __at (0xD6) AC;
|
||||
__sbit __at (0xD7) CY;
|
||||
|
||||
/* CCAPM0-4 (0xD1-0xD5) Bit Values */
|
||||
#define ECCFs 0x01
|
||||
#define PWMs 0x02
|
||||
#define TOGs 0x04
|
||||
#define MATs 0x08
|
||||
#define CAPNs 0x10
|
||||
#define CAPPs 0x20
|
||||
#define ECOMs 0x40
|
||||
#define CEXs 0x80
|
||||
|
||||
/* PSW (0xD8) Bit Registers */
|
||||
__sbit __at (0xD8) RWT;
|
||||
__sbit __at (0xD9) EWT;
|
||||
__sbit __at (0xDA) WTRF;
|
||||
__sbit __at (0xDB) WDIF;
|
||||
|
||||
/* Interrupt Vectors: Address = (N * 8) + 3 */
|
||||
#define IE0_VECTOR 0 /* 0x03 External Interrupt 0 */
|
||||
#define TF0_VECTOR 1 /* 0x0B Timer 0 */
|
||||
#define IE1_VECTOR 2 /* 0x13 External Interrupt 1 */
|
||||
#define TF1_VECTOR 3 /* 0x1B Timer 1 */
|
||||
#define SIO0_VECTOR 4 /* 0x23 Serial port */
|
||||
#define TF2_VECTOR 5 /* 0x2B Timer 2 */
|
||||
#define SIO1_VECTOR 6 /* 0x33 Serial port */
|
||||
#define DMA_VECTOR 7 /* 0x3B Internal DMA Transfer */
|
||||
#define PCA_VECTOR 8 /* 0x43 Internal Programmable Counter Array */
|
||||
#define PIR_VECTOR 9 /* 0x4B Internal Peripherial IRQ */
|
||||
#define SDMA_VECTOR 10 /* 0x53 Internal Software DMA */
|
||||
#define WU_VECTOR 11 /* 0x5B Wake-Up */
|
||||
#define WDT_VECTOR 12 /* 0x63 Internal Watchdog */
|
||||
|
||||
/* UR2_IER (0xE2) Bit Values */
|
||||
#define UR2_RDI_ENB 0x01
|
||||
#define UR2_THRI_ENB 0x02
|
||||
#define UR2_RLSI_ENB 0x04
|
||||
#define UR2_MSI_ENB 0x08
|
||||
|
||||
/* UR2_IIR (0xE3) Bit Values */
|
||||
#define UR2_NONE_INTR 0x01
|
||||
#define UR2_RLS_INTR 0x06
|
||||
#define UR2_RD_TRIG_INTR 0x04
|
||||
#define UR2_RD_TI_INTR 0x0C
|
||||
#define UR2_THRE_INTR 0x02
|
||||
#define UR2_MS_INTR 0x00
|
||||
|
||||
/* UR2_FCR (0xE3) Bit Values */
|
||||
#define UR2_FIFO_MODE 0x01
|
||||
#define UR2_RXFIFO_RST 0x02
|
||||
#define UR2_TXFIFO_RST 0x04
|
||||
#define UR2_TRIG_01 0x00
|
||||
#define UR2_TRIG_04 0x40
|
||||
#define UR2_TRIG_08 0x80
|
||||
#define UR2_TRIG_14 0xC0
|
||||
|
||||
/* UR2_LCR (0xE4) Bit Values */
|
||||
#define UR2_CHAR_5 0x00
|
||||
#define UR2_CHAR_6 0x01
|
||||
#define UR2_CHAR_7 0x02
|
||||
#define UR2_CHAR_8 0x03
|
||||
#define UR2_STOP_10 0x00
|
||||
#define UR2_STOP_15 0x04
|
||||
#define UR2_PARITY_ENB 0x08
|
||||
#define UR2_EVEN_PARITY 0x10
|
||||
#define UR2_STICK_PARITY 0x20
|
||||
#define UR2_BREAK_ENB 0x40
|
||||
#define UR2_DLAB_ENB 0x80
|
||||
|
||||
/* UR2_MCR (0xE5) Bit Values */
|
||||
#define UR2_DTR 0x01
|
||||
#define UR2_RTS 0x02
|
||||
#define UR2_OUT1 0x04
|
||||
#define UR2_OUT2 0x08
|
||||
#define UR2_LOOPBACK 0x10
|
||||
#define UR2_RS485_RECEIVE 0x40
|
||||
#define UR2_RS485_DRIVE 0x80
|
||||
|
||||
/* UR2_LSR (0xE6) Bit Values */
|
||||
#define UR2_DR 0x01
|
||||
#define UR2_OE 0x02
|
||||
#define UR2_PE 0x04
|
||||
#define UR2_FE 0x08
|
||||
#define UR2_BI 0x10
|
||||
#define UR2_THRE 0x20
|
||||
#define UR2_TEMT 0x40
|
||||
#define UR2_FRAME_ERR 0x80
|
||||
|
||||
/* UR2_MSR (0xE7) Bit Values */
|
||||
#define UR2_DCTS 0x01
|
||||
#define UR2_DDSR 0x02
|
||||
#define UR2_TERI 0x04
|
||||
#define UR2_DDCD 0x08
|
||||
#define UR2_CTS 0x10
|
||||
#define UR2_DSR 0x20
|
||||
#define UR2_RI 0x40
|
||||
#define UR2_DCD 0x80
|
||||
|
||||
/* EIE (0xE8) Bit Registers */
|
||||
__sbit __at (0xE8) EINT2;
|
||||
__sbit __at (0xE9) EINT3;
|
||||
__sbit __at (0xEA) EINT4;
|
||||
__sbit __at (0xEB) EINT5;
|
||||
__sbit __at (0xEC) EINT6;
|
||||
__sbit __at (0xED) EWDI;
|
||||
|
||||
/* EIP (0xF8) Bit Registers */
|
||||
__sbit __at (0xF8) PINT2;
|
||||
__sbit __at (0xF9) PINT3;
|
||||
__sbit __at (0xFA) PINT4;
|
||||
__sbit __at (0xFB) PINT5;
|
||||
__sbit __at (0xFC) PINT6;
|
||||
__sbit __at (0xFD) PWDI;
|
||||
|
||||
#endif
|
177
Asixtool/asix-testcode/cpu_ax110xx.c
Normal file
177
Asixtool/asix-testcode/cpu_ax110xx.c
Normal file
|
@ -0,0 +1,177 @@
|
|||
#include "ax110xx.h"
|
||||
#include "interrupt_ax110xx.h"
|
||||
#include "cpu_ax110xx.h"
|
||||
#include "types_ax110xx.h"
|
||||
|
||||
static unsigned char globeInt = 0;
|
||||
static unsigned char cpuSysClk = 0;
|
||||
static unsigned char memShadow = 0;
|
||||
static unsigned char progWtst = 0;
|
||||
static unsigned char dataStretch = 0;
|
||||
|
||||
void AX11000_Init(void)
|
||||
{
|
||||
EA = 0; // turn off globe interrupt
|
||||
|
||||
P0 = 0xFF;
|
||||
P1 = 0xFF;
|
||||
P2 = 0xFF;
|
||||
P3 = 0xFF;
|
||||
|
||||
/* Check program wait-state and data memory wait-state */
|
||||
if (CSREPR & PMS)
|
||||
{
|
||||
memShadow = 1;
|
||||
|
||||
/* for real chip */
|
||||
switch (CSREPR & (BIT6|BIT7))
|
||||
{
|
||||
case SCS_100M :
|
||||
cpuSysClk = SCS_100M;
|
||||
WTST = 0x01;
|
||||
CKCON = 0x01;
|
||||
break;
|
||||
case SCS_50M :
|
||||
cpuSysClk = SCS_50M;
|
||||
WTST = 0x00;
|
||||
CKCON = 0x01;
|
||||
break;
|
||||
case SCS_25M :
|
||||
cpuSysClk = SCS_25M;
|
||||
WTST = 0x00;
|
||||
CKCON = 0x01;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
memShadow = 0;
|
||||
|
||||
/* for real chip */
|
||||
switch (CSREPR & (BIT6|BIT7))
|
||||
{
|
||||
case SCS_100M :
|
||||
cpuSysClk = SCS_100M;
|
||||
WTST = 0x07;
|
||||
CKCON = 0x01;
|
||||
break;
|
||||
case SCS_50M :
|
||||
cpuSysClk = SCS_50M;
|
||||
WTST = 0x03;
|
||||
CKCON = 0x01;
|
||||
break;
|
||||
case SCS_25M :
|
||||
cpuSysClk = SCS_25M;
|
||||
WTST = 0x01;
|
||||
CKCON = 0x01;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
progWtst = WTST & 0x07;
|
||||
dataStretch = CKCON & 0x07;
|
||||
|
||||
PCON &= ~SWB_; // Turn off switchback function.
|
||||
|
||||
EIF &= ~INT5F; // Clear the flag of interrupt 5.
|
||||
EIF &= ~INT6F; // Clear the flag of interrupt 6.
|
||||
if (WTRF)
|
||||
{
|
||||
CSREPR |= SW_RST;
|
||||
WTRF = 0; // Clear Watch Dog Time Out Reset Flag.
|
||||
}
|
||||
|
||||
PINT2 = 1; // INT2 priority is at high level for DMA request.
|
||||
|
||||
EXTINT0(OFF); // EINT0 interrupt.
|
||||
EXTINT1(OFF); // EINT1 interrupt.
|
||||
EXTINT2(OFF); // EINT2 interrupt for DMA request.
|
||||
EXTINT3(OFF); // EINT3 interrupt for PCA.
|
||||
EXTINT4(OFF); // EINT4 interrupt for peripheral device.
|
||||
EXTINT5(OFF); // EINT5 interrupt for software timer.
|
||||
EXTINT6(OFF); // EINT6 interrupt for wake-up of power management mode and stop mode.
|
||||
|
||||
if (globeInt & BIT7)
|
||||
EA = globeInt & BIT0;
|
||||
else
|
||||
EA = 1; // Enable the globe interrupt.
|
||||
}
|
||||
|
||||
unsigned char AX11000_GetSysClk(void)
|
||||
{
|
||||
return cpuSysClk;
|
||||
}
|
||||
|
||||
unsigned char AX11000_GetMemSdw(void)
|
||||
{
|
||||
return memShadow;
|
||||
}
|
||||
|
||||
unsigned char AX11000_GetProgWst(void)
|
||||
{
|
||||
return progWtst;
|
||||
}
|
||||
|
||||
unsigned char AX11000_GetDataSth(void)
|
||||
{
|
||||
return dataStretch;
|
||||
}
|
||||
|
||||
void AX11000_SoftReset(void)
|
||||
{
|
||||
if (EA)
|
||||
globeInt = BIT0 | BIT7; // BIT0:EA bit record ; BIT7:Software reset record.
|
||||
else
|
||||
globeInt = BIT7;
|
||||
|
||||
EA = 0;
|
||||
|
||||
CSREPR |= SW_RST;
|
||||
}
|
||||
|
||||
void AX11000_SoftReboot(void)
|
||||
{
|
||||
CSREPR |= SW_RBT;
|
||||
}
|
||||
|
||||
void AX11000_WatchDogSetting(unsigned char wdIntrEnb, unsigned char wdRstEnb, unsigned char wdPrty, unsigned char wdTime)
|
||||
{
|
||||
CKCON |= wdTime;
|
||||
|
||||
if (wdIntrEnb & WD_INTR_ENABLE)
|
||||
{
|
||||
EWDI = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
EWDI = 0;
|
||||
}
|
||||
|
||||
if (wdRstEnb & WD_RESET_ENABLE)
|
||||
{
|
||||
TA = 0xAA;
|
||||
TA = 0x55;
|
||||
EWT = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
TA = 0xAA;
|
||||
TA = 0x55;
|
||||
EWT = 0;
|
||||
}
|
||||
|
||||
if (wdPrty & WD_HIGH_PRIORITY)
|
||||
{
|
||||
PWDI = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
PWDI = 0;
|
||||
}
|
||||
|
||||
TA = 0xAA;
|
||||
TA = 0x55;
|
||||
RWT = 1;
|
||||
WTRF = 0;
|
||||
WDIF = 0;
|
||||
}
|
61
Asixtool/asix-testcode/cpu_ax110xx.h
Normal file
61
Asixtool/asix-testcode/cpu_ax110xx.h
Normal file
|
@ -0,0 +1,61 @@
|
|||
#ifndef AX11000_H
|
||||
#define AX11000_H
|
||||
|
||||
#define GET_SYS_VALUE 1 // 1:get the system globe value information
|
||||
#define AX_SWRST_ENB 0 // 1:use software reset function ; 0:not use
|
||||
#define AX_SWRBT_ENB 0 // 1:use software reboot function ; 0:not use
|
||||
#define STOE_ENABLE 0
|
||||
#define AX_WATCHDOG_ENB 0 // 1:involve watchdog function ; 0:not use
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
#define RUNTIME_CODE_START_AT_0H 0 /* 0: runtime code start at 0h */
|
||||
#define RUNTIME_CODE_START_AT_24kH 1 /* 1: runtime code start at 24kh. */
|
||||
#define RUNTIME_CODE_START_ADDRESS (RUNTIME_CODE_START_AT_0H)
|
||||
|
||||
/* MACRO DECLARATIONS */
|
||||
#define AX_DBG_LED(value) {P1 = value;} // debug LED port, default is P1
|
||||
|
||||
/* NAMING CONSTANT DECLARATIONS */
|
||||
#define PROG_WTST_0 0
|
||||
#define PROG_WTST_1 1
|
||||
#define PROG_WTST_2 2
|
||||
#define PROG_WTST_3 3
|
||||
#define PROG_WTST_4 4
|
||||
#define PROG_WTST_5 5
|
||||
#define PROG_WTST_6 6
|
||||
#define PROG_WTST_7 7
|
||||
#define DATA_STRETCH_0 0
|
||||
#define DATA_STRETCH_1 1
|
||||
#define DATA_STRETCH_2 2
|
||||
#define DATA_STRETCH_3 3
|
||||
#define DATA_STRETCH_4 4
|
||||
#define DATA_STRETCH_5 5
|
||||
#define DATA_STRETCH_6 6
|
||||
#define DATA_STRETCH_7 7
|
||||
|
||||
#define SHADOW_MEM_ENB 0x10
|
||||
#define SYS_CLK_100M 0xC0
|
||||
#define SYS_CLK_50M 0x40
|
||||
#define SYS_CLK_25M 0x00
|
||||
|
||||
#define WD_INTR_ENABLE 1
|
||||
#define WD_INTR_DISABLE 0
|
||||
#define WD_RESET_ENABLE 1
|
||||
#define WD_RESET_DISABLE 0
|
||||
#define WD_HIGH_PRIORITY 1
|
||||
#define WD_LOW_PRIORITY 0
|
||||
#define WD_INTERVAL_131K 0x00
|
||||
#define WD_INTERVAL_1M WD0_
|
||||
#define WD_INTERVAL_8M WD1_
|
||||
#define WD_INTERVAL_67M WD1_|WD0_
|
||||
|
||||
void AX11000_Init(void);
|
||||
unsigned char AX11000_GetSysClk(void);
|
||||
unsigned char AX11000_GetMemSdw(void);
|
||||
unsigned char AX11000_GetProgWst(void);
|
||||
unsigned char AX11000_GetDataSth(void);
|
||||
void AX11000_SoftReset(void);
|
||||
void AX11000_SoftReboot(void);
|
||||
void AX11000_WatchDogSetting(unsigned char wdIntrEnb, unsigned char wdRstEnb, unsigned char wdPrty, unsigned char wdTime);
|
||||
|
||||
#endif /* End of AX11000_H */
|
188
Asixtool/asix-testcode/interrupt_ax110xx.c
Normal file
188
Asixtool/asix-testcode/interrupt_ax110xx.c
Normal file
|
@ -0,0 +1,188 @@
|
|||
#include "ax110xx.h"
|
||||
#include "cpu_ax110xx.h"
|
||||
#include "interrupt_ax110xx.h"
|
||||
#include "types_ax110xx.h"
|
||||
|
||||
#if LBI_IRQ_ENABLE
|
||||
#include "lbi.h"
|
||||
#endif
|
||||
|
||||
#if ETH_IRQ_ENABLE
|
||||
#include "ethernet/mac.h"
|
||||
#include "ethernet/stoe.h"
|
||||
#endif
|
||||
|
||||
#if I2C_IRQ_ENABLE
|
||||
#include "i2c.h"
|
||||
#endif
|
||||
|
||||
#if SPI_IRQ_ENABLE
|
||||
#include "spi.h"
|
||||
#endif
|
||||
|
||||
#if ONEWIRE_IRQ_ENABLE
|
||||
#include "onewire.h"
|
||||
#endif
|
||||
|
||||
#if CAN_IRQ_ENABLE
|
||||
#include "can.h"
|
||||
#endif
|
||||
|
||||
#if HSUART_IRQ_ENABLE
|
||||
#include "hsuart.h"
|
||||
#endif
|
||||
|
||||
void ax11000_PeripherialISR(void) __interrupt 9;
|
||||
|
||||
#if POWER_MANAGEMENT_IRQ_ENABLE
|
||||
void ax11000_PmmISR(void);
|
||||
#endif
|
||||
|
||||
#if WATCHDOG_IRQ_ENB
|
||||
void ax11000_WatchDogISR(void);
|
||||
#endif
|
||||
|
||||
void ax11000_PeripherialISR(void) __interrupt 9
|
||||
{
|
||||
unsigned int intrStt1 = 0;
|
||||
unsigned int intrStt2 = 0;
|
||||
|
||||
/* Interrupt type check */
|
||||
while (1)
|
||||
{
|
||||
EA = 0;
|
||||
intrStt1 = PISSR1;
|
||||
intrStt2 = PISSR2;
|
||||
EA = 1;
|
||||
|
||||
if ((intrStt1 == 0) && (intrStt2 == 0))
|
||||
break;
|
||||
|
||||
#if LBI_IRQ_ENABLE
|
||||
if (intrStt1 & LB_INT_STU)
|
||||
{
|
||||
LocalBusFunc();
|
||||
}
|
||||
|
||||
if (intrStt1 & LB_EXT_INT_STU)
|
||||
{
|
||||
LocalBusAccessCompleteFunc();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ETH_IRQ_ENABLE
|
||||
#if (MAC_GET_INTSTATUS_MODE == MAC_INTERRUPT_MODE)
|
||||
if (intrStt1 & ETH_INT_STU)
|
||||
{
|
||||
MAC_SetInterruptFlag();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if ETH_IRQ_ENABLE
|
||||
#if (STOE_GET_INTSTATUS_MODE == STOE_INTERRUPT_MODE)
|
||||
if (intrStt1 & TOE_INT_STU)
|
||||
{
|
||||
STOE_SetInterruptFlag();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if CAN_IRQ_ENABLE
|
||||
if (intrStt1 & CAN_INT_STU)
|
||||
{
|
||||
CAN_Func();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if I2C_IRQ_ENABLE
|
||||
if (intrStt1 & I2C_INT_STU)
|
||||
{
|
||||
I2C_Func();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if SPI_IRQ_ENABLE
|
||||
if (intrStt1 & SPI_INT_STU)
|
||||
{
|
||||
SPI_Func();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ONEWIRE_IRQ_ENABLE
|
||||
if (intrStt1 & OW_INT_STU)
|
||||
{
|
||||
ONEWIRE_Func();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if HSUART_IRQ_ENABLE
|
||||
if (intrStt2 & UART2_INT_STU)
|
||||
{
|
||||
HSUR_Func();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if POWER_MANAGEMENT_IRQ_ENABLE
|
||||
void ax11000_PmmISR(void) __interrupt 11
|
||||
{
|
||||
unsigned int wakeStatus = 0;
|
||||
unsigned int mode = 0;
|
||||
unsigned int sysClk = 0;
|
||||
unsigned int canReg = 0;
|
||||
unsigned int intEnb = 0;
|
||||
|
||||
EA = 0;
|
||||
EIF &= ~INT6F; // Clear the flag of interrupt 6.
|
||||
EA = 1;
|
||||
|
||||
|
||||
|
||||
wakeStatus = PCON;
|
||||
if (!(wakeStatus & SWB_))
|
||||
{
|
||||
PCON &= ~ (PMM_ | STOP_);
|
||||
}
|
||||
|
||||
#if ETH_IRQ_ENABLE
|
||||
/* Ethernet wake up function */
|
||||
/* disable wake up interrupt */
|
||||
MDR = 0;
|
||||
MCIR = MAC_STOP_PMM_INT_ENABLE_REG;
|
||||
/* clear MAC status register */
|
||||
CLI_MacRd((ULONG)MAC_STOP_PMM_INT_STATUS_REG, &WakeStatus, 1);
|
||||
STOE_Standby = 0;
|
||||
#endif
|
||||
|
||||
#if CAN_IRQ_ENABLE
|
||||
/* CAN wake up function */
|
||||
CAN_WakeUpEvent(0); // 0 for exit power management mode
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if WATCHDOG_IRQ_ENB
|
||||
ax11000_WatchDogISR(void) __interrupt 12
|
||||
{
|
||||
if (EWDI)
|
||||
{
|
||||
if (EWT)
|
||||
{
|
||||
TA = 0xAA;
|
||||
TA = 0x55;
|
||||
WDIF = 0; // clear WatchDog Interrupt Flag.
|
||||
WTRF = 0; // clear the Watchdog Timer Reset Flag.
|
||||
RWT = 1; // reset watchdog timer.
|
||||
}
|
||||
else
|
||||
{
|
||||
TA = 0xAA;
|
||||
TA = 0x55;
|
||||
WDIF = 0; //clear WatchDog Interrupt Flag.
|
||||
RWT = 1; // reset watchdog timer.
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
25
Asixtool/asix-testcode/interrupt_ax110xx.h
Normal file
25
Asixtool/asix-testcode/interrupt_ax110xx.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
#ifndef INTERRUPT_AX110XX_H
|
||||
#define INTERRUPT_AX110XX_H
|
||||
|
||||
#define LBI_IRQ_ENABLE 0 // Local Bus IRQ; 1:On 2:Off
|
||||
#define ETH_IRQ_ENABLE 0 // Ethernet IRQ; 1:On 2:Off
|
||||
#define I2C_IRQ_ENABLE 0 // I2C IRQ; 1:On 2:Off
|
||||
#define SPI_IRQ_ENABLE 0 // SPI IRQ; 1:On 2:Off
|
||||
#define ONEWIRE_IRQ_ENABLE 0 // OneWire IRQ; 1:On 2:Off
|
||||
#define CAN_IRQ_ENABLE 0 // CAN IRQ; 1:On 2:Off
|
||||
#define HSUART_IRQ_ENABLE 0 // HS-Uart IRQ; 1:On 2:Off
|
||||
#define BOOTLDR_IRQ 0 // Bootloader Source Code; 1:On 2:Off
|
||||
#define POWER_MANAGEMENT_IRQ_ENABLE 0 // Power Management Wake-Up IRQ; 1:On 2:Off
|
||||
#define WATCHDOG_IRQ_ENABLE 0 // Watchdog IRQ; 1:On 2:Off
|
||||
|
||||
#define ON 1
|
||||
#define OFF 0
|
||||
#define EXTINT0(val) {EX0 = val;}
|
||||
#define EXTINT1(val) {EX1 = val;}
|
||||
#define EXTINT2(val) {EINT2 = val;}
|
||||
#define EXTINT3(val) {EINT3 = val;}
|
||||
#define EXTINT4(val) {EINT4 = val;}
|
||||
#define EXTINT5(val) {EINT5 = val;}
|
||||
#define EXTINT6(val) {EINT6 = val;}
|
||||
|
||||
#endif
|
162
Asixtool/asix-testcode/main.c
Normal file
162
Asixtool/asix-testcode/main.c
Normal file
|
@ -0,0 +1,162 @@
|
|||
#include <8052.h>
|
||||
|
||||
#include "ax110xx.h"
|
||||
#include "interrupt_ax110xx.h"
|
||||
#include "cpu_ax110xx.h"
|
||||
#include "types_ax110xx.h"
|
||||
#include "uart/uart.h"
|
||||
|
||||
#define ERASE_EVENT 1
|
||||
#define WRITE_EVENT 2
|
||||
#define READ_EVENT 3
|
||||
|
||||
extern void ax11000_PeripherialISR(void) __interrupt 9;
|
||||
#if UART0_ENABLE
|
||||
extern void uart0_ISR(void) __interrupt 4 __using 2;
|
||||
#endif
|
||||
#if UART1_ENABLE
|
||||
extern void uart1_ISR(void) __interrupt 6 __using 2;
|
||||
#endif
|
||||
|
||||
|
||||
volatile unsigned char hi_flag = 1;
|
||||
volatile unsigned char timer = 0;
|
||||
volatile unsigned char tstate = 0;
|
||||
|
||||
|
||||
void timer0_irq_proc(void) __interrupt 1 using 2
|
||||
{
|
||||
timer++;
|
||||
|
||||
if (timer == 0)
|
||||
{
|
||||
tstate = 1;
|
||||
}
|
||||
|
||||
switch(tstate)
|
||||
{
|
||||
case 1:
|
||||
case 16:
|
||||
P1_0 = 0;
|
||||
break;
|
||||
case 8:
|
||||
case 24:
|
||||
P1_0 = 1;
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
if(tstate)
|
||||
tstate++;
|
||||
|
||||
TR0 = 0; /* Stop Timer 0 counting */
|
||||
TH0 = 0x00;
|
||||
TL0 = 0x00;
|
||||
TR0 = 1; /* Start counting again */
|
||||
}
|
||||
|
||||
void pause(unsigned char len)
|
||||
{
|
||||
unsigned char a;
|
||||
unsigned int b;
|
||||
a=len;
|
||||
b=0xFFFF;
|
||||
while(a--)
|
||||
{
|
||||
while(b--)
|
||||
{
|
||||
__asm
|
||||
nop
|
||||
__endasm;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char _sdcc_external_startup()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void putstring(char *string)
|
||||
{
|
||||
unsigned char sc;
|
||||
sc = 0;
|
||||
while(string[sc] != 0)
|
||||
putchar(string[sc++]);
|
||||
}
|
||||
|
||||
const char hval[16] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' };
|
||||
|
||||
void putHexB(unsigned char b)
|
||||
{
|
||||
putchar(hval[b>>4]);
|
||||
putchar(hval[b&0x0F]);
|
||||
}
|
||||
|
||||
void putHexW(unsigned int w)
|
||||
{
|
||||
putHexB(w>>8);
|
||||
putHexB(w&0xFF);
|
||||
}
|
||||
|
||||
void putHexD(unsigned long d)
|
||||
{
|
||||
putHexW(d>>16);
|
||||
putHexW(d&0xFFFF);
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
AX11000_Init();
|
||||
|
||||
switch (CSREPR & (BIT6|BIT7))
|
||||
{
|
||||
case SCS_100M :
|
||||
goto three;
|
||||
break;
|
||||
case SCS_50M :
|
||||
goto two;
|
||||
break;
|
||||
case SCS_25M :
|
||||
goto one;
|
||||
break;
|
||||
}
|
||||
|
||||
goto none;
|
||||
|
||||
three:
|
||||
P1 = 0x00;
|
||||
pause(0x07);
|
||||
P1 = 0xFF;
|
||||
pause(0x07);
|
||||
two:
|
||||
P1 = 0x00;
|
||||
pause(0x07);
|
||||
P1 = 0xFF;
|
||||
pause(0x07);
|
||||
one:
|
||||
P1 = 0x00;
|
||||
pause(0x07);
|
||||
P1 = 0xFF;
|
||||
none:
|
||||
|
||||
TCON = 0; /* timer control register, byte operation */
|
||||
TH0 = 0x00;
|
||||
TL0 = 0x00;
|
||||
TR0 = 1; /* start timer0 */
|
||||
ET0 = 1; /* Enable Timer 0 overflow interrupt IE.1 */
|
||||
TI = 0; /* clear this out */
|
||||
|
||||
UART_SetPort(0);
|
||||
|
||||
TMOD = (TMOD & 0xF0) | 0x01; /* timer control mode, byte operation */
|
||||
|
||||
EA = 1; /* Enable Interrupts */
|
||||
|
||||
while (1)
|
||||
{
|
||||
pause(0x0F);
|
||||
|
||||
putstring("Hello World!\n\r");
|
||||
}
|
||||
}
|
162
Asixtool/asix-testcode/main.c.bak
Normal file
162
Asixtool/asix-testcode/main.c.bak
Normal file
|
@ -0,0 +1,162 @@
|
|||
#include <8052.h>
|
||||
|
||||
#include "ax110xx.h"
|
||||
#include "interrupt_ax110xx.h"
|
||||
#include "cpu_ax110xx.h"
|
||||
#include "types_ax110xx.h"
|
||||
#include "uart/uart.h"
|
||||
|
||||
#define ERASE_EVENT 1
|
||||
#define WRITE_EVENT 2
|
||||
#define READ_EVENT 3
|
||||
|
||||
extern void ax11000_PeripherialISR(void) __interrupt 9;
|
||||
#if UART0_ENABLE
|
||||
extern void uart0_ISR(void) __interrupt 4 __using 2;
|
||||
#endif
|
||||
#if UART1_ENABLE
|
||||
extern void uart1_ISR(void) __interrupt 6 __using 2;
|
||||
#endif
|
||||
|
||||
|
||||
volatile unsigned char hi_flag = 1;
|
||||
volatile unsigned char timer = 0;
|
||||
volatile unsigned char tstate = 0;
|
||||
|
||||
|
||||
void timer0_irq_proc(void) __interrupt 1 using 2
|
||||
{
|
||||
timer++;
|
||||
|
||||
if (timer == 0)
|
||||
{
|
||||
tstate = 1;
|
||||
}
|
||||
|
||||
switch(tstate)
|
||||
{
|
||||
case 1:
|
||||
case 16:
|
||||
P1_0 = 0;
|
||||
break;
|
||||
case 8:
|
||||
case 24:
|
||||
P1_0 = 1;
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
if(tstate)
|
||||
tstate++;
|
||||
|
||||
TR0 = 0; /* Stop Timer 0 counting */
|
||||
TH0 = 0x00;
|
||||
TL0 = 0x00;
|
||||
TR0 = 1; /* Start counting again */
|
||||
}
|
||||
|
||||
void pause(unsigned char len)
|
||||
{
|
||||
unsigned char a;
|
||||
unsigned int b;
|
||||
a=len;
|
||||
b=0xFFFF;
|
||||
while(a--)
|
||||
{
|
||||
while(b--)
|
||||
{
|
||||
__asm
|
||||
nop
|
||||
__endasm;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char _sdcc_external_startup()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void putstring(char *string)
|
||||
{
|
||||
unsigned char sc;
|
||||
sc = 0;
|
||||
while(string[sc] != 0)
|
||||
putchar(string[sc++]);
|
||||
}
|
||||
|
||||
const char hval[16] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' };
|
||||
|
||||
void putHexB(unsigned char b)
|
||||
{
|
||||
putchar(hval[b>>4]);
|
||||
putchar(hval[b&0x0F]);
|
||||
}
|
||||
|
||||
void putHexW(unsigned int w)
|
||||
{
|
||||
putHexB(w>>8);
|
||||
putHexB(w&0xFF);
|
||||
}
|
||||
|
||||
void putHexD(unsigned long d)
|
||||
{
|
||||
putHexW(d>>16);
|
||||
putHexW(d&0xFFFF);
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
AX11000_Init();
|
||||
|
||||
switch (CSREPR & (BIT6|BIT7))
|
||||
{
|
||||
case SCS_100M :
|
||||
goto three;
|
||||
break;
|
||||
case SCS_50M :
|
||||
goto two;
|
||||
break;
|
||||
case SCS_25M :
|
||||
goto one;
|
||||
break;
|
||||
}
|
||||
|
||||
goto none;
|
||||
|
||||
three:
|
||||
P1 = 0x00;
|
||||
pause(0x07);
|
||||
P1 = 0xFF;
|
||||
pause(0x07);
|
||||
two:
|
||||
P1 = 0x00;
|
||||
pause(0x07);
|
||||
P1 = 0xFF;
|
||||
pause(0x07);
|
||||
one:
|
||||
P1 = 0x00;
|
||||
pause(0x07);
|
||||
P1 = 0xFF;
|
||||
none:
|
||||
|
||||
TCON = 0; /* timer control register, byte operation */
|
||||
TH0 = 0x00;
|
||||
TL0 = 0x00;
|
||||
TR0 = 1; /* start timer0 */
|
||||
ET0 = 1; /* Enable Timer 0 overflow interrupt IE.1 */
|
||||
TI = 0; /* clear this out */
|
||||
|
||||
UART_SetPort(0);
|
||||
|
||||
TMOD = (TMOD & 0xF0) | 0x01; /* timer control mode, byte operation */
|
||||
|
||||
EA = 1; /* Enable Interrupts */
|
||||
|
||||
while (1)
|
||||
{
|
||||
pause(0x0F);
|
||||
|
||||
putstring("Hello betty World!\n\r");
|
||||
}
|
||||
}
|
88
Asixtool/asix-testcode/types_ax110xx.h
Normal file
88
Asixtool/asix-testcode/types_ax110xx.h
Normal file
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2005 ASIX Electronic Corporation All rights reserved.
|
||||
*
|
||||
* This is unpublished proprietary source code of ASIX Electronic Corporation
|
||||
*
|
||||
* The copyright notice above does not evidence any actual or intended
|
||||
* publication of such source code.
|
||||
*********************************************************************************
|
||||
*/
|
||||
/*================================================================================
|
||||
* Module Name : types.h
|
||||
* Purpose : Definition of type.
|
||||
* Author : Robin Lee
|
||||
* Date : 2005-12-28
|
||||
* Notes : None.
|
||||
* $Log: types.h,v $
|
||||
* Revision 1.1 2006/04/07 11:36:17 robin6633
|
||||
* no message
|
||||
*
|
||||
*================================================================================
|
||||
*/
|
||||
|
||||
#ifndef TYPES_H
|
||||
#define TYPES_H
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL ((void *) 0L)
|
||||
#endif
|
||||
|
||||
typedef unsigned short int BOOL;
|
||||
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
/* Bit Definitions for Bitwise Operation */
|
||||
#define BIT0 0x00000001
|
||||
#define BIT1 0x00000002
|
||||
#define BIT2 0x00000004
|
||||
#define BIT3 0x00000008
|
||||
#define BIT4 0x00000010
|
||||
#define BIT5 0x00000020
|
||||
#define BIT6 0x00000040
|
||||
#define BIT7 0x00000080
|
||||
#define BIT8 0x00000100
|
||||
#define BIT9 0x00000200
|
||||
#define BIT10 0x00000400
|
||||
#define BIT11 0x00000800
|
||||
#define BIT12 0x00001000
|
||||
#define BIT13 0x00002000
|
||||
#define BIT14 0x00004000
|
||||
#define BIT15 0x00008000
|
||||
#define BIT16 0x00010000
|
||||
#define BIT17 0x00020000
|
||||
#define BIT18 0x00040000
|
||||
#define BIT19 0x00080000
|
||||
#define BIT20 0x00100000
|
||||
#define BIT21 0x00200000
|
||||
#define BIT22 0x00400000
|
||||
#define BIT23 0x00800000
|
||||
#define BIT24 0x01000000
|
||||
#define BIT25 0x02000000
|
||||
#define BIT26 0x04000000
|
||||
#define BIT27 0x08000000
|
||||
#define BIT28 0x10000000
|
||||
#define BIT29 0x20000000
|
||||
#define BIT30 0x40000000
|
||||
#define BIT31 0x80000000
|
||||
|
||||
#define LOW_BYTE(word) (unsigned char)(word & 0x00FF)
|
||||
#define HIGH_BYTE(word) (unsigned char)((word & 0xFF00) >> 8)
|
||||
|
||||
/* Keil compiler user define */
|
||||
#define XDATA xdata
|
||||
#define IDATA idata
|
||||
#define BDATA bdata
|
||||
#define CODE code
|
||||
#define FAR far
|
||||
|
||||
/* Serial interface command direction */
|
||||
#define SI_WR BIT0
|
||||
#define SI_RD BIT1
|
||||
|
||||
#define FLASH_WR_ENB (PCON |= PWE_)
|
||||
#define FLASH_WR_DISB (PCON &= ~PWE_)
|
||||
|
||||
|
||||
#endif /* end of TYPES_H */
|
821
Asixtool/asix-testcode/uart/uart.c
Normal file
821
Asixtool/asix-testcode/uart/uart.c
Normal file
|
@ -0,0 +1,821 @@
|
|||
/*
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2005 ASIX Electronic Corporation All rights reserved.
|
||||
*
|
||||
* This is unpublished proprietary source code of ASIX Electronic Corporation
|
||||
*
|
||||
* The copyright notice above does not evidence any actual or intended
|
||||
* publication of such source code.
|
||||
*********************************************************************************
|
||||
*/
|
||||
/*================================================================================
|
||||
* Module Name : uart.c
|
||||
* Purpose : The UART module driver. It manages the character
|
||||
* buffer and handles the ISR. This driver includes UART0 and UART1.
|
||||
* Author : Robin Lee
|
||||
* Date : 2006-01-10
|
||||
* Notes : None.
|
||||
* $Log: uart.c,v $
|
||||
* Revision 1.1 2006/04/07 11:39:14 robin6633
|
||||
* no message
|
||||
*
|
||||
*================================================================================
|
||||
*/
|
||||
|
||||
/* INCLUDE FILE DECLARATIONS */
|
||||
#include "../ax110xx.h"
|
||||
#include "uart.h"
|
||||
|
||||
|
||||
|
||||
#if HSUR_ENABLE
|
||||
#include "hsuart.h"
|
||||
#endif
|
||||
|
||||
|
||||
/* STATIC VARIABLE DECLARATIONS */
|
||||
#if UART0_ENABLE
|
||||
static unsigned char uart0_TxBuf[MAX_TX_UART0_BUF_SIZE];
|
||||
static unsigned int uart0_TxHead = 0;
|
||||
static unsigned int uart0_TxTail = 0;
|
||||
static unsigned int uart0_TxCount = 0;
|
||||
static unsigned char uart0_TxFlag = 0;
|
||||
static unsigned char uart0_RxBuf[MAX_RX_UART0_BUF_SIZE];
|
||||
static unsigned int uart0_RxHead = 0;
|
||||
static unsigned int uart0_RxTail = 0;
|
||||
static unsigned char uart0_Mode = 0;
|
||||
unsigned int uart0_RxCount = 0;
|
||||
#endif
|
||||
|
||||
#if UART1_ENABLE
|
||||
static unsigned char uart1_TxBuf[MAX_TX_UART1_BUF_SIZE];
|
||||
static unsigned int uart1_TxHead = 0;
|
||||
static unsigned int uart1_TxTail = 0;
|
||||
static unsigned int uart1_TxCount = 0;
|
||||
static unsigned char uart1_TxFlag = 0;
|
||||
static unsigned char uart1_RxBuf[MAX_RX_UART1_BUF_SIZE];
|
||||
static unsigned int uart1_RxHead = 0;
|
||||
static unsigned int uart1_RxTail = 0;
|
||||
static unsigned char uart1_Mode = 0;
|
||||
unsigned int uart1_RxCount = 0;
|
||||
#endif
|
||||
static unsigned char uartPort = 0;
|
||||
|
||||
|
||||
/* LOCAL SUBPROGRAM DECLARATIONS */
|
||||
#if UART0_ENABLE
|
||||
//void uart0_ISR(void);
|
||||
static void uart0_Init(void);
|
||||
static signed char uart0_PutChar(signed char c);
|
||||
static signed char uart0_GetKey(void);
|
||||
static signed char UART0_NoBlockGetkey(void);
|
||||
#endif
|
||||
#if UART1_ENABLE
|
||||
//void uart1_ISR(void);
|
||||
static void uart1_Init(void);
|
||||
static signed char uart1_PutChar(signed char c);
|
||||
static signed char uart1_GetKey(void);
|
||||
static signed char uart1_NoBlockGetkey(void);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* LOCAL SUBPROGRAM BODIES */
|
||||
#if UART0_ENABLE
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* static void UART0_ISR(void)
|
||||
* Purpose : UART0 interrupt service routine. For sending out, it puts data
|
||||
* from software buffer into hardware serial buffer register (SBUF0).
|
||||
* For receiving, it gets data from hardware serial buffer register
|
||||
* (SBUF0) and stores into software buffer.
|
||||
* Params : none
|
||||
* Returns : none
|
||||
* Note : none
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
void uart0_ISR(void) __interrupt 4 __using 2
|
||||
{
|
||||
unsigned char parity = 0;
|
||||
|
||||
if (RI0)
|
||||
{
|
||||
EA = 0;
|
||||
if (uart0_RxCount != MAX_RX_UART0_BUF_SIZE)
|
||||
{
|
||||
uart0_RxBuf[uart0_RxHead] = SBUF0;
|
||||
|
||||
if (uart0_Mode & BIT1)
|
||||
{
|
||||
parity = UART_ParityChk((unsigned char)uart0_RxBuf[uart0_RxHead]);
|
||||
if (RB08 != parity)
|
||||
P3 = 0xE7;
|
||||
}
|
||||
|
||||
uart0_RxCount++;
|
||||
uart0_RxHead++;
|
||||
uart0_RxHead &= MAX_RX_UART0_MASK;
|
||||
}
|
||||
RI0 = 0;
|
||||
EA = 1;
|
||||
} /* End of if(RI0) */
|
||||
|
||||
if (TI0)
|
||||
{
|
||||
EA = 0;
|
||||
|
||||
uart0_TxTail++;
|
||||
uart0_TxTail &= MAX_TX_UART0_MASK;
|
||||
uart0_TxCount--;
|
||||
if (uart0_TxCount > 0)
|
||||
{
|
||||
SBUF0 = uart0_TxBuf[uart0_TxTail];
|
||||
|
||||
if (uart0_Mode & BIT1)
|
||||
{
|
||||
parity = UART_ParityChk((unsigned char)uart0_TxBuf[uart0_TxTail]);
|
||||
if (parity)
|
||||
TB08 = 1;
|
||||
else
|
||||
TB08 = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
uart0_TxFlag = 0;
|
||||
|
||||
TI0 = 0;
|
||||
EA = 1;
|
||||
|
||||
} /* End of if(TI0) */
|
||||
|
||||
} /* End of UART_Int */
|
||||
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* static void uart0_Init(void)
|
||||
* Purpose : Setting operation mode of UART0 and initiating the global values.
|
||||
* Params : none
|
||||
* Returns : none
|
||||
* Note : none
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
static void uart0_Init(void)
|
||||
{
|
||||
unsigned char sysClk = 0;
|
||||
unsigned int i;
|
||||
|
||||
uart0_TxHead = 0;
|
||||
uart0_TxTail = 0;
|
||||
uart0_TxCount = 0;
|
||||
uart0_TxFlag = 0;
|
||||
uart0_RxHead = 0;
|
||||
uart0_RxTail = 0;
|
||||
uart0_RxCount = 0;
|
||||
for (i=0 ; i<MAX_TX_UART0_BUF_SIZE ; i++)
|
||||
uart0_TxBuf[i] = 0;
|
||||
for (i=0 ; i<MAX_RX_UART0_BUF_SIZE ; i++)
|
||||
uart0_RxBuf[i] = 0;
|
||||
|
||||
// Initialize TIMER1 for standard 8051 UART clock
|
||||
PCON = 0x80; // Disable BaudRate doubler.
|
||||
SM01 = 1; // Use serial port 0 in mode 1 with 8-bits data.
|
||||
REN0 = 1; // Enable UART0 receiver.
|
||||
TMOD = 0x20; // Use timer 1 in mode 2, 8-bit counter with auto-reload.
|
||||
uart0_Mode = 1;
|
||||
|
||||
sysClk = CSREPR & 0xC0;
|
||||
switch (sysClk)
|
||||
{
|
||||
case SCS_100M :
|
||||
TH1 = 0xE4; // Baud rate = 9600 @ 100MHz.
|
||||
break;
|
||||
case SCS_50M :
|
||||
TH1 = 0xF9; // Baud rate = 9600 @ 50MHz.
|
||||
break;
|
||||
case SCS_25M :
|
||||
TH1 = 0xF9; // Baud rate = 9600 @ 25MHz.
|
||||
break;
|
||||
default :
|
||||
TH1 = 0xF9; // Baud rate = 9600 @ 25MHz.
|
||||
break;
|
||||
}
|
||||
|
||||
ES0 = 1; // Enable serial port Interrupt request
|
||||
TR1 = 1; // Run Timer 1
|
||||
TI0 = 0;
|
||||
|
||||
} /* End of UART_Init */
|
||||
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* static signed char uart0_PutChar(signed char c)
|
||||
* Purpose : UART0 output function. This function puts one byte data into the
|
||||
* software character buffer.
|
||||
* Params : c - one byte character.
|
||||
* Returns : c - one byte character.
|
||||
* Note : none
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
static signed char uart0_PutChar(signed char c)
|
||||
{
|
||||
unsigned int count = 0;
|
||||
|
||||
if (c == 0xa)
|
||||
{
|
||||
do
|
||||
{
|
||||
EA = 0;
|
||||
count = uart0_TxCount;
|
||||
EA = 1;
|
||||
} while (count == MAX_TX_UART0_BUF_SIZE);
|
||||
uart0_TxBuf[uart0_TxHead] = 0xd;
|
||||
EA = 0;
|
||||
uart0_TxCount++;
|
||||
EA = 1;
|
||||
uart0_TxHead++;
|
||||
uart0_TxHead &= MAX_TX_UART0_MASK;
|
||||
}
|
||||
do
|
||||
{
|
||||
EA = 0;
|
||||
count = uart0_TxCount;
|
||||
EA = 1;
|
||||
} while (count == MAX_TX_UART0_BUF_SIZE);
|
||||
uart0_TxBuf[uart0_TxHead] = c;
|
||||
EA = 0;
|
||||
uart0_TxCount++;
|
||||
EA = 1;
|
||||
uart0_TxHead++;
|
||||
uart0_TxHead &= MAX_TX_UART0_MASK;
|
||||
|
||||
if (!uart0_TxFlag)
|
||||
{
|
||||
uart0_TxFlag = 1;
|
||||
SBUF0 = uart0_TxBuf[uart0_TxTail];
|
||||
}
|
||||
|
||||
|
||||
return c;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* static signed char uart0_GetKey(void)
|
||||
* Purpose : UART0 input function. This function replies one byte data from the
|
||||
* software character buffer.
|
||||
* Params : none
|
||||
* Returns : c - one byte character.
|
||||
* Note : none
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
static signed char uart0_GetKey (void)
|
||||
{
|
||||
/* NAMING CONSTANT DECLARATIONS */
|
||||
|
||||
/* LOCAL VARIABLE DECLARATIONS */
|
||||
signed char c = 0;
|
||||
/* BODY */
|
||||
while(uart0_RxCount == 0);
|
||||
EA = 0;
|
||||
uart0_RxCount--;
|
||||
EA = 1;
|
||||
c = uart0_RxBuf[uart0_RxTail];
|
||||
uart0_RxTail++;
|
||||
uart0_RxTail &= MAX_RX_UART0_MASK;
|
||||
return c;
|
||||
}
|
||||
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* static signed char uart0_NoBlockGetkey(void)
|
||||
* Purpose : UART0 input function. This function replies one byte data from the
|
||||
* software character buffer. But it only check the buffer one time.
|
||||
* If no data, it will reply a FALSE condition.
|
||||
* Params : none
|
||||
* Returns : c - one byte character.
|
||||
* Note : none
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
static signed char UART0_NoBlockGetkey (void)
|
||||
{
|
||||
char c = 0;
|
||||
|
||||
if (uart0_RxCount !=0 )
|
||||
{
|
||||
EA = 0;
|
||||
uart0_RxCount--;
|
||||
EA = 1;
|
||||
c = uart0_RxBuf[uart0_RxTail];
|
||||
uart0_RxTail++;
|
||||
uart0_RxTail &= MAX_RX_UART0_MASK;
|
||||
return c;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if UART1_ENABLE
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* static void UART1_ISR(void)
|
||||
* Purpose : UART1 interrupt service routine. For sending out, it puts data
|
||||
* from software buffer into hardware serial buffer register (SBUF1).
|
||||
* For receiving, it gets data from hardware serial buffer register
|
||||
* (SBUF1) and stores into software buffer.
|
||||
* Params : none
|
||||
* Returns : none
|
||||
* Note : none
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
uart1_ISR(void) __interrupt 6 __using 2
|
||||
{
|
||||
unsigned char parity = 0;
|
||||
|
||||
if (RI1)
|
||||
{
|
||||
EA = 0;
|
||||
if (uart1_RxCount != MAX_RX_UART1_BUF_SIZE)
|
||||
{
|
||||
uart1_RxBuf[uart1_RxHead] = SBUF1;
|
||||
|
||||
if (uart1_Mode & BIT1)
|
||||
{
|
||||
parity = UART_ParityChk((unsigned char)uart1_RxBuf[uart1_RxHead]);
|
||||
if (RB18 != parity)
|
||||
P3 = 0xE7;
|
||||
}
|
||||
|
||||
uart1_RxCount++;
|
||||
uart1_RxHead++;
|
||||
uart1_RxHead &= MAX_RX_UART1_MASK;
|
||||
}
|
||||
RI1 = 0;
|
||||
EA = 1;
|
||||
} /* End of if(RI0) */
|
||||
|
||||
if (TI1)
|
||||
{
|
||||
EA = 0;
|
||||
|
||||
uart1_TxTail++;
|
||||
uart1_TxTail &= MAX_TX_UART1_MASK;
|
||||
uart1_TxCount--;
|
||||
if (uart1_TxCount > 0)
|
||||
{
|
||||
SBUF1 = uart1_TxBuf[uart1_TxTail];
|
||||
|
||||
if (uart1_Mode & BIT1)
|
||||
{
|
||||
parity = UART_ParityChk((unsigned char)uart1_TxBuf[uart1_TxTail]);
|
||||
if (parity)
|
||||
TB18 = 1;
|
||||
else
|
||||
TB18 = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
uart1_TxFlag = 0;
|
||||
|
||||
TI1 = 0;
|
||||
EA = 1;
|
||||
|
||||
} /* End of if(TI0) */
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* static void uart1_Init(void)
|
||||
* Purpose : Setting operation mode of UART1 and initiating the global values.
|
||||
* Params : none
|
||||
* Returns : none
|
||||
* Note : none
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
static void uart1_Init(void)
|
||||
{
|
||||
unsigned char sysClk = 0;
|
||||
unsigned int i;
|
||||
|
||||
uart1_TxHead = 0;
|
||||
uart1_TxTail = 0;
|
||||
uart1_TxCount = 0;
|
||||
uart1_TxFlag = 0;
|
||||
uart1_RxHead = 0;
|
||||
uart1_RxTail = 0;
|
||||
uart1_RxCount = 0;
|
||||
for (i=0 ; i<MAX_TX_UART1_BUF_SIZE ; i++)
|
||||
uart1_TxBuf[i] = 0;
|
||||
for (i=0 ; i<MAX_RX_UART1_BUF_SIZE ; i++)
|
||||
uart1_RxBuf[i] = 0;
|
||||
|
||||
// Initialize TIMER1 for standard 8051 UART clock
|
||||
PCON = 0; // Disable BaudRate doubler.
|
||||
SM10 = 0;
|
||||
SM11 = 1; // Use serial port 1 in mode 1 with 8-bits data.
|
||||
REN1 = 1; // Enable UART1 receiver.
|
||||
TMOD = 0x20; // Use timer 1 in mode 2, 8-bit counter with auto-reload.
|
||||
uart1_Mode = 1;
|
||||
|
||||
sysClk = CSREPR & 0xC0;
|
||||
switch (sysClk)
|
||||
{
|
||||
case SCS_100M :
|
||||
TH1 = 0xE4; // Baud rate = 9600 @ 100MHz.
|
||||
break;
|
||||
case SCS_50M :
|
||||
TH1 = 0xF2; // Baud rate = 9600 @ 50MHz.
|
||||
break;
|
||||
case SCS_25M :
|
||||
TH1 = 0xF9; // Baud rate = 9600 @ 25MHz.
|
||||
break;
|
||||
default :
|
||||
TH1 = 0xF9; // Baud rate = 9600 @ 25MHz.
|
||||
break;
|
||||
}
|
||||
|
||||
ES1 = 1; // Enable serial port Interrupt request
|
||||
TR1 = 1; // Run Timer 1
|
||||
TI1 = 0;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* static signed char uart1_PutChar(signed char c)
|
||||
* Purpose : UART1 output function. This function puts one byte data into the
|
||||
* software character buffer.
|
||||
* Params : c - one byte character.
|
||||
* Returns : c - one byte character.
|
||||
* Note : none
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
static signed char uart1_PutChar(signed char c)
|
||||
{
|
||||
unsigned int count = 0;
|
||||
|
||||
if (c == 0xa)
|
||||
{
|
||||
do
|
||||
{
|
||||
EA = 0;
|
||||
count = uart1_TxCount;
|
||||
EA = 1;
|
||||
} while (count == MAX_TX_UART1_BUF_SIZE);
|
||||
uart1_TxBuf[uart1_TxHead] = 0xd;
|
||||
EA = 0;
|
||||
uart1_TxCount++;
|
||||
EA = 1;
|
||||
uart1_TxHead++;
|
||||
uart1_TxHead &= MAX_TX_UART1_MASK;
|
||||
}
|
||||
do
|
||||
{
|
||||
EA = 0;
|
||||
count = uart1_TxCount;
|
||||
EA = 1;
|
||||
} while (count == MAX_TX_UART1_BUF_SIZE);
|
||||
uart1_TxBuf[uart1_TxHead] = c;
|
||||
EA = 0;
|
||||
uart1_TxCount++;
|
||||
EA = 1;
|
||||
uart1_TxHead++;
|
||||
uart1_TxHead &= MAX_TX_UART1_MASK;
|
||||
|
||||
if (!uart1_TxFlag)
|
||||
{
|
||||
uart1_TxFlag = 1;
|
||||
SBUF1 = uart1_TxBuf[uart1_TxTail];
|
||||
}
|
||||
|
||||
return c;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* static signed char uart1_GetKey(void)
|
||||
* Purpose : UART1 input function. This function replies one byte data from the
|
||||
* software character buffer.
|
||||
* Params : none
|
||||
* Returns : c - one byte character.
|
||||
* Note : none
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
static signed char uart1_GetKey (void)
|
||||
{
|
||||
/* NAMING CONSTANT DECLARATIONS */
|
||||
|
||||
/* LOCAL VARIABLE DECLARATIONS */
|
||||
signed char c;
|
||||
/* BODY */
|
||||
while(uart1_RxCount==0);
|
||||
EA = 0;
|
||||
uart1_RxCount--;
|
||||
EA = 1;
|
||||
c = uart1_RxBuf[uart1_RxTail];
|
||||
uart1_RxTail++;
|
||||
uart1_RxTail &= MAX_RX_UART1_MASK;
|
||||
return c;
|
||||
}
|
||||
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* static signed char uart1_NoBlockGetkey(void)
|
||||
* Purpose : UART1 input function. This function replies one byte data from the
|
||||
* software character buffer. But it only check the buffer one time.
|
||||
* If no data, it will reply a FALSE condition.
|
||||
* Params : none
|
||||
* Returns : c - one byte character.
|
||||
* Note : none
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
static signed char uart1_NoBlockGetkey (void)
|
||||
{
|
||||
char c = 0;
|
||||
|
||||
if (uart1_RxCount !=0 )
|
||||
{
|
||||
EA = 0;
|
||||
uart1_RxCount--;
|
||||
EA = 1;
|
||||
c = uart1_RxBuf[uart1_RxTail];
|
||||
uart1_RxTail++;
|
||||
uart1_RxTail &= MAX_RX_UART1_MASK;
|
||||
return c;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* EXPORTED SUBPROGRAM BODIES */
|
||||
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* signed char _getkey (void)
|
||||
* Purpose : UART getkey function. This function is the entry of getting
|
||||
* characters from software buffer of system's UART ports,
|
||||
* UART0, UART1 and HSUR.
|
||||
* Params : none
|
||||
* Returns : ch - one byte character.
|
||||
* Note : The default UART port is UART0.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
signed char _getkey (void)
|
||||
{
|
||||
signed char ch = 0;
|
||||
|
||||
switch (uartPort)
|
||||
{
|
||||
#if UART0_ENABLE
|
||||
case 0 :
|
||||
ch = uart0_GetKey();
|
||||
break;
|
||||
#endif
|
||||
#if UART1_ENABLE
|
||||
case 1 :
|
||||
ch = uart1_GetKey();
|
||||
break;
|
||||
#endif
|
||||
#if HSUR_ENABLE
|
||||
case 2 :
|
||||
ch = HSUR_GetChar();
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
return ch;
|
||||
}
|
||||
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* signed char putchar(signed char c)
|
||||
* Purpose : UART putchar function. This function is the entry of putting
|
||||
* characters into software buffer of system's UART ports,
|
||||
* UART0, UART1 and HSUR.
|
||||
* Params : c - one byte character to be put.
|
||||
* Returns : ch - the same character to be replied.
|
||||
* Note : The default UART port is UART0.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
signed char putchar(signed char c)
|
||||
{
|
||||
signed char ch = 0;
|
||||
|
||||
switch (uartPort)
|
||||
{
|
||||
#if UART0_ENABLE
|
||||
case 0 :
|
||||
ch = uart0_PutChar(c);
|
||||
break;
|
||||
#endif
|
||||
#if UART1_ENABLE
|
||||
case 1 :
|
||||
ch = uart1_PutChar(c);
|
||||
break;
|
||||
#endif
|
||||
#if HSUR_ENABLE
|
||||
case 2 :
|
||||
ch = HSUR_PutChar(c);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
return ch;
|
||||
}
|
||||
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* void UART_Init(void)
|
||||
* Purpose : UART initial function. It will call a real initial function
|
||||
* corresponding to the used UART port.
|
||||
* Params : none
|
||||
* Returns : none
|
||||
* Note : none
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
void UART_Init(void)
|
||||
{
|
||||
switch (uartPort)
|
||||
{
|
||||
#if UART0_ENABLE
|
||||
case 0 :
|
||||
uart0_Init();
|
||||
break;
|
||||
#endif
|
||||
#if UART1_ENABLE
|
||||
case 1 :
|
||||
uart1_Init();
|
||||
break;
|
||||
#endif
|
||||
#if HSUR_ENABLE
|
||||
case 2 :
|
||||
HSUR_Init();
|
||||
HSUR_Setup(0x0060, (UR2_CHAR_8|UR2_STOP_10), (UR2_RDI_ENB|UR2_RLSI_ENB),
|
||||
(UR2_FIFO_MODE|UR2_RXFIFO_RST|UR2_TXFIFO_RST|UR2_TRIG_08), UR2_RTS);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* signed char NOBLK_getkey (void)
|
||||
* Purpose : UART no blocking getkey function with one checked. This function
|
||||
* is the entry of getting characters from software buffer of
|
||||
* system's UART ports, UART0, UART1 and HSUR.
|
||||
* Params : none
|
||||
* Returns : ch - one byte character.
|
||||
* Note : The default UART port is UART0.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
signed char NOBLK_getkey (void)
|
||||
{
|
||||
signed char c = 0;
|
||||
|
||||
switch (uartPort)
|
||||
{
|
||||
#if UART0_ENABLE
|
||||
case 0 :
|
||||
c = UART0_NoBlockGetkey();
|
||||
break;
|
||||
#endif
|
||||
#if UART1_ENABLE
|
||||
case 1 :
|
||||
c = uart1_NoBlockGetkey();
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* BOOL UART_ParityChk(signed char checkByte)
|
||||
* Purpose : UART parity checked function in one byte transfer.
|
||||
* Params : checkByte - one byte character.
|
||||
* Returns : TRUE - odd parity ; FALSE - even parity.
|
||||
* Note : none
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
BOOL UART_ParityChk(signed char checkByte)
|
||||
{
|
||||
unsigned char oneNum = 0;
|
||||
unsigned int i;
|
||||
|
||||
oneNum = 0;
|
||||
for (i=0 ; i<=7 ; i++)
|
||||
{
|
||||
if (checkByte & (BIT0<<i))
|
||||
{
|
||||
oneNum ++;
|
||||
}
|
||||
}
|
||||
if ((oneNum % 2) == 0)
|
||||
return FALSE; // if '1' number is even, return 0
|
||||
else
|
||||
return TRUE; // if '1' number is odd, return 1
|
||||
}
|
||||
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* void UART0_SetMode(unsigned char mode)
|
||||
* Purpose : Setting operation mode of UART0.
|
||||
* Params : mode - operation mode (0~3).
|
||||
* Returns : none
|
||||
* Note : none
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
#if UART0_ENABLE
|
||||
void UART0_SetMode(unsigned char mode)
|
||||
{
|
||||
uart0_Mode = mode;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* void UART1_SetMode(unsigned char mode)
|
||||
* Purpose : Setting operation mode of UART0.
|
||||
* Params : mode - operation mode (0~3).
|
||||
* Returns : none
|
||||
* Note : none
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
#if UART1_ENABLE
|
||||
void UART1_SetMode(unsigned char mode)
|
||||
{
|
||||
uart1_Mode = mode;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* BOOL UART_SetPort(unsigned char portNum)
|
||||
* Purpose : Setting which UART port will be used.
|
||||
* Params : portNum - uart port number (0~2).
|
||||
* Returns : none
|
||||
* Note : none
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
BOOL UART_SetPort(unsigned char portNum)
|
||||
{
|
||||
uartPort = portNum & 0x03;
|
||||
UART_Init();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* void PMM_Uart0Init(void)
|
||||
* Purpose : Initiating the UART0 to work in power management mode.
|
||||
* Params : none
|
||||
* Returns : none
|
||||
* Note : none
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
#if UART_PMM_ENABLE
|
||||
void PMM_Uart0Init(void)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
uart0_TxHead = 0;
|
||||
uart0_TxTail = 0;
|
||||
uart0_TxCount = 0;
|
||||
uart0_TxFlag = 0;
|
||||
uart0_RxHead = 0;
|
||||
uart0_RxTail = 0;
|
||||
uart0_RxCount = 0;
|
||||
for (i=0 ; i<MAX_TX_UART0_BUF_SIZE ; i++)
|
||||
uart0_TxBuf[i] = 0;
|
||||
for (i=0 ; i<MAX_RX_UART0_BUF_SIZE ; i++)
|
||||
uart0_RxBuf[i] = 0;
|
||||
|
||||
// Initialize TIMER1 for standard 8051 UART clock
|
||||
PCON = BIT7; // Enable BaudRate doubler.
|
||||
SM01 = 1; // Use serial port 0 in mode 1 with 8-bits data.
|
||||
REN0 = 1; // Enable UART0 receiver.
|
||||
TMOD = 0x20; // Use timer 1 in mode 2, 8-bit counter with auto-reload.
|
||||
|
||||
TH1 = 0xFE; // Baud rate = 1200 @ 25MHz.
|
||||
|
||||
ES0 = 1; // Enable serial port Interrupt request
|
||||
TR1 = 1; // Run Timer 1
|
||||
TI0 = 0;
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* End of uart.c */
|
74
Asixtool/asix-testcode/uart/uart.h
Normal file
74
Asixtool/asix-testcode/uart/uart.h
Normal file
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
******************************************************************************
|
||||
* Copyright (c) 2005 ASIX Electronic Corporation All rights reserved.
|
||||
*
|
||||
* This is unpublished proprietary source code of ASIX Electronic Corporation
|
||||
*
|
||||
* The copyright notice above does not evidence any actual or intended
|
||||
* publication of such source code.
|
||||
******************************************************************************
|
||||
*/
|
||||
/*================================================================================
|
||||
* Module Name : uart.h
|
||||
* Purpose : A header file of uart.c includes UART0 and UART1 module.
|
||||
* Author : Robin Lee
|
||||
* Date : 2006-01-10
|
||||
* Notes :
|
||||
* $Log: uart.h,v $
|
||||
* Revision 1.1 2006/04/07 11:39:14 robin6633
|
||||
* no message
|
||||
*
|
||||
*================================================================================
|
||||
*/
|
||||
|
||||
#ifndef __UART_H__
|
||||
#define __UART_H__
|
||||
|
||||
#include "../types_ax110xx.h"
|
||||
|
||||
#define UART0_ENABLE 1 // 1:enable UART0 ; 0:disable UART0
|
||||
#define UART1_ENABLE 0 // 1:enable UART1 ; 0:disable UART1
|
||||
#define HSUR_ENABLE 0 // 1:enable Hihg Speed UART ; 0:disable Hihg Speed UART
|
||||
#define UART_PMM_ENABLE 0 // 1:use UART in PMM mode ; 0:disable
|
||||
|
||||
|
||||
/* NAMING CONSTANT DECLARATIONS */
|
||||
#if UART0_ENABLE
|
||||
#define MAX_TX_UART0_BUF_SIZE 512
|
||||
#define MAX_TX_UART0_MASK (MAX_TX_UART0_BUF_SIZE - 1)
|
||||
#define MAX_RX_UART0_BUF_SIZE 512
|
||||
#define MAX_RX_UART0_MASK (MAX_RX_UART0_BUF_SIZE - 1)
|
||||
#endif
|
||||
|
||||
#if UART1_ENABLE
|
||||
#define MAX_TX_UART1_BUF_SIZE 512
|
||||
#define MAX_TX_UART1_MASK (MAX_TX_UART1_BUF_SIZE - 1)
|
||||
#define MAX_RX_UART1_BUF_SIZE 512
|
||||
#define MAX_RX_UART1_MASK (MAX_RX_UART1_BUF_SIZE - 1)
|
||||
#endif
|
||||
|
||||
/* GLOBAL VARIABLES */
|
||||
#if UART0_ENABLE
|
||||
extern unsigned int uart0_RxCount;
|
||||
#endif
|
||||
|
||||
#if UART1_ENABLE
|
||||
extern unsigned int uart1_RxCount;
|
||||
#endif
|
||||
|
||||
|
||||
/* EXPORTED SUBPROGRAM SPECIFICATIONS */
|
||||
void UART_Init(void);
|
||||
signed char putchar(signed char);
|
||||
signed char _getkey(void);
|
||||
signed char NOBLK_getkey(void);
|
||||
BOOL UART_ParityChk(signed char checkbyte);
|
||||
void UART0_SetMode(unsigned char mode);
|
||||
void UART1_SetMode(unsigned char mode);
|
||||
BOOL UART_SetPort(unsigned char portNum);
|
||||
void PMM_Uart0Init(void);
|
||||
|
||||
|
||||
#endif /* End of __UART_H__ */
|
||||
|
||||
/* End of uart.h */
|
2
Asixtool/sdcc/README
Normal file
2
Asixtool/sdcc/README
Normal file
|
@ -0,0 +1,2 @@
|
|||
See https://sourceforge.net/projects/sdcc/forums/forum/1864/topic/1881955
|
||||
|
103
Asixtool/sdcc/ax110xx.patch
Normal file
103
Asixtool/sdcc/ax110xx.patch
Normal file
|
@ -0,0 +1,103 @@
|
|||
diff -crB sdcc/ChangeLog sdcc-asix/ChangeLog
|
||||
*** sdcc/ChangeLog 2007-11-17 20:23:59.000000000 +0100
|
||||
--- sdcc-asix/ChangeLog 2007-11-30 05:16:07.136379144 +0100
|
||||
***************
|
||||
*** 1,3 ****
|
||||
--- 1,8 ----
|
||||
+ 2007-11-30 Christian Klippel <ck AT mamalala.net>
|
||||
+
|
||||
+ * src/ds390/main.c: added ax110xx target to ds390 (option --use-asix)
|
||||
+ * src/SDCCglobl.h: added ax110xx target to ds390 (option --use-asix)
|
||||
+
|
||||
2007-11-17 Raphael Neider <rneider AT web.de>
|
||||
|
||||
* src/pic/main.c (_asmCmd): include debug arguments (-g as $3)
|
||||
diff -crB sdcc/src/ds390/main.c sdcc-asix/src/ds390/main.c
|
||||
*** sdcc/src/ds390/main.c 2007-06-18 20:24:42.000000000 +0200
|
||||
--- sdcc-asix/src/ds390/main.c 2007-11-30 05:12:58.453530081 +0100
|
||||
***************
|
||||
*** 21,26 ****
|
||||
--- 21,27 ----
|
||||
#define OPTION_STACK_8BIT "--stack-8bit"
|
||||
#define OPTION_FLAT24_MODEL "--model-flat24"
|
||||
#define OPTION_STACK_SIZE "--stack-size"
|
||||
+ #define OPTION_USE_ASIX "--use-asix"
|
||||
|
||||
static OPTION _ds390_options[] =
|
||||
{
|
||||
***************
|
||||
*** 33,38 ****
|
||||
--- 34,40 ----
|
||||
{ 0, "--use-accelerator", &options.useAccelerator, "generate code for ds390 arithmetic accelerator"},
|
||||
{ 0, "--protect-sp-update", &options.protect_sp_update, "will disable interrupts during ESP:SP updates"},
|
||||
{ 0, "--parms-in-bank1", &options.parms_in_bank1, "use Bank1 for parameter passing"},
|
||||
+ { 0, OPTION_USE_ASIX, &options.use_asix, "generate code for the asix chip" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
***************
|
||||
*** 253,258 ****
|
||||
--- 255,265 ----
|
||||
fputs ("ma\t=\t0xD3\n", of);
|
||||
fputs ("mb\t=\t0xD4\n", of);
|
||||
fputs ("mc\t=\t0xD5\n", of);
|
||||
+ if(options.use_asix)
|
||||
+ {
|
||||
+ fputs ("ta\t=\t0xEB\n", of);
|
||||
+ fputs ("acon\t=\t0x9D\n", of);
|
||||
+ }
|
||||
fputs ("F1\t=\t0xD1\t; user flag\n", of);
|
||||
if (options.parms_in_bank1) {
|
||||
int i ;
|
||||
***************
|
||||
*** 290,295 ****
|
||||
--- 297,311 ----
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
+ if(options.use_asix)
|
||||
+ {
|
||||
+ fprintf (stderr,
|
||||
+ "*** warning: targeting for asix\n");
|
||||
+ dbuf_printf (oBuf, ".flat24 off\n");
|
||||
+ dbuf_printf (oBuf, "\tljmp\t__reset_vect\n");
|
||||
+ dbuf_printf (oBuf, ".flat24 on\n");
|
||||
+ }
|
||||
+ else
|
||||
dbuf_printf (oBuf, "\tajmp\t__reset_vect\n");
|
||||
|
||||
/* now for the other interrupts */
|
||||
***************
|
||||
*** 305,310 ****
|
||||
--- 321,336 ----
|
||||
}
|
||||
}
|
||||
|
||||
+ if(options.use_asix)
|
||||
+ {
|
||||
+ dbuf_printf (oBuf, ".flat24 off\n");
|
||||
+ dbuf_printf (oBuf, "__reset_vect:\n");
|
||||
+ dbuf_printf (oBuf, "\tmov ta,#0xAA\n");
|
||||
+ dbuf_printf (oBuf, "\tmov ta,#0x55\n");
|
||||
+ dbuf_printf (oBuf, "\tmov acon,#0x02\n");
|
||||
+ dbuf_printf (oBuf, ".flat24 on\n");
|
||||
+ }
|
||||
+ else
|
||||
dbuf_printf (oBuf, "__reset_vect:\n\tljmp\t__sdcc_gsinit_startup\n");
|
||||
|
||||
return TRUE;
|
||||
diff -crB sdcc/src/SDCCglobl.h sdcc-asix/src/SDCCglobl.h
|
||||
*** sdcc/src/SDCCglobl.h 2007-07-27 22:23:22.000000000 +0200
|
||||
--- sdcc-asix/src/SDCCglobl.h 2007-11-30 05:06:54.000000000 +0100
|
||||
***************
|
||||
*** 291,296 ****
|
||||
--- 291,297 ----
|
||||
int unsigned_char; /* use unsigned for char without signed/unsigned modifier */
|
||||
char *code_seg; /* segment name to use instead of CSEG */
|
||||
char *const_seg; /* segment name to use instead of CONST */
|
||||
+ bool use_asix; /* since xram_size=0 is a possibility */
|
||||
/* sets */
|
||||
set *calleeSavesSet; /* list of functions using callee save */
|
||||
set *excludeRegsSet; /* registers excluded from saving */
|
||||
|
||||
|
37
Asixtool/trunk/Kopie von Makefile
Normal file
37
Asixtool/trunk/Kopie von Makefile
Normal file
|
@ -0,0 +1,37 @@
|
|||
###############################################################
|
||||
#####
|
||||
##### Makefile for asixtool
|
||||
#####
|
||||
###############################################################
|
||||
|
||||
###############################################################
|
||||
#####
|
||||
##### PATHS (default installation)
|
||||
#####
|
||||
###############################################################
|
||||
|
||||
INSTALLDIR_BIN=/usr/local/bin
|
||||
|
||||
-include Makefile.local
|
||||
|
||||
BASE = D:\Programmieren\Cygwin
|
||||
INCLUDEPATH = $(BASE)\usr\include
|
||||
##LIBPATH = $(BASE)\lib\gcc\i686-pc-cygwin\3.4.4\include
|
||||
|
||||
###############################################################
|
||||
#####
|
||||
##### Do the whole shabang
|
||||
#####
|
||||
###############################################################
|
||||
|
||||
all: asixtool
|
||||
|
||||
asixtool: asix_serial.c asix_serial.h bootcom.c bootcom.h infohelper.h infohelper.c main.c
|
||||
$(BASE)/bin/gcc.exe -Os -Wall asix_serial.c bootcom.c infohelper.c main.c -o asixtool
|
||||
strip asixtool
|
||||
|
||||
|
||||
clean:
|
||||
$(RM) *.o *~ asixtool
|
||||
|
||||
### EOF
|
674
Asixtool/trunk/LICENSE
Normal file
674
Asixtool/trunk/LICENSE
Normal file
|
@ -0,0 +1,674 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
33
Asixtool/trunk/Makefile
Normal file
33
Asixtool/trunk/Makefile
Normal file
|
@ -0,0 +1,33 @@
|
|||
###############################################################
|
||||
#####
|
||||
##### Makefile for asixtool
|
||||
#####
|
||||
###############################################################
|
||||
|
||||
###############################################################
|
||||
#####
|
||||
##### PATHS (default installation)
|
||||
#####
|
||||
###############################################################
|
||||
|
||||
INSTALLDIR_BIN=/usr/local/bin
|
||||
|
||||
-include Makefile.local
|
||||
|
||||
###############################################################
|
||||
#####
|
||||
##### Do the whole shabang
|
||||
#####
|
||||
###############################################################
|
||||
|
||||
all: asixtool
|
||||
|
||||
asixtool: asix_serial.c asix_serial.h bootcom.c bootcom.h infohelper.h infohelper.c main.c
|
||||
gcc -Os -Wall asix_serial.c bootcom.c infohelper.c main.c -o asixtool
|
||||
strip asixtool
|
||||
|
||||
|
||||
clean:
|
||||
$(RM) *.o *~ asixtool
|
||||
|
||||
### EOF
|
237
Asixtool/trunk/asix_serial.c
Normal file
237
Asixtool/trunk/asix_serial.c
Normal file
|
@ -0,0 +1,237 @@
|
|||
/*
|
||||
asix-serial.c - serial port routines (host) to access the asix chip
|
||||
Copyright (C) 2007 Ch. Klippel <ck@mamalala.net>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "asix_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 921600:
|
||||
cfsetispeed(&term,B921600);
|
||||
cfsetospeed(&term,B921600);
|
||||
break;
|
||||
default:
|
||||
cfsetispeed(&term,B115200);
|
||||
cfsetospeed(&term,B115200);
|
||||
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, unsigned int speed)
|
||||
{
|
||||
|
||||
serialDev=open(dev,O_RDWR);
|
||||
if(serialDev<0) {
|
||||
printf("cannot acces %s\n",dev);
|
||||
return serialDev;
|
||||
}
|
||||
|
||||
setDTR(0);
|
||||
setRTS(0);
|
||||
|
||||
tcgetattr(serialDev,&term);
|
||||
|
||||
setBaud(speed);
|
||||
|
||||
term.c_cflag = (term.c_cflag & ~CSIZE) | CS8 | PARENB;
|
||||
term.c_cflag |= CLOCAL | CREAD;
|
||||
|
||||
term.c_cflag &= ~CSTOPB;
|
||||
term.c_iflag=IGNBRK;
|
||||
|
||||
term.c_iflag |= IXON | IXOFF;
|
||||
|
||||
term.c_lflag=0;
|
||||
|
||||
term.c_oflag=0;
|
||||
|
||||
|
||||
setTimeout(2);
|
||||
|
||||
setFlow(0);
|
||||
|
||||
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;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
30
Asixtool/trunk/asix_serial.h
Normal file
30
Asixtool/trunk/asix_serial.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
asix-serial.h - serial port routines (host) to access the asix chip
|
||||
Copyright (C) 2007 Ch. Klippel <ck@mamalala.net>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef ASIX_SERIAL_H
|
||||
#define ASIX_DERIAL_H
|
||||
|
||||
int openSerial(char *dev, unsigned int speed);
|
||||
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
|
389
Asixtool/trunk/bootcom.c
Normal file
389
Asixtool/trunk/bootcom.c
Normal file
|
@ -0,0 +1,389 @@
|
|||
/*
|
||||
bootcom.c - com routines for the asix on.chip bootloader
|
||||
Copyright (C) 2007 Ch. Klippel <ck@mamalala.net>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "bootcom.h"
|
||||
#include "stdio.h"
|
||||
#include "asix_serial.h"
|
||||
#include "infohelper.h"
|
||||
#include "fcntl.h"
|
||||
#include "unistd.h"
|
||||
|
||||
#define MAXSECT 11
|
||||
|
||||
extern char verbosity;
|
||||
char buf[5];
|
||||
char fbuf[0x080000];
|
||||
int do_erase;
|
||||
|
||||
unsigned int sectors[MAXSECT+1] = {
|
||||
0x00000,
|
||||
0x04000,
|
||||
0x06000,
|
||||
0x08000,
|
||||
0x10000,
|
||||
0x20000,
|
||||
0x30000,
|
||||
0x40000,
|
||||
0x50000,
|
||||
0x60000,
|
||||
0x70000,
|
||||
0x80000
|
||||
};
|
||||
|
||||
int findSect(unsigned long adr)
|
||||
{
|
||||
int secnum = 0;
|
||||
while((sectors[secnum] < adr) && (secnum < MAXSECT))
|
||||
{
|
||||
secnum++;
|
||||
}
|
||||
|
||||
if(sectors[secnum] > adr)
|
||||
return secnum-1;
|
||||
else
|
||||
return secnum;
|
||||
}
|
||||
|
||||
|
||||
void dumpBuf()
|
||||
{
|
||||
printf("%02X %02X %02X %02X %02X\n",(unsigned char)buf[0],(unsigned char)buf[1],(unsigned char)buf[2],(unsigned char)buf[3],(unsigned char)buf[4]);
|
||||
}
|
||||
|
||||
void sendCMD(unsigned char a, unsigned char b, unsigned char c, unsigned char d, unsigned char e)
|
||||
{
|
||||
buf[0] = a;
|
||||
buf[1] = b;
|
||||
buf[2] = c;
|
||||
buf[3] = d;
|
||||
buf[4] = e;
|
||||
sendBuf(5, buf);
|
||||
}
|
||||
int setAccessTime(unsigned char val)
|
||||
{
|
||||
sendCMD(0x81, 0x00, 0x00, 0x00, val);
|
||||
getBuf(1, buf);
|
||||
|
||||
if(buf[0] == val)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int setIntervallTime(unsigned char val)
|
||||
{
|
||||
sendCMD(0x82, 0x00, 0x00, 0x00, val);
|
||||
getBuf(1, buf);
|
||||
|
||||
if(buf[0] == val)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int readFlash(char *name, unsigned int start, unsigned int len)
|
||||
{
|
||||
FILE *outfile;
|
||||
unsigned int ret, count, cdone;
|
||||
unsigned char rollover = 0;
|
||||
|
||||
outfile = fopen(name,"w");
|
||||
|
||||
sendCMD(0x00, 0x00, 0x00, 0x00, 0x00);
|
||||
ret = getBuf(5, buf);
|
||||
cdone = 0;
|
||||
count = start+len;
|
||||
|
||||
printInfoH(1, "bytes to read: ",len);
|
||||
|
||||
for(;start<count;start++)
|
||||
{
|
||||
sendCMD(0x00, start & 0xFF, (start & 0xFF00) >> 8, (start & 0xFF0000) >> 16, 0x00);
|
||||
|
||||
ret = getBuf(1, buf);
|
||||
|
||||
if(ret == 1)
|
||||
{
|
||||
fprintf(outfile, "%c",(unsigned char)buf[0]);
|
||||
fflush(outfile);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("FAIL: %02i - %06X - %02X\n",ret, start, (unsigned char) buf[0]);
|
||||
fprintf(outfile, "%c",(unsigned char)buf[0]);
|
||||
fflush(outfile);
|
||||
}
|
||||
|
||||
cdone++;
|
||||
|
||||
if(rollover == 0)
|
||||
printProgress(0, "reading", cdone, len);
|
||||
|
||||
rollover++;
|
||||
rollover &= 0x3F;
|
||||
}
|
||||
printProgress(0, "reading", cdone, len);
|
||||
fclose(outfile);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void resetFlash(unsigned int start)
|
||||
{
|
||||
sendCMD(0x80, 0x33, 0x03, (start & 0xFF0000) >> 16, 0xF0);
|
||||
getBuf(1, buf);
|
||||
}
|
||||
|
||||
void closeWrite(unsigned int start)
|
||||
{
|
||||
sendCMD(0x80, 0x33, 0x03, (start & 0xFF0000) >> 16, 0x90);
|
||||
getBuf(1, buf);
|
||||
resetFlash(start);
|
||||
}
|
||||
|
||||
int eraseFlash(unsigned int adr)
|
||||
{
|
||||
|
||||
unsigned char base = (adr & 0xFF0000) >> 16;
|
||||
|
||||
printInfoH(1, "erasing flash at ", adr & 0x00FF0000);
|
||||
|
||||
sendCMD(0x80, 0x55, 0x05, base, 0xAA);
|
||||
if(!getBuf(1, buf))
|
||||
{
|
||||
goto bailOut;
|
||||
}
|
||||
|
||||
sendCMD(0x80, 0xAA, 0x02, base, 0x55);
|
||||
if(!getBuf(1, buf))
|
||||
{
|
||||
goto bailOut;
|
||||
}
|
||||
|
||||
sendCMD(0x80, 0x55, 0x05, base, 0x80);
|
||||
if(!getBuf(1, buf))
|
||||
{
|
||||
goto bailOut;
|
||||
}
|
||||
|
||||
sendCMD(0x80, 0x55, 0x05, base, 0xAA);
|
||||
if(!getBuf(1, buf))
|
||||
{
|
||||
goto bailOut;
|
||||
}
|
||||
|
||||
sendCMD(0x80, 0xAA, 0x02, base, 0x55);
|
||||
if(!getBuf(1, buf))
|
||||
{
|
||||
goto bailOut;
|
||||
}
|
||||
|
||||
sendCMD(0x80, 0x55, 0x05, base, 0x10);
|
||||
if(!getBuf(1, buf))
|
||||
{
|
||||
goto bailOut;
|
||||
}
|
||||
|
||||
waitErase:
|
||||
sendCMD(0x00, 0x00, 0x00, base, 0x00);
|
||||
if(!getBuf(1, buf))
|
||||
{
|
||||
goto bailOut1;
|
||||
}
|
||||
if(buf[0] == 0x0A || buf[0] == 0x4E)
|
||||
goto waitErase;
|
||||
if((unsigned char)buf[0] != 0xFF)
|
||||
goto bailOut2;
|
||||
|
||||
printInfoS(1, "successfully erased flash", 0);
|
||||
resetFlash(adr);
|
||||
return 1;
|
||||
|
||||
bailOut:
|
||||
return printError("cant issue chip erase sequence, aborting!");
|
||||
bailOut1:
|
||||
return printError("no response during chip erase active, aborting");
|
||||
bailOut2:
|
||||
return printError("cant erase chip, aborting");
|
||||
}
|
||||
|
||||
|
||||
int eraseSector(unsigned int adr)
|
||||
{
|
||||
|
||||
unsigned char baseH = (adr & 0xFF0000) >> 16;
|
||||
unsigned char baseM = (adr & 0xFF00) >> 8;
|
||||
unsigned char baseL = adr & 0xFF;
|
||||
|
||||
printInfoH(1, "erasing sector at ", adr);
|
||||
|
||||
sendCMD(0x80, 0x55, 0x05, 0x00, 0xAA);
|
||||
if(!getBuf(1, buf))
|
||||
{
|
||||
goto bailOut;
|
||||
}
|
||||
|
||||
sendCMD(0x80, 0xAA, 0x02, 0x00, 0x55);
|
||||
if(!getBuf(1, buf))
|
||||
{
|
||||
goto bailOut;
|
||||
}
|
||||
|
||||
sendCMD(0x80, 0x55, 0x05, 0x00, 0x80);
|
||||
if(!getBuf(1, buf))
|
||||
{
|
||||
goto bailOut;
|
||||
}
|
||||
|
||||
sendCMD(0x80, 0x55, 0x05, 0x00, 0xAA);
|
||||
if(!getBuf(1, buf))
|
||||
{
|
||||
goto bailOut;
|
||||
}
|
||||
|
||||
sendCMD(0x80, 0xAA, 0x02, 0x00, 0x55);
|
||||
if(!getBuf(1, buf))
|
||||
{
|
||||
goto bailOut;
|
||||
}
|
||||
|
||||
sendCMD(0x80, baseL, baseM, baseH, 0x30);
|
||||
if(!getBuf(1, buf))
|
||||
{
|
||||
goto bailOut;
|
||||
}
|
||||
|
||||
waitErase:
|
||||
sendCMD(0x00, baseL, baseM, baseH, 0x00);
|
||||
if(!getBuf(1, buf))
|
||||
{
|
||||
goto bailOut1;
|
||||
}
|
||||
|
||||
if(buf[0] == 0x0A || buf[0] == 0x4E)
|
||||
goto waitErase;
|
||||
|
||||
|
||||
|
||||
if((unsigned char)buf[0] != 0xFF)
|
||||
goto bailOut2;
|
||||
|
||||
printInfoS(1, "successfully erased sector",0);
|
||||
resetFlash(adr);
|
||||
return 1;
|
||||
|
||||
bailOut:
|
||||
return printError("cant issue sector erase sequence");
|
||||
bailOut1:
|
||||
return printError("no response during secttor erase active");
|
||||
bailOut2:
|
||||
return printError("cant erase sector");
|
||||
}
|
||||
|
||||
|
||||
unsigned int writeFlash(char *name, unsigned int start, unsigned int len)
|
||||
{
|
||||
int infile, flen;
|
||||
unsigned int ret, count, cdone;
|
||||
unsigned char rollover = 0;
|
||||
|
||||
sendCMD(0x00, 0x00, 0x00, 0x00, 0x00);
|
||||
ret = getBuf(1, buf);
|
||||
|
||||
infile = open(name,O_RDONLY);
|
||||
flen = read(infile, fbuf, 0x80000);
|
||||
|
||||
if(flen < len)
|
||||
{
|
||||
printInfoH(1, "adjusting number of bytes to ",flen);
|
||||
len = flen;
|
||||
}
|
||||
|
||||
cdone = 0;
|
||||
count = start+len;
|
||||
|
||||
if(do_erase)
|
||||
{
|
||||
unsigned char startsec, endsec;
|
||||
startsec = findSect(start);
|
||||
endsec = findSect(start+len-1);
|
||||
nextsect:
|
||||
if(!eraseSector(sectors[startsec]))
|
||||
{
|
||||
return(printError("error at auto-erase"));
|
||||
}
|
||||
if(startsec != endsec)
|
||||
{
|
||||
startsec++;
|
||||
goto nextsect;
|
||||
}
|
||||
}
|
||||
|
||||
printInfoH(1, "bytes to write: ",len);
|
||||
|
||||
retry:
|
||||
|
||||
sendCMD(0x80, 0x55, 0x05, (start & 0xFF0000) >> 16, 0xAA);
|
||||
ret = getBuf(1, buf);
|
||||
|
||||
sendCMD(0x80, 0xAA, 0x02, (start & 0xFF0000) >> 16, 0x55);
|
||||
ret = getBuf(1, buf);
|
||||
|
||||
sendCMD(0x80, 0x55, 0x05, (start & 0xFF0000) >> 16, 0x20);
|
||||
ret = getBuf(1, buf);
|
||||
|
||||
for(;start<count;start++)
|
||||
{
|
||||
sendCMD(0x80, 0x33, 0x03, (start & 0xFF0000) >> 16, 0xA0);
|
||||
ret = getBuf(1, buf);
|
||||
|
||||
sendCMD(0xC0, start & 0xFF, (start & 0xFF00) >> 8, (start & 0xFF0000) >> 16, (unsigned char) fbuf[cdone]);
|
||||
ret = getBuf(2, buf);
|
||||
|
||||
if(ret == 1)
|
||||
{
|
||||
sleep(1);
|
||||
closeWrite(start);
|
||||
printf("\nretrying\n");
|
||||
goto retry;
|
||||
}
|
||||
|
||||
if((ret != 2))
|
||||
{
|
||||
closeWrite(start);
|
||||
return printError("error during write: short response");
|
||||
}
|
||||
|
||||
if((unsigned char)fbuf[cdone] != (unsigned char)buf[1])
|
||||
{
|
||||
closeWrite(start);
|
||||
return printError("error during write: data mismatch");
|
||||
}
|
||||
|
||||
cdone++;
|
||||
|
||||
if(rollover == 0)
|
||||
printProgress(0, "writing", cdone, len);
|
||||
|
||||
rollover++;
|
||||
rollover &= 0x3F;
|
||||
}
|
||||
printProgress(0, "writing", cdone, len);
|
||||
closeWrite(start);
|
||||
close(infile);
|
||||
return len;
|
||||
}
|
28
Asixtool/trunk/bootcom.h
Normal file
28
Asixtool/trunk/bootcom.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
bootcom.h - com routines for the asix on.chip bootloader
|
||||
Copyright (C) 2007 Ch. Klippel <ck@mamalala.net>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef BOOTCOM_H
|
||||
#define BOOTCOM_H
|
||||
|
||||
int readFlash(char *name, unsigned int start, unsigned int len);
|
||||
unsigned int writeFlash(char *name, unsigned int start, unsigned int len);
|
||||
int eraseFlash(unsigned int adr);
|
||||
int eraseSector(unsigned int adr);
|
||||
|
||||
|
||||
#endif
|
97
Asixtool/trunk/infohelper.c
Normal file
97
Asixtool/trunk/infohelper.c
Normal file
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
infohelper.c - info-display routines (host)
|
||||
Copyright (C) 2007 Ch. Klippel <ck@mamalala.net>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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 int 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 int 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;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
30
Asixtool/trunk/infohelper.h
Normal file
30
Asixtool/trunk/infohelper.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
infohelper.h - info-display routines (host)
|
||||
Copyright (C) 2007 Ch. Klippel <ck@mamalala.net>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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 int val);
|
||||
int printProgress(unsigned char level, char *msg, float cval, float maxval);
|
||||
|
||||
#endif
|
312
Asixtool/trunk/main.c
Normal file
312
Asixtool/trunk/main.c
Normal file
|
@ -0,0 +1,312 @@
|
|||
/*
|
||||
main.c - main program
|
||||
Copyright (C) 2007 Ch. Klippel <ck@mamalala.net>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "stdio.h"
|
||||
#include "asix_serial.h"
|
||||
#include "infohelper.h"
|
||||
#include "fcntl.h"
|
||||
#include "unistd.h"
|
||||
#include <string.h>
|
||||
#include "bootcom.h"
|
||||
|
||||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 1
|
||||
|
||||
extern char verbosity;
|
||||
extern int do_erase;
|
||||
|
||||
unsigned long radr, f0adr, f0len;
|
||||
|
||||
void printHeader(void)
|
||||
{
|
||||
printf("\nasixtool 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: asixtool [-d NAME] [-a [NAME] [-A ADRDESS]] [-e] [-S] [-c] [-N]\n\n");
|
||||
printf(" -d NAME specify serial device, default is /dev/ttyS0\n");
|
||||
printf(" -r NAME specify file to read flash into, default is flash_dump.bin\n");
|
||||
printf(" -a NAME specify file to write to flash, default is flash.bin\n");
|
||||
printf(" -A ADDRESS optionally specifies the start-address to load into/read from flash\n");
|
||||
printf(" default is 0x000000 - must be specified in hex\n");
|
||||
printf(" -L ADDRESS optionally specifies the maximum number of bytes to load into/read from flash\n");
|
||||
printf(" default is 0x080000 - must be specified in hex\n");
|
||||
printf(" -e completely erase the flash before writing\n");
|
||||
printf(" default is no erase\n");
|
||||
printf(" -s erase flash sectors as needed.\n");
|
||||
printf(" this is a lot faster if only a few sectors are used\n");
|
||||
printf(" -? print this help\n");
|
||||
printf("\n");
|
||||
printf("ATTENTION: commands are order-sensitive! for example, to set an address, you MUST\n");
|
||||
printf("specify the address with -A before you specify any of the -r or -w commands. this\n");
|
||||
printf("allows you to upload serveral binary files to serveral places with one command.\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;
|
||||
}
|
||||
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
char sname[256];
|
||||
char rname[256];
|
||||
char f0name[256];
|
||||
int isOpen;
|
||||
int numw;
|
||||
|
||||
unsigned int baud;
|
||||
|
||||
unsigned char i, cmd;
|
||||
|
||||
baud = 115200;
|
||||
do_erase = 0;
|
||||
numw = 0;
|
||||
isOpen = 0;
|
||||
sprintf(sname,"/dev/ttyS0");
|
||||
sprintf(rname,"flash_dump.bin");
|
||||
sprintf(f0name,"flash.bin");
|
||||
|
||||
f0adr = 0x000000;
|
||||
f0len = 0x080000;
|
||||
|
||||
printHeader();
|
||||
verbosity = 1;
|
||||
|
||||
if(argc <= 1)
|
||||
goto bailout;
|
||||
|
||||
rescan:
|
||||
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];
|
||||
}
|
||||
if(isOpen == 0)
|
||||
{
|
||||
switch(cmd)
|
||||
{
|
||||
case 'h':
|
||||
baud = 921600;
|
||||
break;
|
||||
case 'd':
|
||||
if((argc > i+1) && (argv[i+1][0] != '-'))
|
||||
{
|
||||
strncpy(sname,argv[++i],256);
|
||||
printInfoS(1,"opening serial device",sname);
|
||||
if(isOpen)
|
||||
{
|
||||
if(closeSerial() == 0)
|
||||
{
|
||||
isOpen = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
printError("cant close port");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if(openSerial(sname, baud))
|
||||
{
|
||||
isOpen = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printError("cant open port");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printError("Error in device argument");
|
||||
goto bailout;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(cmd)
|
||||
{
|
||||
case 'd':
|
||||
if((argc > i+1) && (argv[i+1][0] != '-'))
|
||||
{
|
||||
strncpy(sname,argv[++i],256);
|
||||
printInfoS(1,"closing serial device",sname);
|
||||
if(closeSerial() == 0)
|
||||
{
|
||||
isOpen = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
printError("cant close port");
|
||||
return 0;
|
||||
}
|
||||
printInfoS(1,"opening serial device",sname);
|
||||
if(openSerial(sname, baud))
|
||||
{
|
||||
isOpen = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printError("cant open port");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
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,"reading flash image",rname);
|
||||
numw = readFlash(rname, f0adr, f0len);
|
||||
if(numw)
|
||||
{
|
||||
printInfoS(1, "done reading memory ",0);
|
||||
}
|
||||
else
|
||||
{
|
||||
printErrorS("Error in reading memory-image",rname);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case 'a':
|
||||
if((argc > i+1) && (argv[i+1][0] != '-'))
|
||||
{
|
||||
strncpy(f0name,argv[++i],256);
|
||||
}
|
||||
printInfoS(1,"writing flash image",f0name);
|
||||
numw = writeFlash(f0name, f0adr, f0len);
|
||||
if(numw)
|
||||
{
|
||||
printInfoS(1, "done writing memory ",0);
|
||||
f0len = numw;
|
||||
}
|
||||
else
|
||||
{
|
||||
printErrorS("Error in writing memory-image",f0name);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case 'A':
|
||||
if((argc > i+1) && (argv[i+1][0] != '-'))
|
||||
{
|
||||
f0adr = parseHex(argv[++i]);
|
||||
printInfoH(1,"setting address for flash @",f0adr);
|
||||
}
|
||||
else
|
||||
printInfoH(1,"used -A but no address given, using default",f0adr);
|
||||
f0len = 0x080000;
|
||||
break;
|
||||
case 'L':
|
||||
if((argc > i+1) && (argv[i+1][0] != '-'))
|
||||
{
|
||||
f0len = parseHex(argv[++i]);
|
||||
printInfoH(1,"setting length for flash @",f0len);
|
||||
}
|
||||
else
|
||||
printInfoH(1,"used -L but no address given, using default",f0len);
|
||||
break;
|
||||
case 'e':
|
||||
printInfoS(1,"erasing flash before write",0);
|
||||
if(!eraseFlash(f0adr))
|
||||
{
|
||||
printError("cant erase flash");
|
||||
return 0;
|
||||
}
|
||||
|
||||
break;
|
||||
case 's':
|
||||
printInfoS(1,"erasing sectors as needed",0);
|
||||
do_erase = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bailout:
|
||||
printUsage();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if((isOpen == 0) && (argc > 1))
|
||||
{
|
||||
printInfoS(1,"using serial device",sname);
|
||||
if(openSerial(sname, baud))
|
||||
{
|
||||
isOpen = 1;
|
||||
goto rescan;
|
||||
}
|
||||
}
|
||||
else if(isOpen != 0)
|
||||
{
|
||||
printInfoS(1,"closing serial device",sname);
|
||||
closeSerial();
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue