stream_buffer.h 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280
  1. /*
  2. * FreeRTOS Kernel V11.1.0
  3. * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * SPDX-License-Identifier: MIT
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  8. * this software and associated documentation files (the "Software"), to deal in
  9. * the Software without restriction, including without limitation the rights to
  10. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  11. * the Software, and to permit persons to whom the Software is furnished to do so,
  12. * subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in all
  15. * copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  19. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  20. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  21. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * https://www.FreeRTOS.org
  25. * https://github.com/FreeRTOS
  26. *
  27. */
  28. /*
  29. * Stream buffers are used to send a continuous stream of data from one task or
  30. * interrupt to another. Their implementation is light weight, making them
  31. * particularly suited for interrupt to task and core to core communication
  32. * scenarios.
  33. *
  34. * ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer
  35. * implementation (so also the message buffer implementation, as message buffers
  36. * are built on top of stream buffers) assumes there is only one task or
  37. * interrupt that will write to the buffer (the writer), and only one task or
  38. * interrupt that will read from the buffer (the reader). It is safe for the
  39. * writer and reader to be different tasks or interrupts, but, unlike other
  40. * FreeRTOS objects, it is not safe to have multiple different writers or
  41. * multiple different readers. If there are to be multiple different writers
  42. * then the application writer must place each call to a writing API function
  43. * (such as xStreamBufferSend()) inside a critical section and set the send
  44. * block time to 0. Likewise, if there are to be multiple different readers
  45. * then the application writer must place each call to a reading API function
  46. * (such as xStreamBufferReceive()) inside a critical section section and set the
  47. * receive block time to 0.
  48. *
  49. */
  50. #ifndef STREAM_BUFFER_H
  51. #define STREAM_BUFFER_H
  52. #ifndef INC_FREERTOS_H
  53. #error "include FreeRTOS.h must appear in source files before include stream_buffer.h"
  54. #endif
  55. /* *INDENT-OFF* */
  56. #if defined( __cplusplus )
  57. extern "C" {
  58. #endif
  59. /* *INDENT-ON* */
  60. /**
  61. * Type of stream buffer. For internal use only.
  62. */
  63. #define sbTYPE_STREAM_BUFFER ( ( BaseType_t ) 0 )
  64. #define sbTYPE_MESSAGE_BUFFER ( ( BaseType_t ) 1 )
  65. #define sbTYPE_STREAM_BATCHING_BUFFER ( ( BaseType_t ) 2 )
  66. /**
  67. * Type by which stream buffers are referenced. For example, a call to
  68. * xStreamBufferCreate() returns an StreamBufferHandle_t variable that can
  69. * then be used as a parameter to xStreamBufferSend(), xStreamBufferReceive(),
  70. * etc.
  71. */
  72. struct StreamBufferDef_t;
  73. typedef struct StreamBufferDef_t * StreamBufferHandle_t;
  74. /**
  75. * Type used as a stream buffer's optional callback.
  76. */
  77. typedef void (* StreamBufferCallbackFunction_t)( StreamBufferHandle_t xStreamBuffer,
  78. BaseType_t xIsInsideISR,
  79. BaseType_t * const pxHigherPriorityTaskWoken );
  80. /**
  81. * stream_buffer.h
  82. *
  83. * @code{c}
  84. * StreamBufferHandle_t xStreamBufferCreate( size_t xBufferSizeBytes, size_t xTriggerLevelBytes );
  85. * @endcode
  86. *
  87. * Creates a new stream buffer using dynamically allocated memory. See
  88. * xStreamBufferCreateStatic() for a version that uses statically allocated
  89. * memory (memory that is allocated at compile time).
  90. *
  91. * configSUPPORT_DYNAMIC_ALLOCATION must be set to 1 or left undefined in
  92. * FreeRTOSConfig.h for xStreamBufferCreate() to be available.
  93. * configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
  94. * xStreamBufferCreate() to be available.
  95. *
  96. * @param xBufferSizeBytes The total number of bytes the stream buffer will be
  97. * able to hold at any one time.
  98. *
  99. * @param xTriggerLevelBytes The number of bytes that must be in the stream
  100. * buffer before a task that is blocked on the stream buffer to wait for data is
  101. * moved out of the blocked state. For example, if a task is blocked on a read
  102. * of an empty stream buffer that has a trigger level of 1 then the task will be
  103. * unblocked when a single byte is written to the buffer or the task's block
  104. * time expires. As another example, if a task is blocked on a read of an empty
  105. * stream buffer that has a trigger level of 10 then the task will not be
  106. * unblocked until the stream buffer contains at least 10 bytes or the task's
  107. * block time expires. If a reading task's block time expires before the
  108. * trigger level is reached then the task will still receive however many bytes
  109. * are actually available. Setting a trigger level of 0 will result in a
  110. * trigger level of 1 being used. It is not valid to specify a trigger level
  111. * that is greater than the buffer size.
  112. *
  113. * @param pxSendCompletedCallback Callback invoked when number of bytes at least equal to
  114. * trigger level is sent to the stream buffer. If the parameter is NULL, it will use the default
  115. * implementation provided by sbSEND_COMPLETED macro. To enable the callback,
  116. * configUSE_SB_COMPLETED_CALLBACK must be set to 1 in FreeRTOSConfig.h.
  117. *
  118. * @param pxReceiveCompletedCallback Callback invoked when more than zero bytes are read from a
  119. * stream buffer. If the parameter is NULL, it will use the default
  120. * implementation provided by sbRECEIVE_COMPLETED macro. To enable the callback,
  121. * configUSE_SB_COMPLETED_CALLBACK must be set to 1 in FreeRTOSConfig.h.
  122. *
  123. * @return If NULL is returned, then the stream buffer cannot be created
  124. * because there is insufficient heap memory available for FreeRTOS to allocate
  125. * the stream buffer data structures and storage area. A non-NULL value being
  126. * returned indicates that the stream buffer has been created successfully -
  127. * the returned value should be stored as the handle to the created stream
  128. * buffer.
  129. *
  130. * Example use:
  131. * @code{c}
  132. *
  133. * void vAFunction( void )
  134. * {
  135. * StreamBufferHandle_t xStreamBuffer;
  136. * const size_t xStreamBufferSizeBytes = 100, xTriggerLevel = 10;
  137. *
  138. * // Create a stream buffer that can hold 100 bytes. The memory used to hold
  139. * // both the stream buffer structure and the data in the stream buffer is
  140. * // allocated dynamically.
  141. * xStreamBuffer = xStreamBufferCreate( xStreamBufferSizeBytes, xTriggerLevel );
  142. *
  143. * if( xStreamBuffer == NULL )
  144. * {
  145. * // There was not enough heap memory space available to create the
  146. * // stream buffer.
  147. * }
  148. * else
  149. * {
  150. * // The stream buffer was created successfully and can now be used.
  151. * }
  152. * }
  153. * @endcode
  154. * \defgroup xStreamBufferCreate xStreamBufferCreate
  155. * \ingroup StreamBufferManagement
  156. */
  157. #define xStreamBufferCreate( xBufferSizeBytes, xTriggerLevelBytes ) \
  158. xStreamBufferGenericCreate( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), sbTYPE_STREAM_BUFFER, NULL, NULL )
  159. #if ( configUSE_SB_COMPLETED_CALLBACK == 1 )
  160. #define xStreamBufferCreateWithCallback( xBufferSizeBytes, xTriggerLevelBytes, pxSendCompletedCallback, pxReceiveCompletedCallback ) \
  161. xStreamBufferGenericCreate( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), sbTYPE_STREAM_BUFFER, ( pxSendCompletedCallback ), ( pxReceiveCompletedCallback ) )
  162. #endif
  163. /**
  164. * stream_buffer.h
  165. *
  166. * @code{c}
  167. * StreamBufferHandle_t xStreamBufferCreateStatic( size_t xBufferSizeBytes,
  168. * size_t xTriggerLevelBytes,
  169. * uint8_t *pucStreamBufferStorageArea,
  170. * StaticStreamBuffer_t *pxStaticStreamBuffer );
  171. * @endcode
  172. * Creates a new stream buffer using statically allocated memory. See
  173. * xStreamBufferCreate() for a version that uses dynamically allocated memory.
  174. *
  175. * configSUPPORT_STATIC_ALLOCATION must be set to 1 in FreeRTOSConfig.h for
  176. * xStreamBufferCreateStatic() to be available. configUSE_STREAM_BUFFERS must be
  177. * set to 1 in for FreeRTOSConfig.h for xStreamBufferCreateStatic() to be
  178. * available.
  179. *
  180. * @param xBufferSizeBytes The size, in bytes, of the buffer pointed to by the
  181. * pucStreamBufferStorageArea parameter.
  182. *
  183. * @param xTriggerLevelBytes The number of bytes that must be in the stream
  184. * buffer before a task that is blocked on the stream buffer to wait for data is
  185. * moved out of the blocked state. For example, if a task is blocked on a read
  186. * of an empty stream buffer that has a trigger level of 1 then the task will be
  187. * unblocked when a single byte is written to the buffer or the task's block
  188. * time expires. As another example, if a task is blocked on a read of an empty
  189. * stream buffer that has a trigger level of 10 then the task will not be
  190. * unblocked until the stream buffer contains at least 10 bytes or the task's
  191. * block time expires. If a reading task's block time expires before the
  192. * trigger level is reached then the task will still receive however many bytes
  193. * are actually available. Setting a trigger level of 0 will result in a
  194. * trigger level of 1 being used. It is not valid to specify a trigger level
  195. * that is greater than the buffer size.
  196. *
  197. * @param pucStreamBufferStorageArea Must point to a uint8_t array that is at
  198. * least xBufferSizeBytes big. This is the array to which streams are
  199. * copied when they are written to the stream buffer.
  200. *
  201. * @param pxStaticStreamBuffer Must point to a variable of type
  202. * StaticStreamBuffer_t, which will be used to hold the stream buffer's data
  203. * structure.
  204. *
  205. * @param pxSendCompletedCallback Callback invoked when number of bytes at least equal to
  206. * trigger level is sent to the stream buffer. If the parameter is NULL, it will use the default
  207. * implementation provided by sbSEND_COMPLETED macro. To enable the callback,
  208. * configUSE_SB_COMPLETED_CALLBACK must be set to 1 in FreeRTOSConfig.h.
  209. *
  210. * @param pxReceiveCompletedCallback Callback invoked when more than zero bytes are read from a
  211. * stream buffer. If the parameter is NULL, it will use the default
  212. * implementation provided by sbRECEIVE_COMPLETED macro. To enable the callback,
  213. * configUSE_SB_COMPLETED_CALLBACK must be set to 1 in FreeRTOSConfig.h.
  214. *
  215. * @return If the stream buffer is created successfully then a handle to the
  216. * created stream buffer is returned. If either pucStreamBufferStorageArea or
  217. * pxStaticstreamBuffer are NULL then NULL is returned.
  218. *
  219. * Example use:
  220. * @code{c}
  221. *
  222. * // Used to dimension the array used to hold the streams. The available space
  223. * // will actually be one less than this, so 999.
  224. #define STORAGE_SIZE_BYTES 1000
  225. *
  226. * // Defines the memory that will actually hold the streams within the stream
  227. * // buffer.
  228. * static uint8_t ucStorageBuffer[ STORAGE_SIZE_BYTES ];
  229. *
  230. * // The variable used to hold the stream buffer structure.
  231. * StaticStreamBuffer_t xStreamBufferStruct;
  232. *
  233. * void MyFunction( void )
  234. * {
  235. * StreamBufferHandle_t xStreamBuffer;
  236. * const size_t xTriggerLevel = 1;
  237. *
  238. * xStreamBuffer = xStreamBufferCreateStatic( sizeof( ucStorageBuffer ),
  239. * xTriggerLevel,
  240. * ucStorageBuffer,
  241. * &xStreamBufferStruct );
  242. *
  243. * // As neither the pucStreamBufferStorageArea or pxStaticStreamBuffer
  244. * // parameters were NULL, xStreamBuffer will not be NULL, and can be used to
  245. * // reference the created stream buffer in other stream buffer API calls.
  246. *
  247. * // Other code that uses the stream buffer can go here.
  248. * }
  249. *
  250. * @endcode
  251. * \defgroup xStreamBufferCreateStatic xStreamBufferCreateStatic
  252. * \ingroup StreamBufferManagement
  253. */
  254. #define xStreamBufferCreateStatic( xBufferSizeBytes, xTriggerLevelBytes, pucStreamBufferStorageArea, pxStaticStreamBuffer ) \
  255. xStreamBufferGenericCreateStatic( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), sbTYPE_STREAM_BUFFER, ( pucStreamBufferStorageArea ), ( pxStaticStreamBuffer ), NULL, NULL )
  256. #if ( configUSE_SB_COMPLETED_CALLBACK == 1 )
  257. #define xStreamBufferCreateStaticWithCallback( xBufferSizeBytes, xTriggerLevelBytes, pucStreamBufferStorageArea, pxStaticStreamBuffer, pxSendCompletedCallback, pxReceiveCompletedCallback ) \
  258. xStreamBufferGenericCreateStatic( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), sbTYPE_STREAM_BUFFER, ( pucStreamBufferStorageArea ), ( pxStaticStreamBuffer ), ( pxSendCompletedCallback ), ( pxReceiveCompletedCallback ) )
  259. #endif
  260. /**
  261. * stream_buffer.h
  262. *
  263. * @code{c}
  264. * StreamBufferHandle_t xStreamBatchingBufferCreate( size_t xBufferSizeBytes, size_t xTriggerLevelBytes );
  265. * @endcode
  266. *
  267. * Creates a new stream batching buffer using dynamically allocated memory. See
  268. * xStreamBatchingBufferCreateStatic() for a version that uses statically
  269. * allocated memory (memory that is allocated at compile time).
  270. *
  271. * configSUPPORT_DYNAMIC_ALLOCATION must be set to 1 or left undefined in
  272. * FreeRTOSConfig.h for xStreamBatchingBufferCreate() to be available.
  273. * configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
  274. * xStreamBatchingBufferCreate() to be available.
  275. *
  276. * The difference between a stream buffer and a stream batching buffer is when
  277. * a task performs read on a non-empty buffer:
  278. * - The task reading from a non-empty stream buffer returns immediately
  279. * regardless of the amount of data in the buffer.
  280. * - The task reading from a non-empty steam batching buffer blocks until the
  281. * amount of data in the buffer exceeds the trigger level or the block time
  282. * expires.
  283. *
  284. * @param xBufferSizeBytes The total number of bytes the stream batching buffer
  285. * will be able to hold at any one time.
  286. *
  287. * @param xTriggerLevelBytes The number of bytes that must be in the stream
  288. * batching buffer to unblock a task calling xStreamBufferReceive before the
  289. * block time expires.
  290. *
  291. * @param pxSendCompletedCallback Callback invoked when number of bytes at least
  292. * equal to trigger level is sent to the stream batching buffer. If the
  293. * parameter is NULL, it will use the default implementation provided by
  294. * sbSEND_COMPLETED macro. To enable the callback, configUSE_SB_COMPLETED_CALLBACK
  295. * must be set to 1 in FreeRTOSConfig.h.
  296. *
  297. * @param pxReceiveCompletedCallback Callback invoked when more than zero bytes
  298. * are read from a stream batching buffer. If the parameter is NULL, it will use
  299. * the default implementation provided by sbRECEIVE_COMPLETED macro. To enable
  300. * the callback, configUSE_SB_COMPLETED_CALLBACK must be set to 1 in
  301. * FreeRTOSConfig.h.
  302. *
  303. * @return If NULL is returned, then the stream batching buffer cannot be created
  304. * because there is insufficient heap memory available for FreeRTOS to allocate
  305. * the stream batching buffer data structures and storage area. A non-NULL value
  306. * being returned indicates that the stream batching buffer has been created
  307. * successfully - the returned value should be stored as the handle to the
  308. * created stream batching buffer.
  309. *
  310. * Example use:
  311. * @code{c}
  312. *
  313. * void vAFunction( void )
  314. * {
  315. * StreamBufferHandle_t xStreamBatchingBuffer;
  316. * const size_t xStreamBufferSizeBytes = 100, xTriggerLevel = 10;
  317. *
  318. * // Create a stream batching buffer that can hold 100 bytes. The memory used
  319. * // to hold both the stream batching buffer structure and the data in the stream
  320. * // batching buffer is allocated dynamically.
  321. * xStreamBatchingBuffer = xStreamBatchingBufferCreate( xStreamBufferSizeBytes, xTriggerLevel );
  322. *
  323. * if( xStreamBatchingBuffer == NULL )
  324. * {
  325. * // There was not enough heap memory space available to create the
  326. * // stream batching buffer.
  327. * }
  328. * else
  329. * {
  330. * // The stream batching buffer was created successfully and can now be used.
  331. * }
  332. * }
  333. * @endcode
  334. * \defgroup xStreamBatchingBufferCreate xStreamBatchingBufferCreate
  335. * \ingroup StreamBatchingBufferManagement
  336. */
  337. #define xStreamBatchingBufferCreate( xBufferSizeBytes, xTriggerLevelBytes ) \
  338. xStreamBufferGenericCreate( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), sbTYPE_STREAM_BATCHING_BUFFER, NULL, NULL )
  339. #if ( configUSE_SB_COMPLETED_CALLBACK == 1 )
  340. #define xStreamBatchingBufferCreateWithCallback( xBufferSizeBytes, xTriggerLevelBytes, pxSendCompletedCallback, pxReceiveCompletedCallback ) \
  341. xStreamBufferGenericCreate( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), sbTYPE_STREAM_BATCHING_BUFFER, ( pxSendCompletedCallback ), ( pxReceiveCompletedCallback ) )
  342. #endif
  343. /**
  344. * stream_buffer.h
  345. *
  346. * @code{c}
  347. * StreamBufferHandle_t xStreamBatchingBufferCreateStatic( size_t xBufferSizeBytes,
  348. * size_t xTriggerLevelBytes,
  349. * uint8_t *pucStreamBufferStorageArea,
  350. * StaticStreamBuffer_t *pxStaticStreamBuffer );
  351. * @endcode
  352. * Creates a new stream batching buffer using statically allocated memory. See
  353. * xStreamBatchingBufferCreate() for a version that uses dynamically allocated
  354. * memory.
  355. *
  356. * configSUPPORT_STATIC_ALLOCATION must be set to 1 in FreeRTOSConfig.h for
  357. * xStreamBatchingBufferCreateStatic() to be available. configUSE_STREAM_BUFFERS
  358. * must be set to 1 in for FreeRTOSConfig.h for xStreamBatchingBufferCreateStatic()
  359. * to be available.
  360. *
  361. * The difference between a stream buffer and a stream batching buffer is when
  362. * a task performs read on a non-empty buffer:
  363. * - The task reading from a non-empty stream buffer returns immediately
  364. * regardless of the amount of data in the buffer.
  365. * - The task reading from a non-empty steam batching buffer blocks until the
  366. * amount of data in the buffer exceeds the trigger level or the block time
  367. * expires.
  368. *
  369. * @param xBufferSizeBytes The size, in bytes, of the buffer pointed to by the
  370. * pucStreamBufferStorageArea parameter.
  371. *
  372. * @param xTriggerLevelBytes The number of bytes that must be in the stream
  373. * batching buffer to unblock a task calling xStreamBufferReceive before the
  374. * block time expires.
  375. *
  376. * @param pucStreamBufferStorageArea Must point to a uint8_t array that is at
  377. * least xBufferSizeBytes big. This is the array to which streams are
  378. * copied when they are written to the stream batching buffer.
  379. *
  380. * @param pxStaticStreamBuffer Must point to a variable of type
  381. * StaticStreamBuffer_t, which will be used to hold the stream batching buffer's
  382. * data structure.
  383. *
  384. * @param pxSendCompletedCallback Callback invoked when number of bytes at least
  385. * equal to trigger level is sent to the stream batching buffer. If the parameter
  386. * is NULL, it will use the default implementation provided by sbSEND_COMPLETED
  387. * macro. To enable the callback, configUSE_SB_COMPLETED_CALLBACK must be set to
  388. * 1 in FreeRTOSConfig.h.
  389. *
  390. * @param pxReceiveCompletedCallback Callback invoked when more than zero bytes
  391. * are read from a stream batching buffer. If the parameter is NULL, it will use
  392. * the default implementation provided by sbRECEIVE_COMPLETED macro. To enable
  393. * the callback, configUSE_SB_COMPLETED_CALLBACK must be set to 1 in
  394. * FreeRTOSConfig.h.
  395. *
  396. * @return If the stream batching buffer is created successfully then a handle
  397. * to the created stream batching buffer is returned. If either pucStreamBufferStorageArea
  398. * or pxStaticstreamBuffer are NULL then NULL is returned.
  399. *
  400. * Example use:
  401. * @code{c}
  402. *
  403. * // Used to dimension the array used to hold the streams. The available space
  404. * // will actually be one less than this, so 999.
  405. * #define STORAGE_SIZE_BYTES 1000
  406. *
  407. * // Defines the memory that will actually hold the streams within the stream
  408. * // batching buffer.
  409. * static uint8_t ucStorageBuffer[ STORAGE_SIZE_BYTES ];
  410. *
  411. * // The variable used to hold the stream batching buffer structure.
  412. * StaticStreamBuffer_t xStreamBufferStruct;
  413. *
  414. * void MyFunction( void )
  415. * {
  416. * StreamBufferHandle_t xStreamBatchingBuffer;
  417. * const size_t xTriggerLevel = 1;
  418. *
  419. * xStreamBatchingBuffer = xStreamBatchingBufferCreateStatic( sizeof( ucStorageBuffer ),
  420. * xTriggerLevel,
  421. * ucStorageBuffer,
  422. * &xStreamBufferStruct );
  423. *
  424. * // As neither the pucStreamBufferStorageArea or pxStaticStreamBuffer
  425. * // parameters were NULL, xStreamBatchingBuffer will not be NULL, and can be
  426. * // used to reference the created stream batching buffer in other stream
  427. * // buffer API calls.
  428. *
  429. * // Other code that uses the stream batching buffer can go here.
  430. * }
  431. *
  432. * @endcode
  433. * \defgroup xStreamBatchingBufferCreateStatic xStreamBatchingBufferCreateStatic
  434. * \ingroup StreamBatchingBufferManagement
  435. */
  436. #define xStreamBatchingBufferCreateStatic( xBufferSizeBytes, xTriggerLevelBytes, pucStreamBufferStorageArea, pxStaticStreamBuffer ) \
  437. xStreamBufferGenericCreateStatic( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), sbTYPE_STREAM_BATCHING_BUFFER, ( pucStreamBufferStorageArea ), ( pxStaticStreamBuffer ), NULL, NULL )
  438. #if ( configUSE_SB_COMPLETED_CALLBACK == 1 )
  439. #define xStreamBatchingBufferCreateStaticWithCallback( xBufferSizeBytes, xTriggerLevelBytes, pucStreamBufferStorageArea, pxStaticStreamBuffer, pxSendCompletedCallback, pxReceiveCompletedCallback ) \
  440. xStreamBufferGenericCreateStatic( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), sbTYPE_STREAM_BATCHING_BUFFER, ( pucStreamBufferStorageArea ), ( pxStaticStreamBuffer ), ( pxSendCompletedCallback ), ( pxReceiveCompletedCallback ) )
  441. #endif
  442. /**
  443. * stream_buffer.h
  444. *
  445. * @code{c}
  446. * BaseType_t xStreamBufferGetStaticBuffers( StreamBufferHandle_t xStreamBuffer,
  447. * uint8_t ** ppucStreamBufferStorageArea,
  448. * StaticStreamBuffer_t ** ppxStaticStreamBuffer );
  449. * @endcode
  450. *
  451. * Retrieve pointers to a statically created stream buffer's data structure
  452. * buffer and storage area buffer. These are the same buffers that are supplied
  453. * at the time of creation.
  454. *
  455. * configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
  456. * xStreamBufferGetStaticBuffers() to be available.
  457. *
  458. * @param xStreamBuffer The stream buffer for which to retrieve the buffers.
  459. *
  460. * @param ppucStreamBufferStorageArea Used to return a pointer to the stream
  461. * buffer's storage area buffer.
  462. *
  463. * @param ppxStaticStreamBuffer Used to return a pointer to the stream
  464. * buffer's data structure buffer.
  465. *
  466. * @return pdTRUE if buffers were retrieved, pdFALSE otherwise.
  467. *
  468. * \defgroup xStreamBufferGetStaticBuffers xStreamBufferGetStaticBuffers
  469. * \ingroup StreamBufferManagement
  470. */
  471. #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  472. BaseType_t xStreamBufferGetStaticBuffers( StreamBufferHandle_t xStreamBuffer,
  473. uint8_t ** ppucStreamBufferStorageArea,
  474. StaticStreamBuffer_t ** ppxStaticStreamBuffer ) PRIVILEGED_FUNCTION;
  475. #endif /* configSUPPORT_STATIC_ALLOCATION */
  476. /**
  477. * stream_buffer.h
  478. *
  479. * @code{c}
  480. * size_t xStreamBufferSend( StreamBufferHandle_t xStreamBuffer,
  481. * const void *pvTxData,
  482. * size_t xDataLengthBytes,
  483. * TickType_t xTicksToWait );
  484. * @endcode
  485. *
  486. * Sends bytes to a stream buffer. The bytes are copied into the stream buffer.
  487. *
  488. * ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer
  489. * implementation (so also the message buffer implementation, as message buffers
  490. * are built on top of stream buffers) assumes there is only one task or
  491. * interrupt that will write to the buffer (the writer), and only one task or
  492. * interrupt that will read from the buffer (the reader). It is safe for the
  493. * writer and reader to be different tasks or interrupts, but, unlike other
  494. * FreeRTOS objects, it is not safe to have multiple different writers or
  495. * multiple different readers. If there are to be multiple different writers
  496. * then the application writer must place each call to a writing API function
  497. * (such as xStreamBufferSend()) inside a critical section and set the send
  498. * block time to 0. Likewise, if there are to be multiple different readers
  499. * then the application writer must place each call to a reading API function
  500. * (such as xStreamBufferReceive()) inside a critical section and set the receive
  501. * block time to 0.
  502. *
  503. * Use xStreamBufferSend() to write to a stream buffer from a task. Use
  504. * xStreamBufferSendFromISR() to write to a stream buffer from an interrupt
  505. * service routine (ISR).
  506. *
  507. * configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
  508. * xStreamBufferSend() to be available.
  509. *
  510. * @param xStreamBuffer The handle of the stream buffer to which a stream is
  511. * being sent.
  512. *
  513. * @param pvTxData A pointer to the buffer that holds the bytes to be copied
  514. * into the stream buffer.
  515. *
  516. * @param xDataLengthBytes The maximum number of bytes to copy from pvTxData
  517. * into the stream buffer.
  518. *
  519. * @param xTicksToWait The maximum amount of time the task should remain in the
  520. * Blocked state to wait for enough space to become available in the stream
  521. * buffer, should the stream buffer contain too little space to hold the
  522. * another xDataLengthBytes bytes. The block time is specified in tick periods,
  523. * so the absolute time it represents is dependent on the tick frequency. The
  524. * macro pdMS_TO_TICKS() can be used to convert a time specified in milliseconds
  525. * into a time specified in ticks. Setting xTicksToWait to portMAX_DELAY will
  526. * cause the task to wait indefinitely (without timing out), provided
  527. * INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h. If a task times out
  528. * before it can write all xDataLengthBytes into the buffer it will still write
  529. * as many bytes as possible. A task does not use any CPU time when it is in
  530. * the blocked state.
  531. *
  532. * @return The number of bytes written to the stream buffer. If a task times
  533. * out before it can write all xDataLengthBytes into the buffer it will still
  534. * write as many bytes as possible.
  535. *
  536. * Example use:
  537. * @code{c}
  538. * void vAFunction( StreamBufferHandle_t xStreamBuffer )
  539. * {
  540. * size_t xBytesSent;
  541. * uint8_t ucArrayToSend[] = { 0, 1, 2, 3 };
  542. * char *pcStringToSend = "String to send";
  543. * const TickType_t x100ms = pdMS_TO_TICKS( 100 );
  544. *
  545. * // Send an array to the stream buffer, blocking for a maximum of 100ms to
  546. * // wait for enough space to be available in the stream buffer.
  547. * xBytesSent = xStreamBufferSend( xStreamBuffer, ( void * ) ucArrayToSend, sizeof( ucArrayToSend ), x100ms );
  548. *
  549. * if( xBytesSent != sizeof( ucArrayToSend ) )
  550. * {
  551. * // The call to xStreamBufferSend() times out before there was enough
  552. * // space in the buffer for the data to be written, but it did
  553. * // successfully write xBytesSent bytes.
  554. * }
  555. *
  556. * // Send the string to the stream buffer. Return immediately if there is not
  557. * // enough space in the buffer.
  558. * xBytesSent = xStreamBufferSend( xStreamBuffer, ( void * ) pcStringToSend, strlen( pcStringToSend ), 0 );
  559. *
  560. * if( xBytesSent != strlen( pcStringToSend ) )
  561. * {
  562. * // The entire string could not be added to the stream buffer because
  563. * // there was not enough free space in the buffer, but xBytesSent bytes
  564. * // were sent. Could try again to send the remaining bytes.
  565. * }
  566. * }
  567. * @endcode
  568. * \defgroup xStreamBufferSend xStreamBufferSend
  569. * \ingroup StreamBufferManagement
  570. */
  571. size_t xStreamBufferSend( StreamBufferHandle_t xStreamBuffer,
  572. const void * pvTxData,
  573. size_t xDataLengthBytes,
  574. TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
  575. /**
  576. * stream_buffer.h
  577. *
  578. * @code{c}
  579. * size_t xStreamBufferSendFromISR( StreamBufferHandle_t xStreamBuffer,
  580. * const void *pvTxData,
  581. * size_t xDataLengthBytes,
  582. * BaseType_t *pxHigherPriorityTaskWoken );
  583. * @endcode
  584. *
  585. * Interrupt safe version of the API function that sends a stream of bytes to
  586. * the stream buffer.
  587. *
  588. * ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer
  589. * implementation (so also the message buffer implementation, as message buffers
  590. * are built on top of stream buffers) assumes there is only one task or
  591. * interrupt that will write to the buffer (the writer), and only one task or
  592. * interrupt that will read from the buffer (the reader). It is safe for the
  593. * writer and reader to be different tasks or interrupts, but, unlike other
  594. * FreeRTOS objects, it is not safe to have multiple different writers or
  595. * multiple different readers. If there are to be multiple different writers
  596. * then the application writer must place each call to a writing API function
  597. * (such as xStreamBufferSend()) inside a critical section and set the send
  598. * block time to 0. Likewise, if there are to be multiple different readers
  599. * then the application writer must place each call to a reading API function
  600. * (such as xStreamBufferReceive()) inside a critical section and set the receive
  601. * block time to 0.
  602. *
  603. * Use xStreamBufferSend() to write to a stream buffer from a task. Use
  604. * xStreamBufferSendFromISR() to write to a stream buffer from an interrupt
  605. * service routine (ISR).
  606. *
  607. * configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
  608. * xStreamBufferSendFromISR() to be available.
  609. *
  610. * @param xStreamBuffer The handle of the stream buffer to which a stream is
  611. * being sent.
  612. *
  613. * @param pvTxData A pointer to the data that is to be copied into the stream
  614. * buffer.
  615. *
  616. * @param xDataLengthBytes The maximum number of bytes to copy from pvTxData
  617. * into the stream buffer.
  618. *
  619. * @param pxHigherPriorityTaskWoken It is possible that a stream buffer will
  620. * have a task blocked on it waiting for data. Calling
  621. * xStreamBufferSendFromISR() can make data available, and so cause a task that
  622. * was waiting for data to leave the Blocked state. If calling
  623. * xStreamBufferSendFromISR() causes a task to leave the Blocked state, and the
  624. * unblocked task has a priority higher than the currently executing task (the
  625. * task that was interrupted), then, internally, xStreamBufferSendFromISR()
  626. * will set *pxHigherPriorityTaskWoken to pdTRUE. If
  627. * xStreamBufferSendFromISR() sets this value to pdTRUE, then normally a
  628. * context switch should be performed before the interrupt is exited. This will
  629. * ensure that the interrupt returns directly to the highest priority Ready
  630. * state task. *pxHigherPriorityTaskWoken should be set to pdFALSE before it
  631. * is passed into the function. See the example code below for an example.
  632. *
  633. * @return The number of bytes actually written to the stream buffer, which will
  634. * be less than xDataLengthBytes if the stream buffer didn't have enough free
  635. * space for all the bytes to be written.
  636. *
  637. * Example use:
  638. * @code{c}
  639. * // A stream buffer that has already been created.
  640. * StreamBufferHandle_t xStreamBuffer;
  641. *
  642. * void vAnInterruptServiceRoutine( void )
  643. * {
  644. * size_t xBytesSent;
  645. * char *pcStringToSend = "String to send";
  646. * BaseType_t xHigherPriorityTaskWoken = pdFALSE; // Initialised to pdFALSE.
  647. *
  648. * // Attempt to send the string to the stream buffer.
  649. * xBytesSent = xStreamBufferSendFromISR( xStreamBuffer,
  650. * ( void * ) pcStringToSend,
  651. * strlen( pcStringToSend ),
  652. * &xHigherPriorityTaskWoken );
  653. *
  654. * if( xBytesSent != strlen( pcStringToSend ) )
  655. * {
  656. * // There was not enough free space in the stream buffer for the entire
  657. * // string to be written, ut xBytesSent bytes were written.
  658. * }
  659. *
  660. * // If xHigherPriorityTaskWoken was set to pdTRUE inside
  661. * // xStreamBufferSendFromISR() then a task that has a priority above the
  662. * // priority of the currently executing task was unblocked and a context
  663. * // switch should be performed to ensure the ISR returns to the unblocked
  664. * // task. In most FreeRTOS ports this is done by simply passing
  665. * // xHigherPriorityTaskWoken into portYIELD_FROM_ISR(), which will test the
  666. * // variables value, and perform the context switch if necessary. Check the
  667. * // documentation for the port in use for port specific instructions.
  668. * portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
  669. * }
  670. * @endcode
  671. * \defgroup xStreamBufferSendFromISR xStreamBufferSendFromISR
  672. * \ingroup StreamBufferManagement
  673. */
  674. size_t xStreamBufferSendFromISR( StreamBufferHandle_t xStreamBuffer,
  675. const void * pvTxData,
  676. size_t xDataLengthBytes,
  677. BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
  678. /**
  679. * stream_buffer.h
  680. *
  681. * @code{c}
  682. * size_t xStreamBufferReceive( StreamBufferHandle_t xStreamBuffer,
  683. * void *pvRxData,
  684. * size_t xBufferLengthBytes,
  685. * TickType_t xTicksToWait );
  686. * @endcode
  687. *
  688. * Receives bytes from a stream buffer.
  689. *
  690. * ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer
  691. * implementation (so also the message buffer implementation, as message buffers
  692. * are built on top of stream buffers) assumes there is only one task or
  693. * interrupt that will write to the buffer (the writer), and only one task or
  694. * interrupt that will read from the buffer (the reader). It is safe for the
  695. * writer and reader to be different tasks or interrupts, but, unlike other
  696. * FreeRTOS objects, it is not safe to have multiple different writers or
  697. * multiple different readers. If there are to be multiple different writers
  698. * then the application writer must place each call to a writing API function
  699. * (such as xStreamBufferSend()) inside a critical section and set the send
  700. * block time to 0. Likewise, if there are to be multiple different readers
  701. * then the application writer must place each call to a reading API function
  702. * (such as xStreamBufferReceive()) inside a critical section and set the receive
  703. * block time to 0.
  704. *
  705. * Use xStreamBufferReceive() to read from a stream buffer from a task. Use
  706. * xStreamBufferReceiveFromISR() to read from a stream buffer from an
  707. * interrupt service routine (ISR).
  708. *
  709. * configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
  710. * xStreamBufferReceive() to be available.
  711. *
  712. * @param xStreamBuffer The handle of the stream buffer from which bytes are to
  713. * be received.
  714. *
  715. * @param pvRxData A pointer to the buffer into which the received bytes will be
  716. * copied.
  717. *
  718. * @param xBufferLengthBytes The length of the buffer pointed to by the
  719. * pvRxData parameter. This sets the maximum number of bytes to receive in one
  720. * call. xStreamBufferReceive will return as many bytes as possible up to a
  721. * maximum set by xBufferLengthBytes.
  722. *
  723. * @param xTicksToWait The maximum amount of time the task should remain in the
  724. * Blocked state to wait for data to become available if the stream buffer is
  725. * empty. xStreamBufferReceive() will return immediately if xTicksToWait is
  726. * zero. The block time is specified in tick periods, so the absolute time it
  727. * represents is dependent on the tick frequency. The macro pdMS_TO_TICKS() can
  728. * be used to convert a time specified in milliseconds into a time specified in
  729. * ticks. Setting xTicksToWait to portMAX_DELAY will cause the task to wait
  730. * indefinitely (without timing out), provided INCLUDE_vTaskSuspend is set to 1
  731. * in FreeRTOSConfig.h. A task does not use any CPU time when it is in the
  732. * Blocked state.
  733. *
  734. * @return The number of bytes actually read from the stream buffer, which will
  735. * be less than xBufferLengthBytes if the call to xStreamBufferReceive() timed
  736. * out before xBufferLengthBytes were available.
  737. *
  738. * Example use:
  739. * @code{c}
  740. * void vAFunction( StreamBuffer_t xStreamBuffer )
  741. * {
  742. * uint8_t ucRxData[ 20 ];
  743. * size_t xReceivedBytes;
  744. * const TickType_t xBlockTime = pdMS_TO_TICKS( 20 );
  745. *
  746. * // Receive up to another sizeof( ucRxData ) bytes from the stream buffer.
  747. * // Wait in the Blocked state (so not using any CPU processing time) for a
  748. * // maximum of 100ms for the full sizeof( ucRxData ) number of bytes to be
  749. * // available.
  750. * xReceivedBytes = xStreamBufferReceive( xStreamBuffer,
  751. * ( void * ) ucRxData,
  752. * sizeof( ucRxData ),
  753. * xBlockTime );
  754. *
  755. * if( xReceivedBytes > 0 )
  756. * {
  757. * // A ucRxData contains another xReceivedBytes bytes of data, which can
  758. * // be processed here....
  759. * }
  760. * }
  761. * @endcode
  762. * \defgroup xStreamBufferReceive xStreamBufferReceive
  763. * \ingroup StreamBufferManagement
  764. */
  765. size_t xStreamBufferReceive( StreamBufferHandle_t xStreamBuffer,
  766. void * pvRxData,
  767. size_t xBufferLengthBytes,
  768. TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
  769. /**
  770. * stream_buffer.h
  771. *
  772. * @code{c}
  773. * size_t xStreamBufferReceiveFromISR( StreamBufferHandle_t xStreamBuffer,
  774. * void *pvRxData,
  775. * size_t xBufferLengthBytes,
  776. * BaseType_t *pxHigherPriorityTaskWoken );
  777. * @endcode
  778. *
  779. * An interrupt safe version of the API function that receives bytes from a
  780. * stream buffer.
  781. *
  782. * Use xStreamBufferReceive() to read bytes from a stream buffer from a task.
  783. * Use xStreamBufferReceiveFromISR() to read bytes from a stream buffer from an
  784. * interrupt service routine (ISR).
  785. *
  786. * configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
  787. * xStreamBufferReceiveFromISR() to be available.
  788. *
  789. * @param xStreamBuffer The handle of the stream buffer from which a stream
  790. * is being received.
  791. *
  792. * @param pvRxData A pointer to the buffer into which the received bytes are
  793. * copied.
  794. *
  795. * @param xBufferLengthBytes The length of the buffer pointed to by the
  796. * pvRxData parameter. This sets the maximum number of bytes to receive in one
  797. * call. xStreamBufferReceive will return as many bytes as possible up to a
  798. * maximum set by xBufferLengthBytes.
  799. *
  800. * @param pxHigherPriorityTaskWoken It is possible that a stream buffer will
  801. * have a task blocked on it waiting for space to become available. Calling
  802. * xStreamBufferReceiveFromISR() can make space available, and so cause a task
  803. * that is waiting for space to leave the Blocked state. If calling
  804. * xStreamBufferReceiveFromISR() causes a task to leave the Blocked state, and
  805. * the unblocked task has a priority higher than the currently executing task
  806. * (the task that was interrupted), then, internally,
  807. * xStreamBufferReceiveFromISR() will set *pxHigherPriorityTaskWoken to pdTRUE.
  808. * If xStreamBufferReceiveFromISR() sets this value to pdTRUE, then normally a
  809. * context switch should be performed before the interrupt is exited. That will
  810. * ensure the interrupt returns directly to the highest priority Ready state
  811. * task. *pxHigherPriorityTaskWoken should be set to pdFALSE before it is
  812. * passed into the function. See the code example below for an example.
  813. *
  814. * @return The number of bytes read from the stream buffer, if any.
  815. *
  816. * Example use:
  817. * @code{c}
  818. * // A stream buffer that has already been created.
  819. * StreamBuffer_t xStreamBuffer;
  820. *
  821. * void vAnInterruptServiceRoutine( void )
  822. * {
  823. * uint8_t ucRxData[ 20 ];
  824. * size_t xReceivedBytes;
  825. * BaseType_t xHigherPriorityTaskWoken = pdFALSE; // Initialised to pdFALSE.
  826. *
  827. * // Receive the next stream from the stream buffer.
  828. * xReceivedBytes = xStreamBufferReceiveFromISR( xStreamBuffer,
  829. * ( void * ) ucRxData,
  830. * sizeof( ucRxData ),
  831. * &xHigherPriorityTaskWoken );
  832. *
  833. * if( xReceivedBytes > 0 )
  834. * {
  835. * // ucRxData contains xReceivedBytes read from the stream buffer.
  836. * // Process the stream here....
  837. * }
  838. *
  839. * // If xHigherPriorityTaskWoken was set to pdTRUE inside
  840. * // xStreamBufferReceiveFromISR() then a task that has a priority above the
  841. * // priority of the currently executing task was unblocked and a context
  842. * // switch should be performed to ensure the ISR returns to the unblocked
  843. * // task. In most FreeRTOS ports this is done by simply passing
  844. * // xHigherPriorityTaskWoken into portYIELD_FROM_ISR(), which will test the
  845. * // variables value, and perform the context switch if necessary. Check the
  846. * // documentation for the port in use for port specific instructions.
  847. * portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
  848. * }
  849. * @endcode
  850. * \defgroup xStreamBufferReceiveFromISR xStreamBufferReceiveFromISR
  851. * \ingroup StreamBufferManagement
  852. */
  853. size_t xStreamBufferReceiveFromISR( StreamBufferHandle_t xStreamBuffer,
  854. void * pvRxData,
  855. size_t xBufferLengthBytes,
  856. BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
  857. /**
  858. * stream_buffer.h
  859. *
  860. * @code{c}
  861. * void vStreamBufferDelete( StreamBufferHandle_t xStreamBuffer );
  862. * @endcode
  863. *
  864. * Deletes a stream buffer that was previously created using a call to
  865. * xStreamBufferCreate() or xStreamBufferCreateStatic(). If the stream
  866. * buffer was created using dynamic memory (that is, by xStreamBufferCreate()),
  867. * then the allocated memory is freed.
  868. *
  869. * A stream buffer handle must not be used after the stream buffer has been
  870. * deleted.
  871. *
  872. * configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
  873. * vStreamBufferDelete() to be available.
  874. *
  875. * @param xStreamBuffer The handle of the stream buffer to be deleted.
  876. *
  877. * \defgroup vStreamBufferDelete vStreamBufferDelete
  878. * \ingroup StreamBufferManagement
  879. */
  880. void vStreamBufferDelete( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
  881. /**
  882. * stream_buffer.h
  883. *
  884. * @code{c}
  885. * BaseType_t xStreamBufferIsFull( StreamBufferHandle_t xStreamBuffer );
  886. * @endcode
  887. *
  888. * Queries a stream buffer to see if it is full. A stream buffer is full if it
  889. * does not have any free space, and therefore cannot accept any more data.
  890. *
  891. * configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
  892. * xStreamBufferIsFull() to be available.
  893. *
  894. * @param xStreamBuffer The handle of the stream buffer being queried.
  895. *
  896. * @return If the stream buffer is full then pdTRUE is returned. Otherwise
  897. * pdFALSE is returned.
  898. *
  899. * \defgroup xStreamBufferIsFull xStreamBufferIsFull
  900. * \ingroup StreamBufferManagement
  901. */
  902. BaseType_t xStreamBufferIsFull( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
  903. /**
  904. * stream_buffer.h
  905. *
  906. * @code{c}
  907. * BaseType_t xStreamBufferIsEmpty( StreamBufferHandle_t xStreamBuffer );
  908. * @endcode
  909. *
  910. * Queries a stream buffer to see if it is empty. A stream buffer is empty if
  911. * it does not contain any data.
  912. *
  913. * configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
  914. * xStreamBufferIsEmpty() to be available.
  915. *
  916. * @param xStreamBuffer The handle of the stream buffer being queried.
  917. *
  918. * @return If the stream buffer is empty then pdTRUE is returned. Otherwise
  919. * pdFALSE is returned.
  920. *
  921. * \defgroup xStreamBufferIsEmpty xStreamBufferIsEmpty
  922. * \ingroup StreamBufferManagement
  923. */
  924. BaseType_t xStreamBufferIsEmpty( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
  925. /**
  926. * stream_buffer.h
  927. *
  928. * @code{c}
  929. * BaseType_t xStreamBufferReset( StreamBufferHandle_t xStreamBuffer );
  930. * @endcode
  931. *
  932. * Resets a stream buffer to its initial, empty, state. Any data that was in
  933. * the stream buffer is discarded. A stream buffer can only be reset if there
  934. * are no tasks blocked waiting to either send to or receive from the stream
  935. * buffer.
  936. *
  937. * Use xStreamBufferReset() to reset a stream buffer from a task.
  938. * Use xStreamBufferResetFromISR() to reset a stream buffer from an
  939. * interrupt service routine (ISR).
  940. *
  941. * configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
  942. * xStreamBufferReset() to be available.
  943. *
  944. * @param xStreamBuffer The handle of the stream buffer being reset.
  945. *
  946. * @return If the stream buffer is reset then pdPASS is returned. If there was
  947. * a task blocked waiting to send to or read from the stream buffer then the
  948. * stream buffer is not reset and pdFAIL is returned.
  949. *
  950. * \defgroup xStreamBufferReset xStreamBufferReset
  951. * \ingroup StreamBufferManagement
  952. */
  953. BaseType_t xStreamBufferReset( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
  954. /**
  955. * stream_buffer.h
  956. *
  957. * @code{c}
  958. * BaseType_t xStreamBufferResetFromISR( StreamBufferHandle_t xStreamBuffer );
  959. * @endcode
  960. *
  961. * An interrupt safe version of the API function that resets the stream buffer.
  962. *
  963. * Resets a stream buffer to its initial, empty, state. Any data that was in
  964. * the stream buffer is discarded. A stream buffer can only be reset if there
  965. * are no tasks blocked waiting to either send to or receive from the stream
  966. * buffer.
  967. *
  968. * Use xStreamBufferReset() to reset a stream buffer from a task.
  969. * Use xStreamBufferResetFromISR() to reset a stream buffer from an
  970. * interrupt service routine (ISR).
  971. *
  972. * configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
  973. * xStreamBufferResetFromISR() to be available.
  974. *
  975. * @param xStreamBuffer The handle of the stream buffer being reset.
  976. *
  977. * @return If the stream buffer is reset then pdPASS is returned. If there was
  978. * a task blocked waiting to send to or read from the stream buffer then the
  979. * stream buffer is not reset and pdFAIL is returned.
  980. *
  981. * \defgroup xStreamBufferResetFromISR xStreamBufferResetFromISR
  982. * \ingroup StreamBufferManagement
  983. */
  984. BaseType_t xStreamBufferResetFromISR( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
  985. /**
  986. * stream_buffer.h
  987. *
  988. * @code{c}
  989. * size_t xStreamBufferSpacesAvailable( StreamBufferHandle_t xStreamBuffer );
  990. * @endcode
  991. *
  992. * Queries a stream buffer to see how much free space it contains, which is
  993. * equal to the amount of data that can be sent to the stream buffer before it
  994. * is full.
  995. *
  996. * configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
  997. * xStreamBufferSpacesAvailable() to be available.
  998. *
  999. * @param xStreamBuffer The handle of the stream buffer being queried.
  1000. *
  1001. * @return The number of bytes that can be written to the stream buffer before
  1002. * the stream buffer would be full.
  1003. *
  1004. * \defgroup xStreamBufferSpacesAvailable xStreamBufferSpacesAvailable
  1005. * \ingroup StreamBufferManagement
  1006. */
  1007. size_t xStreamBufferSpacesAvailable( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
  1008. /**
  1009. * stream_buffer.h
  1010. *
  1011. * @code{c}
  1012. * size_t xStreamBufferBytesAvailable( StreamBufferHandle_t xStreamBuffer );
  1013. * @endcode
  1014. *
  1015. * Queries a stream buffer to see how much data it contains, which is equal to
  1016. * the number of bytes that can be read from the stream buffer before the stream
  1017. * buffer would be empty.
  1018. *
  1019. * configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
  1020. * xStreamBufferBytesAvailable() to be available.
  1021. *
  1022. * @param xStreamBuffer The handle of the stream buffer being queried.
  1023. *
  1024. * @return The number of bytes that can be read from the stream buffer before
  1025. * the stream buffer would be empty.
  1026. *
  1027. * \defgroup xStreamBufferBytesAvailable xStreamBufferBytesAvailable
  1028. * \ingroup StreamBufferManagement
  1029. */
  1030. size_t xStreamBufferBytesAvailable( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
  1031. /**
  1032. * stream_buffer.h
  1033. *
  1034. * @code{c}
  1035. * BaseType_t xStreamBufferSetTriggerLevel( StreamBufferHandle_t xStreamBuffer, size_t xTriggerLevel );
  1036. * @endcode
  1037. *
  1038. * A stream buffer's trigger level is the number of bytes that must be in the
  1039. * stream buffer before a task that is blocked on the stream buffer to
  1040. * wait for data is moved out of the blocked state. For example, if a task is
  1041. * blocked on a read of an empty stream buffer that has a trigger level of 1
  1042. * then the task will be unblocked when a single byte is written to the buffer
  1043. * or the task's block time expires. As another example, if a task is blocked
  1044. * on a read of an empty stream buffer that has a trigger level of 10 then the
  1045. * task will not be unblocked until the stream buffer contains at least 10 bytes
  1046. * or the task's block time expires. If a reading task's block time expires
  1047. * before the trigger level is reached then the task will still receive however
  1048. * many bytes are actually available. Setting a trigger level of 0 will result
  1049. * in a trigger level of 1 being used. It is not valid to specify a trigger
  1050. * level that is greater than the buffer size.
  1051. *
  1052. * A trigger level is set when the stream buffer is created, and can be modified
  1053. * using xStreamBufferSetTriggerLevel().
  1054. *
  1055. * configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
  1056. * xStreamBufferSetTriggerLevel() to be available.
  1057. *
  1058. * @param xStreamBuffer The handle of the stream buffer being updated.
  1059. *
  1060. * @param xTriggerLevel The new trigger level for the stream buffer.
  1061. *
  1062. * @return If xTriggerLevel was less than or equal to the stream buffer's length
  1063. * then the trigger level will be updated and pdTRUE is returned. Otherwise
  1064. * pdFALSE is returned.
  1065. *
  1066. * \defgroup xStreamBufferSetTriggerLevel xStreamBufferSetTriggerLevel
  1067. * \ingroup StreamBufferManagement
  1068. */
  1069. BaseType_t xStreamBufferSetTriggerLevel( StreamBufferHandle_t xStreamBuffer,
  1070. size_t xTriggerLevel ) PRIVILEGED_FUNCTION;
  1071. /**
  1072. * stream_buffer.h
  1073. *
  1074. * @code{c}
  1075. * BaseType_t xStreamBufferSendCompletedFromISR( StreamBufferHandle_t xStreamBuffer, BaseType_t *pxHigherPriorityTaskWoken );
  1076. * @endcode
  1077. *
  1078. * For advanced users only.
  1079. *
  1080. * The sbSEND_COMPLETED() macro is called from within the FreeRTOS APIs when
  1081. * data is sent to a message buffer or stream buffer. If there was a task that
  1082. * was blocked on the message or stream buffer waiting for data to arrive then
  1083. * the sbSEND_COMPLETED() macro sends a notification to the task to remove it
  1084. * from the Blocked state. xStreamBufferSendCompletedFromISR() does the same
  1085. * thing. It is provided to enable application writers to implement their own
  1086. * version of sbSEND_COMPLETED(), and MUST NOT BE USED AT ANY OTHER TIME.
  1087. *
  1088. * See the example implemented in FreeRTOS/Demo/Minimal/MessageBufferAMP.c for
  1089. * additional information.
  1090. *
  1091. * configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
  1092. * xStreamBufferSendCompletedFromISR() to be available.
  1093. *
  1094. * @param xStreamBuffer The handle of the stream buffer to which data was
  1095. * written.
  1096. *
  1097. * @param pxHigherPriorityTaskWoken *pxHigherPriorityTaskWoken should be
  1098. * initialised to pdFALSE before it is passed into
  1099. * xStreamBufferSendCompletedFromISR(). If calling
  1100. * xStreamBufferSendCompletedFromISR() removes a task from the Blocked state,
  1101. * and the task has a priority above the priority of the currently running task,
  1102. * then *pxHigherPriorityTaskWoken will get set to pdTRUE indicating that a
  1103. * context switch should be performed before exiting the ISR.
  1104. *
  1105. * @return If a task was removed from the Blocked state then pdTRUE is returned.
  1106. * Otherwise pdFALSE is returned.
  1107. *
  1108. * \defgroup xStreamBufferSendCompletedFromISR xStreamBufferSendCompletedFromISR
  1109. * \ingroup StreamBufferManagement
  1110. */
  1111. BaseType_t xStreamBufferSendCompletedFromISR( StreamBufferHandle_t xStreamBuffer,
  1112. BaseType_t * pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
  1113. /**
  1114. * stream_buffer.h
  1115. *
  1116. * @code{c}
  1117. * BaseType_t xStreamBufferReceiveCompletedFromISR( StreamBufferHandle_t xStreamBuffer, BaseType_t *pxHigherPriorityTaskWoken );
  1118. * @endcode
  1119. *
  1120. * For advanced users only.
  1121. *
  1122. * The sbRECEIVE_COMPLETED() macro is called from within the FreeRTOS APIs when
  1123. * data is read out of a message buffer or stream buffer. If there was a task
  1124. * that was blocked on the message or stream buffer waiting for data to arrive
  1125. * then the sbRECEIVE_COMPLETED() macro sends a notification to the task to
  1126. * remove it from the Blocked state. xStreamBufferReceiveCompletedFromISR()
  1127. * does the same thing. It is provided to enable application writers to
  1128. * implement their own version of sbRECEIVE_COMPLETED(), and MUST NOT BE USED AT
  1129. * ANY OTHER TIME.
  1130. *
  1131. * See the example implemented in FreeRTOS/Demo/Minimal/MessageBufferAMP.c for
  1132. * additional information.
  1133. *
  1134. * configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
  1135. * xStreamBufferReceiveCompletedFromISR() to be available.
  1136. *
  1137. * @param xStreamBuffer The handle of the stream buffer from which data was
  1138. * read.
  1139. *
  1140. * @param pxHigherPriorityTaskWoken *pxHigherPriorityTaskWoken should be
  1141. * initialised to pdFALSE before it is passed into
  1142. * xStreamBufferReceiveCompletedFromISR(). If calling
  1143. * xStreamBufferReceiveCompletedFromISR() removes a task from the Blocked state,
  1144. * and the task has a priority above the priority of the currently running task,
  1145. * then *pxHigherPriorityTaskWoken will get set to pdTRUE indicating that a
  1146. * context switch should be performed before exiting the ISR.
  1147. *
  1148. * @return If a task was removed from the Blocked state then pdTRUE is returned.
  1149. * Otherwise pdFALSE is returned.
  1150. *
  1151. * \defgroup xStreamBufferReceiveCompletedFromISR xStreamBufferReceiveCompletedFromISR
  1152. * \ingroup StreamBufferManagement
  1153. */
  1154. BaseType_t xStreamBufferReceiveCompletedFromISR( StreamBufferHandle_t xStreamBuffer,
  1155. BaseType_t * pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
  1156. /**
  1157. * stream_buffer.h
  1158. *
  1159. * @code{c}
  1160. * UBaseType_t uxStreamBufferGetStreamBufferNotificationIndex( StreamBufferHandle_t xStreamBuffer );
  1161. * @endcode
  1162. *
  1163. * Get the task notification index used for the supplied stream buffer which can
  1164. * be set using vStreamBufferSetStreamBufferNotificationIndex. If the task
  1165. * notification index for the stream buffer is not changed using
  1166. * vStreamBufferSetStreamBufferNotificationIndex, this function returns the
  1167. * default value (tskDEFAULT_INDEX_TO_NOTIFY).
  1168. *
  1169. * configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
  1170. * uxStreamBufferGetStreamBufferNotificationIndex() to be available.
  1171. *
  1172. * @param xStreamBuffer The handle of the stream buffer for which the task
  1173. * notification index is retrieved.
  1174. *
  1175. * @return The task notification index for the stream buffer.
  1176. *
  1177. * \defgroup uxStreamBufferGetStreamBufferNotificationIndex uxStreamBufferGetStreamBufferNotificationIndex
  1178. * \ingroup StreamBufferManagement
  1179. */
  1180. UBaseType_t uxStreamBufferGetStreamBufferNotificationIndex( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
  1181. /**
  1182. * stream_buffer.h
  1183. *
  1184. * @code{c}
  1185. * void vStreamBufferSetStreamBufferNotificationIndex ( StreamBuffer_t xStreamBuffer, UBaseType_t uxNotificationIndex );
  1186. * @endcode
  1187. *
  1188. * Set the task notification index used for the supplied stream buffer.
  1189. * Successive calls to stream buffer APIs (like xStreamBufferSend or
  1190. * xStreamBufferReceive) for this stream buffer will use this new index for
  1191. * their task notifications.
  1192. *
  1193. * If this function is not called, the default index (tskDEFAULT_INDEX_TO_NOTIFY)
  1194. * is used for task notifications. It is recommended to call this function
  1195. * before attempting to send or receive data from the stream buffer to avoid
  1196. * inconsistencies.
  1197. *
  1198. * configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
  1199. * vStreamBufferSetStreamBufferNotificationIndex() to be available.
  1200. *
  1201. * @param xStreamBuffer The handle of the stream buffer for which the task
  1202. * notification index is set.
  1203. *
  1204. * @param uxNotificationIndex The task notification index to set.
  1205. *
  1206. * \defgroup vStreamBufferSetStreamBufferNotificationIndex vStreamBufferSetStreamBufferNotificationIndex
  1207. * \ingroup StreamBufferManagement
  1208. */
  1209. void vStreamBufferSetStreamBufferNotificationIndex( StreamBufferHandle_t xStreamBuffer,
  1210. UBaseType_t uxNotificationIndex ) PRIVILEGED_FUNCTION;
  1211. /* Functions below here are not part of the public API. */
  1212. StreamBufferHandle_t xStreamBufferGenericCreate( size_t xBufferSizeBytes,
  1213. size_t xTriggerLevelBytes,
  1214. BaseType_t xStreamBufferType,
  1215. StreamBufferCallbackFunction_t pxSendCompletedCallback,
  1216. StreamBufferCallbackFunction_t pxReceiveCompletedCallback ) PRIVILEGED_FUNCTION;
  1217. #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  1218. StreamBufferHandle_t xStreamBufferGenericCreateStatic( size_t xBufferSizeBytes,
  1219. size_t xTriggerLevelBytes,
  1220. BaseType_t xStreamBufferType,
  1221. uint8_t * const pucStreamBufferStorageArea,
  1222. StaticStreamBuffer_t * const pxStaticStreamBuffer,
  1223. StreamBufferCallbackFunction_t pxSendCompletedCallback,
  1224. StreamBufferCallbackFunction_t pxReceiveCompletedCallback ) PRIVILEGED_FUNCTION;
  1225. #endif
  1226. size_t xStreamBufferNextMessageLengthBytes( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
  1227. #if ( configUSE_TRACE_FACILITY == 1 )
  1228. void vStreamBufferSetStreamBufferNumber( StreamBufferHandle_t xStreamBuffer,
  1229. UBaseType_t uxStreamBufferNumber ) PRIVILEGED_FUNCTION;
  1230. UBaseType_t uxStreamBufferGetStreamBufferNumber( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
  1231. uint8_t ucStreamBufferGetStreamBufferType( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
  1232. #endif
  1233. /* *INDENT-OFF* */
  1234. #if defined( __cplusplus )
  1235. }
  1236. #endif
  1237. /* *INDENT-ON* */
  1238. #endif /* !defined( STREAM_BUFFER_H ) */