From a9b4e8fc7225e8e2f26554b388f9d069d8f05b5e Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 16 Jan 2009 15:41:08 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@621 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- src/chsys.c | 32 ++++--------- src/include/sys.h | 127 ++++++++++++++++++++++--------------------------- src/templates/chcore.c | 66 +++++++++++++++++-------- src/templates/chcore.h | 10 ++-- 4 files changed, 120 insertions(+), 115 deletions(-) (limited to 'src') diff --git a/src/chsys.c b/src/chsys.c index 45ce8b0f8..2f4c796a8 100644 --- a/src/chsys.c +++ b/src/chsys.c @@ -52,6 +52,7 @@ static void idle_thread(void *p) { void chSysInit(void) { static Thread mainthread; + sys_init(); chSchInit(); chDbgInit(); chVTInit(); @@ -94,37 +95,20 @@ void chSysTimerHandlerI(void) { chVTDoTickI(); } -#if !defined(CH_OPTIMIZE_SPEED) -/** - * Enters the ChibiOS/RT system mutual exclusion zone. - * @note The use of system mutual exclusion zone is not recommended in - * the user code, it is a better idea to use the semaphores or mutexes - * instead. - * @note The code of this API is may be inlined or not depending on the - * @p CH_OPTIMIZE_SPEED setting. - * @see CH_USE_NESTED_LOCKS, chSysLockInline() - */ +#if defined(CH_USE_NESTED_LOCKS) && !defined(CH_OPTIMIZE_SPEED) void chSysLock(void) { - chSysLockInline(); + chDbgAssert(currp->p_locks >= 0, "chinit.c, chSysLock()"); + if (currp->p_locks++ == 0) + sys_lock(); } -/** - * Leaves the ChibiOS/RT system mutual exclusion zone. - * @note The use of system mutual exclusion zone is not recommended in - * the user code, it is a better idea to use the semaphores or mutexes - * instead. - * @note The code of this API is may be inlined or not depending on the - * @p CH_OPTIMIZE_SPEED setting. - * @see CH_USE_NESTED_LOCKS, chSysUnlockInline() - */ void chSysUnlock(void) { -#ifdef CH_USE_NESTED_LOCKS chDbgAssert(currp->p_locks > 0, "chinit.c, chSysUnlock()"); -#endif - chSysUnlockInline(); + if (--currp->p_locks == 0) + sys_unlock(); } -#endif /* !CH_OPTIMIZE_SPEED */ +#endif /* defined(CH_USE_NESTED_LOCKS) && !defined(CH_OPTIMIZE_SPEED) */ /** @} */ diff --git a/src/include/sys.h b/src/include/sys.h index 5acc863f2..ae38a5639 100644 --- a/src/include/sys.h +++ b/src/include/sys.h @@ -50,36 +50,74 @@ #define chSysSwitchI(otp, ntp) sys_switch(otp, ntp) /** - * Lowers the system interrupt priority mask to user level. - * @note The implementation is architecture dependent, it may just enable the - * interrupts. - * @note This API is normally invoked only from within @p chSysInit(). - * @note The use of this API is not an alternative to @p chSysUnlock(). + * Raises the system interrupt priority mask to the maximum level. + * All the maskable interrupt sources are disabled regardless their hardware + * priority. + * @note The implementation is architecture dependent, it may just disable the + * interrupts or be exactly equivalent to @p chSysDisable(). + * @note Do not invoke this API from within a kernel lock. */ -#define chSysEnable() sys_enable() +#define chSysDisableAll() sys_disable_all() /** * Raises the system interrupt priority mask to system level. + * The interrupt sources that should not be able to preempt the kernel are + * disabled, interrupt sources with higher priority are still enabled. * @note The implementation is architecture dependent, it may just disable the * interrupts. - * @note This API should only be invoked from the main thread in order to stop - * ChibiOS/RT, hardware de/re-initialization should follow. It would then - * be possible to re-initialize ChibiOS/RT using @p chSysInit(). - * @note The use of this API is not an alternative to @p chSysLock(). + * @note Do not invoke this API from within a kernel lock. + * @note This API is no replacement for @p chSysLock(), the @p chSysLock() + * could do more than just disable the interrupts. */ #define chSysDisable() sys_disable() /** - * Raises the system interrupt priority mask to the maximum level thus disabling - * any mask-able interrupt source.. - * @note The implementation is architecture dependent, it may just disable the - * interrupts or be exactly equivalent to @p chSysDisable(). + * Lowers the system interrupt priority mask to user level. + * All the interrupt sources are enabled. + * @note The implementation is architecture dependent, it may just enable the + * interrupts. + * @note Do not invoke this API from within a kernel lock. + * @note This API is no replacement for @p chSysUnlock(), the @p chSysUnlock() + * could do more than just enable the interrupts. */ -#define chSysDisableAll() sys_disable_all() +#define chSysEnable() sys_enable() /** - * Enters the ChibiOS/RT system mutual exclusion zone from within an interrupt - * handler. + * Enters the kernel lock mode. + * @note The use of kernel lock mode is not recommended in the user code, it is + * a better idea to use the semaphores or mutexes instead. + * @see CH_USE_NESTED_LOCKS + */ +#if defined(CH_USE_NESTED_LOCKS) || defined(__DOXYGEN__) +#if defined(CH_OPTIMIZE_SPEED) || defined(__DOXYGEN__) +#define chSysLock() { \ + if (currp->p_locks++ == 0) \ + sys_lock(); \ +} +#endif /* defined(CH_OPTIMIZE_SPEED) */ +#else /* !defined(CH_USE_NESTED_LOCKS) */ +#define chSysLock() sys_lock() +#endif /* !defined(CH_USE_NESTED_LOCKS) */ + +/** + * Leaves the kernel lock mode. + * @note The use of kernel lock mode is not recommended in the user code, it is + * a better idea to use the semaphores or mutexes instead. + * @see CH_USE_NESTED_LOCKS + */ +#if defined(CH_USE_NESTED_LOCKS) || defined(__DOXYGEN__) +#if defined(CH_OPTIMIZE_SPEED) || defined(__DOXYGEN__) +#define chSysUnlock() { \ + if (--currp->p_locks == 0) \ + sys_unlock(); \ +} +#endif /* defined(CH_OPTIMIZE_SPEED) */ +#else /* !defined(CH_USE_NESTED_LOCKS) */ +#define chSysUnlock() sys_unlock() +#endif /* !defined(CH_USE_NESTED_LOCKS) */ + +/** + * Enters the kernel lock mode from within an interrupt handler. * @note This API may do nothing on some architectures, it is required because * on ports that support preemptable interrupt handlers it is required to * raise the interrupt mask to the same level of the system mutual @@ -88,11 +126,10 @@ * syscall from an interrupt handler. * @note This API must be invoked exclusively from interrupt handlers. */ -#define chSysLockI() sys_disable_from_isr() +#define chSysLockI() sys_lock_from_isr() /** - * Leaves the ChibiOS/RT system mutual exclusion zone from within an interrupt - * handler. + * Leaves the kernel lock mode from within an interrupt handler. * @note This API may do nothing on some architectures, it is required because * on ports that support preemptable interrupt handlers it is required to * raise the interrupt mask to the same level of the system mutual @@ -101,47 +138,7 @@ * syscall from an interrupt handler. * @note This API must be invoked exclusively from interrupt handlers. */ -#define chSysUnlockI() sys_enable_from_isr() - -#if defined(CH_USE_NESTED_LOCKS) || defined(_DOXYGEN_) -/** - * Enters the ChibiOS/RT system mutual exclusion zone. - * @note The use of system mutual exclusion zone is not recommended in - * the user code, it is a better idea to use the semaphores or mutexes - * instead. - * @note The code of this API is always inlined regardless the - * @p CH_OPTIMIZE_SPEED setting. This function is meant to be used in - * places where the performance is always preferred. - * @see CH_USE_NESTED_LOCKS - */ -#define chSysLockInline() { \ - if (currp->p_locks == 0) { \ - currp->p_locks++; \ - sys_disable(); \ - } \ -} - -/** - * Leaves the ChibiOS/RT system mutual exclusion zone. - * @note The use of system mutual exclusion zone is not recommended in - * the user code, it is a better idea to use the semaphores or mutexes - * instead. - * @note The code of this API is always inlined regardless the - * @p CH_OPTIMIZE_SPEED setting. This function is meant to be used in - * places where the performance is always preferred. - * @see CH_USE_NESTED_LOCKS - */ -#define chSysUnlockInline() { \ - if (--currp->p_locks == 0) \ - sys_enable(); \ -} - -#else /* defined(CH_USE_NESTED_LOCKS) || defined(_DOXYGEN_) */ - -#define chSysLockInline() sys_disable() -#define chSysUnlockInline() sys_enable() - -#endif /* !defined(CH_USE_NESTED_LOCKS) && !defined(_DOXYGEN_) */ +#define chSysUnlockI() sys_unlock_from_isr() /** * IRQ handler enter code. @@ -163,14 +160,6 @@ */ #define CH_IRQ_HANDLER SYS_IRQ_HANDLER -/* - * Inlined code when CH_OPTIMIZE_SPEED is defined. - */ -#if defined(CH_OPTIMIZE_SPEED) -#define chSysLock() chSysLockInline() -#define chSysUnlock() chSysUnlockInline() -#endif /* defined(CH_OPTIMIZE_SPEED) */ - #ifdef __cplusplus extern "C" { #endif diff --git a/src/templates/chcore.c b/src/templates/chcore.c index 65d8e155d..84f0b7418 100644 --- a/src/templates/chcore.c +++ b/src/templates/chcore.c @@ -32,38 +32,32 @@ */ /** - * Prints a message on the system console. - * @param msg pointer to the message + * Port-related initialization code. + * @note This function is usually empty. */ -void sys_puts(char *msg) { -} - -/** - * Performs a context switch between two threads. - * @param otp the thread to be switched out - * @param ntp the thread to be switched in - */ -void sys_switch(Thread *otp, Thread *ntp) { +void sys_init(void){ } /** - * Kernel-unlock action. Usually this function just enables interrupts. + * Kernel-unlock action. Usually this function just disables interrupts but + * may perform more actions. */ -void sys_enable(void) { +void sys_lock(void) { } /** - * Kernel-lock action. Usually this function just disables interrupts. + * Kernel-unlock action. Usually this function just disables interrupts but + * may perform more actions. */ -void sys_disable(void) { +void sys_unlock(void) { } /** * Kernel-lock action from an interrupt handler. This function is invoked * before invoking I-class APIs from interrupt handlers. The implementation - * is architecture dependent, in its simplest form it is void. + * is architecture dependent, in its simplest form it is void. */ -void sys_disable_from_isr(void) { +void sys_lock_from_isr(void) { } /** @@ -71,7 +65,26 @@ void sys_disable_from_isr(void) { * after invoking I-class APIs from interrupt handlers. The implementation * is architecture dependent, in its simplest form it is void. */ -void sys_enable_from_isr(void) { +void sys_unlock_from_isr(void) { +} + +/** + * Disables all the interrupt sources. + * @note Of course non maskable interrupt sources are not included. + */ +void sys_disable_all() { +} + +/** + * Disables the interrupt sources that are not supposed to preempt the kernel. + */ +void sys_disable(void) { +} + +/** + * Enables all the interrupt sources. + */ +void sys_enable(void) { } /** @@ -90,9 +103,24 @@ void sys_wait_for_interrupt(void) { */ void sys_halt(void) { - sys_disable(); + sys_disable_all(); while (TRUE) { } } +/** + * Performs a context switch between two threads. + * @param otp the thread to be switched out + * @param ntp the thread to be switched in + */ +void sys_switch(Thread *otp, Thread *ntp) { +} + +/** + * Prints a message on the system console. + * @param msg pointer to the message + */ +void sys_puts(char *msg) { +} + /** @} */ diff --git a/src/templates/chcore.h b/src/templates/chcore.h index d8d3614c8..dec2deee7 100644 --- a/src/templates/chcore.h +++ b/src/templates/chcore.h @@ -129,14 +129,18 @@ typedef struct { #ifdef __cplusplus extern "C" { #endif - void sys_puts(char *msg); - void sys_switch(Thread *otp, Thread *ntp); - void sys_enable(void); + void sys_init(void); + void sys_disable_all(void); void sys_disable(void); + void sys_enable(void); + void sys_lock(void); + void sys_unlock(void); void sys_disable_from_isr(void); void sys_enable_from_isr(void); void sys_wait_for_interrupt(void); void sys_halt(void); + void sys_switch(Thread *otp, Thread *ntp); + void sys_puts(char *msg); #ifdef __cplusplus } #endif -- cgit v1.2.3