app_loader.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _APP_LOADER_H_
  13. #define _APP_LOADER_H_
  14. #include "osi_compiler.h"
  15. OSI_EXTERN_C_BEGIN
  16. /**
  17. * \brief application image entry function type
  18. *
  19. * When calling the entry function of application image, typically
  20. * \p param will be NULL, except there are known convention of the
  21. * parameter.
  22. *
  23. * When the return value of 0 means success, other values mean error.
  24. * The error code convention depends on application.
  25. *
  26. * Typically, in the entry function, application shall initialize the
  27. * runtime, and create threads for application. It is not expected
  28. * that the entry function itself will take long time.
  29. *
  30. * For any application, the entry function is necessary.
  31. */
  32. typedef int (*appImageEnter_t)(void *param);
  33. /**
  34. * \brief application exit function type
  35. *
  36. * For application, the exit function is optional, and it can be NULL.
  37. */
  38. typedef void (*appImageExit_t)(void);
  39. /**
  40. * \brief application get parameter
  41. *
  42. * It is a general purpose API to get application parameters. The
  43. * parameter ID and value type are defined by application.
  44. *
  45. * For application, the get parameter function is optional, and it can
  46. * be NULL. Caller should always check whether \p header->get_param
  47. * is not NULL before calling it.
  48. *
  49. * It can be used to access application variable and functions. For
  50. * example,
  51. *
  52. * \code{.cpp}
  53. * if (header->get_param != NULL) {
  54. * // get application API address
  55. * function_t api = NULL;
  56. * if (header->get_param(API_ID, &api) && api != NULL)
  57. * api();
  58. * }
  59. * \endcode
  60. *
  61. * \param id parameter id
  62. * \param value output parameter value
  63. * \return
  64. * - true on success
  65. * - false on failed
  66. */
  67. typedef bool (*appImageGetParam_t)(unsigned id, void *value);
  68. /**
  69. * \brief application set parameter
  70. *
  71. * It is a general purpose API to set application parameters. The
  72. * parameter ID, parameter value are defined by application.
  73. *
  74. * For application, the set parameter function is optional, and it can
  75. * be NULL. Caller should always check whether \p header->set_param
  76. * is not NULL before calling it.
  77. *
  78. * It can be used to trigger application action, send events to
  79. * application, and etc.
  80. *
  81. * \code{.cpp}
  82. * if (header->set_param != NULL) {
  83. * // trigger an application action
  84. * int value = 1;
  85. * header->set_param(ACTION_ID, &value);
  86. * }
  87. * \endcode
  88. *
  89. * \param id parameter id
  90. * \param value parameter value
  91. * \return
  92. * - true on success
  93. * - false on failed
  94. */
  95. typedef bool (*appImageSetParam_t)(unsigned id, const void *value);
  96. /**
  97. * \brief data structure for application image load
  98. */
  99. typedef struct
  100. {
  101. appImageEnter_t enter; ///< entry function
  102. appImageExit_t exit; ///< exit function
  103. appImageGetParam_t get_param; ///< get parameter function
  104. appImageSetParam_t set_param; ///< set parameter function
  105. } appImageHandler_t;
  106. /**
  107. * \brief global application image handler in flash
  108. *
  109. * It is defined only when \p CONFIG_APPIMG_LOAD_FLASH is defined
  110. */
  111. extern appImageHandler_t gAppImgFlash;
  112. /**
  113. * \brief global application image handler in file
  114. *
  115. * It is defined only when \p CONFIG_APPIMG_LOAD_FILE is defined
  116. */
  117. extern appImageHandler_t gAppImgFile;
  118. /**
  119. * \brief load application from memory
  120. *
  121. * \p address can be FLASH or RAM, though typically it shoule be FLASH.
  122. *
  123. * When the application is loaded successfully, \p handler->enter can
  124. * be called to run the application.
  125. *
  126. * \param address application image address
  127. * \param handler application image handler to be loaded
  128. * \return
  129. * - true on success
  130. * - false on fail, such as invalid parameters, or invalid image
  131. */
  132. bool appImageFromMem(const void *address, appImageHandler_t *handler);
  133. /**
  134. * \brief load application from file
  135. *
  136. * When the application is loaded successfully, \p handler->enter can
  137. * be called to run the application.
  138. *
  139. * \param fname application image file name
  140. * \param handler application image handler to be loaded
  141. * \return
  142. * - true on success
  143. * - false on fail, such as invalid parameters, or invalid image
  144. */
  145. bool appImageFromFile(const char *fname, appImageHandler_t *handler);
  146. OSI_EXTERN_C_END
  147. #endif