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

🐛 Fix _exit implementation #671

Open
wants to merge 5 commits into
base: develop-pros-4
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
11 changes: 11 additions & 0 deletions src/system/newlib_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,19 @@
#define MICRO_TO_NANO 1000

void _exit(int status) {
extern void flush_output_streams();
flush_output_streams();
extern void ser_output_flush();
ser_output_flush();
rtos_suspend_all();
if(status != 0) dprintf(3, "Error %d\n", status); // kprintf
uint32_t start_time = millis();
static const uint32_t max_flush_time = 50;
while (vexSerialWriteFree(1) != 2048 || millis() - start_time > max_flush_time) {
vexBackgroundProcessing();
}
vexSystemExitRequest();
while (1) vexBackgroundProcessing();
}

int usleep( useconds_t period ) {
Expand Down
8 changes: 8 additions & 0 deletions src/system/newlib_stubs_support.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <cstdio>
#include <iostream>

// called by _exit in newlib_stubs.c
extern "C" void flush_output_streams() {
fflush(stdout);
std::cout.flush();
}