2009-08-16 13:07:24 +00:00
|
|
|
/*
|
2015-01-11 13:45:54 +00:00
|
|
|
ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio.
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2015-01-11 13:45:54 +00:00
|
|
|
This file is part of ChibiOS.
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2015-01-11 13:45:54 +00:00
|
|
|
ChibiOS is free software; you can redistribute it and/or modify
|
2009-08-16 13:07:24 +00:00
|
|
|
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.
|
|
|
|
|
2015-01-11 13:45:54 +00:00
|
|
|
ChibiOS is distributed in the hope that it will be useful,
|
2009-08-16 13:07:24 +00:00
|
|
|
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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-02-27 08:54:22 +00:00
|
|
|
* @file chsys.h
|
2010-02-06 12:31:09 +00:00
|
|
|
* @brief System related macros and structures.
|
|
|
|
*
|
2009-08-30 06:59:43 +00:00
|
|
|
* @addtogroup system
|
2009-08-16 13:07:24 +00:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2010-02-27 08:54:22 +00:00
|
|
|
#ifndef _CHSYS_H_
|
|
|
|
#define _CHSYS_H_
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2015-03-07 11:07:31 +00:00
|
|
|
/*lint -sem(chSysHalt, r_no)*/
|
|
|
|
|
2013-07-19 14:51:35 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module constants. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2015-03-23 16:14:19 +00:00
|
|
|
/**
|
|
|
|
* @name Masks of executable integrity checks.
|
|
|
|
* @{
|
|
|
|
*/
|
2015-04-03 09:40:49 +00:00
|
|
|
#define CH_INTEGRITY_RLIST 1U
|
|
|
|
#define CH_INTEGRITY_VTLIST 2U
|
|
|
|
#define CH_INTEGRITY_REGISTRY 4U
|
|
|
|
#define CH_INTEGRITY_PORT 8U
|
2015-03-23 16:14:19 +00:00
|
|
|
/** @} */
|
|
|
|
|
2013-07-19 14:51:35 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module pre-compile time settings. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Derived constants and error checks. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module data structures and types. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module macros. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2011-08-23 10:09:08 +00:00
|
|
|
/**
|
2013-07-19 14:51:35 +00:00
|
|
|
* @name ISRs abstraction macros
|
2011-08-23 10:09:08 +00:00
|
|
|
*/
|
2015-03-27 09:51:45 +00:00
|
|
|
/**
|
|
|
|
* @brief Priority level validation macro.
|
|
|
|
* @details This macro determines if the passed value is a valid priority
|
|
|
|
* level for the underlying architecture.
|
|
|
|
*
|
|
|
|
* @param[in] prio the priority level
|
|
|
|
* @return Priority range result.
|
2015-04-06 09:59:34 +00:00
|
|
|
* @retval false if the priority is invalid or if the architecture
|
2015-03-27 09:51:45 +00:00
|
|
|
* does not support priorities.
|
2015-04-06 09:59:34 +00:00
|
|
|
* @retval true if the priority is valid.
|
2015-03-27 09:51:45 +00:00
|
|
|
*/
|
|
|
|
#if defined(PORT_IRQ_IS_VALID_PRIORITY) || defined(__DOXYGEN__)
|
|
|
|
#define CH_IRQ_IS_VALID_PRIORITY(prio) \
|
|
|
|
PORT_IRQ_IS_VALID_PRIORITY(prio)
|
|
|
|
#else
|
|
|
|
#define CH_IRQ_IS_VALID_PRIORITY(prio) false
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Priority level validation macro.
|
|
|
|
* @details This macro determines if the passed value is a valid priority
|
|
|
|
* level that cannot preempt the kernel critical zone.
|
|
|
|
*
|
|
|
|
* @param[in] prio the priority level
|
|
|
|
* @return Priority range result.
|
2015-04-06 09:59:34 +00:00
|
|
|
* @retval false if the priority is invalid or if the architecture
|
2015-03-27 09:51:45 +00:00
|
|
|
* does not support priorities.
|
2015-04-06 09:59:34 +00:00
|
|
|
* @retval true if the priority is valid.
|
2015-03-27 09:51:45 +00:00
|
|
|
*/
|
|
|
|
#if defined(PORT_IRQ_IS_VALID_KERNEL_PRIORITY) || defined(__DOXYGEN__)
|
|
|
|
#define CH_IRQ_IS_VALID_KERNEL_PRIORITY(prio) \
|
|
|
|
PORT_IRQ_IS_VALID_KERNEL_PRIORITY(prio)
|
|
|
|
#else
|
|
|
|
#define CH_IRQ_IS_VALID_KERNEL_PRIORITY(prio) false
|
|
|
|
#endif
|
|
|
|
|
2010-08-20 07:15:55 +00:00
|
|
|
/**
|
2013-07-19 14:51:35 +00:00
|
|
|
* @brief IRQ handler enter code.
|
|
|
|
* @note Usually IRQ handlers functions are also declared naked.
|
|
|
|
* @note On some architectures this macro can be empty.
|
2010-08-20 07:15:55 +00:00
|
|
|
*
|
2013-07-19 14:51:35 +00:00
|
|
|
* @special
|
|
|
|
*/
|
|
|
|
#define CH_IRQ_PROLOGUE() \
|
|
|
|
PORT_IRQ_PROLOGUE(); \
|
2013-07-30 09:19:07 +00:00
|
|
|
_stats_increase_irq(); \
|
2013-08-10 10:17:45 +00:00
|
|
|
_dbg_check_enter_isr()
|
2013-07-19 14:51:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief IRQ handler exit code.
|
|
|
|
* @note Usually IRQ handlers function are also declared naked.
|
|
|
|
* @note This macro usually performs the final reschedule by using
|
|
|
|
* @p chSchIsPreemptionRequired() and @p chSchDoReschedule().
|
2010-09-21 10:22:06 +00:00
|
|
|
*
|
2013-07-19 14:51:35 +00:00
|
|
|
* @special
|
2010-08-20 07:15:55 +00:00
|
|
|
*/
|
2013-07-19 14:51:35 +00:00
|
|
|
#define CH_IRQ_EPILOGUE() \
|
2013-08-10 10:17:45 +00:00
|
|
|
_dbg_check_leave_isr(); \
|
2013-07-29 13:28:35 +00:00
|
|
|
PORT_IRQ_EPILOGUE()
|
2013-07-19 14:51:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Standard normal IRQ handler declaration.
|
|
|
|
* @note @p id can be a function name or a vector number depending on the
|
|
|
|
* port implementation.
|
|
|
|
*
|
|
|
|
* @special
|
|
|
|
*/
|
|
|
|
#define CH_IRQ_HANDLER(id) PORT_IRQ_HANDLER(id)
|
|
|
|
/** @} */
|
2010-08-20 07:15:55 +00:00
|
|
|
|
2009-08-16 13:07:24 +00:00
|
|
|
/**
|
2013-07-19 14:51:35 +00:00
|
|
|
* @name Fast ISRs abstraction macros
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @brief Standard fast IRQ handler declaration.
|
|
|
|
* @note @p id can be a function name or a vector number depending on the
|
|
|
|
* port implementation.
|
|
|
|
* @note Not all architectures support fast interrupts.
|
2010-09-21 10:22:06 +00:00
|
|
|
*
|
|
|
|
* @special
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-07-19 14:51:35 +00:00
|
|
|
#define CH_FAST_IRQ_HANDLER(id) PORT_FAST_IRQ_HANDLER(id)
|
|
|
|
/** @} */
|
|
|
|
|
2013-07-29 14:31:13 +00:00
|
|
|
/**
|
|
|
|
* @name Time conversion utilities for the realtime counter
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @brief Seconds to realtime counter.
|
|
|
|
* @details Converts from seconds to realtime counter cycles.
|
2014-01-20 09:38:35 +00:00
|
|
|
* @note The macro assumes that @p freq >= @p 1.
|
2013-07-29 14:31:13 +00:00
|
|
|
*
|
2014-01-20 09:38:35 +00:00
|
|
|
* @param[in] freq clock frequency, in Hz, of the realtime counter
|
2013-07-29 14:31:13 +00:00
|
|
|
* @param[in] sec number of seconds
|
|
|
|
* @return The number of cycles.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2014-01-20 09:38:35 +00:00
|
|
|
#define S2RTC(freq, sec) ((freq) * (sec))
|
2013-07-29 14:31:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Milliseconds to realtime counter.
|
|
|
|
* @details Converts from milliseconds to realtime counter cycles.
|
2014-01-20 09:38:35 +00:00
|
|
|
* @note The result is rounded upward to the next millisecond boundary.
|
|
|
|
* @note The macro assumes that @p freq >= @p 1000.
|
2013-07-29 14:31:13 +00:00
|
|
|
*
|
2014-01-20 09:38:35 +00:00
|
|
|
* @param[in] freq clock frequency, in Hz, of the realtime counter
|
2013-07-29 14:31:13 +00:00
|
|
|
* @param[in] msec number of milliseconds
|
|
|
|
* @return The number of cycles.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2014-01-20 09:38:35 +00:00
|
|
|
#define MS2RTC(freq, msec) (rtcnt_t)((((freq) + 999UL) / 1000UL) * (msec))
|
2013-07-29 14:31:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Microseconds to realtime counter.
|
|
|
|
* @details Converts from microseconds to realtime counter cycles.
|
2014-01-20 09:38:35 +00:00
|
|
|
* @note The result is rounded upward to the next microsecond boundary.
|
|
|
|
* @note The macro assumes that @p freq >= @p 1000000.
|
2013-07-29 14:31:13 +00:00
|
|
|
*
|
2014-01-20 09:38:35 +00:00
|
|
|
* @param[in] freq clock frequency, in Hz, of the realtime counter
|
2013-07-29 14:31:13 +00:00
|
|
|
* @param[in] usec number of microseconds
|
|
|
|
* @return The number of cycles.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2014-01-20 09:38:35 +00:00
|
|
|
#define US2RTC(freq, usec) (rtcnt_t)((((freq) + 999999UL) / 1000000UL) * (usec))
|
2013-07-29 14:31:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Realtime counter cycles to seconds.
|
|
|
|
* @details Converts from realtime counter cycles number to seconds.
|
2013-11-29 13:24:08 +00:00
|
|
|
* @note The result is rounded up to the next second boundary.
|
2014-01-20 09:38:35 +00:00
|
|
|
* @note The macro assumes that @p freq >= @p 1.
|
2013-07-29 14:31:13 +00:00
|
|
|
*
|
2014-01-20 09:38:35 +00:00
|
|
|
* @param[in] freq clock frequency, in Hz, of the realtime counter
|
2013-07-29 14:31:13 +00:00
|
|
|
* @param[in] n number of cycles
|
|
|
|
* @return The number of seconds.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2014-01-20 09:38:35 +00:00
|
|
|
#define RTC2S(freq, n) ((((n) - 1UL) / (freq)) + 1UL)
|
2013-07-29 14:31:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Realtime counter cycles to milliseconds.
|
|
|
|
* @details Converts from realtime counter cycles number to milliseconds.
|
2013-11-29 13:24:08 +00:00
|
|
|
* @note The result is rounded up to the next millisecond boundary.
|
2014-01-20 09:38:35 +00:00
|
|
|
* @note The macro assumes that @p freq >= @p 1000.
|
2013-07-29 14:31:13 +00:00
|
|
|
*
|
2014-01-20 09:38:35 +00:00
|
|
|
* @param[in] freq clock frequency, in Hz, of the realtime counter
|
2013-07-29 14:31:13 +00:00
|
|
|
* @param[in] n number of cycles
|
|
|
|
* @return The number of milliseconds.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2014-01-20 09:38:35 +00:00
|
|
|
#define RTC2MS(freq, n) ((((n) - 1UL) / ((freq) / 1000UL)) + 1UL)
|
2013-07-29 14:31:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Realtime counter cycles to microseconds.
|
|
|
|
* @details Converts from realtime counter cycles number to microseconds.
|
2013-11-29 13:24:08 +00:00
|
|
|
* @note The result is rounded up to the next microsecond boundary.
|
2014-01-20 09:38:35 +00:00
|
|
|
* @note The macro assumes that @p freq >= @p 1000000.
|
2013-07-29 14:31:13 +00:00
|
|
|
*
|
2014-01-20 09:38:35 +00:00
|
|
|
* @param[in] freq clock frequency, in Hz, of the realtime counter
|
2013-07-29 14:31:13 +00:00
|
|
|
* @param[in] n number of cycles
|
|
|
|
* @return The number of microseconds.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2014-01-20 09:38:35 +00:00
|
|
|
#define RTC2US(freq, n) ((((n) - 1UL) / ((freq) / 1000000UL)) + 1UL)
|
2013-07-29 14:31:13 +00:00
|
|
|
/** @} */
|
|
|
|
|
2013-07-29 13:28:35 +00:00
|
|
|
/**
|
|
|
|
* @brief Returns the current value of the system real time counter.
|
2013-07-29 15:13:52 +00:00
|
|
|
* @note This function is only available if the port layer supports the
|
2013-09-03 09:51:32 +00:00
|
|
|
* option @p PORT_SUPPORTS_RT.
|
2013-07-29 13:28:35 +00:00
|
|
|
*
|
|
|
|
* @return The value of the system realtime counter of
|
2013-07-29 15:13:52 +00:00
|
|
|
* type rtcnt_t.
|
2013-07-29 13:28:35 +00:00
|
|
|
*
|
2013-07-29 14:31:13 +00:00
|
|
|
* @xclass
|
2013-07-29 13:28:35 +00:00
|
|
|
*/
|
2015-03-05 21:28:51 +00:00
|
|
|
#if (PORT_SUPPORTS_RT == TRUE) || defined(__DOXYGEN__)
|
2013-07-29 13:28:35 +00:00
|
|
|
#define chSysGetRealtimeCounterX() (rtcnt_t)port_rt_get_counter_value()
|
|
|
|
#endif
|
|
|
|
|
2013-07-30 14:23:37 +00:00
|
|
|
/**
|
|
|
|
* @brief Performs a context switch.
|
|
|
|
* @note Not a user function, it is meant to be invoked by the scheduler
|
|
|
|
* itself or from within the port layer.
|
|
|
|
*
|
|
|
|
* @param[in] ntp the thread to be switched in
|
|
|
|
* @param[in] otp the thread to be switched out
|
|
|
|
*
|
|
|
|
* @special
|
|
|
|
*/
|
|
|
|
#define chSysSwitch(ntp, otp) { \
|
|
|
|
\
|
2013-08-10 10:17:45 +00:00
|
|
|
_dbg_trace(otp); \
|
2013-07-31 12:26:02 +00:00
|
|
|
_stats_ctxswc(ntp, otp); \
|
2013-07-30 14:23:37 +00:00
|
|
|
CH_CFG_CONTEXT_SWITCH_HOOK(ntp, otp); \
|
|
|
|
port_switch(ntp, otp); \
|
|
|
|
}
|
|
|
|
|
2013-07-19 14:51:35 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* External declarations. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
void chSysInit(void);
|
2013-08-17 11:52:50 +00:00
|
|
|
void chSysHalt(const char *reason);
|
2015-03-23 16:14:19 +00:00
|
|
|
bool chSysIntegrityCheckI(unsigned testmask);
|
2013-07-19 14:51:35 +00:00
|
|
|
void chSysTimerHandlerI(void);
|
2013-08-26 13:07:19 +00:00
|
|
|
syssts_t chSysGetStatusAndLockX(void);
|
2013-08-26 14:08:25 +00:00
|
|
|
void chSysRestoreStatusX(syssts_t sts);
|
2013-09-03 09:51:32 +00:00
|
|
|
#if PORT_SUPPORTS_RT
|
2013-07-29 15:13:52 +00:00
|
|
|
bool chSysIsCounterWithinX(rtcnt_t cnt, rtcnt_t start, rtcnt_t end);
|
|
|
|
void chSysPolledDelayX(rtcnt_t cycles);
|
|
|
|
#endif
|
2013-07-19 14:51:35 +00:00
|
|
|
#ifdef __cplusplus
|
2010-08-21 08:38:14 +00:00
|
|
|
}
|
|
|
|
#endif
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-07-19 14:51:35 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module inline functions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2009-08-16 13:07:24 +00:00
|
|
|
/**
|
2010-02-06 12:31:09 +00:00
|
|
|
* @brief Raises the system interrupt priority mask to the maximum level.
|
2009-08-16 13:07:24 +00:00
|
|
|
* @details All the maskable interrupt sources are disabled regardless their
|
2010-02-06 12:31:09 +00:00
|
|
|
* hardware priority.
|
|
|
|
* @note Do not invoke this API from within a kernel lock.
|
2010-09-21 10:22:06 +00:00
|
|
|
*
|
|
|
|
* @special
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-07-19 14:51:35 +00:00
|
|
|
static inline void chSysDisable(void) {
|
|
|
|
|
|
|
|
port_disable();
|
2013-08-10 10:17:45 +00:00
|
|
|
_dbg_check_disable();
|
2011-08-11 17:51:37 +00:00
|
|
|
}
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2010-02-06 12:31:09 +00:00
|
|
|
* @brief Raises the system interrupt priority mask to system level.
|
2009-08-16 13:07:24 +00:00
|
|
|
* @details The interrupt sources that should not be able to preempt the kernel
|
2010-02-06 12:31:09 +00:00
|
|
|
* are disabled, interrupt sources with higher priority are still
|
|
|
|
* enabled.
|
|
|
|
* @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.
|
2010-09-21 10:22:06 +00:00
|
|
|
*
|
|
|
|
* @special
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-07-19 14:51:35 +00:00
|
|
|
static inline void chSysSuspend(void) {
|
|
|
|
|
|
|
|
port_suspend();
|
2013-08-10 10:17:45 +00:00
|
|
|
_dbg_check_suspend();
|
2011-08-11 17:51:37 +00:00
|
|
|
}
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2010-02-06 12:31:09 +00:00
|
|
|
* @brief Lowers the system interrupt priority mask to user level.
|
2009-08-16 13:07:24 +00:00
|
|
|
* @details All the interrupt sources are enabled.
|
2010-02-06 12:31:09 +00:00
|
|
|
* @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.
|
2010-09-21 10:22:06 +00:00
|
|
|
*
|
|
|
|
* @special
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-07-19 14:51:35 +00:00
|
|
|
static inline void chSysEnable(void) {
|
|
|
|
|
2013-08-10 10:17:45 +00:00
|
|
|
_dbg_check_enable();
|
2013-07-19 14:51:35 +00:00
|
|
|
port_enable();
|
2011-08-11 17:51:37 +00:00
|
|
|
}
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2014-08-12 16:05:36 +00:00
|
|
|
* @brief Enters the kernel lock state.
|
2010-09-21 10:22:06 +00:00
|
|
|
*
|
|
|
|
* @special
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-07-19 14:51:35 +00:00
|
|
|
static inline void chSysLock(void) {
|
|
|
|
|
|
|
|
port_lock();
|
2013-07-30 09:19:07 +00:00
|
|
|
_stats_start_measure_crit_thd();
|
2013-08-10 10:17:45 +00:00
|
|
|
_dbg_check_lock();
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-08-12 16:05:36 +00:00
|
|
|
* @brief Leaves the kernel lock state.
|
2010-09-21 10:22:06 +00:00
|
|
|
*
|
|
|
|
* @special
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-07-19 14:51:35 +00:00
|
|
|
static inline void chSysUnlock(void) {
|
|
|
|
|
2013-08-10 10:17:45 +00:00
|
|
|
_dbg_check_unlock();
|
2013-07-30 09:19:07 +00:00
|
|
|
_stats_stop_measure_crit_thd();
|
2013-11-12 11:05:57 +00:00
|
|
|
|
|
|
|
/* The following condition can be triggered by the use of i-class functions
|
|
|
|
in a critical section not followed by a chSchResceduleS(), this means
|
|
|
|
that the current thread has a lower priority than the next thread in
|
|
|
|
the ready list.*/
|
2015-03-16 10:13:55 +00:00
|
|
|
chDbgAssert((ch.rlist.r_queue.p_next == (thread_t *)&ch.rlist.r_queue) ||
|
|
|
|
(ch.rlist.r_current->p_prio >= ch.rlist.r_queue.p_next->p_prio),
|
2015-10-08 13:03:17 +00:00
|
|
|
"priority order violation");
|
2013-11-12 11:05:57 +00:00
|
|
|
|
2013-07-19 14:51:35 +00:00
|
|
|
port_unlock();
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-08-12 16:05:36 +00:00
|
|
|
* @brief Enters the kernel lock state from within an interrupt handler.
|
2010-02-06 12:31:09 +00:00
|
|
|
* @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 exclusion zone.<br>
|
|
|
|
* It is good practice to invoke this API before invoking any I-class
|
|
|
|
* syscall from an interrupt handler.
|
|
|
|
* @note This API must be invoked exclusively from interrupt handlers.
|
2010-09-21 10:22:06 +00:00
|
|
|
*
|
|
|
|
* @special
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-07-24 14:54:26 +00:00
|
|
|
static inline void chSysLockFromISR(void) {
|
2013-07-19 14:51:35 +00:00
|
|
|
|
|
|
|
port_lock_from_isr();
|
2013-07-30 09:19:07 +00:00
|
|
|
_stats_start_measure_crit_isr();
|
2013-08-10 10:17:45 +00:00
|
|
|
_dbg_check_lock_from_isr();
|
2011-08-11 17:51:37 +00:00
|
|
|
}
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2014-08-12 16:05:36 +00:00
|
|
|
* @brief Leaves the kernel lock state from within an interrupt handler.
|
2009-08-16 13:07:24 +00:00
|
|
|
*
|
2010-02-06 12:31:09 +00:00
|
|
|
* @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 exclusion zone.<br>
|
|
|
|
* It is good practice to invoke this API after invoking any I-class
|
|
|
|
* syscall from an interrupt handler.
|
2010-09-21 10:22:06 +00:00
|
|
|
* @note This API must be invoked exclusively from interrupt handlers.
|
|
|
|
*
|
|
|
|
* @special
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-07-24 14:54:26 +00:00
|
|
|
static inline void chSysUnlockFromISR(void) {
|
2010-04-26 12:34:10 +00:00
|
|
|
|
2013-08-10 10:17:45 +00:00
|
|
|
_dbg_check_unlock_from_isr();
|
2013-07-30 09:19:07 +00:00
|
|
|
_stats_stop_measure_crit_isr();
|
2013-07-19 14:51:35 +00:00
|
|
|
port_unlock_from_isr();
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
2014-08-12 16:05:36 +00:00
|
|
|
/**
|
2014-09-10 10:18:02 +00:00
|
|
|
* @brief Unconditionally enters the kernel lock state.
|
2014-08-12 16:05:36 +00:00
|
|
|
* @note Can be called without previous knowledge of the current lock state.
|
|
|
|
* The final state is "s-locked".
|
|
|
|
*
|
|
|
|
* @special
|
|
|
|
*/
|
2014-09-10 10:18:02 +00:00
|
|
|
static inline void chSysUnconditionalLock(void) {
|
2014-08-12 16:05:36 +00:00
|
|
|
|
2015-03-03 11:01:09 +00:00
|
|
|
if (port_irq_enabled(port_get_irq_status())) {
|
2014-08-12 16:05:36 +00:00
|
|
|
chSysLock();
|
2015-03-03 11:01:09 +00:00
|
|
|
}
|
2014-08-12 16:05:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-09-10 10:18:02 +00:00
|
|
|
* @brief Unconditionally leaves the kernel lock state.
|
2014-08-12 16:05:36 +00:00
|
|
|
* @note Can be called without previous knowledge of the current lock state.
|
|
|
|
* The final state is "normal".
|
|
|
|
*
|
|
|
|
* @special
|
|
|
|
*/
|
2014-09-10 10:18:02 +00:00
|
|
|
static inline void chSysUnconditionalUnlock(void) {
|
2014-08-12 16:05:36 +00:00
|
|
|
|
2015-03-03 11:01:09 +00:00
|
|
|
if (!port_irq_enabled(port_get_irq_status())) {
|
2014-08-12 16:05:36 +00:00
|
|
|
chSysUnlock();
|
2015-03-03 11:01:09 +00:00
|
|
|
}
|
2014-08-12 16:05:36 +00:00
|
|
|
}
|
|
|
|
|
2015-03-05 21:28:51 +00:00
|
|
|
#if (CH_CFG_NO_IDLE_THREAD == FALSE) || defined(__DOXYGEN__)
|
2014-10-05 12:21:25 +00:00
|
|
|
/**
|
|
|
|
* @brief Returns a pointer to the idle thread.
|
|
|
|
* @pre In order to use this function the option @p CH_CFG_NO_IDLE_THREAD
|
|
|
|
* must be disabled.
|
|
|
|
* @note The reference counter of the idle thread is not incremented but
|
|
|
|
* it is not strictly required being the idle thread a static
|
|
|
|
* object.
|
|
|
|
*
|
|
|
|
* @return Pointer to the idle thread.
|
|
|
|
*
|
|
|
|
* @xclass
|
|
|
|
*/
|
|
|
|
static inline thread_t *chSysGetIdleThreadX(void) {
|
|
|
|
|
|
|
|
return ch.rlist.r_queue.p_prev;
|
|
|
|
}
|
2015-03-05 21:28:51 +00:00
|
|
|
#endif /* CH_CFG_NO_IDLE_THREAD == FALSE */
|
2014-10-05 12:21:25 +00:00
|
|
|
|
2010-02-27 08:54:22 +00:00
|
|
|
#endif /* _CHSYS_H_ */
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/** @} */
|