|
ChibiOS/RT
2.5.1 |
00001 /* 00002 ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, 00003 2011,2012 Giovanni Di Sirio. 00004 00005 This file is part of ChibiOS/RT. 00006 00007 ChibiOS/RT is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 ChibiOS/RT is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 /** 00022 * @file hal.h 00023 * @brief HAL subsystem header. 00024 * 00025 * @addtogroup HAL 00026 * @{ 00027 */ 00028 00029 #ifndef _HAL_H_ 00030 #define _HAL_H_ 00031 00032 #include "ch.h" 00033 #include "board.h" 00034 #include "halconf.h" 00035 00036 #include "hal_lld.h" 00037 00038 /* Abstract interfaces.*/ 00039 #include "io_channel.h" 00040 #include "io_block.h" 00041 00042 /* Shared headers.*/ 00043 #include "mmcsd.h" 00044 00045 /* Layered drivers.*/ 00046 #include "tm.h" 00047 #include "pal.h" 00048 #include "adc.h" 00049 #include "can.h" 00050 #include "ext.h" 00051 #include "gpt.h" 00052 #include "i2c.h" 00053 #include "icu.h" 00054 #include "mac.h" 00055 #include "pwm.h" 00056 #include "rtc.h" 00057 #include "serial.h" 00058 #include "sdc.h" 00059 #include "spi.h" 00060 #include "uart.h" 00061 #include "usb.h" 00062 00063 /* Complex drivers.*/ 00064 #include "mmc_spi.h" 00065 #include "serial_usb.h" 00066 00067 /*===========================================================================*/ 00068 /* Driver constants. */ 00069 /*===========================================================================*/ 00070 00071 /*===========================================================================*/ 00072 /* Driver pre-compile time settings. */ 00073 /*===========================================================================*/ 00074 00075 /*===========================================================================*/ 00076 /* Derived constants and error checks. */ 00077 /*===========================================================================*/ 00078 00079 /*===========================================================================*/ 00080 /* Driver data structures and types. */ 00081 /*===========================================================================*/ 00082 00083 /*===========================================================================*/ 00084 /* Driver macros. */ 00085 /*===========================================================================*/ 00086 00087 #if HAL_IMPLEMENTS_COUNTERS || defined(__DOXYGEN__) 00088 /** 00089 * @name Time conversion utilities for the realtime counter 00090 * @{ 00091 */ 00092 /** 00093 * @brief Seconds to realtime ticks. 00094 * @details Converts from seconds to realtime ticks number. 00095 * @note The result is rounded upward to the next tick boundary. 00096 * 00097 * @param[in] sec number of seconds 00098 * @return The number of ticks. 00099 * 00100 * @api 00101 */ 00102 #define S2RTT(sec) (halGetCounterFrequency() * (sec)) 00103 00104 /** 00105 * @brief Milliseconds to realtime ticks. 00106 * @details Converts from milliseconds to realtime ticks number. 00107 * @note The result is rounded upward to the next tick boundary. 00108 * 00109 * @param[in] msec number of milliseconds 00110 * @return The number of ticks. 00111 * 00112 * @api 00113 */ 00114 #define MS2RTT(msec) (((halGetCounterFrequency() + 999UL) / 1000UL) * (msec)) 00115 00116 /** 00117 * @brief Microseconds to realtime ticks. 00118 * @details Converts from microseconds to realtime ticks number. 00119 * @note The result is rounded upward to the next tick boundary. 00120 * 00121 * @param[in] usec number of microseconds 00122 * @return The number of ticks. 00123 * 00124 * @api 00125 */ 00126 #define US2RTT(usec) (((halGetCounterFrequency() + 999999UL) / 1000000UL) * \ 00127 (usec)) 00128 00129 /** 00130 * @brief Realtime ticks to seconds to. 00131 * @details Converts from realtime ticks number to seconds. 00132 * 00133 * @param[in] ticks number of ticks 00134 * @return The number of seconds. 00135 * 00136 * @api 00137 */ 00138 #define RTT2S(ticks) ((ticks) / halGetCounterFrequency()) 00139 00140 /** 00141 * @brief Realtime ticks to milliseconds. 00142 * @details Converts from realtime ticks number to milliseconds. 00143 * 00144 * @param[in] ticks number of ticks 00145 * @return The number of milliseconds. 00146 * 00147 * @api 00148 */ 00149 #define RTT2MS(ticks) ((ticks) / (halGetCounterFrequency() / 1000UL)) 00150 00151 /** 00152 * @brief Realtime ticks to microseconds. 00153 * @details Converts from realtime ticks number to microseconds. 00154 * 00155 * @param[in] ticks number of ticks 00156 * @return The number of microseconds. 00157 * 00158 * @api 00159 */ 00160 #define RTT2US(ticks) ((ticks) / (halGetCounterFrequency() / 1000000UL)) 00161 /** @} */ 00162 00163 /** 00164 * @name Macro Functions 00165 * @{ 00166 */ 00167 /** 00168 * @brief Returns the current value of the system free running counter. 00169 * @note This is an optional service that could not be implemented in 00170 * all HAL implementations. 00171 * @note This function can be called from any context. 00172 * 00173 * @return The value of the system free running counter of 00174 * type halrtcnt_t. 00175 * 00176 * @special 00177 */ 00178 #define halGetCounterValue() hal_lld_get_counter_value() 00179 00180 /** 00181 * @brief Realtime counter frequency. 00182 * @note This is an optional service that could not be implemented in 00183 * all HAL implementations. 00184 * @note This function can be called from any context. 00185 * 00186 * @return The realtime counter frequency of type halclock_t. 00187 * 00188 * @special 00189 */ 00190 #define halGetCounterFrequency() hal_lld_get_counter_frequency() 00191 /** @} */ 00192 #endif /* HAL_IMPLEMENTS_COUNTERS */ 00193 00194 /*===========================================================================*/ 00195 /* External declarations. */ 00196 /*===========================================================================*/ 00197 00198 #ifdef __cplusplus 00199 extern "C" { 00200 #endif 00201 void halInit(void); 00202 #if HAL_IMPLEMENTS_COUNTERS 00203 bool_t halIsCounterWithin(halrtcnt_t start, halrtcnt_t end); 00204 void halPolledDelay(halrtcnt_t ticks); 00205 #endif /* HAL_IMPLEMENTS_COUNTERS */ 00206 #ifdef __cplusplus 00207 } 00208 #endif 00209 00210 #endif /* _HAL_H_ */ 00211 00212 /** @} */