Skip to content

Commit

Permalink
RTX5: moved Timer Thread creation to osKernelStart
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertRostohar committed Apr 3, 2017
1 parent fe6dfc7 commit 1b483a0
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 19 deletions.
2 changes: 2 additions & 0 deletions CMSIS/RTOS2/RTX/Include/rtx_os.h
Expand Up @@ -308,6 +308,7 @@ typedef struct {
osRtxTimer_t *list; ///< Active Timer List
osRtxThread_t *thread; ///< Timer Thread
osRtxMessageQueue_t *mq; ///< Timer Message Queue
void (*tick)(void); ///< Timer Tick Function
} timer;
struct { ///< ISR Post Processing Queue
uint16_t max; ///< Maximum Items
Expand Down Expand Up @@ -339,6 +340,7 @@ typedef struct {
osRtxMpInfo_t *memory_pool; ///< Memory Pool Control Blocks
osRtxMpInfo_t *message_queue; ///< Message Queue Control Blocks
} mpi;
uint32_t padding;
} osRtxInfo_t;

extern osRtxInfo_t osRtxInfo; ///< OS Runtime Information
Expand Down
13 changes: 12 additions & 1 deletion CMSIS/RTOS2/RTX/Source/rtx_kernel.c
Expand Up @@ -260,6 +260,17 @@ osStatus_t svcRtxKernelStart (void) {
}
}

// Create Timer Thread
if (osRtxConfig.timer_mq_mcnt != 0U) {
if (osRtxInfo.timer.thread == NULL) {
osRtxInfo.timer.thread = svcRtxThreadNew(osRtxTimerThread, NULL, osRtxConfig.timer_thread_attr);
if (osRtxInfo.timer.thread == NULL) {
EvrRtxKernelError(osError);
return osError;
}
}
}

// Switch to Ready Thread with highest Priority
thread = osRtxThreadListGet(&osRtxInfo.thread.ready);
if (thread == NULL) {
Expand Down Expand Up @@ -433,7 +444,7 @@ void svcRtxKernelResume (uint32_t sleep_ticks) {
sleep_ticks -= timer->tick;
timer->tick = 1U;
do {
osRtxTimerTick();
osRtxInfo.timer.tick();
if (sleep_ticks == 0U) {
break;
}
Expand Down
5 changes: 5 additions & 0 deletions CMSIS/RTOS2/RTX/Source/rtx_lib.c
Expand Up @@ -197,6 +197,11 @@ static const osMessageQueueAttr_t os_timer_mq_attr = {
(uint32_t)sizeof(os_timer_mq_data)
};

#else

extern void osRtxTimerThread (void *argument);
void osRtxTimerThread (void *argument) {}

#endif // ((OS_TIMER_THREAD_STACK_SIZE != 0) && (OS_TIMER_CB_QUEUE != 0))


Expand Down
4 changes: 3 additions & 1 deletion CMSIS/RTOS2/RTX/Source/rtx_system.c
Expand Up @@ -124,7 +124,9 @@ void osRtxTick_Handler (void) {
osRtxInfo.kernel.tick++;

// Process Timers
osRtxTimerTick();
if (osRtxInfo.timer.tick != NULL) {
osRtxInfo.timer.tick();
}

// Process Thread Delays
osRtxThreadDelayTick();
Expand Down
27 changes: 10 additions & 17 deletions CMSIS/RTOS2/RTX/Source/rtx_timer.c
Expand Up @@ -110,11 +110,16 @@ void osRtxTimerTick (void) {
}

/// Timer Thread
__NO_RETURN void osRtxTimerThread (void *argument) {
__WEAK void osRtxTimerThread (void *argument) {
os_timer_finfo_t finfo;
osStatus_t status;
(void) argument;

osRtxInfo.timer.mq = osMessageQueueNew(osRtxConfig.timer_mq_mcnt, sizeof(os_timer_finfo_t), osRtxConfig.timer_mq_attr);
if (osRtxInfo.timer.mq == NULL) {
return;
}
osRtxInfo.timer.tick = osRtxTimerTick;
for (;;) {
status = osMessageQueueGet(osRtxInfo.timer.mq, &finfo, NULL, osWaitForever);
if (status == osOK) {
Expand All @@ -141,22 +146,10 @@ osTimerId_t svcRtxTimerNew (osTimerFunc_t func, osTimerType_t type, void *argume
uint8_t flags;
const char *name;

// Create common timer message queue if not yet active
if (osRtxInfo.timer.mq == NULL) {
osRtxInfo.timer.mq = svcRtxMessageQueueNew(osRtxConfig.timer_mq_mcnt, sizeof(os_timer_finfo_t), osRtxConfig.timer_mq_attr);
if (osRtxInfo.timer.mq == NULL) {
EvrRtxTimerError(NULL, osErrorResource);
return NULL;
}
}

// Create common timer thread if not yet active
if (osRtxInfo.timer.thread == NULL) {
osRtxInfo.timer.thread = svcRtxThreadNew(osRtxTimerThread, NULL, osRtxConfig.timer_thread_attr);
if (osRtxInfo.timer.thread == NULL) {
EvrRtxTimerError(NULL, osErrorResource);
return NULL;
}
// Check Timer Thread and MessageQueue
if ((osRtxInfo.timer.thread == NULL) || (osRtxInfo.timer.mq == NULL)) {
EvrRtxTimerError(NULL, osErrorResource);
return NULL;
}

// Check parameters
Expand Down

0 comments on commit 1b483a0

Please sign in to comment.