mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-02-02 14:08:45 -04:00
HAL_ChibiOS: implement thread_create()
This commit is contained in:
parent
88842adbd5
commit
df3ce87e02
@ -435,4 +435,61 @@ void Scheduler::restore_interrupts(void *state)
|
||||
chSysRestoreStatusX((syssts_t)(uintptr_t)state);
|
||||
}
|
||||
|
||||
/*
|
||||
trampoline for thread create
|
||||
*/
|
||||
void Scheduler::thread_create_trampoline(void *ctx)
|
||||
{
|
||||
AP_HAL::MemberProc *t = (AP_HAL::MemberProc *)ctx;
|
||||
(*t)();
|
||||
free(t);
|
||||
}
|
||||
|
||||
/*
|
||||
create a new thread
|
||||
*/
|
||||
bool Scheduler::thread_create(AP_HAL::MemberProc proc, const char *name, uint32_t stack_size, priority_base base, int8_t priority)
|
||||
{
|
||||
// take a copy of the MemberProc, it is freed after thread exits
|
||||
AP_HAL::MemberProc *tproc = (AP_HAL::MemberProc *)malloc(sizeof(proc));
|
||||
if (!tproc) {
|
||||
return false;
|
||||
}
|
||||
*tproc = proc;
|
||||
|
||||
uint8_t thread_priority = APM_IO_PRIORITY;
|
||||
static const struct {
|
||||
priority_base base;
|
||||
uint8_t p;
|
||||
} priority_map[] = {
|
||||
{ PRIORITY_BOOST, APM_MAIN_PRIORITY_BOOST},
|
||||
{ PRIORITY_MAIN, APM_MAIN_PRIORITY},
|
||||
{ PRIORITY_SPI, APM_SPI_PRIORITY},
|
||||
{ PRIORITY_I2C, APM_I2C_PRIORITY},
|
||||
{ PRIORITY_CAN, APM_CAN_PRIORITY},
|
||||
{ PRIORITY_TIMER, APM_TIMER_PRIORITY},
|
||||
{ PRIORITY_RCIN, APM_RCIN_PRIORITY},
|
||||
{ PRIORITY_IO, APM_IO_PRIORITY},
|
||||
{ PRIORITY_UART, APM_UART_PRIORITY},
|
||||
{ PRIORITY_STORAGE, APM_STORAGE_PRIORITY},
|
||||
};
|
||||
for (uint8_t i=0; i<ARRAY_SIZE(priority_map); i++) {
|
||||
if (priority_map[i].base == base) {
|
||||
thread_priority = constrain_int16(priority_map[i].p + priority, LOWPRIO, HIGHPRIO);
|
||||
break;
|
||||
}
|
||||
}
|
||||
thread_t *thread_ctx = chThdCreateFromHeap(NULL,
|
||||
THD_WORKING_AREA_SIZE(stack_size),
|
||||
name,
|
||||
thread_priority,
|
||||
thread_create_trampoline,
|
||||
tproc);
|
||||
if (thread_ctx == nullptr) {
|
||||
free(tproc);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif // CH_CFG_USE_DYNAMIC
|
||||
|
@ -92,6 +92,11 @@ public:
|
||||
restore interrupt state from disable_interrupts_save()
|
||||
*/
|
||||
void restore_interrupts(void *) override;
|
||||
|
||||
/*
|
||||
create a new thread
|
||||
*/
|
||||
bool thread_create(AP_HAL::MemberProc, const char *name, uint32_t stack_size, priority_base base, int8_t priority) override;
|
||||
|
||||
private:
|
||||
bool _initialized;
|
||||
@ -132,5 +137,6 @@ private:
|
||||
#endif
|
||||
void _run_timers();
|
||||
void _run_io(void);
|
||||
static void thread_create_trampoline(void *ctx);
|
||||
};
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user