ChibiOS/RT Architecture - Reference Manual - Guides |
00001 /* 00002 ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. 00003 00004 This file is part of ChibiOS/RT. 00005 00006 ChibiOS/RT is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 ChibiOS/RT is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 00019 --- 00020 00021 A special exception to the GPL can be applied should you wish to distribute 00022 a combined work that includes ChibiOS/RT, without being obliged to provide 00023 the source code for any proprietary components. See the file exception.txt 00024 for full details of how and when the exception can be applied. 00025 */ 00026 00027 /** 00028 * @file chsys.h 00029 * @brief System related macros and structures. 00030 * 00031 * @addtogroup system 00032 * @{ 00033 */ 00034 00035 #ifndef _CHSYS_H_ 00036 #define _CHSYS_H_ 00037 00038 /** 00039 * @brief Halts the system. 00040 * @details This function is invoked by the operating system when an 00041 * unrecoverable error is detected, as example because a programming 00042 * error in the application code that triggers an assertion while 00043 * in debug mode. 00044 */ 00045 #define chSysHalt() port_halt() 00046 00047 /** 00048 * @brief Performs a context switch. 00049 * 00050 * @param[in] ntp the thread to be switched in 00051 * @param[in] otp the thread to be switched out 00052 */ 00053 #define chSysSwitchI(ntp, otp) port_switch(ntp, otp) 00054 00055 /** 00056 * @brief Raises the system interrupt priority mask to the maximum level. 00057 * @details All the maskable interrupt sources are disabled regardless their 00058 * hardware priority. 00059 * @note The implementation is architecture dependent, it may just disable 00060 * the interrupts or be exactly equivalent to @p chSysDisable(). 00061 * @note Do not invoke this API from within a kernel lock. 00062 */ 00063 #define chSysDisable() port_disable() 00064 00065 /** 00066 * @brief Raises the system interrupt priority mask to system level. 00067 * @details The interrupt sources that should not be able to preempt the kernel 00068 * are disabled, interrupt sources with higher priority are still 00069 * enabled. 00070 * @note The implementation is architecture dependent, it may just disable 00071 * the interrupts. 00072 * @note Do not invoke this API from within a kernel lock. 00073 * @note This API is no replacement for @p chSysLock(), the @p chSysLock() 00074 * could do more than just disable the interrupts. 00075 */ 00076 #define chSysSuspend() port_suspend() 00077 00078 /** 00079 * @brief Lowers the system interrupt priority mask to user level. 00080 * @details All the interrupt sources are enabled. 00081 * @note The implementation is architecture dependent, it may just enable 00082 * the interrupts. 00083 * @note Do not invoke this API from within a kernel lock. 00084 * @note This API is no replacement for @p chSysUnlock(), the 00085 * @p chSysUnlock() could do more than just enable the interrupts. 00086 */ 00087 #define chSysEnable() port_enable() 00088 00089 /** 00090 * @brief Enters the kernel lock mode. 00091 * @note The use of kernel lock mode is not recommended in the user code, 00092 * it is a better idea to use the semaphores or mutexes instead. 00093 * @see CH_USE_NESTED_LOCKS 00094 */ 00095 #if CH_USE_NESTED_LOCKS || defined(__DOXYGEN__) 00096 #if CH_OPTIMIZE_SPEED || defined(__DOXYGEN__) 00097 #define chSysLock() { \ 00098 if (currp->p_locks++ == 0) \ 00099 port_lock(); \ 00100 } 00101 #endif /* CH_OPTIMIZE_SPEED */ 00102 #else /* !CH_USE_NESTED_LOCKS */ 00103 #define chSysLock() port_lock() 00104 #endif /* !CH_USE_NESTED_LOCKS */ 00105 00106 /** 00107 * @brief Leaves the kernel lock mode. 00108 * @note The use of kernel lock mode is not recommended in the user code, 00109 * it is a better idea to use the semaphores or mutexes instead. 00110 * @see CH_USE_NESTED_LOCKS 00111 */ 00112 #if CH_USE_NESTED_LOCKS || defined(__DOXYGEN__) 00113 #if CH_OPTIMIZE_SPEED || defined(__DOXYGEN__) 00114 #define chSysUnlock() { \ 00115 if (--currp->p_locks == 0) \ 00116 port_unlock(); \ 00117 } 00118 #endif /* CH_OPTIMIZE_SPEED */ 00119 #else /* !CH_USE_NESTED_LOCKS */ 00120 #define chSysUnlock() port_unlock() 00121 #endif /* !CH_USE_NESTED_LOCKS */ 00122 00123 /** 00124 * @brief Enters the kernel lock mode from within an interrupt handler. 00125 * @note This API may do nothing on some architectures, it is required 00126 * because on ports that support preemptable interrupt handlers 00127 * it is required to raise the interrupt mask to the same level of 00128 * the system mutual exclusion zone.<br> 00129 * It is good practice to invoke this API before invoking any I-class 00130 * syscall from an interrupt handler. 00131 * @note This API must be invoked exclusively from interrupt handlers. 00132 */ 00133 #define chSysLockFromIsr() port_lock_from_isr() 00134 00135 /** 00136 * @brief Leaves the kernel lock mode from within an interrupt handler. 00137 * 00138 * @note This API may do nothing on some architectures, it is required 00139 * because on ports that support preemptable interrupt handlers 00140 * it is required to raise the interrupt mask to the same level of 00141 * the system mutual exclusion zone.<br> 00142 * It is good practice to invoke this API after invoking any I-class 00143 * syscall from an interrupt handler. 00144 * @note This API must be invoked exclusively from interrupt handlers. 00145 */ 00146 #define chSysUnlockFromIsr() port_unlock_from_isr() 00147 00148 /** 00149 * @brief IRQ handler enter code. 00150 * @note Usually IRQ handlers functions are also declared naked. 00151 * @note On some architectures this macro can be empty. 00152 */ 00153 #define CH_IRQ_PROLOGUE() PORT_IRQ_PROLOGUE() 00154 00155 /** 00156 * @brief IRQ handler exit code. 00157 * @note Usually IRQ handlers function are also declared naked. 00158 * @note This macro usually performs the final reschedule by using 00159 * @p chSchRescRequiredI() and @p chSchDoRescheduleI(). 00160 */ 00161 #define CH_IRQ_EPILOGUE() PORT_IRQ_EPILOGUE() 00162 00163 /** 00164 * @brief Standard normal IRQ handler declaration. 00165 * @note @p id can be a function name or a vector number depending on the 00166 * port implementation. 00167 */ 00168 #define CH_IRQ_HANDLER(id) PORT_IRQ_HANDLER(id) 00169 00170 /** 00171 * @brief Standard fast IRQ handler declaration. 00172 * @note @p id can be a function name or a vector number depending on the 00173 * port implementation. 00174 * @note Not all architectures support fast interrupts. 00175 */ 00176 #define CH_FAST_IRQ_HANDLER(id) PORT_FAST_IRQ_HANDLER(id) 00177 00178 #ifdef __cplusplus 00179 extern "C" { 00180 #endif 00181 void chSysInit(void); 00182 void chSysTimerHandlerI(void); 00183 #if CH_USE_NESTED_LOCKS && !CH_OPTIMIZE_SPEED 00184 void chSysLock(void); 00185 void chSysUnlock(void); 00186 #endif /* CH_USE_NESTED_LOCKS && !CH_OPTIMIZE_SPEED */ 00187 #ifdef __cplusplus 00188 } 00189 #endif 00190 00191 #endif /* _CHSYS_H_ */ 00192 00193 /** @} */