Skip to content

spi: sam0: fix txrx, NULL buffers, and add a stub async method. #5731

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

Merged
merged 2 commits into from
Feb 5, 2018

Conversation

nzmichaelh
Copy link
Collaborator

This gives better coverage on the SAM0 by exercising the RX only
paths.

The benchmark is a simple transcive-big-blocks-in-a-loop. This is
useful for the SAM0 as the driver is CPU based and the benchmark shows
how close the driver gets to peak throughput.

Signed-off-by: Michael Hope [email protected]

@codecov-io
Copy link

codecov-io commented Jan 18, 2018

Codecov Report

Merging #5731 into master will increase coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5731      +/-   ##
==========================================
+ Coverage   54.04%   54.05%   +<.01%     
==========================================
  Files         461      461              
  Lines       43743    43743              
  Branches     8369     8369              
==========================================
+ Hits        23642    23645       +3     
+ Misses      19960    19957       -3     
  Partials      141      141
Impacted Files Coverage Δ
tests/kernel/obj_tracing/src/philosopher.c 88.88% <0%> (+16.66%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1c08d4f...9802bfe. Read the comment docs.

@sknsean
Copy link
Contributor

sknsean commented Jan 20, 2018

LGTM 👍

@@ -146,7 +146,9 @@ static void spi_sam0_shift_master(SercomSpi *regs, struct spi_sam0_data *data)
rx = regs->DATA.reg;

if (spi_context_rx_on(&data->ctx)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this check needed anymore?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yip, it's needed. The SPI API supports discarding a block by setting .buf to NULL and .len to the block length. spi_context_rx_on returns true if .buf is not null or .len is not zero.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If .buf is null and .len is zero, "nothing" will be executed inside the if block.
If .buf is null and .len is not zero, "only" spi_context_update_rx will be executed inside the if block.
If .buf is not null and .len is zero, *data->ctx.rx_buf = rx; will be executed and spi_context_update_rx will return inside the if block.
If .buf is not null and .len is not zero, both *data->ctx.rx_buf = rx; and spi_context_update_rx will be executed.

I think that

if (spi_context_rx_on(&data->ctx)) {
    if (data->ctx.rx_buf != NULL) {
        *data->ctx.rx_buf = rx;
    }
    spi_context_update_rx(&data->ctx, 1, 1);
}

is the same with

if (data->ctx.rx_buf != NULL) {
    *data->ctx.rx_buf = rx;
}
spi_context_update_rx(&data->ctx, 1, 1);

Am I missing something?

Copy link
Collaborator

@tbursztyka tbursztyka Jan 23, 2018

Choose a reason for hiding this comment

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

Original code is actually right.

Sounds like what I did with spi_context_rx_on() is a bit flawed.
If buf != NULL but len == 0: we really don't want to store anything (this could lead to a buffer overflow).

rx is on if only len > 0 in fact. (since the 2 valid cases are : (buf && len) || (!buf && len), factorized: testing len is sufficient).

[edit] Guys, check PR #5785

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note: I'll wait on the result of #5785.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@tbursztyka I've updated after #5785. PTAL.

@galak galak added area: SPI SPI bus platform: Microchip SAM Microchip SAM Platform (formerly Atmel SAM) labels Jan 31, 2018
This patches fixes a few bugs with the SAM0 driver:

- txrx was trasnmitting too many bytes
- adds support for NULL buffers to the fast paths
- fixes a NULL dereference on the rx buffer slow path

The tests under tests/driver/spi/spi_loopback now pass.

Signed-off-by: Michael Hope <[email protected]>
Used to test the recent driver updates.

Signed-off-by: Michael Hope <[email protected]>
@nashif nashif merged commit e13e90f into zephyrproject-rtos:master Feb 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: SPI SPI bus platform: Microchip SAM Microchip SAM Platform (formerly Atmel SAM)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants