Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Description

Obtains a memory block from a memory partition. It is assumed that the application knows the size of each memory block obtained. Also, the application must return the memory block [using OSMemPut()] to the same memory partition when it no longer requires it. OSMemGet() may be called more than once until all memory blocks are allocated. Anchor10009481000948 Arguments Anchor10009491000949 p_mem Anchor10009511000951

Files

os.h/os_mem.c

Prototype

Code Block
void  *OSMemGet (OS_MEM  *p_mem,
                 OS_ERR  *p_err)

Arguments

p_mem

is a pointer to the desired memory partition control block.

Anchor10009521000952p_err Anchor10009531000953

is a pointer to a variable that holds an error code:

...

...

OS_ERR_NONE

...

classWebWorks_Indent_2

...

If a memory block is available and returned to the application.

...

...

classWebWorks_Indent_1

...

OS_ERR_MEM_INVALID_P_MEM

...

classWebWorks_Indent_2

...

If OS_CFG_ARG_CHK_EN is set to

...

DEF_ENABLED in os_cfg.h: if p_mem is a NULL pointer.

...

classWebWorks_Indent_1

...

OS_ERR_MEM_NO_FREE_BLKS

...

classWebWorks_Indent_2

...

If the memory partition does not contain additional memory blocks to allocate.

...

OS_ERR_OBJ_TYPE

If OS_CFG_OBJ_TYPE_CHK_EN is set to DEF_ENABLED in os_cfg.h: if the user did not pass a pointer to a memory partition.

Returned Value

OSMemGet() returns a pointer to the allocated memory block if one is available. If a memory block is not available from the memory partition, OSMemGet() returns a NULL pointer. It is up to the application to “cast” the pointer to the proper data type since OSMemGet() returns a void *. Anchor10509021050902

Required Configuration

OS_CFG_MEM_EN must be enabled in os_cfg.h. Refer to µC-OS-III Configuration Manual,

Callers

Application and ISRs.

Notes/Warnings

...

  1. Memory partitions must be created before they are used.

...

...

rowspan14

...

Example Usage

while

              while (DEF_ON)
{
 {
                  p_msg = (CPU_INT32U *)OSMemGet(&CommMem,
&err); /* Check “err” */ : : } }tr

                                                 &err);
                  /* Check "err" */
                  :
                  :
              }
          }
Code Block
titleOSMemGet() example usage
          OS_MEM  CommMem;
           
           
          void Task (void *p_arg)
          {
              OS_ERR       err;
              CPU_INT32U  *p_msg;
           
           
              (void)&p_arg;
Anchor
10508651050865
Anchor
10508661050866
Anchor
10508671050867
Anchor
10508681050868
Anchor
10508691050869
Anchor
10508701050870
Anchor
10508711050871
Anchor
10508721050872
Table Row (tr)
Table Row (tr)
Table Row (tr)
Table Row (tr)
Table Row (tr)
Table Row (tr)
Table Row (tr)
Table Row (tr)
Table Row (tr)
Table Row (tr)
Table Row (tr)
Table Row (tr)