Skip to content
Permalink
Browse files

RTX5: moved Timer Thread creation to osKernelStart

  • Loading branch information
RobertRostohar committed Apr 3, 2017
1 parent fe6dfc7 commit 1b483a0202e24844da8bd6a8dc5b7830908c961a
@@ -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
@@ -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
@@ -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) {
@@ -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;
}
@@ -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))


@@ -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();
@@ -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) {
@@ -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

0 comments on commit 1b483a0

Please sign in to comment.
You can’t perform that action at this time.