9.2 Fixed-Sized Memory Pools
When a dynamic memory manipulation request is issued from a processing program in the RI600PX, 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.

9.2.1 Create fixed-sized memory pool

Fixed-sized memory pools are created by one of the following methods.

1 ) Creation by the system configuration file
The static API memorypool[] described in the system configuration file creates a fixed-sized memory pool.
Refer to 20.17 Fixed-sized Memory Pool Information (memorypool[]) for the details of memorypool[].



2 ) Creation by cre_mpf or acre_mpf
The cre_mpf creates a fixed-sized memory pool with fixed-sized memory pool ID indicated by parameter mpfid according to the content of parameter pk_cmpf.
The acre_mpf creates a fixed-sized memory pool according to the content of parameter pk_cmpf, and returns the created fixed-sized memory pool ID.
The information specified is shown below.



- Fixed-sized memory pool attribute (mpfatr)
The following informations are specified as mpfatr.


- The order of task wait queue (FIFO order or task current priority order)

- Total number of memory blocks (blkcnt), memory block size (blksz), Start address of the fixed-sized memory pool area (mpf)
The TSZ_MPF(blkcnt, blksz) bytes area from the address indicated by parameter mpf is used for the fixed-sized memory pool area. Refer to 18.3.3 Macros for Fixed-sized Memory Pool for details of TSZ_MPF macro.
The fixed-sized memory pool area should be in the memory object to be able to access by tasks which uses memory blocks.



- Start address of the fixed-sized memory pool management area (mpfmb)
The TSZ_MPFMB(blkcnt, blksz) bytes area from the address indicated by parameter mpfmb is used for the fixed-sized memory pool management area. Refer to 18.3.3 Macros for Fixed-sized Memory Pool for details of TVSZ_MPFMB macro.
The fixed-sized memory pool management area should be generated to the area other than memory objects and user stacks.



These service calls can be called from tasks that belong to Trusted Domain.
The following describes an example for coding acre_mpf as a representative.


 #include    "kernel.h"              /*Standard header file definition*/
 #include    "kernel_id.h"           /*Header file generated by cfg600px*/
 
 #define BLKCNT    32                /*Total number of memory blocks*/
 #define BLKSZ     16                /*Memory block size (in bytes)*/
 
 #pragma section B BU_SH           /*Section for the fixed-sized memory pool area*/
                                       /*Fixed-sized memory pool area*/
 static UW mpf_area[ TSZ_MPF(BLKCNT, BLKSZ)/sizeof(UW) ];
 
                         /* Section for the fixed-sized memory pool management area*/
 #pragma section B BRI_RAM
                                    /*Fixed-sized memory pool management area*/
 static UW mpfmb_area[ TSZ_MPFMB(BLKCNT, BLKSZ)/sizeof(UW) ];
 #pragma section
 
 #pragma task Task1                  /*Refer to note*/
 void Task1 (VP_INT exinf);          /*Refer to note*/
 void Task1 (VP_INT exinf)
 {
     ER      mpfid;        /*Declares variable*/
     T_CMPF  pk_cmpf = {   /*Declares and initializes variable*/
         TA_TFIFO,       /*Fixed-sized memory pool attribute (mpfatr)*/
         BLKCNT,         /*Total number of memory blocks (blkcnt)*/
         BLKSZ,          /*Memory block size (in bytes) (blksz)*/
         (VP)mpf_area,    /*Start address of the fixed-sized memory pool area (mpf)*/
             /*Start address of the fixed-sized memory pool management area (mpfmb)*/
         (VP)mpfmb_area
     };
 
     /* ......... */
 
     mpfid = acre_mpf ( &pk_cmpf );  /*Create fixed-sized memory pool/
 
     /* ......... */
 }


Note These statements are unnecessary for the task which is created by the system configuration file because the cfg600px generates these statement into the "kernel_id.h".

9.2.2 Delete fixed-sized memory pool

- del_mpf
This service call deletes the fixed-sized memory pool specified by parameter mpfid.
When there are waiting tasks for the target fixed-sized memory pool by using get_mpf or tget_mpf, this service call cancels the WAITING state of the tasks and returns E_DLT as a return value of the get_mpf or tget_mpf.
This service call can be called from tasks that belong to Trusted Domain.
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 cfg600px*/
 #pragma task Task1                  /*Refer to note*/
 void Task1 (VP_INT exinf);          /*Refer to note*/
 void Task1 (VP_INT exinf)
 {
     ID      mpfid = 8;          /*Declares and initializes variable*/
 
     /* ......... */
 
     ercd = del_mpf ( mpfid );   /*Delete fixed-sized memory pool*/
 
     /* ......... */
 }


Note These statements are unnecessary for the task which is created by the system configuration file because the cfg600px generates these statement into the "kernel_id.h".

9.2.3 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 RI600PX 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

Forced release from waiting (accept del_mpf while waiting).

E_DLT



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 cfg600px*/
 #pragma task Task1                  /*Refer to note 4*/
 void Task1 (VP_INT exinf);          /*Refer to note 4*/
 void Task1 (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 at creating the fixed-sized memory pool (FIFO order or current priority order).

Note 2 The contents of the block are undefined.

Note 3 The alignment number of memory block is 1. Please perform the following, in order to enlarge the alignment number of memory blocks.

- Specify the memory block size to a multiple of the desired alignment number at creating the fixed-sized memory pool.

- Make the start address of the fixed-sized memory pool area into the address of the desired alignment number.

Note 4 These statements are unnecessary for the task which is created by the system configuration file because the cfg600px generates these statement into the "kernel_id.h".

- 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 cfg600px*/
 #pragma task Task1                  /*Refer to note 3*/
 void Task1 (VP_INT exinf);          /*Refer to note 3*/
 void Task1 (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 alignment number of memory block is 1. Please perform the following, in order to enlarge the alignment number of memory blocks.

- Specify the memory block size to a multiple of the desired alignment number at creating the fixed-sized memory pool.

- Make the start address of the fixed-sized memory pool area into the address of the desired alignment number.

Note 3 These statements are unnecessary for the task which is created by the system configuration file because the cfg600px generates these statement into the "kernel_id.h".

- 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

Forced release from waiting (accept del_mpf while waiting).

E_DLT



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 cfg600px*/
 #pragma task Task1                  /*Refer to note 5*/
 void Task1 (VP_INT exinf);          /*Refer to note 5*/
 void Task1 (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 at creating the fixed-sized memory pool (FIFO order or current priority order).

Note 2 The contents of the block are undefined.

Note 3 The alignment number of memory block is 1. Please perform the following, in order to enlarge the alignment number of memory blocks.

- Specify the memory block size to a multiple of the desired alignment number at creating the fixed-sized memory pool.

- Make the start address of the fixed-sized memory pool area into the address of the desired alignment number.

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.

Note 5 These statements are unnecessary for the task which is created by the system configuration file because the cfg600px generates these statement into the "kernel_id.h".

9.2.4 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 cfg600px*/
 #pragma task Task1                  /*Refer to note*/
 void Task1 (VP_INT exinf);          /*Refer to note*/
 void Task1 (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*/
     }
 
     /* ......... */
 }


Note These statements are unnecessary for the task which is created by the system configuration file because the cfg600px generates these statement into the "kernel_id.h".

9.2.5 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 cfg600px*/
 #pragma task Task1                  /*Refer to note 2*/
 void Task1 (VP_INT exinf);          /*Refer to note 2*/
 void Task1 (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 1 For details about the fixed-sized memory pool state packet, refer to "[Fixed-sized memory pool state packet: T_RMPF]".

Note 2 These statements are unnecessary for the task which is created by the system configuration file because the cfg600px generates these statement into the "kernel_id.h".