mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-12-23 12:51:24 +01:00
I2C volatiles for critical region state
This commit is contained in:
parent
2cfcba5cb2
commit
03a2d01484
10
I2CManager.h
10
I2CManager.h
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* © 2023, Neil McKechnie. All rights reserved.
|
||||
* © 2022 Paul M Antoine
|
||||
* © 2022-2024 Paul M Antoine
|
||||
*
|
||||
* This file is part of CommandStation-EX
|
||||
*
|
||||
@ -519,14 +519,14 @@ private:
|
||||
|
||||
// State is set to I2C_STATE_FREE when the interrupt handler has finished
|
||||
// the current request and is ready to complete.
|
||||
uint8_t state = I2C_STATE_FREE;
|
||||
uint8_t volatile state = I2C_STATE_FREE;
|
||||
|
||||
// CompletionStatus may be set by the interrupt handler at any time but is
|
||||
// not written to the I2CRB until the state is I2C_STATE_FREE.
|
||||
uint8_t completionStatus = I2C_STATUS_OK;
|
||||
uint8_t overallStatus = I2C_STATUS_OK;
|
||||
uint8_t volatile completionStatus = I2C_STATUS_OK;
|
||||
uint8_t volatile overallStatus = I2C_STATUS_OK;
|
||||
|
||||
I2CRB * currentRequest = NULL;
|
||||
I2CRB * volatile currentRequest = NULL;
|
||||
uint8_t txCount = 0;
|
||||
uint8_t rxCount = 0;
|
||||
uint8_t bytesToSend = 0;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* © 2023, Neil McKechnie
|
||||
* © 2022 Paul M Antoine
|
||||
* © 2022-2024, Paul M Antoine
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of CommandStation-EX
|
||||
@ -245,8 +245,8 @@ void I2CManagerClass::checkForTimeout() {
|
||||
I2CRB *t = queueHead;
|
||||
if (state==I2C_STATE_ACTIVE && t!=0 && t==currentRequest && _timeout > 0) {
|
||||
// Check for timeout
|
||||
int32_t elapsed = micros() - startTime;
|
||||
if (elapsed > (int32_t)_timeout) {
|
||||
uint32_t elapsed = micros() - startTime;
|
||||
if (elapsed > _timeout) {
|
||||
#ifdef DIAG_IO
|
||||
//DIAG(F("I2CManager Timeout on %s"), t->i2cAddress.toString());
|
||||
#endif
|
||||
|
@ -117,11 +117,11 @@ void I2CManagerClass::I2C_setClock(uint32_t i2cClockSpeed) {
|
||||
// while (s->CR1 & I2C_CR1_STOP); // Prevents lockup by guarding further
|
||||
// writes to CR1 while STOP is being executed!
|
||||
// Should never happen, but wait for up to 500us only.
|
||||
unsigned long startTime = micros();
|
||||
uint32_t startTime = micros();
|
||||
bool timeout = false;
|
||||
while ((s->CR1 & I2C_CR1_STOP) != 0)
|
||||
{
|
||||
if ((int32_t)(micros() - startTime) >= 500) {
|
||||
if ((micros() - startTime) >= 500) {
|
||||
timeout = true;
|
||||
s->CR1 &= ~I2C_CR1_STOP;
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user