mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #1146 from masaohamanaka/master
RZ_A1H - Modify the OS track acquisition methodpull/1191/merge
commit
c33e334a22
|
@ -426,12 +426,10 @@ sys_thread_t sys_thread_new(const char *pcName,
|
||||||
t->def.pthread = (os_pthread)thread;
|
t->def.pthread = (os_pthread)thread;
|
||||||
t->def.tpriority = (osPriority)priority;
|
t->def.tpriority = (osPriority)priority;
|
||||||
t->def.stacksize = stacksize;
|
t->def.stacksize = stacksize;
|
||||||
#ifndef __MBED_CMSIS_RTOS_CA9
|
|
||||||
t->def.stack_pointer = (uint32_t*)malloc(stacksize);
|
t->def.stack_pointer = (uint32_t*)malloc(stacksize);
|
||||||
if (t->def.stack_pointer == NULL) {
|
if (t->def.stack_pointer == NULL) {
|
||||||
error("Error allocating the stack memory");
|
error("Error allocating the stack memory");
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
t->id = osThreadCreate(&t->def, arg);
|
t->id = osThreadCreate(&t->def, arg);
|
||||||
if (t->id == NULL)
|
if (t->id == NULL)
|
||||||
|
|
|
@ -31,7 +31,6 @@ Thread::Thread(void (*task)(void const *argument), void *argument,
|
||||||
_thread_def.pthread = task;
|
_thread_def.pthread = task;
|
||||||
_thread_def.tpriority = priority;
|
_thread_def.tpriority = priority;
|
||||||
_thread_def.stacksize = stack_size;
|
_thread_def.stacksize = stack_size;
|
||||||
#ifndef __MBED_CMSIS_RTOS_CA9
|
|
||||||
if (stack_pointer != NULL) {
|
if (stack_pointer != NULL) {
|
||||||
_thread_def.stack_pointer = (uint32_t*)stack_pointer;
|
_thread_def.stack_pointer = (uint32_t*)stack_pointer;
|
||||||
_dynamic_stack = false;
|
_dynamic_stack = false;
|
||||||
|
@ -46,7 +45,6 @@ Thread::Thread(void (*task)(void const *argument), void *argument,
|
||||||
for (int i = 0; i < (stack_size / sizeof(uint32_t)); i++) {
|
for (int i = 0; i < (stack_size / sizeof(uint32_t)); i++) {
|
||||||
_thread_def.stack_pointer[i] = 0xE25A2EA5;
|
_thread_def.stack_pointer[i] = 0xE25A2EA5;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
_tid = osThreadCreate(&_thread_def, argument);
|
_tid = osThreadCreate(&_thread_def, argument);
|
||||||
}
|
}
|
||||||
|
@ -136,11 +134,9 @@ osThreadId Thread::gettid() {
|
||||||
|
|
||||||
Thread::~Thread() {
|
Thread::~Thread() {
|
||||||
terminate();
|
terminate();
|
||||||
#ifndef __MBED_CMSIS_RTOS_CA9
|
|
||||||
if (_dynamic_stack) {
|
if (_dynamic_stack) {
|
||||||
delete[] (_thread_def.stack_pointer);
|
delete[] (_thread_def.stack_pointer);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,16 +85,24 @@ OS_RESULT _os_mut_wait (uint32_t p, OS_ID mutex, uint16_t timeout) __svc_indi
|
||||||
|
|
||||||
#if (OS_TIMERS != 0)
|
#if (OS_TIMERS != 0)
|
||||||
#define OS_TASK_CNT (OS_TASKCNT + 1)
|
#define OS_TASK_CNT (OS_TASKCNT + 1)
|
||||||
|
#ifndef __MBED_CMSIS_RTOS_CA9
|
||||||
#define OS_PRIV_CNT (OS_PRIVCNT + 2)
|
#define OS_PRIV_CNT (OS_PRIVCNT + 2)
|
||||||
#define OS_STACK_SZ (4*(OS_PRIVSTKSIZE+OS_MAINSTKSIZE+OS_TIMERSTKSZ))
|
#define OS_STACK_SZ (4*(OS_PRIVSTKSIZE+OS_MAINSTKSIZE+OS_TIMERSTKSZ))
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
#define OS_TASK_CNT OS_TASKCNT
|
#define OS_TASK_CNT OS_TASKCNT
|
||||||
|
#ifndef __MBED_CMSIS_RTOS_CA9
|
||||||
#define OS_PRIV_CNT (OS_PRIVCNT + 1)
|
#define OS_PRIV_CNT (OS_PRIVCNT + 1)
|
||||||
#define OS_STACK_SZ (4*(OS_PRIVSTKSIZE+OS_MAINSTKSIZE))
|
#define OS_STACK_SZ (4*(OS_PRIVSTKSIZE+OS_MAINSTKSIZE))
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
uint16_t const os_maxtaskrun = OS_TASK_CNT;
|
uint16_t const os_maxtaskrun = OS_TASK_CNT;
|
||||||
|
#ifdef __MBED_CMSIS_RTOS_CA9
|
||||||
|
uint32_t const os_stackinfo = (OS_STKCHECK<<24)| (OS_IDLESTKSIZE*4);
|
||||||
|
#else
|
||||||
uint32_t const os_stackinfo = (OS_STKCHECK<<24)| (OS_PRIV_CNT<<16) | (OS_STKSIZE*4);
|
uint32_t const os_stackinfo = (OS_STKCHECK<<24)| (OS_PRIV_CNT<<16) | (OS_STKSIZE*4);
|
||||||
|
#endif
|
||||||
uint32_t const os_rrobin = (OS_ROBIN << 16) | OS_ROBINTOUT;
|
uint32_t const os_rrobin = (OS_ROBIN << 16) | OS_ROBINTOUT;
|
||||||
uint32_t const os_trv = OS_TRV;
|
uint32_t const os_trv = OS_TRV;
|
||||||
uint8_t const os_flags = OS_RUNPRIV;
|
uint8_t const os_flags = OS_RUNPRIV;
|
||||||
|
@ -107,6 +115,11 @@ __USED uint32_t const os_timernum = 0;
|
||||||
_declare_box (mp_tcb, OS_TCB_SIZE, OS_TASK_CNT);
|
_declare_box (mp_tcb, OS_TCB_SIZE, OS_TASK_CNT);
|
||||||
uint16_t const mp_tcb_size = sizeof(mp_tcb);
|
uint16_t const mp_tcb_size = sizeof(mp_tcb);
|
||||||
|
|
||||||
|
#ifdef __MBED_CMSIS_RTOS_CA9
|
||||||
|
/* Memory pool for os_idle_demon stack allocation. */
|
||||||
|
_declare_box8 (mp_stk, OS_IDLESTKSIZE*4, 1);
|
||||||
|
uint32_t const mp_stk_size = sizeof(mp_stk);
|
||||||
|
#else
|
||||||
/* Memory pool for System stack allocation (+os_idle_demon). */
|
/* Memory pool for System stack allocation (+os_idle_demon). */
|
||||||
_declare_box8 (mp_stk, OS_STKSIZE*4, OS_TASK_CNT-OS_PRIV_CNT+1);
|
_declare_box8 (mp_stk, OS_STKSIZE*4, OS_TASK_CNT-OS_PRIV_CNT+1);
|
||||||
uint32_t const mp_stk_size = sizeof(mp_stk);
|
uint32_t const mp_stk_size = sizeof(mp_stk);
|
||||||
|
@ -114,6 +127,7 @@ uint32_t const mp_stk_size = sizeof(mp_stk);
|
||||||
/* Memory pool for user specified stack allocation (+main, +timer) */
|
/* Memory pool for user specified stack allocation (+main, +timer) */
|
||||||
uint64_t os_stack_mem[2+OS_PRIV_CNT+(OS_STACK_SZ/8)];
|
uint64_t os_stack_mem[2+OS_PRIV_CNT+(OS_STACK_SZ/8)];
|
||||||
uint32_t const os_stack_sz = sizeof(os_stack_mem);
|
uint32_t const os_stack_sz = sizeof(os_stack_mem);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef OS_FIFOSZ
|
#ifndef OS_FIFOSZ
|
||||||
#define OS_FIFOSZ 16
|
#define OS_FIFOSZ 16
|
||||||
|
@ -129,7 +143,7 @@ void *os_active_TCB[OS_TASK_CNT];
|
||||||
/* User Timers Resources */
|
/* User Timers Resources */
|
||||||
#if (OS_TIMERS != 0)
|
#if (OS_TIMERS != 0)
|
||||||
extern void osTimerThread (void const *argument);
|
extern void osTimerThread (void const *argument);
|
||||||
#if defined (__MBED_CMSIS_RTOS_CA9)
|
#ifdef __MBED_CMSIS_RTOS_CA9
|
||||||
osThreadDef(osTimerThread, (osPriority)(OS_TIMERPRIO-3), 4*OS_TIMERSTKSZ);
|
osThreadDef(osTimerThread, (osPriority)(OS_TIMERPRIO-3), 4*OS_TIMERSTKSZ);
|
||||||
#else
|
#else
|
||||||
osThreadDef(osTimerThread, (osPriority)(OS_TIMERPRIO-3), 1, 4*OS_TIMERSTKSZ);
|
osThreadDef(osTimerThread, (osPriority)(OS_TIMERPRIO-3), 1, 4*OS_TIMERSTKSZ);
|
||||||
|
@ -237,7 +251,12 @@ __attribute__((used)) void _mutex_release (OS_ID *mutex) {
|
||||||
|
|
||||||
/* Main Thread definition */
|
/* Main Thread definition */
|
||||||
extern int main (void);
|
extern int main (void);
|
||||||
|
#ifdef __MBED_CMSIS_RTOS_CA9
|
||||||
|
uint32_t os_thread_def_stack_main [(4 * OS_MAINSTKSIZE) / sizeof(uint32_t)];
|
||||||
|
osThreadDef_t os_thread_def_main = {(os_pthread)main, osPriorityNormal, 1, 4*OS_MAINSTKSIZE, os_thread_def_stack_main };
|
||||||
|
#else
|
||||||
osThreadDef_t os_thread_def_main = {(os_pthread)main, osPriorityNormal, 1, 4*OS_MAINSTKSIZE };
|
osThreadDef_t os_thread_def_main = {(os_pthread)main, osPriorityNormal, 1, 4*OS_MAINSTKSIZE };
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if defined (__CC_ARM)
|
#if defined (__CC_ARM)
|
||||||
|
|
|
@ -50,12 +50,20 @@
|
||||||
#define OS_TASKCNT 25
|
#define OS_TASKCNT 25
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __MBED_CMSIS_RTOS_CA9
|
||||||
|
// <o>Idle stack size [bytes] <64-4096:8><#/4>
|
||||||
|
// <i> Defines default stack size for the Idle thread.
|
||||||
|
#ifndef OS_IDLESTKSIZE
|
||||||
|
#define OS_IDLESTKSIZE 128
|
||||||
|
#endif
|
||||||
|
#else // __MBED_CMSIS_RTOS_CA9
|
||||||
// <o>Default Thread stack size [bytes] <64-4096:8><#/4>
|
// <o>Default Thread stack size [bytes] <64-4096:8><#/4>
|
||||||
// <i> Defines default stack size for threads with osThreadDef stacksz = 0
|
// <i> Defines default stack size for threads with osThreadDef stacksz = 0
|
||||||
// <i> Default: 200
|
// <i> Default: 200
|
||||||
#ifndef OS_STKSIZE
|
#ifndef OS_STKSIZE
|
||||||
#define OS_STKSIZE 200
|
#define OS_STKSIZE 200
|
||||||
#endif
|
#endif
|
||||||
|
#endif // __MBED_CMSIS_RTOS_CA9
|
||||||
|
|
||||||
// <o>Main Thread stack size [bytes] <64-4096:8><#/4>
|
// <o>Main Thread stack size [bytes] <64-4096:8><#/4>
|
||||||
// <i> Defines stack size for main thread.
|
// <i> Defines stack size for main thread.
|
||||||
|
@ -64,19 +72,21 @@
|
||||||
#define OS_MAINSTKSIZE 2048
|
#define OS_MAINSTKSIZE 2048
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef __MBED_CMSIS_RTOS_CA9
|
||||||
// <o>Number of threads with user-provided stack size <0-250>
|
// <o>Number of threads with user-provided stack size <0-250>
|
||||||
// <i> Defines the number of threads with user-provided stack size.
|
// <i> Defines the number of threads with user-provided stack size.
|
||||||
// <i> Default: 0
|
// <i> Default: 0
|
||||||
#ifndef OS_PRIVCNT
|
#ifndef OS_PRIVCNT
|
||||||
#define OS_PRIVCNT 10
|
#define OS_PRIVCNT 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// <o>Total stack size [bytes] for threads with user-provided stack size <0-4096:8><#/4>
|
// <o>Total stack size [bytes] for threads with user-provided stack size <0-4096:8><#/4>
|
||||||
// <i> Defines the combined stack size for threads with user-provided stack size.
|
// <i> Defines the combined stack size for threads with user-provided stack size.
|
||||||
// <i> Default: 0
|
// <i> Default: 0
|
||||||
#ifndef OS_PRIVSTKSIZE
|
#ifndef OS_PRIVSTKSIZE
|
||||||
#define OS_PRIVSTKSIZE 8192
|
#define OS_PRIVSTKSIZE 0
|
||||||
#endif
|
#endif
|
||||||
|
#endif // __MBED_CMSIS_RTOS_CA9
|
||||||
|
|
||||||
// <q>Check for stack overflow
|
// <q>Check for stack overflow
|
||||||
// <i> Includes the stack checking code for stack overflow.
|
// <i> Includes the stack checking code for stack overflow.
|
||||||
|
|
|
@ -264,6 +264,9 @@ typedef struct os_thread_def {
|
||||||
osPriority tpriority; ///< initial thread priority
|
osPriority tpriority; ///< initial thread priority
|
||||||
uint32_t instances; ///< maximum number of instances of that thread function
|
uint32_t instances; ///< maximum number of instances of that thread function
|
||||||
uint32_t stacksize; ///< stack size requirements in bytes; 0 is default stack size
|
uint32_t stacksize; ///< stack size requirements in bytes; 0 is default stack size
|
||||||
|
#ifdef __MBED_CMSIS_RTOS_CA9
|
||||||
|
uint32_t *stack_pointer; ///< pointer to the stack memory block
|
||||||
|
#endif
|
||||||
} osThreadDef_t;
|
} osThreadDef_t;
|
||||||
|
|
||||||
/// Timer Definition structure contains timer parameters.
|
/// Timer Definition structure contains timer parameters.
|
||||||
|
@ -356,10 +359,11 @@ int32_t osKernelRunning(void);
|
||||||
#define osThreadDef(name, priority, instances, stacksz) \
|
#define osThreadDef(name, priority, instances, stacksz) \
|
||||||
extern const osThreadDef_t os_thread_def_##name
|
extern const osThreadDef_t os_thread_def_##name
|
||||||
#else // define the object
|
#else // define the object
|
||||||
#if defined (__MBED_CMSIS_RTOS_CA9)
|
#ifdef __MBED_CMSIS_RTOS_CA9
|
||||||
#define osThreadDef(name, priority, stacksz) \
|
#define osThreadDef(name, priority, stacksz) \
|
||||||
|
uint32_t os_thread_def_stack_##name [stacksz / sizeof(uint32_t)]; \
|
||||||
const osThreadDef_t os_thread_def_##name = \
|
const osThreadDef_t os_thread_def_##name = \
|
||||||
{ (name), (priority), 1, (stacksz) }
|
{ (name), (priority), 1, (stacksz), (os_thread_def_stack_##name) }
|
||||||
#else
|
#else
|
||||||
#define osThreadDef(name, priority, instances, stacksz) \
|
#define osThreadDef(name, priority, instances, stacksz) \
|
||||||
const osThreadDef_t os_thread_def_##name = \
|
const osThreadDef_t os_thread_def_##name = \
|
||||||
|
|
|
@ -442,9 +442,11 @@ extern const uint32_t os_section_id$$Base;
|
||||||
extern const uint32_t os_section_id$$Limit;
|
extern const uint32_t os_section_id$$Limit;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef __MBED_CMSIS_RTOS_CA9
|
||||||
// OS Stack Memory for Threads definitions
|
// OS Stack Memory for Threads definitions
|
||||||
extern uint64_t os_stack_mem[];
|
extern uint64_t os_stack_mem[];
|
||||||
extern const uint32_t os_stack_sz;
|
extern const uint32_t os_stack_sz;
|
||||||
|
#endif
|
||||||
|
|
||||||
// OS Timers external resources
|
// OS Timers external resources
|
||||||
extern const osThreadDef_t os_thread_def_osTimerThread;
|
extern const osThreadDef_t os_thread_def_osTimerThread;
|
||||||
|
@ -546,6 +548,11 @@ osMessageQId svcMessageCreate (const osMessageQDef_t *queue_def, osThreadId thre
|
||||||
|
|
||||||
/// Initialize the RTOS Kernel for creating objects
|
/// Initialize the RTOS Kernel for creating objects
|
||||||
osStatus svcKernelInitialize (void) {
|
osStatus svcKernelInitialize (void) {
|
||||||
|
#ifdef __MBED_CMSIS_RTOS_CA9
|
||||||
|
if (!os_initialized) {
|
||||||
|
rt_sys_init(); // RTX System Initialization
|
||||||
|
}
|
||||||
|
#else
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!os_initialized) {
|
if (!os_initialized) {
|
||||||
|
@ -557,6 +564,7 @@ osStatus svcKernelInitialize (void) {
|
||||||
|
|
||||||
rt_sys_init(); // RTX System Initialization
|
rt_sys_init(); // RTX System Initialization
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
os_tsk.run->prio = 255; // Highest priority
|
os_tsk.run->prio = 255; // Highest priority
|
||||||
|
|
||||||
|
@ -668,6 +676,13 @@ osThreadId svcThreadCreate (const osThreadDef_t *thread_def, void *argument) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __MBED_CMSIS_RTOS_CA9
|
||||||
|
if (thread_def->stacksize != 0) { // Custom stack size
|
||||||
|
stk = (void *)thread_def->stack_pointer;
|
||||||
|
} else { // Default stack size
|
||||||
|
stk = NULL;
|
||||||
|
}
|
||||||
|
#else
|
||||||
if (thread_def->stacksize != 0) { // Custom stack size
|
if (thread_def->stacksize != 0) { // Custom stack size
|
||||||
stk = rt_alloc_mem( // Allocate stack
|
stk = rt_alloc_mem( // Allocate stack
|
||||||
os_stack_mem,
|
os_stack_mem,
|
||||||
|
@ -680,6 +695,7 @@ osThreadId svcThreadCreate (const osThreadDef_t *thread_def, void *argument) {
|
||||||
} else { // Default stack size
|
} else { // Default stack size
|
||||||
stk = NULL;
|
stk = NULL;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
tsk = rt_tsk_create( // Create task
|
tsk = rt_tsk_create( // Create task
|
||||||
(FUNCP)thread_def->pthread, // Task function pointer
|
(FUNCP)thread_def->pthread, // Task function pointer
|
||||||
|
@ -690,9 +706,11 @@ osThreadId svcThreadCreate (const osThreadDef_t *thread_def, void *argument) {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (tsk == 0) { // Invalid task ID
|
if (tsk == 0) { // Invalid task ID
|
||||||
|
#ifndef __MBED_CMSIS_RTOS_CA9
|
||||||
if (stk != NULL) {
|
if (stk != NULL) {
|
||||||
rt_free_mem(os_stack_mem, stk); // Free allocated stack
|
rt_free_mem(os_stack_mem, stk); // Free allocated stack
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
sysThreadError(osErrorNoMemory); // Create task failed (Out of memory)
|
sysThreadError(osErrorNoMemory); // Create task failed (Out of memory)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -717,20 +735,26 @@ osThreadId svcThreadGetId (void) {
|
||||||
osStatus svcThreadTerminate (osThreadId thread_id) {
|
osStatus svcThreadTerminate (osThreadId thread_id) {
|
||||||
OS_RESULT res;
|
OS_RESULT res;
|
||||||
P_TCB ptcb;
|
P_TCB ptcb;
|
||||||
|
#ifndef __MBED_CMSIS_RTOS_CA9
|
||||||
void *stk;
|
void *stk;
|
||||||
|
#endif
|
||||||
|
|
||||||
ptcb = rt_tid2ptcb(thread_id); // Get TCB pointer
|
ptcb = rt_tid2ptcb(thread_id); // Get TCB pointer
|
||||||
if (ptcb == NULL) return osErrorParameter;
|
if (ptcb == NULL) return osErrorParameter;
|
||||||
|
|
||||||
|
#ifndef __MBED_CMSIS_RTOS_CA9
|
||||||
stk = ptcb->priv_stack ? ptcb->stack : NULL; // Private stack
|
stk = ptcb->priv_stack ? ptcb->stack : NULL; // Private stack
|
||||||
|
#endif
|
||||||
|
|
||||||
res = rt_tsk_delete(ptcb->task_id); // Delete task
|
res = rt_tsk_delete(ptcb->task_id); // Delete task
|
||||||
|
|
||||||
if (res == OS_R_NOK) return osErrorResource; // Delete task failed
|
if (res == OS_R_NOK) return osErrorResource; // Delete task failed
|
||||||
|
|
||||||
|
#ifndef __MBED_CMSIS_RTOS_CA9
|
||||||
if (stk != NULL) {
|
if (stk != NULL) {
|
||||||
rt_free_mem(os_stack_mem, stk); // Free private stack
|
rt_free_mem(os_stack_mem, stk); // Free private stack
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return osOK;
|
return osOK;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue