9.3 Variable-Sized Memory Pools
When a dynamic memory manipulation request is issued from a processing program in the RI600PX, the variable-sized memory pool is provided as a usable memory area.

Dynamic memory manipulation for variable-size memory pools is performed in the units of the specified variable-size memory block size.

9.3.1 Size of Variable-sized memory block

In the current implementation of the RI600PX, the size of the variable-sized memory block to be acquired is selected from 12 (in maximum) kinds of variations. This variations are selected from 24 kinds of inside decided beforehand according to the maximum memory block size that is defined at creating the variable-sized memory pool. Table 9-1 shows variation of memory block size. Note, this behavior may be changed in the future version.

Table 9-1 Variation of memory block size
No,

Size of memory block (Hexadecimal)

Example-1

max_memsize = 0x100

Example-1

max_memsize = 0x20000

1

12 (0xC)

Used

-

2

36 (0x24)

Used

-

3

84 (0x54)

Used

Used

4

180 (0xB4)

Used

Used

5

372 (0x174)

-

Used

6

756 (0x2F4)

-

Used

7

1524 (0x5F4)

-

Used

8

3060 (0xBF4)

-

Used

9

6132 (0x17F4)

-

Used

10

12276 (0x2FF4)

-

Used

11

24564 (0x5FF4)

-

Used

12

49140 (0xBFF4)

-

Used

13

98292 (0x17FF4)

-

Used

14

196596 (0x2FFF4)

-

Used

15

393204 (0x5FFF4)

-

-

16

786420 (0xBFFF4)

-

-

17

1572852 (0x17FFF4)

-

-

18

3145716 (0x2FFFF4)

-

-

19

6291444 (0x5FFFF4)

-

-

20

12582900 (0xBFFFF4)

-

-

21

25165812 (0x17FFFF4)

-

-

22

50331636 (0x2FFFFF4)

-

-

23

100663284 (0x5FFFFF4)

-

-

24

201326580 (0xBFFFFF4)

-

-



9.3.2 Create variable-sized memory pool

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

1 ) Creation by the system configuration file
The static API variable_memorypool[] described in the system configuration file creates a variable-sized memory pool.
Refer to 20.18 Variable-sized Memory Pool Information (variable_memorypool[]) for the details of variable_memorypool[].



2 ) Creation by cre_mpl or acre_mpl
The cre_mpl creates a variable-sized memory pool with variable-sized memory pool ID indicated by parameter mplid according to the content of parameter pk_cmpl.
The acre_mpl creates a variable-sized memory pool according to the content of parameter pk_cmpl, and returns the created variable-sized memory pool ID.
The information specified is shown below.



- Variable-sized memory pool attribute (mplatr)
Only TA_TFIFO (the order of task wait queue is managed by FIFO order.) can be specified for mplatr.


- Size of variable-sized memory pool area (mplsz), Start address of the variable-sized memory pool area (mpl)
The start adderess of the variable-sized memory pool area must be 4-bytes boundary.
The variable-sized memory pool area should be in the memory object to be able to access by tasks which uses memory blocks.



- Maximum memory block size (maxblksz)
Specify the maximum memory block size for maxblksz. For details, refer to 9.3.1 Size of Variable-sized memory block.


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


 #include    "kernel.h"              /*Standard header file definition*/
 #include    "kernel_id.h"           /*Header file generated by cfg600px*/
 
 #define MPLSZ     1024      /*Size of variable-sized memory pool area (in bytes)*/
 #define MAXBLKSZ  128       /*Maximum memory block size (in bytes)*/
 
 #pragma section B BU_SH     /*Section for the variable-sized memory pool area*/
 static UW mpl_area[ MPLSZ/sizeof(UW) ]; /*Variable-sized memory pool area*/
 #pragma section
 
 #pragma task Task1                  /*Refer to note*/
 void Task1 (VP_INT exinf);          /*Refer to note*/
 void Task1 (VP_INT exinf)
 {
     ER      mplid;        /*Declares variable*/
     T_CMPF  pk_cmpl = {   /*Declares and initializes variable*/
         TA_TFIFO,   /*Variable-sized memory pool attribute (mplatr)*/
         MPLSZ,      /*Size of variable-sized memory pool area (in bytes) (mplsz)*/
         (VP)mpl_area,/*Start address of the variable-sized memory pool area (mpl)*/
         MAXBLKLSZ   /*Maximum memory block size (in bytes) (maxblksz)*/
     };
 
     /* ......... */
     mplid = acre_mpl ( &pk_cmpf );  /*Create variable-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.3.3 Delete variable-sized memory pool

- del_mpl
This service call deletes the variable-sized memory pool specified by parameter mplid.
When there are waiting tasks for the target variable-sized memory pool by using get_mpl or tget_mpl, this service call cancels the WAITING state of the tasks and returns E_DLT as a return value of the get_mpl or tget_mpl.
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      mplid = 8;          /*Declares and initializes variable*/
 
     /* ......... */
 
     ercd = del_mpl ( mplid );   /*Delete variable-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.3.4 Acquire variable-sized memory block

A variable-sized memory block is acquired (waiting forever, polling, or with time-out) by issuing the following service call from the processing program.

- get_mpl (Wait)

- pget_mpl, ipget_mpl (Polling)

- tget_mpl (Wait with time-out)

The RI600PX does not perform memory clear processing when a variable-sized memory block is acquired. The contents of the acquired variable-size memory block are therefore undefined.

- get_mpl (Wait)
This service call acquires a variable-size memory block of the size specified by parameter blksz from the variable-size memory pool specified by parameter mplid, and stores its start address into the area specified by parameter p_blk.
If no variable-size memory blocks could be acquired from the target variable-size memory pool (no successive areas equivalent to the requested size were available) when this service call is issued, this service call does not acquire variable-size memory blocks but queues the invoking task to the target variable-size memory pool wait queue and moves it from the RUNNING state to the WAITING state (variable-size memory block acquisition wait state).
The WAITING state for a variable-sized memory block is cancelled in the following cases.




WAITING State for a Variable-sized Memory Block Cancel Operation

Return Value

The variable-size memory block that satisfies the requested size was returned to the target variable-size memory pool as a result of issuing rel_mpl.

E_OK

The task at the top of the transmission wait queue was forcedly released from waiting by following either.

- Forced release from waiting (accept rel_wai while waiting).

- Forced release from waiting (accept irel_wai while waiting).

- Forced release from waiting (accept ter_tsk while waiting).

- The time specified by tmout for tget_mpl has elapsed.

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 variable-sized memory pool is reset as a result of issuing vrst_mpl.

EV_RST

Forced release from waiting (accept del_mpl 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      mplid = 1;              /*Declares and initializes variable*/
     UINT    blksz = 256;            /*Declares and initializes variable*/
     VP      p_blk;                  /*Declares variable*/
 
     /* ......... */
                                     /*Acquire variable-sized memory block */
     ercd = get_mpl (mplid, blksz, &p_blk);
 
     if (ercd == E_OK) {
         /* ......... */             /*Normal termination processing*/
 
         rel_mpl (mplid, p_blk);     /*Release variable-sized memory block*/
     } else if (ercd == E_RLWAI) {
         /* ......... */             /*Forced termination processing*/
     }
 
     /* ......... */
 }


Note 1 For the size of the memory block, refer to "9.3.1 Size of Variable-sized memory block".

Note 2 Invoking tasks are queued to the target variable-size memory pool wait queue in the FIFO order.

Note 3 The contents of the block are undefined.

Note 4 The alignment number of memory blocks changes with creation method of the variable-sized memory pool.

- Created by system configuration file
The alignment number is 1. To enlarge the alignment number to 4, specify unique section to Section name assigned to the memory pool area (mpl_section) in Variable-sized Memory Pool Information (variable_memorypool[]) and locate the section to 4-bytes boundary address when linking.


- Created by cre_mpl or acre_mpl
The alignment number is 4.

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".

- pget_mpl, ipget_mpl (Polling)
This service call acquires a variable-size memory block of the size specified by parameter blksz from the variable-size memory pool specified by parameter mplid, and stores its start address into the area specified by parameter p_blk.
If no variable-size memory blocks could be acquired from the target variable-size memory pool (no successive areas equivalent to the requested size were available) when this service call is issued, this service call does not acquire variable-size memory block but returns E_TMOUT.
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 4*/
 void Task1 (VP_INT exinf);          /*Refer to note 4*/
 void Task1 (VP_INT exinf)
 {
     ER      ercd;                   /*Declares variable*/
     ID      mplid = 1;              /*Declares and initializes variable*/
     UINT    blksz = 256;            /*Declares and initializes variable*/
     VP      p_blk;                  /*Declares variable*/
 
     /* ......... */
 
                                     /*Acquire variable-sized memory block*/
     ercd = pget_mpl (mplid, blksz, &p_blk);
 
     if (ercd == E_OK) {
         /* ......... */             /*Polling success processing*/
 
         rel_mpl (mplid, p_blk);     /*Release variable-sized memory block*/
     } else if (ercd == E_TMOUT) {
         /* ......... */             /*Polling failure processing*/
     }
 
     /* ......... */
 }


Note 1 For the size of the memory block, refer to "9.3.1 Size of Variable-sized memory block".

Note 2 The contents of the block are undefined.

Note 3 The alignment number of memory blocks changes with creation method of the variable-sized memory pool.

- Created by system configuration file
The alignment number is 1. To enlarge the alignment number to 4, specify unique section to Section name assigned to the memory pool area (mpl_section) in Variable-sized Memory Pool Information (variable_memorypool[]) and locate the section to 4-bytes boundary address when linking.


- Created by cre_mpl or acre_mpl
The alignment number is 4.

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".

- tget_mpl (Wait with time-out)
This service call acquires a variable-size memory block of the size specified by parameter blksz from the variable-size memory pool specified by parameter mplid, and stores its start address into the area specified by parameter p_blk.
If no variable-size memory blocks could be acquired from the target variable-size memory pool (no successive areas equivalent to the requested size were available) when this service call is issued, this service call does not acquire variable-size memory blocks but queues the invoking task to the target variable-size memory pool wait queue and moves it from the RUNNING state to the WAITING state with time-out (variable-size memory block acquisition wait state).
The WAITING state for a variable-sized memory block is cancelled in the following cases.




WAITING State for a Variable-sized Memory Block Cancel Operation

Return Value

The variable-size memory block that satisfies the requested size was returned to the target variable-size memory pool as a result of issuing rel_mpl.

E_OK

The task at the top of the transmission wait queue was forcedly released from waiting by following either.

- Forced release from waiting (accept rel_wai while waiting).

- Forced release from waiting (accept irel_wai while waiting).

- Forced release from waiting (accept ter_tsk while waiting).

- The time specified by tmout for tget_mpl has elapsed.

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 variable-sized memory pool is reset as a result of issuing vrst_mpl.

EV_RST

The time specified by tmout has elapsed.

E_TMOUT

Forced release from waiting (accept del_mpl 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      mplid = 1;              /*Declares and initializes variable*/
     UINT    blksz = 256;            /*Declares and initializes variable*/
     VP      p_blk;                  /*Declares variable*/
     TMO     tmout = 3600;           /*Declares and initializes variable*/
 
     /* ......... */
 
                                     /*Acquire variable-sized memory block*/
     ercd = tget_mpl (mplid, blksz, &p_blk, tmout);
 
     if (ercd == E_OK) {
         /* ......... */             /*Normal termination processing*/
 
         rel_mpl (mplid, p_blk ;     /*Release variable-sized memory block*/
     } else if (ercd == E_RLWAI) {
         /* ......... */             /*Forced termination processing*/
     } else if (ercd == E_TMOUT) {
         /* ......... */             /*Time-out processing*/
     }
 
     /* ......... */
 }


Note 1 For the size of the memory block, refer to "9.3.1 Size of Variable-sized memory block".

Note 2 Invoking tasks are queued to the target variable-size memory pool wait queue in the FIFO order.

Note 3 The contents of the block are undefined.

Note 4 The alignment number of memory blocks changes with creation method of the variable-sized memory pool.

- Created by system configuration file
The alignment number is 1. To enlarge the alignment number to 4, specify unique section to Section name assigned to the memory pool area (mpl_section) in Variable-sized Memory Pool Information (variable_memorypool[]) and locate the section to 4-bytes boundary address when linking.


- Created by cre_mpl or acre_mpl
The alignment number is 4.

Note 5 TMO_FEVR is specified for wait time tmout, processing equivalent to get_mpl will be executed. When TMO_POL is specified, processing equivalent to pget_mpl will be executed.

Note 6 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.3.5 Release variable-sized memory block

A variable-sized memory block is returned by issuing the following service call from the processing program.

- rel_mpl
This service call returns the variable-sized memory block specified by parameter blk to the variable-sized memory pool specified by parameter mplid.
After returning the variable-size memory blocks, these service calls check the tasks queued to the target variable-size memory pool wait queue from the top, and assigns the memory if the size of memory requested by the wait queue is available. This operation continues until no tasks queued to the wait queue remain or no memory space is available. As a result, the task that acquired the memory is unlinked from the queue and moved from the WAITING state (variable-size memory block acquisition wait state) 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 2*/
 void Task1 (VP_INT exinf);          /*Refer to note 2*/
 void Task1 (VP_INT exinf)
 {
     ER      ercd;                   /*Declares variable*/
     ID      mplid = 1;              /*Declares and initializes variable*/
     UINT    blksz = 256;            /*Declares and initializes variable*/
     VP      blk;                    /*Declares variable*/
 
     /* ......... */
 
                                     /*Acquire variable-sized memory block*/
     ercd = get_mpl (mplid, blksz, &blk);
 
     if (ercd == E_OK) {
         /* ......... */             /*Normal termination processing*/
 
         rel_mpl (mplid, blk);       /*Release variable-sized memory block*/
     } else if (ercd == E_RLWAI) {
         /* ......... */             /*Forced termination processing*/
     }
 
     /* ......... */
 }


Note 1 The RI600PX do only simple error detection for blk. If blk is illegal and the error is not detected, the operation is not guaranteed after that.

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".

9.3.6 Reference variable-sized memory pool state

A variable-sized memory pool status is referenced by issuing the following service call from the processing program.

- ref_mpl, iref_mpl
These service calls store the detailed information (ID number of the task at the head of the wait queue, total size of free memory blocks, etc.) of the variable-size memory pool specified by parameter mplid into the area specified by parameter pk_rmpl.
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      mplid = 1;              /*Declares and initializes variable*/
     T_RMPL  pk_rmpl;                /*Declares data structure*/
     ID      wtskid;                 /*Declares variable*/
     SIZE    fmplsz;                 /*Declares variable*/
     UINT    fblksz;                 /*Declares variable*/
 
     /* ......... */
 
     ref_mpl (mplid, &pk_rmpl);      /*Reference variable-sized memory pool state*/
 
     wtskid = pk_rmpl.wtskid;        /*Reference ID number of the task at the */
                                     /*head of the wait queue*/
     fmplsz = pk_rmpl.fmplsz;        /*Reference total size of free memory blocks*/
     fblksz = pk_rmpl.fblksz;        /*Reference maximum memory block size*/
 
     /* ......... */
 }


Note 1 For details about the variable-sized memory pool state packet, refer to "[Variable-sized memory pool state packet: T_RMPL]".

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".