|
|
|
@ -435,4 +435,61 @@ void Scheduler::restore_interrupts(void *state)
@@ -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
|
|
|
|
|