Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4943

General • Forced and EXEC’d Instructions

$
0
0
Hi,
The rp2040-datasheet gives an example of controlling the execution of PIO SM with `pio->sm[n].instr` register (page 341/342). So I create this program to test it out:
instr.pio

Code:

.program instr.wrap_target    wait 1 irq 1    irq wait 0.wrap% c-sdk {static inline void instr_program_init(PIO pio, uint sm, uint offset) {    pio_sm_config c = instr_program_get_default_config(offset);    pio_sm_init(pio, sm, offset, &c);}%}
main.c:

Code:

#include <stdio.h>#include "pico/stdlib.h"#include "hardware/pio.h"#include "instr.pio.h"PIO pio = pio0;int sm = 0;void event_handler() {    pio_interrupt_clear(pio, 0);    printf("irq 0 fired\n");}void dummy_handler() {}int main() {    uint offset = pio_add_program(pio, &instr_program);    stdio_init_all();    printf("Loaded program at %d\n", offset);    irq_set_exclusive_handler(PIO0_IRQ_0, event_handler);    irq_set_exclusive_handler(PIO0_IRQ_1, dummy_handler);    irq_set_enabled(PIO0_IRQ_1, true);    pio_set_irq1_source_enabled(pio, pis_interrupt0 + sm, true);    irq_set_enabled(PIO0_IRQ_0, true);    pio_set_irq0_source_enabled(pio, pis_interrupt0 + sm, true);    instr_program_init(pio, sm, offset);    pio_sm_set_enabled(pio, sm, true);    // pio->irq_force = 2u;    pio->sm[sm].instr = 0x0000 | 0x1;    while (true) {        sleep_ms(1000);    }}
When I use the commented out `pio->irq_force = 2u;` event_handler is called and "irq 0 fired" is printed out. However if I change to the `pio->sm[sm].instr = 0x0000 | 0x1;` line event_handler is not called so look like the PIO program doesn't proceed to the `irq wait 0` instruction. Not sure what I am missing or misunderstanding. Could someone sheds some light on this feature of controlling the execution of the PIO program? I would rather use this approach than the interrupt one as it save an interrupt resource.

Statistics: Posted by seanchenca — Wed Aug 14, 2024 11:36 pm



Viewing all articles
Browse latest Browse all 4943

Trending Articles