Preventing UB in wireless and mobile examples after disabling the adapter

This commit is contained in:
Rodrigo Alfonso
2024-08-15 21:39:02 -03:00
parent 9d5ede98ee
commit 36efafde17
3 changed files with 26 additions and 33 deletions

View File

@@ -26,8 +26,6 @@ void init() {
int main() {
init();
bool firstTime = true;
start:
// Options
log("LinkMobile_demo (v7.0.0)\n\n"
@@ -37,18 +35,14 @@ start:
// (1) Create a LinkMobile instance
linkMobile = new LinkMobile();
if (firstTime) {
// (2) Add the required interrupt service routines
interrupt_init();
interrupt_set_handler(INTR_VBLANK, LINK_MOBILE_ISR_VBLANK);
interrupt_enable(INTR_VBLANK);
interrupt_set_handler(INTR_SERIAL, LINK_MOBILE_ISR_SERIAL);
interrupt_enable(INTR_SERIAL);
interrupt_set_handler(INTR_TIMER3, LINK_MOBILE_ISR_TIMER);
interrupt_enable(INTR_TIMER3);
firstTime = false;
}
// (2) Add the required interrupt service routines
interrupt_init();
interrupt_set_handler(INTR_VBLANK, LINK_MOBILE_ISR_VBLANK);
interrupt_enable(INTR_VBLANK);
interrupt_set_handler(INTR_SERIAL, LINK_MOBILE_ISR_SERIAL);
interrupt_enable(INTR_SERIAL);
interrupt_set_handler(INTR_TIMER3, LINK_MOBILE_ISR_TIMER);
interrupt_enable(INTR_TIMER3);
// (3) Initialize the library
linkMobile->activate();
@@ -67,6 +61,9 @@ start:
// SELECT = back
if (keys & KEY_SELECT) {
linkMobile->deactivate();
interrupt_disable(INTR_VBLANK);
interrupt_disable(INTR_SERIAL);
interrupt_disable(INTR_TIMER3);
delete linkMobile;
linkMobile = NULL;
goto start;

View File

@@ -43,8 +43,6 @@ void init() {
int main() {
init();
bool firstTime = true;
start:
// Options
log("LinkWireless_demo (v7.0.0)\n\n\n\n"
@@ -67,22 +65,18 @@ start:
LINK_WIRELESS_DEFAULT_SEND_TIMER_ID, asyncACK ? 0 : -1);
// linkWireless->debug = [](std::string str) { log(str); };
if (firstTime) {
// (2) Add the required interrupt service routines
interrupt_init();
interrupt_set_handler(INTR_VBLANK, LINK_WIRELESS_ISR_VBLANK);
interrupt_enable(INTR_VBLANK);
interrupt_set_handler(INTR_SERIAL, LINK_WIRELESS_ISR_SERIAL);
interrupt_enable(INTR_SERIAL);
interrupt_set_handler(INTR_TIMER3, LINK_WIRELESS_ISR_TIMER);
interrupt_enable(INTR_TIMER3);
// (2) Add the required interrupt service routines
interrupt_init();
interrupt_set_handler(INTR_VBLANK, LINK_WIRELESS_ISR_VBLANK);
interrupt_enable(INTR_VBLANK);
interrupt_set_handler(INTR_SERIAL, LINK_WIRELESS_ISR_SERIAL);
interrupt_enable(INTR_SERIAL);
interrupt_set_handler(INTR_TIMER3, LINK_WIRELESS_ISR_TIMER);
interrupt_enable(INTR_TIMER3);
// (only required when using async ACK)
interrupt_set_handler(INTR_TIMER0, LINK_WIRELESS_ISR_ACK_TIMER);
interrupt_enable(INTR_TIMER0);
firstTime = false;
}
// (only required when using async ACK)
interrupt_set_handler(INTR_TIMER0, LINK_WIRELESS_ISR_ACK_TIMER);
interrupt_enable(INTR_TIMER0);
// (3) Initialize the library
linkWireless->activate();
@@ -106,6 +100,10 @@ start:
// SELECT = back
if (keys & KEY_SELECT) {
linkWireless->deactivate();
interrupt_disable(INTR_VBLANK);
interrupt_disable(INTR_SERIAL);
interrupt_disable(INTR_TIMER3);
interrupt_disable(INTR_TIMER0);
delete linkWireless;
linkWireless = NULL;
goto start;

View File

@@ -943,7 +943,5 @@ inline void LINK_MOBILE_ISR_TIMER() {
#endif // LINK_MOBILE_H
// TODO: Stop keeps running commands and changing state
// TODO: Error screen
// TODO: Keep adapter alive with Wait For Telephone Call
// TODO: Write text fast