Versions Compared

Key

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

...

Anchor10628021062802 Getting a Memory Block from a Partition Anchor10628031062803Application code can request a memory block from a partition by calling OSMemGet() as shown in Listing 17-3. The the listing below. The code assumes that the partition was already created.anchor

Code Block

...

OS_MEM MyPartition; (1) CPU_INT08U *MyDataBlkPtr;     void MyTask (void *p_arg) { OS_ERR err; : while (DEF_ON) { : MyDataBlkPtr = (CPU_INT08U
   (2) 
                                                        (OS_ERR    *)&err);
if (err ==

                  if (err == OS_ERR_NONE) {
(3) /* You have a memory block from the partition */ } : : } }
HTML Table
summary
classCode_Listing
Table Row (tr)
Table Cell (td)
Anchor
10696171069617
Anchor
10696181069618
Anchor
10696191069619
Anchor
10696201069620
Anchor
10696211069621
Anchor
10696221069622
Anchor
10696231069623
Anchor
10696241069624
Anchor
10696251069625
Anchor
10696261069626
Anchor
10696271069627
Anchor
10696281069628
titleObtaining a Memory Block from a Partition
          OS_MEM       MyPartition;                                                  (1) 
          CPU_INT08U  *MyDataBlkPtr;
           
           
          void  MyTask (void *p_arg)  
          {
              OS_ERR  err;
              
              :
              while (DEF_ON) {
                  :
                  MyDataBlkPtr = (CPU_INT08U *)OSMemGet((OS_MEM    *)&MyPartition,
(2)
Anchor
10696291069629
Anchor
10696301069630
Anchor
10696321069632
Anchor
10696331069633
Anchor
10696341069634
Anchor
10696351069635
Anchor
10696361069636
Anchor
10696371069637

...

                                          (3) 
                       /* You have a memory block from the partition */
                  }
                  :
                  :
              }
          }


Panel
bgColor#f0f0f0

(1) The memory partition control block must be accessible by all tasks or ISRs that will be using the partition.

...

(2) Simply call OSMemGet()

...

 to obtain a memory block from the desired partition. A pointer to the allocated memory block is returned. This is similar

...

to malloc(), except that the memory block comes from a pool that is guaranteed to not fragment. Also, it’s assumed that your application knows the size of each block so it doesn’t overflow the block with data.

...

(3) It is important to examine the returned error code to ensure that there are free memory blocks and that the application can start putting content in the memory blocks.