flagxor / ueforth

Apache License 2.0
90 stars 26 forks source link

New timer code for esp32c3 #51

Open Eszartek opened 1 year ago

Eszartek commented 1 year ago

Since the new timer code in 7.0.7.10 now uses the Arduino libs for initialization and register setup, there are just two minor adjustments that need to be made for the esp32c3.

First, the RISCv esp32c3 only has 2 timers available versus the 4 timers in the Xtensa variants. Initialization of the second two timers results in a harmless error:

E (6611) timer_group: timer_init(273): HW TIMER NUM ERROR
E (6615) timer_group: timer_init(273): HW TIMER NUM ERROR

This could be remedied with something like

0 0 timer_init_null
0 1 timer_init_null
# !defined(CONFIG_IDF_TARGET_ESP32C3) 
1 0 timer_init_null
1 1 timer_init_null
#endif

Second, since the esp32c3 doesn't support edge triggered interrupts, I just changed the definition of onalarm to use ESP_INTR_FLAG_IRAM instead of ESP_INTR_FLAG_EDGE

: onalarm ( xt t ) swap >r t>nx r>
                   0 ESP_INTR_FLAG_IRAM timer_isr_callback_add throw ;

and the interval timer works as intended on this chip.

Eszartek commented 1 year ago

I just tried timer 1, which didn't work, but timer 2 does, so I made a mistake. I'll verify and correct the timer_init bits above shortly.