Witam, robię projekt "sterownik cd" z EP2002/7 i próbuje skompilować podany kod, niby wszystko się kompiluje dobrze. Analizując plik ""hex"" w AVRstudio wykryłem że kompilator pozbył się skoków do funkcji "SetAdress..." oto kawałek kodu w C oraz wynik już skompilowanego kodu:
assembler :
Kompilator nie uwzględnia skoków do "SetAdress", co zrobić by to poprawnie kompilowało. Używam WinAvr 20030310 ale próbowałem na najnowszych wersjach i nic to nie dało wynik ten sam. Optymalizację mam ustawioną na "-S", przy "-0" niby jest dobrze ale za to do procedur dodaje za dużo kodu. Pomocy...!!!
Podaje jeszcze plik make :
u08 SetAddress(u08 cs, u08 adr)
{
u16 i;
if (cs==CTRL)
i = adr+0x08; // select A4 low -> CS1 -> CTRL
else
i = adr+0x10; // select A3 low -> CS0 -> CMD
return *(u08 *) (0xE000+i);//
}
//----------------------------------------------------------------------------
// Read data BYTE from Drive
//----------------------------------------------------------------------------
u08 ReadBYTE(u08 cs, u08 adr)
{
u08 tmp;
SetAddress(cs,adr);
cbi(MCUCR, SRE); // disable RAM
outp(0x00, DDRA); // port A as input
outp(0x00, DDRC); // port C as input
outp(0xff, PORTA); // activate Pullups
outp(0xff, PORTC); // activate Pullups
cbi(PORTB, 1); // set DIOR lo
asm volatile ("nop"); // allow pin change
tmp = inp(PINA); // read byte
sbi(PORTB, 1); // set DIOR hi
asm volatile ("nop"); // allow pin change
sbi(MCUCR, SRE); // enable RAM
return tmp;
}
//----------------------------------------------------------------------------
// Write data BYTE to Drive
//----------------------------------------------------------------------------
void WriteBYTE(u08 cs, u08 adr, u08 dat)
{
SetAddress(cs,adr);
outp(0xff, DDRA); // port A as output
outp(0xff, DDRC); // port C as output
cbi(MCUCR, SRE); // disable RAM
asm volatile ("nop"); // allow pin change
outp(dat, PORTA); // write byte
cbi(PORTB, 0); // set DIOW lo
asm volatile ("nop"); // allow pin change
asm volatile ("nop"); // allow pin change
sbi(PORTB, 0); // set DIOW hi
sbi(MCUCR, SRE); // enable RAM
}
assembler :
SetAddress...
+00000165: 2F98 MOV R25,R24
+00000166: 2F26 MOV R18,R22
+00000167: 2733 CLR R19
+00000168: 2399 TST R25
+00000169: F419 BRNE PC+0x04
+0000016A: 01F9 MOVW R30,R18
+0000016B: 9638 ADIW R30,0x08
+0000016C: C002 RJMP PC+0x0003
+0000016D: 01F9 MOVW R30,R18
+0000016E: 9670 ADIW R30,0x10
+0000016F: 50E0 SUBI R30,0x00
+00000170: 42F0 SBCI R31,0x20
+00000171: 8180 LDD R24,Z+0
+00000172: 2799 CLR R25
+00000173: 9508 RET
ReadBYTE.... <--- brak skoku do SetAdress
+00000174: B785 IN R24,0x35
+00000175: 778F ANDI R24,0x7F
+00000176: BF85 OUT 0x35,R24
+00000177: BA1A OUT 0x1A,R1
+00000178: BA14 OUT 0x14,R1
+00000179: EF8F SER R24
+0000017A: BB8B OUT 0x1B,R24
+0000017B: BB85 OUT 0x15,R24
+0000017C: 98C1 CBI 0x18,1
+0000017D: 0000 NOP
+0000017E: B399 IN R25,0x19
+0000017F: 9AC1 SBI 0x18,1
+00000180: 0000 NOP
+00000181: B785 IN R24,0x35
+00000182: 6880 ORI R24,0x80
+00000183: BF85 OUT 0x35,R24
+00000184: 2F89 MOV R24,R25
+00000185: 2799 CLR R25
+00000186: 9508 RET
WriteBYTE.... <--- brak skoku do SetAdress
+00000187: EF8F SER R24
+00000188: BB8A OUT 0x1A,R24
+00000189: BB84 OUT 0x14,R24
+0000018A: B785 IN R24,0x35
+0000018B: 778F ANDI R24,0x7F
+0000018C: BF85 OUT 0x35,R24
+0000018D: 0000 NOP
+0000018E: BB4B OUT 0x1B,R20
+0000018F: 98C0 CBI 0x18,0
+00000190: 0000 NOP
+00000191: 0000 NOP
+00000192: 9AC0 SBI 0x18,0
+00000193: B785 IN R24,0x35
+00000194: 6880 ORI R24,0x80
+00000195: BF85 OUT 0x35,R24
+00000196: 9508 RET
Kompilator nie uwzględnia skoków do "SetAdress", co zrobić by to poprawnie kompilowało. Używam WinAvr 20030310 ale próbowałem na najnowszych wersjach i nic to nie dało wynik ten sam. Optymalizację mam ustawioną na "-S", przy "-0" niby jest dobrze ale za to do procedur dodaje za dużo kodu. Pomocy...!!!
Podaje jeszcze plik make :
Cytat:
# WinAVR Sample makefile (c) 2002-2003 Eric B. Weddington
# Released to the Public Domain
# Please read the make user manual!
#
#
# On command line:
# make all = Make software.
# make clean = Clean out built project files.
# make coff = Convert ELF to COFF using objtool.
#
# To rebuild project do make clean then make all.
#
# MCU name
MCU = atmega161
# Output format. (can be srec, ihex)
FORMAT = ihex
# Target file name (without extension).
TARGET = cdrom
# Optimization level (can be 0, 1, 2, 3, s)
# (Note: 3 is not always the best optimization level. See avr-libc FAQ)
OPT = s
# List C source files here. (C dependencies are automatically generated.)
SRC = $(TARGET).c \
ata_if.c delay.c uart.c
# List Assembler source files here.
ASRC =
# Optional compiler flags.
CFLAGS = -g -O$(OPT) -funsigned-char -funsigned-bitfields -fpack-struct \
-fshort-enums -Wall -Wstrict-prototypes -Wa,-ahlms=$(<:.c=.lst)
# Optional assembler flags.
ASFLAGS = -Wa,-ahlms=$(<:.s=.lst), -gstabs
# Optional linker flags.
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
# Additional library flags (-lm = math library).
LIBFLAGS = -lm
# ---------------------------------------------------------------------------
# Define directories, if needed.
DIRAVR = c:/winavr2
DIRAVRBIN = $(DIRAVR)/bin
DIRAVRUTILS = $(DIRAVR)/utils/bin
DIRINC = .
DIRLIB = $(DIRAVR)/avr/lib
# Define programs and commands.
SHELL = sh
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
REMOVE = rm -f
COPY = cp
ELFCOFF = objtool
HEXSIZE = @AVR-size --target=$(FORMAT) $(TARGET).hex
ELFSIZE = @AVR-size $(TARGET).elf
FINISH = @Echo. Errors: none
BEGIN = @Echo. -------- begin --------
END = @Echo. -------- end --------
# Define all object files.
OBJ = $(SRC:.c=.o) $(ASRC:.s=.o)
# Define all listing files.
LST = $(ASRC:.s=.lst) $(SRC:.c=.lst)
# Combine all necessary flags and optional flags. Add target processor to flags.
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
ALL_LDFLAGS = -mmcu=$(MCU) $(LDFLAGS)
# Default target.
all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep $(TARGET).lss sizeafter finished end
# Eye candy.
begin:
$(BEGIN)
finished:
$(FINISH)
end:
$(END)
# Display size of file.
sizebefore:
@Echo. Size before:
-$(HEXSIZE)
sizeafter:
@Echo. Size after:
$(HEXSIZE)
# Display compiler version information.
gccversion :
$(CC) --version
# Target: Convert ELF to COFF for use in debugging / simulating in AVR Studio.
coff: $(TARGET).cof end
%.cof: %.elf
$(ELFCOFF) loadelf $< mapfile $*.map writecof $@
# Create final output files (.hex, .eep) from ELF output file.
%.hex: %.elf
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
%.eep: %.elf
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
# Create extended listing file from ELF output file.
%.lss: %.elf
$(OBJDUMP) -h -S $< > $@
# Link: create ELF output file from object files.
.SECONDARY : $(TARGET).elf
.PRECIOUS : $(OBJ)
%.elf: $(OBJ)
$(CC) $(ALL_LDFLAGS) $(OBJ) $(LIBFLAGS) --output $@
# Compile: create object files from C source files.
%.o : %.c
$(CC) -c $(ALL_CFLAGS) $< -o $@
# Assemble: create object files from assembler source files.
%.o : %.s
$(CC) -c $(ALL_ASFLAGS) $< -o $@
# Target: clean project.
clean: begin clean_list finished end
clean_list :
$(REMOVE) $(TARGET).hex
$(REMOVE) $(TARGET).eep
$(REMOVE) $(TARGET).obj
$(REMOVE) $(TARGET).cof
$(REMOVE) $(TARGET).elf
$(REMOVE) $(TARGET).map
$(REMOVE) $(TARGET).obj
$(REMOVE) $(TARGET).a90
$(REMOVE) $(TARGET).sym
$(REMOVE) $(TARGET).lnk
$(REMOVE) $(TARGET).lss
$(REMOVE) $(OBJ)
$(REMOVE) $(LST)
# Automatically generate C source code dependencies. (Code taken from the GNU make user manual.)
# Note that this will work with sh (bash) and sed that is shipped with WinAVR (see the SHELL variable defined above).
# This may not work with other shells or other seds.
%.d: %.c
set -e; $(CC) -MM $(ALL_CFLAGS) $< \
| sed 's/$$*$\.o[ :]*/\1.o $@ : /g' > $@; \
[ -s $@ ] || rm -f $@
# Remove the '-' if you want to see the dependency files generated.
-include $(SRC:.c=.d)
# Listing of phony targets.
.PHONY : all begin finish end sizebefore sizeafter gccversion coff clean clean_list
