avr-gcc et programme qui ne fait pas ce qu'il est censé faire...

sous avr-gcc.

conditions, et pas pour d'autres.

Principe de fonctionnement :

typedef volatile struct { volatile uint8_t *port; volatile uint8_t *pin; volatile uint8_t bitNo; volatile int8_t timer; } gpio_t;

volatile uint8_t interrupt_counter;

enum { i_work = 0, i_wait, i_meas_in_progress, i_meas_ready, i_send_data, i_watchdog_reset, i_comm_rx, i_comm_tx, i_comm_ok, i_irq, i_max};

static gpio_t i_led[i_max] = { { &PORTD, &PIND, 3, 0 }, { &PORTD, &PIND, 4, 0 }, { &PORTD, &PIND, 5, 0 }, { &PORTD, &PIND, 6, 0 }, { &PORTD, &PIND, 7, 0 }, { &PORTB, &PINB, 0, 0 }, { &PORTB, &PINB, 1, 0 }, { &PORTB, &PINB, 2, 0 }, { &PORTB, &PINB, 3, 0 }, { &PORTB, &PINB, 4, 0 } };

static inline void gpio_on(gpio_t *g, int8_t d) { // d = 5 => 1/5th s // d = -1 => no timer *(g->port) |= ((uint8_t) 1) bitNo; g->timer = d; return; }

static inline void gpio_off(gpio_t *g) { *(g->port) &= ~(((uint8_t) 1) bitNo); g->timer = 0; return; }

static inline void gpio_toggle(gpio_t *g) { if (*(g->pin) & ((uint8_t) 1) bitNo) { gpio_off(g); } else { gpio_on(g, -1); }

return; }

ISR(TIMER1_COMPA_vect, ISR_BLOCK) { uint8_t i;

interrupt_counter = (interrupt_counter + 1) % 25;

if (interrupt_counter == 0) // 1 s { gpio_toggle(&i_led[i_work]); }

// Switch debug leds off for(i = 0; i < i_max; i++) { if (i_led[i].timer > 0) { i_led[i].timer--;

if (i_led[i].timer == 0) { gpio_off(&i_led[i]); } } }

return; }

Je SAIS que ce timer fonctionne correctement et que l'interruption

autres (i_comm_ok) pour 5 ticks (donc 200ms). Cette led reste

if (command < cmd_max) { gpio_on(&i_led[i_comm_ok], 5); serial_send_byte(i_led[i_comm_ok].timer); _delay_ms(200); serial_send_byte(i_led[i_comm_ok].timer); } ... serial_send_byte(0x06);

Je ne vais pas expliciter serial_send_byte(), cette routine

j'obtiens :

+++RPL/2 (R) version 4.1.32 (Mardi 17/03/2020, 16:39:58 CET)

3: { "\x05" }

Reply to
JKB
Loading thread data ...

Salut JKB,

if (i_led[i].timer == 0) ne sera jamais vrai dans ce cas puiqu'il

Reply to
Loïc G.

Le Thu, 2 Apr 2020 17:35:54 +0200,

Je ne comprends pas.

La valeur .timer peut valoir -1 (pas de timer) ou n'importe quelle valeur positive.

JKB

--
=> http://grincheux.de-charybde-en-scylla.fr 
=> http://loubardes.de-charybde-en-scylla.fr
 Click to see the full signature
Reply to
JKB

Le 02 Apr 2020 15:52:22 GMT,

viens de rajouter une ligne :

for(i = 0; i < i_max; i++) { serial_send_byte(i); if (i_led[i].timer > 0) { i_led[i].timer--;

if (i_led[i].timer == 0) { gpio_off(&i_led[i]); } } }

4 5 6 7 8 9 4 5 6 7 8 9 4 5 6 7 8 9 4 5 6 7 8 9 4 5 6 7 8 9 4 5 6 7 8 9 4 5 6 7 8

JKB

--
=> http://grincheux.de-charybde-en-scylla.fr 
=> http://loubardes.de-charybde-en-scylla.fr
 Click to see the full signature
Reply to
JKB

Le Thu, 2 Apr 2020 18:07:49 +0200,

i_led[i_max] puisque cela n'existe pas.

Certes, mais comme je n'ai pas compris la remarque...

JKB

for(i = 0; i < i_max; i++) { }

--
=> http://grincheux.de-charybde-en-scylla.fr 
=> http://loubardes.de-charybde-en-scylla.fr
 Click to see the full signature
Reply to
JKB

Ok. dans ton enum i_max=10 ...

moment) mais je suis en train de m'y remettre.

Bon courage, H H

Reply to
habib

Le Thu, 2 Apr 2020 20:44:38 +0200,

Bien cordialement,

JKB

--
=> http://grincheux.de-charybde-en-scylla.fr 
=> http://loubardes.de-charybde-en-scylla.fr
 Click to see the full signature
Reply to
JKB

pense que c'est i_work = 0 qui te perturbe (du reste inutile en C actuel

ai vu tellement !) ... quand tu pointe led[i_max] i_max=10 tu pointe en

ce que fait le proc avr

H
Reply to
habib

Curieux en effet et je ne vois rien non plus qui pourrait expliquer cela dans l'exemple du 1er post.

avec 4 qui serait fait en i = 4 au lieu de i == 4, dans la routine d'interruption ...

Reply to
Loïc G.

Le Thu, 2 Apr 2020 21:33:05 +0200,

i_max. i_max ne sert que pour dimensionner le tableau... Il ne s'agit pas d'une led.

JKB

--
=> http://grincheux.de-charybde-en-scylla.fr 
=> http://loubardes.de-charybde-en-scylla.fr
 Click to see the full signature
Reply to
JKB

Le Thu, 2 Apr 2020 23:30:26 +0200,

formatting link

JKB

--
=> http://grincheux.de-charybde-en-scylla.fr 
=> http://loubardes.de-charybde-en-scylla.fr
 Click to see the full signature
Reply to
JKB

Le 02 Apr 2020 21:59:08 GMT,

En particulier :

Dans l'interruption USART0_RX, j'allume deux leds pour 5 ticks (1/5e

root@hilbert:/home/bertrand/cvs/avr-c# ./client.rpl

+++RPL/2 (R) version 4.1.32 (Mardi 17/03/2020, 16:39:58 CET)

6

formatting link
=>
formatting link

Reply to
JKB

Slt?

Je crois que le droit de blaguer s?arrete le 01/04 la doc est ? ?chu !

y

lors

conde.

s comme un

Reply to
ptilou

?chu !

l y

alors

s,

ur

seconde.

s

ros comme un

DLC

Reply to
ptilou

Le Fri, 3 Apr 2020 08:44:14 +0200,

ISR(TIMER1_COMPA_vect, ISR_BLOCK) { uint8_t i;

interrupt_counter = (interrupt_counter + 1) % 25;

if (interrupt_counter == 0) // 1 s { gpio_toggle(&i_led[i_work]); }

// Switch debug leds off for(i = 0; i < i_max; i++) { serial_send_byte(i); if (i_led[i].timer > 0) { i_led[i].timer--;

if (i_led[i].timer == 0) { gpio_off(&i_led[i]); } } }

return; }

4 5 6 7 8 9 4 5 6 7 8 9 4 5 6 7 8 9 4 5 6 7 8 9 4 5 6 7 8 9 4 5 6 7 8 9

Le listing de l'interruption est le suivant :

00000218 : 218: 1f 92 push r1 21a: 0f 92 push r0 21c: 0f b6 in r0, 0x3f ; 63 21e: 0f 92 push r0 220: 11 24 eor r1, r1 222: 0b b6 in r0, 0x3b ; 59 224: 0f 92 push r0 226: 0f 93 push r16 228: 1f 93 push r17 22a: 2f 93 push r18 22c: 3f 93 push r19 22e: 4f 93 push r20 230: 5f 93 push r21 232: 6f 93 push r22 234: 7f 93 push r23 236: 8f 93 push r24 238: 9f 93 push r25 23a: af 93 push r26 23c: bf 93 push r27 23e: cf 93 push r28 240: df 93 push r29 242: ef 93 push r30 244: ff 93 push r31 246: 80 91 5b 03 lds r24, 0x035B ; 0x80035b 24a: 90 e0 ldi r25, 0x00 ; 0 24c: 01 96 adiw r24, 0x01 ; 1 24e: 69 e1 ldi r22, 0x19 ; 25 250: 70 e0 ldi r23, 0x00 ; 0 252: 0e 94 e6 04 call 0x9cc ; 0x9cc 256: 80 93 5b 03 sts 0x035B, r24 ; 0x80035b 25a: 80 91 5b 03 lds r24, 0x035B ; 0x80035b // Test pour savoir si interrupt_counter est nul. 25e: 88 23 and r24, r24 260: 09 f4 brne .+2 ; 0x264 262: 45 c0 rjmp .+138 ; 0x2ee // Debut de la boucle fautive 264: 00 e0 ldi r16, 0x00 ; 0 266: 10 e0 ldi r17, 0x00 ; 0 268: c1 e0 ldi r28, 0x01 ; 1 26a: d0 e0 ldi r29, 0x00 ; 0 26c: 80 2f mov r24, r16 26e: 0e 94 07 03 call 0x60e ; 0x60e 272: f8 01 movw r30, r16 274: ee 0f add r30, r30 276: ff 1f adc r31, r31 278: e0 0f add r30, r16 27a: f1 1f adc r31, r17 27c: ee 0f add r30, r30 27e: ff 1f adc r31, r31 280: e6 5a subi r30, 0xA6 ; 166 282: fe 4f sbci r31, 0xFE ; 254 284: 85 81 ldd r24, Z+5 ; 0x05 286: 18 16 cp r1, r24 288: b4 f4 brge .+44 ; 0x2b6 28a: 85 81 ldd r24, Z+5 ; 0x05 28c: 81 50 subi r24, 0x01 ; 1 28e: 85 83 std Z+5, r24 ; 0x05 290: 85 81 ldd r24, Z+5 ; 0x05 292: 81 11 cpse r24, r1 294: 10 c0 rjmp .+32 ; 0x2b6 296: 84 81 ldd r24, Z+4 ; 0x04 298: a0 81 ld r26, Z 29a: b1 81 ldd r27, Z+1 ; 0x01 29c: 2c 91 ld r18, X 29e: ae 01 movw r20, r28 2a0: 02 c0 rjmp .+4 ; 0x2a6 2a2: 44 0f add r20, r20 2a4: 55 1f adc r21, r21 2a6: 8a 95 dec r24 2a8: e2 f7 brpl .-8 ; 0x2a2 2aa: ca 01 movw r24, r20 2ac: 80 95 com r24 2ae: 90 95 com r25 2b0: 82 23 and r24, r18 2b2: 8c 93 st X, r24 2b2: 8c 93 st X, r24 2b4: 15 82 std Z+5, r1 ; 0x05 2b6: 0f 5f subi r16, 0xFF ; 255 2b8: 1f 4f sbci r17, 0xFF ; 255 2ba: 0a 30 cpi r16, 0x0A ; 10 2bc: 11 05 cpc r17, r1 2be: b1 f6 brne .-84 ; 0x26c // Fin de la boucle 2c0: ff 91 pop r31 2c2: ef 91 pop r30 2c4: df 91 pop r29 2c6: cf 91 pop r28 2c8: bf 91 pop r27 2ca: af 91 pop r26 2cc: 9f 91 pop r25 2ce: 8f 91 pop r24 2d0: 7f 91 pop r23 2d2: 6f 91 pop r22 2d4: 5f 91 pop r21 2d6: 4f 91 pop r20 2d8: 3f 91 pop r19 2da: 2f 91 pop r18 2dc: 1f 91 pop r17 2de: 0f 91 pop r16 2e0: 0f 90 pop r0 2e2: 0b be out 0x3b, r0 ; 59 2e4: 0f 90 pop r0 2e6: 0f be out 0x3f, r0 ; 63 2e8: 0f 90 pop r0 2ea: 1f 90 pop r1 2ec: 18 95 reti // gpio_toggle() 2ee: e0 91 5c 01 lds r30, 0x015C ; 0x80015c 2f2: f0 91 5d 01 lds r31, 0x015D ; 0x80015d 2f6: 80 81 ld r24, Z 2f8: 20 91 5e 01 lds r18, 0x015E ; 0x80015e 2fc: 90 e0 ldi r25, 0x00 ; 0 2fe: 02 c0 rjmp .+4 ; 0x304 300: 95 95 asr r25 302: 87 95 ror r24 304: 2a 95 dec r18 306: e2 f7 brpl .-8 ; 0x300 308: 30 91 5e 01 lds r19, 0x015E ; 0x80015e 30c: e0 91 5a 01 lds r30, 0x015A ; 0x80015a 310: f0 91 5b 01 lds r31, 0x015B ; 0x80015b 314: 20 81 ld r18, Z 316: 80 fd sbrc r24, 0 318: 0c c0 rjmp .+24 ; 0x332 31a: 81 e0 ldi r24, 0x01 ; 1 31c: 90 e0 ldi r25, 0x00 ; 0 31e: 01 c0 rjmp .+2 ; 0x322 320: 88 0f add r24, r24 322: 3a 95 dec r19 324: ea f7 brpl .-6 ; 0x320 326: 82 2b or r24, r18 328: 80 83 st Z, r24 32a: 8f ef ldi r24, 0xFF ; 255 32c: 80 93 5f 01 sts 0x015F, r24 ; 0x80015f 330: 99 cf rjmp .-206 ; 0x264 332: 81 e0 ldi r24, 0x01 ; 1 334: 90 e0 ldi r25, 0x00 ; 0 336: 02 c0 rjmp .+4 ; 0x33c 338: 88 0f add r24, r24 33a: 99 1f adc r25, r25 33c: 3a 95 dec r19 33e: e2 f7 brpl .-8 ; 0x338 340: 80 95 com r24 342: 90 95 com r25 344: 82 23 and r24, r18 346: 80 83 st Z, r24 348: 10 92 5f 01 sts 0x015F, r1 ; 0x80015f 34c: 8b cf rjmp .-234 ; 0x264

De ce que je comprends, r16 est le compteur de boucle.

JKB

--
=> http://grincheux.de-charybde-en-scylla.fr 
=> http://loubardes.de-charybde-en-scylla.fr
 Click to see the full signature
Reply to
JKB

Bonjour,

Que vaut la constante i_max ? 11 (0 ... 10),

le cas ...) alors tu cartonne le tas d'au moins 4 octets et le

Cdt, H.

Reply to
bilboard

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.