CMP EMBEDDED.COM

Login | Register     Welcome Guest  
HOME DESIGN PRODUCTS COLUMNS E-LEARNING CONFERENCES CODE FORUMS/BLOGS NEWSLETTERS CONTACT FEATURES RSS RSS

Listing 2: Sharing memory by using the mbuff driver

// user application
#include "mbuff.h"
...
u16* buf1; // pointer to the buffer to store 16-bit samples
main (int argc,char *argv[])
{
...
buf1 = (u16*) mbuff_alloc("buf1",0x100000);
if (buf1 == NULL) { // failure to allocate buffer }
sprintf((char*)buf1, "Hello, rt-task!\n"); // put some data into buffer
// now you can tell your realtime module to that you wrote
// something to the buffer, say, using RT FIFO
...
mbuff_free("buf1", (void*)buf1); // free buffer when you don't need it
}
// realtime module
#include "mbuff.h"
...
u16* buf1; // pointer to the buffer to store 16-bit samples
init_module(void) // allocate shared buffer during init of realtime module
{
// allocate 1MB buffer named "buf1"
buf1 = (u16*) mbuff_alloc("buf1", 0x100000); 
if (buf1 == NULL) { failure to allocate buffer }
...
}
cleanup_module(void) // deallocate buffer during cleanup of realtime module
{ mbuff_free("buf1", buf1); // free it 
...
}

Embedded.com Career Center
Looking for a new job?
SEARCH JOBS

Browse all jobs

SPONSOR
RECENT JOB POSTINGS





 :