Banked RAM support. More...
Functions | |
char * | NutSegBufReset (void) |
Reset the segmented buffer. | |
char * | NutSegBufInit (size_t size) |
Initialize the segmented buffer. | |
char * | NutSegBufWriteRequest (size_t *bcp) |
Request segmented buffer space for writing. | |
char * | NutSegBufReadRequest (size_t *bcp) |
Request segmented buffer space for reading. | |
char * | NutSegBufWriteCommit (size_t bc) |
Commit written buffer space. | |
char * | NutSegBufReadCommit (size_t bc) |
Commit read buffer space. | |
void | NutSegBufWriteLast (size_t bc) |
Commit written buffer space and finish write access. | |
void | NutSegBufReadLast (size_t bc) |
Commit written buffer space and finish read access. | |
uint32_t | NutSegBufAvailable (void) |
Return the available buffer space. | |
uint32_t | NutSegBufUsed (void) |
Return the used buffer space. |
Banked RAM support.
Even with a hardware decoder like the one used on the Medianut Board, streaming MP3 data in realtime from a TCP/IP network to the decoder requires some special techniques to make it work on a tiny 8 bit system.
The key to success is avoidance of data copying. Usually data streams are moved from the Ethernet Controller to the Ethernet's driver buffer, then moved to the TCP buffer, again moved to the application buffer and finally from the application buffer to the MP3 decoder buffer. Some systems may use additional steps. Nut/OS tries to avoid these copies. In extreme, the data may be moved directly from the Ethernet controller to the MP3 controller. In reality this will fail, because TCP isn't realtime, but playing MP3 is. So at least one buffer stage is required to compensate the non deterministic arrival of TCP data. Each packet received is moved from the Ethernet controller into a so called NETBUF. Each NETBUF is added to a connection specific queue until the application request data from the connection. For portability reasons and to keep things simple, the application provides a buffer and calls NutTcpReceive() to get that buffer filled with application data out of the queued NETBUFs. This is another copy, but frees the application from dealing with system specific NETBUF structures.
The smart part is, that Nut/OS offers a special buffer management to avoid the final copy into the decoder buffer and that the Nut/OS MP3 decoder driver makes use of this buffer management. As stated, normally the application buffer is filled by some kind of read statement (first copy) and transfered to the driver by some kind of write statement (second copy).
When using the segmented memory management, the application will query the driver for buffer space first and then pass this buffer to the TCP read routine. This way the TCP read routine will directly fill the buffer of the decoder driver. When this has been done, the application commits the buffer filled and requests a new one and so on.
Finally the segmented memory mamagement API can not only handle a continuos memory space, but also one that is divided into several segments. This is usefull with banked memory hardware provided by Ethernut 2 boards.
$Log$ Revision 1.7 2009/02/06 15:40:29 haraldkipp Using newly available strdup() and calloc(). Replaced NutHeap routines by standard malloc/free. Replaced pointer value 0 by NULL.
Revision 1.6 2008/08/11 07:00:33 haraldkipp BSD types replaced by stdint types (feature request #1282721).
Revision 1.5 2008/02/15 17:08:05 haraldkipp Calling the initialization routine more than once is now possible. By default, half of the available memory will be allocated. Previous versions eat all free memory but 8k.
Revision 1.4 2007/04/12 09:08:57 haraldkipp Segmented buffer routines ported to ARM.
Revision 1.3 2004/12/17 15:28:33 haraldkipp Bugfix. Comparison of the read and write pointers now includes the segments. Thanks to Pete Allinson and Johan van der Stoel.
Revision 1.2 2004/08/18 18:51:56 haraldkipp Made banked memory configurable.
Revision 1.1 2003/07/21 18:19:48 haraldkipp First check in
char* NutSegBufReset | ( | void | ) |
Reset the segmented buffer.
Definition at line 94 of file bankmem.c.
References NutSegBufEnable.
Referenced by FeederThread(), NutSegBufInit(), and VsCodecOpen().
char* NutSegBufInit | ( | size_t | size | ) |
Initialize the segmented buffer.
size | Number of bytes to allocate for the global buffer. In systems with banked memory this parameter is ignored and all banked memory is occupied for the global buffer. In systems without banked memory, the specified number of bytes is taken from heap memory. |
Definition at line 117 of file bankmem.c.
References NUTBANK_COUNT, NUTBANK_SIZE, NUTBANK_START, NutHeapAlloc, NutHeapAvailable, NutHeapFree, and NutSegBufReset().
Referenced by VsDecoderBufferInit().
char* NutSegBufWriteRequest | ( | size_t * | bcp | ) |
Request segmented buffer space for writing.
This call will also enable the current write segment and may disable the current read segment.
bcp | Pointer to a variable, which receives the number of consecutive bytes available for writing. |
Definition at line 150 of file bankmem.c.
References NutSegBufEnable.
Referenced by FeederThread(), and VsCodecWrite().
char* NutSegBufReadRequest | ( | size_t * | bcp | ) |
Request segmented buffer space for reading.
This call will also enable the current read segment and may disable the current write segment.
bcp | Pointer to a variable, which receives the number of consecutive bytes available for reading. |
Definition at line 173 of file bankmem.c.
References NutSegBufEnable.
Referenced by FeederThread(), and VsCodecRead().
char* NutSegBufWriteCommit | ( | size_t | bc | ) |
Commit written buffer space.
The write pointer will be incremented by the specified number of bytes. If the pointer reaches the end of a segment, the next segment will be enabled and the pointer will point to the start of the new segement.
bc | Number of bytes to commit. |
Definition at line 197 of file bankmem.c.
References NUTBANK_COUNT, and NutSegBufEnable.
char* NutSegBufReadCommit | ( | size_t | bc | ) |
Commit read buffer space.
The read pointer will be incremented by the specified number of bytes. If the pointer reaches the end of a segment, the next segment will be enabled and the pointer will point to the start of the new segement.
bc | Number of bytes to commit. |
Definition at line 226 of file bankmem.c.
References NUTBANK_COUNT, and NutSegBufEnable.
void NutSegBufWriteLast | ( | size_t | bc | ) |
Commit written buffer space and finish write access.
The write pointer will be incremented by the specified number of bytes. This call will also enable the current read segment and may disable the current write segment.
bc | Number of bytes to commit. |
Definition at line 255 of file bankmem.c.
References NUTBANK_COUNT, and NutSegBufEnable.
Referenced by FeederThread(), and VsCodecWrite().
void NutSegBufReadLast | ( | size_t | bc | ) |
Commit written buffer space and finish read access.
The write pointer will be incremented by the specified number of bytes. This call will also enable the current read segment and may disable the current write segment.
bc | Number of bytes to commit. |
Definition at line 281 of file bankmem.c.
References NUTBANK_COUNT, and NutSegBufEnable.
Referenced by FeederThread(), and VsCodecRead().
uint32_t NutSegBufAvailable | ( | void | ) |
Return the available buffer space.
Definition at line 305 of file bankmem.c.
Referenced by VsCodecIOCtl(), and VsDecoderBufferInit().
uint32_t NutSegBufUsed | ( | void | ) |
Return the used buffer space.
Definition at line 315 of file bankmem.c.
Referenced by FeederThread(), VsCodecIOCtl(), and VsPlayerFlush().