放弃了,无法支持dma

This commit is contained in:
feng-arch 2025-10-10 14:22:23 +08:00
parent c3e391b190
commit dca783774d

View File

@ -25,6 +25,7 @@
*/
#include "py/runtime.h"
#include "py/gc.h"
#include "py/mphal.h"
#include "py/mperrno.h"
#include "shared/runtime/mpirq.h"
@ -322,6 +323,7 @@ static void machine_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj
static void machine_spi0_tx_irq_handler(void)
{
// currently only used for spi0
// mp_printf(&mp_plat_print, "program running isr spi0 tx irq %d\n", __LINE__);
machine_spi_obj_t *self = &machine_spi_obj[0];
spi_hw_t *spi_hw = spi_get_hw(self->spi_inst);
// clear the interrupt flag
@ -333,7 +335,16 @@ static void machine_spi0_tx_irq_handler(void)
if ((spi_hw->sr & (1 << 0)) && !(spi_hw->sr & (1 << 4)) && dma_channel_is_busy(self->chan_tx) == false) {
if (self->tx_isr_obj != NULL && self->tx_isr_obj->handler != mp_const_none)
{
mp_irq_handler(self->tx_isr_obj);
// mp_printf(&mp_plat_print, "program running isr spi0 tx irq %d\n", __LINE__);
if(self->tx_isr_obj->ishard){
// mp_sched_lock();
// gc_lock();
mp_call_function_1(self->tx_isr_obj->handler, self->tx_isr_obj->parent);
// gc_unlock();
// mp_sched_unlock();
} else {
mp_irq_handler(self->tx_isr_obj);
}
}
}
// }
@ -369,9 +380,11 @@ static void machine_spi_set_tx_isr(mp_obj_base_t *self_in, size_t n_args, const
enum
{
ARG_tx_isr,
ARG_hard
};
static const mp_arg_t allowed_args[] = {
{MP_QSTR_tx_isr, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = mp_const_none}},
{ MP_QSTR_hard, MP_ARG_BOOL, {.u_bool = false} },
};
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
@ -390,9 +403,10 @@ static void machine_spi_set_tx_isr(mp_obj_base_t *self_in, size_t n_args, const
self->tx_isr_obj->handler = handler;
// self->tx_isr_obj->base.type = &mp_type_irq;
// self->tx_isr_obj->methods = &mp_irq_methods;
self->tx_isr_obj->ishard = true;
self->tx_isr_obj->ishard = args[ARG_hard].u_bool;
self->tx_isr_obj->parent = MP_OBJ_FROM_PTR(self);
irq_set_exclusive_handler(self->spi_id == 0 ? SPI0_IRQ : SPI1_IRQ, self->spi_id == 0 ? machine_spi0_tx_irq_handler : machine_spi1_tx_irq_handler);
spi_hw_t *spi_hw = spi_get_hw(self->spi_inst);
spi_hw->imsc |= (1 << 3);