Skip to content

rtx update to v4.79 #1702

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

Merged
merged 9 commits into from
May 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libraries/net/lwip/lwip-sys/arch/sys_arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ void sys_sem_free(sys_sem_t *sem) {}
* @return a new mutex */
err_t sys_mutex_new(sys_mutex_t *mutex) {
#ifdef CMSIS_OS_RTX
#ifdef __MBED_CMSIS_RTOS_CA9
#if defined(__MBED_CMSIS_RTOS_CA9) || defined(__MBED_CMSIS_RTOS_CM)
memset(mutex->data, 0, sizeof(int32_t)*4);
#else
memset(mutex->data, 0, sizeof(int32_t)*3);
Expand Down
2 changes: 1 addition & 1 deletion libraries/net/lwip/lwip-sys/arch/sys_arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ typedef struct {
osMutexId id;
osMutexDef_t def;
#ifdef CMSIS_OS_RTX
#ifdef __MBED_CMSIS_RTOS_CA9
#if defined(__MBED_CMSIS_RTOS_CA9) || defined(__MBED_CMSIS_RTOS_CM)
int32_t data[4];
#else
int32_t data[3];
Expand Down
2 changes: 1 addition & 1 deletion libraries/rtos/rtos/Mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Mutex {
osMutexId _osMutexId;
osMutexDef_t _osMutexDef;
#ifdef CMSIS_OS_RTX
#ifdef __MBED_CMSIS_RTOS_CA9
#if defined(__MBED_CMSIS_RTOS_CA9) || defined(__MBED_CMSIS_RTOS_CM)
int32_t _mutex_data[4];
#else
int32_t _mutex_data[3];
Expand Down
4 changes: 3 additions & 1 deletion libraries/rtos/rtos/RtosTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ class RtosTimer {
private:
osTimerId _timer_id;
osTimerDef_t _timer;
#ifdef CMSIS_OS_RTX
#if defined(CMSIS_OS_RTX) && !defined(__MBED_CMSIS_RTOS_CM)
uint32_t _timer_data[5];
#else
uint32_t _timer_data[6];
#endif
};

Expand Down
39 changes: 37 additions & 2 deletions libraries/rtos/rtos/Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@
#include "mbed_error.h"
#include "rtos_idle.h"

// rt_tid2ptcb is an internal function which we exposed to get TCB for thread id
#undef NULL //Workaround for conflicting macros in rt_TypeDef.h and stdio.h
#include "rt_TypeDef.h"

extern "C" P_TCB rt_tid2ptcb(osThreadId thread_id);

namespace rtos {

Thread::Thread(void (*task)(void const *argument), void *argument,
osPriority priority, uint32_t stack_size, unsigned char *stack_pointer) {
#ifdef CMSIS_OS_RTX
#ifdef __MBED_CMSIS_RTOS_CM
_thread_def.pthread = task;
_thread_def.tpriority = priority;
_thread_def.stacksize = stack_size;
Expand Down Expand Up @@ -71,8 +77,10 @@ int32_t Thread::signal_clr(int32_t signals) {
}

Thread::State Thread::get_state() {
#ifndef __MBED_CMSIS_RTOS_CA9
#if !defined(__MBED_CMSIS_RTOS_CA9) && !defined(__MBED_CMSIS_RTOS_CM)
#ifdef CMSIS_OS_RTX
return ((State)_thread_def.tcb.state);
#endif
#else
uint8_t status;
status = osThreadGetState(_tid);
Expand All @@ -82,36 +90,61 @@ Thread::State Thread::get_state() {

uint32_t Thread::stack_size() {
#ifndef __MBED_CMSIS_RTOS_CA9
#if defined(CMSIS_OS_RTX) && !defined(__MBED_CMSIS_RTOS_CM)
return _thread_def.tcb.priv_stack;
#else
P_TCB tcb = rt_tid2ptcb(_tid);
return tcb->priv_stack;
#endif
#else
return 0;
#endif
}

uint32_t Thread::free_stack() {
#ifndef __MBED_CMSIS_RTOS_CA9
#if defined(CMSIS_OS_RTX) && !defined(__MBED_CMSIS_RTOS_CM)
uint32_t bottom = (uint32_t)_thread_def.tcb.stack;
return _thread_def.tcb.tsk_stack - bottom;
#else
P_TCB tcb = rt_tid2ptcb(_tid);
uint32_t bottom = (uint32_t)tcb->stack;
return tcb->tsk_stack - bottom;
#endif
#else
return 0;
#endif
}

uint32_t Thread::used_stack() {
#ifndef __MBED_CMSIS_RTOS_CA9
#if defined(CMSIS_OS_RTX) && !defined(__MBED_CMSIS_RTOS_CM)
uint32_t top = (uint32_t)_thread_def.tcb.stack + _thread_def.tcb.priv_stack;
return top - _thread_def.tcb.tsk_stack;
#else
P_TCB tcb = rt_tid2ptcb(_tid);
uint32_t top = (uint32_t)tcb->stack + tcb->priv_stack;
return top - tcb->tsk_stack;
#endif
#else
return 0;
#endif
}

uint32_t Thread::max_stack() {
#ifndef __MBED_CMSIS_RTOS_CA9
#if defined(CMSIS_OS_RTX) && !defined(__MBED_CMSIS_RTOS_CM)
uint32_t high_mark = 0;
while (_thread_def.tcb.stack[high_mark] == 0xE25A2EA5)
high_mark++;
return _thread_def.tcb.priv_stack - (high_mark * 4);
#else
P_TCB tcb = rt_tid2ptcb(_tid);
uint32_t high_mark = 0;
while (tcb->stack[high_mark] == 0xE25A2EA5)
high_mark++;
return tcb->priv_stack - (high_mark * 4);
#endif
#else
return 0;
#endif
Expand Down Expand Up @@ -139,9 +172,11 @@ void Thread::attach_idle_hook(void (*fptr)(void)) {

Thread::~Thread() {
terminate();
#ifdef __MBED_CMSIS_RTOS_CM
if (_dynamic_stack) {
delete[] (_thread_def.stack_pointer);
}
#endif
}

}
85 changes: 61 additions & 24 deletions libraries/rtos/rtx/TARGET_CORTEX_M/HAL_CM.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*----------------------------------------------------------------------------
* RL-ARM - RTX
* CMSIS-RTOS - RTX
*----------------------------------------------------------------------------
* Name: HAL_CM.C
* Purpose: Hardware Abstraction Layer for Cortex-M
* Rev.: V4.60
* Rev.: V4.79
*----------------------------------------------------------------------------
*
* Copyright (c) 1999-2009 KEIL, 2009-2012 ARM Germany GmbH
* Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand All @@ -33,7 +33,7 @@
*---------------------------------------------------------------------------*/

#include "rt_TypeDef.h"
#include "RTX_Conf.h"
#include "RTX_Config.h"
#include "rt_HAL_CM.h"


Expand All @@ -58,12 +58,15 @@ void rt_init_stack (P_TCB p_TCB, FUNCP task_body) {

/* Prepare a complete interrupt frame for first task start */
size = p_TCB->priv_stack >> 2;
if (size == 0U) {
size = (U16)os_stackinfo >> 2;
}

/* Write to the top of stack. */
stk = &p_TCB->stack[size];

/* Auto correct to 8-byte ARM stack alignment. */
if ((U32)stk & 0x04) {
if ((U32)stk & 0x04U) {
stk--;
}

Expand All @@ -74,8 +77,8 @@ void rt_init_stack (P_TCB p_TCB, FUNCP task_body) {
stk[14] = (U32)task_body;

/* Clear R4-R11,R0-R3,R12,LR registers. */
for (i = 0; i < 14; i++) {
stk[i] = 0;
for (i = 0U; i < 14U; i++) {
stk[i] = 0U;
}

/* Assign a void pointer to R0. */
Expand All @@ -87,31 +90,67 @@ void rt_init_stack (P_TCB p_TCB, FUNCP task_body) {
/* Task entry point. */
p_TCB->ptask = task_body;


#ifdef __MBED_CMSIS_RTOS_CM
/* Set a magic word for checking of stack overflow.
For the main thread (ID: 0x01) the stack is in a memory area shared with the
For the main thread (ID: 0x02) the stack is in a memory area shared with the
heap, therefore the last word of the stack is a moving target.
We want to do stack/heap collision detection instead.
Similar applies to stack filling for the magic pattern.
*/
if (p_TCB->task_id != 0x01)
p_TCB->stack[0] = MAGIC_WORD;
if (p_TCB->task_id != 0x02) {
p_TCB->stack[0] = MAGIC_WORD;

/* Initialize stack with magic pattern. */
if (os_stackinfo & 0x10000000U) {
if (size > (16U+1U)) {
for (i = ((size - 16U)/2U) - 1U; i; i--) {
stk -= 2U;
stk[1] = MAGIC_PATTERN;
stk[0] = MAGIC_PATTERN;
}
if (--stk > p_TCB->stack) {
*stk = MAGIC_PATTERN;
}
}
}
}
#else
/* Initialize stack with magic pattern. */
if (os_stackinfo & 0x10000000U) {
if (size > (16U+1U)) {
for (i = ((size - 16U)/2U) - 1U; i; i--) {
stk -= 2U;
stk[1] = MAGIC_PATTERN;
stk[0] = MAGIC_PATTERN;
}
if (--stk > p_TCB->stack) {
*stk = MAGIC_PATTERN;
}
}
}

/* Set a magic word for checking of stack overflow. */
p_TCB->stack[0] = MAGIC_WORD;
#endif
}


/*--------------------------- rt_ret_val ----------------------------------*/

static __inline U32 *rt_ret_regs (P_TCB p_TCB) {
/* Get pointer to task return value registers (R0..R3) in Stack */
#if (__TARGET_FPU_VFP)
#if defined(__TARGET_FPU_VFP)
if (p_TCB->stack_frame) {
/* Extended Stack Frame: R4-R11,S16-S31,R0-R3,R12,LR,PC,xPSR,S0-S15,FPSCR */
return (U32 *)(p_TCB->tsk_stack + 8*4 + 16*4);
return (U32 *)(p_TCB->tsk_stack + (8U*4U) + (16U*4U));
} else {
/* Basic Stack Frame: R4-R11,R0-R3,R12,LR,PC,xPSR */
return (U32 *)(p_TCB->tsk_stack + 8*4);
return (U32 *)(p_TCB->tsk_stack + (8U*4U));
}
#else
/* Stack Frame: R4-R11,R0-R3,R12,LR,PC,xPSR */
return (U32 *)(p_TCB->tsk_stack + 8*4);
return (U32 *)(p_TCB->tsk_stack + (8U*4U));
#endif
}

Expand All @@ -135,9 +174,9 @@ void rt_ret_val2(P_TCB p_TCB, U32 v0, U32 v1) {

#ifdef DBG_MSG
void dbg_init (void) {
if ((DEMCR & DEMCR_TRCENA) &&
(ITM_CONTROL & ITM_ITMENA) &&
(ITM_ENABLE & (1UL << 31))) {
if (((DEMCR & DEMCR_TRCENA) != 0U) &&
((ITM_CONTROL & ITM_ITMENA) != 0U) &&
((ITM_ENABLE & (1UL << 31)) != 0U)) {
dbg_msg = __TRUE;
}
}
Expand All @@ -147,24 +186,22 @@ void dbg_init (void) {

#ifdef DBG_MSG
void dbg_task_notify (P_TCB p_tcb, BOOL create) {
while (ITM_PORT31_U32 == 0);
while (ITM_PORT31_U32 == 0U);
ITM_PORT31_U32 = (U32)p_tcb->ptask;
while (ITM_PORT31_U32 == 0);
ITM_PORT31_U16 = (create << 8) | p_tcb->task_id;
while (ITM_PORT31_U32 == 0U);
ITM_PORT31_U16 = (U16)((create << 8) | p_tcb->task_id);
}
#endif

/*--------------------------- dbg_task_switch -------------------------------*/

#ifdef DBG_MSG
void dbg_task_switch (U32 task_id) {
while (ITM_PORT31_U32 == 0);
ITM_PORT31_U8 = task_id;
while (ITM_PORT31_U32 == 0U);
ITM_PORT31_U8 = (U8)task_id;
}
#endif


/*----------------------------------------------------------------------------
* end of file
*---------------------------------------------------------------------------*/

Loading