From 84e044f176cee7c6946b24c36c90f63534b5b369 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 19 Jul 2013 12:22:31 +0000 Subject: Renamed Thread to thread_t. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@5995 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chsys.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/kernel/src/chsys.c') diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index a6f1d15ba..f960d9b79 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -75,7 +75,7 @@ void _idle_thread(void *p) { * @special */ void chSysInit(void) { - static Thread mainthread; + static thread_t mainthread; #if CH_DBG_ENABLE_STACK_CHECK extern stkalign_t __main_thread_stack_base__; #endif @@ -97,7 +97,7 @@ void chSysInit(void) { setcurrp(_thread_init(&mainthread, NORMALPRIO)); currp->p_state = THD_STATE_CURRENT; #if CH_DBG_ENABLE_STACK_CHECK - /* This is a special case because the main thread Thread structure is not + /* 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 -- cgit v1.2.3 From 25ddb1c801f06a3be7171e20dcfd46d11a75f112 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 19 Jul 2013 14:51:35 +0000 Subject: First cleanup pass finished, queues and streams not yet removed. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@5999 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chsys.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) (limited to 'os/kernel/src/chsys.c') diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index f960d9b79..578de3ccf 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -35,12 +35,30 @@ #include "ch.h" +/*===========================================================================*/ +/* Module exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local variables. */ +/*===========================================================================*/ + #if !CH_NO_IDLE_THREAD || defined(__DOXYGEN__) /** * @brief Idle thread working area. */ -WORKING_AREA(_idle_thread_wa, PORT_IDLE_THREAD_STACK_SIZE); +static WORKING_AREA(_idle_thread_wa, PORT_IDLE_THREAD_STACK_SIZE); +#endif /* CH_NO_IDLE_THREAD */ + +/*===========================================================================*/ +/* Module local functions. */ +/*===========================================================================*/ +#if !CH_NO_IDLE_THREAD || defined(__DOXYGEN__) /** * @brief This function implements the idle thread infinite loop. * @details The function puts the processor in the lowest power mode capable @@ -51,7 +69,7 @@ WORKING_AREA(_idle_thread_wa, PORT_IDLE_THREAD_STACK_SIZE); * * @param[in] p the thread parameter, unused in this scenario */ -void _idle_thread(void *p) { +static void _idle_thread(void *p) { (void)p; chRegSetThreadName("idle"); @@ -62,6 +80,10 @@ void _idle_thread(void *p) { } #endif /* CH_NO_IDLE_THREAD */ +/*===========================================================================*/ +/* Module exported functions. */ +/*===========================================================================*/ + /** * @brief ChibiOS/RT initialization. * @details After executing this function the current instructions stream @@ -116,6 +138,29 @@ void chSysInit(void) { #endif } +/** + * @brief Halts the system. + * @details This function is invoked by the operating system when an + * unrecoverable error is detected, for example because a programming + * error in the application code that triggers an assertion while + * in debug mode. + * @note Can be invoked from any system state. + * + * @special + */ +void chSysHalt(void) { + + chSysDisable(); + +#if defined(SYSTEM_HALT_HOOK) || defined(__DOXYGEN__) + SYSTEM_HALT_HOOK(); +#endif + + /* Harmless infinite loop.*/ + while (true) + ; +} + /** * @brief Handles time ticks for round robin preemption and timer increments. * @details Decrements the remaining time quantum of the running thread -- cgit v1.2.3 From 390ed322cb8f40cb9250021cde5f48acb928d291 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 20 Jul 2013 07:24:12 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6001 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chsys.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/kernel/src/chsys.c') diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index 578de3ccf..b3d99a7d9 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -73,7 +73,7 @@ static void _idle_thread(void *p) { (void)p; chRegSetThreadName("idle"); - while (TRUE) { + while (true) { port_wait_for_interrupt(); IDLE_LOOP_HOOK(); } -- cgit v1.2.3 From 49d71a01abeefa000a4cd7a556052d826b096d49 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 20 Jul 2013 10:12:44 +0000 Subject: Renamed or added prefix to all hernel configuration options. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6010 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chsys.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'os/kernel/src/chsys.c') diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index b3d99a7d9..97f01f933 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -47,18 +47,18 @@ /* Module local variables. */ /*===========================================================================*/ -#if !CH_NO_IDLE_THREAD || defined(__DOXYGEN__) +#if !CH_CFG_NO_IDLE_THREAD || defined(__DOXYGEN__) /** * @brief Idle thread working area. */ static WORKING_AREA(_idle_thread_wa, PORT_IDLE_THREAD_STACK_SIZE); -#endif /* CH_NO_IDLE_THREAD */ +#endif /* CH_CFG_NO_IDLE_THREAD */ /*===========================================================================*/ /* Module local functions. */ /*===========================================================================*/ -#if !CH_NO_IDLE_THREAD || defined(__DOXYGEN__) +#if !CH_CFG_NO_IDLE_THREAD || defined(__DOXYGEN__) /** * @brief This function implements the idle thread infinite loop. * @details The function puts the processor in the lowest power mode capable @@ -75,10 +75,10 @@ static void _idle_thread(void *p) { chRegSetThreadName("idle"); while (true) { port_wait_for_interrupt(); - IDLE_LOOP_HOOK(); + CH_CFG_IDLE_LOOP_HOOK(); } } -#endif /* CH_NO_IDLE_THREAD */ +#endif /* CH_CFG_NO_IDLE_THREAD */ /*===========================================================================*/ /* Module exported functions. */ @@ -105,10 +105,10 @@ void chSysInit(void) { port_init(); _scheduler_init(); _vt_init(); -#if CH_USE_MEMCORE +#if CH_CFG_USE_MEMCORE _core_init(); #endif -#if CH_USE_HEAP +#if CH_CFG_USE_HEAP _heap_init(); #endif #if CH_DBG_ENABLE_TRACE @@ -129,7 +129,7 @@ void chSysInit(void) { active, else the parameter is ignored.*/ chRegSetThreadName((const char *)&ch_debug); -#if !CH_NO_IDLE_THREAD +#if !CH_CFG_NO_IDLE_THREAD /* 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.*/ @@ -152,8 +152,8 @@ void chSysHalt(void) { chSysDisable(); -#if defined(SYSTEM_HALT_HOOK) || defined(__DOXYGEN__) - SYSTEM_HALT_HOOK(); +#if defined(CH_CFG_SYSTEM_HALT_HOOK) || defined(__DOXYGEN__) + CH_CFG_SYSTEM_HALT_HOOK(); #endif /* Harmless infinite loop.*/ @@ -167,7 +167,7 @@ void chSysHalt(void) { * and preempts it when the quantum is used up. Increments system * time and manages the timers. * @note The frequency of the timer determines the system tick granularity - * and, together with the @p CH_TIME_QUANTUM macro, the round robin + * and, together with the @p CH_CFG_TIME_QUANTUM macro, the round robin * interval. * * @iclass @@ -176,7 +176,7 @@ void chSysTimerHandlerI(void) { chDbgCheckClassI(); -#if CH_TIME_QUANTUM > 0 +#if CH_CFG_TIME_QUANTUM > 0 /* Running thread has not used up quantum yet? */ if (currp->p_preempt > 0) /* Decrement remaining quantum.*/ @@ -186,8 +186,8 @@ void chSysTimerHandlerI(void) { currp->p_time++; #endif chVTDoTickI(); -#if defined(SYSTEM_TICK_EVENT_HOOK) - SYSTEM_TICK_EVENT_HOOK(); +#if defined(CH_CFG_SYSTEM_TICK_HOOK) + CH_CFG_SYSTEM_TICK_HOOK(); #endif } -- cgit v1.2.3 From 40f413d3c97a7694703938cd031ce15912b29ff7 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 24 Jul 2013 14:54:26 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6025 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chsys.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'os/kernel/src/chsys.c') diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index 97f01f933..61157b1b9 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -117,7 +117,7 @@ void chSysInit(void) { /* Now this instructions flow becomes the main thread.*/ setcurrp(_thread_init(&mainthread, NORMALPRIO)); - currp->p_state = THD_STATE_CURRENT; + currp->p_state = CH_STATE_CURRENT; #if CH_DBG_ENABLE_STACK_CHECK /* This is a special case because the main thread thread_t structure is not adjacent to its stack area.*/ @@ -191,4 +191,47 @@ void chSysTimerHandlerI(void) { #endif } + +/** + * @brief Returns the execution context and enters the kernel lock mode. + * @details This functions enters into a critical zone and can be called + * from any context. Because its flexibility it is less efficient + * than @p chSysLock() which is preferable when the calling context + * is known. + * + * @return The previous system status, the encoding of this + * status word is architecture-dependent but zero is + * assumed to mean not-locked. + * + * @special + */ +syssts_t chSysGetAndLockX(void) { + + syssts_t sts = port_get_status(); + if (!sts) { + if (port_get_context()) + chSysLockFromISR(); + else + chSysLock(); + } + return sts; +} + +/** + * @brief Restores the specified execution status. + * + * @param[in] sts the system status to be restored. + * + * @special + */ +void chSysRestoreLockX(syssts_t sts) { + + if (!sts) { + if (port_get_context()) + chSysUnlockFromISR(); + else + chSysUnlock(); + } +} + /** @} */ -- cgit v1.2.3 From b21e9a01e5590dd3fe015aeffbe2a15e985af865 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 24 Jul 2013 15:38:50 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6027 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chsys.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'os/kernel/src/chsys.c') diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index 61157b1b9..7a6d3ea20 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -115,8 +115,14 @@ void chSysInit(void) { _trace_init(); #endif +#if !CH_CFG_NO_IDLE_THREAD /* Now this instructions flow becomes the main thread.*/ setcurrp(_thread_init(&mainthread, NORMALPRIO)); +#else + /* Now this instructions flow becomes the main thread.*/ + setcurrp(_thread_init(&mainthread, IDLEPRIO)); +#endif + currp->p_state = CH_STATE_CURRENT; #if CH_DBG_ENABLE_STACK_CHECK /* This is a special case because the main thread thread_t structure is not -- cgit v1.2.3 From 0ca0bc18f97a40b9637f225a114f740b30db5cc1 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 25 Jul 2013 12:40:58 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6028 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chsys.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'os/kernel/src/chsys.c') diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index 7a6d3ea20..4a67c7042 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -206,16 +206,15 @@ void chSysTimerHandlerI(void) { * is known. * * @return The previous system status, the encoding of this - * status word is architecture-dependent but zero is - * assumed to mean not-locked. + * status word is architecture-dependent and opaque. * * @special */ syssts_t chSysGetAndLockX(void) { - syssts_t sts = port_get_status(); - if (!sts) { - if (port_get_context()) + syssts_t sts = port_get_irq_status(); + if (port_irq_enabled(sts)) { + if (port_is_isr_context()) chSysLockFromISR(); else chSysLock(); @@ -232,8 +231,8 @@ syssts_t chSysGetAndLockX(void) { */ void chSysRestoreLockX(syssts_t sts) { - if (!sts) { - if (port_get_context()) + if (port_irq_enabled(sts)) { + if (port_is_isr_context()) chSysUnlockFromISR(); else chSysUnlock(); -- cgit v1.2.3 From 0cb6bc9b9d260beb05fcc9e2ec4d72f0ba621b71 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 28 Jul 2013 12:15:57 +0000 Subject: RT measurements unit added. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6036 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chsys.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'os/kernel/src/chsys.c') diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index 4a67c7042..91277dc60 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -105,6 +105,9 @@ void chSysInit(void) { port_init(); _scheduler_init(); _vt_init(); +#if CH_CFG_USE_RT + _rt_init(); +#endif #if CH_CFG_USE_MEMCORE _core_init(); #endif -- cgit v1.2.3 From 61f841306aaa11b1471db1deb00470ea48f646fd Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 29 Jul 2013 13:28:35 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6037 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chsys.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/kernel/src/chsys.c') diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index 91277dc60..91761b66b 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -211,7 +211,7 @@ void chSysTimerHandlerI(void) { * @return The previous system status, the encoding of this * status word is architecture-dependent and opaque. * - * @special + * @xclass */ syssts_t chSysGetAndLockX(void) { @@ -230,7 +230,7 @@ syssts_t chSysGetAndLockX(void) { * * @param[in] sts the system status to be restored. * - * @special + * @xclass */ void chSysRestoreLockX(syssts_t sts) { -- cgit v1.2.3 From ca4b2f91b7a24abeb6ea7fa43c1816397fb966c4 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 29 Jul 2013 14:31:13 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6039 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chsys.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'os/kernel/src/chsys.c') diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index 91761b66b..0727532ee 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -105,8 +105,8 @@ void chSysInit(void) { port_init(); _scheduler_init(); _vt_init(); -#if CH_CFG_USE_RT - _rt_init(); +#if CH_CFG_USE_TM + _tm_init(); #endif #if CH_CFG_USE_MEMCORE _core_init(); @@ -114,6 +114,9 @@ void chSysInit(void) { #if CH_CFG_USE_HEAP _heap_init(); #endif +#if CH_DBG_STATISTICS + _stats_init(); +#endif #if CH_DBG_ENABLE_TRACE _trace_init(); #endif -- cgit v1.2.3 From f569bcec23452c190248aab184a125f3a52e2eb8 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 29 Jul 2013 15:13:52 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6040 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chsys.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'os/kernel/src/chsys.c') diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index 0727532ee..168bd1376 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -29,6 +29,7 @@ * - Interrupt Handling. * - Power Management. * - Abnormal Termination. + * - Realtime counter. * . * @{ */ @@ -245,4 +246,49 @@ void chSysRestoreLockX(syssts_t sts) { } } + +#if CH_PORT_SUPPORTS_RT || defined(__DOXYGEN__) +/** + * @brief Realtime window test. + * @details This function verifies if the current realtime counter value + * lies within the specified range or not. The test takes care + * of the realtime counter wrapping to zero on overflow. + * @note When start==end then the function returns always true because the + * whole time range is specified. + * @note This function is only available if the port layer supports the + * option @p CH_PORT_SUPPORTS_RT. + * + * @param[in] cnt the counter value to be tested + * @param[in] start the start of the time window (inclusive) + * @param[in] end the end of the time window (non inclusive) + * @retval true current time within the specified time window. + * @retval false current time not within the specified time window. + * + * @xclass + */ +bool chSysIsCounterWithinX(rtcnt_t cnt, rtcnt_t start, rtcnt_t end) { + + return end > start ? (cnt >= start) && (cnt < end) : + (cnt >= start) || (cnt < end); +} + +/** + * @brief Polled delay. + * @note The real delay is always few cycles in excess of the specified + * value. + * @note This function is only available if the port layer supports the + * option @p CH_PORT_SUPPORTS_RT. + * + * @param[in] cycles number of cycles + * + * @xclass + */ +void chSysPolledDelayX(rtcnt_t cycles) { + rtcnt_t start = chSysGetRealtimeCounterX(); + rtcnt_t end = start + cycles; + while (chSysIsCounterWithinX(chSysGetRealtimeCounterX(), start, end)) + ; +} +#endif /* CH_PORT_SUPPORTS_RT */ + /** @} */ -- cgit v1.2.3 From 64403d8f188725bc5814813371382bc148956a83 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 30 Jul 2013 14:23:37 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6048 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chsys.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/kernel/src/chsys.c') diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index 168bd1376..7057a7e01 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -163,7 +163,7 @@ void chSysInit(void) { */ void chSysHalt(void) { - chSysDisable(); + port_disable(); #if defined(CH_CFG_SYSTEM_HALT_HOOK) || defined(__DOXYGEN__) CH_CFG_SYSTEM_HALT_HOOK(); -- cgit v1.2.3 From ec7cf10fcdaf32a56624f408be5830e4d5a0eef2 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 6 Aug 2013 09:24:30 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6085 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chsys.c | 1 - 1 file changed, 1 deletion(-) (limited to 'os/kernel/src/chsys.c') diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index 7057a7e01..cd4832831 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -246,7 +246,6 @@ void chSysRestoreLockX(syssts_t sts) { } } - #if CH_PORT_SUPPORTS_RT || defined(__DOXYGEN__) /** * @brief Realtime window test. -- cgit v1.2.3 From b5349cc22d7deade864d5ceb795a33af0a2eca15 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 6 Aug 2013 09:45:35 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6086 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chsys.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/kernel/src/chsys.c') diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index cd4832831..2494706d7 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -52,7 +52,7 @@ /** * @brief Idle thread working area. */ -static WORKING_AREA(_idle_thread_wa, PORT_IDLE_THREAD_STACK_SIZE); +static WORKING_AREA(_idle_thread_wa, CH_PORT_IDLE_THREAD_STACK_SIZE); #endif /* CH_CFG_NO_IDLE_THREAD */ /*===========================================================================*/ -- cgit v1.2.3 From c3dc5598c315f4650bfcd1e595104a2ace7aa87c Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 10 Aug 2013 08:07:43 +0000 Subject: Global variables consolidation. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6116 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chsys.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'os/kernel/src/chsys.c') diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index 2494706d7..9212cbf5f 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -48,6 +48,11 @@ /* Module local variables. */ /*===========================================================================*/ +/** + * @brief System data structures. + */ +ch_system_t ch; + #if !CH_CFG_NO_IDLE_THREAD || defined(__DOXYGEN__) /** * @brief Idle thread working area. -- cgit v1.2.3 From a1435e018bfc9919cb76b1356509ecc883767fb4 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 10 Aug 2013 14:51:16 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6123 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chsys.c | 298 -------------------------------------------------- 1 file changed, 298 deletions(-) delete mode 100644 os/kernel/src/chsys.c (limited to 'os/kernel/src/chsys.c') diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c deleted file mode 100644 index 9212cbf5f..000000000 --- a/os/kernel/src/chsys.c +++ /dev/null @@ -1,298 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012,2013 Giovanni Di Sirio. - - This file is part of ChibiOS/RT. - - ChibiOS/RT is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS/RT is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/** - * @file chsys.c - * @brief System related code. - * - * @addtogroup system - * @details System related APIs and services: - * - Initialization. - * - Locks. - * - Interrupt Handling. - * - Power Management. - * - Abnormal Termination. - * - Realtime counter. - * . - * @{ - */ - -#include "ch.h" - -/*===========================================================================*/ -/* Module exported variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local types. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local variables. */ -/*===========================================================================*/ - -/** - * @brief System data structures. - */ -ch_system_t ch; - -#if !CH_CFG_NO_IDLE_THREAD || defined(__DOXYGEN__) -/** - * @brief Idle thread working area. - */ -static WORKING_AREA(_idle_thread_wa, CH_PORT_IDLE_THREAD_STACK_SIZE); -#endif /* CH_CFG_NO_IDLE_THREAD */ - -/*===========================================================================*/ -/* Module local functions. */ -/*===========================================================================*/ - -#if !CH_CFG_NO_IDLE_THREAD || defined(__DOXYGEN__) -/** - * @brief This function implements the idle thread infinite loop. - * @details The function puts the processor in the lowest power mode capable - * to serve interrupts.
- * The priority is internally set to the minimum system value so - * that this thread is executed only if there are no other ready - * threads in the system. - * - * @param[in] p the thread parameter, unused in this scenario - */ -static void _idle_thread(void *p) { - - (void)p; - chRegSetThreadName("idle"); - while (true) { - port_wait_for_interrupt(); - CH_CFG_IDLE_LOOP_HOOK(); - } -} -#endif /* CH_CFG_NO_IDLE_THREAD */ - -/*===========================================================================*/ -/* Module exported functions. */ -/*===========================================================================*/ - -/** - * @brief ChibiOS/RT initialization. - * @details After executing this function the current instructions stream - * becomes the main thread. - * @pre Interrupts must be still disabled when @p chSysInit() is invoked - * and are internally enabled. - * @post The main thread is created with priority @p NORMALPRIO. - * @note This function has special, architecture-dependent, requirements, - * see the notes into the various port reference manuals. - * - * @special - */ -void chSysInit(void) { - static thread_t mainthread; -#if CH_DBG_ENABLE_STACK_CHECK - extern stkalign_t __main_thread_stack_base__; -#endif - - port_init(); - _scheduler_init(); - _vt_init(); -#if CH_CFG_USE_TM - _tm_init(); -#endif -#if CH_CFG_USE_MEMCORE - _core_init(); -#endif -#if CH_CFG_USE_HEAP - _heap_init(); -#endif -#if CH_DBG_STATISTICS - _stats_init(); -#endif -#if CH_DBG_ENABLE_TRACE - _trace_init(); -#endif - -#if !CH_CFG_NO_IDLE_THREAD - /* Now this instructions flow becomes the main thread.*/ - setcurrp(_thread_init(&mainthread, NORMALPRIO)); -#else - /* Now this instructions flow becomes the main thread.*/ - setcurrp(_thread_init(&mainthread, IDLEPRIO)); -#endif - - currp->p_state = CH_STATE_CURRENT; -#if CH_DBG_ENABLE_STACK_CHECK - /* 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 - chSysEnable(); - - /* Note, &ch_debug points to the string "main" if the registry is - active, else the parameter is ignored.*/ - chRegSetThreadName((const char *)&ch_debug); - -#if !CH_CFG_NO_IDLE_THREAD - /* 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.*/ - chThdCreateStatic(_idle_thread_wa, sizeof(_idle_thread_wa), IDLEPRIO, - (tfunc_t)_idle_thread, NULL); -#endif -} - -/** - * @brief Halts the system. - * @details This function is invoked by the operating system when an - * unrecoverable error is detected, for example because a programming - * error in the application code that triggers an assertion while - * in debug mode. - * @note Can be invoked from any system state. - * - * @special - */ -void chSysHalt(void) { - - port_disable(); - -#if defined(CH_CFG_SYSTEM_HALT_HOOK) || defined(__DOXYGEN__) - CH_CFG_SYSTEM_HALT_HOOK(); -#endif - - /* Harmless infinite loop.*/ - while (true) - ; -} - -/** - * @brief Handles time ticks for round robin preemption and timer increments. - * @details Decrements the remaining time quantum of the running thread - * and preempts it when the quantum is used up. Increments system - * time and manages the timers. - * @note The frequency of the timer determines the system tick granularity - * and, together with the @p CH_CFG_TIME_QUANTUM macro, the round robin - * interval. - * - * @iclass - */ -void chSysTimerHandlerI(void) { - - chDbgCheckClassI(); - -#if CH_CFG_TIME_QUANTUM > 0 - /* Running thread has not used up quantum yet? */ - if (currp->p_preempt > 0) - /* Decrement remaining quantum.*/ - currp->p_preempt--; -#endif -#if CH_DBG_THREADS_PROFILING - currp->p_time++; -#endif - chVTDoTickI(); -#if defined(CH_CFG_SYSTEM_TICK_HOOK) - CH_CFG_SYSTEM_TICK_HOOK(); -#endif -} - - -/** - * @brief Returns the execution context and enters the kernel lock mode. - * @details This functions enters into a critical zone and can be called - * from any context. Because its flexibility it is less efficient - * than @p chSysLock() which is preferable when the calling context - * is known. - * - * @return The previous system status, the encoding of this - * status word is architecture-dependent and opaque. - * - * @xclass - */ -syssts_t chSysGetAndLockX(void) { - - syssts_t sts = port_get_irq_status(); - if (port_irq_enabled(sts)) { - if (port_is_isr_context()) - chSysLockFromISR(); - else - chSysLock(); - } - return sts; -} - -/** - * @brief Restores the specified execution status. - * - * @param[in] sts the system status to be restored. - * - * @xclass - */ -void chSysRestoreLockX(syssts_t sts) { - - if (port_irq_enabled(sts)) { - if (port_is_isr_context()) - chSysUnlockFromISR(); - else - chSysUnlock(); - } -} - -#if CH_PORT_SUPPORTS_RT || defined(__DOXYGEN__) -/** - * @brief Realtime window test. - * @details This function verifies if the current realtime counter value - * lies within the specified range or not. The test takes care - * of the realtime counter wrapping to zero on overflow. - * @note When start==end then the function returns always true because the - * whole time range is specified. - * @note This function is only available if the port layer supports the - * option @p CH_PORT_SUPPORTS_RT. - * - * @param[in] cnt the counter value to be tested - * @param[in] start the start of the time window (inclusive) - * @param[in] end the end of the time window (non inclusive) - * @retval true current time within the specified time window. - * @retval false current time not within the specified time window. - * - * @xclass - */ -bool chSysIsCounterWithinX(rtcnt_t cnt, rtcnt_t start, rtcnt_t end) { - - return end > start ? (cnt >= start) && (cnt < end) : - (cnt >= start) || (cnt < end); -} - -/** - * @brief Polled delay. - * @note The real delay is always few cycles in excess of the specified - * value. - * @note This function is only available if the port layer supports the - * option @p CH_PORT_SUPPORTS_RT. - * - * @param[in] cycles number of cycles - * - * @xclass - */ -void chSysPolledDelayX(rtcnt_t cycles) { - rtcnt_t start = chSysGetRealtimeCounterX(); - rtcnt_t end = start + cycles; - while (chSysIsCounterWithinX(chSysGetRealtimeCounterX(), start, end)) - ; -} -#endif /* CH_PORT_SUPPORTS_RT */ - -/** @} */ -- cgit v1.2.3