Exemplo n.º 1
0
// Interrupt handler
void Handle_EXTI_Irq(uint32_t line) {
    if (__HAL_GPIO_EXTI_GET_FLAG(1 << line)) {
        __HAL_GPIO_EXTI_CLEAR_FLAG(1 << line);
        if (line < EXTI_NUM_VECTORS) {
            mp_obj_t *cb = &MP_STATE_PORT(pyb_extint_callback)[line];
            if (*cb != mp_const_none) {
                // When executing code within a handler we must lock the GC to prevent
                // any memory allocations.  We must also catch any exceptions.
                gc_lock();
                nlr_buf_t nlr;
                if (nlr_push(&nlr) == 0) {
                    mp_call_function_1(*cb, MP_OBJ_NEW_SMALL_INT(line));
                    nlr_pop();
                } else {
                    // Uncaught exception; disable the callback so it doesn't run again.
                    *cb = mp_const_none;
                    extint_disable(line);
                    printf("Uncaught exception in ExtInt interrupt handler line %lu\n", line);
                    mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val);
                }
                gc_unlock();
            }
        }
    }
}
Exemplo n.º 2
0
void pin_intr_handler(uint32_t status) {
    gc_lock();
    status &= 0xffff;
    for (int p = 0; status; ++p, status >>= 1) {
        if (status & 1) {
            mp_obj_t handler = MP_STATE_PORT(pin_irq_handler)[p];
            if (handler != MP_OBJ_NULL) {
                mp_call_function_1_protected(handler, MP_OBJ_FROM_PTR(&pyb_pin_obj[p]));
            }
        }
    }
    gc_unlock();
}
Exemplo n.º 3
0
void* simon_gc_malloc(size_t n)
{
	gc_lock();
	
	void* ptr = memory_heap_allocate(young, n);
	if (!ptr)
	{
		gc_collect();
		ptr = memory_heap_allocate(young, n);
	}
	
	gc_unlock();
	return ptr;
}
Exemplo n.º 4
0
void pyb_rtc_exec_callback(pyb_rtc_obj_t* self)
{
	// execute callback if it's set
	if (self->callback != mp_const_none) {
		// When executing code within a handler we must lock the GC to prevent
		// any memory allocations.  We must also catch any exceptions.
		gc_lock();
		nlr_buf_t nlr;
		if (nlr_push(&nlr) == 0) {
			mp_call_function_1(self->callback, self);
			nlr_pop();
		} else {
			// Uncaught exception; disable the callback so it doesn't run again.
			self->callback = mp_const_none;
			printf("uncaught exception in RTC(%u) interrupt handler\n",RTC_ID(self));
			mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val);
		}
		gc_unlock();
	}
}
Exemplo n.º 5
0
void mp_irq_handler (mp_obj_t self_in) {
    mp_irq_obj_t *self = self_in;
    if (self && self->handler != mp_const_none) {
        // when executing code within a handler we must lock the GC to prevent
        // any memory allocations.
        gc_lock();
        nlr_buf_t nlr;
        if (nlr_push(&nlr) == 0) {
            mp_call_function_1(self->handler, self->parent);
            nlr_pop();
        }
        else {
            // uncaught exception; disable the callback so that it doesn't run again
            self->methods->disable (self->parent);
            self->handler = mp_const_none;
            // signal the error using the heart beat led and
            // by printing a message
            printf("Uncaught exception in callback handler\n");
            mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val);
            mperror_signal_error();
        }
        gc_unlock();
    }
}
Exemplo n.º 6
0
void gc_collect_end(void) {
    gc_deal_with_stack_overflow();
    gc_sweep();
    gc_unlock();
}
Exemplo n.º 7
0
void gc_collect_end(void) {
    gc_deal_with_stack_overflow();
    gc_sweep();
    MP_STATE_MEM(gc_last_free_atb_index) = 0;
    gc_unlock();
}
Exemplo n.º 8
0
STATIC mp_obj_t mp_micropython_heap_unlock(void) {
    gc_unlock();
    return mp_const_none;
}
Exemplo n.º 9
0
STATIC mp_obj_t gc_enable(void) {
    gc_unlock();
    return mp_const_none;
}
Exemplo n.º 10
0
void simon_gc_yield()
{
	gc_lock();
	gc_unlock();
}
Exemplo n.º 11
0
void simon_gc_collect()
{
	gc_lock();
	gc_collect();
	gc_unlock();
}