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

add function IRAM address verifier, use it with SPISlave:: #5941

Closed
wants to merge 1 commit into from
Closed
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
15 changes: 12 additions & 3 deletions cores/esp8266/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,23 @@

void ICACHE_RAM_ATTR hexdump(const void *mem, uint32_t len, uint8_t cols) {
const uint8_t* src = (const uint8_t*) mem;
os_printf("\n[HEXDUMP] Address: 0x%08X len: 0x%X (%d)", (ptrdiff_t)src, len, len);
::printf((PGM_P)F("\n[HEXDUMP] Address: 0x%08X len: 0x%X (%d)"), (ptrdiff_t)src, len, len);
for(uint32_t i = 0; i < len; i++) {
if(i % cols == 0) {
os_printf("\n[0x%08X] 0x%08X: ", (ptrdiff_t)src, i);
::printf((PGM_P)F("\n[0x%08X] 0x%08X: "), (ptrdiff_t)src, i);
yield();
}
os_printf("%02X ", *src);
::printf((PGM_P)F("%02X "), *src);
src++;
}
os_printf("\n");
}

#ifndef NDEBUG
void assert_iram (uintptr_t address) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Arg should be const

if (address < 0x40100000 || address >= 0x40110000) {
::printf((PGM_P)F("all ISR must be in IRAM with ICACHE_RAM_ATTR\r\n"));
panic();
}
}
#endif
6 changes: 6 additions & 0 deletions cores/esp8266/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,11 @@ void __panic_func(const char* file, int line, const char* func) __attribute__((n
}
#endif

#ifdef NDEBUG
void assert_iram (uintptr_t iram_function_addr) { }
#else
void assert_iram (uintptr_t iram_function_addr);
#endif
#define check_function_is_in_iram(f) do { assert_iram((intptr_t)f); } while (0)

#endif//ARD_DEBUG_H
4 changes: 4 additions & 0 deletions libraries/SPISlave/src/SPISlave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,22 @@ void SPISlaveClass::setStatus(uint32_t status)
}
void SPISlaveClass::onData(SpiSlaveDataHandler cb)
{
check_function_is_in_iram(cb);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't look right, the handler arg is received by value. Same for the other cases below.

_data_cb = cb;
}
void SPISlaveClass::onDataSent(SpiSlaveSentHandler cb)
{
check_function_is_in_iram(cb);
_data_sent_cb = cb;
}
void SPISlaveClass::onStatus(SpiSlaveStatusHandler cb)
{
check_function_is_in_iram(cb);
_status_cb = cb;
}
void SPISlaveClass::onStatusSent(SpiSlaveSentHandler cb)
{
check_function_is_in_iram(cb);
_status_sent_cb = cb;
}

Expand Down