Everything
7.2 Fixed-Sized Memory Pools
When a dynamic memory manipulation request is issued from a processing program in the RI600V4, the fixed-sized memory pool is provided as a usable memory area.
Dynamic memory manipulation of the fixed-size memory pool is executed in fixed size memory block units.
7.2.1 Create fixed-sized memory pool
In the RI600V4, the method of creating a fixed-sized memory pool is limited to "static creation".
Fixed-sized memory pools therefore cannot be created dynamically using a method such as issuing a service call from a processing program.
Static fixed-size memory pool creation means defining of fixed-size memory pools using static API "memorypool[]" in the system configuration file.
For details about the static API "memorypool[]", refer to "19.14 Fixed-sized Memory Pool Information (memorypool[])".
7.2.2 Acquire fixed-sized memory block
A fixed-sized memory block is acquired (waiting forever, polling, or with time-out) by issuing the following service call from the processing program.
- get_mpf (Wait)
- pget_mpf, ipget_mpf (Polling)
- tget_mpf (Wait with time-out)
The RI600V4 does not perform memory clear processing when a fixed-sized memory block is acquired. The contents of the acquired fixed-size memory block are therefore undefined.
- get_mpf (Wait)
This service call acquires the fixed-sized memory block from the fixed-sized memory pool specified by parameter mpfid and stores the start address in the area specified by parameter p_blk.
If no fixed-size memory blocks could be acquired from the target fixed-size memory pool (no available fixed-size memory blocks exist) when this service call is issued, this service call does not acquire the fixed-size memory block but queues the invoking task to the target fixed-size memory pool wait queue and moves it from the RUNNING state to the WAITING state (fixed-size memory block acquisition wait state).
The WAITING state for a fixed-sized memory block is cancelled in the following cases.
WAITING State for a Fixed-sized Memory Block Cancel Operation
Return Value
A fixed-sized memory block was returned to the target fixed-sized memory pool as a result of issuing rel_mpf.
E_OK
A fixed-sized memory block was returned to the target fixed-sized memory pool as a result of issuing irel_mpf.
E_OK
Forced release from waiting (accept rel_wai while waiting).
E_RLWAI
Forced release from waiting (accept irel_wai while waiting).
E_RLWAI
The fixed-sized memory pool is reset as a result of issuing vrst_mpf.
EV_RST

The following describes an example for coding this service call.
 #include    "kernel.h"              /*Standard header file definition*/
 #include    "kernel_id.h"           /*Header file generated by cfg600*/
 
 void task (VP_INT exinf)
 {
     ER      ercd;                   /*Declares variable*/
     ID      mpfid = 1;              /*Declares and initializes variable*/
     VP      p_blk;                  /*Declares variable*/
 
     /* ......... */
 
     ercd = get_mpf (mpfid, &p_blk); /*Acquire fixed-sized memory block */
 
     if (ercd == E_OK) {
         /* ......... */             /*Normal termination processing*/
 
         rel_mpf (mpfid, p_blk);     /*Release fixed-sized memory block*/
     } else if (ercd == E_RLWAI) {
         /* ......... */             /*Forced termination processing*/
     }
 
     /* ......... */
 }

Note 1 Invoking tasks are queued to the target fixed-size memory pool wait queue in the order defined during configuration (FIFO order or current priority order).
Note 2 The contents of the block are undefined.
Note 3 The boundary alignment for the memory blocks acquired is 1. If memory blocks need to be acquired with a larger boundary alignment than that, observe the following:
- Specify unique section name to the Section name assigned to the memory pool area (section) in Fixed-sized Memory Pool Information (memorypool[]) and locate the section to the address of the desired boundary alignment when linking.
- pget_mpf, ipget_mpf (Polling)
This service call acquires the fixed-sized memory block from the fixed-sized memory pool specified by parameter mpfid and stores the start address in the area specified by parameter p_blk.
If a fixed-sized memory block could not be acquired from the target fixed-sized memory pool (no available fixed-sized memory blocks exist) when this service call is issued, fixed-sized memory block acquisition processing is not performed but E_TMOUT is returned.
The following describes an example for coding these service calls.
 #include    "kernel.h"              /*Standard header file definition*/
 #include    "kernel_id.h"           /*Header file generated by cfg600*/
 
 void task (VP_INT exinf)
 {
     ER      ercd;                   /*Declares variable*/
     ID      mpfid = 1;              /*Declares and initializes variable*/
     VP      p_blk;                  /*Declares variable*/
 
     /* ......... */
 
                                     /*Acquire fixed-sized memory block */
     ercd = pget_mpf (mpfid, &p_blk);
 
     if (ercd == E_OK) {
         /* ......... */             /*Polling success processing*/
 
         rel_mpf (mpfid, p_blk);     /*Release fixed-sized memory block*/
     } else if (ercd == E_TMOUT) {
         /* ......... */             /*Polling failure processing*/
     }
 
     /* ......... */
 }

Note 1 The contents of the block are undefined.
Note 2 The boundary alignment for the memory blocks acquired is 1. If memory blocks need to be acquired with a larger boundary alignment than that, observe the following:
- Specify unique section name to the Section name assigned to the memory pool area (section) in Fixed-sized Memory Pool Information (memorypool[]) and locate the section to the address of the desired boundary alignment when linking.
- tget_mpf (Wait with time-out)
This service call acquires the fixed-sized memory block from the fixed-sized memory pool specified by parameter mpfid and stores the start address in the area specified by parameter p_blk.
If no fixed-size memory blocks could be acquired from the target fixed-size memory pool (no available fixed-size memory blocks exist) when this service call is issued, this service call does not acquire the fixed-size memory block but queues the invoking task to the target fixed-size memory pool wait queue and moves it from the RUNNING state to the WAITING state with time-out (fixed-size memory block acquisition wait state).
The WAITING state for a fixed-sized memory block is cancelled in the following cases.
WAITING State for a Fixed-sized Memory Block Cancel Operation
Return Value
A fixed-sized memory block was returned to the target fixed-sized memory pool as a result of issuing rel_mpf.
E_OK
A fixed-sized memory block was returned to the target fixed-sized memory pool as a result of issuing irel_mpf.
E_OK
Forced release from waiting (accept rel_wai while waiting).
E_RLWAI
Forced release from waiting (accept irel_wai while waiting).
E_RLWAI
The fixed-sized memory pool is reset as a result of issuing vrst_mpf.
EV_RST
The time specified by tmout has elapsed.
E_TMOUT

The following describes an example for coding this service call.
 #include    "kernel.h"              /*Standard header file definition*/
 #include    "kernel_id.h"           /*Header file generated by cfg600*/
 
 void task (VP_INT exinf)
 {
     ER      ercd;                   /*Declares variable*/
     ID      mpfid = 1;              /*Declares and initializes variable*/
     VP      p_blk;                  /*Declares variable*/
     TMO     tmout = 3600;           /*Declares and initializes variable*/
 
     /* ......... */
                                     /*Acquire fixed-sized memory block*/
     ercd = tget_mpf (mpfid, &p_blk, tmout);
 
     if (ercd == E_OK) {
         /* ......... */             /*Normal termination processing*/
 
         rel_mpf (mpfid, p_blk);     /*Release fixed-sized memory block*/
     } else if (ercd == E_RLWAI) {
         /* ......... */             /*Forced termination processing*/
     } else if (ercd == E_TMOUT) {
         /* ......... */             /*Time-out processing*/
     }
 
     /* ......... */
 }

Note 1 Invoking tasks are queued to the target fixed-size memory pool wait queue in the order defined during configuration (FIFO order or current priority order).
Note 2 The contents of the block are undefined.
Note 3 The boundary alignment for the memory blocks acquired is 1. If memory blocks need to be acquired with a larger boundary alignment than that, observe the following:
- Specify unique section name to the Section name assigned to the memory pool area (section) in Fixed-sized Memory Pool Information (memorypool[]) and locate the section to the address of the desired boundary alignment when linking.
Note 4 TMO_FEVR is specified for wait time tmout, processing equivalent to get_mpf will be executed. When TMO_POL is specified, processing equivalent to pget_mpf will be executed.
7.2.3 Release fixed-sized memory block
A fixed-sized memory block is returned by issuing the following service call from the processing program.
- rel_mpf, irel_mpf
This service call returns the fixed-sized memory block specified by parameter blk to the fixed-sized memory pool specified by parameter mpfid.
If a task is queued to the target fixed-sized memory pool wait queue when this service call is issued, fixed-sized memory block return processing is not performed but fixed-sized memory blocks are returned to the relevant task (first task of wait queue).
As a result, the relevant task is unlinked from the wait queue and is moved from the WAITING state (WAITING state for a fixed-sized memory block) to the READY state, or from the WAITING-SUSPENDED state to the SUSPENDED state.
The following describes an example for coding these service calls.
 #include    "kernel.h"              /*Standard header file definition*/
 #include    "kernel_id.h"           /*Header file generated by cfg600*/
 
 void task (VP_INT exinf)
 {
     ER      ercd;                   /*Declares variable*/
     ID      mpfid = 1;              /*Declares and initializes variable*/
     VP      blk;                    /*Declares variable*/
 
     /* ......... */
 
     ercd = get_mpf (mpfid, &blk);   /*Acquire fixed-sized memory block */
                                     /*(waiting forever)*/
 
     if (ercd == E_OK) {
         /* ......... */             /*Normal termination processing*/
 
         rel_mpf (mpfid, blk);       /*Release fixed-sized memory block*/
     } else if (ercd == E_RLWAI) {
         /* ......... */             /*Forced termination processing*/
     }
 
     /* ......... */
 }

7.2.4 Reference fixed-sized memory pool state
A fixed-sized memory pool status is referenced by issuing the following service call from the processing program.
- ref_mpf, iref_mpf
Stores fixed-sized memory pool state packet (ID number of the task at the head of the wait queue, number of free memory blocks, etc.) of the fixed-sized memory pool specified by parameter mpfid in the area specified by parameter pk_rmpf.
The following describes an example for coding these service calls.
 #include    "kernel.h"              /*Standard header file definition*/
 #include    "kernel_id.h"           /*Header file generated by cfg600*/
 
 void task (VP_INT exinf)
 {
     ID      mpfid = 1;              /*Declares and initializes variable*/
     T_RMPF  pk_rmpf;                /*Declares data structure*/
     ID      wtskid;                 /*Declares variable*/
     UINT    fblkcnt;                /*Declares variable*/
 
     /* ......... */
 
     ref_mpf (mpfid, &pk_rmpf);      /*Reference fixed-sized memory pool state*/
 
     wtskid = pk_rmpf.wtskid;        /*Reference ID number of the task at the */
                                     /*head of the wait queue*/
     fblkcnt = pk_rmpf.fblkcnt;      /*Reference number of free memory blocks*/
 
     /* ......... */
 }

Note For details about the fixed-sized memory pool state packet, refer to "[Fixed-sized memory pool state packet: T_RMPF]".