← index #896PR #738
Related · high · value 0.466
QUERY · ISSUE

Discussion about allocating memory from within an irq

openby dhylandsopened 2014-10-08updated 2024-07-19
rfcports

So I've been thinkng about this, and I think it would be possible to have some type of scratch allocator which could be used inside interrupt handlers.

The actual scratch buffer would be allocated outside of the interrupt and somehow associated with the handler.

When the handler runs it would put the registered handler on top of a list of allocators. When a memory allocation is required, it would either use the scratch allocator, or if none were present, use the heap allocator. The scrath allocator would basically just increment a pointer by the number of bytes being allocated, as long as that number of bytes still exists in the scratch buffer,

Each time the interrupt fires, it would reset the scratch buffer.

I just thought I'd throw this out as an idea.

CANDIDATE · PULL REQUEST

Add support for storing args during an exception raised by an irq.

mergedby dhylandsopened 2014-07-02updated 2014-07-29

The user code should call micropython.alloc_emergency_exception_buf(size)
where size is the size of the buffer used to print the argument
passed to the exception.

With the test code from #732, and a call to micropython.alloc_emergency_exception_buf(100) in boot.py, the following error is now printed:

>>> import heartbeat_irq
Uncaught exception in Timer(4) interrupt handler
Traceback (most recent call last):
  File "0://heartbeat_irq.py", line 14, in heartbeat_cb
NameError: name 'led' is not defined

Currently the exception handler assumes intimate knowledge of the tuple, str, and list classes. If desired, we could create functions for each of these classes which initialize the object into a previously allocated buffer.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied