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

Return the number of blocks completely read when querying read completion #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/common/pico_sd_card/include/pico/sd_card.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int sd_init_1pin();
int sd_readblocks_sync(uint32_t *buf, uint32_t block, uint block_count);
int sd_readblocks_async(uint32_t *buf, uint32_t block, uint block_count);
int sd_readblocks_scatter_async(uint32_t *control_words, uint32_t block, uint block_count);
bool sd_scatter_read_complete(int *status);
bool sd_scatter_read_complete(int *status, int *blocks_complete);
int sd_writeblocks_async(const uint32_t *data, uint32_t sector_num, uint sector_count);
bool sd_write_complete(int *status);
int sd_read_sectors_1bit_crc_async(uint32_t *sector_buf, uint32_t sector, uint sector_count);
Expand Down
8 changes: 6 additions & 2 deletions src/rp2_common/pico_sd_card/sd_card.c
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ int sd_readblocks_sync(uint32_t *buf, uint32_t block, uint block_count)
if (!rc)
{
// printf("waiting for finish\n");
while (!sd_scatter_read_complete(&rc))
while (!sd_scatter_read_complete(&rc, NULL))
{
tight_loop_contents();
}
Expand Down Expand Up @@ -804,7 +804,7 @@ int sd_readblocks_scatter_async(uint32_t *control_words, uint32_t block, uint bl

int check_crc_count;

bool sd_scatter_read_complete(int *status) {
bool sd_scatter_read_complete(int *status, int *blocks_complete) {
// printf("%d:%d %d:%d %d:%d %d\n", dma_busy(sd_chain_dma_channel), (uint)dma_hw->ch[sd_chain_dma_channel].transfer_count,
// dma_busy(sd_data_dma_channel), (uint)dma_hw->ch[sd_data_dma_channel].transfer_count,
// dma_busy(sd_pio_dma_channel), (uint)dma_hw->ch[sd_pio_dma_channel].transfer_count, (uint)pio->sm[SD_DAT_SM].addr);
Expand All @@ -828,6 +828,10 @@ bool sd_scatter_read_complete(int *status) {
}
check_crc_count = 0;
}
else if (blocks_complete)
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if there should be a code-comment that blocks_complete will only be set when sd_scatter_read_complete returns false? 🤷

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I mean, I would've added a comment to the API if the API had any comments at all 🤣

{
Copy link
Contributor

Choose a reason for hiding this comment

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

brace-error 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do normally try to fit in with surrounding code's style, but I'm very much used to braces being on their own line! Will try to remember.

*blocks_complete = ((uint32_t*)dma_channel_hw_addr(sd_chain_dma_channel)->read_addr - ctrl_words) >> 2;
}
if (status) *status = s;
return rc;
}
Expand Down