osal.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*
  2. * Copyright (c) 2015 - 2017, Texas Instruments Incorporated
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. *
  12. * * Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. *
  16. * * Neither the name of Texas Instruments Incorporated nor the names of
  17. * its contributors may be used to endorse or promote products derived
  18. * from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  24. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  25. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  26. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  27. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  28. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  29. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  30. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. /** ============================================================================
  33. * @file osal.h
  34. *
  35. * @brief OS Abstraction Layer header
  36. *
  37. * ============================================================================
  38. */
  39. #ifndef ti_OSAL__include
  40. #define ti_OSAL__include
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44. #include <ti/osal/HwiP.h>
  45. #include <ti/osal/MuxIntcP.h>
  46. #include <ti/osal/SemaphoreP.h>
  47. #include <ti/osal/CacheP.h>
  48. #include <ti/osal/TimerP.h>
  49. #include <ti/osal/RegisterIntr.h>
  50. #include <ti/osal/Queue.h>
  51. #ifdef _TMS320C6X
  52. #include <ti/osal/EventCombinerP.h>
  53. #endif
  54. #define osal_OK (0)
  55. #define osal_FAILURE (-(int32_t)(1))
  56. #define osal_UNSUPPORTED (-(int32_t)(2))
  57. /* Set the number of SemaphoreP_Handles for TIRTOS */
  58. #ifndef OSAL_TIRTOS_CONFIGNUM_SEMAPHORE
  59. #define OSAL_TIRTOS_CONFIGNUM_SEMAPHORE ((uint32_t)100U)
  60. #endif
  61. /* Set the number of TimerP_Handles for TIRTOS */
  62. #ifndef OSAL_TIRTOS_CONFIGNUM_TIMER
  63. #define OSAL_TIRTOS_CONFIGNUM_TIMER ((uint32_t)100U)
  64. #endif
  65. /* Set the number of HwiP_Handles for TIRTOS */
  66. #ifndef OSAL_TIRTOS_CONFIGNUM_HWI
  67. #define OSAL_TIRTOS_CONFIGNUM_HWI ((uint32_t)100U)
  68. #endif
  69. /**
  70. * \brief This structure holds static memory status parameters of OSAL
  71. * library
  72. */
  73. typedef struct Osal_StaticMemoryStatus
  74. {
  75. uint32_t peakSemObjs;
  76. uint32_t numMaxSemObjs;
  77. uint32_t numFreeSemObjs;
  78. uint32_t peakTimerObjs;
  79. uint32_t numMaxTimerObjs;
  80. uint32_t numFreeTimerObjs;
  81. uint32_t peakHwiObjs;
  82. uint32_t numMaxHwiObjs;
  83. uint32_t numFreeHwiObjs;
  84. } Osal_StaticMemStatus;
  85. typedef enum Osal_ThreadType_e {
  86. Osal_ThreadType_Hwi, /*!< Current thread is a Hwi */
  87. Osal_ThreadType_Swi, /*!< Current thread is a Swi */
  88. Osal_ThreadType_Task, /*!< Current thread is a Task */
  89. Osal_ThreadType_Main /*!< Current thread is Main */
  90. } Osal_ThreadType;
  91. #ifdef __KLOCWORK__
  92. extern void abort(void);
  93. /* tell klockwork that OSAL_Assert(1) is fatal */
  94. #define OSAL_Assert(x) do { if ((x)) { abort(); } } while (0)
  95. #else
  96. /* Internal function for assert */
  97. extern void _DebugP_assert(int32_t expression, const char *file, int32_t line);
  98. /*!
  99. * @brief Assert checking function
  100. *
  101. * If the expression is evaluated to true, the API does nothing.
  102. * If it is evaluated to false, the underlying RTOS port implementation
  103. * handles the assert via its mechanisms.
  104. *
  105. * @param expression Expression to evaluate
  106. */
  107. /* in real code use TI's version of OSAL_Assert (which is also fatal for OSAL_Assert(1)*/
  108. #define OSAL_Assert(expression) (_DebugP_assert((expression), \
  109. __FILE__, __LINE__))
  110. #endif
  111. /*!
  112. * @brief Function to get the current thread type.
  113. *
  114. * @param none
  115. *
  116. * @return current thread type
  117. */
  118. extern Osal_ThreadType Osal_getThreadType(void);
  119. /*!
  120. * @brief Function to get the delay/sleep.
  121. *
  122. * @param nTicks number of ticks
  123. *
  124. * #@note for bare metal application it is number of 1ms ticks
  125. *
  126. * Prerequisites: Board_init() to be called before
  127. * invoking this API
  128. *
  129. * @return osal_OK for success, osal_FAILURE on failure
  130. */
  131. extern int32_t Osal_delay(uint32_t nTicks);
  132. /*!
  133. * @brief Osal hw access type
  134. *
  135. */
  136. typedef enum {
  137. OSAL_HWACCESS_UNRESTRICTED, /* No restriction on hardware access or configuration */
  138. OSAL_HWACCESS_RESTRICTED /* Restrictive access to hardware such as GIC */
  139. } Osal_HwAccessType;
  140. /*!
  141. * @brief Osal hw attributes structure
  142. *
  143. */
  144. typedef struct Osal_HwAttrs_s
  145. {
  146. /* External Clock value in KHz */
  147. int32_t extClkKHz;
  148. #ifdef _TMS320C6X
  149. int32_t ECM_intNum[4]; /* Interrupt numbers for Event combiner groups (0-3)*/
  150. #endif
  151. Osal_HwAccessType hwAccessType;
  152. /* Below timer base configuration is applicable for only AM335x/AM437x SoCs
  153. * It is not applicable and should not be set for other SoCs
  154. * Osal setHwAttrs API would return failure (osal_UNSUPPORTED) if attempted to
  155. * be set for SoCs other than AM335x and AM437x.
  156. */
  157. uintptr_t osalDelayTimerBaseAddr;
  158. } Osal_HwAttrs;
  159. /*!
  160. * bit map to set external clock in Osal_HwAttr default value
  161. */
  162. #define OSAL_HWATTR_SET_EXT_CLK (0x00000001U)
  163. /*!
  164. * bit map to set Event combiner interrupt numbers in the Osal_HwAttr
  165. */
  166. #define OSAL_HWATTR_SET_ECM_INT (0x00000002)
  167. /*!
  168. * bit map to set the hardware access type
  169. */
  170. #define OSAL_HWATTR_SET_HWACCESS_TYPE (0x00000004)
  171. /*!
  172. * bit map to set the osal_delay Timer base address
  173. */
  174. #define OSAL_HWATTR_SET_OSALDELAY_TIMER_BASE (0x00000008)
  175. /*!
  176. * @brief Function to set the Hw Attributes
  177. *
  178. * @param control bit map as defined by the OSAL_HWATTR_SET control bits
  179. *
  180. * @param hwAttrs pointer to Osal_HwAttrs structure
  181. *
  182. * @return osal_OK for success, osal_FAILURE on failure and
  183. * osal_UNSUPPORTED for unsupported configurations
  184. * osal_UNSUPPORTED is a non fatal error and applications
  185. * can continue processing if they get this error code.
  186. * Osal would be configured to utilize default timer for
  187. * Osal_delay() API. The default timer address for AM437x and
  188. * AM335x SoCs are found under ti/osal/soc/<soc_part>/osal_soc.h
  189. * For other SoCs the time base address is not applicable and
  190. * the API returns osal_UNSUPPORTED as the return value.
  191. */
  192. extern int32_t Osal_setHwAttrs(uint32_t ctrlBitMap, const Osal_HwAttrs *hwAttrs);
  193. /*!
  194. * @brief Function to get the Hw Attributes
  195. *
  196. * @param hwAttrs pointer to Osal_HwAttrs structure
  197. *
  198. * @return osal_OK for success, osal_FAILURE on failure
  199. */
  200. extern int32_t Osal_getHwAttrs(Osal_HwAttrs *hwAttrs);
  201. /*!
  202. * @brief Function to get the static memory usage of OSAL library
  203. *
  204. * @param pMemStat pointer to Osal_StaticMemStatus structure
  205. *
  206. * @return osal_OK for success, osal_FAILURE on failure
  207. */
  208. extern int32_t Osal_getStaticMemStatus(Osal_StaticMemStatus *pMemStat);
  209. #ifdef __cplusplus
  210. }
  211. #endif
  212. #endif /* ti_OSAL__include */