Skip to content

put inline helpers in IRAM for slave ISRs [issue 6875] #6894

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

Closed
wants to merge 3 commits into from
Closed
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
39 changes: 20 additions & 19 deletions cores/esp8266/core_esp8266_si2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,31 +95,32 @@ class Twi
unsigned char read_byte(bool nack);
void ICACHE_RAM_ATTR onTwipEvent(uint8_t status);

// Inline helpers
inline void SDA_LOW()
// !Inline helpers (linker doesn't bring them inline)
ICACHE_RAM_ATTR void SDA_LOW()
{
GPES = (1 << twi_sda);
}
inline void SDA_HIGH()
ICACHE_RAM_ATTR void SDA_HIGH()
{
GPEC = (1 << twi_sda);
}
inline bool SDA_READ()
ICACHE_RAM_ATTR bool SDA_READ()
{
return (GPI & (1 << twi_sda)) != 0;
}
inline void SCL_LOW()
ICACHE_RAM_ATTR void SCL_LOW()
{
GPES = (1 << twi_scl);
}
inline void SCL_HIGH()
ICACHE_RAM_ATTR void SCL_HIGH()
{
GPEC = (1 << twi_scl);
}
inline bool SCL_READ()
ICACHE_RAM_ATTR bool SCL_READ()
{
return (GPI & (1 << twi_scl)) != 0;
}

// Handle the case where a slave needs to stretch the clock with a time-limited busy wait
inline void WAIT_CLOCK_STRETCH()
{
Expand Down Expand Up @@ -439,6 +440,14 @@ unsigned char Twi::readFrom(unsigned char address, unsigned char* buf, unsigned
return 0;
}

void Twi::twi_scl_valley(void)
{
SCL_LOW();
busywait(twi_dcount);
SCL_HIGH();
WAIT_CLOCK_STRETCH();
}

uint8_t Twi::status()
{
WAIT_CLOCK_STRETCH(); // wait for a slow slave to finish
Expand Down Expand Up @@ -650,14 +659,6 @@ void ICACHE_RAM_ATTR Twi::onTwipEvent(uint8_t status)
}
}

void Twi::twi_scl_valley(void)
{
SCL_LOW();
busywait(twi_dcount);
SCL_HIGH();
WAIT_CLOCK_STRETCH();
}

void ICACHE_RAM_ATTR Twi::onTimer(void *unused)
{
(void)unused;
Expand Down Expand Up @@ -714,8 +715,8 @@ void ICACHE_RAM_ATTR Twi::onSclChange(void)
unsigned int scl;

// Store bool return in int to reduce final code size.
sda = twi.SDA_READ();
scl = twi.SCL_READ();
sda = (GPI & (1 << twi.twi_sda)) != 0; // SDA_READ() fast, no time for a call
scl = (GPI & (1 << twi.twi_scl)) != 0; // SCL_READ()

twi.twip_status = 0xF8; // reset TWI status

Expand Down Expand Up @@ -911,8 +912,8 @@ void ICACHE_RAM_ATTR Twi::onSdaChange(void)
unsigned int scl;

// Store bool return in int to reduce final code size.
sda = twi.SDA_READ();
scl = twi.SCL_READ();
sda = (GPI & (1 << twi.twi_sda)) != 0; // SDA_READ()
scl = (GPI & (1 << twi.twi_scl)) != 0; // SCL_READ()

int twip_state_mask = S2M(twi.twip_state);
if (scl) /* !DATA */
Expand Down