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

Generalize RP2040 (and in the future, STM32) support to NUM_CORES #438

Open
sberkun opened this issue May 26, 2024 · 0 comments
Open

Generalize RP2040 (and in the future, STM32) support to NUM_CORES #438

sberkun opened this issue May 26, 2024 · 0 comments

Comments

@sberkun
Copy link
Collaborator

sberkun commented May 26, 2024

Currently, the rp2040 support assumes that there is one main core and one other core:

#define MAGIC_THREAD1_ID 314159
void core1_entry() {
thread_1_return = thread_1(thread_1_args);
sem_reset(&thread_1_done, 1);
}
int lf_thread_create(lf_thread_t* thread, void* (*lf_thread)(void*), void* arguments) {
// make sure this fn is only called once
if (num_create_threads_called != 0) {
return 1;
}
thread_1 = lf_thread;
thread_1_args = arguments;
num_create_threads_called += 1;
sem_init(&thread_1_done, 0, 1);
multicore_launch_core1(core1_entry);
*thread = MAGIC_THREAD1_ID;
return 0;
}
int lf_thread_join(lf_thread_t thread, void** thread_return) {
if (thread != MAGIC_THREAD1_ID) {
return 1;
}
sem_acquire_blocking(&thread_1_done);
// release in case join is called again
if (!sem_release(&thread_1_done)) {
// shouldn't be possible; lf_thread_join is only called from main thread
return 1;
}
if (thread_return) {
*thread_return = thread_1_return;
}
return 0;
}

However, future versions of this chip (i.e. an RP4040) may have more cores. Ideally, lf_thread_create and lf_thread_join should be revised to account for this. The generalization probably won't be perfect (since multicore_launch_core1 doesn't lend itself well to more cores), but should be aimed at a potential future with a 4-core RP4040. Something like the following may be used to abstract away multicore_launch_core1:

// assume this function will exist in some future version of the pico-sdk
void multicore_launch(int core, void (*entry)(void)) {
    multicore_launch_core1(entry); // for now, assume core == 1
}

This work on generalization will probably lend itself well to future STM32 support, as many STM32 devices do have more than 2 cores.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant