oad_app.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. /**************************************************************************************************
  2. Filename: oad_app.h
  3. Revised: $Date: 2007-01-15 10:33:29 -0700 (Mon, 15 Jan 2007) $
  4. Revision: $Revision: 13298 $
  5. Description: This file contains the declaration of an Over Air Download application.
  6. Copyright 2008-2009 Texas Instruments Incorporated. All rights reserved.
  7. IMPORTANT: Your use of this Software is limited to those specific rights
  8. granted under the terms of a software license agreement between the user
  9. who downloaded the software, his/her employer (which must be your employer)
  10. and Texas Instruments Incorporated (the "License"). You may not use this
  11. Software unless you agree to abide by the terms of the License. The License
  12. limits your use, and you acknowledge, that the Software may not be modified,
  13. copied or distributed unless embedded on a Texas Instruments microcontroller
  14. or used solely and exclusively in conjunction with a Texas Instruments radio
  15. frequency transceiver, which is integrated into your product. Other than for
  16. the foregoing purpose, you may not use, reproduce, copy, prepare derivative
  17. works of, modify, distribute, perform, display or sell this Software and/or
  18. its documentation for any purpose.
  19. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  20. PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  21. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  22. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  23. TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
  24. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  25. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  26. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  27. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  28. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  29. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  30. Should you have any questions regarding your right to use this Software,
  31. contact Texas Instruments Incorporated at www.TI.com.
  32. **************************************************************************************************/
  33. #ifndef OAD_APP_H
  34. #define OAD_APP_H
  35. #ifdef __cplusplus
  36. extern "C"
  37. {
  38. #endif
  39. /* ------------------------------------------------------------------------------------------------
  40. * Includes
  41. * ------------------------------------------------------------------------------------------------
  42. */
  43. #include "hal_oad.h"
  44. #include "hal_types.h"
  45. /* ------------------------------------------------------------------------------------------------
  46. * Macros
  47. * ------------------------------------------------------------------------------------------------
  48. */
  49. /* ------------------------------------------------------------------------------------------------
  50. * Constants
  51. * ------------------------------------------------------------------------------------------------
  52. */
  53. #define OAD_PROFILE_ID 0xC003
  54. #define OAD_CLUSTERID_CS 0x0001 // Used by the original Client-Server managed-session method.
  55. #define OAD_CLUSTER_CNT 2
  56. #define OAD_DEVICEID 0x0001
  57. #define OAD_DEVICE_VERSION 0
  58. #define OAD_FLAGS 0
  59. #define OAD_ENDPOINT 200
  60. #define OAD_EVT_TIMER 0x0001
  61. // Message ID's.
  62. #define ZLMSGID_STATUSQ ((uint8) 0x01)
  63. #define ZLMSGID_SESSION_START ((uint8) 0x02)
  64. #define ZLMSGID_SESSION_TERM ((uint8) 0x03)
  65. #define ZLMSGID_CLIENT_CMD ((uint8) 0x04)
  66. #define ZLMSGID_CODE_ENABLE ((uint8) 0x05)
  67. #define ZLMSGID_SEND_DATA ((uint8) 0x06)
  68. #define ZLMSGID_RESET ((uint8) 0x07)
  69. // Bit OR'ed into message ID to signify a reply to that message.
  70. #define ZLMSGID_REPLY_BIT ((uint8) 0x80)
  71. // for now, the block size and number of blocks per data transfer tansaction is fixed.
  72. #define ZL_DATA_BLK_SIZE 8
  73. #define ZL_NUM_DATA_BLKS 4
  74. // capabilties bits. none for now.
  75. #define ZLOAD_CAPABILTIES (0)
  76. #define ZLOAD_PROTOCOL_VERSION (1)
  77. // Event message bits.
  78. #define ZLOAD_CODE_ENABLE_EVT 0x0001
  79. #define ZLOAD_IS_CLIENT_EVT 0x0002
  80. #define ZLOAD_XFER_DONE_EVT 0x0004
  81. #define ZLOAD_RESET_EVT 0x0008
  82. #define ZLOAD_SDRTIMER_EVT 0x0010
  83. #define ZLOAD_RESET_BOARD_EVT 0x0020
  84. // STATE definitions for state machine
  85. #define ZLSTATE_IDLE (1)
  86. #define ZLSTATE_CLIENT (2)
  87. #define ZLSTATE_SERVER (3)
  88. #define ZLSTATE_PASS_THROUGH (4)
  89. #define ZLSTATE_SUBSTATE_NONE (1)
  90. #define ZLSTATE_SUBSTATE_XFER_DONE (2)
  91. // Error Codes for replies to commands.
  92. // Status Query and Reset always return No Error
  93. #define EC_NO_ERROR ((uint8) 0x00)
  94. #define EC_BAD_VDD ((uint8) 0xDD) // Not enough Vdd to write NV/XNV.
  95. // Begin Session
  96. #define EC_BS_NOT_IDLE ((uint8) 0x21)
  97. #define EC_BS_NO_MATCHES ((uint8) 0x22)
  98. #define EC_BS_NO_MEM ((uint8) 0x23)
  99. #define EC_BS_NOT_SERVER ((uint8) 0x24)
  100. // End Session
  101. #define EC_ES_BAD_SESS_ID ((uint8) 0x31)
  102. #define EC_ES_NOT_SERVER ((uint8) 0x32)
  103. #define EC_ES_NO_MEM ((uint8) 0x33)
  104. // Client
  105. #define EC_CL_NOT_IDLE ((uint8) 0x41)
  106. #define EC_CL_NO_MEM ((uint8) 0x42)
  107. #define EC_CL_NOT_CLIENT ((uint8) 0x43)
  108. // Code enable
  109. #define EC_CE_NO_IMAGE ((uint8) 0x51)
  110. #define EC_CE_NO_MATCH ((uint8) 0x52)
  111. #define EC_CE_NOT_IDLE ((uint8) 0x53)
  112. #define EC_CE_IMAGE_INSANE ((uint8) 0x54)
  113. #define EC_CE_NOT_CLIENT ((uint8) 0x55)
  114. // Send data
  115. #define EC_SD_NOT_SERVER ((uint8) 0x61)
  116. #define EC_SD_BAD_SESS_ID ((uint8) 0x62)
  117. #define EC_SD_BAD_PKT_NUM ((uint8) 0x63)
  118. #define EC_SD_NO_BEG_SESS ((uint8) 0x64)
  119. #define EC_SD_NOT_CLIENT ((uint8) 0x65)
  120. #define EC_SD_NO_MEM ((uint8) 0x66)
  121. // other support
  122. #define PREAMBLE_DL ((uint8) 1)
  123. #define PREAMBLE_OP ((uint8) 2)
  124. #define ZL_IMAGE_ID_LENGTH (6)
  125. #define SERIAL_SERVER_ADDRESS (0xFFFE)
  126. /* ------------------------------------------------------------------------------------------------
  127. * Typedefs
  128. * ------------------------------------------------------------------------------------------------
  129. */
  130. // Message header.
  131. PACK_1
  132. typedef struct {
  133. uint8 zlhdr_msgid;
  134. uint8 zlhdr_seqnum;
  135. uint8 zlhdr_msglen;
  136. } zlmhdr_t;
  137. // STATUS QUERY
  138. // Command: no payload with status query
  139. // Reply
  140. PACK_1
  141. typedef struct {
  142. uint8 zlsqR_state;
  143. uint8 zlsqR_errorCode;
  144. uint8 zlsqR_ProtocolVersion;
  145. uint8 zlsqR_capabilties;
  146. uint16 zlsqR_opVer;
  147. uint16 zlsqR_opManu;
  148. uint16 zlsqR_opProd;
  149. uint16 zlsqR_dlVer;
  150. uint16 zlsqR_dlManu;
  151. uint16 zlsqR_dlProd;
  152. uint16 zlsqR_curPkt;
  153. uint16 zlsqR_totPkt;
  154. } zlstatusR_t;
  155. // SESSION START
  156. // Command
  157. PACK_1
  158. typedef struct {
  159. uint16 zlbsC_ver;
  160. uint16 zlbsC_manu;
  161. uint16 zlbsC_prod;
  162. uint8 zlbsC_sessionID;
  163. } zlbegsessC_t;
  164. // Reply
  165. PACK_1
  166. typedef struct {
  167. uint8 zlbsR_state;
  168. uint8 zlbsR_errorCode;
  169. uint32 zlbsR_imgLen;
  170. uint8 zlbsR_blkSize;
  171. uint8 zlbsR_numBlks;
  172. uint8 zlbsR_preambleOffset;
  173. } zlbegsessR_t;
  174. // SESSION TERMINATE
  175. // Command
  176. PACK_1
  177. typedef struct {
  178. uint8 zlesC_sessionID;
  179. } zlendsessC_t;
  180. // Reply
  181. PACK_1
  182. typedef struct {
  183. uint8 zlesR_state;
  184. uint8 zlesR_errorCode;
  185. } zlendsessR_t;
  186. // CLIENT COMMAND
  187. // Command
  188. PACK_1
  189. typedef struct {
  190. uint16 zlclC_ver;
  191. uint16 zlclC_manu;
  192. uint16 zlclC_prod;
  193. uint8 zlclC_IEEE[Z_EXTADDR_LEN];
  194. uint16 zlclC_nwk;
  195. uint8 zlclC_endp;
  196. } zlclientC_t;
  197. // Reply
  198. PACK_1
  199. typedef struct {
  200. uint8 zlclR_state;
  201. uint8 zlclR_errorCode;
  202. } zlclientR_t;
  203. // CODE ENABLE COMMAND
  204. // Command
  205. PACK_1
  206. typedef struct {
  207. uint16 zlceC_ver;
  208. uint16 zlceC_manu;
  209. uint16 zlceC_prod;
  210. } zlceC_t;
  211. // Reply
  212. PACK_1
  213. typedef struct {
  214. uint8 zlceR_state;
  215. uint8 zlceR_errorCode;
  216. } zlceR_t;
  217. // SEND DATA COMMAND
  218. // Command
  219. PACK_1
  220. typedef struct {
  221. uint16 zlsdC_pktNum;
  222. uint8 zlsdC_sessionID;
  223. } zlsdC_t;
  224. // Reply
  225. PACK_1
  226. typedef struct {
  227. uint8 zlsdR_state;
  228. uint8 zlsdR_errorCode;
  229. uint16 zlsdR_pktNum;
  230. uint8 zlsdR_data[ZL_DATA_BLK_SIZE * ZL_NUM_DATA_BLKS];
  231. } zlsdR_t;
  232. // RESET COMMAND
  233. // Command: no payload with reset command
  234. // Reply
  235. PACK_1
  236. typedef struct {
  237. uint8 zlrstR_state;
  238. uint8 zlrstR_errorCode;
  239. } zlrstR_t;
  240. // the replies (except for send data) are all small. use a union so we can have a single
  241. // malloc() and save code space.
  242. typedef union {
  243. zlstatusR_t statusq;
  244. zlbegsessR_t begSess;
  245. zlendsessR_t endSess;
  246. zlclientR_t client;
  247. zlceR_t enable;
  248. zlrstR_t reset;
  249. } zlreply_t;
  250. /* ------------------------------------------------------------------------------------------------
  251. * Global Variables
  252. * ------------------------------------------------------------------------------------------------
  253. */
  254. extern uint8 oad_app_taskId;
  255. /* ------------------------------------------------------------------------------------------------
  256. * Functions
  257. * ------------------------------------------------------------------------------------------------
  258. */
  259. /**************************************************************************************************
  260. * @fn oadAppInit
  261. *
  262. * @brief This function is called by OSAL system startup.
  263. *
  264. * input parameters
  265. *
  266. * @param id - The Task ID assigned by OSAL.
  267. *
  268. * output parameters
  269. *
  270. * None.
  271. *
  272. * @return None.
  273. **************************************************************************************************
  274. */
  275. void oadAppInit(uint8 id);
  276. /**************************************************************************************************
  277. * @fn oadAppEvt
  278. *
  279. * @brief This function is called to process the OSAL events for the task.
  280. *
  281. * input parameters
  282. *
  283. * @param id - The Task ID assigned by OSAL.
  284. * @param evts - A bit mask representing the OSAL events that are pending for this task.
  285. *
  286. * output parameters
  287. *
  288. * None.
  289. *
  290. * @return None.
  291. **************************************************************************************************
  292. */
  293. uint16 oadAppEvt(uint8 id, uint16 evts);
  294. /**************************************************************************************
  295. * @fn oadAppRegisterCB
  296. *
  297. * @brief Register a callback to be referenced when OAD events occur.
  298. *
  299. * @param input
  300. * pCBFunction pointer to void function with an unsigned short argument.
  301. * eventMask bit mask of events for which the callback should be invoked.
  302. *
  303. * When the callback is invoked its argument will indicate via the bit mask argument
  304. * which event occurred. A null pointer or a null bit mask will have the effect of
  305. * deregistration.
  306. *
  307. * @return none.
  308. */
  309. void oadAppRegisterCB(void (*pCBFunction)(uint16), uint16 eventMask);
  310. /**************************************************************************************************
  311. */
  312. #ifdef __cplusplus
  313. }
  314. #endif
  315. #endif