8000 Switch SAMD21 ticks to PER event · tannewt/circuitpython@0139ec1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0139ec1

Browse files
committed
Switch SAMD21 ticks to PER event
The EVSYS is used to generate an interrupt from the event. This simplifies timing used in pulseio that conflicted with the auto-reload countdown. Fixes micropython#3890
1 parent 3ec3e70 commit 0139ec1

File tree

5 files changed

+110
-122
lines changed

5 files changed

+110
-122
lines changed

ports/atmel-samd/audio_dma.c

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
/*
23
* This file is part of the MicroPython project, http://micropython.org/
34
*
@@ -265,13 +266,13 @@ audio_dma_result audio_dma_setup_playback(audio_dma_t *dma,
265266

266267
#ifdef SAM_D5X_E5X
267268
int irq = dma->event_channel < 4 ? EVSYS_0_IRQn + dma->event_channel : EVSYS_4_IRQn;
269+
// Only disable and clear on SAMD51 because the SAMD21 shares EVSYS with ticks.
270+
NVIC_DisableIRQ(irq);
271+
NVIC_ClearPendingIRQ(irq);
268272
#else
269273
int irq = EVSYS_IRQn;
270274
#endif
271275

272-
NVIC_DisableIRQ(irq);
273-
NVIC_ClearPendingIRQ(irq);
274-
275276
DmacDescriptor *first_descriptor = dma_descriptor(dma_channel);
276277
setup_audio_descriptor(first_descriptor, dma->beat_size, output_spacing, output_register_address);
277278
if (single_buffer) {
@@ -366,7 +367,7 @@ STATIC void dma_callback_fun(void *arg) {
366367
audio_dma_load_next_block(dma);
367368
}
368369

369-
void evsyshandler_common(void) {
370+
void audio_evsys_handler(void) {
370371
for (uint8_t i = 0; i < AUDIO_DMA_CHANNEL_COUNT; i++) {
371372
audio_dma_t *dma = audio_dma_state[i];
372373
if (dma == NULL) {
@@ -380,26 +381,4 @@ void evsyshandler_common(void) {
380381
}
381382
}
382383

383-
#ifdef SAM_D5X_E5X
384-
void EVSYS_0_Handler(void) {
385-
evsyshandler_common();
386-
}
387-
void EVSYS_1_Handler(void) {
388-
evsyshandler_common();
389-
}
390-
void EVSYS_2_Handler(void) {
391-
evsyshandler_common();
392-
}
393-
void EVSYS_3_Handler(void) {
394-
evsyshandler_common();
395-
}
396-
void EVSYS_4_Handler(void) {
397-
evsyshandler_common();
398-
}
399-
#else
400-
void EVSYS_Handler(void) {
401-
evsyshandler_common();
402-
}
403-
#endif
404-
405384
#endif

ports/atmel-samd/audio_dma.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,6 @@ void audio_dma_background(void);
9999

100100
uint8_t find_sync_event_channel_raise(void);
101101

102+
void audio_evsys_handler(void);
103+
102104
#endif // MICROPY_INCLUDED_ATMEL_SAMD_AUDIO_DMA_H

ports/atmel-samd/common-hal/pulseio/PulseIn.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,6 @@ void pulsein_interrupt_handler(uint8_t channel) {
141141
}
142142

143143
void pulsein_reset() {
144-
#ifdef SAMD21
145-
rtc_end_pulse();
146-
#endif
147144
refcount = 0;
148145
pulsein_tc_index = 0xff;
149146
overflow_count = 0;
@@ -240,10 +237,6 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self,
240237

241238
// Set config will enable the EIC.
242239
pulsein_set_config(self, true);
243-
#ifdef SAMD21
244-
rtc_start_pulse();
245-
#endif
246-
247240
}
248241

249242
bool common_hal_pulseio_pulsein_deinited(pulseio_pulsein_obj_t *self) {
@@ -254,9 +247,6 @@ void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t *self) {
254247
if (common_hal_pulseio_pulsein_deinited(self)) {
255248
return;
256249
}
257-
#ifdef SAMD21
258-
rtc_end_pulse();
259-
#endif
260250
set_eic_handler(self->channel, EIC_HANDLER_NO_INTERRUPT);
261251
turn_off_eic_channel(self->channel);
262252
reset_pin_number(self->pin);

ports/atmel-samd/common-hal/pulseio/PulseOut.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ void pulseout_reset() {
9797
refcount = 0;
9898
pulseout_tc_index = 0xff;
9999
active_pincfg = NULL;
100-
#ifdef SAMD21
101-
rtc_end_pulse();
102-
#endif
103100
}
104101

105102
void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t *self,
@@ -168,10 +165,6 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t *self,
168165

169166
// Turn off the pinmux which should connect the port output.
170167
turn_off(self->pincfg);
171-
#ifdef SAMD21
172-
rtc_start_pulse();
173-
#endif
174-
175168
}
176169

177170
bool common_hal_pulseio_pulseout_deinited(pulseio_pulseout_obj_t *self) {
@@ -194,9 +187,6 @@ void common_hal_pulseio_pulseout_deinit(pulseio_pulseout_obj_t *self) {
194187
}
195188
self->pin = NO_PIN;
196189
common_hal_pwmio_pwmout_deinit(&self->pwmout);
197-
#ifdef SAMD21
198-
rtc_end_pulse();
199-
#endif
200190
}
201191

202192
void common_hal_pulseio_pulseout_send(pulseio_pulseout_obj_t *self, uint16_t *pulses, uint16_t length) {

0 commit comments

Comments
 (0)
0