Presentation is loading. Please wait.

Presentation is loading. Please wait.

TI BIOS SIO – Data Streaming 7 November 2018 Dr. Veton Këpuska.

Similar presentations


Presentation on theme: "TI BIOS SIO – Data Streaming 7 November 2018 Dr. Veton Këpuska."— Presentation transcript:

1 TI BIOS SIO – Data Streaming 7 November 2018 Dr. Veton Këpuska

2 Introduction In this chapter a technique to exchange buffers of data between input/output devices and processing threads will be considered. The BIOS ‘stream’ interface will be seen to provide a universal interface between I/O and processing threads, making coding easier and more easily reused. 7 November 2018 Dr. Veton Këpuska

3 1 2 3 4 5 6 Objectives Describe the concept of BIOS streams
List the key stream API 2 Adapt a Task to use stream interfacing 3 Describe the benefits of multi-buffer streams 4 Set up a stream via the configuration tool 5 Describe how stream can interface to SWI 6 7 November 2018 Dr. Veton Këpuska 2

4 1 2 3 4 5 6 7 Stream Topics Stream Concepts Stream API
TSK with SIO Coding 3 Double Buffered Streams 4 Stream Configuration 5 Review 6 Lab 7 7 November 2018 Dr. Veton Këpuska 3

5 1 2 3 4 5 6 7 Stream Concepts Stream Concepts Stream API
TSK with SIO Coding 3 Double Buffered Streams 4 Stream Configuration 5 Review 6 Lab 7 7 November 2018 Dr. Veton Këpuska 3

6 Stream Concepts 7 November 2018 Dr. Veton Këpuska

7 Why Not Use Direct Pointer Passing?
SWI or TSK HWI pBuf1 Problems with direct pointer passing: Adaptability: changes are within the threads both driver and process need to be adapted time consuming ownership of both code sets? opportunity to introduce errors 7 November 2018 Dr. Veton Këpuska

8 Why Not Use Direct Pointer Passing?
Preferred: Insulation between threads Independent authorship Increased and more direct reuse Limits scope of required knowledge 7 November 2018 Dr. Veton Këpuska

9 Standardized IO Interface Benefits
SWI or TSK HWI pBuf1 pBuf1 Proposal: Standardized interface between IO and Process IO’s write to generic interface Process assumes the generic interface as data source/sink Each can be written independently of the other Maximized reuse – all I, P, O authors write to the same interface Major Bonus: Make interface a system integration control point Allows late-stage selection of interface properties Size of buffers Number of buffers Which memories buffers reside in Key: Larger systems need to separate component authoring details from system integration adjustments 7 November 2018 Dr. Veton Këpuska

10 SIO Concepts IOM HWI SIO SIO_issue() process buffer... SIO_reclaim()
pBufx pBufx HWI SIO pBufx pBufx 7 November 2018 Dr. Veton Këpuska

11 SIO Concepts How is all this done?
IOM pBufx pBufx SIO_reclaim() process buffer... SIO_issue() HWI SIO pBufx pBufx How is all this done? IO author will ‘wrap’ the basic HWI with code to i/f to the ‘stream’ (Driver details are in chapter 14) TSK controls and ‘owns’ the stream via SIO API TSK usually ‘owns’ the memory blocks passed between TSK and IOM TSK will ‘issue’ a block to the stream to begin data activity Issue to an input device is usually of an ‘empty’ buffer to be filled Issue to output device is usually ‘full’ buffer to be consumed TSK will ‘reclaim’ the issued buffer to: read new input data or obtain ‘used’ output buffer to write new data into Stream will block the TSK on reclaim if no buffer currently available Stream unblocks TSK when data buffer becomes available 7 November 2018 Dr. Veton Këpuska

12 SIO Tactical Benefits IOM pBufx pBufx SIO_reclaim() process buffer... SIO_issue() HWI SIO pBufx pBufx Stream API are part of BIOS and streams are managed by BIOS, so the user obtains this infrastructure with no coding effort on their part Stream ‘decouples’ the hard real-time nature of the IOM from the TSK Stream synchronizes TSK to IOM via SIO_reclaim being a blocking call Stream can maintain any desired number of buffers specified Data block size can be whatever is desired/needed TSK and IOM can be written to obtain these parameters from the SIO Therefore – system integrators can use the specification of the stream properties to perform late-stage system tuning – adapting the number and size of buffers to optimize the performance of the TSK & IOM without changing any of the internal code of the TSK or IOM! SIO can be created dynamically, so this ‘tuning’ can even be performed as the DSP runs! 7 November 2018 Dr. Veton Këpuska

13 SIO Concepts IOM Packet Input IOM Task Output IOM SIO SIO issue issue
MY_DSP_algo reclaim reclaim IOM Packet prev {QUE_Elem} next Ptr addr Uns size Arg misc Arg arg Uns cmd Int status 7 November 2018 Dr. Veton Këpuska

14 SIO Concepts Summary Common I/O interface: between Tasks and Devices
Universal interface to I/O devices Yields improved code maintenance and portability Number of buffers and buffer size are user selectable Unidirectional: streams are input or output - not both Efficiency: uses pointer exchange instead of buffer copy SIO_issue passes an “IOM Packet” buffer descriptor to device (DEV) via stream SIO_reclaim waits for an IOM Packet to be returned by the DEV via stream Abstraction: TSK author is insulated from device-specific functionality BIOS manages two QUEues (todevice & fromdevice) Driver author signals TSK buffer is ready via SEM 7 November 2018 Dr. Veton Këpuska

15 SIO Concepts Summary Asynchronous: TSK and DEV activity is independent, synch’d by buffer passes Buffers: Data buffers must be created - by config tool or TSK 7 November 2018 Dr. Veton Këpuska

16 1 2 3 4 5 6 7 Stream API Stream Concepts Stream API
TSK with SIO Coding 3 Double Buffered Streams 4 Stream Configuration 5 Review 6 Lab 7 7 November 2018 Dr. Veton Këpuska 3

17 SIO API 7 November 2018 Dr. Veton Këpuska

18 Buffer Passing: SIO_issue() & SIO_reclaim()
status = SIO_issue(hStream, pBuf, uSize, arg); uSize = SIO_reclaim(hStream, &pBuf, pArg); SIO_issue() and SIO_reclaim() are the key stream API for exchanging buffers with IOM via the stream interface. SIO_issue() places a buffer in the stream SIO_reclaim() requests a buffer from the stream 7 November 2018 Dr. Veton Këpuska

19 Buffer Passing: SIO_issue() & SIO_reclaim()
Note: if no buffers are already available in the stream, this call can block until a buffer is made available from the IOM Never attempt a reclaim prior to issuing buffer(s) into the stream first *pBuf is where SIO_reclaim writes the address of the buffer returned. 7 November 2018 Dr. Veton Këpuska

20 Buffer Passing: SIO_issue() & SIO_reclaim()
type param usage Int status report of success/failure of operation uSize # of used values in block - in nmadus (error = -) SIO_Handle hStream handle to stream obj Ptr pBuf pointer to buffer being stream transferred Arg arg uncommitted gen’l purpose user argument 7 November 2018 Dr. Veton Këpuska

21 Buffer Declaration/ Creation Options
A variety of methods are available for obtaining buffers for use in streams The table below compares the most common methods by Globals, Statics TSK Locals SIO_staticbuf() Dynamic Allocation malloc(), MEM_alloc(), etc Setup Speed Fastest No setup cycle time Fast- Uses few cycles; Is deterministic Consumes significant cycles to setup, not deterministic RAM Re-use Not possible without specific planning RAM is easily returned to system for reuse SIO Property Tracking Manual – buffer properties not derived from SIO properties Buffer properties are specified by SIO properties Buffer properties can track stream properties via SIO_create arguments Ease of routing an SIO’s buffers to a particular HW RAM Requires use of pragma statements and linker routing Each SIO’s buffers can come from any available HW RAM Each SIO’s buffers can come from any available HW RAM containing a heap section 7 November 2018 Dr. Veton Këpuska

22 Heap Data-Structure Tutorial 7 November 2018 Dr. Veton Këpuska

23 Heap Data-Structure The Heap data-structure consists of the data (e.g., keys) that is organized in ascending/descending. Example is binary heap with its members ordered from the root-node up/down its children that are arranged accordingly (ascending/descending) depending on the heap type. For example, if a has child node b then − key(a) ≥ key(b) As the value of parent is greater than that of child, this property generates Max Heap. 7 November 2018 Dr. Veton Këpuska

24 Heap Since a heap is a complete binary tree, it has a smallest possible height - a heap with N nodes always has O(log N) height. A heap is useful data structure when you need to remove the object with the highest (or lowest) priority. A common use of a heap is to implement a priority queue. Based on this criteria, a heap can be of two types − 7 November 2018 Dr. Veton Këpuska

25 Heap Min-Heap − Where the value of the root node is less than or equal to either of its children. 7 November 2018 Dr. Veton Këpuska

26 Heap Max-Heap − Where the value of the root node is greater than or equal to either of its children. 7 November 2018 Dr. Veton Këpuska

27 Max Heap Construction Algorithm
We shall use the same example to demonstrate how a Max Heap is created. The procedure to create Min Heap is similar but we go for min values instead of max values. We are going to derive an algorithm for max heap by inserting one element at a time. At any point of time, heap must maintain its property. While insertion, we also assume that we are inserting a node in an already heapified tree. 7 November 2018 Dr. Veton Këpuska

28 Heap Construction Step 1 − Create a new node at the end of heap.
Step 2 − Assign new value to the node. Step 3 − Compare the value of this child node with its parent. Step 4 − If value of parent is less than child, then swap them. Step 5 − Repeat step 3 & 4 until Heap property holds. 7 November 2018 Dr. Veton Këpuska

29 Max Heap Construction Lets consider the input sample: 35 35 35 33 42 7 November 2018 Dr. Veton Këpuska

30 Max Heap Deletion Deletion in Max Heap always starts at the root by removing it and resorting the tree. Step 1 − Remove root node. Step 2 − Move the last element of last level to root. Step 3 − Compare the value of this child node with its parent. Step 4 − If value of parent is less than child, then swap them. Step 5 − Repeat step 3 & 4 until Heap property holds. 7 November 2018 Dr. Veton Këpuska

31 Animation Example 7 November 2018 Dr. Veton Këpuska

32 End Heap 7 November 2018 Dr. Veton Këpuska

33 SIO 7 November 2018 Dr. Veton Këpuska

34 Buffer Declaration/ Creation Options
Static allocation Systems. Dynamic Allocation System Each system, and even individual streams might use a different approach, based on which of the noted criteria is of greatest importance for that particular case All discussion to this point has been exclusively of static systems. Dynamic Allocation techniques will be covered latter 7 November 2018 Dr. Veton Këpuska

35 Obtaining Buffers: SIO_staticbuf()
uSize = SIO_staticbuf(hStream, &pBuf); SIO_staticbuf() returns buffers for statically created streams where the ‘Allocate Static Buffers’ box was checked SIO_staticbuf() can only be called prior to any SIO_issue or _reclaim call 7 November 2018 Dr. Veton Këpuska

36 Obtaining Buffers: SIO_staticbuf()
Digital Systems: Hardware Organization and Design 11/7/2018 Obtaining Buffers: SIO_staticbuf() Type param usage Int uSize size of block obtained - in nmadus (0 if no more) SIO_Handle hStream handle to statically created parent stream obj Ptr pBuf pointer to buffer being stream transferred 7 November 2018 Dr. Veton Këpuska Architecture of a Respresentative 32 Bit Processor

37 Halting a Stream: SIO_idle(), SIO_flush()
status = SIO_idle(hStream); status = SIO_flush(hStream); SIO_flush() indicates to immediately return all buffers, regardless of state of data (sent, waiting, in progress) SIO_idle() is identical to _flush for input streams, directs output streams to complete sending any remaining ‘live’ data prior to return blocks the calling task until all output data is sent In both cases, the underlying driver is idled prior to their return type param usage Int Status report of success/failure of operation SIO_Handle hStream handle to stream obj 7 November 2018 Dr. Veton Këpuska

38 Managing the Underlying IOM: SIO_ctrl()
status = SIO_ctrl(hStream, uCmd, arg); Example: SIO_ctrl() allows control and communication with the underlying IOM Not a frequently used SIO API Abilities offered with SIO_ctrl() are entirely the option of the IOM author Are by definition hardware-specific and unlikely matched with another IOM If IOM management only required when being bound to stream, can use parameter structure instead (see IOM chapter) SIO_ctrl() is ideal if parameter changes required after stream creation status = SIO_ctrl(hMySIO, DAC_RATE, 12000); 7 November 2018 Dr. Veton Këpuska

39 Managing the Underlying IOM: SIO_ctrl()
type param usage Int status whatever return value the IOM author provided SIO_Handle hStream handle to statically created parent stream obj Uns uCmd command value passed to IOM – IOM specific Arg arg uncommitted gen’l purpose user argument 7 November 2018 Dr. Veton Këpuska

40 “First Available” Stream: SIO_select()
uMask = SIO_select(ahSioTab, nSio, uTimeout); Wait until one or more streams are ready for I/O streamtab defines which streams to pend on Useful for slow-device I/O Daemon task to route data from several sources recommended: use newer BIOS messaging API, eg: MSGQ 7 November 2018 Dr. Veton Këpuska

41 “First Available” Stream: SIO_select()
IOM In IOM Out SIO_Handle hSioIn, hSioOut, ahSioTab[2]; Uns uMask; ahSioTab [0] = hSioIn; ahSioTab [1] = hSioOut; uMask = SIO_select(ahSioTab, 2, SYS_FOREVER) if (uMask == 0x1) { // service streamIn } if (uMask == 0x2) { // service streamOut } post or post unblocks Type param usage Uns uMask ready stream ID SIO_Handle ahSioTab[] table of streams Int nSio # of streams in table uTimeout max blocking time 7 November 2018 Dr. Veton Këpuska

42 SIO API Summary Buffer Passing Stream Management
SIO_issue Send a buffer to a stream SIO_reclaim Request a buffer back from a stream SIO_ready Test to see if stream has buffer available for reclaim SIO_select Wait for any of a specified group of streams to be ready Stream Management SIO_staticbuf Obtain pointer to statically created buffer SIO_flush Idle a stream by flushing buffers SIO_idle Idle a stream SIO_ctrl Perform a device-dependent control operation Stream Properties Interrogation SIO_bufsize Returns size of the buffers specified in stream object SIO_nbufs Returns number of buffers specified in stream object SIO_segid Memory segment used by a stream as per stream object 7 November 2018 Dr. Veton Këpuska

43 SIO API Summary Dynamic Stream Management (mod.11) Archaic Stream API
SIO_create Dynamically create a stream (malloc fxn) SIO_delete Delete a dynamically created stream (free fxn) Archaic Stream API SIO_get Get buffer from stream SIO_put Put buffer to a stream 7 November 2018 Dr. Veton Këpuska

44 1 2 3 4 5 6 7 TSK with SIO Coding Stream Concepts Stream API
Double Buffered Streams 4 Stream Configuration 5 Review 6 Lab 7 7 November 2018 Dr. Veton Këpuska 3

45 TSK with SIO Coding 7 November 2018 Dr. Veton Këpuska

46 Creating and Deleting Streams
Create the stream object in the configuration or at runtime with the SIO_create function. Creating Streams Statically In the configuration, you can create streams and set the properties for each stream and for the SIO Manager itself. You cannot use the SIO_delete function to delete statically-created streams. Creating and Deleting Streams Dynamically You can also create a stream at run time with the SIO_create function as shown in Example below. 7 November 2018 Dr. Veton Këpuska

47 Basic Task Code Topology:
Void taskFunction(…) { /* Prolog */ while (‘condition’) { SIO_reclaim(); /* Process */ SIO_issue(); } /* Epilog */ Initialization (runs once only) Processing loop - option: termination condition Wait for resources to be available Perform desired DSP work... Shutdown (runs once - at most) 7 November 2018 Dr. Veton Këpuska

48 Creating a Stream with SIO_create
SIO_create creates a stream and returns a handle of type SIO_Handle. SIO_create opens the device(s) specified by name, specifying buffers of size bufsize. Additional optional attributes specify the number of buffers, the buffer memory segment, the streaming model, etc. The mode parameter is used to specify whether the stream is an input (SIO_INPUT) or output (SIO_OUTPUT) stream. 7 November 2018 Dr. Veton Këpuska

49 Creating a Stream with SIO_create
SIO_Handle SIO_create (name, mode, bufsize, attrs) String name; Int mode; Uns bufsize; SIO_Attrs *attrs; 7 November 2018 Dr. Veton Këpuska

50 Creating a Stream with SIO_create
If you open the stream with the streaming model set to SIO_ISSUERECLAIM, no stream buffers are allocated, since the creator of the stream is expected to supply all necessary buffers. SIO_delete, closes the associated device(s) and frees the stream object. If the stream was opened using the SIO_STANDARD streaming model, it also frees all buffers remaining in the stream. User-held stream buffers must be explicitly freed by the user’s code. 7 November 2018 Dr. Veton Këpuska

51 Freeing User-Held Stream Buffers
Int SIO_delete (stream) SIO_Handle stream 7 November 2018 Dr. Veton Këpuska

52 Stream I/O There are two models for streaming data in DSP/BIOS:
standard model, and Issue/Reclaim model. The standard model provides a simple method for using streams, The Issue/Reclaim model provides more control over the stream operation. 7 November 2018 Dr. Veton Këpuska

53 Standard SIO 7 November 2018 Dr. Veton Këpuska

54 Standard SIO Model SIO_get and SIO_put implement the standard stream model. SIO_get is used to input the data buffers. SIO_get exchanges buffers with the stream. The bufp parameter is used to pass the device a buffer and return a different buffer to the application. SIO_get returns the number of bytes in the input buffer 7 November 2018 Dr. Veton Këpuska

55 Stream I/O The SIO_put function performs the output of data buffers, and, like SIO_get, exchanges physical buffers with the stream. SIO_put takes the number of bytes in the output buffer 7 November 2018 Dr. Veton Këpuska

56 Stream I/O Int SIO_get (stream, bufp)
SIO_Handle stream; Ptr *bufp; Int SIO_put(stream, bufp, nbytes) Uns nbytes; 7 November 2018 Dr. Veton Këpuska

57 Issue/Reclaim Streaming Model
7 November 2018 Dr. Veton Këpuska

58 Isue/Reclaim SIO Model
SIO_issue and SIO_reclaim are the calls that implement the Issue/Reclaim streaming model as shown in Example below. SIO_issue sends a buffer to a stream. No buffer is returned, and the stream returns control to the task without blocking. arg is not interpreted by DSP/BIOS, but is offered as a service to the stream client. arg is passed to each device with the associated buffer data. It can be used by the stream client as a method of communicating with the device drivers. For example, arg could be used to send a time stamp to an output device, indicating exactly when the data is to be rendered. SIO_reclaim requests a stream to return a buffer. 7 November 2018 Dr. Veton Këpuska

59 Issue/Reclaim Streaming Model
Int SIO_issue (stream, pbuf, nbytes, arg) SIO_Handle stream; Ptr pbuf; Uns nbytes; Arg arg; Int SIO_reclaim (stream, bufp, parg) Ptr *bufp; Arg *parg; 7 November 2018 Dr. Veton Këpuska

60 SIO Details If no buffer is available, the stream will block the task until the buffer becomes available or the stream’s timeout has elapsed. At a basic level, the most obvious difference between the standard and Issue/Reclaim models is that the Issue/Reclaim model separates the notification of a buffer’s arrival (SIO_issue) and the waiting for a buffer to become available (SIO_reclaim). So, an SIO_issue/SIO_reclaim pair provides the same buffer exchange as calling SIO_get or SIO_put. 7 November 2018 Dr. Veton Këpuska

61 SIO Details The Issue/Reclaim streaming model provides greater flexibility by allowing the stream client to control the number of outstanding buffers at runtime. A client can send multiple buffers to a stream, without blocking, by using SIO_issue. The buffers are returned, at the client’s request, by calling SIO_reclaim. This allows the client to choose how deep to buffer a device and when to block and wait for a buffer. The Issue/Reclaim streaming model also provides greater determinism in buffer management by guaranteeing that the client’s buffers are returned in the order that they were issued. This allows a client to use memory from any source for streaming. 7 November 2018 Dr. Veton Këpuska

62 SIO Details If a DSP/BIOS task receives a large buffer, that task can pass the buffer to the stream in small pieces—simply by advancing a pointer through the larger buffer and calling SIO_issue for each piece. This works because each piece of the buffer is guaranteed to come back in the same order it was sent. 7 November 2018 Dr. Veton Këpuska

63 Buffer Exchange An important part of the streaming model in DSP/BIOS is buffer exchange. To provide efficient I/O operations with a low amount of overhead, DSP/BIOS avoids copying data from one place to another during certain I/O operations. Instead, DSP/BIOS uses SIO_get, SIO_put, SIO_issue, and SIO_reclaim to move buffer pointers to and from the device. Figure in the next slide shows a conceptual view of how SIO_get works: 7 November 2018 Dr. Veton Këpuska

64 SIO_get: Application Program Device Driver SIO_get(strem, &bufp)
Exchange Free Buffer Full Buffer 7 November 2018 Dr. Veton Këpuska

65 ======== siotest1. c ========
======== siotest1.c ======== * In this program a task reads data from a DGN sine device * and prints the contents of the data buffers to a log buffer. The data exchange between the task and the device is done * in a device independent fashion using the SIO module APIs. * * The stream in this example follows the SIO_STANDARD streaming * model and is created statically. */ #include <std.h> #include <sio.h> #include <sys.h> #include <tsk.h> extern Int IDRAM1; /* MEM segment ID defined by Conf tool */ extern LOG_Obj trace; /* LOG object created with Conf tool */ extern SIO_Obj inputStream; /* SIO object created w Conf tool */ extern TSK_Obj streamTask; /* pre-created task */ SIO_Handle input = &inputStream; /* SIO handle used below */ Void doStreaming(Uns nloops); /* function for streamTask */ /* * ======== main ======== */ Void main() { LOG_printf(&trac 7 November 2018 Dr. Veton Këpuska

66 Task Coding Example void myTask() { short inBuf[BUFSIZE]; make stream buffers short outBuf [BUFSIZE]; SIO_issue(&inStream, inBuf, sizeof(inBuf), NULL); prime streams w buffers SIO_issue(&outStream, outBuf,sizeof(outBuf), NULL); while (continue == TRUE) { run loop w exit condition inSize = SIO_reclaim(&inStream, (Ptr *)&inBuf, NULL); outSize = SIO_reclaim(&outStream, (Ptr *)&outBuf, NULL); get buffers for (i = 0; i < (outSize / sizeof(short)); i++) { do DSP... outBuf[i] = 2*inBuf[i]; } SIO_issue(&outStream, outBuf, outSize, NULL); send buffers SIO_issue(&inStream, inBuf, inSize, NULL); } SIO_idle(&inStream); turn off streams & IOMs SIO_idle(&outStream); SIO_reclaim(&inStream, (Ptr *)&inBuf, NULL); get back buffers SIO_reclaim(&outStream, (Ptr *)&outBuf, NULL); } Note: conceptual example only – cannot use static declaration ‘inBuf’ ()and outBuf) as rtn ptrs… 7 November 2018 Dr. Veton Këpuska

67 1 2 3 4 5 6 7 TSK with SIO Coding Stream Concepts Stream API
Double Buffered Streams 4 Stream Configuration 5 Review 6 Lab 7 7 November 2018 Dr. Veton Këpuska 3

68 Double buffers 7 November 2018 Dr. Veton Këpuska

69 Double Buffer Concepts
To maintain real-time throughput, it is often beneficial to provide two buffers to each stream: One should always be available to the IOM The other is available to the TSK for processing Once processed by the TSK, it is re-issued back into the stream Stream maintains buffers in a (BIOS) QUE until needed by IOM or TSK After returning (issuing) the used buffer back into the stream, the TSK usually requests (reclaim) a new buffer from the stream to continue processing If a block is available, the stream provides it to the TSK Otherwise, TSK is blocked until IOM returns a buffer to the stream; then TSK is unblocked and given the buffer requested and now available Allows for effective ‘concurrency’ (processing one buffer while filling another) For real-time to be met, DSP processing should complete before the I/O does 7 November 2018 Dr. Veton Këpuska

70 Single Buffer Example IOM Device BIOS: empty empty ToDeviceQUE empty
TASK int pBuf[SIZE]; status = SIO_issue(hStrm, pBuf, SIZE, NULL ); while(…) size = SIO_reclaim(hStrm, &pBuf, NULL); // process & send output IOM Device BIOS: Stream empty empty ToDeviceQUE empty Input Stream full FromDeviceQUE full empty ToDeviceQUE empty 7 November 2018 Dr. Veton Këpuska

71 Double Buffer Example IOM Device BIOS: empty empty ToDeviceQUE empty
TASK iint pBuf_1[SIZE]; int pBuf_2[SIZE]; status = SIO_issue(hStrm, pBuf_1, SIZE, NULL ); status = SIO_issue(hStrm, pBuf_2, SIZE, NULL ); while(…) size = SIO_reclaim(hStrm, &pBuf_x, NULL); // process & send output status = SIO_issue(hStrm, pBuf_x, SIZE, NULL ); size = SIO_reclaim(hStrm, &pBuf_1, NULL); size = SIO_reclaim(hStrm, &pBuf_2, NULL); IOM Device BIOS: Stream empty empty ToDeviceQUE empty Input Stream full FromDeviceQUE full empty ToDeviceQUE empty 7 November 2018 Dr. Veton Këpuska

72 Double Buffer Stream TSK Coding Example
Digital Systems: Hardware Organization and Design 11/7/2018 Double Buffer Stream TSK Coding Example //prolog – prime the process… status = SIO_issue(&sioIn, pIn1, SIZE, NULL); status = SIO_issue(&sioIn, pIn2, SIZE, NULL); status = SIO_issue(&sioOut, pOut1, SIZE, NULL); status = SIO_issue(&sioOut, pOut2, SIZE, NULL); //while loop – iterate the process… while (condition == TRUE){ size = SIO_reclaim(&sioIn, (Ptr *)&pInX, NULL); size = SIO_reclaim(&sioOut, (Ptr *)&pOutX, NULL); // DSP... to pOut status = SIO_issue(&sioIn, pInX, SIZE, NULL); status = SIO_issue(&sioOut, pOutX, SIZE, NULL); } //epilog – wind down the process… status = SIO_flush(&sioIn); status = SIO_idle(&sioOut); size = SIO_reclaim(&sioIn, (Ptr *)&pIn1, NULL); size = SIO_reclaim(&sioIn, (Ptr *)&pIn2, NULL); size = SIO_reclaim(&sioOut, (Ptr *)&pOut1, NULL); size = SIO_reclaim(&sioOut, (Ptr *)&pOut2, NULL); This is a fairly ‘tricky’ coding solution, with many subtle solutions to problems seldom thought of. It is recommended that you highlight the points below to make the code well understood to the students: we presume that 4 buffers were obtained : pBuf In1 and 2 , Out 1 and 2 notice that we issue both input buffers to begin and then wait for 1 to come back we store the ptr to the reclaimed input buffer as pInX – a ‘temporary’ pointer to the recently reclaimed buffer we do the DSP on the 1st input buf and store the results in the 1st output buf – but we DON’T send the buf out yet – this is critical – and subtle, so please point this out: If we sent out the 1st output buf NOW we’d never have time to load TWO buffers to the output, since by the time there is a new input buffer, the output buffer we just sent would also have just drained, so the output would have two buffers available, but never would have 2 buffers worth of results on hand at any time. To solve this REALLY hard to visualize problem, we HOLD the 1st output buffer until we have BOTH ready to send. At this point, we can wait for a new input, and have a freshly emptied output buffer to put results into – perfect balance of input and output loading we reissue the used input buffer back to the in stream for refilling and wait for the 2nd buffer to fill and be reclaimed. we block until the 2nd buffer comes in, as we do in all reclaims with the 2nd buffer in, we perform DSP on the new buffer and produce the 2nd output buffer results NOW we can send BOTH output buffers to the out stream & underlying out device, which gives us proper “double buffering” on the output side finally, we re-issue the used 2nd buffer back to the in stream at this point, all 4 buffers are ‘out’ in stream and device, so the 1st two reclaims in the while loop that follows will each block until a buffer fill/empty period has concluded, at which time we’ll get back another in and out ptr to do DSP through in the loop we obtain a ready to use block on BOTH the in and out streams, then do DSP on the IN block, putting the results in the OUT block the empty in buffer is returned to the in stream to be re-filled. the new out data is sent via the out stream to the out device this loop could continue forever, or until any author defined ‘condition’ is true (end of data signal, user throws switch to turn off thread, etc) if loop can terminate, the epilog script will run at this point both streams are idled, which turns off each device and inhibits them from obtaining new interrupt signals. The choice of flush or idle is up to the author The final reclaims are technically required, but don’t actually serve a purpose in the code above. The final reclaim does two things: it gives back the final pointer to the buffers that were outstanding it ‘proves’ the stream and device are no longer in possession of these resources However, this code doesn’t need the return of the pointer, since we never overwrote their original values, still available in pIn1 and 2 and out 1 and 2. We used the ‘x’ pointer which has been overwritten instead with ever different pointer values. So, if we were going to do a ‘free’ at this point to release heap resources, we could refer back to the ‘1’ and ‘2’ pointers and not worry about the x pointer at all. As to the 2nd value: the ‘proof’ that the block was no longer in use by the SIO or IOM, this is assuerd by the return of the flush or idle already, so there is no need to obtain proof of this again, thus these last two lines will be seen commonly in system examples, but are probably not worth keeping in code such as that shown here. Lastly, it is good to note that the pro/epi logs run 1x each, and maybe never for the epilogue. However, the while loop often runs MANY times over, many times ‘forever’ in the life of the system. No follow-on point, just the notion that this is the way this code usually runs, so the students can see this general approach. SUGGESTION: IN ADVANCED CLASSES, WHERE TIME AND INTEREST ALLOW, CONSIDER DEMONSTRATING HOW TO SCALE THIS SOLUTION TO A 3 BUFFER SOLUTION. IT MIGHT EVEN BE BENEFICIAL IF STUDENTS ARE DOING WELL WITH THE CONCEPTS TO HAVE **THEM** WORK OUT THE 3 BUFFER SOLUTION. ANOTHER OPTION: EXTRAPOLATE THE SOLUTION TO AN ‘N’ BUFFER GENERAL SOLUTION. THE SOLUTIONS TO THESE EXERCISES ARE PROVIDED AT THE END OF THE CHAPTER IN THE ‘OPTIONAL’ SECTION. PRESENTING THESE EXTRA SLIDES IS NOT REQUIRED, AND NOT RECOMMENDED FOR NOVICE CLASSES OR WHEN TIME OR INTEREST IN THE SUBJECT IS NOT AVAILABLE. 7 November 2018 Dr. Veton Këpuska Architecture of a Respresentative 32 Bit Processor

73 Triple Buffer Stream Coding Example
//prolog – prime the process… status = SIO_issue(&sioIn, pIn1, SIZE, NULL); status = SIO_issue(&sioIn, pIn2, SIZE, NULL); status = SIO_issue(&sioIn, pIn3, SIZE, NULL); size = SIO_reclaim(&sioIn, (Ptr *)&pInX, NULL); // DSP... to pOut1 status = SIO_issue(&sioIn, pInX, SIZE, NULL ); size = SIO_reclaim(&sioIn, (Ptr *)&pInX, NULL); // DSP... to pOut2 status = SIO_issue(&sioIn, pInX, SIZE, NULL ); size = SIO_reclaim(&sioIn, (Ptr *)&pInX, NULL); // DSP... to pOut3 status = SIO_issue(&sioIn, pInX, SIZE, NULL ); status = SIO_issue(&sioOut, pOut1, SIZE, NULL); status = SIO_issue(&sioOut, pOut2, SIZE, NULL); status = SIO_issue(&sioOut, pOut3, SIZE, NULL); //while loop – iterate the process… No change here ! while (condition == TRUE){ size = SIO_reclaim(&sioIn, (Ptr *)&pInX, NULL); size = SIO_reclaim(&sioOut,(Ptr *)&pOutX, NULL); // DSP... to pOut status = SIO_issue(&sioIn, pInX, SIZE, NULL); status = SIO_issue(&sioOut, pOutX, SIZE, NULL); } //epilog – wind down... status = SIO_flush(&sioIn); status = SIO_idle(&sioOut); size = SIO_reclaim(&sioIn, (Ptr *)&pIn1, NULL); size = SIO_reclaim(&sioIn, (Ptr *)&pIn2, NULL); size = SIO_reclaim(&sioIn, (Ptr *)&pIn3, NULL); size = SIO_reclaim(&sioOut,(Ptr *)&pOut1, NULL); size = SIO_reclaim(&sioOut,(Ptr *)&pOut2, NULL); size = SIO_reclaim(&sioOut,(Ptr *)&pOut3, NULL); 7 November 2018 Dr. Veton Këpuska

74 “N” Buffer Stream Coding Example
//prolog – prime the process… for (n=0;n<SIO_nbufs(&sioIn);n++) status = SIO_issue(&sioIn, pIn[n], SIZE, NULL); for (n=0;n<SIO_nbufs(&sioOut);n++){ size = SIO_reclaim(&sioIn, (Ptr *)&pInX, NULL); // DSP... to pOut[n] status = SIO_issue(&sioIn, pInX, SIZE, NULL ); } for (n=0;n<SIO_nbufs(&sioOut);n++) status = SIO_issue(&sioOut, pOut[n], SIZE, NULL); //while loop – iterate the process… NO CHANGE HERE ! ! while (condition == TRUE){ size = SIO_reclaim(&sioIn, (Ptr *)&pInX, NULL); size = SIO_reclaim(&sioOut, (Ptr *)&pOutX, NULL); // DSP... to pOut status = SIO_issue(&sioIn, pInX, SIZE, NULL ); status = SIO_issue(&sioOut, pOutX, SIZE, NULL); } //epilog – wind down... status = SIO_flush(&sioIn); status = SIO_idle(&sioOut); size = SIO_reclaim(&sioIn, (Ptr *)&pIn[n], NULL); size = SIO_reclaim(&sioOut, (Ptr *)&pOut[n], NULL); 7 November 2018 Dr. Veton Këpuska

75 1 2 3 4 5 6 7 TSK with SIO Coding Stream Concepts Stream API
Double Buffered Streams 4 Stream Configuration 5 Review 6 Lab 7 7 November 2018 Dr. Veton Këpuska 3

76 Stream Configuration 7 November 2018 Dr. Veton Këpuska

77 1. Register the I/O Mini-Driver
DEV Table Include the files/library containing the IOM in the project name fxns devid params type devp /uDevMyCodec _DSK6416_EDMA…FXN 0x0 IOM_Fxns 7 November 2018 Dr. Veton Këpuska

78 2. Register the DIO, Bind to IOM
Important! DEV Table DIO code is built into BIOS – no new files to include name fxns devid params type devp /uDevMyCodec _DSK6416_EDMA…FXN 0x0 IOM_Fxns /dioCodecXmt _DIO_tskStaticFxns DEV_Fxns 7 November 2018 Dr. Veton Këpuska

79 3. SIO Module Params & Object Creation
GCONF TCONF var mySio = SIO.create(“sio_Receive"); SIO.OBJMEMSEG = prog.get(“IRAM”); SIO.USEISSUERECLAIM = true; 7 November 2018 Dr. Veton Këpuska

80 4. Define SIO Object Properties
Digital Systems: Hardware Organization and Design 11/7/2018 4. Define SIO Object Properties Device – IOM to ‘bind’ to Model: select Issue/Reclaim! sioRcv.comment = “input stream"; sioRcv.deviceName = prog.get(“dioCodecRcv"); // sioRcv.controlParameter = sioRcv.mode = "input"; // “output” sioRcv.bufSize = 764; sioRcv.numBufs = 2; // sioRcv.bufSegId = prog.get(“IRAM"); // sioRcv.bufAlign = 1; // 2**n sioRcv.flush = false; sioRcv.modelName = “Issue/Reclaim"; sioRcv.allocStaticBuf = true; // false sioRcv.timeout = -1; sioRcv.useCallBackFxn = false; // true w. SWI Question leading to next two slides: where/how did the “dioCodec” device get created? See next two slides... GCONF TCONF 7 November 2018 Dr. Veton Këpuska Architecture of a Respresentative 32 Bit Processor

81 1 2 3 4 5 6 7 TSK with SIO Coding Stream Concepts Stream API
Double Buffered Streams 4 Stream Configuration 5 Review 6 Lab 7 7 November 2018 Dr. Veton Këpuska 3

82 review 7 November 2018 Dr. Veton Këpuska

83 SIO Concepts IOM Packet Input IOM Task Output IOM SIO SIO issue issue
MY_DSP_algo reclaim reclaim IOM Packet prev {QUE_Elem} next Ptr addr Uns size Arg misc Arg arg Uns cmd Int status 7 November 2018 Dr. Veton Këpuska

84 SIO Concepts Common I/O interface: between Tasks and Devices
Universal interface to I/O devices Yields improved code maintenance and portability Number of buffers and buffer size are user selectable Unidirectional: streams are input or output - not both Efficiency: uses pointer exchange instead of buffer copy SIO_issue passes an “IOM Packet” buffer descriptor to Device via stream SIO_reclaim waits for an IOM Packet to be returned by the DEV via stream Abstraction: TSK author insulated from device-specific functionality BIOS manages two QUEues (todevice & fromdevice) Driver author signals TSK buffer is ready via SEM 7 November 2018 Dr. Veton Këpuska

85 SIO Concepts Asynchronous: TSK and DEV activity is independent, synch’d by buffer passes Buffers: Data buffers must be created - by config tool or TSK 7 November 2018 Dr. Veton Këpuska

86 1 2 3 4 5 6 7 TSK with SIO Coding Stream Concepts Stream API
Double Buffered Streams 4 Stream Configuration 5 Review 6 Lab 7 7 November 2018 Dr. Veton Këpuska 3

87 SIO Interfaced Task Thread
C:\dvsdk_1_01_00_15\psp_1_00_02_00 BIOS provided Audio In (48 KHz) ADC AIC33 McBSP DRR dioCodec IOM udevCodec DAC AIC33 McBSP DXR SIO Audio Out (48 KHz) tskProcBuf procBuf while() SIO_reclaim(&sioIn) for (i =0, i<HIST; i ++) pIn[i-HIST]=pPriorIn[2*BUF-HIST]; if( sw0 == 1 ) FIR(in[pIn-HIST],out[pOut]) else {pOut[i]=pIn[i]} BIOS\Labs\Algos FIR.c FIR Code coeffs.c Coefficients 7 November 2018 Dr. Veton Këpuska

88 SIO Interfaced Task Thread
A – Test driver example in PSP tree B – Move driver example into \Work folder C – Restore FIR application - Replace SEM & QUE, with SIO; delete isrAudio(), etc… D&E – Optional: implement enhanced coding options 7 November 2018 Dr. Veton Këpuska

89 Lab06.c void procBuf(void) { // No args - common for TSK
short i; // for loop indexer short *pPriorIn; // points to history buf short *pIn, *pOut; // local ptrs to I/O bufs SIO_Handle sioIn, sioOut; sioIn = SIO_create("/dioIn" , SIO_INPUT , 4*BUF, NULL); sioOut = SIO_create("/dioOut", SIO_OUTPUT, 4*BUF, NULL); SIO_issue(sioIn , &in[0][HIST],4*BUF, NULL); // put 1st buf to I strm SIO_issue(sioIn , &in[1][HIST],4*BUF, NULL); // put 2nd buf to I strm SIO_issue(sioOut, &out[0][0], 4*BUF, NULL); // put 1st buf to O strm SIO_issue(sioOut, &out[1][0], 4*BUF, NULL); // put 2nd buf to O strm while(1) { // infinite loop: std w TSK SIO_reclaim(sioIn, (Ptr *)&pIn, NULL); // get full buf from a/d SIO_reclaim(sioOut, (Ptr *)&pOut, NULL); // get empty buf from d/a for ( i = 0; i < HIST; i++ ) // for (size of history) pIn[i-HIST] = pPriorIn[i+2*BUF-HIST]; // prime stereo hist buf pPriorIn = pIn; // update ptr to hist data if( sw0 == 1 ) { // if filtering is 'on‘ FIR(pIn-HIST , &coeffs[cSet][0], pOut , FIRSZ, BUF); FIR(pIn+1-HIST, &coeffs[cSet][0], pOut+1, FIRSZ, BUF); } else { // if filtering is 'off' for( i = 0; i < 2*BUF; i++ ) // for all new in data pOut[i] = pIn[i]; // copy L in to L out } SIO_issue(sioIn, pIn, 4*BUF, NULL); // send empty buf to a/d SIO_issue(sioOut, pOut, 4*BUF, NULL); // send full buf to d/a } }

90 Lab Details HWI – based lab 3 TSK – based lab 5 Filter Debug Release
Off 18% 4.7% On 61% 6.5% Filter Debug Release Off 3.8% 2.5% On 45% SWI – based lab 4 SIO – based lab 6 Filter Debug Release Off 3.8% 2.3% On 45% 3.7% Filter Debug Release Off 6.9% 5.1% On 48% 6.3 %

91 Lab Details Observations:
Adding SWI in almost all cases dropped CPU load In addition, it greatly increases HWI response time, reduces interrupt latency, spreads instantaneous demand into average demand, lowering required processor speed greatly in most systems ! 7 November 2018 Dr. Veton Këpuska

92 TI BIOS Data Streaming SIO
END 7 November 2018 Dr. Veton Këpuska


Download ppt "TI BIOS SIO – Data Streaming 7 November 2018 Dr. Veton Këpuska."

Similar presentations


Ads by Google