Skip to content

Commit 9e8758c

Browse files
authored
Merge pull request #47 from stevenewald/echavemann/demo-code
Demo Code
2 parents 577792f + 84b1db4 commit 9e8758c

6 files changed

+45
-4
lines changed

src/entrypoint.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
extern void ipc_part1(void);
1010
extern void ipc_part2(void);
1111
extern void exception_task(void);
12+
extern void spinlock_task(void);
13+
extern void ending_task(void);
1214
extern void captouch_task(void);
1315

1416
int main(void)
@@ -23,5 +25,8 @@ int main(void)
2325
edge::scheduler.add_task(ipc_part1);
2426
edge::scheduler.add_task(ipc_part2);
2527

28+
edge::scheduler.add_task(spinlock_task);
29+
edge::scheduler.add_task(ending_task);
30+
2631
edge::scheduler.start_scheduler();
2732
}

src/scheduler/pending_process_callbacks.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ void PendingProcessCallbacks::add_ready_callback(
1515
)
1616
{
1717
if (ready_callbacks[process_id].size() == MAX_READY_CALLBACKS) {
18-
printf("Process %d is OUT OF SPACE FOR CALLBACKS\n", process_id);
18+
// printf("Process %d is OUT OF SPACE FOR CALLBACKS\n", process_id);
1919
return;
2020
}
2121
ready_callbacks[process_id].emplace_back(callback, arg1, arg2);

src/scheduler/user_callback_storage.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ void UserCallbackStorage::set_callback(ProcessId id, ProcessCallbackPtr ptr)
2020
void UserCallbackStorage::call_callback(ProcessId id, int arg1, int arg2)
2121
{
2222
if (!has_callback(id)) {
23-
panic("Attempted to call callback when it has not been set");
23+
printf(
24+
"Attempted to call callback when it has not been set for process %d\n", id
25+
);
2426
}
2527

2628
PendingProcessCallbacks::get().add_ready_callback(id, callbacks_[id], arg1, arg2);
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "userlib/syscalls.hpp"
2+
3+
#include <cstdio>
4+
5+
void ending_task(void)
6+
{
7+
using namespace edge::userlib;
8+
volatile int i = 0;
9+
bool enabled = true;
10+
while (i < 5'000'000) {
11+
if (i % 1'000'000 == 0) {
12+
edge::userlib::set_led(0, 0, enabled);
13+
enabled = !enabled;
14+
}
15+
i = i + 1;
16+
}
17+
debug_print("Ending Task: Done Running. 0,0 should stop changing.\n");
18+
}

src/user_programs/user_program_ipc_part_2.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ void ipc_part2(void)
88
static void (*on_button_press)(ButtonType, ButtonState) = [](ButtonType type,
99
ButtonState state) {
1010
if (state == ButtonState::DOWN) {
11-
if (type == ButtonType::A)
11+
if (type == ButtonType::A) {
12+
edge::userlib::debug_print("Button A pressed\n");
1213
send_ipc("LED_DISPLAY", true);
13-
else
14+
}
15+
else {
1416
send_ipc("LED_DISPLAY", false);
17+
edge::userlib::debug_print("Button B pressed\n");
18+
}
1519
}
1620
};
1721

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "nrf_delay.h"
2+
#include "userlib/syscalls.hpp"
3+
4+
#include <cstdint>
5+
6+
void spinlock_task(void)
7+
{
8+
while (1) {
9+
nrf_delay_ms(1000);
10+
edge::userlib::debug_print("Spinlock Task : Still Spinlocked.\n");
11+
}
12+
}

0 commit comments

Comments
 (0)