nwk_bufs.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /**************************************************************************************************
  2. Filename: nwk_bufs.h
  3. Revised: $Date: 2010-10-19 12:38:16 -0700 (Tue, 19 Oct 2010) $
  4. Revision: $Revision: 24150 $
  5. Description: Network buffer utility functions.
  6. Copyright 2004-2010 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 NWK_BUFS_H
  34. #define NWK_BUFS_H
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. /*********************************************************************
  39. * INCLUDES
  40. */
  41. #include "ZComDef.h"
  42. #include "ZMAC.h"
  43. /*********************************************************************
  44. * MACROS
  45. */
  46. /*********************************************************************
  47. * CONSTANTS
  48. */
  49. // Data buffer queue states
  50. #define NWK_DATABUF_INIT 0 // Initialized but not queued.
  51. #define NWK_DATABUF_WAITING 1 // Waiting to be sent out.
  52. #define NWK_DATABUF_SENT 2 // Sent to the MAC - waiting for confirm.
  53. #define NWK_DATABUF_CONFIRMED 3 // Waiting to be resent or deleted.
  54. #define NWK_DATABUF_SCHEDULED 4 // Queued and waiting N msecs til send.
  55. #define NWK_DATABUF_HOLD 5 // Hold msg for sleeping end device.
  56. #define NWK_DATABUF_DONE 6 // Waiting to be deleted.
  57. // Handle options
  58. #define HANDLE_NONE 0x0000u
  59. #define HANDLE_CNF 0x0001u
  60. #define HANDLE_WAIT_FOR_ACK 0x0002u
  61. #define HANDLE_BROADCAST 0x0004u
  62. #define HANDLE_REFLECT 0x0008u
  63. #define HANDLE_DELAY 0x0010u
  64. #define HANDLE_HI_DELAY 0x0020u
  65. //#define HANDLE_DIRECT 0x0040
  66. #define HANDLE_SKIP_ROUTING 0x0040u
  67. #define HANDLE_RTRY_MASK 0x0380u
  68. #define HANDLE_RTRY_SHIFT 7
  69. #define HANDLE_FORCE_INDIRECT 0x0400u
  70. #define HANDLE_INDIRECT_HOLD 0x0800u // A bit indicating the indirect msg has been in HOLD state
  71. #define HANDLE_MCAST 0x1000u
  72. #define HANDLE_MASK \
  73. ~( HANDLE_CNF | HANDLE_WAIT_FOR_ACK | HANDLE_BROADCAST | HANDLE_DELAY | \
  74. HANDLE_HI_DELAY | HANDLE_FORCE_INDIRECT | HANDLE_MCAST)
  75. /*********************************************************************
  76. * TYPEDEFS
  77. */
  78. typedef struct
  79. {
  80. uint8 type;
  81. void* load;
  82. } nwkDB_UserData_t;
  83. typedef struct
  84. {
  85. ZMacDataReq_t *pDataReq;
  86. void *next;
  87. uint16 dataX;
  88. uint16 handleOptions; // Packet type options
  89. byte nsduHandle; // unique ID
  90. byte state; // state of buffer
  91. byte retries; // number of retries
  92. nwkDB_UserData_t ud; // user data
  93. uint16 macSrcAddr; // original MAC src address
  94. } nwkDB_t;
  95. typedef uint8 (*nwkDB_FindMatchCB_t)( nwkDB_t* db, void* mf );
  96. /*********************************************************************
  97. * GLOBAL VARIABLES
  98. */
  99. /*********************************************************************
  100. * FUNCTIONS
  101. */
  102. /*
  103. * Variable initialization
  104. */
  105. extern void nwkbufs_init( void );
  106. /*
  107. * Send the next buffer
  108. */
  109. extern void nwk_SendNextDataBuf( void );
  110. /*
  111. * Determines whether or not the data buffers are full.
  112. */
  113. extern byte nwk_MacDataBuffersFull( void );
  114. /*
  115. * Add buffer to the send queue, if already in queue - set
  116. */
  117. extern uint8 nwk_MacDataBuffersAdd( nwkDB_t* db, uint8 sent );
  118. /*
  119. * Deallocate the sent MAC Data Buffer
  120. *
  121. */
  122. extern uint8 nwk_MacDataBuffersDealloc( byte handle );
  123. /*********************************************************************
  124. * Queued Allocated functions
  125. */
  126. /*
  127. * Create the header
  128. */
  129. extern nwkDB_t *nwkDB_CreateHdr( ZMacDataReq_t *pkt, byte handle, uint16 handleOptions );
  130. /*
  131. * Add a buffer to the queue.
  132. */
  133. extern ZStatus_t nwkDB_Add( nwkDB_t *pkt, byte type, uint16 dataX );
  134. /*
  135. * Find the number of buffers with type.
  136. */
  137. extern byte nwkDB_CountTypes( byte type );
  138. /*
  139. * Find the next type in list.
  140. */
  141. extern nwkDB_t *nwkDB_FindNextType( nwkDB_t *pkt, byte type, byte direct );
  142. /*
  143. * Find the rec with handle.
  144. */
  145. extern nwkDB_t *nwkDB_FindHandle( byte handle );
  146. /*
  147. * Find the rec with destination address.
  148. */
  149. extern nwkDB_t *nwkDB_FindDstAddr( uint16 addr );
  150. /*
  151. * Find the rec with MAC data packet.
  152. */
  153. extern nwkDB_t *nwkDB_FindDataPkt( ZMacDataReq_t *pkt );
  154. /*
  155. * Find a buffer match.
  156. */
  157. extern nwkDB_t* nwkDB_FindMatch( nwkDB_FindMatchCB_t cb, void* mf );
  158. /*
  159. * Find and remove from the list. This function doesn't
  160. * free the memory used by the record.
  161. */
  162. extern void nwkDB_RemoveFromList( nwkDB_t *pkt );
  163. /*
  164. * Frees the data, mac packet and hdr
  165. */
  166. extern void nwkDB_DeleteRecAll( nwkDB_t *rec );
  167. /*
  168. * Setup hold state and timer tick.
  169. */
  170. extern void nwkbufs_hold( nwkDB_t *rec );
  171. /*
  172. * Return cntIndirectHolding
  173. */
  174. extern uint8 nwkDB_ReturnIndirectHoldingCnt( void );
  175. /*
  176. * Count Indirect held message
  177. */
  178. extern uint8 nwkDB_CountIndirectHold( void );
  179. /*
  180. * Delete all records and reset queue
  181. */
  182. extern void nwkbufs_reset( void );
  183. /*
  184. * Stub to load the user frame data
  185. */
  186. extern void* nwkDB_UserDataLoad( nwkDB_UserData_t* ud );
  187. /*********************************************************************
  188. * Broadcast Message Queue functions
  189. */
  190. /*
  191. * Add a broadcast data indication to the network broadcast queue
  192. */
  193. extern uint8 nwk_broadcastSend( uint8 *msg_ptr );
  194. /*
  195. * Remove a broadcast data indication to the network broadcast queue
  196. */
  197. extern uint8 *nwk_broadcastReceive( void );
  198. /*********************************************************************
  199. *********************************************************************/
  200. #ifdef __cplusplus
  201. }
  202. #endif
  203. #endif /* NWK_BUFS_H */