aboutsummaryrefslogtreecommitdiffstats
path: root/os/rt/src/chsys.c
diff options
context:
space:
mode:
Diffstat (limited to 'os/rt/src/chsys.c')
-rw-r--r--os/rt/src/chsys.c90
1 files changed, 48 insertions, 42 deletions
diff --git a/os/rt/src/chsys.c b/os/rt/src/chsys.c
index a22a66482..d9ca6d81a 100644
--- a/os/rt/src/chsys.c
+++ b/os/rt/src/chsys.c
@@ -91,13 +91,11 @@ static void _idle_thread(void *p) {
* @special
*/
void chSysInit(void) {
-#if CH_DBG_ENABLE_STACK_CHECK == TRUE
extern stkalign_t __main_thread_stack_base__;
-#endif
- port_init();
_scheduler_init();
_vt_init();
+
#if CH_DBG_SYSTEM_STATE_CHECK == TRUE
ch.dbg.isr_cnt = (cnt_t)0;
ch.dbg.lock_cnt = (cnt_t)0;
@@ -114,30 +112,34 @@ void chSysInit(void) {
#if CH_DBG_STATISTICS == TRUE
_stats_init();
#endif
-#if CH_DBG_ENABLE_TRACE == TRUE
+#if CH_DBG_TRACE_MASK != CH_DBG_TRACE_MASK_NONE
_dbg_trace_init();
#endif
#if CH_CFG_NO_IDLE_THREAD == FALSE
/* Now this instructions flow becomes the main thread.*/
- setcurrp(_thread_init(&ch.mainthread, NORMALPRIO));
+ currp = _thread_init(&ch.mainthread, "main", NORMALPRIO);
#else
/* Now this instructions flow becomes the idle thread.*/
- setcurrp(_thread_init(&ch.mainthread, IDLEPRIO));
+ currp = _thread_init(&ch.mainthread, "idle", IDLEPRIO));
#endif
- currp->p_state = CH_STATE_CURRENT;
-#if CH_DBG_ENABLE_STACK_CHECK == TRUE
- /* This is a special case because the main thread thread_t structure is not
- adjacent to its stack area.*/
- currp->p_stklimit = &__main_thread_stack_base__;
-#endif
+ /* Setting up the base address of the static main thread stack.*/
+ currp->stklimit = &__main_thread_stack_base__;
+
+ /* Setting up the caller as current thread.*/
+ currp->state = CH_STATE_CURRENT;
+
+ /* Port layer initialization last because it depend on some of the
+ initializations performed before.*/
+ port_init();
#if CH_DBG_STATISTICS == TRUE
/* Starting measurement for this thread.*/
chTMStartMeasurementX(&currp->p_stats);
#endif
+ /* It is alive now.*/
chSysEnable();
#if CH_CFG_USE_REGISTRY == TRUE
@@ -148,15 +150,19 @@ void chSysInit(void) {
#if CH_CFG_NO_IDLE_THREAD == FALSE
{
- /* This thread has the lowest priority in the system, its role is just to
- serve interrupts in its context while keeping the lowest energy saving
- mode compatible with the system status.*/
- thread_t *tp = chThdCreateStatic(ch.idle_thread_wa,
- sizeof(ch.idle_thread_wa),
- IDLEPRIO,
- (tfunc_t)_idle_thread,
- NULL);
- chRegSetThreadNameX(tp, "idle");
+ static const thread_descriptor_t idle_descriptor = {
+ "idle",
+ THD_WORKING_AREA_BASE(ch.idle_thread_wa),
+ THD_WORKING_AREA_END(ch.idle_thread_wa),
+ IDLEPRIO,
+ _idle_thread,
+ NULL
+ };
+
+ /* This thread has the lowest priority in the system, its role is just to
+ serve interrupts in its context while keeping the lowest energy saving
+ mode compatible with the system status.*/
+ (void) chThdCreate(&idle_descriptor);
}
#endif
}
@@ -177,9 +183,11 @@ void chSysHalt(const char *reason) {
port_disable();
-#if defined(CH_CFG_SYSTEM_HALT_HOOK) || defined(__DOXYGEN__)
+ /* Halt hook code, usually empty.*/
CH_CFG_SYSTEM_HALT_HOOK(reason);
-#endif
+
+ /* Logging the event.*/
+ _dbg_trace_halt(reason);
/* Pointing to the passed message.*/
ch.dbg.panic_msg = reason;
@@ -224,17 +232,17 @@ bool chSysIntegrityCheckI(unsigned testmask) {
/* Scanning the ready list forward.*/
n = (cnt_t)0;
- tp = ch.rlist.r_queue.p_next;
- while (tp != (thread_t *)&ch.rlist.r_queue) {
+ tp = ch.rlist.queue.next;
+ while (tp != (thread_t *)&ch.rlist.queue) {
n++;
- tp = tp->p_next;
+ tp = tp->next;
}
/* Scanning the ready list backward.*/
- tp = ch.rlist.r_queue.p_prev;
- while (tp != (thread_t *)&ch.rlist.r_queue) {
+ tp = ch.rlist.queue.prev;
+ while (tp != (thread_t *)&ch.rlist.queue) {
n--;
- tp = tp->p_prev;
+ tp = tp->prev;
}
/* The number of elements must match.*/
@@ -249,17 +257,17 @@ bool chSysIntegrityCheckI(unsigned testmask) {
/* Scanning the timers list forward.*/
n = (cnt_t)0;
- vtp = ch.vtlist.vt_next;
+ vtp = ch.vtlist.next;
while (vtp != (virtual_timer_t *)&ch.vtlist) {
n++;
- vtp = vtp->vt_next;
+ vtp = vtp->next;
}
/* Scanning the timers list backward.*/
- vtp = ch.vtlist.vt_prev;
+ vtp = ch.vtlist.prev;
while (vtp != (virtual_timer_t *)&ch.vtlist) {
n--;
- vtp = vtp->vt_prev;
+ vtp = vtp->prev;
}
/* The number of elements must match.*/
@@ -274,17 +282,17 @@ bool chSysIntegrityCheckI(unsigned testmask) {
/* Scanning the ready list forward.*/
n = (cnt_t)0;
- tp = ch.rlist.r_newer;
+ tp = ch.rlist.newer;
while (tp != (thread_t *)&ch.rlist) {
n++;
- tp = tp->p_newer;
+ tp = tp->newer;
}
/* Scanning the ready list backward.*/
- tp = ch.rlist.r_older;
+ tp = ch.rlist.older;
while (tp != (thread_t *)&ch.rlist) {
n--;
- tp = tp->p_older;
+ tp = tp->older;
}
/* The number of elements must match.*/
@@ -320,18 +328,16 @@ void chSysTimerHandlerI(void) {
#if CH_CFG_TIME_QUANTUM > 0
/* Running thread has not used up quantum yet? */
- if (currp->p_preempt > (tslices_t)0) {
+ if (currp->preempt > (tslices_t)0) {
/* Decrement remaining quantum.*/
- currp->p_preempt--;
+ currp->preempt--;
}
#endif
#if CH_DBG_THREADS_PROFILING == TRUE
- currp->p_time++;
+ currp->time++;
#endif
chVTDoTickI();
-#if defined(CH_CFG_SYSTEM_TICK_HOOK)
CH_CFG_SYSTEM_TICK_HOOK();
-#endif
}
/**