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

ACAN_ESP32: Add ACAN_ESP32::end() to stop the controller and remove ISR #15

Open
wants to merge 1 commit into
base: main
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
19 changes: 19 additions & 0 deletions src/ACAN_ESP32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,25 @@ uint32_t ACAN_ESP32::begin (const ACAN_ESP32_Settings & inSettings,
return errorCode ;
}

//----------------------------------------------------------------------------------------
// Stop CAN controller and uninstall ISR
//----------------------------------------------------------------------------------------

void ACAN_ESP32::end (void) {
//--------------------------------- Abort any pending transfer, don't care about resetting
TWAI_CMD_REG = TWAI_ABORT_TX ;

//--------------------------------- Disable Interupts
TWAI_INT_ENA_REG = 0 ;
if (mInterruptHandler != nullptr) {
esp_intr_free (mInterruptHandler) ;
mInterruptHandler = nullptr ;
}

//--------------------------------- Disable CAN module
periph_module_disable (PERIPH_TWAI_MODULE) ;
}

//----------------------------------------------------------------------------------------
//--- Status Flags (returns 0 if no error)
// Bit 0 : hardware receive FIFO overflow
Expand Down
5 changes: 5 additions & 0 deletions src/ACAN_ESP32.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class ACAN_ESP32 {
public: uint32_t begin (const ACAN_ESP32_Settings & inSettings,
const ACAN_ESP32_Filter & inFilterSettings = ACAN_ESP32_Filter::acceptAll ()) ;

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Deinit: Stop CAN controller and uninstall ISR
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public: void end (void) ;

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// CAN Configuration Private Methods
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down