100% found this document useful (1 vote)
115 views

Memory Management - RTOS

Most RTOSs provide memory management functions for allocating and freeing fixed-size memory buffers from pools in a fast and predictable manner. The document describes MultiTask!'s memory management functions, which allocate buffers from pools using reqbuf or getbuf and free them with relbuf. It also explains how init_mem_pool is used to initialize a memory pool by specifying the memory block, buffer size, count, and pool ID. Memory buffers in a pool are all the same size. The RTOS manages the pools but the application must provide the memory blocks.

Uploaded by

Deepak Reddy
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
115 views

Memory Management - RTOS

Most RTOSs provide memory management functions for allocating and freeing fixed-size memory buffers from pools in a fast and predictable manner. The document describes MultiTask!'s memory management functions, which allocate buffers from pools using reqbuf or getbuf and free them with relbuf. It also explains how init_mem_pool is used to initialize a memory pool by specifying the memory block, buffer size, count, and pool ID. Memory buffers in a pool are all the same size. The RTOS manages the pools but the application must provide the memory blocks.

Uploaded by

Deepak Reddy
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Memory management - RTOS

http://sites.google.com/site/rtosmifmim/home/-memory-management

RTOS

Navigation
Home A first look to Embedded Computing Tasks and States Tasks and Data Semaphores and Shared Data Semaphores as a Signaling Device Message Queues, Mailboxes, and Pipes Timer Functions Events Memory management Interrupt Routines in an RTOS Environment - Part 1 Interrupt Routines in an RTOS Environment - Part 2 Nested Interrupts Self control questions and tasks Rating criteria and Final test The contents of the course Additional literature and references

Home >

Memory management
Most RTOSs have some kind of memory management subsystem. Although some offer the equivalent of the C library functions malloc and free, real-time systems engineers often avoid these two functions because they are typically slow and because their execution times are unpredictable. They favor instead functions that allocate and free fixed-size buffers, and most RTOSs offer fast and predictable functions for that purpose. The MultiTask! system is a fairly typical RTOS in this regard: you can set up pools, each of which consists of some number of memory buffers. In any given pool, all of the buffers are the same size. The reqbuf and getbut functions allocate a. memory buffer from a pool. Each returns a pointer to the allocated buffer; the only difference between them is that if no memory buffers are available, get but will block the task that calls it, whereas reqbuf will return a NULL pointer right away. void *getbuf (unsigned int uPoolId, unsigned int uTimeout); void *reqbuf (unsigned int uPoolId); In each of these functions, the uPoolId parameter indicates the pool from which the memory buffer is to be allocated. The uTimeout parameter in getbuf indicates the length of time that the task is willing to wait for a buffer if none are free. The size of the buffer that is returned is determined by the pool from which the buffer is allocated, since all the buffers in anyone pool are the same size. The tasks that call, these functions must know the sizes of the buffers in each pool. The relbuf function frees a memory buffer. void relbuf (unsigned int uPoolId, void *p_vBuffer); Note that relbuf does not check that p_vBufter really points to a buffer in the pool indicated by uPoolId. If your code passes an invalid value for p_vBuffer, the results are usually catastrophic. The MultiTask! system is also typical of many RTOSs in that it does not know where the memory on your system is. Remember that in most embedded systems, unlike desktop systems, your software, not the operating system, gets control of a machine first. When it starts, the RTOS has no way of knowing what memory is free and what memory your application is already using. MultiTask! will manage a pool of memory buffers for you, but you must tell it where the

1 of 3

11/21/2011 9:38 PM

Memory management - RTOS

http://sites.google.com/site/rtosmifmim/home/-memory-management

memory is. The init_mem_pool function allows you to do this. int init_mem_pool ( unsigned int uPoolId, void *p_vMemory, unsigned int.uBufSize, unsigned int uBufCount, unsigned int uPoolType ); The uPoolId parameter is the identifier you will use in later calls to getbuf, reqbuf, and relbuf. The p_vMemory parameter points to the block of memory to use as the pool; you must make sure that it points to available memory. The uBufSize and uBufCount parameters indicate how large each buffer is and how many of them there are the pool. (The uPoolType parameter indicates whether these buffers will be used by tasks or by interrupt routines. This distinction is peculiar to MultiTask!, and we will not discuss it here.) The picture shows how this function allocates the pool of memory buffers. Memory management

Link to lesson 10 - Interrupt Routines in an RTOS Environment - Part 1 Link to this part Self Test Link to this part Assignment Link to this part Chat
Subpages (1): Week 9

2 of 3

11/21/2011 9:38 PM

Memory management - RTOS

http://sites.google.com/site/rtosmifmim/home/-memory-management

Sign in | Recent Site Activity | T erms | Report Abuse | Print page | Powered by Google Sites

3 of 3

11/21/2011 9:38 PM

You might also like