------- Additional Comments From ulyssesric at yahoo dot com dot tw 2005-05-31 03:35 ------- Fine, I'll list all codes if you insist:
#include <avr/io.h> typedef unsigned char byte_t; typedef unsigned long long qword_t; void uart_init(void) { // 115200 & 8N1 UBRR1H = 0x00; UBRR1L = 0x08; UCSR1A |= (0x01<<U2X1); UCSR1C = 0x06; UCSR1B &= ~0x04; UCSR1B |= ((0x01<<RXEN1) | (0x01<<TXEN1)); } void uart_putchar(byte_t octet) { UDR1 = octet; while (!(UCSR1A & (0x01<<UDRE1))); } void uart_write(byte_t *octet, uint8_t len) { while (len--) { UDR1 = *octet++; while (!(UCSR1A & (0x01<<UDRE1))); } } void foo( byte_t state, qword_t srcAddr, byte_t routeOptions, qword_t dstAddr ) { uart_putchar(state); uart_write((byte_t *)(&srcAddr),8); uart_putchar(routeOptions); uart_write((byte_t *)(&dstAddr),8); } void main(void) { uart_init(); foo(0x00,0x1234ll,0x01, 0x5678ll); while(1); } and the output is: D1, 34,12,D1,D1,D1,D1,D1,D1, 01, AB,CD,00,CF,00,80,00,78 in hexdecimal format. Obviously it's incorrect. If I change the code to: #include <avr/io.h> typedef unsigned char byte_t; typedef unsigned long long qword_t; void uart_init(void) { // 115200 & 8N1 UBRR1H = 0x00; UBRR1L = 0x08; UCSR1A |= (0x01<<U2X1); UCSR1C = 0x06; UCSR1B &= ~0x04; UCSR1B |= ((0x01<<RXEN1) | (0x01<<TXEN1)); } void uart_putchar(byte_t octet) { UDR1 = octet; while (!(UCSR1A & (0x01<<UDRE1))); } void uart_write(byte_t *octet, uint8_t len) { while (len--) { UDR1 = *octet++; while (!(UCSR1A & (0x01<<UDRE1))); } } void foo( qword_t srcAddr, qword_t dstAddr, byte_t state, byte_t routeOptions ) { uart_putchar(state); uart_write((byte_t *)(&srcAddr),8); uart_putchar(routeOptions); uart_write((byte_t *)(&dstAddr),8); } void main(void) { uart_init(); foo(0x1234ll,0x5678ll,0x00,0x01); while(1); } And the output will be: 00, 34,12,00,00,00,00,00,00, 01, 78,56,00,00,00,00,00,00 Compiling Procedure: avr-gcc -mmcu=atmega128 -g -Os -Wall -Wa,-adhlns=main.lst -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -ffreestanding -Wl,-Map=main.map -Wl,--cref main.c -o main.elf avr-objcopy -O ihex -R .eeprom test.elf test.hex avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex test.elf test.eep avr-objdump -h -S test.elf > test.lss avr-nm -n test.elf > test.sym Programming with AVR Studio 4.11 build 401, JTAGICE mkII -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21834