Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i2s: Add an nrfx-based implementation for Nordic ICs #19436

Closed

Conversation

adamkondraciuk
Copy link
Contributor

@adamkondraciuk
Copy link
Contributor Author

@kl-cruz @barsok - please review

@carlescufi
Copy link
Member

@adamkondraciuk thanks for the PR. Could you perhaps take the .pdf and convert it to a combination of .rst and .png that we could place somewhere in doc? Otherwise we just leave it out of the PR and that's fine too.

@zephyrbot
Copy link
Collaborator

zephyrbot commented Sep 27, 2019

All checks are passing now.

Tip: The bot edits this comment instead of posting a new one, so you can check the comment's history to see earlier messages.

@carlescufi
Copy link
Member

@adamkondraciuk thanks for the PR. Could you perhaps take the .pdf and convert it to a combination of .rst and .png that we could place somewhere in doc? Otherwise we just leave it out of the PR and that's fine too.

On second thought, we don't really have anywhere to place this kind of documentation today, and it would probably be very difficult to keep it updated, so let's not include it in the Pull Request

drivers/i2s/i2s_nrfx.c Outdated Show resolved Hide resolved
Copy link
Member

@anangl anangl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of initial comments. More to come.

drivers/i2s/Kconfig.nrfx Outdated Show resolved Hide resolved
drivers/i2s/Kconfig.nrfx Outdated Show resolved Hide resolved
drivers/i2s/i2s_nrfx.h Outdated Show resolved Hide resolved
drivers/i2s/i2s_nrfx.c Show resolved Hide resolved
drivers/i2s/i2s_nrfx.c Outdated Show resolved Hide resolved
drivers/i2s/i2s_nrfx.c Outdated Show resolved Hide resolved
drivers/i2s/i2s_nrfx.c Outdated Show resolved Hide resolved
drivers/i2s/i2s_nrfx.c Outdated Show resolved Hide resolved
drivers/i2s/i2s_nrfx.c Outdated Show resolved Hide resolved
drivers/i2s/i2s_nrfx.c Outdated Show resolved Hide resolved
drivers/i2s/i2s_nrfx.c Outdated Show resolved Hide resolved
drivers/i2s/i2s_nrfx.c Outdated Show resolved Hide resolved
drivers/i2s/i2s_nrfx.c Outdated Show resolved Hide resolved
drivers/i2s/i2s_nrfx.c Outdated Show resolved Hide resolved
drivers/i2s/i2s_nrfx.c Outdated Show resolved Hide resolved
drivers/i2s/i2s_nrfx.c Outdated Show resolved Hide resolved
drivers/i2s/i2s_nrfx.c Outdated Show resolved Hide resolved
drivers/i2s/i2s_nrfx.c Outdated Show resolved Hide resolved
drivers/i2s/i2s_nrfx.c Outdated Show resolved Hide resolved
drivers/i2s/i2s_nrfx.c Outdated Show resolved Hide resolved
drivers/i2s/i2s_nrfx.c Outdated Show resolved Hide resolved
drivers/i2s/i2s_nrfx.c Outdated Show resolved Hide resolved
drivers/i2s/i2s_nrfx.c Outdated Show resolved Hide resolved
drivers/i2s/i2s_nrfx.c Outdated Show resolved Hide resolved
drivers/i2s/i2s_nrfx.h Show resolved Hide resolved
drivers/i2s/i2s_nrfx.c Outdated Show resolved Hide resolved
drivers/i2s/i2s_nrfx.c Outdated Show resolved Hide resolved
drivers/i2s/i2s_nrfx.c Outdated Show resolved Hide resolved
drivers/i2s/i2s_nrfx.c Outdated Show resolved Hide resolved
drivers/i2s/i2s_nrfx.c Outdated Show resolved Hide resolved
@@ -176,6 +176,8 @@
/drivers/i2c/i2c_rv32m1_lpi2c* @henrikbrixandersen
/drivers/i2c/*sam0* @Sizurka
/drivers/i2c/i2c_dw* @gnuless
/drivers/i2s/Kconfig.nrfx @adamkondraciuk
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some example code you can add as well? Having a sample that e.g. sends incremental numbers over I2S would greatly assist developers in getting started.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some example code you can add as well? Having a sample that e.g. sends incremental numbers over I2S would greatly assist developers in getting started.

I'll push it as another PR after driver review

drivers/i2s/i2s_nrfx.c Outdated Show resolved Hide resolved
drivers/i2s/i2s_nrfx.c Outdated Show resolved Hide resolved
drivers/i2s/i2s_nrfx.c Outdated Show resolved Hide resolved
drivers/i2s/i2s_nrfx.c Outdated Show resolved Hide resolved
drivers/i2s/i2s_nrfx.c Show resolved Hide resolved
drivers/i2s/i2s_nrfx.c Outdated Show resolved Hide resolved
drivers/i2s/i2s_nrfx.c Outdated Show resolved Hide resolved
{ \
IRQ_CONNECT(DT_NORDIC_NRF_I2S_I2S_##idx##_IRQ_0, \
DT_NORDIC_NRF_I2S_I2S_##idx##_IRQ_0_PRIORITY, \
isr, DEVICE_GET(i2s_##idx), 0); \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use:

Suggested change
isr, DEVICE_GET(i2s_##idx), 0); \
nrfx_isr, nrfx_i2s_irq_handler, 0); \

and remove the isr function.

* next to be transferred (content of 'TXD.PTR' register).
* Status parameter informs about handler execution reason:
* - if 1 - next buffer is needed
* - if 0 - transfer is finishing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not guaranteed. nrfx_i2s API does not specify it so.

struct channel_str *ch_rx = &i2s->channel_rx;
int ret;

if (p_released->p_rx_buffer != NULL && next_buffers_needed(status)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p_released itself may also be NULL, see nrfx_i2s.h.

* - allocates new rx buffer for next transfer purpose
* Status parameter informs about handler execution reason:
* - if 1 - next buffer is needed
* - if 0 - transfer is finishing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not guaranteed. nrfx_i2s API does not specify it so.

}
return;
}
if (p_released->p_tx_buffer != NULL) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p_released itself may also be NULL, see nrfx_i2s.h.

if (p_released->p_rx_buffer != NULL && next_buffers_needed(status)) {
/* Content of received buffer is valuable.
* If 'EVENT_STOPPED' generated 'then next_buffers_needed()'
* returns false - function 'channel_rx_store_data()' won't
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to use some different logic here. next_buffers_needed() returns false when the event handler was called without the driver's request of next buffers, what does not necessarily mean that the STOPPED event has been generated. nrfx_i2s API does not specify it this way, so you cannot rely on it.

next_buffers_needed(status)) {
/* when interface needs to be restarted and
* last event was 'EVENT_STOPPED' then we don't
* free this buffer - it will be used after
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in channel_rx_callback, you cannot use next_buffers_needed to check if the transfer was stopped.

} else {
if (p_released->p_rx_buffer) {
ret = channel_rx_store_data(i2s,
(u32_t **)&p_released->p_rx_buffer);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part of code needs to be described. For instance, why is this data stored only when next buffers were not requested by the nrfx_i2s driver?

break;
default:
channel_change_state(ch_tx, I2S_STATE_ERROR);
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part of code needs to be described as well, and perhaps reworked. Currently, it is too hard to understand what is actually going on here. For instance, what happens with mem_block here (when the error is signaled)? When will it get freed?

}

static void channel_tx_mem_clear(struct i2s_nrfx_data *i2s,
void const *first_block)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is called only from two places, and only once it is called with first_block not being NULL. Why not free this first block right there, get rid of this parameter, and thus seriously simplify whole this function?

Changed board definitions to use I2S driver

Signed-off-by: Adam Kondraciuk <adam.kondraciuk@nordicsemi.no>
Translation layer to make I2S drivers work with Zephyr API.
This shim is provided only for master-stereo transmission

Signed-off-by: Adam Kondraciuk <adam.kondraciuk@nordicsemi.no>
@mnkp
Copy link
Member

mnkp commented Dec 30, 2019

Since i2s interface and API are quite complex this driver should be tested with tests/drivers/i2s/ tests. Unfortunately, the tests assume that the driver supports I2S_OPT_LOOPBACK flag. They need to be modified to support also hardware loopback mode.

@koffes
Copy link
Collaborator

koffes commented Feb 21, 2020

The driver has a function called interface_error_service(struct i2s_nrfx_data *i2s, const char * const err_msg).
It would be great if this instead of taking a string could take some form of int .
This function may then again be used to alert the application in some way. We are in a position where we need to get updates of TX underruns and RX overruns.

@github-actions github-actions bot added has-conflicts Issue/PR has conflicts with another issue/PR area: Device Tree labels Jun 29, 2020
@github-actions github-actions bot added has-conflicts Issue/PR has conflicts with another issue/PR and removed has-conflicts Issue/PR has conflicts with another issue/PR labels Jul 1, 2020
@nashif nashif added the Stale label Sep 4, 2020
@github-actions github-actions bot closed this Sep 19, 2020
@anangl
Copy link
Member

anangl commented Apr 13, 2021

This PR has been superseded by #34251.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants