mirror of
https://github.com/mytechnotalent/Embedded-Hacking.git
synced 2026-07-09 22:08:42 +02:00
Updated Drivers
This commit is contained in:
@@ -41,24 +41,48 @@
|
||||
#include "pico/stdlib.h"
|
||||
#include "multicore.h"
|
||||
|
||||
static void core1_main(void) {
|
||||
/**
|
||||
* @brief Core 1 entry point: receive a value and return it incremented
|
||||
*
|
||||
* Blocks on the FIFO, adds one to each received value, and pushes
|
||||
* the result back to core 0.
|
||||
*/
|
||||
static void _core1_main(void) {
|
||||
while (true) {
|
||||
uint32_t value = multicore_driver_pop();
|
||||
multicore_driver_push(value + 1u);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Send the counter to core 1 and print the round-trip result
|
||||
*
|
||||
* @param counter Pointer to the running counter (post-incremented)
|
||||
*/
|
||||
static void _send_and_print(uint32_t *counter) {
|
||||
multicore_driver_push(*counter);
|
||||
uint32_t response = multicore_driver_pop();
|
||||
printf("core0 sent: %lu, core1 returned: %lu\r\n",
|
||||
(unsigned long)*counter, (unsigned long)response);
|
||||
(*counter)++;
|
||||
sleep_ms(1000);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Application entry point for the multicore FIFO demo
|
||||
*
|
||||
* Launches core 1 and continuously sends an incrementing counter
|
||||
* through the inter-core FIFO, printing both sent and returned
|
||||
* values over UART every second.
|
||||
*
|
||||
* @return int Does not return
|
||||
*/
|
||||
int main(void) {
|
||||
stdio_init_all();
|
||||
multicore_driver_launch(core1_main);
|
||||
|
||||
multicore_driver_launch(_core1_main);
|
||||
uint32_t counter = 0;
|
||||
while (true) {
|
||||
multicore_driver_push(counter);
|
||||
uint32_t response = multicore_driver_pop();
|
||||
printf("core0 sent: %lu, core1 returned: %lu\r\n",
|
||||
(unsigned long)counter, (unsigned long)response);
|
||||
counter++;
|
||||
sleep_ms(1000);
|
||||
}
|
||||
while (true)
|
||||
_send_and_print(&counter);
|
||||
}
|
||||
|
||||
@@ -34,10 +34,12 @@ void multicore_driver_launch(void (*core1_entry)(void)) {
|
||||
multicore_launch_core1(core1_entry);
|
||||
}
|
||||
|
||||
|
||||
void multicore_driver_push(uint32_t data) {
|
||||
multicore_fifo_push_blocking(data);
|
||||
}
|
||||
|
||||
|
||||
uint32_t multicore_driver_pop(void) {
|
||||
return multicore_fifo_pop_blocking();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user