1- #include < Arduino.h>
21#include " pico/async_context_threadsafe_background.h"
2+ #include < Arduino.h>
33
44bool core1_separate_stack = true ;
55
@@ -10,72 +10,71 @@ static volatile uint64_t timestamp_enter = 0;
1010
1111static async_context_threadsafe_background_t asyncCtx;
1212
13- uint32_t doSomeWork (void * param) {
14- const auto value = static_cast <uint32_t *>(param);
15- (*value)++;
16- // Log timestamp right before sem_release will happen
17- if (const auto worker = static_cast <async_when_pending_worker*>(asyncCtx.core .when_pending_list )) {
18- Serial1.printf (" [INFO][%u][%llu] Pre-sem_release worker state:\n "
19- " address: %p\n "
20- " next: %p\n "
21- " do_work: %p\n "
22- " work_pending: %d\n "
23- " value: %d\n " ,
24- get_core_num (),
25- to_us_since_boot (get_absolute_time ()),
26- worker,
27- worker->next ,
28- worker->do_work ,
29- worker->work_pending ,
30- *value);
31- }
32- return *value;
13+ uint32_t do_some_work (void *param) {
14+ const auto value = static_cast <uint32_t *>(param);
15+ (*value)++;
16+ // Log timestamp right before sem_release will happen
17+ if (const auto worker = static_cast <async_when_pending_worker *>(
18+ asyncCtx.core .when_pending_list )) {
19+ Serial1.printf (" [INFO][%u][%llu] Pre-sem_release worker state:\n "
20+ " address: %p\n "
21+ " next: %p\n "
22+ " do_work: %p\n "
23+ " work_pending: %d\n "
24+ " value: %d\n " ,
25+ get_core_num (), to_us_since_boot (get_absolute_time ()),
26+ worker, worker->next , worker->do_work , worker->work_pending ,
27+ *value);
28+ }
29+ return *value;
3330}
3431
3532void setup () {
36- Serial1.setRX (PIN_SERIAL1_RX);
37- Serial1.setTX (PIN_SERIAL1_TX);
38- Serial1.setPollingMode (true );
39- Serial1.begin (115200 );
33+ Serial1.setRX (PIN_SERIAL1_RX);
34+ Serial1.setTX (PIN_SERIAL1_TX);
35+ Serial1.setPollingMode (true );
36+ Serial1.begin (115200 );
4037
41- while (!Serial1) {
42- delay (10 );
43- }
38+ while (!Serial1) {
39+ delay (10 );
40+ }
4441
45- RP2040::enableDoubleResetBootloader ();
46- serial_ready = true ;
47- while (!operational) {
48- delay (10 );
49- }
42+ RP2040::enableDoubleResetBootloader ();
43+ serial_ready = true ;
44+ while (!operational) {
45+ delay (10 );
46+ }
5047
51- Serial1.printf (" C0 ready...\n " );
48+ Serial1.printf (" C0 ready...\n " );
5249}
5350
5451void setup1 () {
55- while (!serial_ready) {
56- delay (10 );
57- }
58- async_context_threadsafe_background_config_t cfg = async_context_threadsafe_background_default_config ();
59- operational = async_context_threadsafe_background_init (&asyncCtx, &cfg);
60- assert (operational);
61- Serial1.printf (" C1 ready...\n " );
52+ while (!serial_ready) {
53+ delay (10 );
54+ }
55+ async_context_threadsafe_background_config_t cfg =
56+ async_context_threadsafe_background_default_config ();
57+ operational = async_context_threadsafe_background_init (&asyncCtx, &cfg);
58+ assert (operational);
59+ Serial1.printf (" C1 ready...\n " );
6260}
6361
6462void loop () {
65- static unsigned long c0_counter = 0 ;
66- static uint32_t myNumber = 0 ;
63+ static unsigned long c0_counter = 0 ;
64+ static uint32_t ref_counter = 0 ;
6765
68- if (c0_counter % 111 == 0 ) {
69- timestamp_enter = to_us_since_boot (get_absolute_time ());
70- const auto rc = async_context_execute_sync (&asyncCtx.core , doSomeWork, &myNumber);
71- assert (rc == myNumber);
72- timestamp_exit = to_us_since_boot (get_absolute_time ());
73- Serial1.printf (" value: %d; enter: %llu; exit: %llu\n " , rc, timestamp_enter, timestamp_exit);
74- }
75- c0_counter++;
76- delay (1 );
66+ if (c0_counter % 111 == 0 ) {
67+ timestamp_enter = to_us_since_boot (get_absolute_time ());
68+ const auto rc =
69+ async_context_execute_sync (&asyncCtx.core , do_some_work, &ref_counter);
70+ assert (rc == ref_counter);
71+ timestamp_exit = to_us_since_boot (get_absolute_time ());
72+ Serial1.printf (" [INFO][%u][%llu] value: %d; enter: %llu; exit: %llu\n " ,
73+ get_core_num (), timestamp_exit, rc, timestamp_enter,
74+ timestamp_exit);
75+ }
76+ c0_counter++;
77+ delay (1 );
7778}
7879
79- void loop1 () {
80- tight_loop_contents ();
81- }
80+ void loop1 () { tight_loop_contents (); }
0 commit comments