-
Notifications
You must be signed in to change notification settings - Fork 952
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
I2C abort reason #1370
Open
peterharperuk
wants to merge
1
commit into
raspberrypi:develop
Choose a base branch
from
peterharperuk:add_last_abort_reason
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
I2C abort reason #1370
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,6 +130,15 @@ void i2c_set_slave_mode(i2c_inst_t *i2c, bool slave, uint8_t addr) { | |
i2c->hw->enable = 1; | ||
} | ||
|
||
// PICO_CONFIG: PICO_I2C_RETURN_ABORT_REASON, change i2c functions to return the abort reason via a return code less than or equal to PICO_ERROR_ABORT, type=bool, default=0, group=harware_i2c | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
#if PICO_I2C_RETURN_ABORT_REASON | ||
// if (ret <= PICO_ERROR_ABORT) abort_reason = PICO_ERROR_ABORT - ret; // one of I2C_IC_TX_ABRT_SOURCE_ABRT_*_LSB | ||
#define PICO_I2C_MAKE_ABORT_ERROR(A) (PICO_ERROR_ABORT - __builtin_ctz(A)) | ||
#else | ||
// By default, for compatibility, return PICO_ERROR_GENERIC if an abort occurs | ||
#define PICO_I2C_MAKE_ABORT_ERROR(A) PICO_ERROR_GENERIC | ||
#endif | ||
|
||
static int i2c_write_blocking_internal(i2c_inst_t *i2c, uint8_t addr, const uint8_t *src, size_t len, bool nostop, | ||
check_timeout_fn timeout_check, struct timeout_state *ts) { | ||
invalid_params_if(HARDWARE_I2C, addr >= 0x80); // 7-bit addresses | ||
|
@@ -225,13 +234,13 @@ static int i2c_write_blocking_internal(i2c_inst_t *i2c, uint8_t addr, const uint | |
else if (!abort_reason || abort_reason & I2C_IC_TX_ABRT_SOURCE_ABRT_7B_ADDR_NOACK_BITS) { | ||
// No reported errors - seems to happen if there is nothing connected to the bus. | ||
// Address byte not acknowledged | ||
rval = PICO_ERROR_GENERIC; | ||
rval = PICO_I2C_MAKE_ABORT_ERROR(I2C_IC_TX_ABRT_SOURCE_ABRT_7B_ADDR_NOACK_BITS); | ||
} else if (abort_reason & I2C_IC_TX_ABRT_SOURCE_ABRT_TXDATA_NOACK_BITS) { | ||
// Address acknowledged, some data not acknowledged | ||
rval = byte_ctr; | ||
} else { | ||
//panic("Unknown abort from I2C instance @%08x: %08x\n", (uint32_t) i2c->hw, abort_reason); | ||
rval = PICO_ERROR_GENERIC; | ||
rval = PICO_I2C_MAKE_ABORT_ERROR(abort_reason); | ||
} | ||
} else { | ||
rval = byte_ctr; | ||
|
@@ -319,10 +328,10 @@ static int i2c_read_blocking_internal(i2c_inst_t *i2c, uint8_t addr, uint8_t *ds | |
else if (!abort_reason || abort_reason & I2C_IC_TX_ABRT_SOURCE_ABRT_7B_ADDR_NOACK_BITS) { | ||
// No reported errors - seems to happen if there is nothing connected to the bus. | ||
// Address byte not acknowledged | ||
rval = PICO_ERROR_GENERIC; | ||
rval = PICO_I2C_MAKE_ABORT_ERROR(I2C_IC_TX_ABRT_SOURCE_ABRT_7B_ADDR_NOACK_BITS); | ||
} else { | ||
// panic("Unknown abort from I2C instance @%08x: %08x\n", (uint32_t) i2c->hw, abort_reason); | ||
rval = PICO_ERROR_GENERIC; | ||
rval = PICO_I2C_MAKE_ABORT_ERROR(abort_reason); | ||
} | ||
} else { | ||
rval = byte_ctr; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: "requires resourcesw" -> "required resources"