ports: In machine_i2s.c, rename uasyncio to asyncio.

Mostly updates comments, but also renames the UASYNCIO enum value to
ASYNCIO.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
Jim Mussared 2023-06-08 16:14:54 +10:00 committed by Damien George
parent d975bb1f27
commit 7979a4d267
4 changed files with 45 additions and 45 deletions

View File

@ -61,9 +61,9 @@
// - a FreeRTOS task is created to implement the asynchronous background operations
// - a FreeRTOS queue is used to transfer the supplied buffer to the background task
//
// Mode3: Uasyncio
// Mode3: Asyncio
// - implements the stream protocol
// - uasyncio mode is enabled when the ioctl() function is called
// - asyncio mode is enabled when the ioctl() function is called
// - the I2S event queue is used to detect that I2S samples can be read or written from/to DMA memory
//
// The samples contained in the app buffer supplied for the readinto() and write() methods have the following convention:
@ -102,7 +102,7 @@ typedef enum {
typedef enum {
BLOCKING,
NON_BLOCKING,
UASYNCIO
ASYNCIO
} io_mode_t;
typedef enum {
@ -240,7 +240,7 @@ STATIC uint32_t fill_appbuf_from_dma(machine_i2s_obj_t *self, mp_buffer_info_t *
// copy audio samples from DMA memory to the app buffer
// audio samples are read from DMA memory in chunks
// loop, reading and copying chunks until the app buffer is filled
// For uasyncio mode, the loop will make an early exit if DMA memory becomes empty
// For asyncio mode, the loop will make an early exit if DMA memory becomes empty
// Example:
// a MicroPython I2S object is configured for 16-bit mono (2 bytes per audio sample).
// For every frame coming from DMA (8 bytes), 2 bytes are "cherry picked" and
@ -257,7 +257,7 @@ STATIC uint32_t fill_appbuf_from_dma(machine_i2s_obj_t *self, mp_buffer_info_t *
size_t num_bytes_received_from_dma = 0;
TickType_t delay;
if (self->io_mode == UASYNCIO) {
if (self->io_mode == ASYNCIO) {
delay = 0; // stop i2s_read() operation if DMA memory becomes empty
} else {
delay = portMAX_DELAY; // block until supplied buffer is filled
@ -307,7 +307,7 @@ STATIC uint32_t fill_appbuf_from_dma(machine_i2s_obj_t *self, mp_buffer_info_t *
num_bytes_needed_from_dma -= num_bytes_received_from_dma;
if ((self->io_mode == UASYNCIO) && (num_bytes_received_from_dma < num_bytes_requested_from_dma)) {
if ((self->io_mode == ASYNCIO) && (num_bytes_received_from_dma < num_bytes_requested_from_dma)) {
// Unable to fill the entire app buffer from DMA memory. This indicates all DMA RX buffers are empty.
// Clear the I2S event queue so ioctl() indicates that the I2S object cannot currently
// supply more audio samples
@ -327,7 +327,7 @@ STATIC size_t copy_appbuf_to_dma(machine_i2s_obj_t *self, mp_buffer_info_t *appb
size_t num_bytes_written = 0;
TickType_t delay;
if (self->io_mode == UASYNCIO) {
if (self->io_mode == ASYNCIO) {
delay = 0; // stop i2s_write() operation if DMA memory becomes full
} else {
delay = portMAX_DELAY; // block until supplied buffer is emptied
@ -345,14 +345,14 @@ STATIC size_t copy_appbuf_to_dma(machine_i2s_obj_t *self, mp_buffer_info_t *appb
check_esp_err(ret);
if ((self->io_mode == UASYNCIO) && (num_bytes_written < appbuf->len)) {
if ((self->io_mode == ASYNCIO) && (num_bytes_written < appbuf->len)) {
// Unable to empty the entire app buffer into DMA memory. This indicates all DMA TX buffers are full.
// Clear the I2S event queue so ioctl() indicates that the I2S object cannot currently
// accept more audio samples
xQueueReset(self->i2s_event_queue);
// Undo the swap transformation as the buffer has not been completely emptied.
// The uasyncio stream writer will use the same buffer in a future write call.
// The asyncio stream writer will use the same buffer in a future write call.
if ((self->bits == I2S_BITS_PER_SAMPLE_32BIT) && (self->format == STEREO)) {
swap_32_bit_stereo_channels(appbuf);
}
@ -729,7 +729,7 @@ STATIC mp_uint_t machine_i2s_stream_read(mp_obj_t self_in, void *buf_in, mp_uint
// send the descriptor to the task that handles non-blocking mode
xQueueSend(self->non_blocking_mode_queue, &descriptor, 0);
return size;
} else { // blocking or uasyncio mode
} else { // blocking or asyncio mode
mp_buffer_info_t appbuf;
appbuf.buf = (void *)buf_in;
appbuf.len = size;
@ -759,7 +759,7 @@ STATIC mp_uint_t machine_i2s_stream_write(mp_obj_t self_in, const void *buf_in,
// send the descriptor to the task that handles non-blocking mode
xQueueSend(self->non_blocking_mode_queue, &descriptor, 0);
return size;
} else { // blocking or uasyncio mode
} else { // blocking or asyncio mode
mp_buffer_info_t appbuf;
appbuf.buf = (void *)buf_in;
appbuf.len = size;
@ -772,7 +772,7 @@ STATIC mp_uint_t machine_i2s_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
machine_i2s_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_uint_t ret;
mp_uint_t flags = arg;
self->io_mode = UASYNCIO; // a call to ioctl() is an indication that uasyncio is being used
self->io_mode = ASYNCIO; // a call to ioctl() is an indication that asyncio is being used
if (request == MP_STREAM_POLL) {
ret = 0;

View File

@ -60,9 +60,9 @@
// - non-blocking mode is enabled when a callback is set with the irq() method
// - the DMA callback is used to implement the asynchronous background operations
//
// Mode3: Uasyncio
// Mode3: Asyncio
// - implements the stream protocol
// - uasyncio mode is enabled when the ioctl() function is called
// - asyncio mode is enabled when the ioctl() function is called
// - the state of the internal ring buffer is used to detect that I2S samples can be read or written
//
// The samples contained in the app buffer supplied for the readinto() and write() methods have the following convention:
@ -122,7 +122,7 @@ typedef enum {
typedef enum {
BLOCKING,
NON_BLOCKING,
UASYNCIO
ASYNCIO
} io_mode_t;
typedef enum {
@ -441,7 +441,7 @@ STATIC uint32_t fill_appbuf_from_ringbuf(machine_i2s_obj_t *self, mp_buffer_info
// copy audio samples from the ring buffer to the app buffer
// loop, copying samples until the app buffer is filled
// For uasyncio mode, the loop will make an early exit if the ring buffer becomes empty
// For asyncio mode, the loop will make an early exit if the ring buffer becomes empty
// Example:
// a MicroPython I2S object is configured for 16-bit mono (2 bytes per audio sample).
// For every frame coming from the ring buffer (8 bytes), 2 bytes are "cherry picked" and
@ -467,7 +467,7 @@ STATIC uint32_t fill_appbuf_from_ringbuf(machine_i2s_obj_t *self, mp_buffer_info
;
}
num_bytes_copied_to_appbuf++;
} else if (self->io_mode == UASYNCIO) {
} else if (self->io_mode == ASYNCIO) {
if (ringbuf_pop(&self->ring_buffer, app_p + r_to_a_mapping) == false) {
// ring buffer is empty, exit
goto exit;
@ -484,7 +484,7 @@ STATIC uint32_t fill_appbuf_from_ringbuf(machine_i2s_obj_t *self, mp_buffer_info
while (ringbuf_pop(&self->ring_buffer, &discard_byte) == false) {
;
}
} else if (self->io_mode == UASYNCIO) {
} else if (self->io_mode == ASYNCIO) {
if (ringbuf_pop(&self->ring_buffer, &discard_byte) == false) {
// ring buffer is empty, exit
goto exit;
@ -547,7 +547,7 @@ STATIC uint32_t copy_appbuf_to_ringbuf(machine_i2s_obj_t *self, mp_buffer_info_t
// copy audio samples from the app buffer to the ring buffer
// loop, reading samples until the app buffer is emptied
// for uasyncio mode, the loop will make an early exit if the ring buffer becomes full
// for asyncio mode, the loop will make an early exit if the ring buffer becomes full
uint32_t a_index = 0;
@ -558,7 +558,7 @@ STATIC uint32_t copy_appbuf_to_ringbuf(machine_i2s_obj_t *self, mp_buffer_info_t
;
}
a_index++;
} else if (self->io_mode == UASYNCIO) {
} else if (self->io_mode == ASYNCIO) {
if (ringbuf_push(&self->ring_buffer, ((uint8_t *)appbuf->buf)[a_index]) == false) {
// ring buffer is full, exit
break;
@ -1185,7 +1185,7 @@ STATIC mp_uint_t machine_i2s_stream_read(mp_obj_t self_in, void *buf_in, mp_uint
self->non_blocking_descriptor.index = 0;
self->non_blocking_descriptor.copy_in_progress = true;
return size;
} else { // blocking or uasyncio mode
} else { // blocking or asyncio mode
mp_buffer_info_t appbuf;
appbuf.buf = (void *)buf_in;
appbuf.len = size;
@ -1212,7 +1212,7 @@ STATIC mp_uint_t machine_i2s_stream_write(mp_obj_t self_in, const void *buf_in,
self->non_blocking_descriptor.index = 0;
self->non_blocking_descriptor.copy_in_progress = true;
return size;
} else { // blocking or uasyncio mode
} else { // blocking or asyncio mode
mp_buffer_info_t appbuf;
appbuf.buf = (void *)buf_in;
appbuf.len = size;
@ -1225,7 +1225,7 @@ STATIC mp_uint_t machine_i2s_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
machine_i2s_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_uint_t ret;
uintptr_t flags = arg;
self->io_mode = UASYNCIO; // a call to ioctl() is an indication that uasyncio is being used
self->io_mode = ASYNCIO; // a call to ioctl() is an indication that asyncio is being used
if (request == MP_STREAM_POLL) {
ret = 0;

View File

@ -57,9 +57,9 @@
// - non-blocking mode is enabled when a callback is set with the irq() method
// - the DMA IRQ handler is used to implement the asynchronous background operations
//
// Mode3: Uasyncio
// Mode3: Asyncio
// - implements the stream protocol
// - uasyncio mode is enabled when the ioctl() function is called
// - asyncio mode is enabled when the ioctl() function is called
// - the state of the internal ring buffer is used to detect that I2S samples can be read or written
//
// The samples contained in the app buffer supplied for the readinto() and write() methods have the following convention:
@ -112,7 +112,7 @@ typedef enum {
typedef enum {
BLOCKING,
NON_BLOCKING,
UASYNCIO
ASYNCIO
} io_mode_t;
typedef enum {
@ -307,7 +307,7 @@ STATIC uint32_t fill_appbuf_from_ringbuf(machine_i2s_obj_t *self, mp_buffer_info
// copy audio samples from the ring buffer to the app buffer
// loop, copying samples until the app buffer is filled
// For uasyncio mode, the loop will make an early exit if the ring buffer becomes empty
// For asyncio mode, the loop will make an early exit if the ring buffer becomes empty
// Example:
// a MicroPython I2S object is configured for 16-bit mono (2 bytes per audio sample).
// For every frame coming from the ring buffer (8 bytes), 2 bytes are "cherry picked" and
@ -333,7 +333,7 @@ STATIC uint32_t fill_appbuf_from_ringbuf(machine_i2s_obj_t *self, mp_buffer_info
;
}
num_bytes_copied_to_appbuf++;
} else if (self->io_mode == UASYNCIO) {
} else if (self->io_mode == ASYNCIO) {
if (ringbuf_pop(&self->ring_buffer, app_p + r_to_a_mapping) == false) {
// ring buffer is empty, exit
goto exit;
@ -350,7 +350,7 @@ STATIC uint32_t fill_appbuf_from_ringbuf(machine_i2s_obj_t *self, mp_buffer_info
while (ringbuf_pop(&self->ring_buffer, &discard_byte) == false) {
;
}
} else if (self->io_mode == UASYNCIO) {
} else if (self->io_mode == ASYNCIO) {
if (ringbuf_pop(&self->ring_buffer, &discard_byte) == false) {
// ring buffer is empty, exit
goto exit;
@ -413,7 +413,7 @@ STATIC uint32_t copy_appbuf_to_ringbuf(machine_i2s_obj_t *self, mp_buffer_info_t
// copy audio samples from the app buffer to the ring buffer
// loop, reading samples until the app buffer is emptied
// for uasyncio mode, the loop will make an early exit if the ring buffer becomes full
// for asyncio mode, the loop will make an early exit if the ring buffer becomes full
uint32_t a_index = 0;
@ -424,7 +424,7 @@ STATIC uint32_t copy_appbuf_to_ringbuf(machine_i2s_obj_t *self, mp_buffer_info_t
;
}
a_index++;
} else if (self->io_mode == UASYNCIO) {
} else if (self->io_mode == ASYNCIO) {
if (ringbuf_push(&self->ring_buffer, ((uint8_t *)appbuf->buf)[a_index]) == false) {
// ring buffer is full, exit
break;
@ -1056,7 +1056,7 @@ STATIC mp_uint_t machine_i2s_stream_read(mp_obj_t self_in, void *buf_in, mp_uint
self->non_blocking_descriptor.index = 0;
self->non_blocking_descriptor.copy_in_progress = true;
return size;
} else { // blocking or uasyncio mode
} else { // blocking or asyncio mode
mp_buffer_info_t appbuf;
appbuf.buf = (void *)buf_in;
appbuf.len = size;
@ -1083,7 +1083,7 @@ STATIC mp_uint_t machine_i2s_stream_write(mp_obj_t self_in, const void *buf_in,
self->non_blocking_descriptor.index = 0;
self->non_blocking_descriptor.copy_in_progress = true;
return size;
} else { // blocking or uasyncio mode
} else { // blocking or asyncio mode
mp_buffer_info_t appbuf;
appbuf.buf = (void *)buf_in;
appbuf.len = size;
@ -1096,7 +1096,7 @@ STATIC mp_uint_t machine_i2s_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
machine_i2s_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_uint_t ret;
uintptr_t flags = arg;
self->io_mode = UASYNCIO; // a call to ioctl() is an indication that uasyncio is being used
self->io_mode = ASYNCIO; // a call to ioctl() is an indication that asyncio is being used
if (request == MP_STREAM_POLL) {
ret = 0;

View File

@ -55,9 +55,9 @@
// - non-blocking mode is enabled when a callback is set with the irq() method
// - the DMA callbacks (1/2 complete and complete) are used to implement the asynchronous background operations
//
// Mode3: Uasyncio
// Mode3: Asyncio
// - implements the stream protocol
// - uasyncio mode is enabled when the ioctl() function is called
// - asyncio mode is enabled when the ioctl() function is called
// - the state of the internal ring buffer is used to detect that I2S samples can be read or written
//
// The samples contained in the app buffer supplied for the readinto() and write() methods have the following convention:
@ -104,7 +104,7 @@ typedef enum {
typedef enum {
BLOCKING,
NON_BLOCKING,
UASYNCIO
ASYNCIO
} io_mode_t;
typedef enum {
@ -287,7 +287,7 @@ STATIC uint32_t fill_appbuf_from_ringbuf(machine_i2s_obj_t *self, mp_buffer_info
// copy audio samples from the ring buffer to the app buffer
// loop, copying samples until the app buffer is filled
// For uasyncio mode, the loop will make an early exit if the ring buffer becomes empty
// For asyncio mode, the loop will make an early exit if the ring buffer becomes empty
// Example:
// a MicroPython I2S object is configured for 16-bit mono (2 bytes per audio sample).
// For every frame coming from the ring buffer (8 bytes), 2 bytes are "cherry picked" and
@ -313,7 +313,7 @@ STATIC uint32_t fill_appbuf_from_ringbuf(machine_i2s_obj_t *self, mp_buffer_info
;
}
num_bytes_copied_to_appbuf++;
} else if (self->io_mode == UASYNCIO) {
} else if (self->io_mode == ASYNCIO) {
if (ringbuf_pop(&self->ring_buffer, app_p + r_to_a_mapping) == false) {
// ring buffer is empty, exit
goto exit;
@ -330,7 +330,7 @@ STATIC uint32_t fill_appbuf_from_ringbuf(machine_i2s_obj_t *self, mp_buffer_info
while (ringbuf_pop(&self->ring_buffer, &discard_byte) == false) {
;
}
} else if (self->io_mode == UASYNCIO) {
} else if (self->io_mode == ASYNCIO) {
if (ringbuf_pop(&self->ring_buffer, &discard_byte) == false) {
// ring buffer is empty, exit
goto exit;
@ -393,7 +393,7 @@ STATIC uint32_t copy_appbuf_to_ringbuf(machine_i2s_obj_t *self, mp_buffer_info_t
// copy audio samples from the app buffer to the ring buffer
// loop, reading samples until the app buffer is emptied
// for uasyncio mode, the loop will make an early exit if the ring buffer becomes full
// for asyncio mode, the loop will make an early exit if the ring buffer becomes full
uint32_t a_index = 0;
@ -404,7 +404,7 @@ STATIC uint32_t copy_appbuf_to_ringbuf(machine_i2s_obj_t *self, mp_buffer_info_t
;
}
a_index++;
} else if (self->io_mode == UASYNCIO) {
} else if (self->io_mode == ASYNCIO) {
if (ringbuf_push(&self->ring_buffer, ((uint8_t *)appbuf->buf)[a_index]) == false) {
// ring buffer is full, exit
break;
@ -1033,7 +1033,7 @@ STATIC mp_uint_t machine_i2s_stream_read(mp_obj_t self_in, void *buf_in, mp_uint
self->non_blocking_descriptor.index = 0;
self->non_blocking_descriptor.copy_in_progress = true;
return size;
} else { // blocking or uasyncio mode
} else { // blocking or asyncio mode
mp_buffer_info_t appbuf;
appbuf.buf = (void *)buf_in;
appbuf.len = size;
@ -1060,7 +1060,7 @@ STATIC mp_uint_t machine_i2s_stream_write(mp_obj_t self_in, const void *buf_in,
self->non_blocking_descriptor.index = 0;
self->non_blocking_descriptor.copy_in_progress = true;
return size;
} else { // blocking or uasyncio mode
} else { // blocking or asyncio mode
mp_buffer_info_t appbuf;
appbuf.buf = (void *)buf_in;
appbuf.len = size;
@ -1073,7 +1073,7 @@ STATIC mp_uint_t machine_i2s_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
machine_i2s_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_uint_t ret;
uintptr_t flags = arg;
self->io_mode = UASYNCIO; // a call to ioctl() is an indication that uasyncio is being used
self->io_mode = ASYNCIO; // a call to ioctl() is an indication that asyncio is being used
if (request == MP_STREAM_POLL) {
ret = 0;