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