MPLABĀ® Harmony Graphics Suite  GFX v3.13.0
Legato API Documentation
legato_stream.h
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright (C) 2020 Microchip Technology Inc. and its subsidiaries.
3 *
4 * Subject to your compliance with these terms, you may use Microchip software
5 * and any derivatives exclusively with Microchip products. It is your
6 * responsibility to comply with third party license terms applicable to your
7 * use of third party software (including open source software) that may
8 * accompany Microchip software.
9 *
10 * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
11 * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
12 * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
13 * PARTICULAR PURPOSE.
14 *
15 * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
16 * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
17 * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
18 * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
19 * FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
20 * ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
21 * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
22 *******************************************************************************/
29 #ifndef LE_STREAM_H
30 #define LE_STREAM_H
31 
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 // *****************************************************************************
39 /* Structure:
40  leStreamDescriptor
41 
42  Summary:
43  Defines a common header for all stream operations.
44 
45  Description:
46  dataLocation - indicates the location of the data. 0 is always
47  internal flash. any other number must be understood
48  by the application
49 
50  dataAddress - the address at which the data resides. may be a local pointer
51  or a location in some external storage location not in the
52  local memory map.
53 
54  dataSize - the size of the data in bytes
55 */
60 typedef struct leStreamDescriptor
61 {
62  uint32_t location;
63  void* address;
64  uint32_t size;
66 
71 #define LE_STREAM_LOCATION_ID_INTERNAL 0
72 
77 #if LE_STREAMING_ENABLED == 1
78 
79 // *****************************************************************************
80 /* enum:
81  leStreamState
82 
83  Summary:
84  Enumerates stream state machine states.
85 
86  LE_STREAM_CLOSED - stream isn't currently open
87  LE_STREAM_READY - stream is ready to fetch data
88  LE_STREAM_WAITING - stream is waiting for a memory operation to complete
89  LE_STREAM_DATAREADY - stream has data ready for use
90  LE_STREAM_ERROR - stream encountered an unrecoverable error
91 */
92 typedef enum leStreamState
93 {
94  LE_STREAM_CLOSED = 1 << 0,
95  LE_STREAM_READY = 1 << 1,
96  LE_STREAM_WAITING = 1 << 2,
97  LE_STREAM_DATAREADY = 1 << 3,
98  LE_STREAM_ERROR = 1 << 4,
99 } leStreamState;
100 
101 struct leStream;
102 
103 typedef void (*leStream_DataReadyCallback)(struct leStream* strm);
104 
105 // *****************************************************************************
106 /* Structure:
107  enum leStreamFlag
108 
109  Summary:
110  Defines the base description of an stream reader. Specific reader
111  implementations will build on this foundation for each decoder type.
112 
113  Description:
114  SF_NONE - no flags
115 
116  SF_BLOCKING - indicates that this stream can operate in blocking mode
117  this method is much faster than non-blocking as it can
118  stream data without having to self-preempt
119 */
120 
121 enum leStreamFlag
122 {
123  SF_NONE = 0,
124  SF_BLOCKING = 1 << 0
125 };
126 
127 // *****************************************************************************
128 /* Structure:
129  struct leStream
130 
131  Summary:
132  Defines the base description of an stream reader. Specific reader
133  implementations will build on this foundation for each decoder type.
134 
135  Description:
136  data - the data being streamed
137 
138  status - the overall status of the stream state machine
139 
140  dataReady - signals that the requested data is ready. if NULL then the stream
141  is a blocking-type stream and cannot preempt itself
142 
143  flags - configuration flags for the stream
144 
145  userData - any kind of user or application data attached to this reader
146 
147 */
148 typedef struct leStream
149 {
150  const leStreamDescriptor* desc;
151 
152  enum leStreamState state;
153 
154  int32_t result;
155 
156  struct
157  {
158  uint32_t size;
159  uint8_t* buf;
160  leStream_DataReadyCallback dataReadyCB;
161  } readRequest;
162 
163  struct
164  {
165  uint32_t physicalSize;
166  uint32_t baseAddress;
167  uint32_t logicalSize;
168  uint8_t* ptr;
169  } cache;
170 
171  enum leStreamFlag flags;
172 
173  void* userData;
174 } leStream;
175 
176 // *****************************************************************************
177 /* Function:
178  void leStream_Init(leStream* stream,
179  const leStreamDescriptor* desc,
180  uint32_t cacheSize,
181  uint8_t* cacheBuf,
182  void* userData)
183 
184  Summary:
185  Initialize a stream object
186 
187  Description:
188  A stream object is a construct that is capable of making external data
189  read requests to the application. It is responsible for opening, reading
190  from, and closing an external device to the standard application data
191  streaming interface.
192 
193  It can also be configured to manage a local data cache for faster
194  data streaming speed.
195 
196  Parameters:
197  leStream* stream - the stream struct to initialize
198  const leStreamDescriptor* desc - the stream descriptor to read from
199  uint32_t cacheSize - the size of the cache being passed in
200  uint8_t* cacheBuf - a buffer to use as a local cache
201  void* userData - a user data pointer for general purpose use
202 
203  Returns:
204 
205 
206  Remarks:
207 
208 */
209 void leStream_Init(leStream* stream,
210  const leStreamDescriptor* desc,
211  uint32_t cacheSize,
212  uint8_t* cacheBuf,
213  void* userData);
214 
215 // *****************************************************************************
216 /* Function:
217  void leStream_Open(leStream* stream)
218 
219  Summary:
220  Opens a stream object
221 
222  Description:
223  Instructs the stream object to attempt to open the data source through the
224  leApplication_MediaOpenRequest API.
225 
226  Parameters:
227  leStream* stream - the stream to open
228 
229  Returns:
230 
231 
232  Remarks:
233 
234 */
235 leResult leStream_Open(leStream* stream);
236 
237 // *****************************************************************************
238 /* Function:
239  void leStream_IsOpen(leStream* stream)
240 
241  Summary:
242  Tests a stream to see if it is open
243 
244  Description:
245  Tests a stream to see if it is open
246 
247  Parameters:
248  leStream* stream - the stream to test
249 
250  Returns:
251  leBool - true if open
252 
253  Remarks:
254 
255 */
256 leBool leStream_IsOpen(leStream* stream);
257 
258 // *****************************************************************************
259 /* Function:
260  leResult leStream_Read(leStream* stream,
261  size_t addr,
262  uint32_t size,
263  uint8_t* buf,
264  leStream_DataReadyCallback cb)
265 
266  Summary:
267  Read from a stream object.
268 
269  Description:
270  Instructs a stream object to attempt to read from its data source using the
271  leApplication_MediaReadRequest API.
272 
273  Parameters:
274  leStream* stream - the stream to read from
275  size_t addr - the address to read from
276  uint32_t size - the size to read
277  uint8_t* buf - the destination buffer to read to
278  leStream_DataReadyCallback cb - a callback to indicate that the data is ready
279 
280 
281  Returns:
282 
283 
284  Remarks:
285 
286 */
287 leResult leStream_Read(leStream* stream,
288  size_t addr,
289  uint32_t size,
290  uint8_t* buf,
291  leStream_DataReadyCallback cb);
292 
293 // *****************************************************************************
294 /* Function:
295  leBool leStream_IsBlocking(leStream* stream)
296 
297  Summary:
298  Indicates of this stream is capable of operating in blocking mode.
299 
300  Description:
301  Indicates of this stream is capable of operating in blocking mode.
302 
303  Parameters:
304  leStream* stream - the stream to query
305 
306  Returns:
307  leBool - LE_TRUE if the stream can block
308 
309  Remarks:
310 
311 */
312 leBool leStream_IsBlocking(leStream* stream);
313 
314 // *****************************************************************************
315 /* Function:
316  leBool leStream_IsDataReady(leStream* stream)
317 
318  Summary:
319  Polls the state of the stream to see if the data request is read. Used
320  if a data ready callback was not provided.
321 
322  Description:
323  Polls the state of the stream to see if the data request is read. Used
324  if a data ready callback was not provided.
325 
326  Parameters:
327  leStream* stream - the stream to poll
328 
329  Returns:
330  leBool - LE_TRUE if the stream data is ready
331 
332  Remarks:
333 
334 */
335 leBool leStream_IsDataReady(leStream* stream);
336 
337 // *****************************************************************************
338 /* Function:
339  leResult leStream_DataReady(leStream* stream)
340 
341  Summary:
342  Notifies a stream that its data is ready.
343 
344  Description:
345  Notifies a stream that its data is ready. Call after filling the stream's
346  destination buffer to the requested size.
347 
348  Parameters:
349  leStream* stream - the stream to notify
350 
351  Returns:
352 
353  Remarks:
354 
355 */
356 leResult leStream_DataReady(leStream* stream);
357 
358 // *****************************************************************************
359 /* Function:
360  leResult leStream_Close(leStream* stream)
361 
362  Summary:
363  Closes a stream.
364 
365  Description:
366  Closes a stream. The stream will call the leApplication_MediaCloseRequest
367  API to close any open data sources. If multiple streams use the same data
368  source then it is up to the application to determine when all streams are
369  finished with source. The use of a reference counter is advised.
370 
371  Parameters:
372  leStream* stream - the stream to close
373 
374  Returns:
375 
376  Remarks:
377 
378 */
379 leResult leStream_Close(leStream* stream);
380 
381 // *****************************************************************************
382 /* Structure:
383  struct leStreamManager
384 
385  Summary:
386  A common interface for a manager object that is capable of managing a stream
387  object.
388 
389  Description:
390  A manager object that is capable of managing a stream object. Stream
391  managers will typically manage the streaming and decoding of some kind
392  of file format
393 
394  exec - function that runs the stream manager
395  isDone - function that queries if the stream manager is finished
396  abort - function that aborts the stream manager
397 
398  onDone - a callback that is called when the stream manager is finished
399  void* userData - general purpose data storage
400 
401 */
402 typedef struct leStreamManager
403 {
404  leResult (*exec)(struct leStreamManager* mgr);
405  leBool (*isDone)(struct leStreamManager* mgr);
406  void (*abort)(struct leStreamManager* mgr);
407  void (*cleanup)(struct leStreamManager* mgr);
408 
409  void (*onDone)(struct leStreamManager* mgr);
410  void* userData;
411 } leStreamManager;
412 
413 
414 
415 // *****************************************************************************
416 /* typedef:
417  leApplication_MediaOpenRequest
418 
419  Summary:
420  A callback that indicates that a stream wishes to read from an external
421  source and that the application should prepare that source.
422 
423  If the result is false then the stream will abort.
424 
425  stream - the reader that is requesting to stream data
426 */
427 leResult leApplication_MediaOpenRequest(leStream* stream);
428 
429 // *****************************************************************************
430 /* typedef:
431  leMemoryReadRequest_FnPtr
432 
433  Summary:
434  A memory read request function is a request that is issued by anything that
435  needs external support to access data that is stored in some external
436  location. For instance, an image may be stored in an SPI memory chip.
437  A JPEG decoder has no knowledge of what SPI is. This read request is issued
438  to the application so that the application can then assume responsibility for
439  communication with the peripherial to retrieve the data.
440 
441  From the reader the handler can determine which asset is being decoded and
442  which media it resides in.
443 
444  stream - the stream requesting the media data
445  address - the requested source address
446  size - the requested data size
447  buf - the destination data address
448 
449  The application servicing the request should call leStream_DataReady
450  when it has finished streaming from the peripheral.
451 */
452 leResult leApplication_MediaReadRequest(leStream* stream, // stream reader
453  uint32_t address, // address
454  uint32_t size, // dest size
455  uint8_t* buf); // dest buffer);
456 
457 // *****************************************************************************
458 /* typedef:
459  leMediaCloseRequest_FnPtr
460 
461  Summary:
462  A callback that indicates that a stream is finished with a given
463  media location and that the application can close if it.
464 
465  reader - the reader that was streaming data.
466 */
467 void leApplication_MediaCloseRequest(leStream* stream);
468 
469 
470 #endif /* LE_STREAMING_ENABLED */
471 
477 #ifdef __cplusplus
478 }
479 #endif
480 
481 #endif /* LE_STREAM_H */
Common macros and definitions used by Legato.
void * address
Definition: legato_stream.h:63
struct leStreamDescriptor leStreamDescriptor
This struct represents a stream descriptor.
uint32_t location
Definition: legato_stream.h:62
leResult
This enum represents function call results.
Definition: legato_common.h:123
This struct represents a stream descriptor.
Definition: legato_stream.h:60
uint32_t size
Definition: legato_stream.h:64
leBool
This enum represents booleans.
Definition: legato_common.h:146