oi_osinterface.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2014 The Android Open Source Project
  4. * Copyright 2002 - 2004 Open Interface North America, Inc. All rights reserved.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at:
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. ******************************************************************************/
  19. #ifndef _OI_OSINTERFACE_H
  20. #define _OI_OSINTERFACE_H
  21. /**
  22. @file
  23. * This file provides the platform-independent interface for functions for which
  24. * implementation is platform-specific.
  25. *
  26. * The functions in this header file define the operating system or hardware
  27. * services needed by the BLUEmagic 3.0 protocol stack. The
  28. * actual implementation of these services is platform-dependent.
  29. *
  30. */
  31. /**********************************************************************************
  32. $Revision: #1 $
  33. ***********************************************************************************/
  34. #include "oi_stddefs.h"
  35. #include "oi_time.h"
  36. #include "oi_status.h"
  37. #include "oi_modules.h"
  38. /** \addtogroup Misc Miscellaneous APIs */
  39. /**@{*/
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /**
  44. * Terminates execution.
  45. *
  46. * @param reason Reason for termination
  47. */
  48. void OI_FatalError(OI_STATUS reason);
  49. /**
  50. * This function logs an error.
  51. *
  52. * When built for release mode, BLUEmagic 3 errors are logged to
  53. * this function. (in debug mode, errors are logged via
  54. * OI_Print()).
  55. *
  56. * @param module Module in which the error was detected (see
  57. * oi_modules.h)
  58. * @param lineno Line number of the C file OI_SLOG_ERROR called
  59. * @param status Status code associated with the error event
  60. */
  61. void OI_LogError(OI_MODULE module, OI_INT lineno, OI_STATUS status);
  62. /**
  63. * This function initializes the debug code handling.
  64. *
  65. * When built for debug mode, this function performs platform
  66. * dependent initialization to handle message codes passed in
  67. * via OI_SetMsgCode().
  68. */
  69. void OI_InitDebugCodeHandler(void);
  70. /**
  71. * This function reads the time from the real time clock.
  72. *
  73. * All timing in BM3 is relative, typically a granularity
  74. * of 5 or 10 msecs is adequate.
  75. *
  76. * @param[out] now Pointer to the buffer to which the current
  77. * time will be returned
  78. */
  79. void OI_Time_Now(OI_TIME *now);
  80. /**
  81. * This function causes the current thread to sleep for the
  82. * specified amount of time. This function must be called
  83. * without the stack access token.
  84. *
  85. * @note BM3 corestack and profiles never suspend and never call
  86. * OI_Sleep. The use of OI_Sleep is limited to applications and
  87. * platform-specific code.
  88. *
  89. * If your port and applications never use OI_Sleep, this function can be left unimplemented.
  90. *
  91. * @param milliseconds Number of milliseconds to sleep
  92. */
  93. void OI_Sleep(OI_UINT32 milliseconds);
  94. /**
  95. * Defines for message type codes.
  96. */
  97. #define OI_MSG_CODE_APPLICATION 0 /**< Application output */
  98. #define OI_MSG_CODE_ERROR 1 /**< Error message output */
  99. #define OI_MSG_CODE_WARNING 2 /**< Warning message output */
  100. #define OI_MSG_CODE_TRACE 3 /**< User API function trace output */
  101. #define OI_MSG_CODE_PRINT1 4 /**< Catagory 1 debug print output */
  102. #define OI_MSG_CODE_PRINT2 5 /**< Catagory 2 debug print output */
  103. #define OI_MSG_CODE_HEADER 6 /**< Error/Debug output header */
  104. /**
  105. * This function is used to indicate the type of text being output with
  106. * OI_Print(). For the Linux and Win32 platforms, it will set
  107. * the color of the text. Other possible uses could be to insert
  108. * HTML style tags, add some other message type indication, or
  109. * be completely ignored altogether.
  110. *
  111. * @param code OI_MSG_CODE_* indicating setting the message type.
  112. */
  113. void OI_SetMsgCode(OI_UINT8 code);
  114. /**
  115. * All output from OI_Printf() and all debug output is sent to OI_Print.
  116. * Typically, if the platform has a console, OI_Print() is sent to stdout.
  117. * Embedded platforms typically send OI_Print() output to a serial port.
  118. *
  119. * @param str String to print
  120. */
  121. void OI_Print(OI_CHAR const *str);
  122. /**
  123. * In cases where OI_Print() is sending output to a logfile in addition to console,
  124. * it is desirable to also put console input into the logfile.
  125. * This function can be called by the console input process.
  126. *
  127. * @note This is an optional API which is strictly
  128. * between the platform-specific stack_console and osinterface
  129. * modules. This API need only be implemented on those
  130. * platforms where is serves a useful purpose, e.g., win32.
  131. *
  132. * @param str Console input string
  133. */
  134. void OI_Print_ConsoleInput(OI_CHAR const *str);
  135. /**
  136. * This function computes the CRC16 of the program image.
  137. */
  138. OI_UINT16 OI_ProgramImageCRC16(void);
  139. /**
  140. * Writes an integer to stdout in hex. This macro is intended
  141. * for selective use when debugging in small memory
  142. * configurations or other times when it is not possible to use
  143. * OI_DBGPRINT.
  144. *
  145. * @param n the integer to print
  146. */
  147. #define OI_Print_Int(n) \
  148. { \
  149. static const OI_CHAR _digits[] = "0123456789ABCDEF"; \
  150. OI_CHAR _buf[9]; \
  151. OI_CHAR *_str = &_buf[8]; \
  152. OI_UINT32 _i = n; \
  153. *_str = 0; \
  154. do { *(--_str) = _digits[(_i & 0xF)]; _i >>= 4; } while (_i); \
  155. OI_Print(_str); \
  156. }
  157. /**
  158. * Application Dynamic Memory allocation.
  159. *
  160. * These APIs are provided for application use on those
  161. * platforms which have no dynamic memory support. Memory is
  162. * allocated from the pool-based heap managed by the stack's
  163. * internal memory manager.
  164. */
  165. void *OI_APP_Malloc(OI_INT32 size);
  166. void OI_APP_Free(void *ptr);
  167. /*****************************************************************************/
  168. #ifdef __cplusplus
  169. }
  170. #endif
  171. /**@}*/
  172. #endif /* _OI_OSINTERFACE_H */