2016-09-03 04:20:19 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Wind River Systems, Inc.
|
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-09-03 04:20:19 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief ARM Cortex-M k_thread_abort() routine
|
|
|
|
*
|
|
|
|
* The ARM Cortex-M architecture provides its own k_thread_abort() to deal
|
|
|
|
* with different CPU modes (handler vs thread) when a thread aborts. When its
|
|
|
|
* entry point returns or when it aborts itself, the CPU is in thread mode and
|
|
|
|
* must call _Swap() (which triggers a service call), but when in handler
|
|
|
|
* mode, the CPU must exit handler mode to cause the context switch, and thus
|
|
|
|
* must queue the PendSV exception.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <kernel.h>
|
2016-11-08 23:36:50 +08:00
|
|
|
#include <kernel_structs.h>
|
2016-09-03 04:20:19 +08:00
|
|
|
#include <toolchain.h>
|
2017-06-17 23:30:47 +08:00
|
|
|
#include <linker/sections.h>
|
2016-10-13 22:31:48 +08:00
|
|
|
#include <ksched.h>
|
2016-09-03 04:20:19 +08:00
|
|
|
#include <wait_q.h>
|
2017-08-29 07:02:24 +08:00
|
|
|
#include <misc/__assert.h>
|
2016-09-03 04:20:19 +08:00
|
|
|
|
2017-03-27 22:35:09 +08:00
|
|
|
extern void _k_thread_single_abort(struct k_thread *thread);
|
2016-09-03 04:20:19 +08:00
|
|
|
|
2017-09-30 05:00:48 +08:00
|
|
|
void _impl_k_thread_abort(k_tid_t thread)
|
2016-09-03 04:20:19 +08:00
|
|
|
{
|
|
|
|
unsigned int key;
|
|
|
|
|
|
|
|
key = irq_lock();
|
|
|
|
|
2017-08-29 07:02:24 +08:00
|
|
|
__ASSERT(!(thread->base.user_options & K_ESSENTIAL),
|
|
|
|
"essential thread aborted");
|
|
|
|
|
2016-09-03 04:20:19 +08:00
|
|
|
_k_thread_single_abort(thread);
|
2016-10-26 01:45:05 +08:00
|
|
|
_thread_monitor_exit(thread);
|
2016-09-03 04:20:19 +08:00
|
|
|
|
|
|
|
if (_current == thread) {
|
2017-01-25 22:29:03 +08:00
|
|
|
if ((SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) == 0) {
|
2016-09-03 04:20:19 +08:00
|
|
|
_Swap(key);
|
|
|
|
CODE_UNREACHABLE;
|
|
|
|
} else {
|
2017-01-25 22:24:57 +08:00
|
|
|
SCB->ICSR |= SCB_ICSR_PENDSVSET_Msk;
|
2016-09-03 04:20:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The abort handler might have altered the ready queue. */
|
|
|
|
_reschedule_threads(key);
|
|
|
|
}
|