Wątek przeniesiony 2018-11-08 11:16 z C/C++ przez Marooned.

endianess AVR Vs dostęp do rejestru ICR1

0

Mam atmege8.
Stworzyłem w C funkcję obsługi przerwania od modułu timer1 capture unit:

ISR(TIMER1_CAPT_vect)
{
    /* immediately read data from input capture register */
    uint16_t data = ICR1;
}

I teraz chciałbym mieć pewność że kompilator to zrobi tak że wpierw dobierze się do młodszego bajta a potem do starszego. Nota bowiem mówi:

Reading the 16-bit value in the Input Capture Register (ICR1) is done by first reading the Low byte (ICR1L) and then the High byte (ICR1H). When the Low byte is read the High byte is copied into the High byte temporary register (TEMP). When the CPU reads the ICR1H I/O location it will access the TEMP Register

Aby taką pewność mieć podejrzałem kod assemblera który mi kompilator wygenerował:

push	r1
 2da:	0f 92       	push	r0
 2dc:	0f b6       	in	r0, 0x3f	; 63
 2de:	0f 92       	push	r0
 2e0:	11 24       	eor	r1, r1
 2e2:	8f 93       	push	r24
 2e4:	9f 93       	push	r25
 2e6:	86 b5       	in	r24, 0x26	; 38
 2e8:	97 b5       	in	r25, 0x27	; 39
 2ea:	9f 91       	pop	r25
 2ec:	8f 91       	pop	r24
 2ee:	0f 90       	pop	r0
 2f0:	0f be       	out	0x3f, r0	; 63
 2f2:	0f 90       	pop	r0
 2f4:	1f 90       	pop	r1
 2f6:	18 95       	reti

Dodam tylko że rejestry 0x26 i 0x27 to właśnie ten nieszczęsny ICR1.
Czy ktoś może mi powiedzieć czy to jest dobrze?

1

Tak, jest ok. Zasadniczo twórcy kompilatora/biblioteki standardowej wiedzą co jest w datasheecie i kompilator sam o to powinien zadbać (co ma miejsce). Skąd Twoja niepewność?

1

Po prostu to właśnie chciałem usłyszeć co napisałeś. Dziękuję Ci @alagner. Pozdrawiam.

1 użytkowników online, w tym zalogowanych: 0, gości: 1