Before continuing, make sure you read through the caveats regarding running the program in bare-metal mode:
- once the program is started with such a long watchdog_timeout
, the only way to stop it is to briefly press the button on the cape (or route the button pins to an external switch with a cable if needed)
- we have not tested this for more than a few minutes. In principle it should work, but there may be some unexpected behaviour arising,, e.g.: overheating, if you run it within an air-sealed enclosure in a warm environment for extended periods of time.
- when running this way, 100% of the CPU is assigned to the audio thread, and as a consequence:
- AuxiliaryTasks (or any pthread_
threads) will not run
- the Bela Scope will not work
- the IDE will become unresponsive
- no CPU monitoring is available (it's 100%!)
- all Linux services (including disk and networking) will stop running while the program is on, and there is no guarantee they will successfully recover when the program stops (you may have to reboot the board)
- the file you are running may get corrupted on disk if it has just been built and the program then takes all the CPU, preventing Linux from properly saving it to disk. We therefore recommend that, after each edit to the program, you run it only briefly and then force stop it (within a few seconds), to allow the file to be properly saved to disk. After you have done this once, simply restart the program and it can now safely run for an extended period of time without risking file corruption.
Now that you know the caveats, here's how you can shoot yourself in the foot:
Apply these changes (that, is, add the lines marked with +
(not including the +
, obviously) and remove the lines marked with -
) to Bela/core/PRU.cpp
(you will need to ssh
on to the board to do that).
diff --git a/core/PRU.cpp b/core/PRU.cpp
index dd72604..296278a 100644
--- a/core/PRU.cpp
+++ b/core/PRU.cpp
@@ -35,8 +35,12 @@
#include <sys/mman.h>
#include <string.h>
-#if !(defined(BELA_USE_POLL) || defined(BELA_USE_RTDM))
-#error Define one of BELA_USE_POLL, BELA_USE_RTDM
+// manually enable busywait
+#define BELA_USE_BUSYWAIT
+#undef BELA_USE_RTDM
+
+#if !(defined(BELA_USE_POLL) || defined(BELA_USE_RTDM) || defined(BELA_USE_BUSYWAIT))
+#error Define one of BELA_USE_POLL, BELA_USE_RTDM, BELA_USE_BUSYWAIT
#endif
#ifdef BELA_USE_RTDM
@@ -894,12 +898,14 @@ void PRU::loop(void *userData, void(*render)(BelaContext*, void*), bool highPerf
int underrunLedCount = -1;
while(!gShouldStop) {
-#ifdef BELA_USE_POLL
+#if defined BELA_USE_POLL || defined BELA_USE_BUSYWAIT
// Which buffer the PRU was last processing
static uint32_t lastPRUBuffer = 0;
// Poll
while(pru_buffer_comm[PRU_CURRENT_BUFFER] == lastPRUBuffer && !gShouldStop) {
+#ifdef BELA_USE_POLL
task_sleep_ns(sleepTime);
+#endif /* BELA_USE_POLL */
if(testPruError())
{
break;
@@ -907,7 +913,7 @@ void PRU::loop(void *userData, void(*render)(BelaContext*, void*), bool highPerf
}
lastPRUBuffer = pru_buffer_comm[PRU_CURRENT_BUFFER];
-#endif
+#endif /* BELA_USE_POLL || BELA_USE_BUSYWAIT */
#ifdef BELA_USE_RTDM
// make sure we always sleep a tiny bit to prevent hanging the board
if(!highPerformanceMode) // unless the user requested us not to.
If all works fine, when you start the program it will run for 4 seconds at full CPU and then it will stop with an error message.
You can change the time it takes for the program to stop by running on the board (again, after ssh
'ing into it):
echo 10 > /sys/module/xenomai/parameters/watchdog_timeout
this will get the program running for 10 seconds before stopping it. If you replace 10
in the above line with some very large number (e.g.: echo 999999999 > /sys/module/xenomai/parameters/watchdog_timeout
), the program will run "forever" (that is for 999999999 seconds, that is 277,777.775 hours) unless you stop it before then by pressing the button.
The echo XXX > /sys/module/xenomai/parameters/watchdog_timeout
operation has to be repeated after each reboot (and can be automated if desired).
If later on you want to revert to the normal behaviour, simply comment out these lines in Bela/core/PRU.cpp
:
#define BELA_USE_BUSYWAIT
#undef BELA_USE_RTDM
and rebuild.